diff options
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 */ |