Subject: kern/4393: MSDOSFS_DEBUG doesn't work
To: None <netbsd-bugs@NetBSD.ORG>
From: Rick Byers <rickb@iaw.on.ca>
List: netbsd-bugs
Date: 11/14/1997 20:48:56
I'm resending theese because they got lost the first time (they did make
it into the gnats databse though).

>Number:         4393
>Category:       kern
>Synopsis:       kernel won't compile if MSDOSFS_DEBUG is enabled
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    kern-bug-people (Kernel Bug People)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Oct 29 22:50:01 1997
>Originator:     Rick Byers
>Organization:
=========================================================================
Rick Byers                                      Internet Access Worldwide
rickb@iaw.on.ca                                              System Admin
University of Waterloo, Computer Science                    (905)714-1400
http://www.iaw.on.ca/rickb/                         http://www.iaw.on.ca/


>Release:        Oct 25, 1997
>Environment:
System: NetBSD rickb 1.3_ALPHA NetBSD 1.3_ALPHA (RICKB) #16: Thu Oct 30 00:17:5
8 EST 1997 root@rickb:/usr/src/sys/arch/i386/compile/RICKB i386




>Description:
        If MSDOSFS_DEBUG is enabled, the msdosfs code fails in many places,
        mostly due to printf format/argument mismatches, but a few variable
        names needed to be changed as well.
>How-To-Repeat:
        Try to track down some of the bugs in the msdosfs code (next few
        pr's).
>Fix:
        Apply the follwing patch (or something like it atleast).
        There is one spot in msdosfs_vfsops where I wasn't sure what to do.
        The debug code tries to print vp->v_freef, v_freeb, v_mountf, and
        v_mountb.  I couldn't find any reference to these variables, so
        I commented it out.  Someone that understands vnode's better than
        I should replace it with something more suitable (or remove it
        entirely).

Index: msdosfs_denode.c
===================================================================
RCS file: /usr/cvsroot/netbsd/src/sys/msdosfs/msdosfs_denode.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -c -r1.1.1.2 -r1.2
*** msdosfs_denode.c	1997/10/23 03:06:41	1.1.1.2
--- msdosfs_denode.c	1997/10/30 06:18:05	1.2
***************
*** 167,173 ****
  	struct buf *bp;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("deget(pmp %08x, dirclust %d, diroffset %x, depp %08x)\n",
  	    pmp, dirclust, diroffset, depp);
  #endif
  
--- 167,173 ----
  	struct buf *bp;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("deget(pmp %p, dirclust %ld, diroffset %lx, depp %p)\n",
  	    pmp, dirclust, diroffset, depp);
  #endif
  
***************
*** 430,436 ****
  	vinvalbuf(DETOV(dep), vflags, cred, p, 0, 0);
  	allerror = deupdat(dep, 1);
  #ifdef MSDOSFS_DEBUG
! 	printf("detrunc(): allerror %d, eofentry %d\n",
  	       allerror, eofentry);
  #endif
  
--- 430,436 ----
  	vinvalbuf(DETOV(dep), vflags, cred, p, 0, 0);
  	allerror = deupdat(dep, 1);
  #ifdef MSDOSFS_DEBUG
! 	printf("detrunc(): allerror %d, eofentry %ld\n",
  	       allerror, eofentry);
  #endif
  
***************
*** 543,549 ****
  	extern int prtactive;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_reclaim(): dep %08x, file %s, refcnt %d\n",
  	    dep, dep->de_Name, dep->de_refcnt);
  #endif
  
--- 543,549 ----
  	extern int prtactive;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_reclaim(): dep %p, file %s, refcnt %ld\n",
  	    dep, dep->de_Name, dep->de_refcnt);
  #endif
  
***************
*** 582,588 ****
  	extern int prtactive;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_inactive(): dep %08x, de_Name[0] %x\n", dep, dep->de_Name[0]);
  #endif
  
  	if (prtactive && vp->v_usecount != 0)
--- 582,588 ----
  	extern int prtactive;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_inactive(): dep %p, de_Name[0] %x\n", dep, dep->de_Name[0]);
  #endif
  
  	if (prtactive && vp->v_usecount != 0)
