int main(int argc, char *argv[]) { struct fstab *fs; int i, rval = 0; const char *vfstype = NULL; char globopt[3]; const char *etc_fstab; globopt[0] = '-'; globopt[2] = '\0'; TAILQ_INIT(&selhead); TAILQ_INIT(&opthead); etc_fstab = NULL; while ((i = getopt(argc, argv, "BCdvpfFnyl:t:T:c:")) != -1) switch (i) { case 'B': if (flags & CHECK_BACKGRD) errx(1, "Cannot specify -B and -F."); flags |= DO_BACKGRD; break; case 'd': flags |= CHECK_DEBUG; break; case 'v': flags |= CHECK_VERBOSE; break; case 'F': if (flags & DO_BACKGRD) errx(1, "Cannot specify -B and -F."); flags |= CHECK_BACKGRD; break; case 'p': flags |= CHECK_PREEN; /*FALLTHROUGH*/ case 'C': flags |= CHECK_CLEAN; /*FALLTHROUGH*/ case 'n': case 'y': globopt[1] = i; catopt(&options, globopt); break; case 'f': forceflag = 1; globopt[1] = i; catopt(&options, globopt); break; case 'l': warnx("Ignoring obsolete -l option\n"); break; case 'T': if (*optarg) addoption(optarg); break; case 't': if (!TAILQ_EMPTY(&selhead)) errx(1, "only one -t option may be specified."); maketypelist(optarg); vfstype = optarg; break; case 'c': etc_fstab = optarg; break; case '?': default: usage(); /* NOTREACHED */ } argc -= optind; argv += optind; if (etc_fstab != NULL) setfstab(etc_fstab); if (argc == 0) return checkfstab(flags, isok, checkfs); #define BADTYPE(type) \ (strcmp(type, FSTAB_RO) && \ strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) for (; argc--; argv++) { const char *spec, *mntpt, *type, *cp; char device[MAXPATHLEN]; struct statfs *mntp; mntpt = NULL; spec = *argv; cp = strrchr(spec, '/'); if (cp == 0) { (void)snprintf(device, sizeof(device), "%s%s", _PATH_DEV, spec); spec = device; } mntp = getmntpt(spec); if (mntp != NULL) { spec = mntp->f_mntfromname; mntpt = mntp->f_mntonname; } if ((fs = getfsfile(spec)) == NULL && (fs = getfsspec(spec)) == NULL) { if (vfstype == NULL) vfstype = getfslab(spec); if (vfstype == NULL) errx(1, "Could not determine filesystem type"); type = vfstype; devcheck(spec); } else { spec = fs->fs_spec; type = fs->fs_vfstype; mntpt = fs->fs_file; if (BADTYPE(fs->fs_type)) errx(1, "%s has unknown file system type.", spec); } if ((flags & CHECK_BACKGRD) && checkfs(type, spec, mntpt, "-F", NULL) == 0) { printf("%s: DEFER FOR BACKGROUND CHECKING\n", *argv); continue; } if ((flags & DO_BACKGRD) && forceflag == 0 && checkfs(type, spec, mntpt, "-F", NULL) != 0) continue; rval |= checkfs(type, spec, mntpt, NULL, NULL); } return rval; }
int main(int argc, char *argv[]) { struct fstab *fs; int i, rval; const char *vfstype = NULL; char globopt[3]; int ret = FSCK_EXIT_OK; globopt[0] = '-'; globopt[2] = '\0'; TAILQ_INIT(&selhead); TAILQ_INIT(&opthead); while ((i = getopt(argc, argv, "dfl:nPpqT:t:vy")) != -1) { switch (i) { case 'd': flags |= CHECK_DEBUG; continue; case 'f': flags |= CHECK_FORCE; break; case 'n': flags |= CHECK_NOFIX; break; case 'p': flags |= CHECK_PREEN; break; case 'P': flags |= CHECK_PROGRESS; break; case 'q': break; case 'l': maxrun = atoi(optarg); continue; case 'T': if (*optarg) addoption(optarg); continue; case 't': if (TAILQ_FIRST(&selhead) != NULL) errx(1, "only one -t option may be specified."); maketypelist(optarg); vfstype = optarg; continue; case 'v': flags |= CHECK_VERBOSE; continue; case 'y': break; case '?': default: usage(); /* NOTREACHED */ } /* Pass option to fsck_xxxfs */ globopt[1] = i; catopt(&options, globopt); } /* Don't do progress meters if we're debugging. */ if (flags & CHECK_DEBUG) flags &= ~CHECK_PROGRESS; /* * If progress meters are being used, force max parallel to 1 * so the progress meter outputs don't interfere with one another. */ if (flags & CHECK_PROGRESS) maxrun = 1; 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++) { const char *spec, *type, *cp; char device[MAXPATHLEN]; spec = *argv; cp = strrchr(spec, '/'); if (cp == 0) { (void)snprintf(device, sizeof(device), "%s%s", _PATH_DEV, spec); spec = device; } if ((fs = getfsfile(spec)) == NULL && (fs = getfsspec(spec)) == NULL) { if (vfstype == NULL) vfstype = getfslab(spec); type = vfstype; } else { spec = fs->fs_spec; type = fs->fs_vfstype; if (BADTYPE(fs->fs_type)) errx(FSCK_EXIT_CHECK_FAILED, "%s has unknown file system type.", spec); } rval = checkfs(type, blockcheck(spec), *argv, NULL, NULL); if (rval > ret) ret = rval; } return ret; }