Now uses functions from util.[ch] instead of local ones.
Also some anal KNF from me...
-# $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>
-/* $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
#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>
perror("could not read boot block");
else
pfatal("Short bootblock?");
- return FSFATAL;
+ return (FSFATAL);
}
/* decode bios parameter block */
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;
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);
}
-/* $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 $ */
/*
#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>
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)
if (mod & FSFATAL) {
if (fat)
free(fat);
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
if (fat == NULL)
free(currentFat);
if (mod & FSFATAL) {
free(fat);
- close(dosfs);
- return 8;
+ (void)close(dosfs);
+ return (8);
}
}
}
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)
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)
finishDosDirSection();
free(fat);
- close(dosfs);
+ (void)close(dosfs);
if (boot.NumBad)
pwarn("%d files, %d free (%d clusters), %d bad (%d clusters)\n",
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);
}
-/* $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
#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>
#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.
*/
if (!(de = freede)) {
if (!(de = (struct dosDirEntry *)malloc(sizeof *de)))
- return 0;
+ return (0);
} else
freede = de->next;
- return de;
+ return (de);
}
static void
if (!(dt = freedt)) {
if (!(dt = (struct dirTodoNode *)malloc(sizeof *dt)))
- return 0;
+ return (0);
} else
freedt = dt->next;
- return dt;
+ return (dt);
}
static void
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);
}
/*
sum += p[i];
}
- return sum;
+ return (sum);
}
/*
|| !(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);
}
/*
}
pendingDirectories = 0;
for (d = rootDir; d; d = nd) {
- if ((nd = d->child)) {
+ if ((nd = d->child) != NULL) {
d->child = 0;
continue;
}
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;
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
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);
}
/*
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;
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));
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);
}
/*
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;
/*
* Already handled somewhere else.
*/
- return FSOK;
+ return (FSOK);
}
shortSum = -1;
vallfn = invlfn = empty = NULL;
if (lseek(f, off, SEEK_SET) != off
|| read(f, buffer, last) != last) {
perror("Unable to read directory");
- return FSFATAL;
+ return (FSFATAL);
}
last /= 32;
/*
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;
}
invcl = valcl;
}
}
- memset(longName, 0, sizeof longName);
+ (void)memset(longName, 0, sizeof longName);
shortSum = p[13];
vallfn = p;
valcl = cl;
/*
* 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
invcl, vallfn ? valcl : cl, cl,
fullpath(&dirent), 0);
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
if (vallfn
? (valcl == cl && vallfn != buffer)
: p != buffer)
/* 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;
if (lseek(f, off, SEEK_SET) != off
|| write(f, buffer, last) != last) {
perror("Unable to write directory");
- return FSFATAL;
+ return (FSFATAL);
}
mod &= ~THISMOD;
}
invlfn ? invlfn : vallfn, p,
invlfn ? invcl : valcl, -1, 0,
fullpath(dir), 1);
- return mod & ~THISMOD;
+ return (mod & ~THISMOD);
}
int
mod = readDosDirSection(dosfs, boot, fat, rootDir);
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
if (mod & FSFATMOD) {
mod &= ~FSFATMOD;
}
if (mod & FSFATAL)
- return FSFATAL;
+ return (FSFATAL);
/*
* process the directory todo list
*/
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);
}
/*
}
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
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;
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
-/* $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
#include <sys/types.h>
#include "dosfs.h"
+#include "fsutil.h"
#define LOSTDIR "LOST.DIR"
/*
* 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
-/* $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 $ */
/*
#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>
*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)) {
*next);
if (ask(0, "Truncate")) {
*next = CLUST_EOF;
- return FSFATMOD;
+ return (FSFATMOD);
}
- return FSERROR;
+ return (FSERROR);
}
- return FSOK;
+ return (FSOK);
}
/*
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;
perror("Unable to read FAT");
free(buffer);
free(fat);
- return FSFATAL;
+ return (FSFATAL);
}
if ((size = read(fs, buffer, boot->FATsecs * boot->BytesPerSec))
pfatal("Short FAT?");
free(buffer);
free(fat);
- return FSFATAL;
+ return (FSFATAL);
}
/*
free(buffer);
*fp = fat;
- return ret;
+ return (ret);
}
/*
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
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);
}
/*
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
ret |= conf;
}
- return ret;
+ return (ret);
}
/*
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);
}
}
free(buffer);
- return ret;
+ return (ret);
}
/*
}
finishlf();
- return mod;
+ return (mod);
}
-.\" $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
.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.
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.
-/* $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
#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>
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
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;
alwaysyes = alwaysno = 0;
break;
- case 'f':
- break;
-
default:
usage();
break;
if (!argc)
usage();
-
+
while (argc-- > 0) {
- erg = checkfilesys(fname = *argv++);
+ setcdevname(*argv, preen);
+ erg = checkfilesys(*argv++);
if (erg > ret)
ret = erg;
}
exit(ret);
}
-/*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__
#endif
{
va_list ap;
-
+
char prompt[256];
int c;
def = 0;
if (def)
printf("FIXED\n");
- return def;
+ return (def);
}
#if __STDC__
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);
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');
}