summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/Makefile7
-rw-r--r--sbin/fsck/Makefile8
-rw-r--r--sbin/fsck/fsck.896
-rw-r--r--sbin/fsck/fsck.c480
-rw-r--r--sbin/fsck/fsutil.c321
-rw-r--r--sbin/fsck/fsutil.h58
-rw-r--r--sbin/fsck/pathnames.h34
-rw-r--r--sbin/fsck/preen.c341
-rw-r--r--sbin/fsck_ffs/Makefile13
-rw-r--r--sbin/fsck_ffs/SMM.doc/0.t16
-rw-r--r--sbin/fsck_ffs/SMM.doc/1.t14
-rw-r--r--sbin/fsck_ffs/SMM.doc/3.t80
-rw-r--r--sbin/fsck_ffs/SMM.doc/4.t158
-rw-r--r--sbin/fsck_ffs/SMM.doc/Makefile4
-rw-r--r--sbin/fsck_ffs/dir.c77
-rw-r--r--sbin/fsck_ffs/extern.h96
-rw-r--r--sbin/fsck_ffs/fsck.h25
-rw-r--r--sbin/fsck_ffs/fsck_ffs.8 (renamed from sbin/fsck_ffs/fsck.8)49
-rw-r--r--sbin/fsck_ffs/inode.c82
-rw-r--r--sbin/fsck_ffs/main.c64
-rw-r--r--sbin/fsck_ffs/pass1.c39
-rw-r--r--sbin/fsck_ffs/pass1b.c10
-rw-r--r--sbin/fsck_ffs/pass2.c35
-rw-r--r--sbin/fsck_ffs/pass4.c8
-rw-r--r--sbin/fsck_ffs/pass5.c11
-rw-r--r--sbin/fsck_ffs/preen.c381
-rw-r--r--sbin/fsck_ffs/setup.c26
-rw-r--r--sbin/fsck_ffs/utilities.c80
28 files changed, 1757 insertions, 856 deletions
diff --git a/sbin/Makefile b/sbin/Makefile
index 877b4dde0ec..14ad8d2c20b 100644
--- a/sbin/Makefile
+++ b/sbin/Makefile
@@ -1,10 +1,10 @@
-# $OpenBSD: Makefile,v 1.20 1996/09/18 08:03:30 deraadt Exp $
+# $OpenBSD: Makefile,v 1.21 1996/10/20 08:36:21 tholo Exp $
# $NetBSD: Makefile,v 1.29 1996/05/14 17:39:21 ws Exp $
# Not ported: XNSrouted enpload scsiformat startslip
# Missing: icheck ncheck
-SUBDIR= badsect disklabel ccdconfig dmesg fastboot ifconfig init ipf ipfstat \
+SUBDIR= badsect disklabel ccdconfig dmesg fastboot fsck ifconfig init ipf ipfstat \
ipnat kbd mknod modload modunload mount mountd ncheck_ffs nfsd nfsiod \
nologin ping quotacheck reboot route routed savecore scsi \
shutdown slattach swapon ttyflags umount
@@ -36,7 +36,8 @@ SUBDIR+= pcmcia_cntrl
SUBDIR+= fdisk
.elif ${MACHINE} == "pc532"
SUBDIR+= bim
-.elif (${MACHINE} == "sun3") || (${MACHINE} == "atari") || (${MACHINE} == "sparc")
+.elif (${MACHINE} == "sun3") || (${MACHINE} == "atari") || \
+ (${MACHINE} == "sparc")
SUBDIR+= edlabel
.endif
diff --git a/sbin/fsck/Makefile b/sbin/fsck/Makefile
new file mode 100644
index 00000000000..661563156ef
--- /dev/null
+++ b/sbin/fsck/Makefile
@@ -0,0 +1,8 @@
+# $OpenBSD: Makefile,v 1.3 1996/10/20 08:36:22 tholo Exp $
+# $NetBSD: Makefile,v 1.14 1996/09/27 22:38:37 christos Exp $
+
+PROG= fsck
+SRCS= fsck.c fsutil.c preen.c
+MAN= fsck.8
+
+.include <bsd.prog.mk>
diff --git a/sbin/fsck/fsck.8 b/sbin/fsck/fsck.8
new file mode 100644
index 00000000000..444a15804a5
--- /dev/null
+++ b/sbin/fsck/fsck.8
@@ -0,0 +1,96 @@
+.\" $OpenBSD: fsck.8,v 1.3 1996/10/20 08:36:23 tholo Exp $
+.\" $NetBSD: fsck.8,v 1.14 1996/10/03 20:08:29 christos Exp $
+.\"
+.\" Copyright (c) 1996 Christos Zoulas. All rights reserved.
+.\"
+.\" Redistribution and use in source and binary forms, with or without
+.\" modification, are permitted provided that the following conditions
+.\" are met:
+.\" 1. Redistributions of source code must retain the above copyright
+.\" notice, this list of conditions and the following disclaimer.
+.\" 2. Redistributions in binary form must reproduce the above copyright
+.\" notice, this list of conditions and the following disclaimer in the
+.\" documentation and/or other materials provided with the distribution.
+.\" 3. All advertising materials mentioning features or use of this software
+.\" must display the following acknowledgement:
+.\" This product includes software developed by Christos Zoulas.
+.\" 4. The name of the author may not be used to endorse or promote products
+.\" derived from this software without specific prior written permission.
+.\"
+.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+.\"
+.Dd September 23, 1996
+.Dt FSCK 8
+.Os NetBSD 1
+.Sh NAME
+.Nm fsck
+.Nd file system consistency check and interactive repair
+.Sh SYNOPSIS
+.Nm fsck
+.Op Fl dvplfyn
+.Op Fl l Ar maxparallel
+.Op Fl t Ar fstype
+.Op Fl T Ar fstype:fsoptions
+.Ar special | node ...
+.Sh DESCRIPTION
+The
+.Nm fsck
+command invokes filesystem-specific programs to check the
+the special devices listed in the
+.Xr fstab 5
+file or in the command line for consistency.
+The options are as follows:
+.Bl -tag -width indent
+.It Fl d
+Debugging mode. Just print the commands without executing them. Available
+only if
+.Nm
+is compiled to support it.
+.It Fl f
+Force checking of filesystems, even when they are marked clean (for filesystems
+that support this).
+.It Fl l Ar maxparallel
+Limit the number of parallel checks to the number specified in
+the following argument. By default, the limit is the number of
+disks, running one process per disk. If a smaller limit is giv-
+en, the disks are checked round-robin, one filesystem at a time.
+.It Fl n
+Causes
+.Nm
+to assume no as the answer to all operator questions, except "CONTINUE?".
+.It Fl p
+Enter preen mode.
+.It Fl t Ar fstype
+Invoke fsck only in the comma separated list of filesystem types. If the
+list starts with no
+then invoke fsck the the filesystem types that are not specified in the list.
+.It Fl v
+Print the commands before executing them.
+.It Fl y
+Causes
+.Nm
+to assume yes
+as the answer to all operator questions.
+.It Fl T Ar fstype:fsoptions
+List of comma separated file system specific options for the specified
+file system type, in the same format as
+.Xr mount 8
+.Sh FILES
+.Bl -tag -width /etc/fstab -compact
+.It Pa /etc/fstab
+file system table
+.El
+.Sh SEE ALSO
+.Xr mount 8 ,
+.Xr fstab 5 ,
+.Xr fsck_msdos 8 ,
+.Xr fsck_ffs 8
diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c
new file mode 100644
index 00000000000..5d1a150975b
--- /dev/null
+++ b/sbin/fsck/fsck.c
@@ -0,0 +1,480 @@
+/* $OpenBSD: fsck.c,v 1.1 1996/10/20 08:36:24 tholo Exp $ */
+/* $NetBSD: fsck.c,v 1.7 1996/10/03 20:06:30 christos Exp $ */
+
+/*
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ * Copyright (c) 1980, 1989, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * From: @(#)mount.c 8.19 (Berkeley) 4/19/94
+ * From: NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp
+ *
+ */
+
+static char rcsid[] = "$NetBSD: fsck.c,v 1.7 1996/10/03 20:06:30 christos Exp $";
+
+#include <sys/param.h>
+#include <sys/mount.h>
+#include <sys/queue.h>
+#include <sys/wait.h>
+
+#include <err.h>
+#include <errno.h>
+#include <fstab.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "pathnames.h"
+#include "fsutil.h"
+
+static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
+
+TAILQ_HEAD(fstypelist, entry) opthead, selhead;
+
+struct entry {
+ char *type;
+ char *options;
+ TAILQ_ENTRY(entry) entries;
+};
+
+static int maxrun = 0;
+static char *options = NULL;
+static int flags = 0;
+
+int main __P((int, char *[]));
+
+static int checkfs __P((const char *, const char *, const char *, void *,
+ pid_t *));
+static int selected __P((const char *));
+static void addoption __P((char *));
+static const char *getoptions __P((const char *));
+static void addentry __P((struct fstypelist *, const char *, const char *));
+static void maketypelist __P((char *));
+static char *catopt __P((char *, const char *, int));
+static void mangle __P((char *, int *, const char ***, int *));
+static void usage __P((void));
+static void *isok __P((struct fstab *));
+
+
+int
+main(argc, argv)
+ int argc;
+ char *argv[];
+{
+ struct fstab *fs;
+ int i, rval = 0;
+ char *vfstype = NULL;
+ char globopt[3];
+
+ globopt[0] = '-';
+ globopt[2] = '\0';
+
+ TAILQ_INIT(&selhead);
+ TAILQ_INIT(&opthead);
+
+ while ((i = getopt(argc, argv, "dvpfnyl:t:T:")) != -1)
+ switch (i) {
+ case 'd':
+ flags |= CHECK_DEBUG;
+ break;
+
+ case 'v':
+ flags |= CHECK_VERBOSE;
+ break;
+
+ case 'p':
+ flags |= CHECK_PREEN;
+ /*FALLTHROUGH*/
+ case 'n':
+ case 'f':
+ case 'y':
+ globopt[1] = i;
+ options = catopt(options, globopt, 1);
+ break;
+
+ case 'l':
+ maxrun = atoi(optarg);
+ break;
+
+ case 'T':
+ if (*optarg)
+ addoption(optarg);
+ break;
+
+ case 't':
+ if (selhead.tqh_first != NULL)
+ errx(1, "only one -t option may be specified.");
+
+ maketypelist(optarg);
+ vfstype = optarg;
+ break;
+
+ case '?':
+ default:
+ usage();
+ /* NOTREACHED */
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc == 0)
+ return checkfstab(flags, maxrun, isok, checkfs);
+
+#define BADTYPE(type) \
+ (strcmp(type, FSTAB_RO) && \
+ strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
+
+
+ for (; argc--; argv++) {
+ char *spec, *type;
+
+ if ((fs = getfsfile(*argv)) == NULL &&
+ (fs = getfsspec(*argv)) == NULL) {
+ if (vfstype == NULL)
+ errx(1,
+ "%s: unknown special file or file system.",
+ *argv);
+ spec = *argv;
+ type = vfstype;
+ }
+ else {
+ spec = fs->fs_spec;
+ type = fs->fs_vfstype;
+ if (BADTYPE(fs->fs_type))
+ errx(1, "%s has unknown file system type.",
+ *argv);
+ }
+
+ rval |= checkfs(type, blockcheck(spec), *argv, NULL, NULL);
+ }
+
+ return rval;
+}
+
+
+static void *
+isok(fs)
+ struct fstab *fs;
+{
+ if (fs->fs_passno == 0)
+ return NULL;
+
+ if (BADTYPE(fs->fs_type))
+ return NULL;
+
+ if (!selected(fs->fs_vfstype))
+ return NULL;
+
+ return fs;
+}
+
+
+static int
+checkfs(vfstype, spec, mntpt, auxarg, pidp)
+ const char *vfstype, *spec, *mntpt;
+ void *auxarg;
+ pid_t *pidp;
+{
+ /* List of directories containing fsck_xxx subcommands. */
+ static const char *edirs[] = {
+ _PATH_SBIN,
+ _PATH_USRSBIN,
+ NULL
+ };
+ const char **argv, **edir;
+ pid_t pid;
+ int argc, i, status, maxargc;
+ char *optbuf = NULL, execname[MAXPATHLEN + 1];
+ const char *extra = getoptions(vfstype);
+
+#ifdef __GNUC__
+ /* Avoid vfork clobbering */
+ (void) &optbuf;
+#endif
+
+ if (strcmp(vfstype, "ufs") == 0)
+ vfstype = MOUNT_UFS;
+
+ maxargc = 100;
+ argv = emalloc(sizeof(char *) * maxargc);
+
+ argc = 0;
+ argv[argc++] = vfstype;
+
+ if (options) {
+ if (extra != NULL)
+ optbuf = catopt(options, extra, 0);
+ else
+ optbuf = estrdup(options);
+ }
+ else if (extra)
+ optbuf = estrdup(extra);
+
+ if (optbuf)
+ mangle(optbuf, &argc, &argv, &maxargc);
+
+ argv[argc++] = spec;
+ argv[argc] = NULL;
+
+ if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) {
+ (void)printf("start %s %swait fsck_%s", mntpt,
+ pidp ? "no" : "", vfstype);
+ for (i = 1; i < argc; i++)
+ (void)printf(" %s", argv[i]);
+ (void)printf("\n");
+ }
+
+ switch (pid = vfork()) {
+ case -1: /* Error. */
+ warn("vfork");
+ if (optbuf)
+ free(optbuf);
+ return (1);
+
+ case 0: /* Child. */
+ if (flags & CHECK_DEBUG)
+ _exit(0);
+
+ /* Go find an executable. */
+ edir = edirs;
+ do {
+ (void)snprintf(execname,
+ sizeof(execname), "%s/fsck_%s", *edir, vfstype);
+ execv(execname, (char * const *)argv);
+ if (errno != ENOENT)
+ if (spec)
+ warn("exec %s for %s", execname, spec);
+ else
+ warn("exec %s", execname);
+ } while (*++edir != NULL);
+
+ if (errno == ENOENT)
+ if (spec)
+ warn("exec %s for %s", execname, spec);
+ else
+ warn("exec %s", execname);
+ exit(1);
+ /* NOTREACHED */
+
+ default: /* Parent. */
+ if (optbuf)
+ free(optbuf);
+
+ if (pidp) {
+ *pidp = pid;
+ return 0;
+ }
+
+ if (waitpid(pid, &status, 0) < 0) {
+ warn("waitpid");
+ return (1);
+ }
+
+ if (WIFEXITED(status)) {
+ if (WEXITSTATUS(status) != 0)
+ return (WEXITSTATUS(status));
+ }
+ else if (WIFSIGNALED(status)) {
+ warnx("%s: %s", spec, strsignal(WTERMSIG(status)));
+ return (1);
+ }
+ break;
+ }
+
+ return (0);
+}
+
+
+static int
+selected(type)
+ const char *type;
+{
+ struct entry *e;
+
+ /* If no type specified, it's always selected. */
+ for (e = selhead.tqh_first; e != NULL; e = e->entries.tqe_next)
+ if (!strncmp(e->type, type, MFSNAMELEN))
+ return which == IN_LIST ? 1 : 0;
+
+ return which == IN_LIST ? 0 : 1;
+}
+
+
+static const char *
+getoptions(type)
+ const char *type;
+{
+ struct entry *e;
+
+ for (e = opthead.tqh_first; e != NULL; e = e->entries.tqe_next)
+ if (!strncmp(e->type, type, MFSNAMELEN))
+ return e->options;
+ return "";
+}
+
+
+static void
+addoption(optstr)
+ char *optstr;
+{
+ char *newoptions;
+ struct entry *e;
+
+ if ((newoptions = strchr(optstr, ':')) == NULL)
+ errx(1, "Invalid option string");
+
+ *newoptions++ = '\0';
+
+ for (e = opthead.tqh_first; e != NULL; e = e->entries.tqe_next)
+ if (!strncmp(e->type, optstr, MFSNAMELEN)) {
+ e->options = catopt(e->options, newoptions, 1);
+ return;
+ }
+ addentry(&opthead, optstr, newoptions);
+}
+
+
+static void
+addentry(list, type, opts)
+ struct fstypelist *list;
+ const char *type;
+ const char *opts;
+{
+ struct entry *e;
+
+ e = emalloc(sizeof(struct entry));
+ e->type = estrdup(type);
+ e->options = estrdup(opts);
+ TAILQ_INSERT_TAIL(list, e, entries);
+}
+
+
+static void
+maketypelist(fslist)
+ char *fslist;
+{
+ char *ptr;
+
+ if ((fslist == NULL) || (fslist[0] == '\0'))
+ errx(1, "empty type list");
+
+ if (fslist[0] == 'n' && fslist[1] == 'o') {
+ fslist += 2;
+ which = NOT_IN_LIST;
+ }
+ else
+ which = IN_LIST;
+
+ while ((ptr = strsep(&fslist, ",")) != NULL)
+ addentry(&selhead, ptr, "");
+
+}
+
+
+static char *
+catopt(s0, s1, fr)
+ char *s0;
+ const char *s1;
+ int fr;
+{
+ size_t i;
+ char *cp;
+
+ if (s0 && *s0) {
+ i = strlen(s0) + strlen(s1) + 1 + 1;
+ cp = emalloc(i);
+ (void)snprintf(cp, i, "%s,%s", s0, s1);
+ }
+ else
+ cp = estrdup(s1);
+
+ if (s0 && fr)
+ free(s0);
+ return (cp);
+}
+
+
+static void
+mangle(opts, argcp, argvp, maxargcp)
+ char *opts;
+ int *argcp;
+ const char ***argvp;
+ int *maxargcp;
+{
+ char *p, *s;
+ int argc = *argcp, maxargc = *maxargcp;
+ const char **argv = *argvp;
+
+ argc = *argcp;
+ maxargc = *maxargcp;
+
+ for (s = opts; (p = strsep(&s, ",")) != NULL;) {
+ /* always leave space for one more argument and the NULL */
+ if (argc >= maxargc - 3) {
+ maxargc += 50;
+ argv = erealloc(argv, maxargc * sizeof(char *));
+ }
+ if (*p != '\0')
+ if (*p == '-') {
+ argv[argc++] = p;
+ p = strchr(p, '=');
+ if (p) {
+ *p = '\0';
+ argv[argc++] = p+1;
+ }
+ }
+ else {
+ argv[argc++] = "-o";
+ argv[argc++] = p;
+ }
+ }
+
+ *argcp = argc;
+ *argvp = argv;
+ *maxargcp = maxargc;
+}
+
+
+static void
+usage()
+{
+ extern char *__progname;
+ static const char common[] =
+ "[-dpvlyn] [-T fstype:fsoptions] [-t fstype]";
+
+ (void)fprintf(stderr, "Usage: %s %s [special|node]...\n",
+ __progname, common);
+ exit(1);
+}
diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c
new file mode 100644
index 00000000000..caaa18343f8
--- /dev/null
+++ b/sbin/fsck/fsutil.c
@@ -0,0 +1,321 @@
+/* $OpenBSD: fsutil.c,v 1.1 1996/10/20 08:36:25 tholo Exp $ */
+/* $NetBSD: fsutil.c,v 1.2 1996/10/03 20:06:31 christos Exp $ */
+
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+#ifndef lint
+static char rcsid[] = "$NetBSD: fsutil.c,v 1.2 1996/10/03 20:06:31 christos Exp $";
+#endif /* not lint */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#if __STDC__
+#include <stdarg.h>
+#else
+#include <varargs.h>
+#endif
+#include <errno.h>
+#include <fstab.h>
+#include <err.h>
+
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#include "fsutil.h"
+
+static const char *dev = NULL;
+static int hot = 0;
+static int preen = 0;
+
+extern char *__progname;
+
+static void vmsg __P((int, const char *, va_list));
+
+void
+setcdevname(cd, pr)
+ const char *cd;
+ int pr;
+{
+ dev = cd;
+ preen = pr;
+}
+
+const char *
+cdevname()
+{
+ return dev;
+}
+
+int
+hotroot()
+{
+ return hot;
+}
+
+/*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
+ (void) vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ exit(8);
+}
+
+static void
+vmsg(fatal, fmt, ap)
+ int fatal;
+ const char *fmt;
+ va_list ap;
+{
+ if (!fatal && preen)
+ (void) printf("%s: ", dev);
+
+ (void) vprintf(fmt, ap);
+
+ if (fatal && preen)
+ (void) printf("\n");
+
+ if (fatal && preen) {
+ (void) printf(
+ "%s: UNEXPECTED INCONSISTENCY; RUN %s MANUALLY.\n",
+ dev, __progname);
+ exit(8);
+ }
+}
+
+/*VARARGS*/
+void
+#if __STDC__
+pfatal(const char *fmt, ...)
+#else
+pfatal(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ vmsg(1, fmt, ap);
+ va_end(ap);
+}
+
+/*VARARGS*/
+void
+#if __STDC__
+pwarn(const char *fmt, ...)
+#else
+pwarn(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ vmsg(0, fmt, ap);
+ va_end(ap);
+}
+
+void
+perror(s)
+ const char *s;
+{
+ pfatal("%s (%s)", s, strerror(errno));
+}
+
+void
+#if __STDC__
+panic(const char *fmt, ...)
+#else
+panic(fmt, va_alist)
+ char *fmt;
+ va_dcl
+#endif
+{
+ va_list ap;
+
+#if __STDC__
+ va_start(ap, fmt);
+#else
+ va_start(ap);
+#endif
+ vmsg(1, fmt, ap);
+ va_end(ap);
+ exit(8);
+}
+
+char *
+unrawname(name)
+ char *name;
+{
+ char *dp;
+ struct stat stb;
+
+ if ((dp = strrchr(name, '/')) == 0)
+ return (name);
+ if (stat(name, &stb) < 0)
+ return (name);
+ if (!S_ISCHR(stb.st_mode))
+ return (name);
+ if (dp[1] != 'r')
+ return (name);
+ (void)strcpy(&dp[1], &dp[2]);
+ return (name);
+}
+
+char *
+rawname(name)
+ char *name;
+{
+ static char rawbuf[32];
+ char *dp;
+
+ if ((dp = strrchr(name, '/')) == 0)
+ return (0);
+ *dp = 0;
+ (void)strcpy(rawbuf, name);
+ *dp = '/';
+ (void)strcat(rawbuf, "/r");
+ (void)strcat(rawbuf, &dp[1]);
+ return (rawbuf);
+}
+
+char *
+blockcheck(origname)
+ char *origname;
+{
+ struct stat stslash, stblock, stchar;
+ char *newname, *raw;
+ struct fstab *fsp;
+ int retried = 0;
+
+ hot = 0;
+ if (stat("/", &stslash) < 0) {
+ perror("/");
+ printf("Can't stat root\n");
+ return (origname);
+ }
+ newname = origname;
+retry:
+ if (stat(newname, &stblock) < 0) {
+ perror(newname);
+ printf("Can't stat %s\n", newname);
+ return (origname);
+ }
+ if (S_ISBLK(stblock.st_mode)) {
+ if (stslash.st_dev == stblock.st_rdev)
+ hot++;
+ raw = rawname(newname);
+ if (stat(raw, &stchar) < 0) {
+ perror(raw);
+ printf("Can't stat %s\n", raw);
+ return (origname);
+ }
+ if (S_ISCHR(stchar.st_mode)) {
+ return (raw);
+ } else {
+ printf("%s is not a character device\n", raw);
+ return (origname);
+ }
+ } else if (S_ISCHR(stblock.st_mode) && !retried) {
+ newname = unrawname(newname);
+ retried++;
+ goto retry;
+ } else if ((fsp = getfsfile(newname)) != 0 && !retried) {
+ newname = fsp->fs_spec;
+ retried++;
+ goto retry;
+ }
+ /*
+ * Not a block or character device, just return name and
+ * let the user decide whether to use it.
+ */
+ return (origname);
+}
+
+
+void *
+emalloc(s)
+ size_t s;
+{
+ void *p = malloc(s);
+ if (p == NULL)
+ err(1, "malloc failed");
+ return p;
+}
+
+
+void *
+erealloc(p, s)
+ void *p;
+ size_t s;
+{
+ p = realloc(p, s);
+ if (p == NULL)
+ err(1, "realloc failed");
+ return p;
+}
+
+
+char *
+estrdup(s)
+ const char *s;
+{
+ char *p = strdup(s);
+ if (p == NULL)
+ err(1, "strdup failed");
+ return p;
+}
diff --git a/sbin/fsck/fsutil.h b/sbin/fsck/fsutil.h
new file mode 100644
index 00000000000..e185fc7e901
--- /dev/null
+++ b/sbin/fsck/fsutil.h
@@ -0,0 +1,58 @@
+/* $OpenBSD: fsutil.h,v 1.1 1996/10/20 08:36:25 tholo Exp $ */
+/* $NetBSD: fsutil.h,v 1.3 1996/10/03 20:06:31 christos Exp $ */
+
+/*
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+void perror __P((const char *));
+void errexit __P((const char *, ...))
+ __attribute__((__noreturn__,__format__(__printf__,1,2)));
+void pfatal __P((const char *, ...))
+ __attribute__((__format__(__printf__,1,2)));
+void pwarn __P((const char *, ...))
+ __attribute__((__format__(__printf__,1,2)));
+void panic __P((const char *, ...))
+ __attribute__((__noreturn__,__format__(__printf__,1,2)));
+char *rawname __P((char *));
+char *unrawname __P((char *));
+char *blockcheck __P((char *));
+const char *cdevname __P((void));
+void setcdevname __P((const char *, int));
+int hotroot __P((void));
+void *emalloc __P((size_t));
+void *erealloc __P((void *, size_t));
+char *estrdup __P((const char *));
+
+#define CHECK_PREEN 1
+#define CHECK_VERBOSE 2
+#define CHECK_DEBUG 4
+
+struct fstab;
+int checkfstab __P((int, int, void *(*)(struct fstab *),
+ int (*) (const char *, const char *, const char *, void *, pid_t *)));
diff --git a/sbin/fsck/pathnames.h b/sbin/fsck/pathnames.h
new file mode 100644
index 00000000000..930c3ee6e6f
--- /dev/null
+++ b/sbin/fsck/pathnames.h
@@ -0,0 +1,34 @@
+/* $OpenBSD: pathnames.h,v 1.1 1996/10/20 08:36:26 tholo Exp $ */
+/* $NetBSD: pathnames.h,v 1.1 1996/09/11 20:27:15 christos Exp $ */
+
+/*
+ * Copyright (c) 1996 Christos Zoulas. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#define _PATH_SBIN "/sbin"
+#define _PATH_USRSBIN "/usr/sbin"
diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c
new file mode 100644
index 00000000000..abcb2eb4b5f
--- /dev/null
+++ b/sbin/fsck/preen.c
@@ -0,0 +1,341 @@
+/* $OpenBSD: preen.c,v 1.3 1996/10/20 08:36:27 tholo Exp $ */
+/* $NetBSD: preen.c,v 1.15 1996/09/28 19:21:42 christos Exp $ */
+
+/*
+ * Copyright (c) 1990, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)preen.c 8.3 (Berkeley) 12/6/94";
+#else
+static char rcsid[] = "$NetBSD: preen.c,v 1.15 1996/09/28 19:21:42 christos Exp $";
+#endif
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+#include <sys/wait.h>
+#include <sys/queue.h>
+
+#include <fstab.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <err.h>
+
+#include "fsutil.h"
+
+struct partentry {
+ TAILQ_ENTRY(partentry) p_entries;
+ char *p_devname; /* device name */
+ char *p_mntpt; /* mount point */
+ char *p_type; /* filesystem type */
+ void *p_auxarg; /* auxiliary argument */
+};
+
+TAILQ_HEAD(part, partentry) badh;
+
+struct diskentry {
+ TAILQ_ENTRY(diskentry) d_entries;
+ char *d_name; /* disk base name */
+ TAILQ_HEAD(prt, partentry) d_part; /* list of partitions on disk */
+ int d_pid; /* 0 or pid of fsck proc */
+};
+
+TAILQ_HEAD(disk, diskentry) diskh;
+
+static int nrun = 0, ndisks = 0;
+
+static struct diskentry *finddisk __P((const char *));
+static void addpart __P((const char *, const char *, const char *, void *));
+static int startdisk __P((struct diskentry *,
+ int (*)(const char *, const char *, const char *, void *, pid_t *)));
+static void printpart __P((void));
+
+int
+checkfstab(flags, maxrun, docheck, checkit)
+ int flags, maxrun;
+ void *(*docheck) __P((struct fstab *));
+ int (*checkit) __P((const char *, const char *, const char *, void *,
+ pid_t *));
+{
+ struct fstab *fs;
+ struct diskentry *d, *nextdisk;
+ struct partentry *p;
+ int ret, pid, retcode, passno, sumstatus, status;
+ void *auxarg;
+ char *name;
+
+ TAILQ_INIT(&badh);
+ TAILQ_INIT(&diskh);
+
+ sumstatus = 0;
+
+ for (passno = 1; passno <= 2; passno++) {
+ if (setfsent() == 0) {
+ warnx("Can't open checklist file: %s\n", _PATH_FSTAB);
+ return (8);
+ }
+ while ((fs = getfsent()) != 0) {
+ if ((auxarg = (*docheck)(fs)) == NULL)
+ continue;
+
+ name = blockcheck(fs->fs_spec);
+ if (flags & CHECK_DEBUG)
+ printf("pass %d, name %s\n", passno, name);
+
+ if ((flags & CHECK_PREEN) == 0 ||
+ (passno == 1 && fs->fs_passno == 1)) {
+ if (name == NULL) {
+ if (flags & CHECK_PREEN)
+ return 8;
+ else
+ continue;
+ }
+ sumstatus = (*checkit)(fs->fs_vfstype,
+ name, fs->fs_file, auxarg, NULL);
+
+ if (sumstatus)
+ return (sumstatus);
+ } else if (passno == 2 && fs->fs_passno > 1) {
+ if (name == NULL) {
+ (void) fprintf(stderr,
+ "BAD DISK NAME %s\n", fs->fs_spec);
+ sumstatus |= 8;
+ continue;
+ }
+ addpart(fs->fs_vfstype, name, fs->fs_file,
+ auxarg);
+ }
+ }
+ if ((flags & CHECK_PREEN) == 0)
+ return 0;
+ }
+
+ if (flags & CHECK_DEBUG)
+ printpart();
+
+ if (flags & CHECK_PREEN) {
+ if (maxrun == 0)
+ maxrun = ndisks;
+ if (maxrun > ndisks)
+ maxrun = ndisks;
+ nextdisk = diskh.tqh_first;
+ for (passno = 0; passno < maxrun; ++passno) {
+ if ((ret = startdisk(nextdisk, checkit)) != 0)
+ return ret;
+ nextdisk = nextdisk->d_entries.tqe_next;
+ }
+
+ while ((pid = wait(&status)) != -1) {
+ for (d = diskh.tqh_first; d; d = d->d_entries.tqe_next)
+ if (d->d_pid == pid)
+ break;
+
+ if (d == NULL) {
+ warnx("Unknown pid %d\n", pid);
+ continue;
+ }
+
+
+ if (WIFEXITED(status))
+ retcode = WEXITSTATUS(status);
+ else
+ retcode = 0;
+
+ p = d->d_part.tqh_first;
+
+ if (flags & (CHECK_DEBUG|CHECK_VERBOSE))
+ (void) printf("done %s: %s (%s) = %x\n",
+ p->p_type, p->p_devname, p->p_mntpt,
+ status);
+
+ if (WIFSIGNALED(status)) {
+ (void) fprintf(stderr,
+ "%s: %s (%s): EXITED WITH SIGNAL %d\n",
+ p->p_type, p->p_devname, p->p_mntpt,
+ WTERMSIG(status));
+ retcode = 8;
+ }
+
+ TAILQ_REMOVE(&d->d_part, p, p_entries);
+
+ if (retcode != 0) {
+ TAILQ_INSERT_TAIL(&badh, p, p_entries);
+ sumstatus |= retcode;
+ } else {
+ free(p->p_type);
+ free(p->p_devname);
+ free(p);
+ }
+ d->d_pid = 0;
+ nrun--;
+
+ if (d->d_part.tqh_first == NULL)
+ ndisks--;
+
+ if (nextdisk == NULL) {
+ if (d->d_part.tqh_first) {
+ if ((ret = startdisk(d, checkit)) != 0)
+ return ret;
+ }
+ } else if (nrun < maxrun && nrun < ndisks) {
+ for ( ;; ) {
+ nextdisk = nextdisk->d_entries.tqe_next;
+ if (nextdisk == NULL)
+ nextdisk = diskh.tqh_first;
+ if (nextdisk->d_part.tqh_first != NULL
+ && nextdisk->d_pid == 0)
+ break;
+ }
+ if ((ret = startdisk(nextdisk, checkit)) != 0)
+ return ret;
+ }
+ }
+ }
+ if (sumstatus) {
+ p = badh.tqh_first;
+ if (p == NULL)
+ return (sumstatus);
+
+ (void) fprintf(stderr,
+ "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t",
+ p->p_entries.tqe_next ? "S" : "",
+ "UNEXPECTED INCONSISTENCY:");
+
+ for (; p; p = p->p_entries.tqe_next)
+ (void) fprintf(stderr,
+ "%s: %s (%s)%s", p->p_type, p->p_devname,
+ p->p_mntpt, p->p_entries.tqe_next ? ", " : "\n");
+
+ return sumstatus;
+ }
+ (void) endfsent();
+ return (0);
+}
+
+
+static struct diskentry *
+finddisk(name)
+ const char *name;
+{
+ const char *p;
+ size_t len;
+ struct diskentry *d;
+
+ for (p = name + strlen(name) - 1; p >= name; --p)
+ if (isdigit(*p)) {
+ len = p - name + 1;
+ break;
+ }
+
+ if (p < name)
+ len = strlen(name);
+
+ for (d = diskh.tqh_first; d != NULL; d = d->d_entries.tqe_next)
+ if (strncmp(d->d_name, name, len) == 0 && d->d_name[len] == 0)
+ return d;
+
+ d = emalloc(sizeof(*d));
+ d->d_name = estrdup(name);
+ d->d_name[len] = '\0';
+ TAILQ_INIT(&d->d_part);
+ d->d_pid = 0;
+
+ TAILQ_INSERT_TAIL(&diskh, d, d_entries);
+ ndisks++;
+
+ return d;
+}
+
+
+static void
+printpart()
+{
+ struct diskentry *d;
+ struct partentry *p;
+
+ for (d = diskh.tqh_first; d != NULL; d = d->d_entries.tqe_next) {
+ (void) printf("disk %s: ", d->d_name);
+ for (p = d->d_part.tqh_first; p != NULL;
+ p = p->p_entries.tqe_next)
+ (void) printf("%s ", p->p_devname);
+ (void) printf("\n");
+ }
+}
+
+
+static void
+addpart(type, devname, mntpt, auxarg)
+ const char *type, *devname, *mntpt;
+ void *auxarg;
+{
+ struct diskentry *d = finddisk(devname);
+ struct partentry *p;
+
+ for (p = d->d_part.tqh_first; p != NULL; p = p->p_entries.tqe_next)
+ if (strcmp(p->p_devname, devname) == 0) {
+ warnx("%s in fstab more than once!\n", devname);
+ return;
+ }
+
+ p = emalloc(sizeof(*p));
+ p->p_devname = estrdup(devname);
+ p->p_mntpt = estrdup(mntpt);
+ p->p_type = estrdup(type);
+ p->p_auxarg = auxarg;
+
+ TAILQ_INSERT_TAIL(&d->d_part, p, p_entries);
+}
+
+
+static int
+startdisk(d, checkit)
+ register struct diskentry *d;
+ int (*checkit) __P((const char *, const char *, const char *, void *,
+ pid_t *));
+{
+ register struct partentry *p = d->d_part.tqh_first;
+ int rv;
+
+ while ((rv = (*checkit)(p->p_type, p->p_devname, p->p_mntpt,
+ p->p_auxarg, &d->d_pid)) != 0 && nrun > 0)
+ sleep(10);
+
+ if (rv == 0)
+ nrun++;
+
+ return rv;
+}
diff --git a/sbin/fsck_ffs/Makefile b/sbin/fsck_ffs/Makefile
index 0c1863fb1cb..2d0332f7bcc 100644
--- a/sbin/fsck_ffs/Makefile
+++ b/sbin/fsck_ffs/Makefile
@@ -1,11 +1,12 @@
-# $OpenBSD: Makefile,v 1.2 1996/06/23 14:30:25 deraadt Exp $
-# $NetBSD: Makefile,v 1.10 1995/03/18 14:55:39 cgd Exp $
+# $OpenBSD: Makefile,v 1.3 1996/10/20 08:36:28 tholo Exp $
+# $NetBSD: Makefile,v 1.13 1996/09/27 22:45:10 christos Exp $
-PROG= fsck
-MAN= fsck.8
+PROG= fsck_ffs
+MAN= fsck_ffs.8
SRCS= dir.c inode.c main.c pass1.c pass1b.c pass2.c pass3.c pass4.c \
- pass5.c preen.c setup.c utilities.c ffs_subr.c ffs_tables.c
-.PATH: ${.CURDIR}/../../sys/ufs/ffs
+ pass5.c fsutil.c setup.c utilities.c ffs_subr.c ffs_tables.c
+.PATH: ${.CURDIR}/../../sys/ufs/ffs ${.CURDIR}/../fsck
+CFLAGS= -I${.CURDIR}/../fsck
.if make(install)
SUBDIR+= SMM.doc
diff --git a/sbin/fsck_ffs/SMM.doc/0.t b/sbin/fsck_ffs/SMM.doc/0.t
index 1c41939d2db..638bf97701c 100644
--- a/sbin/fsck_ffs/SMM.doc/0.t
+++ b/sbin/fsck_ffs/SMM.doc/0.t
@@ -1,5 +1,5 @@
-.\" $OpenBSD: 0.t,v 1.2 1996/06/23 14:30:36 deraadt Exp $
-.\" $NetBSD: 0.t,v 1.2 1995/03/18 14:56:05 cgd Exp $
+.\" $OpenBSD: 0.t,v 1.3 1996/10/20 08:36:43 tholo Exp $
+.\" $NetBSD: 0.t,v 1.3 1996/04/05 01:45:40 cgd Exp $
.\"
.\" Copyright (c) 1986, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -36,7 +36,7 @@
.\"
.if n .ND
.TL
-Fsck \- The UNIX\(dg File System Check Program
+Fsck_ffs \- The UNIX\(dg File System Check Program
.EH 'SMM:3-%''The \s-2UNIX\s+2 File System Check Program'
.OH 'The \s-2UNIX\s+2 File System Check Program''SMM:3-%'
.AU
@@ -64,15 +64,15 @@ Arpa Order No. 4031 monitored by Naval Electronic System Command under
Contract No. N00039-82-C-0235.
.FE
This document reflects the use of
-.I fsck
+.I fsck_ffs
with the 4.2BSD and 4.3BSD file system organization. This
is a revision of the
original paper written by
T. J. Kowalski.
.PP
-File System Check Program (\fIfsck\fR)
+File System Check Program (\fIfsck_ffs\fR)
is an interactive file system check and repair program.
-.I Fsck
+.I Fsck_ffs
uses the redundant structural information in the
UNIX file system to perform several consistency checks.
If an inconsistency is detected, it is reported
@@ -82,7 +82,7 @@ These inconsistencies result from the permanent interruption
of the file system updates, which are performed every
time a file is modified.
Unless there has been a hardware failure,
-.I fsck
+.I fsck_ffs
is able to repair corrupted file systems
using procedures based upon the order in which UNIX honors
these file system update requests.
@@ -92,7 +92,7 @@ of the file system,
to discuss the possible causes of file system corruption,
and to present the corrective actions implemented
by
-.I fsck.
+.I fsck_ffs.
Both the program and the interaction between the
program and the operator are described.
.sp 2
diff --git a/sbin/fsck_ffs/SMM.doc/1.t b/sbin/fsck_ffs/SMM.doc/1.t
index 258aeba31b5..8853320cf65 100644
--- a/sbin/fsck_ffs/SMM.doc/1.t
+++ b/sbin/fsck_ffs/SMM.doc/1.t
@@ -1,5 +1,5 @@
-.\" $OpenBSD: 1.t,v 1.2 1996/06/23 14:30:36 deraadt Exp $
-.\" $NetBSD: 1.t,v 1.2 1995/03/18 14:56:06 cgd Exp $
+.\" $OpenBSD: 1.t,v 1.3 1996/10/20 08:36:44 tholo Exp $
+.\" $NetBSD: 1.t,v 1.3 1996/04/05 01:45:44 cgd Exp $
.\"
.\" Copyright (c) 1982, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -39,7 +39,7 @@
Introduction
.PP
This document reflects the use of
-.I fsck
+.I fsck_ffs
with the 4.2BSD and 4.3BSD file system organization. This
is a revision of the
original paper written by
@@ -52,7 +52,7 @@ This precautionary measure helps to insure
a reliable environment for file storage on disk.
If an inconsistency is discovered,
corrective action must be taken.
-.I Fsck
+.I Fsck_ffs
runs in two modes.
Normally it is run non-interactively by the system after
a normal boot.
@@ -60,11 +60,11 @@ When running in this mode,
it will only make changes to the file system that are known
to always be correct.
If an unexpected inconsistency is found
-.I fsck
+.I fsck_ffs
will exit with a non-zero exit status,
leaving the system running single-user.
Typically the operator then runs
-.I fsck
+.I fsck_ffs
interactively.
When running in this mode,
each problem is listed followed by a suggested corrective action.
@@ -80,7 +80,7 @@ then describes file system corruption (the storm).
Finally,
the set of deterministic corrective actions
used by
-.I fsck
+.I fsck_ffs
(the Coast Guard
to the rescue) is presented.
.ds RH Overview of the File System
diff --git a/sbin/fsck_ffs/SMM.doc/3.t b/sbin/fsck_ffs/SMM.doc/3.t
index e236f5d869f..547c90067cc 100644
--- a/sbin/fsck_ffs/SMM.doc/3.t
+++ b/sbin/fsck_ffs/SMM.doc/3.t
@@ -1,5 +1,5 @@
-.\" $OpenBSD: 3.t,v 1.3 1996/10/12 03:06:55 tholo Exp $
-.\" $NetBSD: 3.t,v 1.2 1995/03/18 14:56:10 cgd Exp $
+.\" $OpenBSD: 3.t,v 1.4 1996/10/20 08:36:45 tholo Exp $
+.\" $NetBSD: 3.t,v 1.4 1996/10/11 20:15:49 thorpej Exp $
.\"
.\" Copyright (c) 1982, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -69,19 +69,19 @@ on a disk pack, or as blatant as a non-functional disk-controller.
Detecting and correcting corruption
.PP
Normally
-.I fsck
+.I fsck_ffs
is run non-interactively.
In this mode it will only fix
corruptions that are expected to occur from an unclean halt.
These actions are a proper subset of the actions that
-.I fsck
+.I fsck_ffs
will take when it is running interactively.
Throughout this paper we assume that
-.I fsck
+.I fsck_ffs
is being run interactively,
and all possible errors can be encountered.
When an inconsistency is discovered in this mode,
-.I fsck
+.I fsck_ffs
reports the inconsistency for the operator to
chose a corrective action.
.PP
@@ -98,10 +98,10 @@ or computed from other known values.
The file system
.B must
be in a quiescent state when
-.I fsck
+.I fsck_ffs
is run,
since
-.I fsck
+.I fsck_ffs
is a multi-pass program.
.PP
In the following sections,
@@ -129,54 +129,54 @@ number of blocks used by the super-block
and the number of blocks used by the list of inodes.
The file-system size and layout information
are the most critical pieces of information for
-.I fsck .
+.I fsck_ffs .
While there is no way to actually check these sizes,
since they are statically determined by
.I newfs ,
-.I fsck
+.I fsck_ffs
can check that these sizes are within reasonable bounds.
All other file system checks require that these sizes be correct.
If
-.I fsck
+.I fsck_ffs
detects corruption in the static parameters of the default super-block,
-.I fsck
+.I fsck_ffs
requests the operator to specify the location of an alternate super-block.
.NH 2
Free block checking
.PP
-.I Fsck
+.I Fsck_ffs
checks that all the blocks
marked as free in the cylinder group block maps
are not claimed by any files.
When all the blocks have been initially accounted for,
-.I fsck
+.I fsck_ffs
checks that
the number of free blocks
plus the number of blocks claimed by the inodes
equals the total number of blocks in the file system.
.PP
If anything is wrong with the block allocation maps,
-.I fsck
+.I fsck_ffs
will rebuild them,
based on the list it has computed of allocated blocks.
.PP
The summary information associated with the super-block
counts the total number of free blocks within the file system.
-.I Fsck
+.I Fsck_ffs
compares this count to the
number of free blocks it found within the file system.
If the two counts do not agree, then
-.I fsck
+.I fsck_ffs
replaces the incorrect count in the summary information
by the actual free-block count.
.PP
The summary information
counts the total number of free inodes within the file system.
-.I Fsck
+.I Fsck_ffs
compares this count to the number
of free inodes it found within the file system.
If the two counts do not agree, then
-.I fsck
+.I fsck_ffs
replaces the incorrect count in the
summary information by the actual free-inode count.
.NH 2
@@ -210,7 +210,7 @@ This last state suggests an incorrectly formated inode.
An inode can get in this state if
bad data is written into the inode list.
The only possible corrective action is for
-.I fsck
+.I fsck_ffs
is to clear the inode.
.NH 2
Inode links
@@ -218,7 +218,7 @@ Inode links
Each inode counts the
total number of directory entries
linked to the inode.
-.I Fsck
+.I Fsck_ffs
verifies the link count of each inode
by starting at the root of the file system,
and descending through the directory structure.
@@ -229,7 +229,7 @@ If the stored link count is non-zero and the actual
link count is zero,
then no directory entry appears for the inode.
If this happens,
-.I fsck
+.I fsck_ffs
will place the disconnected file in the
.I lost+found
directory.
@@ -237,7 +237,7 @@ If the stored and actual link counts are non-zero and unequal,
a directory entry may have been added or removed without the inode being
updated.
If this happens,
-.I fsck
+.I fsck_ffs
replaces the incorrect stored link count by the actual link count.
.PP
Each inode contains a list,
@@ -248,7 +248,7 @@ Since indirect blocks are owned by an inode,
inconsistencies in indirect blocks directly
affect the inode that owns it.
.PP
-.I Fsck
+.I Fsck_ffs
compares each block number claimed by an inode
against a list of already allocated blocks.
If another inode already claims a block number,
@@ -258,7 +258,7 @@ Otherwise, the list of allocated blocks
is updated to include the block number.
.PP
If there are any duplicate blocks,
-.I fsck
+.I fsck_ffs
will perform a partial second
pass over the inode list
to find the inode of the duplicated block.
@@ -273,12 +273,12 @@ then the inode with the earliest
modify time is usually incorrect,
and should be cleared.
If this happens,
-.I fsck
+.I fsck_ffs
prompts the operator to clear both inodes.
The operator must decide which one should be kept
and which one should be cleared.
.PP
-.I Fsck
+.I Fsck_ffs
checks the range of each block number claimed by an inode.
If the block number is
lower than the first data block in the file system,
@@ -289,7 +289,7 @@ Many bad blocks in an inode are usually caused by
an indirect block that was not written to the file system,
a condition which can only occur if there has been a hardware failure.
If an inode contains bad block numbers,
-.I fsck
+.I fsck_ffs
prompts the operator to clear it.
.NH 2
Inode data size
@@ -299,12 +299,12 @@ that it contains.
The number of actual data blocks
is the sum of the allocated data blocks
and the indirect blocks.
-.I Fsck
+.I Fsck_ffs
computes the actual number of data blocks
and compares that block count against
the actual number of blocks the inode claims.
If an inode contains an incorrect count
-.I fsck
+.I fsck_ffs
prompts the operator to fix it.
.PP
Each inode contains a thirty-two bit size field.
@@ -328,7 +328,7 @@ contain the information stored in a file;
symbolic link data blocks
contain the path name stored in a link.
Directory data blocks contain directory entries.
-.I Fsck
+.I Fsck_ffs
can only check the validity of directory data blocks.
.PP
Each directory data block is checked for
@@ -342,7 +342,7 @@ and directories that are not attached to the file system.
If the inode number in a directory data block
references an unallocated inode,
then
-.I fsck
+.I fsck_ffs
will remove that directory entry.
Again,
this condition can only arise when there has been a hardware failure.
@@ -362,7 +362,7 @@ directory containing an unallocated block.
.PP
If a directory entry inode number references
outside the inode list, then
-.I fsck
+.I fsck_ffs
will remove that directory entry.
This condition occurs if bad data is written into a directory data block.
.PP
@@ -382,19 +382,19 @@ data block if the directory is the
root directory).
If the directory inode numbers are
incorrect,
-.I fsck
+.I fsck_ffs
will replace them with the correct values.
If there are multiple hard links to a directory,
the first one encountered is considered the real parent
to which ``\fB..\fP'' should point;
-\fIfsck\fP recommends deletion for the subsequently discovered names.
+\fIfsck_ffs\fP recommends deletion for the subsequently discovered names.
.NH 2
File system connectivity
.PP
-.I Fsck
+.I Fsck_ffs
checks the general connectivity of the file system.
If directories are not linked into the file system, then
-.I fsck
+.I fsck_ffs
links the directory back into the file system in the
.I lost+found
directory.
@@ -415,9 +415,9 @@ Contract No. N00039-82-C-0235. (Kirk McKusick, July 1983)
.PP
I would like to thank Larry A. Wehr for advice that lead
to the first version of
-.I fsck
+.I fsck_ffs
and Rick B. Brandt for adapting
-.I fsck
+.I fsck_ffs
to
UNIX/TS. (T. Kowalski, July 1979)
.sp 2
@@ -451,5 +451,5 @@ UNIX Implementation,
.I "The Bell System Technical Journal\^"
.B 57 ,
6 (July-August 1978, Part 2), pp. 1931-46.
-.ds RH Appendix A \- Fsck Error Conditions
+.ds RH Appendix A \- Fsck_ffs Error Conditions
.bp
diff --git a/sbin/fsck_ffs/SMM.doc/4.t b/sbin/fsck_ffs/SMM.doc/4.t
index a071d2593ac..e24b77d516d 100644
--- a/sbin/fsck_ffs/SMM.doc/4.t
+++ b/sbin/fsck_ffs/SMM.doc/4.t
@@ -1,5 +1,5 @@
-.\" $OpenBSD: 4.t,v 1.2 1996/06/23 14:30:39 deraadt Exp $
-.\" $NetBSD: 4.t,v 1.2 1995/03/18 14:56:12 cgd Exp $
+.\" $OpenBSD: 4.t,v 1.3 1996/10/20 08:36:46 tholo Exp $
+.\" $NetBSD: 4.t,v 1.3 1996/04/05 01:45:48 cgd Exp $
.\"
.\" Copyright (c) 1982, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -34,20 +34,20 @@
.\"
.\" @(#)4.t 8.1 (Berkeley) 6/5/93
.\"
-.ds RH Appendix A \- Fsck Error Conditions
+.ds RH Appendix A \- Fsck_ffs Error Conditions
.NH
-Appendix A \- Fsck Error Conditions
+Appendix A \- Fsck_ffs Error Conditions
.NH 2
Conventions
.PP
-.I Fsck
+.I Fsck_ffs
is
a multi-pass file system check program.
Each file system pass invokes a different Phase of the
-.I fsck
+.I fsck_ffs
program.
After the initial setup,
-.I fsck
+.I fsck_ffs
performs successive Phases over each file system,
checking blocks and sizes,
path-names,
@@ -58,7 +58,7 @@ and the map of free blocks,
and performs some cleanup.
.LP
Normally
-.I fsck
+.I fsck_ffs
is run non-interactively to
.I preen
the file systems after an unclean halt.
@@ -66,15 +66,15 @@ While preen'ing a file system,
it will only fix corruptions that are expected
to occur from an unclean halt.
These actions are a proper subset of the actions that
-.I fsck
+.I fsck_ffs
will take when it is running interactively.
Throughout this appendix many errors have several options
that the operator can take.
When an inconsistency is detected,
-.I fsck
+.I fsck_ffs
reports the error condition to the operator.
If a response is required,
-.I fsck
+.I fsck_ffs
prints a prompt message and
waits for a response.
When preen'ing most errors are fatal.
@@ -86,7 +86,7 @@ the possible responses, and the related error conditions.
The error conditions are organized by the
.I Phase
of the
-.I fsck
+.I fsck_ffs
program in which they can occur.
The error conditions that may occur
in more than one Phase
@@ -112,12 +112,12 @@ when the file system is being preen'ed.
.B "\fIC\fP option?"
.br
\fIC\fP is not a legal option to
-.I fsck ;
+.I fsck_ffs ;
legal options are \-b, \-c, \-y, \-n, and \-p.
-.I Fsck
+.I Fsck_ffs
terminates on this error condition.
See the
-.I fsck (8)
+.I fsck_ffs (8)
manual entry for further detail.
.sp
.LP
@@ -129,11 +129,11 @@ manual entry for further detail.
.br
.B "cannot alloc NNN bytes for lncntp"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request for memory for its virtual
memory tables failed.
This should never happen.
-.I Fsck
+.I Fsck_ffs
terminates on this error condition.
See a guru.
.sp
@@ -144,17 +144,17 @@ The file system checklist file
\fIF\fP (usually
.I /etc/fstab )
can not be opened for reading.
-.I Fsck
+.I Fsck_ffs
terminates on this error condition.
Check access modes of \fIF\fP.
.sp
.LP
.B "Can't stat root"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request for statistics about the root directory ``/'' failed.
This should never happen.
-.I Fsck
+.I Fsck_ffs
terminates on this error condition.
See a guru.
.sp
@@ -163,7 +163,7 @@ See a guru.
.br
.B "Can't make sense out of name \fIF\fP"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request for statistics about the file system \fIF\fP failed.
When running manually,
it ignores this file system
@@ -173,7 +173,7 @@ Check access modes of \fIF\fP.
.LP
.B "Can't open \fIF\fP"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request attempt to open the file system \fIF\fP failed.
When running manually, it ignores this file system
and continues checking the next file system given.
@@ -183,7 +183,7 @@ Check access modes of \fIF\fP.
.B "\fIF\fP: (NO WRITE)"
.br
Either the \-n flag was specified or
-.I fsck 's
+.I fsck_ffs 's
attempt to open the file system \fIF\fP for writing failed.
When running manually,
all the diagnostics are printed out,
@@ -193,7 +193,7 @@ but no modifications are attempted to fix them.
.B "file is not a block or character device; OK"
.br
You have given
-.I fsck
+.I fsck_ffs
a regular file name by mistake.
Check the type of the file specified.
.LP
@@ -275,9 +275,9 @@ and will be followed by the message:
.br
.B "\fIF\fP: BAD SUPER BLOCK: \fIB\fP"
.br
-.B "USE -b OPTION TO FSCK TO SPECIFY LOCATION OF AN ALTERNATE"
+.B "USE -b OPTION TO FSCK_FFS TO SPECIFY LOCATION OF AN ALTERNATE"
.br
-.B "SUPER-BLOCK TO SUPPLY NEEDED INFORMATION; SEE fsck(8)."
+.B "SUPER-BLOCK TO SUPPLY NEEDED INFORMATION; SEE fsck_ffs(8)."
.br
The super block has been corrupted.
An alternative super block must be selected from among those
@@ -290,7 +290,7 @@ specifying \-b 32 is a good first choice.
.LP
.B "INTERNAL INCONSISTENCY: \fIM\fP"
.br
-.I Fsck 's
+.I Fsck_ffs 's
has had an internal panic, whose message is specified as \fIM\fP.
This should never happen.
See a guru.
@@ -298,7 +298,7 @@ See a guru.
.LP
.B "CAN NOT SEEK: BLK \fIB\fP (CONTINUE)"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request for moving to a specified block number \fIB\fP in
the file system failed.
This should never happen.
@@ -311,11 +311,11 @@ Often,
however the problem will persist.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
If the block was part of the virtual memory buffer
cache,
-.I fsck
+.I fsck_ffs
will terminate with the message ``Fatal I/O error''.
.IP NO
terminate the program.
@@ -323,7 +323,7 @@ terminate the program.
.LP
.B "CAN NOT READ: BLK \fIB\fP (CONTINUE)"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request for reading a specified block number \fIB\fP in
the file system failed.
This should never happen.
@@ -338,7 +338,7 @@ It will retry the read and print out the message:
.br
where \fIN\fP indicates the sectors that could not be read.
If
-.I fsck
+.I fsck_ffs
ever tries to write back one of the blocks on which the read failed
it will print the message:
.br
@@ -348,11 +348,11 @@ where \fIN\fP indicates the sector that was written with zero's.
If the disk is experiencing hardware problems, the problem will persist.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
If the block was part of the virtual memory buffer
cache,
-.I fsck
+.I fsck_ffs
will terminate with the message ``Fatal I/O error''.
.IP NO
terminate the program.
@@ -360,7 +360,7 @@ terminate the program.
.LP
.B "CAN NOT WRITE: BLK \fIB\fP (CONTINUE)"
.br
-.I Fsck 's
+.I Fsck_ffs 's
request for writing a specified block number \fIB\fP
in the file system failed.
The disk is write-protected;
@@ -379,11 +379,11 @@ where \fIN\fP indicates the sectors that could not be written.
If the disk is experiencing hardware problems, the problem will persist.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
If the block was part of the virtual memory buffer
cache,
-.I fsck
+.I fsck_ffs
will terminate with the message ``Fatal I/O error''.
.IP NO
terminate the program.
@@ -393,7 +393,7 @@ terminate the program.
.br
An internal error has attempted to read non-existent inode \fIDDD\fP.
This error causes
-.I fsck
+.I fsck_ffs
to exit.
See a guru.
.NH 2
@@ -431,13 +431,13 @@ ignore this error condition.
.LP
.B "PARTIALLY TRUNCATED INODE I=\fII\fP (SALVAGE)"
.br
-.I Fsck
+.I Fsck_ffs
has found inode \fII\fP whose size is shorter than the number of
blocks allocated to it.
This condition should only occur if the system crashes while in the
midst of truncating a file.
When preen'ing the file system,
-.I fsck
+.I fsck_ffs
completes the truncation to the specified size.
.LP
Possible responses to SALVAGE are:
@@ -450,18 +450,18 @@ ignore this error condition.
.B "LINK COUNT TABLE OVERFLOW (CONTINUE)"
.br
An internal table for
-.I fsck
+.I fsck_ffs
containing allocated inodes with a link count of
zero cannot allocate more memory.
Increase the virtual memory for
-.I fsck .
+.I fsck_ffs .
.LP
Possible responses to the CONTINUE prompt are:
.IP YES
continue with the program.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
If another allocated inode with a zero link count is found,
this error condition is repeated.
@@ -496,7 +496,7 @@ ignore the rest of the blocks in this inode
and continue checking with the next inode in the file system.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
.IP NO
terminate the program.
@@ -505,9 +505,9 @@ terminate the program.
.B "BAD STATE DDD TO BLKERR"
.br
An internal error has scrambled
-.I fsck 's
+.I fsck_ffs 's
state map to have the impossible value \fIDDD\fP.
-.I Fsck
+.I Fsck_ffs
exits immediately.
See a guru.
.sp
@@ -536,7 +536,7 @@ ignore the rest of the blocks in this inode
and continue checking with the next inode in the file system.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
.IP NO
terminate the program.
@@ -545,17 +545,17 @@ terminate the program.
.B "DUP TABLE OVERFLOW (CONTINUE)"
.br
An internal table in
-.I fsck
+.I fsck_ffs
containing duplicate block numbers cannot allocate any more space.
Increase the amount of virtual memory available to
-.I fsck .
+.I fsck_ffs .
.LP
Possible responses to the CONTINUE prompt are:
.IP YES
continue with the program.
This error condition will not allow a complete check of the file system.
A second run of
-.I fsck
+.I fsck_ffs
should be made to re-check this file system.
If another duplicate block is found, this error condition will repeat.
.IP NO
@@ -630,12 +630,12 @@ The files and directories usually found in the root will be recovered
in Phase 3 and put into
.I lost+found .
If the attempt to allocate the root fails,
-.I fsck
+.I fsck_ffs
will exit with the message:
.br
.B "CANNOT ALLOCATE ROOT INODE" .
.IP NO
-.I fsck
+.I fsck_ffs
will exit.
.sp
.LP
@@ -652,12 +652,12 @@ The files and directories usually found in the root will be recovered
in Phase 3 and put into
.I lost+found .
If the attempt to allocate the root fails,
-.I fsck
+.I fsck_ffs
will exit with the message:
.br
.B "CANNOT ALLOCATE ROOT INODE" .
.IP NO
-.I fsck
+.I fsck_ffs
will then prompt with
.B "FIX"
.LP
@@ -683,12 +683,12 @@ The files and directories usually found in the root will be recovered
in Phase 3 and put into
.I lost+found .
If the attempt to allocate the root fails,
-.I fsck
+.I fsck_ffs
will exit with the message:
.br
.B "CANNOT ALLOCATE ROOT INODE" .
.IP NO
-.I fsck
+.I fsck_ffs
will then prompt with
.B "CONTINUE" .
.LP
@@ -837,12 +837,12 @@ leave the directory unchanged.
.B "CANNOT FIX, FIRST ENTRY IN DIRECTORY CONTAINS \fIF\fP"
.br
A directory \fII\fP has been found whose first entry is \fIF\fP.
-.I Fsck
+.I Fsck_ffs
cannot resolve this problem.
The file system should be mounted and the offending entry \fIF\fP
moved elsewhere.
The file system should then be unmounted and
-.I fsck
+.I fsck_ffs
should be run again.
.sp
.LP
@@ -851,7 +851,7 @@ should be run again.
.B "CANNOT FIX, INSUFFICIENT SPACE TO ADD `.'"
.br
A directory \fII\fP has been found whose first entry is not `.'.
-.I Fsck
+.I Fsck_ffs
cannot resolve this problem as it should never happen.
See a guru.
.sp
@@ -897,12 +897,12 @@ leave the directory unchanged.
.B "CANNOT FIX, SECOND ENTRY IN DIRECTORY CONTAINS \fIF\fP"
.br
A directory \fII\fP has been found whose second entry is \fIF\fP.
-.I Fsck
+.I Fsck_ffs
cannot resolve this problem.
The file system should be mounted and the offending entry \fIF\fP
moved elsewhere.
The file system should then be unmounted and
-.I fsck
+.I fsck_ffs
should be run again.
.sp
.LP
@@ -911,12 +911,12 @@ should be run again.
.B "CANNOT FIX, INSUFFICIENT SPACE TO ADD `..'"
.br
A directory \fII\fP has been found whose second entry is not `..'.
-.I Fsck
+.I Fsck_ffs
cannot resolve this problem.
The file system should be mounted and the second entry in the directory
moved elsewhere.
The file system should then be unmounted and
-.I fsck
+.I fsck_ffs
should be run again.
.sp
.LP
@@ -933,7 +933,7 @@ leave the directory unchanged.
.LP
.B "\fIN\fP IS AN EXTRANEOUS HARD LINK TO A DIRECTORY \fID\fP (REMOVE)
.br
-.I Fsck
+.I Fsck_ffs
has found a hard link, \fIN\fP, to a directory, \fID\fP.
When preen'ing the extraneous links are ignored.
.LP
@@ -948,7 +948,7 @@ ignore the error condition.
.br
An internal error has caused an impossible state \fIS\fP to be passed to the
routine that descends the file system directory structure.
-.I Fsck
+.I Fsck_ffs
exits.
See a guru.
.sp
@@ -957,7 +957,7 @@ See a guru.
.br
An internal error has caused an impossible state \fIS\fP to be returned
from the routine that descends the file system directory structure.
-.I Fsck
+.I Fsck_ffs
exits.
See a guru.
.sp
@@ -966,7 +966,7 @@ See a guru.
.br
An internal error has caused an impossible state \fIS\fP to be assigned
to the root inode.
-.I Fsck
+.I Fsck_ffs
exits.
See a guru.
.NH 2
@@ -1011,7 +1011,7 @@ There is no
.I lost+found
directory in the root directory of the file system;
When preen'ing
-.I fsck
+.I fsck_ffs
tries to create a \fIlost+found\fP directory.
.LP
Possible responses to the CREATE prompt are:
@@ -1072,7 +1072,7 @@ the
.I lost+found
directory is expanded to make room for the new entry.
If the attempted expansion fails
-.I fsck
+.I fsck_ffs
prints the message:
.br
.B "SORRY. NO SPACE IN lost+found DIRECTORY"
@@ -1119,7 +1119,7 @@ ignore the error condition.
.br
An internal error has caused an impossible state \fIS\fP to be passed to the
routine that descends the file system directory structure.
-.I Fsck
+.I Fsck_ffs
exits.
See a guru.
.NH 2
@@ -1183,7 +1183,7 @@ There is no
.I lost+found
directory in the root directory of the file system;
When preen'ing
-.I fsck
+.I fsck_ffs
tries to create a \fIlost+found\fP directory.
.LP
Possible responses to the CREATE prompt are:
@@ -1244,7 +1244,7 @@ the
.I lost+found
directory is expanded to make room for the new entry.
If the attempted expansion fails
-.I fsck
+.I fsck_ffs
prints the message:
.br
.B "SORRY. NO SPACE IN lost+found DIRECTORY"
@@ -1269,7 +1269,7 @@ When preen'ing the link count is adjusted unless the number of references
is increasing, a condition that should never occur unless precipitated
by a hardware failure.
When the number of references is increasing under preen mode,
-.I fsck
+.I fsck_ffs
exits with the message:
.br
.B "LINK COUNT INCREASING"
@@ -1399,14 +1399,14 @@ The numbers in parenthesis breaks the free count down into
.br
This is an advisory message indicating that
the root file system has been modified by
-.I fsck.
+.I fsck_ffs.
If UNIX is not rebooted immediately,
the work done by
-.I fsck
+.I fsck_ffs
may be undone by the in-core copies of tables
UNIX keeps.
When preen'ing,
-.I fsck
+.I fsck_ffs
will exit with a code of 4.
The standard auto-reboot script distributed with 4.3BSD
interprets an exit code of 4 by issuing a reboot system call.
@@ -1416,12 +1416,12 @@ interprets an exit code of 4 by issuing a reboot system call.
.br
This is an advisory message indicating that
the current file system was modified by
-.I fsck.
+.I fsck_ffs.
If this file system is mounted or is the current root file system,
-.I fsck
+.I fsck_ffs
should be halted and UNIX rebooted.
If UNIX is not rebooted immediately,
the work done by
-.I fsck
+.I fsck_ffs
may be undone by the in-core copies of tables
UNIX keeps.
diff --git a/sbin/fsck_ffs/SMM.doc/Makefile b/sbin/fsck_ffs/SMM.doc/Makefile
index 6000fd3e54d..c7dff5b3c46 100644
--- a/sbin/fsck_ffs/SMM.doc/Makefile
+++ b/sbin/fsck_ffs/SMM.doc/Makefile
@@ -1,5 +1,5 @@
-# $OpenBSD: Makefile,v 1.3 1996/06/23 14:30:39 deraadt Exp $
-# $NetBSD: Makefile,v 1.2 1995/03/18 14:56:15 cgd Exp $
+# $OpenBSD: Makefile,v 1.4 1996/10/20 08:36:47 tholo Exp $
+# $NetBSD: Makefile,v 1.3 1996/04/05 01:45:49 cgd Exp $
DIR= smm/03.fsck_ffs
SRCS= 0.t 1.t 2.t 3.t 4.t
diff --git a/sbin/fsck_ffs/dir.c b/sbin/fsck_ffs/dir.c
index e22fd4a3bea..6bd11ba8e24 100644
--- a/sbin/fsck_ffs/dir.c
+++ b/sbin/fsck_ffs/dir.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: dir.c,v 1.2 1996/06/23 14:30:26 deraadt Exp $ */
-/* $NetBSD: dir.c,v 1.17 1995/03/18 14:55:40 cgd Exp $ */
+/* $OpenBSD: dir.c,v 1.3 1996/10/20 08:36:30 tholo Exp $ */
+/* $NetBSD: dir.c,v 1.20 1996/09/27 22:45:11 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)dir.c 8.5 (Berkeley) 12/8/94";
#else
-static char rcsid[] = "$OpenBSD: dir.c,v 1.2 1996/06/23 14:30:26 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: dir.c,v 1.3 1996/10/20 08:36:30 tholo Exp $";
#endif
#endif /* not lint */
@@ -53,6 +53,7 @@ static char rcsid[] = "$OpenBSD: dir.c,v 1.2 1996/06/23 14:30:26 deraadt Exp $";
#include <string.h>
#include "fsck.h"
+#include "fsutil.h"
#include "extern.h"
char *lfname = "lost+found";
@@ -67,11 +68,13 @@ struct odirtemplate odirhead = {
0, DIRBLKSIZ - 12, 2, ".."
};
-int expanddir __P((struct dinode *, char *));
-void freedir __P((ino_t, ino_t));
-struct direct *fsck_readdir();
-struct bufarea *getdirblk();
-int lftempname __P((char *, ino_t));
+static int expanddir __P((struct dinode *, char *));
+static void freedir __P((ino_t, ino_t));
+static struct direct *fsck_readdir __P((struct inodesc *));
+static struct bufarea *getdirblk __P((daddr_t, long));
+static int lftempname __P((char *, ino_t));
+static int mkentry __P((struct inodesc *));
+static int chgino __P((struct inodesc *));
/*
* Propagate connected state through the tree.
@@ -79,24 +82,34 @@ int lftempname __P((char *, ino_t));
void
propagate()
{
- register struct inoinfo **inpp, *inp;
+ register struct inoinfo **inpp, *inp, *pinp;
struct inoinfo **inpend;
- long change;
+ /*
+ * Create a list of children for each directory.
+ */
inpend = &inpsort[inplast];
- do {
- change = 0;
- for (inpp = inpsort; inpp < inpend; inpp++) {
- inp = *inpp;
- if (inp->i_parent == 0)
- continue;
- if (statemap[inp->i_parent] == DFOUND &&
- statemap[inp->i_number] == DSTATE) {
- statemap[inp->i_number] = DFOUND;
- change++;
- }
- }
- } while (change > 0);
+ for (inpp = inpsort; inpp < inpend; inpp++) {
+ inp = *inpp;
+ if (inp->i_parent == 0 ||
+ inp->i_number == ROOTINO)
+ continue;
+ pinp = getinoinfo(inp->i_parent);
+ inp->i_parentp = pinp;
+ inp->i_sibling = pinp->i_child;
+ pinp->i_child = inp;
+ }
+ inp = getinoinfo(ROOTINO);
+ while (inp) {
+ statemap[inp->i_number] = DFOUND;
+ if (inp->i_child &&
+ statemap[inp->i_child->i_number] == DSTATE)
+ inp = inp->i_child;
+ else if (inp->i_sibling)
+ inp = inp->i_sibling;
+ else
+ inp = inp->i_parentp;
+ }
}
/*
@@ -164,7 +177,7 @@ dirscan(idesc)
/*
* get next entry in a directory.
*/
-struct direct *
+static struct direct *
fsck_readdir(idesc)
register struct inodesc *idesc;
{
@@ -334,7 +347,7 @@ adjust(idesc, lcnt)
}
}
-int
+static int
mkentry(idesc)
struct inodesc *idesc;
{
@@ -379,7 +392,7 @@ mkentry(idesc)
return (ALTERED|STOP);
}
-int
+static int
chgino(idesc)
struct inodesc *idesc;
{
@@ -490,9 +503,9 @@ linkup(orphan, parentdir)
dp->di_nlink++;
inodirty();
lncntp[lfdir]++;
- pwarn("DIR I=%lu CONNECTED. ", orphan);
+ pwarn("DIR I=%u CONNECTED. ", orphan);
if (parentdir != (ino_t)-1)
- printf("PARENT WAS I=%lu\n", parentdir);
+ printf("PARENT WAS I=%u\n", parentdir);
if (preen == 0)
printf("\n");
}
@@ -559,7 +572,7 @@ makeentry(parent, ino, name)
/*
* Attempt to expand the size of a directory
*/
-int
+static int
expanddir(dp, name)
register struct dinode *dp;
char *name;
@@ -672,7 +685,7 @@ allocdir(parent, request, mode)
/*
* free a directory inode
*/
-void
+static void
freedir(ino, parent)
ino_t ino, parent;
{
@@ -689,7 +702,7 @@ freedir(ino, parent)
/*
* generate a temporary name for the lost+found directory.
*/
-int
+static int
lftempname(bufp, ino)
char *bufp;
ino_t ino;
@@ -716,7 +729,7 @@ lftempname(bufp, ino)
* Get a directory block.
* Insure that it is held until another is requested.
*/
-struct bufarea *
+static struct bufarea *
getdirblk(blkno, size)
daddr_t blkno;
long size;
diff --git a/sbin/fsck_ffs/extern.h b/sbin/fsck_ffs/extern.h
index fc8d21c7801..4c8bb497d90 100644
--- a/sbin/fsck_ffs/extern.h
+++ b/sbin/fsck_ffs/extern.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: extern.h,v 1.2 1996/06/23 14:30:27 deraadt Exp $ */
-/* $NetBSD: extern.h,v 1.4 1995/04/12 21:24:07 mycroft Exp $ */
+/* $OpenBSD: extern.h,v 1.3 1996/10/20 08:36:31 tholo Exp $ */
+/* $NetBSD: extern.h,v 1.6 1996/09/27 22:45:12 christos Exp $ */
/*
* Copyright (c) 1994 James A. Jegers
@@ -25,47 +25,51 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-void adjust __P((struct inodesc *, short));
-int allocblk __P((long));
-int allocdir __P((ino_t, ino_t, int));
-void blkerror __P((ino_t, char *, daddr_t));
-int bread __P((int, char *, daddr_t, long));
-void bufinit();
-void bwrite __P((int, char *, daddr_t, long));
-void cacheino __P((struct dinode *, ino_t));
-int changeino __P((ino_t, char *, ino_t));
-int checkfstab __P((int, int, int (*)(), int (*)() ));
-int chkrange __P((daddr_t, int));
-void ckfini __P((int));
-int ckinode __P((struct dinode *, struct inodesc *));
-void clri __P((struct inodesc *, char *, int));
-int dircheck __P((struct inodesc *, struct direct *));
-void direrror __P((ino_t, char *));
-int dirscan __P((struct inodesc *));
-int dofix __P((struct inodesc *, char *));
-void fileerror __P((ino_t, ino_t, char *));
-int findino __P((struct inodesc *));
-int findname __P((struct inodesc *));
-void flush __P((int, struct bufarea *));
-void freeblk __P((daddr_t, long));
-void freeino __P((ino_t));
-void freeinodebuf();
-int ftypeok __P((struct dinode *));
-void getpathname __P((char *, ino_t, ino_t));
-void inocleanup();
-void inodirty();
-int linkup __P((ino_t, ino_t));
-int makeentry __P((ino_t, ino_t, char *));
-void pass1();
-void pass1b();
-void pass2();
-void pass3();
-void pass4();
-int pass4check();
-void pass5();
-void pinode __P((ino_t));
-void propagate();
-int reply __P((char *));
-void resetinodebuf();
-int setup __P((char *));
-
+void adjust __P((struct inodesc *, short));
+int allocblk __P((long));
+int allocdir __P((ino_t, ino_t, int));
+void blkerror __P((ino_t, char *, daddr_t));
+int bread __P((int, char *, daddr_t, long));
+void bufinit __P((void));
+void bwrite __P((int, char *, daddr_t, long));
+void cacheino __P((struct dinode *, ino_t));
+int changeino __P((ino_t, char *, ino_t));
+struct fstab;
+int chkrange __P((daddr_t, int));
+void ckfini __P((int));
+int ckinode __P((struct dinode *, struct inodesc *));
+void clri __P((struct inodesc *, char *, int));
+int dircheck __P((struct inodesc *, struct direct *));
+void direrror __P((ino_t, char *));
+int dirscan __P((struct inodesc *));
+int dofix __P((struct inodesc *, char *));
+void fileerror __P((ino_t, ino_t, char *));
+int findino __P((struct inodesc *));
+int findname __P((struct inodesc *));
+void flush __P((int, struct bufarea *));
+void freeblk __P((daddr_t, long));
+void freeino __P((ino_t));
+void freeinodebuf __P((void));
+int ftypeok __P((struct dinode *));
+void getpathname __P((char *, ino_t, ino_t));
+void inocleanup __P((void));
+void inodirty __P((void));
+int linkup __P((ino_t, ino_t));
+int makeentry __P((ino_t, ino_t, char *));
+void pass1 __P((void));
+void pass1b __P((void));
+void pass2 __P((void));
+void pass3 __P((void));
+void pass4 __P((void));
+int pass1check __P((struct inodesc *));
+int pass4check __P((struct inodesc *));
+void pass5 __P((void));
+void pinode __P((ino_t));
+void propagate __P((void));
+int reply __P((char *));
+void resetinodebuf __P((void));
+int setup __P((char *));
+struct dinode * getnextinode __P((ino_t));
+void catch __P((int));
+void catchquit __P((int));
+void voidquit __P((int));
diff --git a/sbin/fsck_ffs/fsck.h b/sbin/fsck_ffs/fsck.h
index f227e378d7b..23892c6346f 100644
--- a/sbin/fsck_ffs/fsck.h
+++ b/sbin/fsck_ffs/fsck.h
@@ -1,5 +1,5 @@
-/* $OpenBSD: fsck.h,v 1.3 1996/10/12 03:06:53 tholo Exp $ */
-/* $NetBSD: fsck.h,v 1.10 1995/04/12 21:24:09 mycroft Exp $ */
+/* $OpenBSD: fsck.h,v 1.4 1996/10/20 08:36:32 tholo Exp $ */
+/* $NetBSD: fsck.h,v 1.13 1996/10/11 20:15:46 thorpej Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -80,7 +80,7 @@ struct bufarea sblk; /* file system superblock */
struct bufarea cgblk; /* cylinder group blocks */
struct bufarea *pdirbp; /* current directory contents */
struct bufarea *pbp; /* current inode block */
-struct bufarea *getdatablk();
+struct bufarea *getdatablk __P((daddr_t, long));
#define dirty(bp) (bp)->b_dirty = 1
#define initbarea(bp) \
@@ -97,7 +97,8 @@ enum fixstate {DONTKNOW, NOFIX, FIX, IGNORE};
struct inodesc {
enum fixstate id_fix; /* policy on fixing errors */
- int (*id_func)(); /* function to be applied to blocks of inode */
+ int (*id_func) /* function to be applied to blocks of inode */
+ __P((struct inodesc *));
ino_t id_number; /* inode number described */
ino_t id_parent; /* for DATA nodes, their parent */
daddr_t id_blkno; /* current block number being examined */
@@ -155,6 +156,7 @@ struct zlncnt *zlnhead; /* head of zero link count list */
*/
struct inoinfo {
struct inoinfo *i_nexthash; /* next entry in hash chain */
+ struct inoinfo *i_child, *i_sibling, *i_parentp;
ino_t i_number; /* inode number of this entry */
ino_t i_parent; /* inode number of parent */
ino_t i_dotdot; /* inode number of `..' */
@@ -164,7 +166,6 @@ struct inoinfo {
} **inphead, **inpsort;
long numdirs, listmax, inplast;
-char *cdevname; /* name of device being checked */
long dev_bsize; /* computed value of DEV_BSIZE */
long secsize; /* actual disk sector size */
char nflag; /* assume a no response */
@@ -175,14 +176,13 @@ int cvtlevel; /* convert to newer file system format */
int doinglevel1; /* converting to new cylinder group format */
int doinglevel2; /* converting to new inode format */
int newinofmt; /* filesystem has new inode format */
-char preen; /* just fix normal inconsistencies */
-char hotroot; /* checking root device */
+int preen; /* just fix normal inconsistencies */
char havesb; /* superblock has been read */
char skipclean; /* skip clean file systems if preening */
int fsmodified; /* 1 => write done to file system */
int fsreadfd; /* file descriptor for reading file system */
int fswritefd; /* file descriptor for writing file system */
-int rerun; /* rerun fsck. Only used in non-preen mode */
+int rerun; /* rerun fsck. Only used in non-preen mode */
daddr_t maxfsblock; /* number of blocks in the file system */
char *blockmap; /* ptr to primary blk allocation map */
@@ -212,8 +212,7 @@ struct dinode zino;
#define ALTERED 0x08
#define FOUND 0x10
-time_t time();
-struct dinode *ginode();
-struct inoinfo *getinoinfo();
-void getblk();
-ino_t allocino();
+struct dinode *ginode __P((ino_t));
+struct inoinfo *getinoinfo __P((ino_t));
+void getblk __P((struct bufarea *, daddr_t, long));
+ino_t allocino __P((ino_t, int));
diff --git a/sbin/fsck_ffs/fsck.8 b/sbin/fsck_ffs/fsck_ffs.8
index 64a54368291..9969379596d 100644
--- a/sbin/fsck_ffs/fsck.8
+++ b/sbin/fsck_ffs/fsck_ffs.8
@@ -1,5 +1,5 @@
-.\" $OpenBSD: fsck.8,v 1.3 1996/10/12 03:06:52 tholo Exp $
-.\" $NetBSD: fsck.8,v 1.10 1995/07/12 01:49:16 cgd Exp $
+.\" $OpenBSD: fsck_ffs.8,v 1.1 1996/10/20 08:36:33 tholo Exp $
+.\" $NetBSD: fsck_ffs.8,v 1.12 1996/09/23 16:18:34 christos Exp $
.\"
.\" Copyright (c) 1980, 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -35,21 +35,20 @@
.\" @(#)fsck.8 8.3 (Berkeley) 11/29/94
.\"
.Dd November 29, 1994
-.Dt FSCK 8
+.Dt FSCK_FFS 8
.Os BSD 4
.Sh NAME
-.Nm fsck
-.Nd filesystem consistency check and interactive repair
+.Nm fsck_ffs, fsck
+.Nd Fast File System consistency check and interactive repair
.Sh SYNOPSIS
-.Nm fsck
+.Nm fsck_ffs
.Fl p
.Op Fl f
.Op Fl m Ar mode
-.Nm fsck
+.Nm fsck_ffs
.Op Fl f
.Op Fl b Ar block#
.Op Fl c Ar level
-.Op Fl l Ar maxparallel
.Op Fl y
.Op Fl n
.Op Fl m Ar mode
@@ -57,13 +56,13 @@
.Ar ...
.Sh DESCRIPTION
The first form of
-.Nm fsck
+.Nm fsck_ffs
preens a standard set of filesystems or the specified filesystems.
It is normally used in the script
.Pa /etc/rc
during automatic reboot.
Here
-.Nm fsck
+.Nm fsck_ffs
reads the table
.Pa /etc/fstab
to determine which filesystems to check.
@@ -94,7 +93,7 @@ Counts in the super-block wrong
.El
.Pp
These are the only inconsistencies that
-.Nm fsck
+.Nm fsck_ffs
with the
.Fl p
option will correct; if it encounters other inconsistencies, it exits
@@ -102,7 +101,7 @@ with an abnormal return status and an automatic reboot will then fail.
For each corrected inconsistency one or more lines will be printed
identifying the filesystem on which the correction will take place,
and the nature of the correction. After successfully correcting a filesystem,
-.Nm fsck
+.Nm fsck_ffs
will print the number of files on that filesystem,
the number of used and free blocks,
and the percentage of fragmentation.
@@ -110,7 +109,7 @@ and the percentage of fragmentation.
If sent a
.Dv QUIT
signal,
-.Nm fsck
+.Nm fsck_ffs
will finish the filesystem checks, then exit with an abnormal
return status that causes an automatic reboot to fail.
This is useful when you want to finish the filesystem checks during an
@@ -120,7 +119,7 @@ but do not want the machine to come up multiuser after the checks complete.
Without the
.Fl p
option,
-.Nm fsck
+.Nm fsck_ffs
audits and interactively repairs inconsistent conditions for filesystems.
If the filesystem is inconsistent the operator is prompted for concurrence
before each correction is attempted.
@@ -136,7 +135,7 @@ is to wait for the operator to respond
or
.Li no .
If the operator does not have write permission on the filesystem
-.Nm fsck
+.Nm fsck_ffs
will default to a
.Fl n
action.
@@ -150,7 +149,7 @@ and
combined.
.Pp
The following flags are interpreted by
-.Nm fsck .
+.Nm fsck_ffs .
.Bl -tag -width indent
.It Fl f
Force checking of file systems. Normally, if a file system is cleanly
@@ -165,12 +164,6 @@ to check the file system, regardless of the state of the clean flag.
Use the block specified immediately after the flag as
the super block for the filesystem. Block 32 is usually
an alternate super block.
-.It Fl l
-Limit the number of parallel checks to the number specified in the following
-argument.
-By default, the limit is the number of disks, running one process per disk.
-If a smaller limit is given, the disks are checked round-robin, one filesystem
-at a time.
.It Fl m
Use the mode specified in octal immediately after the flag as the
permission bits to use when creating the
@@ -181,12 +174,12 @@ by all users on the system should use a more restrictive
set of permissions such as 700.
.It Fl y
Assume a yes response to all questions asked by
-.Nm fsck ;
+.Nm fsck_ffs ;
this should be used with great caution as this is a free license
to continue after essentially unlimited trouble has been encountered.
.It Fl n
Assume a no response to all questions asked by
-.Nm fsck
+.Nm fsck_ffs
except for
.Ql CONTINUE? ,
which is assumed to be affirmative;
@@ -211,7 +204,7 @@ If maxcontig is equal to one, delete any existing segment maps.
.El
.Pp
In interactive mode,
-.Nm fsck
+.Nm fsck_ffs
will list the conversion to be made
and ask whether the conversion should be done.
If a negative answer is given,
@@ -227,7 +220,7 @@ first line of output from
.El
.Pp
If no filesystems are given to
-.Nm fsck
+.Nm fsck_ffs
then a default list of filesystems is read from
the file
.Pa /etc/fstab .
@@ -260,8 +253,6 @@ File pointing to unallocated inode.
.It
Inode number out of range.
.It
-Holes in directories.
-.It
Dot or dot-dot not the first two entries of a directory
or having the wrong inode number.
.El
@@ -297,7 +288,7 @@ contains default list of filesystems to check.
.El
.Sh DIAGNOSTICS
The diagnostics produced by
-.Nm fsck
+.Nm fsck_ffs
are fully enumerated and explained in Appendix A of
.Rs
.%T "Fsck \- The UNIX File System Check Program"
diff --git a/sbin/fsck_ffs/inode.c b/sbin/fsck_ffs/inode.c
index 59187d1c220..8c5c051116b 100644
--- a/sbin/fsck_ffs/inode.c
+++ b/sbin/fsck_ffs/inode.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: inode.c,v 1.7 1996/10/12 03:06:54 tholo Exp $ */
-/* $NetBSD: inode.c,v 1.18 1996/05/21 16:58:12 mycroft Exp $ */
+/* $OpenBSD: inode.c,v 1.8 1996/10/20 08:36:34 tholo Exp $ */
+/* $NetBSD: inode.c,v 1.23 1996/10/11 20:15:47 thorpej Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)inode.c 8.5 (Berkeley) 2/8/95";
#else
-static char rcsid[] = "$OpenBSD: inode.c,v 1.7 1996/10/12 03:06:54 tholo Exp $";
+static char rcsid[] = "$OpenBSD: inode.c,v 1.8 1996/10/20 08:36:34 tholo Exp $";
#endif
#endif /* not lint */
@@ -55,11 +55,12 @@ static char rcsid[] = "$OpenBSD: inode.c,v 1.7 1996/10/12 03:06:54 tholo Exp $";
#include <string.h>
#include "fsck.h"
+#include "fsutil.h"
#include "extern.h"
static ino_t startinum;
-int iblock __P((struct inodesc *, long, quad_t));
+static int iblock __P((struct inodesc *, long, u_int64_t));
int
ckinode(dp, idesc)
@@ -69,7 +70,7 @@ ckinode(dp, idesc)
register ufs_daddr_t *ap;
long ret, n, ndb, offset;
struct dinode dino;
- quad_t remsize, sizepb;
+ u_int64_t remsize, sizepb;
mode_t mode;
char pathbuf[MAXPATHLEN + 1];
@@ -94,19 +95,18 @@ ckinode(dp, idesc)
if (idesc->id_type == DATA && ndb >= 0) {
/* An empty block in a directory XXX */
getpathname(pathbuf, idesc->id_number,
- idesc->id_number);
- pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
- pathbuf);
- if (reply("ADJUST LENGTH") == 1) {
+ idesc->id_number);
+ pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
+ pathbuf);
+ if (reply("ADJUST LENGTH") == 1) {
dp = ginode(idesc->id_number);
- dp->di_size = (ap - &dino.di_db[0]) *
+ dp->di_size = (ap - &dino.di_db[0]) *
sblock.fs_bsize;
printf(
"YOU MUST RERUN FSCK AFTERWARDS\n");
rerun = 1;
- inodirty();
-
- }
+ inodirty();
+ }
}
continue;
}
@@ -131,19 +131,19 @@ ckinode(dp, idesc)
if (idesc->id_type == DATA && remsize > 0) {
/* An empty block in a directory XXX */
getpathname(pathbuf, idesc->id_number,
- idesc->id_number);
- pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
- pathbuf);
- if (reply("ADJUST LENGTH") == 1) {
+ idesc->id_number);
+ pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
+ pathbuf);
+ if (reply("ADJUST LENGTH") == 1) {
dp = ginode(idesc->id_number);
- dp->di_size -= remsize;
+ dp->di_size -= remsize;
remsize = 0;
printf(
"YOU MUST RERUN FSCK AFTERWARDS\n");
rerun = 1;
- inodirty();
+ inodirty();
break;
- }
+ }
}
}
sizepb *= NINDIR(&sblock);
@@ -152,21 +152,20 @@ ckinode(dp, idesc)
return (KEEPON);
}
-int
+static int
iblock(idesc, ilevel, isize)
struct inodesc *idesc;
long ilevel;
- quad_t isize;
+ u_int64_t isize;
{
register daddr_t *ap;
register daddr_t *aplim;
register struct bufarea *bp;
- int i, n, (*func)(), nif;
- quad_t sizepb;
- char pathbuf[MAXPATHLEN + 1];
+ int i, n, (*func) __P((struct inodesc *)), nif;
+ u_int64_t sizepb;
char buf[BUFSIZ];
+ char pathbuf[MAXPATHLEN + 1];
struct dinode *dp;
- extern int pass1check();
if (idesc->id_type == ADDR) {
func = idesc->id_func;
@@ -189,7 +188,7 @@ iblock(idesc, ilevel, isize)
for (ap = &bp->b_un.b_indir[nif]; ap < aplim; ap++) {
if (*ap == 0)
continue;
- (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%lu",
+ (void)sprintf(buf, "PARTIALLY TRUNCATED INODE I=%u",
idesc->id_number);
if (dofix(idesc, buf)) {
*ap = 0;
@@ -214,20 +213,20 @@ iblock(idesc, ilevel, isize)
if (idesc->id_type == DATA && isize > 0) {
/* An empty block in a directory XXX */
getpathname(pathbuf, idesc->id_number,
- idesc->id_number);
- pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
- pathbuf);
- if (reply("ADJUST LENGTH") == 1) {
+ idesc->id_number);
+ pfatal("DIRECTORY %s: CONTAINS EMPTY BLOCKS",
+ pathbuf);
+ if (reply("ADJUST LENGTH") == 1) {
dp = ginode(idesc->id_number);
- dp->di_size -= isize;
+ dp->di_size -= isize;
isize = 0;
printf(
"YOU MUST RERUN FSCK AFTERWARDS\n");
rerun = 1;
- inodirty();
+ inodirty();
bp->b_flags &= ~B_INUSE;
return(STOP);
- }
+ }
}
}
isize -= sizepb;
@@ -253,9 +252,9 @@ chkrange(blk, cnt)
if (blk < cgdmin(&sblock, c)) {
if ((blk + cnt) > cgsblock(&sblock, c)) {
if (debug) {
- printf("blk %ld < cgdmin %ld;",
+ printf("blk %d < cgdmin %d;",
blk, cgdmin(&sblock, c));
- printf(" blk + cnt %ld > cgsbase %ld\n",
+ printf(" blk + cnt %d > cgsbase %d\n",
blk + cnt, cgsblock(&sblock, c));
}
return (1);
@@ -263,9 +262,9 @@ chkrange(blk, cnt)
} else {
if ((blk + cnt) > cgbase(&sblock, c+1)) {
if (debug) {
- printf("blk %ld >= cgdmin %ld;",
+ printf("blk %d >= cgdmin %d;",
blk, cgdmin(&sblock, c));
- printf(" blk + cnt %ld > sblock.fs_fpg %ld\n",
+ printf(" blk + cnt %d > sblock.fs_fpg %d\n",
blk+cnt, sblock.fs_fpg);
}
return (1);
@@ -391,6 +390,7 @@ cacheino(dp, inumber)
inpp = &inphead[inumber % numdirs];
inp->i_nexthash = *inpp;
*inpp = inp;
+ inp->i_child = inp->i_sibling = inp->i_parentp = 0;
if (inumber == ROOTINO)
inp->i_parent = ROOTINO;
else
@@ -514,7 +514,7 @@ pinode(ino)
struct passwd *pw;
time_t t;
- printf(" I=%lu ", ino);
+ printf(" I=%u ", ino);
if (ino < ROOTINO || ino > maxino)
return;
dp = ginode(ino);
@@ -527,7 +527,7 @@ pinode(ino)
printf("%u ", (unsigned)dp->di_uid);
printf("MODE=%o\n", dp->di_mode);
if (preen)
- printf("%s: ", cdevname);
+ printf("%s: ", cdevname());
printf("SIZE=%qu ", dp->di_size);
t = dp->di_mtime;
p = ctime(&t);
@@ -541,7 +541,7 @@ blkerror(ino, type, blk)
daddr_t blk;
{
- pfatal("%ld %s I=%lu", blk, type, ino);
+ pfatal("%d %s I=%u", blk, type, ino);
printf("\n");
switch (statemap[ino]) {
diff --git a/sbin/fsck_ffs/main.c b/sbin/fsck_ffs/main.c
index 0cf12d913bb..27908279056 100644
--- a/sbin/fsck_ffs/main.c
+++ b/sbin/fsck_ffs/main.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: main.c,v 1.5 1996/10/12 03:06:54 tholo Exp $ */
-/* $NetBSD: main.c,v 1.18.2.1 1995/11/01 00:06:18 jtc Exp $ */
+/* $OpenBSD: main.c,v 1.6 1996/10/20 08:36:35 tholo Exp $ */
+/* $NetBSD: main.c,v 1.22 1996/10/11 20:15:48 thorpej Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -44,7 +44,7 @@ static char copyright[] =
#if 0
static char sccsid[] = "@(#)main.c 8.2 (Berkeley) 1/23/94";
#else
-static char rcsid[] = "$OpenBSD: main.c,v 1.5 1996/10/12 03:06:54 tholo Exp $";
+static char rcsid[] = "$OpenBSD: main.c,v 1.6 1996/10/20 08:36:35 tholo Exp $";
#endif
#endif /* not lint */
@@ -62,23 +62,13 @@ static char rcsid[] = "$OpenBSD: main.c,v 1.5 1996/10/12 03:06:54 tholo Exp $";
#include "fsck.h"
#include "extern.h"
+#include "fsutil.h"
-void catch(), catchquit(), voidquit();
int returntosingle;
-int argtoi __P((int, char *, char *, int));
-int checkfilesys __P((char *, char *, long, int));
-int docheck __P((struct fstab *));
-
-void
-usage()
-{
- fprintf(stderr,
- "usage: fsck -p [-f] [-m mode]\n");
- fprintf(stderr,
- " fsck [-f] [-b block#] [-c level] [-l maxparallel] [-y] "
- "[-n] [-m mode] [filesystems]\n");
- exit(1);
-}
+int argtoi __P((int, char *, char *, int));
+int checkfilesys __P((char *, char *, long, int));
+int docheck __P((struct fstab *));
+int main __P((int, char *[]));
int
main(argc, argv)
@@ -86,8 +76,8 @@ main(argc, argv)
char *argv[];
{
int ch;
- int ret, maxrun = 0;
- extern char *optarg, *blockcheck();
+ int ret = 0;
+ extern char *optarg;
extern int optind;
sync();
@@ -117,10 +107,6 @@ main(argc, argv)
skipclean = 0;
break;
- case 'l':
- maxrun = argtoi('l', "number", optarg, 10);
- break;
-
case 'm':
lfmode = argtoi('m', "mode", optarg, 8);
if (lfmode &~ 07777)
@@ -141,7 +127,7 @@ main(argc, argv)
break;
default:
- usage();
+ errexit("%c option?\n", ch);
}
}
argc -= optind;
@@ -150,14 +136,14 @@ main(argc, argv)
(void)signal(SIGINT, catch);
if (preen)
(void)signal(SIGQUIT, catchquit);
- if (argc) {
+
+ if (argc)
while (argc-- > 0)
(void)checkfilesys(blockcheck(*argv++), 0, 0L, 0);
- exit(0);
- }
- ret = checkfstab(preen, maxrun, docheck, checkfilesys);
+
if (returntosingle)
- exit(2);
+ ret = 2;
+
exit(ret);
}
@@ -210,7 +196,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
if (preen && child)
(void)signal(SIGQUIT, voidquit);
- cdevname = filesys;
+ setcdevname(filesys, preen);
if (debug && preen)
pwarn("starting\n");
switch (setup(filesys)) {
@@ -225,7 +211,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
*/
if (preen == 0) {
printf("** Last Mounted on %s\n", sblock.fs_fsmnt);
- if (hotroot)
+ if (hotroot())
printf("** Root file system\n");
printf("** Phase 1 - Check Blocks and Sizes\n");
}
@@ -274,31 +260,31 @@ checkfilesys(filesys, mntpt, auxdata, child)
*/
n_ffree = sblock.fs_cstotal.cs_nffree;
n_bfree = sblock.fs_cstotal.cs_nbfree;
- pwarn("%ld files, %ld used, %ld free ",
+ pwarn("%d files, %d used, %d free ",
n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
- printf("(%ld frags, %ld blocks, %d.%d%% fragmentation)\n",
+ printf("(%d frags, %d blocks, %d.%d%% fragmentation)\n",
n_ffree, n_bfree, (n_ffree * 100) / sblock.fs_dsize,
((n_ffree * 1000 + sblock.fs_dsize / 2) / sblock.fs_dsize) % 10);
if (debug &&
(n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree))
- printf("%ld files missing\n", n_files);
+ printf("%d files missing\n", n_files);
if (debug) {
n_blks += sblock.fs_ncg *
(cgdmin(&sblock, 0) - cgsblock(&sblock, 0));
n_blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0);
n_blks += howmany(sblock.fs_cssize, sblock.fs_fsize);
if (n_blks -= maxfsblock - (n_ffree + sblock.fs_frag * n_bfree))
- printf("%ld blocks missing\n", n_blks);
+ printf("%d blocks missing\n", n_blks);
if (duplist != NULL) {
printf("The following duplicate blocks remain:");
for (dp = duplist; dp; dp = dp->next)
- printf(" %ld,", dp->dup);
+ printf(" %d,", dp->dup);
printf("\n");
}
if (zlnhead != NULL) {
printf("The following zero link count inodes remain:");
for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
- printf(" %lu,", zlnp->zlncnt);
+ printf(" %u,", zlnp->zlncnt);
printf("\n");
}
}
@@ -328,7 +314,7 @@ checkfilesys(filesys, mntpt, auxdata, child)
printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
if (rerun)
printf("\n***** PLEASE RERUN FSCK *****\n");
- if (hotroot) {
+ if (hotroot()) {
struct statfs stfs_buf;
/*
* We modified the root. Do a mount update on
diff --git a/sbin/fsck_ffs/pass1.c b/sbin/fsck_ffs/pass1.c
index a90635409e7..e35ed2b656a 100644
--- a/sbin/fsck_ffs/pass1.c
+++ b/sbin/fsck_ffs/pass1.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: pass1.c,v 1.3 1996/06/23 14:30:30 deraadt Exp $ */
-/* $NetBSD: pass1.c,v 1.14 1996/01/18 21:55:27 mycroft Exp $ */
+/* $OpenBSD: pass1.c,v 1.4 1996/10/20 08:36:36 tholo Exp $ */
+/* $NetBSD: pass1.c,v 1.16 1996/09/27 22:45:15 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pass1.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: pass1.c,v 1.3 1996/06/23 14:30:30 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pass1.c,v 1.4 1996/10/20 08:36:36 tholo Exp $";
#endif
#endif /* not lint */
@@ -54,12 +54,11 @@ static char rcsid[] = "$OpenBSD: pass1.c,v 1.3 1996/06/23 14:30:30 deraadt Exp $
#include "fsck.h"
#include "extern.h"
+#include "fsutil.h"
static daddr_t badblk;
static daddr_t dupblk;
-int pass1check();
-struct dinode *getnextinode();
-void checkinode __P((ino_t, struct inodesc *));
+static void checkinode __P((ino_t, struct inodesc *));
void
pass1()
@@ -103,7 +102,7 @@ pass1()
freeinodebuf();
}
-void
+static void
checkinode(inumber, idesc)
ino_t inumber;
register struct inodesc *idesc;
@@ -120,7 +119,7 @@ checkinode(inumber, idesc)
if (memcmp(dp->di_db, zino.di_db, NDADDR * sizeof(daddr_t)) ||
memcmp(dp->di_ib, zino.di_ib, NIADDR * sizeof(daddr_t)) ||
dp->di_mode || dp->di_size) {
- pfatal("PARTIALLY ALLOCATED INODE I=%lu", inumber);
+ pfatal("PARTIALLY ALLOCATED INODE I=%u", inumber);
if (reply("CLEAR") == 1) {
dp = ginode(inumber);
clearinode(dp);
@@ -170,8 +169,8 @@ checkinode(inumber, idesc)
errexit("cannot read symlink");
if (debug) {
symbuf[dp->di_size] = 0;
- printf("convert symlink %d(%s) of size %d\n",
- inumber, symbuf, (long)dp->di_size);
+ printf("convert symlink %d(%s) of size %qd\n",
+ inumber, symbuf, dp->di_size);
}
dp = ginode(inumber);
memcpy(dp->di_shortlink, symbuf, (long)dp->di_size);
@@ -196,7 +195,7 @@ checkinode(inumber, idesc)
for (j = ndb; j < NDADDR; j++)
if (dp->di_db[j] != 0) {
if (debug)
- printf("bad direct addr: %ld\n", dp->di_db[j]);
+ printf("bad direct addr: %d\n", dp->di_db[j]);
goto unknown;
}
for (j = 0, ndb -= NDADDR; ndb > 0; j++)
@@ -204,7 +203,7 @@ checkinode(inumber, idesc)
for (; j < NIADDR; j++)
if (dp->di_ib[j] != 0) {
if (debug)
- printf("bad indirect addr: %ld\n",
+ printf("bad indirect addr: %d\n",
dp->di_ib[j]);
goto unknown;
}
@@ -217,7 +216,7 @@ checkinode(inumber, idesc)
if (zlnp == NULL) {
pfatal("LINK COUNT TABLE OVERFLOW");
if (reply("CONTINUE") == 0)
- errexit("");
+ errexit("%s", "");
} else {
zlnp->zlncnt = inumber;
zlnp->next = zlnhead;
@@ -247,7 +246,7 @@ checkinode(inumber, idesc)
(void)ckinode(dp, idesc);
idesc->id_entryno *= btodb(sblock.fs_fsize);
if (dp->di_blocks != idesc->id_entryno) {
- pwarn("INCORRECT BLOCK COUNT I=%lu (%ld should be %ld)",
+ pwarn("INCORRECT BLOCK COUNT I=%u (%d should be %d)",
inumber, dp->di_blocks, idesc->id_entryno);
if (preen)
printf(" (CORRECTED)\n");
@@ -259,7 +258,7 @@ checkinode(inumber, idesc)
}
return;
unknown:
- pfatal("UNKNOWN FILE TYPE I=%lu", inumber);
+ pfatal("UNKNOWN FILE TYPE I=%u", inumber);
statemap[inumber] = FCLEAR;
if (reply("CLEAR") == 1) {
statemap[inumber] = USTATE;
@@ -282,12 +281,12 @@ pass1check(idesc)
if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) {
blkerror(idesc->id_number, "BAD", blkno);
if (badblk++ >= MAXBAD) {
- pwarn("EXCESSIVE BAD BLKS I=%lu",
+ pwarn("EXCESSIVE BAD BLKS I=%u",
idesc->id_number);
if (preen)
printf(" (SKIPPING)\n");
else if (reply("CONTINUE") == 0)
- errexit("");
+ errexit("%s", "");
return (STOP);
}
}
@@ -300,19 +299,19 @@ pass1check(idesc)
} else {
blkerror(idesc->id_number, "DUP", blkno);
if (dupblk++ >= MAXDUP) {
- pwarn("EXCESSIVE DUP BLKS I=%lu",
+ pwarn("EXCESSIVE DUP BLKS I=%u",
idesc->id_number);
if (preen)
printf(" (SKIPPING)\n");
else if (reply("CONTINUE") == 0)
- errexit("");
+ errexit("%s", "");
return (STOP);
}
new = (struct dups *)malloc(sizeof(struct dups));
if (new == NULL) {
pfatal("DUP TABLE OVERFLOW.");
if (reply("CONTINUE") == 0)
- errexit("");
+ errexit("%s", "");
return (STOP);
}
new->dup = blkno;
diff --git a/sbin/fsck_ffs/pass1b.c b/sbin/fsck_ffs/pass1b.c
index 084d7962a68..0624180bfdd 100644
--- a/sbin/fsck_ffs/pass1b.c
+++ b/sbin/fsck_ffs/pass1b.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: pass1b.c,v 1.2 1996/06/23 14:30:31 deraadt Exp $ */
-/* $NetBSD: pass1b.c,v 1.9 1995/03/18 14:55:51 cgd Exp $ */
+/* $OpenBSD: pass1b.c,v 1.3 1996/10/20 08:36:37 tholo Exp $ */
+/* $NetBSD: pass1b.c,v 1.10 1996/09/23 16:18:37 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pass1b.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: pass1b.c,v 1.2 1996/06/23 14:30:31 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pass1b.c,v 1.3 1996/10/20 08:36:37 tholo Exp $";
#endif
#endif /* not lint */
@@ -51,7 +51,7 @@ static char rcsid[] = "$OpenBSD: pass1b.c,v 1.2 1996/06/23 14:30:31 deraadt Exp
#include "fsck.h"
#include "extern.h"
-int pass1bcheck();
+static int pass1bcheck __P((struct inodesc *));
static struct dups *duphead;
void
@@ -82,7 +82,7 @@ pass1b()
}
}
-int
+static int
pass1bcheck(idesc)
register struct inodesc *idesc;
{
diff --git a/sbin/fsck_ffs/pass2.c b/sbin/fsck_ffs/pass2.c
index e62c2b9fca4..3b0d095d0b1 100644
--- a/sbin/fsck_ffs/pass2.c
+++ b/sbin/fsck_ffs/pass2.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: pass2.c,v 1.3 1996/06/23 14:30:31 deraadt Exp $ */
-/* $NetBSD: pass2.c,v 1.14 1996/05/21 15:32:16 mycroft Exp $ */
+/* $OpenBSD: pass2.c,v 1.4 1996/10/20 08:36:38 tholo Exp $ */
+/* $NetBSD: pass2.c,v 1.17 1996/09/27 22:45:15 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pass2.c 8.6 (Berkeley) 10/27/94";
#else
-static char rcsid[] = "$OpenBSD: pass2.c,v 1.3 1996/06/23 14:30:31 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pass2.c,v 1.4 1996/10/20 08:36:38 tholo Exp $";
#endif
#endif /* not lint */
@@ -51,12 +51,15 @@ static char rcsid[] = "$OpenBSD: pass2.c,v 1.3 1996/06/23 14:30:31 deraadt Exp $
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
#include "fsck.h"
+#include "fsutil.h"
#include "extern.h"
#define MINDIRSIZE (sizeof (struct dirtemplate))
-int pass2check(), blksort();
+static int pass2check __P((struct inodesc *));
+static int blksort __P((const void *, const void *));
void
pass2()
@@ -73,7 +76,7 @@ pass2()
case USTATE:
pfatal("ROOT INODE UNALLOCATED");
if (reply("ALLOCATE") == 0)
- errexit("");
+ errexit("%s", "");
if (allocdir(ROOTINO, ROOTINO, 0755) != ROOTINO)
errexit("CANNOT ALLOCATE ROOT INODE\n");
break;
@@ -87,7 +90,7 @@ pass2()
break;
}
if (reply("CONTINUE") == 0)
- errexit("");
+ errexit("%s", "");
break;
case FSTATE:
@@ -100,7 +103,7 @@ pass2()
break;
}
if (reply("FIX") == 0)
- errexit("");
+ errexit("%s", "");
dp = ginode(ROOTINO);
dp->di_mode &= ~IFMT;
dp->di_mode |= IFDIR;
@@ -113,7 +116,6 @@ pass2()
default:
errexit("BAD STATE %d FOR ROOT INODE", statemap[ROOTINO]);
}
- statemap[ROOTINO] = DFOUND;
if (newinofmt) {
statemap[WINO] = FSTATE;
typemap[WINO] = DT_WHT;
@@ -170,9 +172,6 @@ pass2()
inp = *inpp;
if (inp->i_parent == 0 || inp->i_isize == 0)
continue;
- if (statemap[inp->i_parent] == DFOUND &&
- statemap[inp->i_number] == DSTATE)
- statemap[inp->i_number] = DFOUND;
if (inp->i_dotdot == inp->i_parent ||
inp->i_dotdot == (ino_t)-1)
continue;
@@ -200,7 +199,7 @@ pass2()
propagate();
}
-int
+static int
pass2check(idesc)
struct inodesc *idesc;
{
@@ -413,10 +412,6 @@ again:
goto again;
case DSTATE:
- if (statemap[idesc->id_number] == DFOUND)
- statemap[dirp->d_ino] = DFOUND;
- /* fall through */
-
case DFOUND:
inp = getinoinfo(dirp->d_ino);
if (inp->i_parent != 0 && idesc->id_entryno > 2) {
@@ -460,10 +455,10 @@ again:
/*
* Routine to sort disk blocks.
*/
-int
+static int
blksort(inpp1, inpp2)
- struct inoinfo **inpp1, **inpp2;
+ const void *inpp1, *inpp2;
{
-
- return ((*inpp1)->i_blks[0] - (*inpp2)->i_blks[0]);
+ return ((* (struct inoinfo **) inpp1)->i_blks[0] -
+ (* (struct inoinfo **) inpp2)->i_blks[0]);
}
diff --git a/sbin/fsck_ffs/pass4.c b/sbin/fsck_ffs/pass4.c
index bc8518fc547..4c931c7f143 100644
--- a/sbin/fsck_ffs/pass4.c
+++ b/sbin/fsck_ffs/pass4.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: pass4.c,v 1.2 1996/06/23 14:30:32 deraadt Exp $ */
-/* $NetBSD: pass4.c,v 1.9 1995/03/18 14:55:56 cgd Exp $ */
+/* $OpenBSD: pass4.c,v 1.3 1996/10/20 08:36:39 tholo Exp $ */
+/* $NetBSD: pass4.c,v 1.11 1996/09/27 22:45:17 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pass4.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: pass4.c,v 1.2 1996/06/23 14:30:32 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pass4.c,v 1.3 1996/10/20 08:36:39 tholo Exp $";
#endif
#endif /* not lint */
@@ -48,6 +48,8 @@ static char rcsid[] = "$OpenBSD: pass4.c,v 1.2 1996/06/23 14:30:32 deraadt Exp $
#include <ufs/ffs/fs.h>
#include <stdlib.h>
#include <string.h>
+
+#include "fsutil.h"
#include "fsck.h"
#include "extern.h"
diff --git a/sbin/fsck_ffs/pass5.c b/sbin/fsck_ffs/pass5.c
index 42ad1c6b97e..ecfad373247 100644
--- a/sbin/fsck_ffs/pass5.c
+++ b/sbin/fsck_ffs/pass5.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: pass5.c,v 1.2 1996/06/23 14:30:33 deraadt Exp $ */
-/* $NetBSD: pass5.c,v 1.14 1995/03/21 01:30:16 cgd Exp $ */
+/* $OpenBSD: pass5.c,v 1.3 1996/10/20 08:36:40 tholo Exp $ */
+/* $NetBSD: pass5.c,v 1.16 1996/09/27 22:45:18 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)pass5.c 8.6 (Berkeley) 11/30/94";
#else
-static char rcsid[] = "$OpenBSD: pass5.c,v 1.2 1996/06/23 14:30:33 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: pass5.c,v 1.3 1996/10/20 08:36:40 tholo Exp $";
#endif
#endif /* not lint */
@@ -46,7 +46,10 @@ static char rcsid[] = "$OpenBSD: pass5.c,v 1.2 1996/06/23 14:30:33 deraadt Exp $
#include <sys/time.h>
#include <ufs/ufs/dinode.h>
#include <ufs/ffs/fs.h>
+#include <ufs/ffs/ffs_extern.h>
#include <string.h>
+
+#include "fsutil.h"
#include "fsck.h"
#include "extern.h"
@@ -225,7 +228,7 @@ pass5()
default:
if (j < ROOTINO)
break;
- errexit("BAD STATE %d FOR INODE I=%d",
+ errexit("BAD STATE %d FOR INODE I=%ld",
statemap[j], j);
}
}
diff --git a/sbin/fsck_ffs/preen.c b/sbin/fsck_ffs/preen.c
deleted file mode 100644
index 7af281c5ead..00000000000
--- a/sbin/fsck_ffs/preen.c
+++ /dev/null
@@ -1,381 +0,0 @@
-/* $OpenBSD: preen.c,v 1.4 1996/06/23 14:30:34 deraadt Exp $ */
-/* $NetBSD: preen.c,v 1.12 1996/05/11 14:27:50 mycroft Exp $ */
-
-/*
- * Copyright (c) 1990, 1993
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- * must display the following acknowledgement:
- * This product includes software developed by the University of
- * California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)preen.c 8.3 (Berkeley) 12/6/94";
-#else
-static char rcsid[] = "$OpenBSD: preen.c,v 1.4 1996/06/23 14:30:34 deraadt Exp $";
-#endif
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <fstab.h>
-#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-#include <unistd.h>
-
-struct part {
- struct part *next; /* forward link of partitions on disk */
- char *name; /* device name */
- char *fsname; /* mounted filesystem name */
- long auxdata; /* auxillary data for application */
-} *badlist, **badnext = &badlist;
-
-struct disk {
- char *name; /* disk base name */
- struct disk *next; /* forward link for list of disks */
- struct part *part; /* head of list of partitions on disk */
- int pid; /* If != 0, pid of proc working on */
-} *disks;
-
-int nrun, ndisks;
-char hotroot;
-
-char *rawname(), *unrawname(), *blockcheck();
-void addpart __P((char *, char *, long));
-int startdisk __P((struct disk *, int (*)() ));
-
-int
-checkfstab(preen, maxrun, docheck, chkit)
- int preen, maxrun;
- int (*docheck)(), (*chkit)();
-{
- register struct fstab *fsp;
- register struct disk *dk, *nextdisk;
- register struct part *pt;
- int ret, pid, retcode, passno, sumstatus, status;
- long auxdata;
- char *name;
-
- sumstatus = 0;
- for (passno = 1; passno <= 2; passno++) {
- if (setfsent() == 0) {
- fprintf(stderr, "Can't open checklist file: %s\n",
- _PATH_FSTAB);
- return (8);
- }
- while ((fsp = getfsent()) != 0) {
- if ((auxdata = (*docheck)(fsp)) == 0)
- continue;
- if (preen == 0 || passno == 1 && fsp->fs_passno == 1) {
- if (name = blockcheck(fsp->fs_spec)) {
- if (sumstatus = (*chkit)(name,
- fsp->fs_file, auxdata, 0))
- return (sumstatus);
- } else if (preen)
- return (8);
- } else if (passno == 2 && fsp->fs_passno > 1) {
- if ((name = blockcheck(fsp->fs_spec)) == NULL) {
- fprintf(stderr, "BAD DISK NAME %s\n",
- fsp->fs_spec);
- sumstatus |= 8;
- continue;
- }
- addpart(name, fsp->fs_file, auxdata);
- }
- }
- if (preen == 0)
- return (0);
- }
- if (preen) {
- if (maxrun == 0)
- maxrun = ndisks;
- if (maxrun > ndisks)
- maxrun = ndisks;
- nextdisk = disks;
- for (passno = 0; passno < maxrun; ++passno) {
- while (ret = startdisk(nextdisk, chkit) && nrun > 0)
- sleep(10);
- if (ret)
- return (ret);
- nextdisk = nextdisk->next;
- }
- while ((pid = wait(&status)) != -1) {
- for (dk = disks; dk; dk = dk->next)
- if (dk->pid == pid)
- break;
- if (dk == 0) {
- printf("Unknown pid %d\n", pid);
- continue;
- }
- if (WIFEXITED(status))
- retcode = WEXITSTATUS(status);
- else
- retcode = 0;
- if (WIFSIGNALED(status)) {
- printf("%s (%s): EXITED WITH SIGNAL %d\n",
- dk->part->name, dk->part->fsname,
- WTERMSIG(status));
- retcode = 8;
- }
- if (retcode != 0) {
- sumstatus |= retcode;
- *badnext = dk->part;
- badnext = &dk->part->next;
- dk->part = dk->part->next;
- *badnext = NULL;
- } else
- dk->part = dk->part->next;
- dk->pid = 0;
- nrun--;
- if (dk->part == NULL)
- ndisks--;
-
- if (nextdisk == NULL) {
- if (dk->part) {
- while (ret = startdisk(dk, chkit) &&
- nrun > 0)
- sleep(10);
- if (ret)
- return (ret);
- }
- } else if (nrun < maxrun && nrun < ndisks) {
- for ( ;; ) {
- if ((nextdisk = nextdisk->next) == NULL)
- nextdisk = disks;
- if (nextdisk->part != NULL &&
- nextdisk->pid == 0)
- break;
- }
- while (ret = startdisk(nextdisk, chkit) &&
- nrun > 0)
- sleep(10);
- if (ret)
- return (ret);
- }
- }
- }
- if (sumstatus) {
- if (badlist == 0)
- return (sumstatus);
- fprintf(stderr, "THE FOLLOWING FILE SYSTEM%s HAD AN %s\n\t",
- badlist->next ? "S" : "", "UNEXPECTED INCONSISTENCY:");
- for (pt = badlist; pt; pt = pt->next)
- fprintf(stderr, "%s (%s)%s", pt->name, pt->fsname,
- pt->next ? ", " : "\n");
- return (sumstatus);
- }
- (void)endfsent();
- return (0);
-}
-
-struct disk *
-finddisk(name)
- char *name;
-{
- register struct disk *dk, **dkp;
- register char *p;
- size_t len;
-
- for (p = name + strlen(name) - 1; p >= name; --p)
- if (isdigit(*p)) {
- len = p - name + 1;
- break;
- }
- if (p < name)
- len = strlen(name);
-
- for (dk = disks, dkp = &disks; dk; dkp = &dk->next, dk = dk->next) {
- if (strncmp(dk->name, name, len) == 0 &&
- dk->name[len] == 0)
- return (dk);
- }
- if ((*dkp = (struct disk *)malloc(sizeof(struct disk))) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
- dk = *dkp;
- if ((dk->name = malloc(len + 1)) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
- (void)strncpy(dk->name, name, len);
- dk->name[len] = '\0';
- dk->part = NULL;
- dk->next = NULL;
- dk->pid = 0;
- ndisks++;
- return (dk);
-}
-
-void
-addpart(name, fsname, auxdata)
- char *name, *fsname;
- long auxdata;
-{
- struct disk *dk = finddisk(name);
- register struct part *pt, **ppt = &dk->part;
-
- for (pt = dk->part; pt; ppt = &pt->next, pt = pt->next)
- if (strcmp(pt->name, name) == 0) {
- printf("%s in fstab more than once!\n", name);
- return;
- }
- if ((*ppt = (struct part *)malloc(sizeof(struct part))) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
- pt = *ppt;
- if ((pt->name = malloc(strlen(name) + 1)) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
- (void)strcpy(pt->name, name);
- if ((pt->fsname = malloc(strlen(fsname) + 1)) == NULL) {
- fprintf(stderr, "out of memory");
- exit (8);
- }
- (void)strcpy(pt->fsname, fsname);
- pt->next = NULL;
- pt->auxdata = auxdata;
-}
-
-int
-startdisk(dk, checkit)
- register struct disk *dk;
- int (*checkit)();
-{
- register struct part *pt = dk->part;
-
- dk->pid = fork();
- if (dk->pid < 0) {
- perror("fork");
- return (8);
- }
- if (dk->pid == 0)
- exit((*checkit)(pt->name, pt->fsname, pt->auxdata, 1));
- nrun++;
- return (0);
-}
-
-char *
-blockcheck(origname)
- char *origname;
-{
- struct stat stslash, stblock, stchar;
- struct fstab *fsp;
- char *newname, *raw;
- int retried = 0;
-
- hotroot = 0;
- if (stat("/", &stslash) < 0) {
- perror("/");
- printf("Can't stat root\n");
- return (origname);
- }
- newname = origname;
-retry:
- if (stat(newname, &stblock) < 0) {
- perror(newname);
- printf("Can't stat %s\n", newname);
- return (origname);
- }
- if (S_ISBLK(stblock.st_mode)) {
- if (stslash.st_dev == stblock.st_rdev)
- hotroot++;
- raw = rawname(newname);
- if (stat(raw, &stchar) < 0) {
- perror(raw);
- printf("Can't stat %s\n", raw);
- return (origname);
- }
- if (S_ISCHR(stchar.st_mode)) {
- return (raw);
- } else {
- printf("%s is not a character device\n", raw);
- return (origname);
- }
- } else if (S_ISCHR(stblock.st_mode) && !retried) {
- newname = unrawname(newname);
- retried++;
- goto retry;
- } else if ((fsp = getfsfile(newname)) != 0 && !retried) {
- newname = fsp->fs_spec;
- retried++;
- goto retry;
- }
- /*
- * Not a block or character device, just return name and
- * let the user decide whether to use it.
- */
- if ((fsp = getfsfile(origname))) {
- newname = fsp->fs_spec;
- retried++;
- goto retry;
- }
- return (origname);
-}
-
-char *
-unrawname(name)
- char *name;
-{
- char *dp;
- struct stat stb;
-
- if ((dp = strrchr(name, '/')) == 0)
- return (name);
- if (stat(name, &stb) < 0)
- return (name);
- if (!S_ISCHR(stb.st_mode))
- return (name);
- if (dp[1] != 'r')
- return (name);
- (void)strcpy(&dp[1], &dp[2]);
- return (name);
-}
-
-char *
-rawname(name)
- char *name;
-{
- static char rawbuf[32];
- char *dp;
-
- if ((dp = strrchr(name, '/')) == 0)
- return (0);
- *dp = 0;
- (void)strcpy(rawbuf, name);
- *dp = '/';
- (void)strcat(rawbuf, "/r");
- (void)strcat(rawbuf, &dp[1]);
- return (rawbuf);
-}
diff --git a/sbin/fsck_ffs/setup.c b/sbin/fsck_ffs/setup.c
index 2c569088947..e48c5f0b12d 100644
--- a/sbin/fsck_ffs/setup.c
+++ b/sbin/fsck_ffs/setup.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: setup.c,v 1.3 1996/06/23 14:30:34 deraadt Exp $ */
-/* $NetBSD: setup.c,v 1.25 1996/05/21 17:36:21 mycroft Exp $ */
+/* $OpenBSD: setup.c,v 1.4 1996/10/20 08:36:41 tholo Exp $ */
+/* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)setup.c 8.5 (Berkeley) 11/23/94";
#else
-static char rcsid[] = "$OpenBSD: setup.c,v 1.3 1996/06/23 14:30:34 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: setup.c,v 1.4 1996/10/20 08:36:41 tholo Exp $";
#endif
#endif /* not lint */
@@ -57,8 +57,10 @@ static char rcsid[] = "$OpenBSD: setup.c,v 1.3 1996/06/23 14:30:34 deraadt Exp $
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+
#include "fsck.h"
#include "extern.h"
+#include "fsutil.h"
struct bufarea asblk;
#define altsblock (*asblk.b_un.b_fs)
@@ -66,8 +68,8 @@ struct bufarea asblk;
void badsb __P((int, char *));
int calcsb __P((char *, int, struct fs *));
-struct disklabel *getdisklabel();
-int readsb __P((int));
+static struct disklabel *getdisklabel __P((char *, int));
+static int readsb __P((int));
int
setup(dev)
@@ -116,7 +118,7 @@ setup(dev)
asblk.b_un.b_buf = malloc(SBSIZE);
if (sblk.b_un.b_buf == NULL || asblk.b_un.b_buf == NULL)
errexit("cannot allocate space for superblock\n");
- if (lp = getdisklabel((char *)NULL, fsreadfd))
+ if ((lp = getdisklabel((char *)NULL, fsreadfd)) != NULL)
dev_bsize = secsize = lp->d_secsize;
else
dev_bsize = secsize = DEV_BSIZE;
@@ -335,7 +337,7 @@ setup(dev)
size) != 0 && !asked) {
pfatal("BAD SUMMARY INFORMATION");
if (reply("CONTINUE") == 0)
- errexit("");
+ errexit("%s", "");
asked++;
}
}
@@ -390,7 +392,7 @@ badsblabel:
/*
* Read in the super block and its summary info.
*/
-int
+static int
readsb(listerr)
int listerr;
{
@@ -478,7 +480,7 @@ readsb(listerr)
for ( ; olp < endlp; olp++, nlp++) {
if (*olp == *nlp)
continue;
- printf("offset %d, original %d, alternate %d\n",
+ printf("offset %d, original %ld, alternate %ld\n",
olp - (long *)&sblock, *olp, *nlp);
}
}
@@ -499,7 +501,7 @@ badsb(listerr, s)
if (!listerr)
return;
if (preen)
- printf("%s: ", cdevname);
+ printf("%s: ", cdevname());
pfatal("BAD SUPER BLOCK: %s\n", s);
}
@@ -521,7 +523,7 @@ calcsb(dev, devfd, fs)
int i;
cp = strchr(dev, '\0') - 1;
- if (cp == (char *)-1 || (*cp < 'a' || *cp > 'h') && !isdigit(*cp)) {
+ if ((cp == (char *)-1 || (*cp < 'a' || *cp > 'h')) && !isdigit(*cp)) {
pfatal("%s: CANNOT FIGURE OUT FILE SYSTEM PARTITION\n", dev);
return (0);
}
@@ -563,7 +565,7 @@ calcsb(dev, devfd, fs)
return (1);
}
-struct disklabel *
+static struct disklabel *
getdisklabel(s, fd)
char *s;
int fd;
diff --git a/sbin/fsck_ffs/utilities.c b/sbin/fsck_ffs/utilities.c
index b1071eaa86d..36dda840ee8 100644
--- a/sbin/fsck_ffs/utilities.c
+++ b/sbin/fsck_ffs/utilities.c
@@ -1,5 +1,5 @@
-/* $OpenBSD: utilities.c,v 1.2 1996/06/23 14:30:35 deraadt Exp $ */
-/* $NetBSD: utilities.c,v 1.15 1995/04/23 10:33:09 cgd Exp $ */
+/* $OpenBSD: utilities.c,v 1.3 1996/10/20 08:36:42 tholo Exp $ */
+/* $NetBSD: utilities.c,v 1.18 1996/09/27 22:45:20 christos Exp $ */
/*
* Copyright (c) 1980, 1986, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)utilities.c 8.1 (Berkeley) 6/5/93";
#else
-static char rcsid[] = "$OpenBSD: utilities.c,v 1.2 1996/06/23 14:30:35 deraadt Exp $";
+static char rcsid[] = "$OpenBSD: utilities.c,v 1.3 1996/10/20 08:36:42 tholo Exp $";
#endif
#endif /* not lint */
@@ -53,11 +53,14 @@ static char rcsid[] = "$OpenBSD: utilities.c,v 1.2 1996/06/23 14:30:35 deraadt E
#include <ctype.h>
#include <unistd.h>
+#include "fsutil.h"
#include "fsck.h"
#include "extern.h"
long diskreads, totalreads; /* Disk cache statistics */
+static void rwerror __P((char *, daddr_t));
+
int
ftypeok(dp)
struct dinode *dp;
@@ -227,7 +230,7 @@ flush(fd, bp)
}
}
-void
+static void
rwerror(mesg, blk)
char *mesg;
daddr_t blk;
@@ -235,7 +238,7 @@ rwerror(mesg, blk)
if (preen == 0)
printf("\n");
- pfatal("CANNOT %s: BLK %ld", mesg, blk);
+ pfatal("CANNOT %s: BLK %d", mesg, blk);
if (reply("CONTINUE") == 0)
errexit("Program terminated\n");
}
@@ -470,7 +473,8 @@ getpathname(namebuf, curdir, ino)
}
void
-catch()
+catch(n)
+ int n;
{
if (!doinglevel2)
ckfini(0);
@@ -483,7 +487,8 @@ catch()
* so that reboot sequence may be interrupted.
*/
void
-catchquit()
+catchquit(n)
+ int n;
{
extern returntosingle;
@@ -497,7 +502,8 @@ catchquit()
* Used by child processes in preen.
*/
void
-voidquit()
+voidquit(n)
+ int n;
{
sleep(1);
@@ -545,61 +551,3 @@ dofix(idesc, msg)
}
/* NOTREACHED */
}
-
-/* VARARGS1 */
-errexit(s1, s2, s3, s4)
- char *s1;
- long s2, s3, s4;
-{
- printf(s1, s2, s3, s4);
- exit(8);
-}
-
-/*
- * An unexpected inconsistency occured.
- * Die if preening, otherwise just print message and continue.
- */
-/* VARARGS1 */
-pfatal(s, a1, a2, a3)
- char *s;
- long a1, a2, a3;
-{
-
- if (preen) {
- printf("%s: ", cdevname);
- printf(s, a1, a2, a3);
- printf("\n");
- printf("%s: UNEXPECTED INCONSISTENCY; RUN fsck MANUALLY.\n",
- cdevname);
- exit(8);
- }
- printf(s, a1, a2, a3);
-}
-
-/*
- * Pwarn just prints a message when not preening,
- * or a warning (preceded by filename) when preening.
- */
-/* VARARGS1 */
-pwarn(s, a1, a2, a3, a4, a5, a6)
- char *s;
- long a1, a2, a3, a4, a5, a6;
-{
-
- if (preen)
- printf("%s: ", cdevname);
- printf(s, a1, a2, a3, a4, a5, a6);
-}
-
-#ifndef lint
-/*
- * Stub for routines from kernel.
- */
-panic(s)
- char *s;
-{
-
- pfatal("INTERNAL INCONSISTENCY:");
- errexit(s);
-}
-#endif