***************
*** 613,619 ****
  	 * as empty.  (This may not be necessary for the dos filesystem.)
  	 */
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_inactive(): dep %08x, refcnt %d, mntflag %x, MNT_RDONLY %x\n",
  	       dep, dep->de_refcnt, vp->v_mount->mnt_flag, MNT_RDONLY);
  #endif
  	if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
--- 613,619 ----
  	 * as empty.  (This may not be necessary for the dos filesystem.)
  	 */
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_inactive(): dep %p, refcnt %ld, mntflag %x, MNT_RDONLY %x\n",
  	       dep, dep->de_refcnt, vp->v_mount->mnt_flag, MNT_RDONLY);
  #endif
  	if (dep->de_refcnt <= 0 && (vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
Index: msdosfs_fat.c
===================================================================
RCS file: /usr/cvsroot/netbsd/src/sys/msdosfs/msdosfs_fat.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -c -r1.1.1.2 -r1.2
*** msdosfs_fat.c	1997/10/23 03:06:42	1.1.1.2
--- msdosfs_fat.c	1997/10/30 06:18:06	1.2
***************
*** 336,342 ****
  	struct buf *bpn;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("updatefats(pmp %08x, bp %08x, fatbn %d)\n",
  	    pmp, bp, fatbn);
  #endif
  
--- 336,342 ----
  	struct buf *bpn;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("updatefats(pmp %p, bp %p, fatbn %ld)\n",
  	    pmp, bp, fatbn);
  #endif
  
***************
*** 510,517 ****
  	struct buf *bp;
  
  #ifdef	MSDOSFS_DEBUG
! 	printf("fatentry(func %d, pmp %08x, clust %d, oldcon %08x, newcon %d)\n",
! 	     function, pmp, cluster, oldcontents, newcontents);
  #endif
  
  #ifdef DIAGNOSTIC
--- 510,517 ----
  	struct buf *bp;
  
  #ifdef	MSDOSFS_DEBUG
! 	printf("fatentry(func %d, pmp %p, clust %ld, oldcon %p, newcon %ld)\n",
! 	     function, pmp, cn, oldcontents, newcontents);
  #endif
  
  #ifdef DIAGNOSTIC
***************
*** 615,621 ****
  	struct buf *bp;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("fatchain(pmp %08x, start %d, count %d, fillwith %d)\n",
  	    pmp, start, count, fillwith);
  #endif
  	/*
--- 615,621 ----
  	struct buf *bp;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("fatchain(pmp %p, start %ld, count %ld, fillwith %ld)\n",
  	    pmp, start, count, fillwith);
  #endif
  	/*
***************
*** 740,746 ****
  	if ((error = fatchain(pmp, start, count, fillwith)) != 0)
  		return (error);
  #ifdef MSDOSFS_DEBUG
! 	printf("clusteralloc(): allocated cluster chain at %d (%d clusters)\n",
  	    start, count);
  #endif
  	if (retcluster)
--- 740,746 ----
  	if ((error = fatchain(pmp, start, count, fillwith)) != 0)
  		return (error);
  #ifdef MSDOSFS_DEBUG
! 	printf("clusteralloc(): allocated cluster chain at %ld (%ld clusters)\n",
  	    start, count);
  #endif
  	if (retcluster)
***************
*** 776,782 ****
  	u_int map;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("clusteralloc(): find %d clusters\n",count);
  #endif
  	if (start) {
  		if ((len = chainlength(pmp, start, count)) >= count)
--- 776,782 ----
  	u_int map;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("clusteralloc(): find %ld clusters\n",count);
  #endif
  	if (start) {
  		if ((len = chainlength(pmp, start, count)) >= count)
Index: msdosfs_lookup.c
===================================================================
RCS file: /usr/cvsroot/netbsd/src/sys/msdosfs/msdosfs_lookup.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -c -r1.1.1.2 -r1.2
*** msdosfs_lookup.c	1997/10/23 03:06:44	1.1.1.2
--- msdosfs_lookup.c	1997/10/30 06:18:07	1.2
***************
*** 123,129 ****
  	lockparent = flags & LOCKPARENT;
  	wantparent = flags & (LOCKPARENT | WANTPARENT);
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_lookup(): vdp %08x, dp %08x, Attr %02x\n",
  	    vdp, dp, dp->de_Attributes);
  #endif
  
--- 123,129 ----
  	lockparent = flags & LOCKPARENT;
  	wantparent = flags & (LOCKPARENT | WANTPARENT);
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_lookup(): vdp %p, dp %p, Attr %02x\n",
  	    vdp, dp, dp->de_Attributes);
  #endif
  
***************
*** 174,180 ****
  		if (!error) {
  			if (vpid == vdp->v_id) {
  #ifdef MSDOSFS_DEBUG
! 				printf("msdosfs_lookup(): cache hit, vnode %08x, file %s\n",
  				       vdp, dp->de_Name);
  #endif
  				return (0);
--- 174,180 ----
  		if (!error) {
  			if (vpid == vdp->v_id) {
  #ifdef MSDOSFS_DEBUG
! 				printf("msdosfs_lookup(): cache hit, vnode %p, file %s\n",
  				       vdp, dp->de_Name);
  #endif
  				return (0);
***************
*** 239,245 ****
  		slotcount = 0;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_lookup(): dos version of filename %s, length %d\n",
  	    dosfilename, cnp->cn_namelen);
  #endif
  	/*
--- 239,245 ----
  		slotcount = 0;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_lookup(): dos version of filename %s, length %ld\n",
  	    dosfilename, cnp->cn_namelen);
  #endif
  	/*
***************
*** 378,384 ****
  	 * the pathname and the directory hasn't been removed.
  	 */
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_lookup(): op %d, refcnt %d\n",
  	    nameiop, dp->de_refcnt);
  	printf("               slotcount %d, slotoffset %d\n",
  	       slotcount, slotoffset);
--- 378,384 ----
  	 * the pathname and the directory hasn't been removed.
  	 */
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_lookup(): op %d, refcnt %ld\n",
  	    nameiop, dp->de_refcnt);
  	printf("               slotcount %d, slotoffset %d\n",
  	       slotcount, slotoffset);
