summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSan Mehat <san@google.com>2009-07-16 09:26:05 -0700
committerSan Mehat <san@google.com>2009-07-16 09:34:08 -0700
commit11877c86e96c485b9632ea758b225bcacf6e7670 (patch)
treec0537c7f7fe610b8d724bed1fb3d75e58d09c55f
parenta3833718636c6bdcdf0bef2674e864e948e81d27 (diff)
downloadandroid_external_fsck_msdos-11877c86e96c485b9632ea758b225bcacf6e7670.tar.gz
android_external_fsck_msdos-11877c86e96c485b9632ea758b225bcacf6e7670.tar.bz2
android_external_fsck_msdos-11877c86e96c485b9632ea758b225bcacf6e7670.zip
fsck_msdos: Instead of bailing out when we can't reconnect a lost cluster chain, clear it.
Also, use exit code 4 when the FS has been modified in someway. Signed-off-by: San Mehat <san@google.com>
-rw-r--r--check.c25
-rw-r--r--fat.c10
2 files changed, 27 insertions, 8 deletions
diff --git a/check.c b/check.c
index f6a95a0..e4a8dfa 100644
--- a/check.c
+++ b/check.c
@@ -112,6 +112,7 @@ checkfilesys(const char *fname)
mod |= readfat(dosfs, &boot, boot.ValidFat >= 0 ? boot.ValidFat : 0, &fat);
if (mod & FSFATAL) {
+ printf("Fatal error during readfat()\n");
close(dosfs);
return 8;
}
@@ -122,21 +123,27 @@ checkfilesys(const char *fname)
mod |= readfat(dosfs, &boot, i, &currentFat);
- if (mod & FSFATAL)
+ if (mod & FSFATAL) {
+ printf("Fatal error during readfat() for comparison\n");
goto out;
+ }
mod |= comparefat(&boot, fat, currentFat, i);
free(currentFat);
- if (mod & FSFATAL)
+ if (mod & FSFATAL) {
+ printf("Fatal error during FAT comparison\n");
goto out;
+ }
}
if (!quiet)
printf("** Phase 2 - Check Cluster Chains\n");
mod |= checkfat(&boot, fat);
- if (mod & FSFATAL)
+ if (mod & FSFATAL) {
+ printf("Fatal error during FAT check\n");
goto out;
+ }
/* delay writing FATs */
if (!quiet)
@@ -144,8 +151,10 @@ checkfilesys(const char *fname)
mod |= resetDosDirSection(&boot, fat);
finish_dosdirsection = 1;
- if (mod & FSFATAL)
+ if (mod & FSFATAL) {
+ printf("Fatal error during resetDosDirSection()\n");
goto out;
+ }
/* delay writing FATs */
mod |= handleDirTree(dosfs, &boot, fat);
@@ -163,8 +172,10 @@ checkfilesys(const char *fname)
if (mod & FSFATMOD) {
if (ask(1, "Update FATs")) {
mod |= writefat(dosfs, &boot, fat, mod & FSFIXFAT);
- if (mod & FSFATAL)
+ if (mod & FSFATAL) {
+ printf("Fatal error during writefat()\n");
goto out;
+ }
} else
mod |= FSERROR;
}
@@ -205,8 +216,10 @@ checkfilesys(const char *fname)
free(fat);
close(dosfs);
- if (mod & (FSFATMOD|FSDIRMOD))
+ if (mod & (FSFATMOD|FSDIRMOD)) {
pwarn("\n***** FILE SYSTEM WAS MODIFIED *****\n");
+ return 4;
+ }
return ret;
}
diff --git a/fat.c b/fat.c
index 3411196..8871407 100644
--- a/fat.c
+++ b/fat.c
@@ -667,8 +667,14 @@ checklost(int dosfs, struct bootblock *boot, struct fatEntry *fat)
pwarn("Lost cluster chain at cluster %u\n%d Cluster(s) lost\n",
head, fat[head].length);
mod |= ret = reconnect(dosfs, boot, fat, head);
- if (mod & FSFATAL)
- break;
+ if (mod & FSFATAL) {
+ /* If the reconnect failed, then just clear the chain */
+ pwarn("Error reconnecting chain - clearing\n");
+ mod &= ~FSFATAL;
+ clearchain(boot, fat, head);
+ mod |= FSFATMOD;
+ continue;
+ }
if (ret == FSERROR && ask(1, "Clear")) {
clearchain(boot, fat, head);
mod |= FSFATMOD;