Changeset View
Changeset View
Standalone View
Standalone View
sbin/fsck_msdosfs/check.c
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | |||||
#include "ext.h" | #include "ext.h" | ||||
#include "fsutil.h" | #include "fsutil.h" | ||||
int | int | ||||
checkfilesys(const char *fname) | checkfilesys(const char *fname) | ||||
{ | { | ||||
int dosfs; | int dosfs; | ||||
struct bootblock boot; | struct bootblock boot; | ||||
struct fatEntry *fat = NULL; | struct fat_descriptor *fat = NULL; | ||||
int finish_dosdirsection=0; | int finish_dosdirsection=0; | ||||
u_int i; | |||||
int mod = 0; | int mod = 0; | ||||
int ret = 8; | int ret = 8; | ||||
rdonly = alwaysno; | rdonly = alwaysno; | ||||
if (!preen) | if (!preen) | ||||
printf("** %s", fname); | printf("** %s", fname); | ||||
dosfs = open(fname, rdonly ? O_RDONLY : O_RDWR, 0); | dosfs = open(fname, rdonly ? O_RDONLY : O_RDWR, 0); | ||||
Show All 22 Lines | checkfilesys(const char *fname) | ||||
if (skipclean && preen && checkdirty(dosfs, &boot)) { | if (skipclean && preen && checkdirty(dosfs, &boot)) { | ||||
printf("%s: ", fname); | printf("%s: ", fname); | ||||
printf("FILESYSTEM CLEAN; SKIPPING CHECKS\n"); | printf("FILESYSTEM CLEAN; SKIPPING CHECKS\n"); | ||||
ret = 0; | ret = 0; | ||||
goto out; | goto out; | ||||
} | } | ||||
if (!preen) { | if (!preen) { | ||||
if (boot.ValidFat < 0) | |||||
printf("** Phase 1 - Read and Compare FATs\n"); | |||||
else | |||||
printf("** Phase 1 - Read FAT\n"); | printf("** Phase 1 - Read FAT\n"); | ||||
} | } | ||||
mod |= readfat(dosfs, &boot, boot.ValidFat >= 0 ? boot.ValidFat : 0, &fat); | mod |= readfat(dosfs, &boot, &fat); | ||||
if (mod & FSFATAL) { | if (mod & FSFATAL) { | ||||
close(dosfs); | close(dosfs); | ||||
return 8; | return 8; | ||||
} | } | ||||
if (boot.ValidFat < 0) | |||||
for (i = 1; i < boot.bpbFATs; i++) { | |||||
struct fatEntry *currentFat; | |||||
mod |= readfat(dosfs, &boot, i, ¤tFat); | |||||
if (mod & FSFATAL) | |||||
goto out; | |||||
mod |= comparefat(&boot, fat, currentFat, i); | |||||
free(currentFat); | |||||
if (mod & FSFATAL) | |||||
goto out; | |||||
} | |||||
if (!preen) | if (!preen) | ||||
printf("** Phase 2 - Check Cluster Chains\n"); | printf("** Phase 2 - Checking Directories\n"); | ||||
mod |= checkfat(&boot, fat); | |||||
if (mod & FSFATAL) | |||||
goto out; | |||||
/* delay writing FATs */ | |||||
if (!preen) | |||||
printf("** Phase 3 - Checking Directories\n"); | |||||
mod |= resetDosDirSection(&boot, fat); | mod |= resetDosDirSection(&boot, fat); | ||||
finish_dosdirsection = 1; | finish_dosdirsection = 1; | ||||
if (mod & FSFATAL) | if (mod & FSFATAL) | ||||
goto out; | goto out; | ||||
/* delay writing FATs */ | /* delay writing FATs */ | ||||
mod |= handleDirTree(dosfs, &boot, fat); | mod |= handleDirTree(dosfs, &boot, fat); | ||||
if (mod & FSFATAL) | if (mod & FSFATAL) | ||||
goto out; | goto out; | ||||
if (!preen) | if (!preen) | ||||
printf("** Phase 4 - Checking for Lost Files\n"); | printf("** Phase 3 - Checking for Lost Files\n"); | ||||
mod |= checklost(dosfs, &boot, fat); | mod |= checklost(dosfs, &boot, fat); | ||||
if (mod & FSFATAL) | if (mod & FSFATAL) | ||||
goto out; | goto out; | ||||
/* now write the FATs */ | /* now write the FATs */ | ||||
if (mod & (FSFATMOD|FSFIXFAT)) { | if (mod & (FSFATMOD|FSFIXFAT)) { | ||||
if (ask(1, "Update FATs")) { | if (ask(1, "Update FATs")) { | ||||
mod |= writefat(dosfs, &boot, fat, mod & FSFIXFAT); | mod |= writefat(dosfs, &boot, fat); | ||||
if (mod & FSFATAL) | if (mod & FSFATAL) | ||||
goto out; | goto out; | ||||
} else | } else | ||||
mod |= FSERROR; | mod |= FSERROR; | ||||
} | } | ||||
if (boot.NumBad) | if (boot.NumBad) | ||||
pwarn("%d files, %d free (%d clusters), %d bad (%d clusters)\n", | pwarn("%d files, %d free (%d clusters), %d bad (%d clusters)\n", | ||||
boot.NumFiles, | boot.NumFiles, | ||||
boot.NumFree * boot.ClusterSize / 1024, boot.NumFree, | boot.NumFree * boot.ClusterSize / 1024, boot.NumFree, | ||||
boot.NumBad * boot.ClusterSize / 1024, boot.NumBad); | boot.NumBad * boot.ClusterSize / 1024, boot.NumBad); | ||||
else | else | ||||
pwarn("%d files, %d free (%d clusters)\n", | pwarn("%d files, %d free (%d clusters)\n", | ||||
boot.NumFiles, | boot.NumFiles, | ||||
boot.NumFree * boot.ClusterSize / 1024, boot.NumFree); | boot.NumFree * boot.ClusterSize / 1024, boot.NumFree); | ||||
if (mod && (mod & FSERROR) == 0) { | if (mod && (mod & FSERROR) == 0) { | ||||
if (mod & FSDIRTY) { | if (mod & FSDIRTY) { | ||||
if (ask(1, "MARK FILE SYSTEM CLEAN") == 0) | if (ask(1, "MARK FILE SYSTEM CLEAN") == 0) | ||||
mod &= ~FSDIRTY; | mod &= ~FSDIRTY; | ||||
if (mod & FSDIRTY) { | if (mod & FSDIRTY) { | ||||
pwarn("MARKING FILE SYSTEM CLEAN\n"); | pwarn("MARKING FILE SYSTEM CLEAN\n"); | ||||
mod |= writefat(dosfs, &boot, fat, 1); | mod |= writefat(dosfs, &boot, fat); | ||||
} else { | } else { | ||||
pwarn("\n***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****\n"); | pwarn("\n***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****\n"); | ||||
mod |= FSERROR; /* file system not clean */ | mod |= FSERROR; /* file system not clean */ | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if (mod & (FSFATAL | FSERROR)) | if (mod & (FSFATAL | FSERROR)) | ||||
Show All 15 Lines |