***************
*** 609,615 ****
  	int blsize;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("createde(dep %08x, ddep %08x, depp %08x, cnp %08x)\n",
  	    dep, ddep, depp, cnp);
  #endif
  
--- 609,615 ----
  	int blsize;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("createde(dep %p, ddep %p, depp %p, cnp %p)\n",
  	    dep, ddep, depp, cnp);
  #endif
  
***************
*** 952,958 ****
  	u_long offset = pdep->de_fndoffset;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("removede(): filename %s, dep %08x, offset %08x\n",
  	    dep->de_Name, dep, offset);
  #endif
  
--- 952,958 ----
  	u_long offset = pdep->de_fndoffset;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("removede(): filename %s, dep %p, offset %08lx\n",
  	    dep->de_Name, dep, offset);
  #endif
  
Index: msdosfs_vfsops.c
===================================================================
RCS file: /usr/cvsroot/netbsd/src/sys/msdosfs/msdosfs_vfsops.c,v
retrieving revision 1.1.1.3
retrieving revision 1.2
diff -c -r1.1.1.3 -r1.2
*** msdosfs_vfsops.c	1997/10/23 03:06:45	1.1.1.3
--- msdosfs_vfsops.c	1997/10/30 06:18:08	1.2
***************
*** 345,351 ****
  	    &size);
  	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_mount(): mp %x, pmp %x, inusemap %x\n", mp, pmp, pmp->pm_inusemap);
  #endif
  	return (0);
  }
--- 345,351 ----
  	    &size);
  	bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_mount(): mp %p, pmp %p, inusemap %p\n", mp, pmp, pmp->pm_inusemap);
  #endif
  	return (0);
  }
***************
*** 747,762 ****
  	pmp->pm_devvp->v_specflags &= ~SI_MOUNTEDON;
  #ifdef MSDOSFS_DEBUG
  	printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
