svn commit: r204414 - stable/8/sys/fs/msdosfs

Konstantin Belousov kib at FreeBSD.org
Sat Feb 27 16:51:23 UTC 2010


Author: kib
Date: Sat Feb 27 16:51:23 2010
New Revision: 204414
URL: http://svn.freebsd.org/changeset/base/204414

Log:
  MFC r203827:
  - Add idempotency guards so the structures can be used in other utilities.
  - Update bpb structs with reserved fields.
  - In direntry struct join deName with deExtension. Although a
    fix was attempted in the past, these fields were being overflowed,
    Now this is consistent with the spec, and we can now share the
    WinChksum code with NetBSD.

Modified:
  stable/8/sys/fs/msdosfs/bootsect.h
  stable/8/sys/fs/msdosfs/bpb.h
  stable/8/sys/fs/msdosfs/direntry.h
  stable/8/sys/fs/msdosfs/msdosfs_conv.c
  stable/8/sys/fs/msdosfs/msdosfs_lookup.c
  stable/8/sys/fs/msdosfs/msdosfs_vnops.c
Directory Properties:
  stable/8/sys/   (props changed)
  stable/8/sys/amd64/include/xen/   (props changed)
  stable/8/sys/cddl/contrib/opensolaris/   (props changed)
  stable/8/sys/contrib/dev/acpica/   (props changed)
  stable/8/sys/contrib/pf/   (props changed)
  stable/8/sys/dev/xen/xenpci/   (props changed)
  stable/8/sys/netinet/   (props changed)

Modified: stable/8/sys/fs/msdosfs/bootsect.h
==============================================================================
--- stable/8/sys/fs/msdosfs/bootsect.h	Sat Feb 27 15:32:49 2010	(r204413)
+++ stable/8/sys/fs/msdosfs/bootsect.h	Sat Feb 27 16:51:23 2010	(r204414)
@@ -16,6 +16,8 @@
  *
  * October 1992
  */
+#ifndef _FS_MSDOSFS_BOOTSECT_H_
+#define	_FS_MSDOSFS_BOOTSECT_H_
 
 /*
  * Format of a boot sector.  This is the first sector on a DOS floppy disk
@@ -91,3 +93,5 @@ union bootsector {
 #define	bsHiddenSecs	bsBPB.bpbHiddenSecs
 #define	bsHugeSectors	bsBPB.bpbHugeSectors
 #endif
+
+#endif /* !_FS_MSDOSFS_BOOTSECT_H_ */

Modified: stable/8/sys/fs/msdosfs/bpb.h
==============================================================================
--- stable/8/sys/fs/msdosfs/bpb.h	Sat Feb 27 15:32:49 2010	(r204413)
+++ stable/8/sys/fs/msdosfs/bpb.h	Sat Feb 27 16:51:23 2010	(r204414)
@@ -17,6 +17,9 @@
  * October 1992
  */
 
+#ifndef _FS_MSDOSFS_BPB_H_
+#define	_FS_MSDOSFS_BPB_H_
+
 /*
  * BIOS Parameter Block (BPB) for DOS 3.3
  */
@@ -78,7 +81,7 @@ struct bpb710 {
 	u_int32_t	bpbRootClust;	/* start cluster for root directory */
 	u_int16_t	bpbFSInfo;	/* filesystem info structure sector */
 	u_int16_t	bpbBackup;	/* backup boot sector */
-	/* There is a 12 byte filler here, but we ignore it */
+	u_int8_t	bpbReserved[12]; /* reserved for future expansion */
 };
 
 /*
@@ -153,7 +156,7 @@ struct byte_bpb710 {
 	u_int8_t bpbRootClust[4];	/* start cluster for root directory */
 	u_int8_t bpbFSInfo[2];		/* filesystem info structure sector */
 	u_int8_t bpbBackup[2];		/* backup boot sector */
-	/* There is a 12 byte filler here, but we ignore it */
+	u_int8_t bpbReserved[12];	/* reserved for future expansion */
 };
 
 /*
@@ -168,3 +171,4 @@ struct fsinfo {
 	u_int8_t fsifill2[12];
 	u_int8_t fsisig3[4];
 };
+#endif /* !_FS_MSDOSFS_BPB_H_ */

Modified: stable/8/sys/fs/msdosfs/direntry.h
==============================================================================
--- stable/8/sys/fs/msdosfs/direntry.h	Sat Feb 27 15:32:49 2010	(r204413)
+++ stable/8/sys/fs/msdosfs/direntry.h	Sat Feb 27 16:51:23 2010	(r204414)
@@ -47,16 +47,17 @@
  *
  * October 1992
  */
