diff options
author | bde <bde@FreeBSD.org> | 2004-02-05 06:32:16 +0000 |
---|---|---|
committer | bde <bde@FreeBSD.org> | 2004-02-05 06:32:16 +0000 |
commit | 12c02b35e97ff2d4f5bf34a44e06193b4315e534 (patch) | |
tree | 9008ab2913063932f40be7efb7bb3092cae7d6a8 /sbin/fsck_msdosfs/fat.c | |
parent | c03701303f41816c9200f9b8e4a89b06f6a94112 (diff) | |
download | FreeBSD-src-12c02b35e97ff2d4f5bf34a44e06193b4315e534.zip FreeBSD-src-12c02b35e97ff2d4f5bf34a44e06193b4315e534.tar.gz |
Prepare to fix checkdirty() by moving it from check.c to fat.c. It is
identical to a subset of readfat(), so it belongs near readfat() if not
in it.
Diffstat (limited to 'sbin/fsck_msdosfs/fat.c')
-rw-r--r-- | sbin/fsck_msdosfs/fat.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/sbin/fsck_msdosfs/fat.c b/sbin/fsck_msdosfs/fat.c index 9e0aef9..d04661a 100644 --- a/sbin/fsck_msdosfs/fat.c +++ b/sbin/fsck_msdosfs/fat.c @@ -52,6 +52,49 @@ static int clustdiffer(cl_t, cl_t *, cl_t *, int); static int tryclear(struct bootblock *, struct fatEntry *, cl_t, cl_t *); static int _readfat(int, struct bootblock *, int, u_char **); +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; +} + /* * Check a cluster number for valid value */ |