check in temporary version with compatibility hacks
[unix-history] / usr / src / sbin / fsck / main.c
index b9c84d5..0bcd7db 100644 (file)
@@ -2,17 +2,7 @@
  * Copyright (c) 1980, 1986 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980, 1986 The Regents of the University of California.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -22,15 +12,17 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)main.c     5.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)main.c     5.29 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
-#include <ufs/dinode.h>
-#include <ufs/fs.h>
+#include <ufs/ufs/dinode.h>
+#include <ufs/ffs/fs.h>
 #include <fstab.h>
 #include <fstab.h>
-#include <strings.h>
+#include <stdlib.h>
+#include <string.h>
 #include <ctype.h>
 #include <ctype.h>
+#include <stdio.h>
 #include "fsck.h"
 
 void   catch(), catchquit(), voidquit();
 #include "fsck.h"
 
 void   catch(), catchquit(), voidquit();
@@ -40,24 +32,21 @@ main(argc, argv)
        int     argc;
        char    *argv[];
 {
        int     argc;
        char    *argv[];
 {
+       int ch;
        int ret, maxrun = 0;
        int ret, maxrun = 0;
-       extern int (docheck)(), (checkfilesys)();
+       extern int docheck(), checkfilesys();
+       extern char *optarg;
+       extern int optind;
 
        sync();
 
        sync();
-       while (--argc > 0 && **++argv == '-') {
-               switch (*++*argv) {
-
+       while ((ch = getopt(argc, argv, "cdpnNyYb:l:m:")) != EOF) {
+               switch (ch) {
                case 'p':
                        preen++;
                        break;
 
                case 'b':
                case 'p':
                        preen++;
                        break;
 
                case 'b':
-                       if (argv[0][1] != '\0') {
-                               bflag = atoi(argv[0]+1);
-                       } else {
-                               bflag = atoi(*++argv);
-                               argc--;
-                       }
+                       bflag = argtoi('b', "number", optarg, 10);
                        printf("Alternate super block location: %d\n", bflag);
                        break;
 
                        printf("Alternate super block location: %d\n", bflag);
                        break;
 
@@ -70,19 +59,13 @@ main(argc, argv)
                        break;
 
                case 'l':
                        break;
 
                case 'l':
-                       if (!isdigit(argv[1][0]))
-                               errexit("-l flag requires a number\n");
-                       maxrun = atoi(*++argv);
-                       argc--;
+                       maxrun = argtoi('l', "number", optarg, 10);
                        break;
 
                case 'm':
                        break;
 
                case 'm':
-                       if (!isdigit(argv[1][0]))
-                               errexit("-m flag requires a mode\n");
-                       sscanf(*++argv, "%o", &lfmode);
+                       lfmode = argtoi('m', "mode", optarg, 8);
                        if (lfmode &~ 07777)
                                errexit("bad mode to -m: %o\n", lfmode);
                        if (lfmode &~ 07777)
                                errexit("bad mode to -m: %o\n", lfmode);
-                       argc--;
                        printf("** lost+found creation mode %o\n", lfmode);
                        break;
 
                        printf("** lost+found creation mode %o\n", lfmode);
                        break;
 
@@ -99,18 +82,18 @@ main(argc, argv)
                        break;
 
                default:
                        break;
 
                default:
-                       errexit("%c option?\n", **argv);
+                       errexit("%c option?\n", ch);
                }
        }
                }
        }
+       argc -= optind;
+       argv += optind;
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                (void)signal(SIGINT, catch);
        if (preen)
                (void)signal(SIGQUIT, catchquit);
        if (argc) {
        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
                (void)signal(SIGINT, catch);
        if (preen)
                (void)signal(SIGQUIT, catchquit);
        if (argc) {
-               while (argc-- > 0) {
-                       hotroot = 0;
-                       checkfilesys(*argv++);
-               }
+               while (argc-- > 0)
+                       (void)checkfilesys(*argv++, (char *)0, 0L, 0);
                exit(0);
        }
        ret = checkfstab(preen, maxrun, docheck, checkfilesys);
                exit(0);
        }
        ret = checkfstab(preen, maxrun, docheck, checkfilesys);
@@ -119,6 +102,20 @@ main(argc, argv)
        exit(ret);
 }
 
        exit(ret);
 }
 
