diff --git a/sbin/fsck/fsck.c b/sbin/fsck/fsck.c --- a/sbin/fsck/fsck.c +++ b/sbin/fsck/fsck.c @@ -254,6 +254,9 @@ return (0); if (!selected(fs->fs_vfstype)) return (0); + /* If failok, always check now */ + if (getfsopt(fs, "failok")) + return (1); /* * If the -B flag has been given, then process the needed * background checks. Background checks cannot be run on diff --git a/sbin/fsck/fsutil.h b/sbin/fsck/fsutil.h --- a/sbin/fsck/fsutil.h +++ b/sbin/fsck/fsutil.h @@ -28,6 +28,9 @@ * $FreeBSD$ */ +int checkfstab(int, int (*)(struct fstab *), + int (*) (const char *, const char *, const char *, const char *, pid_t *)); +int getfsopt(struct fstab *, const char *); void pfatal(const char *, ...) __printflike(1, 2); void pwarn(const char *, ...) __printflike(1, 2); void perr(const char *, ...) __printflike(1, 2); @@ -46,7 +49,3 @@ #define CHECK_BACKGRD 0x0008 #define DO_BACKGRD 0x0010 #define CHECK_CLEAN 0x0020 - -struct fstab; -int checkfstab(int, int (*)(struct fstab *), - int (*) (const char *, const char *, const char *, const char *, pid_t *)); diff --git a/sbin/fsck/fsutil.c b/sbin/fsck/fsutil.c --- a/sbin/fsck/fsutil.c +++ b/sbin/fsck/fsutil.c @@ -42,6 +42,7 @@ #include #include +#include #include #include #include @@ -55,6 +56,44 @@ static void vmsg(int, const char *, va_list) __printflike(2, 0); +/* + * The getfsopt() function checks whether an option is present in + * an fstab(5) fs_mntops entry. There are six possible cases: + * + * fs_mntops getfsopt result + * rw,foo foo true + * rw,nofoo nofoo true + * rw,nofoo foo false + * rw,foo nofoo false + * rw foo false + * rw nofoo false + * + * This function should be part of and documented in getfsent(3). + */ +int +getfsopt(struct fstab *fs, const char *option) +{ + int negative, found; + char *opt, *optbuf; + + if (option[0] == 'n' && option[1] == 'o') { + negative = 1; + option += 2; + } else + negative = 0; + optbuf = strdup(fs->fs_mntops); + found = 0; + for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) { + if (opt[0] == 'n' && opt[1] == 'o') { + if (!strcasecmp(opt + 2, option)) + found = negative; + } else if (!strcasecmp(opt, option)) + found = !negative; + } + free(optbuf); + return (found); +} + void setcdevname(const char *cd, int pr) { diff --git a/sbin/fsck/preen.c b/sbin/fsck/preen.c --- a/sbin/fsck/preen.c +++ b/sbin/fsck/preen.c @@ -62,6 +62,7 @@ char *p_devname; /* device name */ char *p_mntpt; /* mount point */ char *p_type; /* file system type */ + int p_failok; /* failok option set */ }; static TAILQ_HEAD(part, partentry) badh; @@ -78,7 +79,7 @@ static int nrun = 0, ndisks = 0; static struct diskentry *finddisk(const char *); -static void addpart(const char *, const char *, const char *); +static void addpart(const char *, const char *, const char *, const int); static int startdisk(struct diskentry *, int (*)(const char *, const char *, const char *, const char *, pid_t *)); static void printpart(void); @@ -132,7 +133,6 @@ } sumstatus = (*checkit)(fs->fs_vfstype, name, fs->fs_file, NULL, NULL); - if (sumstatus) return (sumstatus); continue; @@ -143,7 +143,8 @@ sumstatus |= 8; continue; } - addpart(fs->fs_vfstype, name, fs->fs_file); + addpart(fs->fs_vfstype, name, fs->fs_file, + getfsopt(fs, "failok")); } if ((flags & CHECK_PREEN) == 0 || passno == 1 || @@ -172,12 +173,17 @@ continue; } - if (WIFEXITED(status)) + p = TAILQ_FIRST(&d->d_part); + + if (WIFEXITED(status) == 0) { + retcode = 0; + } else if (p->p_failok == 0) { retcode = WEXITSTATUS(status); - else + } else { retcode = 0; - - p = TAILQ_FIRST(&d->d_part); + fprintf(stderr, "%s: failok SPECIFIED, FSCK " + "ERROR(S) IGNORED\n", p->p_devname); + } if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) (void) printf("done %s: %s (%s) = 0x%x\n", @@ -243,7 +249,6 @@ return (0); } - static struct diskentry * finddisk(const char *name) { @@ -297,7 +302,7 @@ static void -addpart(const char *type, const char *dev, const char *mntpt) +addpart(const char *type, const char *dev, const char *mntpt, const int failok) { struct diskentry *d = finddisk(dev); struct partentry *p; @@ -312,6 +317,7 @@ p->p_devname = estrdup(dev); p->p_mntpt = estrdup(mntpt); p->p_type = estrdup(type); + p->p_failok = failok; TAILQ_INSERT_TAIL(&d->d_part, p, p_entries); }