Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/fsck_msdos Recognize "dirty" signature on FAT as set by...
details: https://anonhg.NetBSD.org/src/rev/f0d2739b9056
branches: trunk
changeset: 485355:f0d2739b9056
user: jdolecek <jdolecek%NetBSD.org@localhost>
date: Tue Apr 25 23:02:51 2000 +0000
description:
Recognize "dirty" signature on FAT as set by Windows 95 OSR2+ and don't report
it just as "odd byte sequence". Handle the dirty flag similar way
it's treated on e.g. FFS - e.g. clear it separately from rest of FAT.
Changing of FAT is now postponed until after all checks are done,
check.c:checkfilesys() was cleaned considerably and several messages
has been adjusted to be more accurate.
If file system was modified and no error has occured, just return 0
instead of 4 - there is no need for forcing a reboot in this case.
This addresses bin/5638 by Christos Zoulas.
diffstat:
sbin/fsck_msdos/check.c | 121 ++++++++++++++-----------------
sbin/fsck_msdos/dir.c | 19 +----
sbin/fsck_msdos/ext.h | 6 +-
sbin/fsck_msdos/fat.c | 182 +++++++++++++++++++++++++++++++++--------------
4 files changed, 189 insertions(+), 139 deletions(-)
diffs (truncated from 498 to 300 lines):
diff -r 588c322c92ad -r f0d2739b9056 sbin/fsck_msdos/check.c
--- a/sbin/fsck_msdos/check.c Tue Apr 25 22:52:03 2000 +0000
+++ b/sbin/fsck_msdos/check.c Tue Apr 25 23:02:51 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: check.c,v 1.9 1998/08/25 19:18:15 ross Exp $ */
+/* $NetBSD: check.c,v 1.10 2000/04/25 23:02:51 jdolecek Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: check.c,v 1.9 1998/08/25 19:18:15 ross Exp $");
+__RCSID("$NetBSD: check.c,v 1.10 2000/04/25 23:02:51 jdolecek Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -55,8 +55,9 @@
int dosfs;
struct bootblock boot;
struct fatEntry *fat = NULL;
- int i;
+ int i, finish_dosdirsection=0;
int mod = 0;
+ int ret = 8;
rdonly = alwaysno;
if (!preen)
@@ -102,85 +103,52 @@
mod |= readfat(dosfs, &boot, i, ¤tFat);
- if (mod & FSFATAL) {
- free(fat);
- close(dosfs);
- return 8;
- }
+ if (mod & FSFATAL)
+ goto out;
mod |= comparefat(&boot, fat, currentFat, i);
free(currentFat);
- if (mod & FSFATAL) {
- free(fat);
- close(dosfs);
- return 8;
- }
+ if (mod & FSFATAL)
+ goto out;
}
if (!preen)
printf("** Phase 2 - Check Cluster Chains\n");
mod |= checkfat(&boot, fat);
- if (mod & FSFATAL) {
- free(fat);
- close(dosfs);
- return 8;
- }
-
- if (mod & FSFATMOD)
- mod |= writefat(dosfs, &boot, fat); /* delay writing fats? XXX */
- if (mod & FSFATAL) {
- free(fat);
- close(dosfs);
- return 8;
- }
+ if (mod & FSFATAL)
+ goto out;
+ /* delay writing FATs */
if (!preen)
printf("** Phase 3 - Checking Directories\n");
mod |= resetDosDirSection(&boot, fat);
- if (mod & FSFATAL) {
- free(fat);
- close(dosfs);
- return 8;
- }
-
- if (mod & FSFATMOD)
- mod |= writefat(dosfs, &boot, fat); /* delay writing fats? XXX */
- if (mod & FSFATAL) {
- finishDosDirSection();
- free(fat);
- close(dosfs);
- return 8;
- }
+ finish_dosdirsection = 1;
+ if (mod & FSFATAL)
+ goto out;
+ /* delay writing FATs */
mod |= handleDirTree(dosfs, &boot, fat);
- if (mod & FSFATAL) {
- finishDosDirSection();
- free(fat);
- close(dosfs);
- return 8;
- }
+ if (mod & FSFATAL)
+ goto out;
if (!preen)
printf("** Phase 4 - Checking for Lost Files\n");
mod |= checklost(dosfs, &boot, fat);
- if (mod & FSFATAL) {
- finishDosDirSection();
- free(fat);
- close(dosfs);
- return 8;
- }
+ if (mod & FSFATAL)
+ goto out;
- if (mod & FSFATMOD)
- mod |= writefat(dosfs, &boot, fat); /* delay writing fats? XXX */
-
- finishDosDirSection();
- free(fat);
- close(dosfs);
- if (mod & FSFATAL)
- return 8;
+ /* now write the FATs */
+ if (mod & FSFATMOD) {
+ if (ask(1, "Update FATs")) {
+ mod |= writefat(dosfs, &boot, fat, mod & FSFIXFAT);
+ if (mod & FSFATAL)
+ goto out;
+ } else
+ mod |= FSERROR;
+ }
if (boot.NumBad)
pwarn("%d files, %d free (%d clusters), %d bad (%d clusters)\n",
@@ -192,11 +160,34 @@
boot.NumFiles,
boot.NumFree * boot.ClusterSize / 1024, boot.NumFree);
+ if (mod && (mod & FSERROR) == 0) {
+ if (mod & FSDIRTY) {
+ if (ask(1, "MARK FILE SYSTEM CLEAN") == 0)
+ mod &= ~FSDIRTY;
+
+ if (mod & FSDIRTY) {
+ pwarn("MARKING FILE SYSTEM CLEAN\n");
+ mod |= writefat(dosfs, &boot, fat, 1);
+ } else {
+ pwarn("\n***** FILE SYSTEM IS LEFT MARKED AS DIRTY *****\n");
+ mod |= FSERROR; /* file system not clean */
+ }
+ }
+ }
+
if (mod & (FSFATAL | FSERROR))
- return 8;
- if (mod) {
+ goto out;
+
+ ret = 0;
+
+ out:
+ if (finish_dosdirsection)
+ finishDosDirSection();
+ free(fat);
+ close(dosfs);
+
+ if (mod & (FSFATMOD|FSDIRMOD))
pwarn("\n***** FILE SYSTEM WAS MODIFIED *****\n");
- return 4;
- }
- return 0;
+
+ return ret;
}
diff -r 588c322c92ad -r f0d2739b9056 sbin/fsck_msdos/dir.c
--- a/sbin/fsck_msdos/dir.c Tue Apr 25 22:52:03 2000 +0000
+++ b/sbin/fsck_msdos/dir.c Tue Apr 25 23:02:51 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: dir.c,v 1.14 1998/08/25 19:18:15 ross Exp $ */
+/* $NetBSD: dir.c,v 1.15 2000/04/25 23:02:51 jdolecek Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -37,7 +37,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: dir.c,v 1.14 1998/08/25 19:18:15 ross Exp $");
+__RCSID("$NetBSD: dir.c,v 1.15 2000/04/25 23:02:51 jdolecek Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -890,14 +890,6 @@
if (mod & FSFATAL)
return FSFATAL;
- if (mod & FSFATMOD) {
- mod &= ~FSFATMOD;
- mod |= writefat(dosfs, boot, fat); /* delay writing fats? XXX */
- }
-
- if (mod & FSFATAL)
- return FSFATAL;
-
/*
* process the directory todo list
*/
@@ -918,13 +910,8 @@
mod |= readDosDirSection(dosfs, boot, fat, dir);
if (mod & FSFATAL)
return FSFATAL;
- if (mod & FSFATMOD) {
- mod &= ~FSFATMOD;
- mod |= writefat(dosfs, boot, fat); /* delay writing fats? XXX */
- }
- if (mod & FSFATAL)
- return FSFATAL;
}
+
return mod;
}
diff -r 588c322c92ad -r f0d2739b9056 sbin/fsck_msdos/ext.h
--- a/sbin/fsck_msdos/ext.h Tue Apr 25 22:52:03 2000 +0000
+++ b/sbin/fsck_msdos/ext.h Tue Apr 25 23:02:51 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ext.h,v 1.5 1997/10/17 11:19:48 ws Exp $ */
+/* $NetBSD: ext.h,v 1.6 2000/04/25 23:02:51 jdolecek Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -72,6 +72,8 @@
#define FSFATMOD 4 /* The FAT was modified */
#define FSERROR 8 /* Some unrecovered error remains */
#define FSFATAL 16 /* Some unrecoverable error occured */
+#define FSDIRTY 32 /* File system is dirty */
+#define FSFIXFAT 64 /* Fix file system FAT */
/*
* read a boot block in a machine independend fashion and translate
@@ -104,7 +106,7 @@
/*
* Write back FAT entries
*/
-int writefat __P((int, struct bootblock *, struct fatEntry *));
+int writefat __P((int, struct bootblock *, struct fatEntry *, int));
/*
* Read a directory
diff -r 588c322c92ad -r f0d2739b9056 sbin/fsck_msdos/fat.c
--- a/sbin/fsck_msdos/fat.c Tue Apr 25 22:52:03 2000 +0000
+++ b/sbin/fsck_msdos/fat.c Tue Apr 25 23:02:51 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fat.c,v 1.9 1998/01/22 18:48:44 ws Exp $ */
+/* $NetBSD: fat.c,v 1.10 2000/04/25 23:02:51 jdolecek Exp $ */
/*
* Copyright (C) 1995, 1996, 1997 Wolfgang Solfrank
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: fat.c,v 1.9 1998/01/22 18:48:44 ws Exp $");
+__RCSID("$NetBSD: fat.c,v 1.10 2000/04/25 23:02:51 jdolecek Exp $");
#endif /* not lint */
#include <stdlib.h>
@@ -87,6 +87,45 @@
}
/*
+ * Read a FAT from disk. Returns 1 if successful, 0 otherwise.
+ */
+int
+_readfat(fs, boot, no, buffer)
+ int fs;
+ struct bootblock *boot;
+ int no;
+ u_char **buffer;
+{
+ off_t off;
+
+ *buffer = malloc(boot->FATsecs * boot->BytesPerSec);
+ if (*buffer == NULL) {
+ perror("No space for FAT");
+ return 0;
+ }
+
+ off = boot->ResSectors + no * boot->FATsecs;
+ off *= boot->BytesPerSec;
+
+ if (lseek(fs, off, SEEK_SET) != off) {
+ perror("Unable to read FAT");
+ goto err;
+ }
Home |
Main Index |
Thread Index |
Old Index