! 	printf("flag %08x, usecount %d, writecount %d, holdcnt %d\n",
! 	    vp->v_flag, vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
! 	printf("lastr %d, id %d, mount %08x, op %08x\n",
! 	    vp->v_lastr, vp->v_id, vp->v_mount, vp->v_op);
! 	printf("freef %08x, freeb %08x, mountf %08x, mountb %08x\n",
! 	    vp->v_freef, vp->v_freeb, vp->v_mountf, vp->v_mountb);
! 	printf("cleanblkhd %08x, dirtyblkhd %08x, numoutput %d, type %d\n",
! 	    vp->v_cleanblkhd, vp->v_dirtyblkhd, vp->v_numoutput, vp->v_type);
! 	printf("union %08x, tag %d, data[0] %08x, data[1] %08x\n",
! 	    vp->v_socket, vp->v_tag, vp->v_data[0], vp->v_data[1]);
  #endif
  	error = VOP_CLOSE(pmp->pm_devvp,
  	    pmp->pm_flags & MSDOSFSMNT_RONLY ? FREAD : FREAD|FWRITE, NOCRED, p);
--- 747,769 ----
  	pmp->pm_devvp->v_specflags &= ~SI_MOUNTEDON;
  #ifdef MSDOSFS_DEBUG
  	printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
! 	printf("flag %08lx, usecount %d, writecount %d, holdcnt %ld\n",
! 	    pmp->pm_devvp->v_flag, pmp->pm_devvp->v_usecount, 
! 	    pmp->pm_devvp->v_writecount, pmp->pm_devvp->v_holdcnt);
! 	printf("lastr %d, id %ld, mount %p, op %p\n",
! 	    pmp->pm_devvp->v_lastr, pmp->pm_devvp->v_id, 
! 	    pmp->pm_devvp->v_mount, pmp->pm_devvp->v_op);
! /*	printf("freef %08x, freeb %08x, mountf %08x, mountb %08x\n",
! 	    pmp->pm_devvp->v_freef, pmp->pm_devvp->v_freeb, 
! 	    pmp->pm_devvp->v_mountf, pmp->pm_devvp->v_mountb); */
! 	printf("cleanblkhd %p, dirtyblkhd %p, numoutput %ld, type %d\n",
! 	    pmp->pm_devvp->v_cleanblkhd.lh_first, 
! 	    pmp->pm_devvp->v_dirtyblkhd.lh_first, 
! 	    pmp->pm_devvp->v_numoutput, pmp->pm_devvp->v_type);
! 	printf("union %p, tag %d, data[0] %08x, data[1] %08x\n",
! 	    pmp->pm_devvp->v_socket, pmp->pm_devvp->v_tag, 
! 	    ((unsigned int*)pmp->pm_devvp->v_data)[0], 
! 	    ((unsigned int*)pmp->pm_devvp->v_data)[1] );
  #endif
  	error = VOP_CLOSE(pmp->pm_devvp,
  	    pmp->pm_flags & MSDOSFSMNT_RONLY ? FREAD : FREAD|FWRITE, NOCRED, p);
***************
*** 778,784 ****
  	int error;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_root(); mp %08x, pmp %08x, ndep %08x, vp %08x\n",
  	    mp, pmp, ndep, DETOV(ndep));
  #endif
  	if ((error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep)) != 0)
--- 785,791 ----
  	int error;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_root(); mp %p, pmp %p, ndep %p, vp %p\n",
  	    mp, pmp, ndep, DETOV(ndep));
  #endif
  	if ((error = deget(pmp, MSDOSFSROOT, MSDOSFSROOT_OFS, &ndep)) != 0)