+#ifndef _FS_MSDOSFS_DIRENTRY_H_
+#define	_FS_MSDOSFS_DIRENTRY_H_
 
 /*
  * Structure of a dos directory entry.
  */
 struct direntry {
-	u_int8_t	deName[8];	/* filename, blank filled */
+	u_int8_t	deName[11];	/* filename, blank filled */
 #define	SLOT_EMPTY	0x00		/* slot has never been used */
 #define	SLOT_E5		0x05		/* the real value is 0xe5 */
 #define	SLOT_DELETED	0xe5		/* file in this slot deleted */
-	u_int8_t	deExtension[3];	/* extension, blank filled */
 	u_int8_t	deAttributes;	/* file attributes */
 #define	ATTR_NORMAL	0x00		/* normal file */
 #define	ATTR_READONLY	0x01		/* file is readonly */
@@ -155,7 +156,8 @@ int	winChkName(struct mbnambuf *nbp, con
 	    int chksum, struct msdosfsmount *pmp);
 int	win2unixfn(struct mbnambuf *nbp, struct winentry *wep, int chksum,
 	    struct msdosfsmount *pmp);
-u_int8_t winChksum(struct direntry *dep);
+u_int8_t winChksum(u_int8_t *name);
 int	winSlotCnt(const u_char *un, size_t unlen, struct msdosfsmount *pmp);
 size_t	winLenFixup(const u_char *un, size_t unlen);
 #endif	/* _KERNEL */
+#endif	/* !_FS_MSDOSFS_DIRENTRY_H_ */

Modified: stable/8/sys/fs/msdosfs/msdosfs_conv.c
==============================================================================
--- stable/8/sys/fs/msdosfs/msdosfs_conv.c	Sat Feb 27 15:32:49 2010	(r204413)
+++ stable/8/sys/fs/msdosfs/msdosfs_conv.c	Sat Feb 27 16:51:23 2010	(r204414)
@@ -741,22 +741,13 @@ win2unixfn(nbp, wep, chksum, pmp)
  * Compute the unrolled checksum of a DOS filename for Win95 LFN use.
  */
 u_int8_t
-winChksum(struct direntry *dep)
+winChksum(u_int8_t *name)
 {
+	int i;
 	u_int8_t s;
 
-	s = dep->deName[0];
-	s = ((s << 7) | (s >> 1)) + dep->deName[1];
-	s = ((s << 7) | (s >> 1)) + dep->deName[2];
-	s = ((s << 7) | (s >> 1)) + dep->deName[3];
-	s = ((s << 7) | (s >> 1)) + dep->deName[4];
-	s = ((s << 7) | (s >> 1)) + dep->deName[5];
-	s = ((s << 7) | (s >> 1)) + dep->deName[6];
-	s = ((s << 7) | (s >> 1)) + dep->deName[7];
-	s = ((s << 7) | (s >> 1)) + dep->deExtension[0];
-	s = ((s << 7) | (s >> 1)) + dep->deExtension[1];
-	s = ((s << 7) | (s >> 1)) + dep->deExtension[2];
-
+	for (s = 0, i = 11; --i >= 0; s += *name++)
+		s = (s << 7)|(s >> 1);
 	return (s);
 }
 

Modified: stable/8/sys/fs/msdosfs/msdosfs_lookup.c
==============================================================================
--- stable/8/sys/fs/msdosfs/msdosfs_lookup.c	Sat Feb 27 15:32:49 2010	(r204413)
+++ stable/8/sys/fs/msdosfs/msdosfs_lookup.c	Sat Feb 27 16:51:23 2010	(r204414)
@@ -276,7 +276,7 @@ msdosfs_lookup(ap)
 				/*
 				 * Check for a checksum or name match
 				 */
-				chksum_ok = (chksum == winChksum(dep));
+				chksum_ok = (chksum == winChksum(dep->deName));
 				if (!chksum_ok
 				    && (!olddos || bcmp(dosfilename, dep->deName, 11))) {
 					chksum = -1;
@@ -617,7 +617,7 @@ createde(dep, ddep, depp, cnp)
 	 * Now write the Win95 long name
 	 */
 	if (ddep->de_fndcnt > 0) {
-		u_int8_t chksum = winChksum(ndep);
+		u_int8_t chksum = winChksum(ndep->deName);
 		const u_char *un = (const u_char *)cnp->cn_nameptr;
 		int unlen = cnp->cn_namelen;
 		int cnt = 1;

Modified: stable/8/sys/fs/msdosfs/msdosfs_vnops.c
==============================================================================
--- stable/8/sys/fs/msdosfs/msdosfs_vnops.c	Sat Feb 27 15:32:49 2010	(r204413)
+++ stable/8/sys/fs/msdosfs/msdosfs_vnops.c	Sat Feb 27 16:51:23 2010	(r204414)
@@ -1287,7 +1287,7 @@ static struct {
 	struct direntry dot;
 	struct direntry dotdot;
 } dosdirtemplate = {
-	{	".       ", "   ",			/* the . entry */
+	{	".          ",				/* the . entry */
 		ATTR_DIRECTORY,				/* file attribute */
 		0,					/* reserved */
 		0, { 0, 0 }, { 0, 0 },			/* create time & date */
@@ -1297,7 +1297,7 @@ static struct {
 		{ 0, 0 },				/* startcluster */
 		{ 0, 0, 0, 0 }				/* filesize */
 	},
-	{	"..      ", "   ",			/* the .. entry */
+	{	"..         ",				/* the .. entry */
 		ATTR_DIRECTORY,				/* file attribute */
 		0,					/* reserved */
 		0, { 0, 0 }, { 0, 0 },			/* create time & date */
@@ -1729,7 +1729,7 @@ msdosfs_readdir(ap)
 			} else
 				dirbuf.d_fileno = (uint32_t)fileno;
 
-			if (chksum != winChksum(dentp)) {
+			if (chksum != winChksum(dentp->deName)) {
 				dirbuf.d_namlen = dos2unixfn(dentp->deName,
 				    (u_char *)dirbuf.d_name,
 				    dentp->deLowerCase |


More information about the svn-src-all mailing list