diff options
author | trhodes <trhodes@FreeBSD.org> | 2003-12-26 17:19:19 +0000 |
---|---|---|
committer | trhodes <trhodes@FreeBSD.org> | 2003-12-26 17:19:19 +0000 |
commit | 7dde93f1df429cf9a818bf7b716962298f489807 (patch) | |
tree | 9835c24a1c804ff149a9d1763c5619fbd69ab703 /sbin/fsck_msdosfs | |
parent | 1b287b69e9efa62bb22618045208556c1edcbff7 (diff) | |
download | FreeBSD-src-7dde93f1df429cf9a818bf7b716962298f489807.zip FreeBSD-src-7dde93f1df429cf9a818bf7b716962298f489807.tar.gz |
Make msdosfs support the dirty flag in FAT16 and FAT32.
Enable lockf support.
PR: 55861
Submitted by: Jun Su <junsu@m-net.arbornet.org> (original version)
Reviewed by: make universe
Diffstat (limited to 'sbin/fsck_msdosfs')
-rw-r--r-- | sbin/fsck_msdosfs/check.c | 52 | ||||
-rw-r--r-- | sbin/fsck_msdosfs/ext.h | 7 | ||||
-rw-r--r-- | sbin/fsck_msdosfs/fsck_msdosfs.8 | 8 | ||||
-rw-r--r-- | sbin/fsck_msdosfs/main.c | 9 |
4 files changed, 66 insertions, 10 deletions
diff --git a/sbin/fsck_msdosfs/check.c b/sbin/fsck_msdosfs/check.c index 28b1588..72e5b0a 100644 --- a/sbin/fsck_msdosfs/check.c +++ b/sbin/fsck_msdosfs/check.c @@ -84,6 +84,13 @@ checkfilesys(const char *fname) return 8; } + if (checkdirty(dosfs, &boot) && !force) { + if (preen) printf("%s: ", fname); + printf("FILESYSTEM CLEAN; SKIPPING CHECKS\n"); + ret = 0; + goto out; + } + if (!preen) { if (boot.ValidFat < 0) printf("** Phase 1 - Read and Compare FATs\n"); @@ -191,3 +198,48 @@ checkfilesys(const char *fname) return ret; } + +int checkdirty(int fs, struct bootblock *boot) +{ + off_t off; + u_char *buffer; + int ret = 0; + + if (boot->ClustMask == CLUST12_MASK) + return 0; + + off = boot->ResSectors; + off *= boot->BytesPerSec; + + buffer = malloc(boot->BytesPerSec); + if (buffer == NULL) { + perror("No space for FAT"); + return 1; + } + + if (lseek(fs, off, SEEK_SET) != off) { + perror("Unable to read FAT"); + goto err; + } + + if (read(fs, buffer, boot->BytesPerSec) + != boot->BytesPerSec) { + perror("Unable to read FAT"); + goto err; + } + + if (buffer[0] == boot->Media && buffer[1] == 0xff + && buffer[2] == 0xff + && ((boot->ClustMask == CLUST16_MASK && buffer[3] == 0x7f) + || (boot->ClustMask == CLUST32_MASK + && buffer[3] == 0x0f && buffer[4] == 0xff + && buffer[5] == 0xff && buffer[6] == 0xff + && buffer[7] == 0x07))) + ret = 0; + else + ret = 1; + +err: + free(buffer); + return ret; +} diff --git a/sbin/fsck_msdosfs/ext.h b/sbin/fsck_msdosfs/ext.h index ce67792..9eb4098 100644 --- a/sbin/fsck_msdosfs/ext.h +++ b/sbin/fsck_msdosfs/ext.h @@ -48,6 +48,7 @@ extern int alwaysno; /* assume "no" for all questions */ extern int alwaysyes; /* assume "yes" for all questions */ extern int preen; /* we are preening */ extern int rdonly; /* device is opened read only (supersedes above) */ +extern int force; extern struct dosDirEntry *rootDir; @@ -85,6 +86,12 @@ int readboot(int, struct bootblock *); int writefsinfo(int, struct bootblock *); /* + * Check the dirty flag. If clean return 1, otherwise return 0. + * If it is FAT12, return 0 always. + */ +int checkdirty(int, struct bootblock *); + +/* * Read one of the FAT copies and return a pointer to the new * allocated array holding our description of it. */ diff --git a/sbin/fsck_msdosfs/fsck_msdosfs.8 b/sbin/fsck_msdosfs/fsck_msdosfs.8 index 7b2985d..d07e53d 100644 --- a/sbin/fsck_msdosfs/fsck_msdosfs.8 +++ b/sbin/fsck_msdosfs/fsck_msdosfs.8 @@ -88,11 +88,9 @@ immediately in foreground, or if its cleaning can be deferred to background. FAT (MS-DOS) file systems must always be cleaned in the foreground. A non-zero exit code is always returned for this option. .It Fl f -This option is ignored by -.Nm , -and is present only for compatibility with programs that -check other file system types for consistency, such as -.Xr fsck_ffs 8 . +Force +.Nm +to check 'clean' file systems when preening. .It Fl n Causes .Nm diff --git a/sbin/fsck_msdosfs/main.c b/sbin/fsck_msdosfs/main.c index cbfe6da..bef877b 100644 --- a/sbin/fsck_msdosfs/main.c +++ b/sbin/fsck_msdosfs/main.c @@ -53,6 +53,7 @@ int alwaysno; /* assume "no" for all questions */ int alwaysyes; /* assume "yes" for all questions */ int preen; /* set when preening */ int rdonly; /* device is opened read only (supersedes above) */ +int force; /* force check even the fs is clean */ static void usage(void) __dead2; @@ -67,14 +68,12 @@ main(int argc, char **argv) { int ret = 0, erg; int ch; - + + force = 0; while ((ch = getopt(argc, argv, "fFnpy")) != -1) { switch (ch) { case 'f': - /* - * We are always forced, since we don't - * have a clean flag - */ + force = 1; break; case 'F': /* We can never run in background */ |