+argtoi(flag, req, str, base)
+       int flag;
+       char *req, *str;
+       int base;
+{
+       char *cp;
+       int ret;
+
+       ret = (int)strtol(str, &cp, base);
+       if (cp == str || *cp)
+               errexit("-%c flag requires a %s\n", flag, req);
+       return (ret);
+}
+
 /*
  * Determine whether a filesystem should be checked.
  */
 /*
  * Determine whether a filesystem should be checked.
  */
@@ -138,7 +135,7 @@ docheck(fsp)
  * Check the specified filesystem.
  */
 /* ARGSUSED */
  * Check the specified filesystem.
  */
 /* ARGSUSED */
-checkfilesys(filesys, mntpt, auxdata)
+checkfilesys(filesys, mntpt, auxdata, child)
        char *filesys, *mntpt;
        long auxdata;
 {
        char *filesys, *mntpt;
        long auxdata;
 {
@@ -146,7 +143,8 @@ checkfilesys(filesys, mntpt, auxdata)
        struct dups *dp;
        struct zlncnt *zlnp;
 
        struct dups *dp;
        struct zlncnt *zlnp;
 
-       (void)signal(SIGQUIT, voidquit);
+       if (preen && child)
+               (void)signal(SIGQUIT, voidquit);
        devname = filesys;
        if (debug && preen)
                pwarn("starting\n");
        devname = filesys;
        if (debug && preen)
                pwarn("starting\n");
@@ -209,35 +207,36 @@ checkfilesys(filesys, mntpt, auxdata)
         */
        n_ffree = sblock.fs_cstotal.cs_nffree;
        n_bfree = sblock.fs_cstotal.cs_nbfree;
         */
        n_ffree = sblock.fs_cstotal.cs_nffree;
        n_bfree = sblock.fs_cstotal.cs_nbfree;
-       pwarn("%d files, %d used, %d free ",
+       pwarn("%ld files, %ld used, %ld free ",
            n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
            n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
-       printf("(%d frags, %d blocks, %.1f%% fragmentation)\n",
+       printf("(%ld frags, %ld blocks, %.1f%% fragmentation)\n",
            n_ffree, n_bfree, (float)(n_ffree * 100) / sblock.fs_dsize);
        if (debug &&
            (n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree))
            n_ffree, n_bfree, (float)(n_ffree * 100) / sblock.fs_dsize);
        if (debug &&
            (n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree))
-               printf("%d files missing\n", n_files);
+               printf("%ld 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))
        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("%d blocks missing\n", n_blks);
+                       printf("%ld blocks missing\n", n_blks);
                if (duplist != NULL) {
                        printf("The following duplicate blocks remain:");
                        for (dp = duplist; dp; dp = dp->next)
                if (duplist != NULL) {
                        printf("The following duplicate blocks remain:");
                        for (dp = duplist; dp; dp = dp->next)
-                               printf(" %d,", dp->dup);
+                               printf(" %ld,", dp->dup);
                        printf("\n");
                }
                if (zlnhead != NULL) {
                        printf("The following zero link count inodes remain:");
                        for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
                        printf("\n");
                }
                if (zlnhead != NULL) {
                        printf("The following zero link count inodes remain:");
                        for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
-                               printf(" %d,", zlnp->zlncnt);
+                               printf(" %lu,", zlnp->zlncnt);
                        printf("\n");
                }
        }
        zlnhead = (struct zlncnt *)0;
        duplist = (struct dups *)0;
                        printf("\n");
                }
        }
        zlnhead = (struct zlncnt *)0;
        duplist = (struct dups *)0;
+       muldup = (struct dups *)0;
        inocleanup();
        if (fsmodified) {
                (void)time(&sblock.fs_time);
        inocleanup();
        if (fsmodified) {
                (void)time(&sblock.fs_time);