2000-10-09 10:23:31 +00:00
|
|
|
/* $NetBSD: fsck.c,v 1.21 1999/04/22 04:20:53 abs 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
|
2000-10-10 08:57:30 +00:00
|
|
|
* From: $NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp
|
|
|
|
* $NetBSD: fsck.c,v 1.21 1999/04/22 04:20:53 abs Exp $
|
2000-10-09 10:23:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
2002-03-24 15:06:48 +00:00
|
|
|
__FBSDID("$FreeBSD$");
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
#define FSTYPENAMES
|
|
|
|
#define DKTYPENAMES
|
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
2002-03-24 15:06:48 +00:00
|
|
|
#include <ctype.h>
|
2000-10-09 10:23:31 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fstab.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <paths.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 char *options = NULL;
|
|
|
|
static int flags = 0;
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
static int forceflag = 0;
|
2000-10-09 10:23:31 +00:00
|
|
|
|
2002-03-20 22:57:10 +00:00
|
|
|
static int checkfs(const char *, const char *, const char *, char *, pid_t *);
|
|
|
|
static int selected(const char *);
|
|
|
|
static void addoption(char *);
|
|
|
|
static const char *getoptions(const char *);
|
|
|
|
static void addentry(struct fstypelist *, const char *, const char *);
|
|
|
|
static void maketypelist(char *);
|
|
|
|
static void catopt(char **, const char *);
|
|
|
|
static void mangle(char *, int *, const char ***, int *);
|
|
|
|
static const char *getfslab(const char *);
|
|
|
|
static void usage(void) __dead2;
|
|
|
|
static int isok(struct fstab *);
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
int
|
2002-03-20 22:57:10 +00:00
|
|
|
main(int argc, char *argv[])
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
struct fstab *fs;
|
|
|
|
int i, rval = 0;
|
|
|
|
const char *vfstype = NULL;
|
|
|
|
char globopt[3];
|
|
|
|
|
|
|
|
globopt[0] = '-';
|
|
|
|
globopt[2] = '\0';
|
|
|
|
|
|
|
|
TAILQ_INIT(&selhead);
|
|
|
|
TAILQ_INIT(&opthead);
|
|
|
|
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
while ((i = getopt(argc, argv, "BdvpfFnyl:t:T:")) != -1)
|
2000-10-09 10:23:31 +00:00
|
|
|
switch (i) {
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
case 'B':
|
|
|
|
if (flags & CHECK_BACKGRD)
|
|
|
|
errx(1, "Cannot specify -B and -F.");
|
|
|
|
flags |= DO_BACKGRD;
|
|
|
|
break;
|
|
|
|
|
2000-10-09 10:23:31 +00:00
|
|
|
case 'd':
|
|
|
|
flags |= CHECK_DEBUG;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
flags |= CHECK_VERBOSE;
|
|
|
|
break;
|
|
|
|
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
case 'F':
|
|
|
|
if (flags & DO_BACKGRD)
|
|
|
|
errx(1, "Cannot specify -B and -F.");
|
|
|
|
flags |= CHECK_BACKGRD;
|
|
|
|
break;
|
|
|
|
|
2000-10-09 10:23:31 +00:00
|
|
|
case 'p':
|
|
|
|
flags |= CHECK_PREEN;
|
|
|
|
/*FALLTHROUGH*/
|
|
|
|
case 'n':
|
|
|
|
case 'y':
|
|
|
|
globopt[1] = i;
|
|
|
|
catopt(&options, globopt);
|
|
|
|
break;
|
|
|
|
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
case 'f':
|
|
|
|
forceflag = 1;
|
|
|
|
globopt[1] = i;
|
|
|
|
catopt(&options, globopt);
|
|
|
|
break;
|
|
|
|
|
2000-10-09 10:23:31 +00:00
|
|
|
case 'l':
|
2001-03-30 08:01:34 +00:00
|
|
|
warnx("Ignoring obsolete -l option\n");
|
2000-10-09 10:23:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'T':
|
|
|
|
if (*optarg)
|
|
|
|
addoption(optarg);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 't':
|
2000-12-30 21:05:45 +00:00
|
|
|
if (!TAILQ_EMPTY(&selhead))
|
2000-10-09 10:23:31 +00:00
|
|
|
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)
|
2001-03-30 08:01:34 +00:00
|
|
|
return checkfstab(flags, isok, checkfs);
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
#define BADTYPE(type) \
|
|
|
|
(strcmp(type, FSTAB_RO) && \
|
|
|
|
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
|
|
|
|
|
|
|
|
|
|
|
|
for (; argc--; argv++) {
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
const char *spec, *mntpt, *type, *cp;
|
|
|
|
char device[MAXPATHLEN];
|
|
|
|
struct statfs *mntp;
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
spec = *argv;
|
|
|
|
cp = strrchr(spec, '/');
|
|
|
|
if (cp == 0) {
|
|
|
|
(void)snprintf(device, sizeof(device), "%s%s",
|
|
|
|
_PATH_DEV, spec);
|
|
|
|
spec = device;
|
|
|
|
}
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
mntp = getmntpt(spec);
|
|
|
|
if (mntp != NULL) {
|
|
|
|
spec = mntp->f_mntfromname;
|
|
|
|
mntpt = mntp->f_mntonname;
|
|
|
|
}
|
2000-10-09 10:23:31 +00:00
|
|
|
if ((fs = getfsfile(spec)) == NULL &&
|
|
|
|
(fs = getfsspec(spec)) == NULL) {
|
|
|
|
if (vfstype == NULL)
|
|
|
|
vfstype = getfslab(spec);
|
2002-10-31 15:32:39 +00:00
|
|
|
if (vfstype == NULL)
|
|
|
|
errx(1, "Could not determine filesystem type");
|
2000-10-09 10:23:31 +00:00
|
|
|
type = vfstype;
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
devcheck(spec);
|
|
|
|
} else {
|
2000-10-09 10:23:31 +00:00
|
|
|
spec = fs->fs_spec;
|
|
|
|
type = fs->fs_vfstype;
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
mntpt = fs->fs_file;
|
2000-10-09 10:23:31 +00:00
|
|
|
if (BADTYPE(fs->fs_type))
|
2002-08-21 18:11:48 +00:00
|
|
|
errx(1, "%s has unknown file system type.",
|
2000-10-09 10:23:31 +00:00
|
|
|
spec);
|
|
|
|
}
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
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;
|
2000-10-09 10:23:31 +00:00
|
|
|
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
rval |= checkfs(type, spec, mntpt, NULL, NULL);
|
2000-10-09 10:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
static int
|
2002-03-20 22:57:10 +00:00
|
|
|
isok(struct fstab *fs)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
int i;
|
2000-10-09 10:23:31 +00:00
|
|
|
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
if (fs->fs_passno == 0)
|
|
|
|
return (0);
|
2000-10-09 10:23:31 +00:00
|
|
|
if (BADTYPE(fs->fs_type))
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
return (0);
|
2000-10-09 10:23:31 +00:00
|
|
|
if (!selected(fs->fs_vfstype))
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
return (0);
|
|
|
|
/*
|
|
|
|
* If the -B flag has been given, then process the needed
|
|
|
|
* background checks. Background checks cannot be run on
|
2002-08-21 18:11:48 +00:00
|
|
|
* file systems that will be mounted read-only or that were
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
* not mounted at boot time (typically those marked `noauto').
|
2002-08-21 18:11:48 +00:00
|
|
|
* If these basic tests are passed, check with the file system
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
* itself to see if it is willing to do background checking
|
|
|
|
* by invoking its check program with the -F flag.
|
|
|
|
*/
|
|
|
|
if (flags & DO_BACKGRD) {
|
|
|
|
if (!strcmp(fs->fs_type, FSTAB_RO))
|
|
|
|
return (0);
|
|
|
|
if (getmntpt(fs->fs_spec) == NULL)
|
|
|
|
return (0);
|
|
|
|
if (checkfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, "-F", 0))
|
|
|
|
return (0);
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If the -F flag has been given, then consider deferring the
|
|
|
|
* check to background. Background checks cannot be run on
|
2002-08-21 18:11:48 +00:00
|
|
|
* file systems that will be mounted read-only or that will
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
* not be mounted at boot time (e.g., marked `noauto'). If
|
2002-08-21 18:11:48 +00:00
|
|
|
* these basic tests are passed, check with the file system
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
* itself to see if it is willing to defer to background
|
|
|
|
* checking by invoking its check program with the -F flag.
|
|
|
|
*/
|
|
|
|
if ((flags & CHECK_BACKGRD) == 0 || !strcmp(fs->fs_type, FSTAB_RO))
|
|
|
|
return (1);
|
|
|
|
for (i = strlen(fs->fs_mntops) - 6; i >= 0; i--)
|
|
|
|
if (!strncmp(&fs->fs_mntops[i], "noauto", 6))
|
|
|
|
break;
|
|
|
|
if (i >= 0)
|
|
|
|
return (1);
|
|
|
|
if (checkfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, "-F", NULL) != 0)
|
|
|
|
return (1);
|
|
|
|
printf("%s: DEFER FOR BACKGROUND CHECKING\n", fs->fs_spec);
|
|
|
|
return (0);
|
2000-10-09 10:23:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2003-04-25 01:12:35 +00:00
|
|
|
checkfs(const char *pvfstype, const char *spec, const char *mntpt,
|
2002-03-20 22:57:10 +00:00
|
|
|
char *auxopt, pid_t *pidp)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
/* 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, execname[MAXPATHLEN + 1], execbase[MAXPATHLEN];
|
2003-04-25 01:12:35 +00:00
|
|
|
char *vfstype = NULL;
|
2000-10-09 10:23:31 +00:00
|
|
|
const char *extra = NULL;
|
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
/* Avoid vfork clobbering */
|
|
|
|
(void) &optbuf;
|
|
|
|
(void) &vfstype;
|
|
|
|
#endif
|
2003-04-25 01:12:35 +00:00
|
|
|
/*
|
|
|
|
* We convert the vfstype to lowercase and any spaces to underscores
|
|
|
|
* to not confuse the issue
|
|
|
|
*
|
|
|
|
* XXX This is a kludge to make automatic filesystem type guessing
|
|
|
|
* from the disklabel work for "4.2BSD" filesystems. It does a
|
|
|
|
* very limited subset of transliteration to a normalised form of
|
|
|
|
* filesystem name, and we do not seem to enforce a filesystem
|
|
|
|
* name character set.
|
|
|
|
*/
|
|
|
|
vfstype = strdup(pvfstype);
|
|
|
|
if (vfstype == NULL)
|
|
|
|
perror("strdup(pvfstype)");
|
|
|
|
for (i = 0; i < strlen(vfstype); i++) {
|
|
|
|
vfstype[i] = tolower(vfstype[i]);
|
|
|
|
if (vfstype[i] == ' ')
|
|
|
|
vfstype[i] = '_';
|
|
|
|
}
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
extra = getoptions(vfstype);
|
|
|
|
optbuf = NULL;
|
|
|
|
if (options)
|
|
|
|
catopt(&optbuf, options);
|
|
|
|
if (extra)
|
|
|
|
catopt(&optbuf, extra);
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
if (auxopt)
|
|
|
|
catopt(&optbuf, auxopt);
|
|
|
|
else if (flags & DO_BACKGRD)
|
|
|
|
catopt(&optbuf, "-B");
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
maxargc = 64;
|
|
|
|
argv = emalloc(sizeof(char *) * maxargc);
|
|
|
|
|
|
|
|
(void) snprintf(execbase, sizeof(execbase), "fsck_%s", vfstype);
|
|
|
|
argc = 0;
|
|
|
|
argv[argc++] = execbase;
|
|
|
|
if (optbuf)
|
|
|
|
mangle(optbuf, &argc, &argv, &maxargc);
|
|
|
|
argv[argc++] = spec;
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) {
|
|
|
|
(void)printf("start %s %swait", mntpt,
|
|
|
|
pidp ? "no" : "");
|
|
|
|
for (i = 0; i < argc; i++)
|
|
|
|
(void)printf(" %s", argv[i]);
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pid = vfork()) {
|
|
|
|
case -1: /* Error. */
|
|
|
|
warn("vfork");
|
|
|
|
if (optbuf)
|
|
|
|
free(optbuf);
|
2003-04-25 01:12:35 +00:00
|
|
|
free(vfstype);
|
2000-10-09 10:23:31 +00:00
|
|
|
return (1);
|
|
|
|
|
|
|
|
case 0: /* Child. */
|
Add support for running foreground (-F) and background (-B) checks.
Traditionally, fsck is invoked before the filesystems are mounted
and all checks are done to completion at that time. If background
checking is available, fsck is invoked twice. It is first invoked
at the traditional time, before the filesystems are mounted, with
the -F flag to do checking on all the filesystems that cannot do
background checking. It is then invoked a second time, after the
system has completed going multiuser, with the -B flag to do checking
on all the filesystems that can do background checking. Unlike
the foreground checking, the background checking is started
asynchonously so that other system activity can proceed even on
the filesystems that are being checked.
At the moment, only the fast filesystem supports background checking.
To be able to do background checking, a filesystem must have been
running with soft updates, not have been marked as needing a
foreground check, and be mounted and writable when the background
check is to be done (i.e., not listed as `noauto' in /etc/fstab).
These changes are the final piece needed to support background
filesystem checking. They will not have any effect until you update
your /etc/rc to invoke fsck in its new mode of operation. I am
still playing around with exactly what those changes should be
and should be committing them later this week.
2001-04-25 07:18:22 +00:00
|
|
|
if ((flags & CHECK_DEBUG) && auxopt == NULL)
|
2000-10-09 10:23:31 +00:00
|
|
|
_exit(0);
|
|
|
|
|
|
|
|
/* Go find an executable. */
|
|
|
|
edir = edirs;
|
|
|
|
do {
|
|
|
|
(void)snprintf(execname,
|
|
|
|
sizeof(execname), "%s/%s", *edir, execbase);
|
|
|
|
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);
|
|
|
|
|
2003-04-25 01:12:35 +00:00
|
|
|
free(vfstype);
|
|
|
|
|
2000-10-09 10:23:31 +00:00
|
|
|
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
|
2002-03-20 22:57:10 +00:00
|
|
|
selected(const char *type)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
/* If no type specified, it's always selected. */
|
2000-12-30 21:05:45 +00:00
|
|
|
TAILQ_FOREACH(e, &selhead, entries)
|
2000-10-09 10:23:31 +00:00
|
|
|
if (!strncmp(e->type, type, MFSNAMELEN))
|
|
|
|
return which == IN_LIST ? 1 : 0;
|
|
|
|
|
|
|
|
return which == IN_LIST ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static const char *
|
2002-03-20 22:57:10 +00:00
|
|
|
getoptions(const char *type)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
struct entry *e;
|
|
|
|
|
2000-12-30 21:05:45 +00:00
|
|
|
TAILQ_FOREACH(e, &opthead, entries)
|
2000-10-09 10:23:31 +00:00
|
|
|
if (!strncmp(e->type, type, MFSNAMELEN))
|
|
|
|
return e->options;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-03-20 22:57:10 +00:00
|
|
|
addoption(char *optstr)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
char *newoptions;
|
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
if ((newoptions = strchr(optstr, ':')) == NULL)
|
|
|
|
errx(1, "Invalid option string");
|
|
|
|
|
|
|
|
*newoptions++ = '\0';
|
|
|
|
|
2000-12-30 21:05:45 +00:00
|
|
|
TAILQ_FOREACH(e, &opthead, entries)
|
2000-10-09 10:23:31 +00:00
|
|
|
if (!strncmp(e->type, optstr, MFSNAMELEN)) {
|
|
|
|
catopt(&e->options, newoptions);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
addentry(&opthead, optstr, newoptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-03-20 22:57:10 +00:00
|
|
|
addentry(struct fstypelist *list, const char *type, const char *opts)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
e = emalloc(sizeof(struct entry));
|
|
|
|
e->type = estrdup(type);
|
|
|
|
e->options = estrdup(opts);
|
|
|
|
TAILQ_INSERT_TAIL(list, e, entries);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-03-20 22:57:10 +00:00
|
|
|
maketypelist(char *fslist)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
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 void
|
2002-03-20 22:57:10 +00:00
|
|
|
catopt(char **sp, const char *o)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
char *s;
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
s = *sp;
|
|
|
|
if (s) {
|
|
|
|
i = strlen(s);
|
|
|
|
j = i + 1 + strlen(o) + 1;
|
|
|
|
s = erealloc(s, j);
|
|
|
|
(void)snprintf(s + i, j, ",%s", o);
|
|
|
|
} else
|
|
|
|
s = estrdup(o);
|
|
|
|
*sp = s;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-03-20 22:57:10 +00:00
|
|
|
mangle(char *options, int *argcp, const char ***argvp, int *maxargcp)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
char *p, *s;
|
|
|
|
int argc, maxargc;
|
|
|
|
const char **argv;
|
|
|
|
|
|
|
|
argc = *argcp;
|
|
|
|
argv = *argvp;
|
|
|
|
maxargc = *maxargcp;
|
|
|
|
|
|
|
|
for (s = options; (p = strsep(&s, ",")) != NULL;) {
|
|
|
|
/* Always leave space for one more argument and the NULL. */
|
|
|
|
if (argc >= maxargc - 3) {
|
|
|
|
maxargc <<= 1;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const static char *
|
2002-03-20 22:57:10 +00:00
|
|
|
getfslab(const char *str)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
struct disklabel dl;
|
|
|
|
int fd;
|
|
|
|
char p;
|
|
|
|
const char *vfstype;
|
|
|
|
u_char t;
|
|
|
|
|
2002-08-21 18:11:48 +00:00
|
|
|
/* deduce the file system type from the disk label */
|
2000-10-09 10:23:31 +00:00
|
|
|
if ((fd = open(str, O_RDONLY)) == -1)
|
|
|
|
err(1, "cannot open `%s'", str);
|
|
|
|
|
|
|
|
if (ioctl(fd, DIOCGDINFO, &dl) == -1)
|
2002-10-31 15:32:39 +00:00
|
|
|
return(NULL);
|
2000-10-09 10:23:31 +00:00
|
|
|
|
|
|
|
(void) close(fd);
|
|
|
|
|
|
|
|
p = str[strlen(str) - 1];
|
|
|
|
|
|
|
|
if ((p - 'a') >= dl.d_npartitions)
|
|
|
|
errx(1, "partition `%s' is not defined on disk", str);
|
|
|
|
|
|
|
|
if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES)
|
|
|
|
errx(1, "partition `%s' is not of a legal vfstype",
|
|
|
|
str);
|
|
|
|
|
|
|
|
if ((vfstype = fstypenames[t]) == NULL)
|
|
|
|
errx(1, "vfstype `%s' on partition `%s' is not supported",
|
|
|
|
fstypenames[t], str);
|
|
|
|
|
|
|
|
return vfstype;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2002-03-20 22:57:10 +00:00
|
|
|
usage(void)
|
2000-10-09 10:23:31 +00:00
|
|
|
{
|
|
|
|
static const char common[] =
|
2001-04-30 05:36:32 +00:00
|
|
|
"[-BFdpvlyn] [-T fstype:fsoptions] [-t fstype]";
|
2000-10-09 10:23:31 +00:00
|
|
|
|
2002-04-22 13:44:47 +00:00
|
|
|
(void)fprintf(stderr, "usage: %s %s [special|node]...\n",
|
2002-03-24 15:06:48 +00:00
|
|
|
getprogname(), common);
|
2000-10-09 10:23:31 +00:00
|
|
|
exit(1);
|
|
|
|
}
|