Annotation of 43BSDReno/sbin/fsck/main.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Copyright (c) 1980, 1986 The Regents of the University of California.
        !             3:  * All rights reserved.
        !             4:  *
        !             5:  * Redistribution and use in source and binary forms are permitted provided
        !             6:  * that: (1) source distributions retain this entire copyright notice and
        !             7:  * comment, and (2) distributions including binaries display the following
        !             8:  * acknowledgement:  ``This product includes software developed by the
        !             9:  * University of California, Berkeley and its contributors'' in the
        !            10:  * documentation or other materials provided with the distribution and in
        !            11:  * all advertising materials mentioning features or use of this software.
        !            12:  * Neither the name of the University nor the names of its contributors may
        !            13:  * be used to endorse or promote products derived from this software without
        !            14:  * specific prior written permission.
        !            15:  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
        !            16:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
        !            17:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
        !            18:  */
        !            19: 
        !            20: #ifndef lint
        !            21: char copyright[] =
        !            22: "@(#) Copyright (c) 1980, 1986 The Regents of the University of California.\n\
        !            23:  All rights reserved.\n";
        !            24: #endif /* not lint */
        !            25: 
        !            26: #ifndef lint
        !            27: static char sccsid[] = "@(#)main.c     5.26 (Berkeley) 7/20/90";
        !            28: #endif /* not lint */
        !            29: 
        !            30: #include <sys/param.h>
        !            31: #include <ufs/dinode.h>
        !            32: #include <ufs/fs.h>
        !            33: #include <fstab.h>
        !            34: #include <stdlib.h>
        !            35: #include <string.h>
        !            36: #include <ctype.h>
        !            37: #include <stdio.h>
        !            38: #include "fsck.h"
        !            39: 
        !            40: void   catch(), catchquit(), voidquit();
        !            41: int    returntosingle;
        !            42: 
        !            43: main(argc, argv)
        !            44:        int     argc;
        !            45:        char    *argv[];
        !            46: {
        !            47:        int ch;
        !            48:        int ret, maxrun = 0;
        !            49:        extern int docheck(), checkfilesys();
        !            50:        extern char *optarg;
        !            51:        extern int optind;
        !            52: 
        !            53:        sync();
        !            54:        while ((ch = getopt(argc, argv, "cdpnNyYb:l:m:")) != EOF) {
        !            55:                switch (ch) {
        !            56:                case 'p':
        !            57:                        preen++;
        !            58:                        break;
        !            59: 
        !            60:                case 'b':
        !            61:                        bflag = argtoi('b', "number", optarg, 10);
        !            62:                        printf("Alternate super block location: %d\n", bflag);
        !            63:                        break;
        !            64: 
        !            65:                case 'c':
        !            66:                        cvtflag++;
        !            67:                        break;
        !            68: 
        !            69:                case 'd':
        !            70:                        debug++;
        !            71:                        break;
        !            72: 
        !            73:                case 'l':
        !            74:                        maxrun = argtoi('l', "number", optarg, 10);
        !            75:                        break;
        !            76: 
        !            77:                case 'm':
        !            78:                        lfmode = argtoi('m', "mode", optarg, 8);
        !            79:                        if (lfmode &~ 07777)
        !            80:                                errexit("bad mode to -m: %o\n", lfmode);
        !            81:                        printf("** lost+found creation mode %o\n", lfmode);
        !            82:                        break;
        !            83: 
        !            84:                case 'n':
        !            85:                case 'N':
        !            86:                        nflag++;
        !            87:                        yflag = 0;
        !            88:                        break;
        !            89: 
        !            90:                case 'y':
        !            91:                case 'Y':
        !            92:                        yflag++;
        !            93:                        nflag = 0;
        !            94:                        break;
        !            95: 
        !            96:                default:
        !            97:                        errexit("%c option?\n", ch);
        !            98:                }
        !            99:        }
        !           100:        argc -= optind;
        !           101:        argv += optind;
        !           102:        if (signal(SIGINT, SIG_IGN) != SIG_IGN)
        !           103:                (void)signal(SIGINT, catch);
        !           104:        if (preen)
        !           105:                (void)signal(SIGQUIT, catchquit);
        !           106:        if (argc) {
        !           107:                while (argc-- > 0)
        !           108:                        (void)checkfilesys(*argv++, (char *)0, 0L);
        !           109:                exit(0);
        !           110:        }
        !           111:        ret = checkfstab(preen, maxrun, docheck, checkfilesys);
        !           112:        if (returntosingle)
        !           113:                exit(2);
        !           114:        exit(ret);
        !           115: }
        !           116: 
        !           117: argtoi(flag, req, str, base)
        !           118:        int flag;
        !           119:        char *req, *str;
        !           120:        int base;
        !           121: {
        !           122:        char *cp;
        !           123:        int ret;
        !           124: 
        !           125:        ret = (int)strtol(str, &cp, base);
        !           126:        if (cp == str || *cp)
        !           127:                errexit("-%c flag requires a %s\n", flag, req);
        !           128:        return (ret);
        !           129: }
        !           130: 
        !           131: /*
        !           132:  * Determine whether a filesystem should be checked.
        !           133:  */
        !           134: docheck(fsp)
        !           135:        register struct fstab *fsp;
        !           136: {
        !           137: 
        !           138:        if (strcmp(fsp->fs_vfstype, "ufs") ||
        !           139:            (strcmp(fsp->fs_type, FSTAB_RW) &&
        !           140:             strcmp(fsp->fs_type, FSTAB_RO)) ||
        !           141:            fsp->fs_passno == 0)
        !           142:                return (0);
        !           143:        return (1);
        !           144: }
        !           145: 
        !           146: /*
        !           147:  * Check the specified filesystem.
        !           148:  */
        !           149: /* ARGSUSED */
        !           150: checkfilesys(filesys, mntpt, auxdata)
        !           151:        char *filesys, *mntpt;
        !           152:        long auxdata;
        !           153: {
        !           154:        daddr_t n_ffree, n_bfree;
        !           155:        struct dups *dp;
        !           156:        struct zlncnt *zlnp;
        !           157: 
        !           158:        (void)signal(SIGQUIT, voidquit);
        !           159:        devname = filesys;
        !           160:        if (debug && preen)
        !           161:                pwarn("starting\n");
        !           162:        if (setup(filesys) == 0) {
        !           163:                if (preen)
        !           164:                        pfatal("CAN'T CHECK FILE SYSTEM.");
        !           165:                return (0);
        !           166:        }
        !           167:        /*
        !           168:         * 1: scan inodes tallying blocks used
        !           169:         */
        !           170:        if (preen == 0) {
        !           171:                printf("** Last Mounted on %s\n", sblock.fs_fsmnt);
        !           172:                if (hotroot)
        !           173:                        printf("** Root file system\n");
        !           174:                printf("** Phase 1 - Check Blocks and Sizes\n");
        !           175:        }
        !           176:        pass1();
        !           177: 
        !           178:        /*
        !           179:         * 1b: locate first references to duplicates, if any
        !           180:         */
        !           181:        if (duplist) {
        !           182:                if (preen)
        !           183:                        pfatal("INTERNAL ERROR: dups with -p");
        !           184:                printf("** Phase 1b - Rescan For More DUPS\n");
        !           185:                pass1b();
        !           186:        }
        !           187: 
        !           188:        /*
        !           189:         * 2: traverse directories from root to mark all connected directories
        !           190:         */
        !           191:        if (preen == 0)
        !           192:                printf("** Phase 2 - Check Pathnames\n");
        !           193:        pass2();
        !           194: 
        !           195:        /*
        !           196:         * 3: scan inodes looking for disconnected directories
        !           197:         */
        !           198:        if (preen == 0)
        !           199:                printf("** Phase 3 - Check Connectivity\n");
        !           200:        pass3();
        !           201: 
        !           202:        /*
        !           203:         * 4: scan inodes looking for disconnected files; check reference counts
        !           204:         */
        !           205:        if (preen == 0)
        !           206:                printf("** Phase 4 - Check Reference Counts\n");
        !           207:        pass4();
        !           208: 
        !           209:        /*
        !           210:         * 5: check and repair resource counts in cylinder groups
        !           211:         */
        !           212:        if (preen == 0)
        !           213:                printf("** Phase 5 - Check Cyl groups\n");
        !           214:        pass5();
        !           215: 
        !           216:        /*
        !           217:         * print out summary statistics
        !           218:         */
        !           219:        n_ffree = sblock.fs_cstotal.cs_nffree;
        !           220:        n_bfree = sblock.fs_cstotal.cs_nbfree;
        !           221:        pwarn("%ld files, %ld used, %ld free ",
        !           222:            n_files, n_blks, n_ffree + sblock.fs_frag * n_bfree);
        !           223:        printf("(%ld frags, %ld blocks, %.1f%% fragmentation)\n",
        !           224:            n_ffree, n_bfree, (float)(n_ffree * 100) / sblock.fs_dsize);
        !           225:        if (debug &&
        !           226:            (n_files -= maxino - ROOTINO - sblock.fs_cstotal.cs_nifree))
        !           227:                printf("%ld files missing\n", n_files);
        !           228:        if (debug) {
        !           229:                n_blks += sblock.fs_ncg *
        !           230:                        (cgdmin(&sblock, 0) - cgsblock(&sblock, 0));
        !           231:                n_blks += cgsblock(&sblock, 0) - cgbase(&sblock, 0);
        !           232:                n_blks += howmany(sblock.fs_cssize, sblock.fs_fsize);
        !           233:                if (n_blks -= maxfsblock - (n_ffree + sblock.fs_frag * n_bfree))
        !           234:                        printf("%ld blocks missing\n", n_blks);
        !           235:                if (duplist != NULL) {
        !           236:                        printf("The following duplicate blocks remain:");
        !           237:                        for (dp = duplist; dp; dp = dp->next)
        !           238:                                printf(" %ld,", dp->dup);
        !           239:                        printf("\n");
        !           240:                }
        !           241:                if (zlnhead != NULL) {
        !           242:                        printf("The following zero link count inodes remain:");
        !           243:                        for (zlnp = zlnhead; zlnp; zlnp = zlnp->next)
        !           244:                                printf(" %lu,", zlnp->zlncnt);
        !           245:                        printf("\n");
        !           246:                }
        !           247:        }
        !           248:        zlnhead = (struct zlncnt *)0;
        !           249:        duplist = (struct dups *)0;
        !           250:        inocleanup();
        !           251:        if (fsmodified) {
        !           252:                (void)time(&sblock.fs_time);
        !           253:                sbdirty();
        !           254:        }
        !           255:        ckfini();
        !           256:        free(blockmap);
        !           257:        free(statemap);
        !           258:        free((char *)lncntp);
        !           259:        if (!fsmodified)
        !           260:                return (0);
        !           261:        if (!preen) {
        !           262:                printf("\n***** FILE SYSTEM WAS MODIFIED *****\n");
        !           263:                if (hotroot)
        !           264:                        printf("\n***** REBOOT UNIX *****\n");
        !           265:        }
        !           266:        if (hotroot) {
        !           267:                sync();
        !           268:                return (4);
        !           269:        }
        !           270:        return (0);
        !           271: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.