From d0381ad1b0ae87e6cf4ff7e79e47131563ccf0bf Mon Sep 17 00:00:00 2001 From: pfg Date: Thu, 17 Jul 2014 02:43:53 +0000 Subject: [PATCH] MFC r268628, r268631, r268635: Convert *rootDir from external to static. fsck_msdosfs: be a bit more permissive. The free space value in the FSInfo block is merely unitialized when it is 0xffffffff. This fixes a bug found in NetBSD. Respect FSFIXFAT. Fix some whitespace issues while here. Obtained from: NetBSD (CVS rev. 1.22, rev. 1.9), OpenBSD (misc) git-svn-id: svn://svn.freebsd.org/base/stable/9@268785 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- sbin/fsck_msdosfs/check.c | 2 +- sbin/fsck_msdosfs/dir.c | 2 +- sbin/fsck_msdosfs/ext.h | 8 +++----- sbin/fsck_msdosfs/fat.c | 11 ++++++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/sbin/fsck_msdosfs/check.c b/sbin/fsck_msdosfs/check.c index 96ebdc528..bad612158 100644 --- a/sbin/fsck_msdosfs/check.c +++ b/sbin/fsck_msdosfs/check.c @@ -142,7 +142,7 @@ checkfilesys(const char *fname) goto out; /* now write the FATs */ - if (mod & FSFATMOD) { + if (mod & (FSFATMOD|FSFIXFAT)) { if (ask(1, "Update FATs")) { mod |= writefat(dosfs, &boot, fat, mod & FSFIXFAT); if (mod & FSFATAL) diff --git a/sbin/fsck_msdosfs/dir.c b/sbin/fsck_msdosfs/dir.c index f2ecff351..2783779e7 100644 --- a/sbin/fsck_msdosfs/dir.c +++ b/sbin/fsck_msdosfs/dir.c @@ -206,7 +206,7 @@ static char longName[DOSLONGNAMELEN] = ""; static u_char *buffer = NULL; static u_char *delbuf = NULL; -struct dosDirEntry *rootDir; +static struct dosDirEntry *rootDir; static struct dosDirEntry *lostDir; /* diff --git a/sbin/fsck_msdosfs/ext.h b/sbin/fsck_msdosfs/ext.h index a4fd19b8c..c729acaec 100644 --- a/sbin/fsck_msdosfs/ext.h +++ b/sbin/fsck_msdosfs/ext.h @@ -26,7 +26,7 @@ */ #ifndef EXT_H -#define EXT_H +#define EXT_H #include @@ -43,8 +43,6 @@ extern int preen; /* we are preening */ extern int rdonly; /* device is opened read only (supersedes above) */ extern int skipclean; /* skip clean file systems if preening */ -extern struct dosDirEntry *rootDir; - /* * function declarations */ @@ -71,8 +69,8 @@ int checkfilesys(const char *); #define FSFATMOD 4 /* The FAT was modified */ #define FSERROR 8 /* Some unrecovered error remains */ #define FSFATAL 16 /* Some unrecoverable error occurred */ -#define FSDIRTY 32 /* File system is dirty */ -#define FSFIXFAT 64 /* Fix file system FAT */ +#define FSDIRTY 32 /* File system is dirty */ +#define FSFIXFAT 64 /* Fix file system FAT */ /* * read a boot block in a machine independent fashion and translate diff --git a/sbin/fsck_msdosfs/fat.c b/sbin/fsck_msdosfs/fat.c index 7a6368c02..b345883c5 100644 --- a/sbin/fsck_msdosfs/fat.c +++ b/sbin/fsck_msdosfs/fat.c @@ -240,7 +240,7 @@ readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp) ret |= FSDIRTY; else { /* just some odd byte sequence in FAT */ - + switch (boot->ClustMask) { case CLUST32_MASK: pwarn("%s (%02x%02x%02x%02x%02x%02x%02x%02x)\n", @@ -260,7 +260,7 @@ readfat(int fs, struct bootblock *boot, u_int no, struct fatEntry **fp) break; } - + if (ask(1, "Correct")) ret |= FSFIXFAT; } @@ -651,7 +651,7 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) cl_t head; int mod = FSOK; int ret; - + for (head = CLUST_FIRST; head < boot->NumClusters; head++) { /* find next untravelled chain */ if (fat[head].head != head @@ -675,8 +675,9 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat) if (boot->bpbFSInfo) { ret = 0; - if (boot->FSFree != boot->NumFree) { - pwarn("Free space in FSInfo block (%d) not correct (%d)\n", + if (boot->FSFree != 0xffffffffU && + boot->FSFree != boot->NumFree) { + pwarn("Free space in FSInfo block (%u) not correct (%u)\n", boot->FSFree, boot->NumFree); if (ask(1, "Fix")) { boot->FSFree = boot->NumFree; -- 2.45.0