summaryrefslogtreecommitdiff
path: root/sbin/fsck_msdos
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1997-03-02 05:25:57 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1997-03-02 05:25:57 +0000
commitbfb1a05d6a058148ecda43a30a40a20bbe225220 (patch)
tree762ec7992bd0146643fdddd762b26b738e21c79c /sbin/fsck_msdos
parent559202916340bf0b5dad20520920ee1ee9fc368b (diff)
Update based on latest NetBSD version.
Now uses functions from util.[ch] instead of local ones. Also some anal KNF from me...
Diffstat (limited to 'sbin/fsck_msdos')
-rw-r--r--sbin/fsck_msdos/Makefile8
-rw-r--r--sbin/fsck_msdos/boot.c16
-rw-r--r--sbin/fsck_msdos/check.c42
-rw-r--r--sbin/fsck_msdos/dir.c136
-rw-r--r--sbin/fsck_msdos/ext.h9
-rw-r--r--sbin/fsck_msdos/fat.c70
-rw-r--r--sbin/fsck_msdos/fsck_msdos.859
-rw-r--r--sbin/fsck_msdos/main.c116
8 files changed, 218 insertions, 238 deletions
diff --git a/sbin/fsck_msdos/Makefile b/sbin/fsck_msdos/Makefile
index 81c6fa8c5a3..a04d307c2b8 100644
--- a/sbin/fsck_msdos/Makefile
+++ b/sbin/fsck_msdos/Makefile
@@ -1,8 +1,10 @@
-# $OpenBSD: Makefile,v 1.2 1996/06/23 14:30:40 deraadt Exp $
-# $NetBSD: Makefile,v 1.1 1996/05/14 17:39:26 ws Exp $
+# $OpenBSD: Makefile,v 1.3 1997/03/02 05:25:50 millert Exp $
+# $NetBSD: Makefile,v 1.4 1997/01/03 14:32:47 ws Exp $
PROG= fsck_msdos
MAN= fsck_msdos.8
-SRCS= main.c check.c boot.c fat.c dir.c
+SRCS= main.c check.c boot.c fat.c dir.c fsutil.c
+CFLAGS+= -I${.CURDIR}/../fsck
+.PATH: ${.CURDIR}/../fsck
.include <bsd.prog.mk>
diff --git a/sbin/fsck_msdos/boot.c b/sbin/fsck_msdos/boot.c
index 8b21fcad726..191388c60ac 100644
--- a/sbin/fsck_msdos/boot.c
+++ b/sbin/fsck_msdos/boot.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: boot.c,v 1.2 1996/06/23 14:30:41 deraadt Exp $ */
-/* $NetBSD: boot.c,v 1.1 1996/05/14 17:39:28 ws Exp $ */
+/* $OpenBSD: boot.c,v 1.3 1997/03/02 05:25:51 millert Exp $ */
+/* $NetBSD: boot.c,v 1.3 1996/09/27 23:22:51 christos Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: boot.c,v 1.2 1996/06/23 14:30:41 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: boot.c,v 1.3 1997/03/02 05:25:51 millert Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -59,7 +59,7 @@ readboot(dosfs, boot)
perror("could not read boot block");
else
pfatal("Short bootblock?");
- return FSFATAL;
+ return (FSFATAL);
}
/* decode bios parameter block */
@@ -83,11 +83,11 @@ readboot(dosfs, boot)
if (boot->BytesPerSec % DOSBOOTBLOCKSIZE != 0) {
pfatal("Invalid sector size: %u\n", boot->BytesPerSec);
- return FSFATAL;
+ return (FSFATAL);
}
if (boot->SecPerClust == 0) {
pfatal("Invalid cluster size: %u\n", boot->SecPerClust);
- return FSFATAL;
+ return (FSFATAL);
}
if (boot->Sectors) {
boot->HugeSectors = 0;
@@ -107,12 +107,12 @@ readboot(dosfs, boot)
if (boot->NumFatEntries < boot->NumClusters) {
pfatal("FAT size too small, %d entries won't fit into %u sectors\n",
boot->NumClusters, boot->FATsecs);
- return FSFATAL;
+ return (FSFATAL);
}
boot->ClusterSize = boot->BytesPerSec * boot->SecPerClust;
boot->NumFiles = 1;
boot->NumFree = 0;
- return FSOK;
+ return (FSOK);
}
diff --git a/sbin/fsck_msdos/check.c b/sbin/fsck_msdos/check.c
index 629e70d8e8b..2403c3fa3ae 100644
--- a/sbin/fsck_msdos/check.c
+++ b/sbin/fsck_msdos/check.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: check.c,v 1.4 1997/02/28 08:36:10 millert Exp $ */
+/* $OpenBSD: check.c,v 1.5 1997/03/02 05:25:52 millert Exp $ */
/* $NetBSD: check.c,v 1.6 1997/01/03 14:32:48 ws Exp $ */
/*
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: check.c,v 1.4 1997/02/28 08:36:10 millert Exp $";
+static char rcsid[] = "$OpenBSD: check.c,v 1.5 1997/03/02 05:25:52 millert Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -74,12 +74,12 @@ checkfilesys(fname)
if (dosfs < 0) {
perror("Can't open");
- return 8;
+ return (8);
}
if (readboot(dosfs, &boot) != FSOK) {
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
if (!preen)
@@ -93,8 +93,8 @@ checkfilesys(fname)
if (mod & FSFATAL) {
if (fat)
free(fat);
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
if (fat == NULL)
@@ -104,8 +104,8 @@ checkfilesys(fname)
free(currentFat);
if (mod & FSFATAL) {
free(fat);
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
}
}
@@ -116,16 +116,16 @@ checkfilesys(fname)
mod |= checkfat(&boot, fat);
if (mod & FSFATAL) {
free(fat);
- close(dosfs);
- return 8;
+ (void)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;
+ (void)close(dosfs);
+ return (8);
}
if (!preen)
@@ -133,16 +133,16 @@ checkfilesys(fname)
if (resetDosDirSection(&boot) & FSFATAL) {
free(fat);
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
mod |= handleDirTree(dosfs, &boot, fat);
if (mod & FSFATAL) {
finishDosDirSection();
free(fat);
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
if (!preen)
@@ -152,7 +152,7 @@ checkfilesys(fname)
finishDosDirSection();
free(fat);
- close(dosfs);
+ (void)close(dosfs);
if (boot.NumBad)
pwarn("%d files, %d free (%d clusters), %d bad (%d clusters)\n",
@@ -164,10 +164,10 @@ checkfilesys(fname)
boot.NumFiles,
boot.NumFree * boot.ClusterSize / 1024, boot.NumFree);
if (mod & (FSFATAL | FSERROR))
- return 8;
+ return (8);
if (mod) {
pwarn("\n***** FILE SYSTEM WAS MODIFIED *****\n");
- return 4;
+ return (4);
}
- return 0;
+ return (0);
}
diff --git a/sbin/fsck_msdos/dir.c b/sbin/fsck_msdos/dir.c
index 92b21c05f8e..4c5fe5ee4f9 100644
--- a/sbin/fsck_msdos/dir.c
+++ b/sbin/fsck_msdos/dir.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: dir.c,v 1.6 1997/02/28 08:36:11 millert Exp $ */
-/* $NetBSD: dir.c,v 1.1.4.1 1996/05/31 18:41:38 jtc Exp $ */
+/* $OpenBSD: dir.c,v 1.7 1997/03/02 05:25:53 millert Exp $ */
+/* $NetBSD: dir.c,v 1.8 1996/09/27 23:22:52 christos Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank
@@ -37,7 +37,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: dir.c,v 1.6 1997/02/28 08:36:11 millert Exp $";
+static char rcsid[] = "$OpenBSD: dir.c,v 1.7 1997/03/02 05:25:53 millert Exp $";
#endif /* not lint */
#include <stdio.h>
@@ -90,6 +90,22 @@ static char rcsid[] = "$OpenBSD: dir.c,v 1.6 1997/02/28 08:36:11 millert Exp $";
#define DD_YEAR_MASK 0xFE00 /* year - 1980 */
#define DD_YEAR_SHIFT 9
+/* dir.c */
+static struct dosDirEntry *newDosDirEntry __P((void));
+static void freeDosDirEntry __P((struct dosDirEntry *));
+static struct dirTodoNode *newDirTodo __P((void));
+static void freeDirTodo __P((struct dirTodoNode *));
+static char *fullpath __P((struct dosDirEntry *));
+static u_char calcShortSum __P((u_char *));
+static int delete __P((int, struct bootblock *, struct fatEntry *, cl_t, int,
+ cl_t, int, int));
+static int removede __P((int, struct bootblock *, struct fatEntry *, u_char *,
+ u_char *, cl_t, cl_t, cl_t, char *, int));
+static int checksize __P((struct bootblock *, struct fatEntry *, u_char *,
+ struct dosDirEntry *));
+static int readDosDirSection __P((int, struct bootblock *, struct fatEntry *,
+ struct dosDirEntry *));
+
/*
* Manage free dosDirEntry structures.
*/
@@ -102,10 +118,10 @@ newDosDirEntry()
if (!(de = freede)) {
if (!(de = (struct dosDirEntry *)malloc(sizeof *de)))
- return 0;
+ return (0);
} else
freede = de->next;
- return de;
+ return (de);
}
static void
@@ -128,10 +144,10 @@ newDirTodo()
if (!(dt = freedt)) {
if (!(dt = (struct dirTodoNode *)malloc(sizeof *dt)))
- return 0;
+ return (0);
} else
freedt = dt->next;
- return dt;
+ return (dt);
}
static void
@@ -165,12 +181,12 @@ fullpath(dir)
nl = strlen(np);
if ((cp -= nl) <= namebuf + 1)
break;
- memcpy(cp, np, nl);
+ (void)memcpy(cp, np, nl);
*--cp = '/';
- } while ((dir = dir->parent));
+ } while ((dir = dir->parent) != NULL);
if (dir != NULL && dir->parent != NULL)
*--cp = '?';
- return cp;
+ return (cp);
}
/*
@@ -188,7 +204,7 @@ calcShortSum(p)
sum += p[i];
}
- return sum;
+ return (sum);
}
/*
@@ -217,10 +233,10 @@ resetDosDirSection(boot)
|| !(delbuf = malloc(b2))
|| !(rootDir = newDosDirEntry())) {
perror("No space for directory");
- return FSFATAL;
+ return (FSFATAL);
}
- memset(rootDir, 0, sizeof *rootDir);
- return FSOK;
+ (void)memset(rootDir, 0, sizeof *rootDir);
+ return (FSOK);
}
/*
@@ -238,7 +254,7 @@ finishDosDirSection()
}
pendingDirectories = 0;
for (d = rootDir; d; d = nd) {
- if ((nd = d->child)) {
+ if ((nd = d->child) != NULL) {
d->child = 0;
continue;
}
@@ -284,7 +300,7 @@ delete(f, boot, fat, startcl, startoff, endcl, endoff, notlast)
if (lseek(f, off, SEEK_SET) != off
|| read(f, delbuf, clsz) != clsz) {
perror("Unable to read directory");
- return FSFATAL;
+ return (FSFATAL);
}
while (s < e) {
*s = SLOT_DELETED;
@@ -293,14 +309,14 @@ delete(f, boot, fat, startcl, startoff, endcl, endoff, notlast)
if (lseek(f, off, SEEK_SET) != off
|| write(f, delbuf, clsz) != clsz) {
perror("Unable to write directory");
- return FSFATAL;
+ return (FSFATAL);
}
if (startcl == endcl)
break;
startcl = fat[startcl].next;
s = delbuf;
}
- return FSOK;
+ return (FSOK);
}
static int
@@ -333,15 +349,15 @@ removede(f, boot, fat, start, end, startcl, endcl, curcl, path, type)
startcl, start - buffer,
endcl, end - buffer,
endcl == curcl) == FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
start = buffer;
}
if (endcl == curcl)
for (; start < end; start += 32)
*start = SLOT_DELETED;
- return FSDIRMOD;
+ return (FSDIRMOD);
}
- return FSERROR;
+ return (FSERROR);
}
/*
@@ -363,11 +379,11 @@ checksize(boot, fat, p, dir)
physicalSize = 0;
else {
if (dir->head < CLUST_FIRST || dir->head >= boot->NumClusters)
- return FSERROR;
+ return (FSERROR);
physicalSize = fat[dir->head].length * boot->ClusterSize;
}
if (physicalSize < dir->size) {
- pwarn("size of %s is %lu, should at most be %lu\n",
+ pwarn("size of %s is %u, should at most be %u\n",
fullpath(dir), dir->size, physicalSize);
if (ask(1, "Truncate")) {
dir->size = physicalSize;
@@ -375,9 +391,9 @@ checksize(boot, fat, p, dir)
p[29] = (u_char)(physicalSize >> 8);
p[30] = (u_char)(physicalSize >> 16);
p[31] = (u_char)(physicalSize >> 24);
- return FSDIRMOD;
+ return (FSDIRMOD);
} else
- return FSERROR;
+ return (FSERROR);
} else if (physicalSize - dir->size >= boot->ClusterSize) {
pwarn("%s has too many clusters allocated\n",
fullpath(dir));
@@ -389,11 +405,11 @@ checksize(boot, fat, p, dir)
cl = fat[cl].next;
clearchain(boot, fat, fat[cl].next);
fat[cl].next = CLUST_EOF;
- return FSFATMOD;
+ return (FSFATMOD);
} else
- return FSERROR;
+ return (FSERROR);
}
- return FSOK;
+ return (FSOK);
}
/*
@@ -413,7 +429,7 @@ readDosDirSection(f, boot, fat, dir)
u_char *p, *vallfn, *invlfn, *empty;
off_t off;
int i, j, k, last;
- cl_t cl, valcl, invcl, empcl;
+ cl_t cl, valcl = ~0, invcl = ~0, empcl = ~0;
char *t;
u_int lidx = 0;
int shortSum;
@@ -425,7 +441,7 @@ readDosDirSection(f, boot, fat, dir)
/*
* Already handled somewhere else.
*/
- return FSOK;
+ return (FSOK);
}
shortSum = -1;
vallfn = invlfn = empty = NULL;
@@ -442,7 +458,7 @@ readDosDirSection(f, boot, fat, dir)
if (lseek(f, off, SEEK_SET) != off
|| read(f, buffer, last) != last) {
perror("Unable to read directory");
- return FSFATAL;
+ return (FSFATAL);
}
last /= 32;
/*
@@ -468,11 +484,17 @@ readDosDirSection(f, boot, fat, dir)
pwarn("%s has entries after end of directory\n",
fullpath(dir));
if (ask(1, "Extend")) {
+ u_char *q;
+
dir->fsckflags &= ~DIREMPTY;
if (delete(f, boot, fat,
empcl, empty - buffer,
- cl, p - buffer) == FSFATAL)
- return FSFATAL;
+ cl, p - buffer, 1) == FSFATAL)
+ return (FSFATAL);
+ q = empcl == cl ? empty : buffer;
+ for (; q < p; q += 32)
+ *q = SLOT_DELETED;
+ mod |= THISMOD|FSDIRMOD;
} else if (ask(0, "Truncate"))
dir->fsckflags |= DIREMPWARN;
}
@@ -493,7 +515,7 @@ readDosDirSection(f, boot, fat, dir)
invcl = valcl;
}
}
- memset(longName, 0, sizeof longName);
+ (void)memset(longName, 0, sizeof longName);
shortSum = p[13];
vallfn = p;
valcl = cl;
@@ -560,7 +582,7 @@ readDosDirSection(f, boot, fat, dir)
/*
* This is a standard msdosfs directory entry.
*/
- memset(&dirent, 0, sizeof dirent);
+ (void)memset(&dirent, 0, sizeof dirent);
/*
* it's a short name record, but we need to know
@@ -622,7 +644,7 @@ readDosDirSection(f, boot, fat, dir)
invcl, vallfn ? valcl : cl, cl,
fullpath(&dirent), 0);
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
if (vallfn
? (valcl == cl && vallfn != buffer)
: p != buffer)
@@ -751,17 +773,17 @@ readDosDirSection(f, boot, fat, dir)
/* create directory tree node */
if (!(d = newDosDirEntry())) {
perror("No space for directory");
- return FSFATAL;
+ return (FSFATAL);
}
- memcpy(d, &dirent, sizeof(struct dosDirEntry));
+ (void)memcpy(d, &dirent, sizeof(struct dosDirEntry));
/* link it into the tree */
dir->child = d;
/* Enter this directory into the todo list */
if (!(n = newDirTodo())) {
perror("No space for todo list");
- return FSFATAL;
+ return (FSFATAL);
}
n->next = pendingDirectories;
n->dir = d;
@@ -778,7 +800,7 @@ readDosDirSection(f, boot, fat, dir)
if (lseek(f, off, SEEK_SET) != off
|| write(f, buffer, last) != last) {
perror("Unable to write directory");
- return FSFATAL;
+ return (FSFATAL);
}
mod &= ~THISMOD;
}
@@ -788,7 +810,7 @@ readDosDirSection(f, boot, fat, dir)
invlfn ? invlfn : vallfn, p,
invlfn ? invcl : valcl, -1, 0,
fullpath(dir), 1);
- return mod & ~THISMOD;
+ return (mod & ~THISMOD);
}
int
@@ -801,7 +823,7 @@ handleDirTree(dosfs, boot, fat)
mod = readDosDirSection(dosfs, boot, fat, rootDir);
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
if (mod & FSFATMOD) {
mod &= ~FSFATMOD;
@@ -809,7 +831,7 @@ handleDirTree(dosfs, boot, fat)
}
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
/*
* process the directory todo list
@@ -830,15 +852,15 @@ handleDirTree(dosfs, boot, fat)
*/
mod |= readDosDirSection(dosfs, boot, fat, dir);
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
if (mod & FSFATMOD) {
mod &= ~FSFATMOD;
mod |= writefat(dosfs, boot, fat); /* delay writing fats? XXX */
}
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
}
- return mod;
+ return (mod);
}
/*
@@ -865,14 +887,14 @@ reconnect(dosfs, boot, fat, head)
}
if (!lostDir) { /* Create LOSTDIR? XXX */
pwarn("No %s directory\n", LOSTDIR);
- return FSERROR;
+ return (FSERROR);
}
}
if (!lfbuf) {
lfbuf = malloc(boot->ClusterSize);
if (!lfbuf) {
perror("No space for buffer");
- return FSFATAL;
+ return (FSFATAL);
}
p = NULL;
} else
@@ -889,32 +911,32 @@ reconnect(dosfs, boot, fat, head)
if (lfcl < CLUST_FIRST || lfcl >= boot->NumClusters) {
/* Extend LOSTDIR? XXX */
pwarn("No space in %s\n", LOSTDIR);
- return FSERROR;
+ return (FSERROR);
}
lfoff = lfcl * boot->ClusterSize
+ boot->ClusterOffset * boot->BytesPerSec;
if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
|| read(dosfs, buffer, boot->ClusterSize) != boot->ClusterSize) {
perror("could not read LOST.DIR");
- return FSFATAL;
+ return (FSFATAL);
}
p = lfbuf;
}
if (!ask(0, "Reconnect"))
- return FSERROR;
+ return (FSERROR);
boot->NumFiles++;
/* Ensure uniqueness of entry here! XXX */
- memset(&d, 0, sizeof d);
+ (void)memset(&d, 0, sizeof d);
sprintf(d.name, "%d", head);
d.flags = 0;
d.head = head;
d.size = fat[head].length * boot->ClusterSize;
- memset(p, 0, 32);
- memset(p, ' ', 11);
- memcpy(p, d.name, strlen(d.name));
+ (void)memset(p, 0, 32);
+ (void)memset(p, ' ', 11);
+ (void)memcpy(p, d.name, strlen(d.name));
p[26] = (u_char)d.head;
p[27] = (u_char)(d.head >> 8);
p[28] = (u_char)d.size;
@@ -925,9 +947,9 @@ reconnect(dosfs, boot, fat, head)
if (lseek(dosfs, lfoff, SEEK_SET) != lfoff
|| write(dosfs, buffer, boot->ClusterSize) != boot->ClusterSize) {
perror("could not write LOST.DIR");
- return FSFATAL;
+ return (FSFATAL);
}
- return FSDIRMOD;
+ return (FSDIRMOD);
}
void
diff --git a/sbin/fsck_msdos/ext.h b/sbin/fsck_msdos/ext.h
index ad490c04bad..aa74ea1ff17 100644
--- a/sbin/fsck_msdos/ext.h
+++ b/sbin/fsck_msdos/ext.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: ext.h,v 1.3 1996/06/23 14:30:43 deraadt Exp $ */
-/* $NetBSD: ext.h,v 1.1.4.1 1996/05/31 18:41:45 jtc Exp $ */
+/* $OpenBSD: ext.h,v 1.4 1997/03/02 05:25:54 millert Exp $ */
+/* $NetBSD: ext.h,v 1.4 1996/09/23 16:27:59 christos Exp $ */
/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank
@@ -39,6 +39,7 @@
#include <sys/types.h>
#include "dosfs.h"
+#include "fsutil.h"
#define LOSTDIR "LOST.DIR"
@@ -57,11 +58,7 @@ extern struct dosDirEntry *rootDir;
/*
* function declarations
*/
-void errexit __P((const char *, ...));
-void pfatal __P((const char *, ...));
-void pwarn __P((const char *, ...));
int ask __P((int, const char *, ...));
-void perror __P((const char *));
/*
* Check filesystem given as arg
diff --git a/sbin/fsck_msdos/fat.c b/sbin/fsck_msdos/fat.c
index 0388ce22ed4..1c8c4a035ce 100644
--- a/sbin/fsck_msdos/fat.c
+++ b/sbin/fsck_msdos/fat.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fat.c,v 1.4 1997/02/28 08:36:12 millert Exp $ */
+/* $OpenBSD: fat.c,v 1.5 1997/03/02 05:25:55 millert Exp $ */
/* $NetBSD: fat.c,v 1.5 1997/01/03 14:32:49 ws Exp $ */
/*
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: fat.c,v 1.4 1997/02/28 08:36:12 millert Exp $";
+static char rcsid[] = "$OpenBSD: fat.c,v 1.5 1997/03/02 05:25:55 millert Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -63,11 +63,11 @@ checkclnum(boot, fat, cl, next)
*next |= 0xf000;
if (*next == CLUST_FREE) {
boot->NumFree++;
- return FSOK;
+ return (FSOK);
}
if (*next == CLUST_BAD) {
boot->NumBad++;
- return FSOK;
+ return (FSOK);
}
if (*next < CLUST_FIRST
|| (*next >= boot->NumClusters && *next < CLUST_EOFS)) {
@@ -77,11 +77,11 @@ checkclnum(boot, fat, cl, next)
*next);
if (ask(0, "Truncate")) {
*next = CLUST_EOF;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSERROR;
+ return (FSERROR);
}
- return FSOK;
+ return (FSOK);
}
/*
@@ -108,10 +108,10 @@ readfat(fs, boot, no, fp)
perror("No space for FAT");
if (fat)
free(fat);
- return FSFATAL;
+ return (FSFATAL);
}
- memset(fat, 0, sizeof(struct fatEntry) * boot->NumClusters);
+ (void)memset(fat, 0, sizeof(struct fatEntry) * boot->NumClusters);
off = boot->ResSectors + no * boot->FATsecs;
off *= boot->BytesPerSec;
@@ -120,7 +120,7 @@ readfat(fs, boot, no, fp)
perror("Unable to read FAT");
free(buffer);
free(fat);
- return FSFATAL;
+ return (FSFATAL);
}
if ((size = read(fs, buffer, boot->FATsecs * boot->BytesPerSec))
@@ -131,7 +131,7 @@ readfat(fs, boot, no, fp)
pfatal("Short FAT?");
free(buffer);
free(fat);
- return FSFATAL;
+ return (FSFATAL);
}
/*
@@ -173,7 +173,7 @@ readfat(fs, boot, no, fp)
free(buffer);
*fp = fat;
- return ret;
+ return (ret);
}
/*
@@ -184,10 +184,10 @@ rsrvdcltype(cl)
cl_t cl;
{
if (cl < CLUST_BAD)
- return "reserved";
+ return ("reserved");
if (cl > CLUST_BAD)
- return "as EOF";
- return "bad";
+ return ("as EOF");
+ return ("bad");
}
static int
@@ -205,58 +205,58 @@ clustdiffer(cl, cp1, cp2, fatnum)
cl, rsrvdcltype(*cp1));
if (ask(1, "fix")) {
*cp2 = *cp1;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSFATAL;
+ return (FSFATAL);
}
pwarn("Cluster %d is marked %s in FAT 1, %s in FAT %d\n",
cl, rsrvdcltype(*cp1), rsrvdcltype(*cp2), fatnum);
if (ask(0, "use FAT #1's entry")) {
*cp2 = *cp1;
- return FSFATMOD;
+ return (FSFATMOD);
}
if (ask(0, "use FAT #%d's entry", fatnum)) {
*cp1 = *cp2;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSFATAL;
+ return (FSFATAL);
}
pwarn("Cluster %d is marked %s in FAT 1, but continues with cluster %d in FAT %d\n",
cl, rsrvdcltype(*cp1), *cp2, fatnum);
if (ask(0, "Use continuation from FAT %d", fatnum)) {
*cp1 = *cp2;
- return FSFATMOD;
+ return (FSFATMOD);
}
if (ask(0, "Use mark from FAT 1")) {
*cp2 = *cp1;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSFATAL;
+ return (FSFATAL);
}
if (*cp2 >= CLUST_RSRVD) {
pwarn("Cluster %d continues with cluster %d in FAT 1, but is marked %s in FAT %d\n",
cl, *cp1, rsrvdcltype(*cp2), fatnum);
if (ask(0, "Use continuation from FAT 1")) {
*cp2 = *cp1;
- return FSFATMOD;
+ return (FSFATMOD);
}
if (ask(0, "Use mark from FAT %d", fatnum)) {
*cp1 = *cp2;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSERROR;
+ return (FSERROR);
}
pwarn("Cluster %d continues with cluster %d in FAT 1, but with cluster %d in FAT %d\n",
cl, *cp1, *cp2, fatnum);
if (ask(0, "Use continuation from FAT 1")) {
*cp2 = *cp1;
- return FSFATMOD;
+ return (FSFATMOD);
}
if (ask(0, "Use continuation from FAT %d", fatnum)) {
*cp1 = *cp2;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSERROR;
+ return (FSERROR);
}
/*
@@ -288,7 +288,7 @@ comparefat(boot, first, second, fatnum)
for (cl = CLUST_FIRST; cl < boot->NumClusters; cl++)
if (first[cl].next != second[cl].next)
ret |= clustdiffer(cl, &first[cl].next, &second[cl].next, fatnum);
- return ret;
+ return (ret);
}
void
@@ -420,7 +420,7 @@ checkfat(boot, fat)
ret |= conf;
}
- return ret;
+ return (ret);
}
/*
@@ -442,9 +442,9 @@ writefat(fs, boot, fat)
buffer = malloc(fatsz = boot->FATsecs * boot->BytesPerSec);
if (buffer == NULL) {
perror("No space for FAT");
- return FSFATAL;
+ return (FSFATAL);
}
- memset(buffer, 0, fatsz);
+ (void)memset(buffer, 0, fatsz);
boot->NumFree = 0;
buffer[0] = (u_char)fat[0].length;
buffer[1] = (u_char)(fat[0].length >> 8);
@@ -480,7 +480,7 @@ writefat(fs, boot, fat)
}
}
free(buffer);
- return ret;
+ return (ret);
}
/*
@@ -512,5 +512,5 @@ checklost(dosfs, boot, fat)
}
finishlf();
- return mod;
+ return (mod);
}
diff --git a/sbin/fsck_msdos/fsck_msdos.8 b/sbin/fsck_msdos/fsck_msdos.8
index d32c49ded12..a61c33b7810 100644
--- a/sbin/fsck_msdos/fsck_msdos.8
+++ b/sbin/fsck_msdos/fsck_msdos.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: fsck_msdos.8,v 1.3 1996/10/08 01:20:23 michaels Exp $
-.\" $NetBSD: fsck_msdos.8,v 1.1 1996/05/14 17:39:35 ws Exp $
+.\" $OpenBSD: fsck_msdos.8,v 1.4 1997/03/02 05:25:55 millert Exp $
+.\" $NetBSD: fsck_msdos.8,v 1.4 1996/10/17 20:41:24 cgd Exp $
.\"
.\" Copyright (C) 1995 Wolfgang Solfrank
.\" Copyright (c) 1995 Martin Husemann
@@ -41,14 +41,23 @@
.Sh SYNOPSIS
.Nm fsck_msdos
.Fl p
+.Op Fl f
.Ar filesystem
.Ar ...
.Nm fsck_msdos
-.Op Fl y
-.Op Fl n
+.Op Fl fny
.Ar filesystem
.Ar ...
.Sh DESCRIPTION
+.Pp
+The
+.Nm
+utility verifies and repairs
+.Tn FAT
+filesystems (more commonly known as
+.Tn DOS
+filesystems).
+.Pp
The first form of
.Nm
preens the specified filesystems.
@@ -57,21 +66,45 @@ It is normally started by
run from
.Pa /etc/rc
during automatic reboot, when a FAT filesystem is detected.
+When preening file systems,
+.Nm
+will fix common inconsistencies non-interactively. If
+more serious problems are found,
+.Nm
+does not try to fix them, indicates that it was not
+successful, and exits.
.Pp
-.Nm fsck_msdos
-verifies a FAT filesystem (more commonly known as DOS filesystem) and tries
-to recover it from inconsistencies.
+The second form of
+.Nm
+checks the specified file systems and tries to repair all
+detected inconsistencies, requesting confirmation before
+making any changes.
.Pp
-Options are:
+The options are as follows:
.Bl -hang -offset indent
-.It Em -y
-assume yes as answer to all questions.
-.It Em -n
-assume no as answer to all questions.
+.It Fl f
+This option is ignored by
+.Nm fsck_msdos ,
+and is present only for compatibility with programs that
+check other file system types for consistency, such as
+.Xr fsck_ffs 8 .
+.It Fl n
+Causes
+.Nm
+to assume no as the answer to all operator
+questions, except
+.Dq CONTINUE? .
+.It Fl p
+Preen the specified filesystems.
+.It Fl y
+Causes
+.Nm
+to assume yes as the answer to all operator questions.
.El
.Sh SEE ALSO
.Xr fsck 8 ,
+.Xr fsck_ffs 8 ,
.Xr mount_msdos 8
.Sh BUGS
-.Nm fsck_msdos
+.Nm Fsck_msdos
is still under construction.
diff --git a/sbin/fsck_msdos/main.c b/sbin/fsck_msdos/main.c
index 3e388f6d619..e7a73ecbaba 100644
--- a/sbin/fsck_msdos/main.c
+++ b/sbin/fsck_msdos/main.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: main.c,v 1.6 1997/02/28 08:38:26 millert Exp $ */
-/* $NetBSD: main.c,v 1.1.4.1 1996/05/31 18:41:54 jtc Exp $ */
+/* $OpenBSD: main.c,v 1.7 1997/03/02 05:25:56 millert Exp $ */
+/* $NetBSD: main.c,v 1.8 1996/10/17 20:29:53 cgd Exp $ */
/*
* Copyright (C) 1995 Wolfgang Solfrank
@@ -35,7 +35,7 @@
#ifndef lint
-static char rcsid[] = "$OpenBSD: main.c,v 1.6 1997/02/28 08:38:26 millert Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.7 1997/03/02 05:25:56 millert Exp $";
#endif /* not lint */
#include <stdlib.h>
@@ -57,12 +57,13 @@ int alwaysyes; /* assume "yes" for all questions */
int preen; /* set when preening */
int rdonly; /* device is opened read only (supersedes above) */
-char *fname; /* filesystem currently checked */
-
+static void usage __P((void));
+int main __P((int, char **));
+
static void
usage()
{
- errexit("Usage: fsck_msdos [-pny] filesystem ... \n");
+ errexit("Usage: fsck_msdos [-fnpy] filesystem ... \n");
}
int
@@ -74,12 +75,17 @@ main(argc, argv)
int ret = 0, erg;
int ch;
- while ((ch = getopt(argc, argv, "vpynf")) != -1) {
+ while ((ch = getopt(argc, argv, "pynf")) != -1) {
switch (ch) {
+ case 'f':
+ /* Ignore for consistency with fsck_ffs */
+ break;
+
case 'n':
alwaysno = 1;
alwaysyes = preen = 0;
break;
+
case 'y':
alwaysyes = 1;
alwaysno = preen = 0;
@@ -90,9 +96,6 @@ main(argc, argv)
alwaysyes = alwaysno = 0;
break;
- case 'f':
- break;
-
default:
usage();
break;
@@ -103,9 +106,10 @@ main(argc, argv)
if (!argc)
usage();
-
+
while (argc-- > 0) {
- erg = checkfilesys(fname = *argv++);
+ setcdevname(*argv, preen);
+ erg = checkfilesys(*argv++);
if (erg > ret)
ret = erg;
}
@@ -113,84 +117,6 @@ main(argc, argv)
}
/*VARARGS*/
-void
-#if __STDC__
-errexit(const char *fmt, ...)
-#else
-errexit(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vprintf(fmt, ap);
- va_end(ap);
- exit(8);
-}
-
-/*VARARGS*/
-void
-#if __STDC__
-pfatal(const char *fmt, ...)
-#else
-pfatal(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-
- if (preen)
- printf("%s: ", fname);
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vprintf(fmt, ap);
- va_end(ap);
- printf("\n");
- if (preen)
- exit(8);
-}
-
-/*VARARGS*/
-void
-#if __STDC__
-pwarn(const char *fmt, ...)
-#else
-pwarn(fmt, va_alist)
- char *fmt;
- va_dcl
-#endif
-{
- va_list ap;
-
- if (preen)
- printf("%s: ", fname);
-#if __STDC__
- va_start(ap, fmt);
-#else
- va_start(ap);
-#endif
- vprintf(fmt, ap);
- va_end(ap);
-}
-
-void
-perror(s)
- const char *s;
-{
- pfatal("%s (%s)", s, strerror(errno));
-}
-
-/*VARARGS*/
int
#if __STDC__
ask(int def, const char *fmt, ...)
@@ -202,7 +128,7 @@ ask(def, fmt, va_alist)
#endif
{
va_list ap;
-
+
char prompt[256];
int c;
@@ -211,7 +137,7 @@ ask(def, fmt, va_alist)
def = 0;
if (def)
printf("FIXED\n");
- return def;
+ return (def);
}
#if __STDC__
@@ -222,7 +148,7 @@ ask(def, fmt, va_alist)
vsnprintf(prompt, sizeof(prompt), fmt, ap);
if (alwaysyes || rdonly) {
printf("%s? %s\n", prompt, rdonly ? "no" : "yes");
- return !rdonly;
+ return (!rdonly);
}
do {
printf("%s? [yn] ", prompt);
@@ -230,7 +156,7 @@ ask(def, fmt, va_alist)
c = getchar();
while (c != '\n' && getchar() != '\n')
if (feof(stdin))
- return 0;
+ return (0);
} while (c != 'y' && c != 'Y' && c != 'n' && c != 'N');
- return c == 'y' || c == 'Y';
+ return (c == 'y' || c == 'Y');
}