Index: msdosfs_vnops.c
===================================================================
RCS file: /usr/cvsroot/netbsd/src/sys/msdosfs/msdosfs_vnops.c,v
retrieving revision 1.1.1.4
retrieving revision 1.2
diff -c -r1.1.1.4 -r1.2
*** msdosfs_vnops.c	1997/10/23 03:06:46	1.1.1.4
--- msdosfs_vnops.c	1997/10/30 06:18:09	1.2
***************
*** 116,122 ****
  	struct timespec ts;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_create(cnp %08x, vap %08x\n", cnp, ap->a_vap);
  #endif
  
  	/*
--- 116,122 ----
  	struct timespec ts;
  
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_create(cnp %p, vap %p\n", cnp, ap->a_vap);
  #endif
  
  	/*
***************
*** 338,344 ****
  	struct ucred *cred = ap->a_cred;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_setattr(): vp %08x, vap %08x, cred %08x, p %08x\n",
  	    ap->a_vp, vap, cred, ap->a_p);
  #endif
  	if ((vap->va_type != VNON) || (vap->va_nlink != (nlink_t)VNOVAL) ||
--- 338,344 ----
  	struct ucred *cred = ap->a_cred;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_setattr(): vp %p, vap %p, cred %p, p %p\n",
  	    ap->a_vp, vap, cred, ap->a_p);
  #endif
  	if ((vap->va_type != VNON) || (vap->va_nlink != (nlink_t)VNOVAL) ||
***************
*** 348,356 ****
  	    (vap->va_uid != VNOVAL) || (vap->va_gid != VNOVAL)) {
  #ifdef MSDOSFS_DEBUG
  		printf("msdosfs_setattr(): returning EINVAL\n");
! 		printf("    va_type %d, va_nlink %x, va_fsid %x, va_fileid %x\n",
  		    vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
! 		printf("    va_blocksize %x, va_rdev %x, va_bytes %x, va_gen %x\n",
  		    vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen);
  		printf("    va_uid %x, va_gid %x\n",
  		    vap->va_uid, vap->va_gid);
--- 348,356 ----
  	    (vap->va_uid != VNOVAL) || (vap->va_gid != VNOVAL)) {
  #ifdef MSDOSFS_DEBUG
  		printf("msdosfs_setattr(): returning EINVAL\n");
! 		printf("    va_type %d, va_nlink %x, va_fsid %lx, va_fileid %lx\n",
  		    vap->va_type, vap->va_nlink, vap->va_fsid, vap->va_fileid);
! 		printf("    va_blocksize %lx, va_rdev %x, va_bytes %qx, va_gen %lx\n",
  		    vap->va_blocksize, vap->va_rdev, vap->va_bytes, vap->va_gen);
  		printf("    va_uid %x, va_gid %x\n",
  		    vap->va_uid, vap->va_gid);
***************
*** 525,533 ****
  	struct ucred *cred = ap->a_cred;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_write(vp %08x, uio %08x, ioflag %08x, cred %08x\n",
  	    vp, uio, ioflag, cred);
! 	printf("msdosfs_write(): diroff %d, dirclust %d, startcluster %d\n",
  	    dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
  #endif
  
--- 525,533 ----
  	struct ucred *cred = ap->a_cred;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_write(vp %p, uio %p, ioflag %08x, cred %p\n",
  	    vp, uio, ioflag, cred);
! 	printf("msdosfs_write(): diroff %ld, dirclust %ld, startcluster %ld\n",
  	    dep->de_diroffset, dep->de_dirclust, dep->de_StartCluster);
  #endif
  
***************
*** 787,793 ****
  	else
  		error = removede(ddep, dep);
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_remove(), dep %08x, v_usecount %d\n", dep, ap->a_vp->v_usecount);
  #endif
  	if (ddep == dep)
  		vrele(ap->a_vp);
--- 787,793 ----
  	else
  		error = removede(ddep, dep);
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_remove(), dep %p, v_usecount %d\n", dep, ap->a_vp->v_usecount);
  #endif
  	if (ddep == dep)
  		vrele(ap->a_vp);
***************
*** 1444,1450 ****
  	int chksum = -1;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_readdir(): vp %08x, uio %08x, cred %08x, eofflagp %08x\n",
  	    ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
  #endif
  
--- 1444,1450 ----
  	int chksum = -1;
  	
  #ifdef MSDOSFS_DEBUG
! 	printf("msdosfs_readdir(): vp %p, uio %p, cred %p, eofflagp %p\n",
  	    ap->a_vp, uio, ap->a_cred, ap->a_eofflag);
  #endif


>Audit-Trail:
>Unformatted:


>Last-Modified:

=========================================================================
Rick Byers                                      Internet Access Worldwide
rickb@iaw.on.ca                                		     System Admin
University of Waterloo, Computer Science                    (905)714-1400
http://www.iaw.on.ca/rickb/                         http://www.iaw.on.ca/