2003-10-20 16:04:38 +04:00
|
|
|
/* $NetBSD: fsck.c,v 1.31 2003/10/20 12:04:38 dsl Exp $ */
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* 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.
|
2003-08-07 14:04:11 +04:00
|
|
|
* 3. 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
|
|
|
|
* From: NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1996 Christos Zoulas. 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.
|
1996-09-12 00:27:11 +04:00
|
|
|
* 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
|
|
|
|
* From: NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
1997-09-14 18:11:00 +04:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#ifndef lint
|
2003-10-20 16:04:38 +04:00
|
|
|
__RCSID("$NetBSD: fsck.c,v 1.31 2003/10/20 12:04:38 dsl Exp $");
|
1997-09-14 18:11:00 +04:00
|
|
|
#endif /* not lint */
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/wait.h>
|
1998-11-12 19:19:47 +03:00
|
|
|
#define FSTYPENAMES
|
|
|
|
#define FSCKNAMES
|
1996-12-05 21:30:23 +03:00
|
|
|
#include <sys/disklabel.h>
|
|
|
|
#include <sys/ioctl.h>
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fstab.h>
|
1996-12-05 21:30:23 +03:00
|
|
|
#include <fcntl.h>
|
1999-04-22 08:20:53 +04:00
|
|
|
#include <paths.h>
|
1996-09-12 00:27:11 +04:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "pathnames.h"
|
1996-09-28 02:38:37 +04:00
|
|
|
#include "fsutil.h"
|
1996-09-12 00:27:11 +04:00
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
|
1996-09-12 00:27:11 +04:00
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
TAILQ_HEAD(fstypelist, entry) opthead, selhead;
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
struct entry {
|
|
|
|
char *type;
|
1996-09-23 20:11:32 +04:00
|
|
|
char *options;
|
1996-09-12 00:27:11 +04:00
|
|
|
TAILQ_ENTRY(entry) entries;
|
|
|
|
};
|
|
|
|
|
1996-09-28 02:38:37 +04:00
|
|
|
static int maxrun = 0;
|
1996-09-23 20:11:32 +04:00
|
|
|
static char *options = NULL;
|
1996-09-28 02:38:37 +04:00
|
|
|
static int flags = 0;
|
1996-09-23 20:11:32 +04:00
|
|
|
|
2001-06-18 06:31:09 +04:00
|
|
|
int main(int, char *[]);
|
|
|
|
|
|
|
|
static int checkfs(const char *, const char *, const char *, void *, 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);
|
|
|
|
static void *isok(struct fstab *);
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
int
|
2001-06-18 06:31:09 +04:00
|
|
|
main(int argc, char *argv[])
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
|
|
|
struct fstab *fs;
|
|
|
|
int i, rval = 0;
|
1998-07-26 16:00:43 +04:00
|
|
|
const char *vfstype = NULL;
|
1996-10-04 00:06:30 +04:00
|
|
|
char globopt[3];
|
|
|
|
|
|
|
|
globopt[0] = '-';
|
|
|
|
globopt[2] = '\0';
|
1996-09-12 00:27:11 +04:00
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
TAILQ_INIT(&selhead);
|
|
|
|
TAILQ_INIT(&opthead);
|
|
|
|
|
2003-10-20 16:04:38 +04:00
|
|
|
while ((i = getopt(argc, argv, "dfl:npqT:t:vy")) != -1) {
|
1996-09-12 00:27:11 +04:00
|
|
|
switch (i) {
|
|
|
|
case 'd':
|
1996-09-28 02:38:37 +04:00
|
|
|
flags |= CHECK_DEBUG;
|
2003-10-20 16:04:38 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
flags |= CHECK_FORCE;
|
1996-09-12 00:27:11 +04:00
|
|
|
break;
|
|
|
|
|
2003-10-20 16:04:38 +04:00
|
|
|
case 'n':
|
1996-09-12 00:27:11 +04:00
|
|
|
break;
|
|
|
|
|
1996-10-04 00:06:30 +04:00
|
|
|
case 'p':
|
2003-10-20 16:04:38 +04:00
|
|
|
flags |= CHECK_PREEN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'q':
|
1996-09-23 20:11:32 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
maxrun = atoi(optarg);
|
2003-10-20 16:04:38 +04:00
|
|
|
continue;
|
1996-09-12 00:27:11 +04:00
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
case 'T':
|
1996-09-12 00:27:11 +04:00
|
|
|
if (*optarg)
|
1996-09-23 20:11:32 +04:00
|
|
|
addoption(optarg);
|
2003-10-20 16:04:38 +04:00
|
|
|
continue;
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
case 't':
|
2001-06-18 06:22:33 +04:00
|
|
|
if (TAILQ_FIRST(&selhead) != NULL)
|
1996-09-12 00:27:11 +04:00
|
|
|
errx(1, "only one -t option may be specified.");
|
1996-09-23 20:11:32 +04:00
|
|
|
|
1996-09-12 00:27:11 +04:00
|
|
|
maketypelist(optarg);
|
|
|
|
vfstype = optarg;
|
2003-10-20 16:04:38 +04:00
|
|
|
continue;
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
flags |= CHECK_VERBOSE;
|
|
|
|
continue;
|
|
|
|
|
|
|
|
case 'y':
|
1996-09-12 00:27:11 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
2003-10-20 16:04:38 +04:00
|
|
|
/* Pass option to fsck_xxxfs */
|
|
|
|
globopt[1] = i;
|
|
|
|
catopt(&options, globopt);
|
|
|
|
}
|
|
|
|
|
1996-09-12 00:27:11 +04:00
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
if (argc == 0)
|
1996-09-28 02:38:37 +04:00
|
|
|
return checkfstab(flags, maxrun, isok, checkfs);
|
1996-09-23 20:11:32 +04:00
|
|
|
|
1996-09-12 00:27:11 +04:00
|
|
|
#define BADTYPE(type) \
|
|
|
|
(strcmp(type, FSTAB_RO) && \
|
|
|
|
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
|
|
|
|
|
|
|
|
|
|
|
|
for (; argc--; argv++) {
|
1999-04-22 08:20:53 +04:00
|
|
|
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) {
|
1996-09-12 00:27:11 +04:00
|
|
|
if (vfstype == NULL)
|
1999-04-22 08:20:53 +04:00
|
|
|
vfstype = getfslab(spec);
|
1996-09-12 00:27:11 +04:00
|
|
|
type = vfstype;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
spec = fs->fs_spec;
|
|
|
|
type = fs->fs_vfstype;
|
|
|
|
if (BADTYPE(fs->fs_type))
|
|
|
|
errx(1, "%s has unknown file system type.",
|
1999-04-22 08:20:53 +04:00
|
|
|
spec);
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
1996-09-28 23:23:29 +04:00
|
|
|
rval |= checkfs(type, blockcheck(spec), *argv, NULL, NULL);
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rval;
|
|
|
|
}
|
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
|
1996-09-28 02:38:37 +04:00
|
|
|
static void *
|
2001-06-18 06:31:09 +04:00
|
|
|
isok(struct fstab *fs)
|
1996-09-23 20:11:32 +04:00
|
|
|
{
|
2001-06-18 06:31:09 +04:00
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
if (fs->fs_passno == 0)
|
1996-09-28 02:38:37 +04:00
|
|
|
return NULL;
|
1996-09-23 20:11:32 +04:00
|
|
|
|
|
|
|
if (BADTYPE(fs->fs_type))
|
1996-09-28 02:38:37 +04:00
|
|
|
return NULL;
|
1996-09-23 20:11:32 +04:00
|
|
|
|
|
|
|
if (!selected(fs->fs_vfstype))
|
1996-09-28 02:38:37 +04:00
|
|
|
return NULL;
|
1996-09-23 20:11:32 +04:00
|
|
|
|
1996-09-28 02:38:37 +04:00
|
|
|
return fs;
|
1996-09-23 20:11:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static int
|
2001-06-18 06:31:09 +04:00
|
|
|
checkfs(const char *vfstype, const char *spec, const char *mntpt, void *auxarg,
|
|
|
|
pid_t *pidp)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
|
|
|
/* List of directories containing fsck_xxx subcommands. */
|
|
|
|
static const char *edirs[] = {
|
2002-08-23 07:17:18 +04:00
|
|
|
#ifdef _PATH_RESCUE
|
|
|
|
_PATH_RESCUE,
|
|
|
|
#endif
|
1996-09-12 00:27:11 +04:00
|
|
|
_PATH_SBIN,
|
|
|
|
_PATH_USRSBIN,
|
|
|
|
NULL
|
|
|
|
};
|
1996-10-04 00:06:30 +04:00
|
|
|
const char **argv, **edir;
|
1996-09-12 00:27:11 +04:00
|
|
|
pid_t pid;
|
1997-10-31 12:11:53 +03:00
|
|
|
int argc, i, status, maxargc;
|
|
|
|
char *optbuf, execname[MAXPATHLEN + 1], execbase[MAXPATHLEN];
|
1996-09-23 20:11:32 +04:00
|
|
|
const char *extra = getoptions(vfstype);
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
#ifdef __GNUC__
|
|
|
|
/* Avoid vfork clobbering */
|
|
|
|
(void) &optbuf;
|
1996-12-05 21:30:23 +03:00
|
|
|
(void) &vfstype;
|
1996-09-12 00:27:11 +04:00
|
|
|
#endif
|
|
|
|
|
1997-10-31 12:11:53 +03:00
|
|
|
if (!strcmp(vfstype, "ufs"))
|
1996-09-28 01:51:03 +04:00
|
|
|
vfstype = MOUNT_UFS;
|
|
|
|
|
1997-10-31 12:48:04 +03:00
|
|
|
optbuf = NULL;
|
|
|
|
if (options)
|
|
|
|
catopt(&optbuf, options);
|
|
|
|
if (extra)
|
|
|
|
catopt(&optbuf, extra);
|
1996-09-23 20:11:32 +04:00
|
|
|
|
1997-10-31 12:11:53 +03:00
|
|
|
maxargc = 64;
|
|
|
|
argv = emalloc(sizeof(char *) * maxargc);
|
|
|
|
|
|
|
|
(void) snprintf(execbase, sizeof(execbase), "fsck_%s", vfstype);
|
|
|
|
argc = 0;
|
|
|
|
argv[argc++] = execbase;
|
1996-09-23 20:11:32 +04:00
|
|
|
if (optbuf)
|
1996-10-04 00:06:30 +04:00
|
|
|
mangle(optbuf, &argc, &argv, &maxargc);
|
1996-09-23 20:11:32 +04:00
|
|
|
argv[argc++] = spec;
|
1996-10-04 00:06:30 +04:00
|
|
|
argv[argc] = NULL;
|
1996-09-12 00:27:11 +04:00
|
|
|
|
1996-09-28 02:38:37 +04:00
|
|
|
if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) {
|
1996-12-05 21:30:23 +03:00
|
|
|
(void)printf("start %s %swait", mntpt,
|
|
|
|
pidp ? "no" : "");
|
|
|
|
for (i = 0; i < argc; i++)
|
1996-09-12 00:27:11 +04:00
|
|
|
(void)printf(" %s", argv[i]);
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (pid = vfork()) {
|
|
|
|
case -1: /* Error. */
|
|
|
|
warn("vfork");
|
|
|
|
if (optbuf)
|
|
|
|
free(optbuf);
|
|
|
|
return (1);
|
|
|
|
|
|
|
|
case 0: /* Child. */
|
2001-06-18 10:28:59 +04:00
|
|
|
if ((flags & CHECK_FORCE) == 0) {
|
|
|
|
struct statfs sfs;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* if mntpt is a mountpoint of a mounted file
|
|
|
|
* system and it's mounted read-write, skip it
|
|
|
|
* unless -f is given.
|
|
|
|
*/
|
|
|
|
if ((statfs(mntpt, &sfs) == 0) &&
|
|
|
|
(strcmp(mntpt, sfs.f_mntonname) == 0) &&
|
|
|
|
((sfs.f_flags & MNT_RDONLY) == 0)) {
|
|
|
|
printf(
|
|
|
|
"%s: file system is mounted read-write on %s; not checking\n",
|
|
|
|
spec, mntpt);
|
|
|
|
if ((flags & CHECK_PREEN) && auxarg != NULL)
|
|
|
|
_exit(0); /* fsck -p */
|
|
|
|
else
|
|
|
|
_exit(1); /* fsck [[-p] ...] */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1996-09-28 02:38:37 +04:00
|
|
|
if (flags & CHECK_DEBUG)
|
1996-09-23 20:11:32 +04:00
|
|
|
_exit(0);
|
|
|
|
|
1996-09-12 00:27:11 +04:00
|
|
|
/* Go find an executable. */
|
|
|
|
edir = edirs;
|
|
|
|
do {
|
|
|
|
(void)snprintf(execname,
|
1996-12-05 21:30:23 +03:00
|
|
|
sizeof(execname), "%s/%s", *edir, execbase);
|
1996-09-12 00:27:11 +04:00
|
|
|
execv(execname, (char * const *)argv);
|
1998-08-25 23:18:12 +04:00
|
|
|
if (errno != ENOENT) {
|
1996-09-12 00:27:11 +04:00
|
|
|
if (spec)
|
|
|
|
warn("exec %s for %s", execname, spec);
|
|
|
|
else
|
|
|
|
warn("exec %s", execname);
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
1996-09-12 00:27:11 +04:00
|
|
|
} while (*++edir != NULL);
|
|
|
|
|
1998-08-25 23:18:12 +04:00
|
|
|
if (errno == ENOENT) {
|
1996-09-12 00:27:11 +04:00
|
|
|
if (spec)
|
|
|
|
warn("exec %s for %s", execname, spec);
|
|
|
|
else
|
|
|
|
warn("exec %s", execname);
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
1996-12-05 21:30:23 +03:00
|
|
|
_exit(1);
|
1996-09-12 00:27:11 +04:00
|
|
|
/* NOTREACHED */
|
|
|
|
|
|
|
|
default: /* Parent. */
|
|
|
|
if (optbuf)
|
|
|
|
free(optbuf);
|
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
if (pidp) {
|
|
|
|
*pidp = pid;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
1996-09-12 00:27:11 +04:00
|
|
|
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
|
2001-06-18 06:31:09 +04:00
|
|
|
selected(const char *type)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
/* If no type specified, it's always selected. */
|
2001-06-18 06:22:33 +04:00
|
|
|
TAILQ_FOREACH(e, &selhead, entries)
|
1996-09-12 00:27:11 +04:00
|
|
|
if (!strncmp(e->type, type, MFSNAMELEN))
|
|
|
|
return which == IN_LIST ? 1 : 0;
|
|
|
|
|
|
|
|
return which == IN_LIST ? 0 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
static const char *
|
2001-06-18 06:31:09 +04:00
|
|
|
getoptions(const char *type)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
|
|
|
struct entry *e;
|
|
|
|
|
2001-06-18 06:22:33 +04:00
|
|
|
TAILQ_FOREACH(e, &opthead, entries)
|
1996-09-23 20:11:32 +04:00
|
|
|
if (!strncmp(e->type, type, MFSNAMELEN))
|
|
|
|
return e->options;
|
|
|
|
return "";
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-06-18 06:31:09 +04:00
|
|
|
addoption(char *optstr)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
1996-09-23 20:11:32 +04:00
|
|
|
char *newoptions;
|
1996-09-12 00:27:11 +04:00
|
|
|
struct entry *e;
|
|
|
|
|
1996-09-23 20:11:32 +04:00
|
|
|
if ((newoptions = strchr(optstr, ':')) == NULL)
|
|
|
|
errx(1, "Invalid option string");
|
|
|
|
|
|
|
|
*newoptions++ = '\0';
|
|
|
|
|
2001-06-18 06:22:33 +04:00
|
|
|
TAILQ_FOREACH(e, &opthead, entries)
|
1996-09-23 20:11:32 +04:00
|
|
|
if (!strncmp(e->type, optstr, MFSNAMELEN)) {
|
1997-10-31 12:48:04 +03:00
|
|
|
catopt(&e->options, newoptions);
|
1996-09-12 00:27:11 +04:00
|
|
|
return;
|
|
|
|
}
|
1996-09-23 20:11:32 +04:00
|
|
|
addentry(&opthead, optstr, newoptions);
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-06-18 06:31:09 +04:00
|
|
|
addentry(struct fstypelist *list, const char *type, const char *opts)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
1996-09-23 20:11:32 +04:00
|
|
|
struct entry *e;
|
|
|
|
|
|
|
|
e = emalloc(sizeof(struct entry));
|
|
|
|
e->type = estrdup(type);
|
|
|
|
e->options = estrdup(opts);
|
|
|
|
TAILQ_INSERT_TAIL(list, e, entries);
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-06-18 06:31:09 +04:00
|
|
|
maketypelist(char *fslist)
|
1996-09-12 00:27:11 +04: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)
|
1996-09-23 20:11:32 +04:00
|
|
|
addentry(&selhead, ptr, "");
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1997-10-31 12:48:04 +03:00
|
|
|
static void
|
2001-06-18 06:31:09 +04:00
|
|
|
catopt(char **sp, const char *o)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
1997-10-31 12:48:04 +03: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);
|
1997-10-31 12:11:53 +03:00
|
|
|
} else
|
1997-10-31 12:48:04 +03:00
|
|
|
s = estrdup(o);
|
|
|
|
*sp = s;
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2001-11-01 10:31:22 +03:00
|
|
|
mangle(char *opts, int *argcp, const char ***argvp, int *maxargcp)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
|
|
|
char *p, *s;
|
1997-10-31 12:11:53 +03:00
|
|
|
int argc, maxargc;
|
|
|
|
const char **argv;
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
argc = *argcp;
|
1997-10-31 12:11:53 +03:00
|
|
|
argv = *argvp;
|
1996-10-04 00:06:30 +04:00
|
|
|
maxargc = *maxargcp;
|
|
|
|
|
2001-11-01 10:31:22 +03:00
|
|
|
for (s = opts; (p = strsep(&s, ",")) != NULL;) {
|
1997-10-31 12:11:53 +03:00
|
|
|
/* Always leave space for one more argument and the NULL. */
|
1996-10-04 00:06:30 +04:00
|
|
|
if (argc >= maxargc - 3) {
|
1997-10-31 12:11:53 +03:00
|
|
|
maxargc <<= 1;
|
1996-10-04 00:06:30 +04:00
|
|
|
argv = erealloc(argv, maxargc * sizeof(char *));
|
|
|
|
}
|
1998-08-25 23:18:12 +04:00
|
|
|
if (*p != '\0') {
|
1996-09-12 00:27:11 +04:00
|
|
|
if (*p == '-') {
|
|
|
|
argv[argc++] = p;
|
|
|
|
p = strchr(p, '=');
|
|
|
|
if (p) {
|
|
|
|
*p = '\0';
|
|
|
|
argv[argc++] = p+1;
|
|
|
|
}
|
1997-10-31 12:11:53 +03:00
|
|
|
} else {
|
1996-09-12 00:27:11 +04:00
|
|
|
argv[argc++] = "-o";
|
|
|
|
argv[argc++] = p;
|
|
|
|
}
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
1996-10-04 00:06:30 +04:00
|
|
|
}
|
1996-09-12 00:27:11 +04:00
|
|
|
|
|
|
|
*argcp = argc;
|
1996-10-04 00:06:30 +04:00
|
|
|
*argvp = argv;
|
|
|
|
*maxargcp = maxargc;
|
1996-09-12 00:27:11 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1998-07-26 16:00:43 +04:00
|
|
|
const static char *
|
2001-06-18 06:31:09 +04:00
|
|
|
getfslab(const char *str)
|
1996-12-05 21:30:23 +03:00
|
|
|
{
|
|
|
|
struct disklabel dl;
|
|
|
|
int fd;
|
1998-07-26 16:00:43 +04:00
|
|
|
char p;
|
|
|
|
const char *vfstype;
|
1996-12-05 21:30:23 +03:00
|
|
|
u_char t;
|
|
|
|
|
2001-06-18 10:28:59 +04:00
|
|
|
/* deduce the file system type from the disk label */
|
1996-12-05 21:30:23 +03:00
|
|
|
if ((fd = open(str, O_RDONLY)) == -1)
|
|
|
|
err(1, "cannot open `%s'", str);
|
|
|
|
|
|
|
|
if (ioctl(fd, DIOCGDINFO, &dl) == -1)
|
|
|
|
err(1, "cannot get disklabel for `%s'", str);
|
|
|
|
|
|
|
|
(void) close(fd);
|
|
|
|
|
|
|
|
p = str[strlen(str) - 1];
|
|
|
|
|
|
|
|
if ((p - 'a') >= dl.d_npartitions)
|
|
|
|
errx(1, "partition `%s' is not defined on disk", str);
|
|
|
|
|
1997-10-13 13:44:18 +04:00
|
|
|
if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES)
|
1996-12-05 21:30:23 +03:00
|
|
|
errx(1, "partition `%s' is not of a legal vfstype",
|
1997-06-23 05:03:35 +04:00
|
|
|
str);
|
1996-12-05 21:30:23 +03:00
|
|
|
|
|
|
|
if ((vfstype = fscknames[t]) == NULL)
|
|
|
|
errx(1, "vfstype `%s' on partition `%s' is not supported",
|
|
|
|
fstypenames[t], str);
|
|
|
|
|
|
|
|
return vfstype;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1996-09-12 00:27:11 +04:00
|
|
|
static void
|
2001-06-18 06:31:09 +04:00
|
|
|
usage(void)
|
1996-09-12 00:27:11 +04:00
|
|
|
{
|
1996-09-23 20:11:32 +04:00
|
|
|
static const char common[] =
|
2003-10-20 16:04:38 +04:00
|
|
|
"[-dfnpqvy] [-T fstype:fsoptions] [-t fstype]";
|
1996-09-12 00:27:11 +04:00
|
|
|
|
1996-09-28 02:38:37 +04:00
|
|
|
(void)fprintf(stderr, "Usage: %s %s [special|node]...\n",
|
2001-02-20 01:48:57 +03:00
|
|
|
getprogname(), common);
|
1996-09-12 00:27:11 +04:00
|
|
|
exit(1);
|
|
|
|
}
|