Home | History | Annotate | Line # | Download | only in fsck
fsck.c revision 1.13.2.1
      1  1.13.2.1    mellon /*	$NetBSD: fsck.c,v 1.13.2.1 1997/10/31 21:18:29 mellon Exp $	*/
      2       1.1  christos 
      3       1.1  christos /*
      4       1.1  christos  * Copyright (c) 1996 Christos Zoulas. All rights reserved.
      5       1.1  christos  * Copyright (c) 1980, 1989, 1993, 1994
      6       1.1  christos  *	The Regents of the University of California.  All rights reserved.
      7       1.1  christos  *
      8       1.1  christos  * Redistribution and use in source and binary forms, with or without
      9       1.1  christos  * modification, are permitted provided that the following conditions
     10       1.1  christos  * are met:
     11       1.1  christos  * 1. Redistributions of source code must retain the above copyright
     12       1.1  christos  *    notice, this list of conditions and the following disclaimer.
     13       1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     14       1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     15       1.1  christos  *    documentation and/or other materials provided with the distribution.
     16       1.1  christos  * 3. All advertising materials mentioning features or use of this software
     17       1.1  christos  *    must display the following acknowledgement:
     18       1.1  christos  *	This product includes software developed by the University of
     19       1.1  christos  *	California, Berkeley and its contributors.
     20       1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     21       1.1  christos  *    may be used to endorse or promote products derived from this software
     22       1.1  christos  *    without specific prior written permission.
     23       1.1  christos  *
     24       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     25       1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     26       1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     27       1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     28       1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     29       1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     30       1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     31       1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     32       1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     33       1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34       1.1  christos  * SUCH DAMAGE.
     35       1.1  christos  *
     36       1.1  christos  * From: @(#)mount.c	8.19 (Berkeley) 4/19/94
     37       1.1  christos  * From: NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp
     38       1.1  christos  *
     39       1.1  christos  */
     40       1.1  christos 
     41      1.12     lukem #include <sys/cdefs.h>
     42      1.12     lukem #ifndef lint
     43  1.13.2.1    mellon __RCSID("$NetBSD: fsck.c,v 1.13.2.1 1997/10/31 21:18:29 mellon Exp $");
     44      1.12     lukem #endif /* not lint */
     45       1.1  christos 
     46       1.1  christos #include <sys/param.h>
     47       1.1  christos #include <sys/mount.h>
     48       1.1  christos #include <sys/queue.h>
     49       1.1  christos #include <sys/wait.h>
     50       1.8  christos #define DKTYPENAMES
     51       1.8  christos #include <sys/disklabel.h>
     52       1.8  christos #include <sys/ioctl.h>
     53       1.1  christos 
     54       1.1  christos #include <err.h>
     55       1.1  christos #include <errno.h>
     56       1.1  christos #include <fstab.h>
     57       1.8  christos #include <fcntl.h>
     58       1.1  christos #include <signal.h>
     59       1.1  christos #include <stdio.h>
     60       1.1  christos #include <stdlib.h>
     61       1.1  christos #include <string.h>
     62       1.1  christos #include <unistd.h>
     63       1.1  christos 
     64       1.1  christos #include "pathnames.h"
     65       1.4  christos #include "fsutil.h"
     66       1.1  christos 
     67       1.2  christos static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST;
     68       1.1  christos 
     69       1.2  christos TAILQ_HEAD(fstypelist, entry) opthead, selhead;
     70       1.1  christos 
     71       1.1  christos struct entry {
     72       1.1  christos 	char *type;
     73       1.2  christos 	char *options;
     74       1.1  christos 	TAILQ_ENTRY(entry) entries;
     75       1.1  christos };
     76       1.1  christos 
     77       1.4  christos static int maxrun = 0;
     78       1.2  christos static char *options = NULL;
     79       1.4  christos static int flags = 0;
     80       1.2  christos 
     81       1.2  christos int main __P((int, char *[]));
     82       1.1  christos 
     83       1.5  christos static int checkfs __P((const char *, const char *, const char *, void *,
     84       1.5  christos     pid_t *));
     85       1.1  christos static int selected __P((const char *));
     86       1.2  christos static void addoption __P((char *));
     87       1.2  christos static const char *getoptions __P((const char *));
     88       1.2  christos static void addentry __P((struct fstypelist *, const char *, const char *));
     89       1.1  christos static void maketypelist __P((char *));
     90  1.13.2.1    mellon static void catopt __P((char **, const char *));
     91       1.7  christos static void mangle __P((char *, int *, const char ***, int *));
     92       1.8  christos static char *getfslab __P((const char *));
     93       1.1  christos static void usage __P((void));
     94       1.4  christos static void *isok __P((struct fstab *));
     95       1.1  christos 
     96       1.1  christos int
     97       1.1  christos main(argc, argv)
     98       1.1  christos 	int argc;
     99       1.2  christos 	char *argv[];
    100       1.1  christos {
    101       1.1  christos 	struct fstab *fs;
    102       1.1  christos 	int i, rval = 0;
    103       1.1  christos 	char *vfstype = NULL;
    104       1.7  christos 	char globopt[3];
    105       1.7  christos 
    106       1.7  christos 	globopt[0] = '-';
    107       1.7  christos 	globopt[2] = '\0';
    108       1.1  christos 
    109       1.2  christos 	TAILQ_INIT(&selhead);
    110       1.2  christos 	TAILQ_INIT(&opthead);
    111       1.2  christos 
    112       1.7  christos 	while ((i = getopt(argc, argv, "dvpfnyl:t:T:")) != -1)
    113       1.1  christos 		switch (i) {
    114       1.1  christos 		case 'd':
    115       1.4  christos 			flags |= CHECK_DEBUG;
    116       1.1  christos 			break;
    117       1.1  christos 
    118       1.1  christos 		case 'v':
    119       1.4  christos 			flags |= CHECK_VERBOSE;
    120       1.1  christos 			break;
    121       1.1  christos 
    122       1.7  christos 		case 'p':
    123       1.7  christos 			flags |= CHECK_PREEN;
    124       1.7  christos 			/*FALLTHROUGH*/
    125       1.7  christos 		case 'n':
    126       1.7  christos 		case 'f':
    127       1.1  christos 		case 'y':
    128       1.7  christos 			globopt[1] = i;
    129  1.13.2.1    mellon 			catopt(&options, globopt);
    130       1.2  christos 			break;
    131       1.2  christos 
    132       1.2  christos 		case 'l':
    133       1.2  christos 			maxrun = atoi(optarg);
    134       1.1  christos 			break;
    135       1.1  christos 
    136       1.2  christos 		case 'T':
    137       1.1  christos 			if (*optarg)
    138       1.2  christos 				addoption(optarg);
    139       1.1  christos 			break;
    140       1.1  christos 
    141       1.1  christos 		case 't':
    142       1.2  christos 			if (selhead.tqh_first != NULL)
    143       1.1  christos 				errx(1, "only one -t option may be specified.");
    144       1.2  christos 
    145       1.1  christos 			maketypelist(optarg);
    146       1.1  christos 			vfstype = optarg;
    147       1.1  christos 			break;
    148       1.1  christos 
    149       1.1  christos 		case '?':
    150       1.1  christos 		default:
    151       1.1  christos 			usage();
    152       1.1  christos 			/* NOTREACHED */
    153       1.1  christos 		}
    154       1.1  christos 
    155       1.1  christos 	argc -= optind;
    156       1.1  christos 	argv += optind;
    157       1.1  christos 
    158       1.2  christos 	if (argc == 0)
    159       1.4  christos 		return checkfstab(flags, maxrun, isok, checkfs);
    160       1.2  christos 
    161       1.1  christos #define	BADTYPE(type)							\
    162       1.1  christos 	(strcmp(type, FSTAB_RO) &&					\
    163       1.1  christos 	    strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
    164       1.1  christos 
    165       1.1  christos 
    166       1.1  christos 	for (; argc--; argv++) {
    167       1.1  christos 		char *spec, *type;
    168       1.1  christos 
    169       1.1  christos 		if ((fs = getfsfile(*argv)) == NULL &&
    170       1.1  christos 		    (fs = getfsspec(*argv)) == NULL) {
    171       1.1  christos 			if (vfstype == NULL)
    172       1.8  christos 				vfstype = getfslab(*argv);
    173       1.1  christos 			spec = *argv;
    174       1.1  christos 			type = vfstype;
    175       1.1  christos 		}
    176       1.1  christos 		else {
    177       1.1  christos 			spec = fs->fs_spec;
    178       1.1  christos 			type = fs->fs_vfstype;
    179       1.1  christos 			if (BADTYPE(fs->fs_type))
    180       1.1  christos 				errx(1, "%s has unknown file system type.",
    181       1.1  christos 				    *argv);
    182       1.1  christos 		}
    183       1.1  christos 
    184       1.6  christos 		rval |= checkfs(type, blockcheck(spec), *argv, NULL, NULL);
    185       1.1  christos 	}
    186       1.1  christos 
    187       1.1  christos 	return rval;
    188       1.1  christos }
    189       1.1  christos 
    190       1.2  christos 
    191       1.4  christos static void *
    192       1.2  christos isok(fs)
    193       1.2  christos 	struct fstab *fs;
    194       1.2  christos {
    195       1.2  christos 	if (fs->fs_passno == 0)
    196       1.4  christos 		return NULL;
    197       1.2  christos 
    198       1.2  christos 	if (BADTYPE(fs->fs_type))
    199       1.4  christos 		return NULL;
    200       1.2  christos 
    201       1.2  christos 	if (!selected(fs->fs_vfstype))
    202       1.4  christos 		return NULL;
    203       1.2  christos 
    204       1.4  christos 	return fs;
    205       1.2  christos }
    206       1.2  christos 
    207       1.2  christos 
    208       1.1  christos static int
    209       1.6  christos checkfs(vfstype, spec, mntpt, auxarg, pidp)
    210       1.4  christos 	const char *vfstype, *spec, *mntpt;
    211       1.5  christos 	void *auxarg;
    212       1.5  christos 	pid_t *pidp;
    213       1.1  christos {
    214       1.1  christos 	/* List of directories containing fsck_xxx subcommands. */
    215       1.1  christos 	static const char *edirs[] = {
    216       1.1  christos 		_PATH_SBIN,
    217       1.1  christos 		_PATH_USRSBIN,
    218       1.1  christos 		NULL
    219       1.1  christos 	};
    220       1.7  christos 	const char **argv, **edir;
    221       1.1  christos 	pid_t pid;
    222  1.13.2.1    mellon 	int argc, i, status, maxargc;
    223  1.13.2.1    mellon 	char *optbuf, execname[MAXPATHLEN + 1], execbase[MAXPATHLEN];
    224       1.2  christos 	const char *extra = getoptions(vfstype);
    225       1.1  christos 
    226       1.1  christos #ifdef __GNUC__
    227       1.1  christos 	/* Avoid vfork clobbering */
    228       1.1  christos 	(void) &optbuf;
    229       1.8  christos 	(void) &vfstype;
    230       1.1  christos #endif
    231       1.1  christos 
    232  1.13.2.1    mellon 	if (!strcmp(vfstype, "ufs"))
    233       1.3       cgd 		vfstype = MOUNT_UFS;
    234       1.3       cgd 
    235  1.13.2.1    mellon 	optbuf = NULL;
    236  1.13.2.1    mellon 	if (options)
    237  1.13.2.1    mellon 		catopt(&optbuf, options);
    238  1.13.2.1    mellon 	if (extra)
    239  1.13.2.1    mellon 		catopt(&optbuf, extra);
    240  1.13.2.1    mellon 
    241  1.13.2.1    mellon 	maxargc = 64;
    242       1.7  christos 	argv = emalloc(sizeof(char *) * maxargc);
    243       1.7  christos 
    244       1.9  christos 	(void) snprintf(execbase, sizeof(execbase), "fsck_%s", vfstype);
    245  1.13.2.1    mellon 	argc = 0;
    246  1.13.2.1    mellon 	argv[argc++] = execbase;
    247       1.2  christos 	if (optbuf)
    248       1.7  christos 		mangle(optbuf, &argc, &argv, &maxargc);
    249       1.2  christos 	argv[argc++] = spec;
    250       1.7  christos 	argv[argc] = NULL;
    251       1.1  christos 
    252       1.4  christos 	if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) {
    253       1.8  christos 		(void)printf("start %s %swait", mntpt,
    254       1.8  christos 			pidp ? "no" : "");
    255       1.8  christos 		for (i = 0; i < argc; i++)
    256       1.1  christos 			(void)printf(" %s", argv[i]);
    257       1.1  christos 		(void)printf("\n");
    258       1.1  christos 	}
    259       1.1  christos 
    260       1.1  christos 	switch (pid = vfork()) {
    261       1.1  christos 	case -1:				/* Error. */
    262       1.1  christos 		warn("vfork");
    263       1.1  christos 		if (optbuf)
    264       1.1  christos 			free(optbuf);
    265       1.1  christos 		return (1);
    266       1.1  christos 
    267       1.1  christos 	case 0:					/* Child. */
    268       1.4  christos 		if (flags & CHECK_DEBUG)
    269       1.2  christos 			_exit(0);
    270       1.2  christos 
    271       1.1  christos 		/* Go find an executable. */
    272       1.1  christos 		edir = edirs;
    273       1.1  christos 		do {
    274       1.1  christos 			(void)snprintf(execname,
    275       1.8  christos 			    sizeof(execname), "%s/%s", *edir, execbase);
    276       1.1  christos 			execv(execname, (char * const *)argv);
    277       1.1  christos 			if (errno != ENOENT)
    278       1.1  christos 				if (spec)
    279       1.1  christos 					warn("exec %s for %s", execname, spec);
    280       1.1  christos 				else
    281       1.1  christos 					warn("exec %s", execname);
    282       1.1  christos 		} while (*++edir != NULL);
    283       1.1  christos 
    284       1.1  christos 		if (errno == ENOENT)
    285       1.1  christos 			if (spec)
    286       1.1  christos 				warn("exec %s for %s", execname, spec);
    287       1.1  christos 			else
    288       1.1  christos 				warn("exec %s", execname);
    289       1.8  christos 		_exit(1);
    290       1.1  christos 		/* NOTREACHED */
    291       1.1  christos 
    292       1.1  christos 	default:				/* Parent. */
    293       1.1  christos 		if (optbuf)
    294       1.1  christos 			free(optbuf);
    295       1.1  christos 
    296       1.2  christos 		if (pidp) {
    297       1.2  christos 			*pidp = pid;
    298       1.2  christos 			return 0;
    299       1.2  christos 		}
    300       1.2  christos 
    301       1.1  christos 		if (waitpid(pid, &status, 0) < 0) {
    302       1.1  christos 			warn("waitpid");
    303       1.1  christos 			return (1);
    304       1.1  christos 		}
    305       1.1  christos 
    306       1.1  christos 		if (WIFEXITED(status)) {
    307       1.1  christos 			if (WEXITSTATUS(status) != 0)
    308       1.1  christos 				return (WEXITSTATUS(status));
    309       1.1  christos 		}
    310       1.1  christos 		else if (WIFSIGNALED(status)) {
    311       1.1  christos 			warnx("%s: %s", spec, strsignal(WTERMSIG(status)));
    312       1.1  christos 			return (1);
    313       1.1  christos 		}
    314       1.1  christos 		break;
    315       1.1  christos 	}
    316       1.1  christos 
    317       1.1  christos 	return (0);
    318       1.1  christos }
    319       1.1  christos 
    320       1.1  christos 
    321       1.1  christos static int
    322       1.1  christos selected(type)
    323       1.1  christos 	const char *type;
    324       1.1  christos {
    325       1.1  christos 	struct entry *e;
    326       1.1  christos 
    327       1.1  christos 	/* If no type specified, it's always selected. */
    328       1.2  christos 	for (e = selhead.tqh_first; e != NULL; e = e->entries.tqe_next)
    329       1.1  christos 		if (!strncmp(e->type, type, MFSNAMELEN))
    330       1.1  christos 			return which == IN_LIST ? 1 : 0;
    331       1.1  christos 
    332       1.1  christos 	return which == IN_LIST ? 0 : 1;
    333       1.1  christos }
    334       1.1  christos 
    335       1.1  christos 
    336       1.2  christos static const char *
    337       1.2  christos getoptions(type)
    338       1.1  christos 	const char *type;
    339       1.1  christos {
    340       1.1  christos 	struct entry *e;
    341       1.1  christos 
    342       1.2  christos 	for (e = opthead.tqh_first; e != NULL; e = e->entries.tqe_next)
    343       1.2  christos 		if (!strncmp(e->type, type, MFSNAMELEN))
    344       1.2  christos 			return e->options;
    345       1.2  christos 	return "";
    346       1.1  christos }
    347       1.1  christos 
    348       1.1  christos 
    349       1.1  christos static void
    350       1.2  christos addoption(optstr)
    351       1.2  christos 	char *optstr;
    352       1.1  christos {
    353       1.2  christos 	char *newoptions;
    354       1.1  christos 	struct entry *e;
    355       1.1  christos 
    356       1.2  christos 	if ((newoptions = strchr(optstr, ':')) == NULL)
    357       1.2  christos 		errx(1, "Invalid option string");
    358       1.2  christos 
    359       1.2  christos 	*newoptions++ = '\0';
    360       1.2  christos 
    361       1.2  christos 	for (e = opthead.tqh_first; e != NULL; e = e->entries.tqe_next)
    362       1.2  christos 		if (!strncmp(e->type, optstr, MFSNAMELEN)) {
    363  1.13.2.1    mellon 			catopt(&e->options, newoptions);
    364       1.1  christos 			return;
    365       1.1  christos 		}
    366       1.2  christos 	addentry(&opthead, optstr, newoptions);
    367       1.1  christos }
    368       1.1  christos 
    369       1.1  christos 
    370       1.1  christos static void
    371       1.2  christos addentry(list, type, opts)
    372       1.2  christos 	struct fstypelist *list;
    373       1.1  christos 	const char *type;
    374       1.2  christos 	const char *opts;
    375       1.1  christos {
    376       1.2  christos 	struct entry *e;
    377       1.2  christos 
    378       1.2  christos 	e = emalloc(sizeof(struct entry));
    379       1.2  christos 	e->type = estrdup(type);
    380       1.2  christos 	e->options = estrdup(opts);
    381       1.2  christos 	TAILQ_INSERT_TAIL(list, e, entries);
    382       1.1  christos }
    383       1.1  christos 
    384       1.1  christos 
    385       1.1  christos static void
    386       1.1  christos maketypelist(fslist)
    387       1.1  christos 	char *fslist;
    388       1.1  christos {
    389       1.1  christos 	char *ptr;
    390       1.1  christos 
    391       1.1  christos 	if ((fslist == NULL) || (fslist[0] == '\0'))
    392       1.1  christos 		errx(1, "empty type list");
    393       1.1  christos 
    394       1.1  christos 	if (fslist[0] == 'n' && fslist[1] == 'o') {
    395       1.1  christos 		fslist += 2;
    396       1.1  christos 		which = NOT_IN_LIST;
    397       1.1  christos 	}
    398       1.1  christos 	else
    399       1.1  christos 		which = IN_LIST;
    400       1.1  christos 
    401       1.1  christos 	while ((ptr = strsep(&fslist, ",")) != NULL)
    402       1.2  christos 		addentry(&selhead, ptr, "");
    403       1.1  christos 
    404       1.1  christos }
    405       1.1  christos 
    406       1.1  christos 
    407  1.13.2.1    mellon static void
    408  1.13.2.1    mellon catopt(sp, o)
    409  1.13.2.1    mellon 	char **sp;
    410  1.13.2.1    mellon 	const char *o;
    411       1.1  christos {
    412  1.13.2.1    mellon 	char *s;
    413  1.13.2.1    mellon 	size_t i, j;
    414       1.1  christos 
    415  1.13.2.1    mellon 	s = *sp;
    416  1.13.2.1    mellon 	if (s) {
    417  1.13.2.1    mellon 		i = strlen(s);
    418  1.13.2.1    mellon 		j = i + 1 + strlen(o) + 1;
    419  1.13.2.1    mellon 		s = erealloc(s, j);
    420  1.13.2.1    mellon 		(void)snprintf(s + i, j, ",%s", o);
    421  1.13.2.1    mellon 	} else
    422  1.13.2.1    mellon 		s = estrdup(o);
    423  1.13.2.1    mellon 	*sp = s;
    424       1.1  christos }
    425       1.1  christos 
    426       1.1  christos 
    427       1.1  christos static void
    428  1.13.2.1    mellon mangle(options, argcp, argvp, maxargcp)
    429  1.13.2.1    mellon 	char *options;
    430  1.13.2.1    mellon 	int *argcp, *maxargcp;
    431       1.7  christos 	const char ***argvp;
    432       1.1  christos {
    433       1.1  christos 	char *p, *s;
    434  1.13.2.1    mellon 	int argc, maxargc;
    435  1.13.2.1    mellon 	const char **argv;
    436       1.1  christos 
    437       1.1  christos 	argc = *argcp;
    438  1.13.2.1    mellon 	argv = *argvp;
    439       1.7  christos 	maxargc = *maxargcp;
    440       1.7  christos 
    441  1.13.2.1    mellon 	for (s = options; (p = strsep(&s, ",")) != NULL;) {
    442  1.13.2.1    mellon 		/* Always leave space for one more argument and the NULL. */
    443       1.7  christos 		if (argc >= maxargc - 3) {
    444  1.13.2.1    mellon 			maxargc <<= 1;
    445       1.7  christos 			argv = erealloc(argv, maxargc * sizeof(char *));
    446       1.7  christos 		}
    447       1.1  christos 		if (*p != '\0')
    448       1.1  christos 			if (*p == '-') {
    449       1.1  christos 				argv[argc++] = p;
    450       1.1  christos 				p = strchr(p, '=');
    451       1.1  christos 				if (p) {
    452       1.1  christos 					*p = '\0';
    453       1.1  christos 					argv[argc++] = p+1;
    454       1.1  christos 				}
    455  1.13.2.1    mellon 			} else {
    456       1.1  christos 				argv[argc++] = "-o";
    457       1.1  christos 				argv[argc++] = p;
    458       1.1  christos 			}
    459       1.7  christos 	}
    460       1.1  christos 
    461       1.1  christos 	*argcp = argc;
    462       1.7  christos 	*argvp = argv;
    463       1.7  christos 	*maxargcp = maxargc;
    464       1.1  christos }
    465       1.8  christos 
    466       1.8  christos 
    467       1.8  christos static char *
    468       1.8  christos getfslab(str)
    469       1.8  christos 	const char *str;
    470       1.8  christos {
    471       1.8  christos 	struct disklabel dl;
    472       1.8  christos 	int fd;
    473       1.8  christos 	char p, *vfstype;
    474       1.8  christos 	u_char t;
    475       1.8  christos 
    476       1.8  christos 	/* deduce the filesystem type from the disk label */
    477       1.8  christos 	if ((fd = open(str, O_RDONLY)) == -1)
    478       1.8  christos 		err(1, "cannot open `%s'", str);
    479       1.8  christos 
    480       1.8  christos 	if (ioctl(fd, DIOCGDINFO, &dl) == -1)
    481       1.8  christos 		err(1, "cannot get disklabel for `%s'", str);
    482       1.8  christos 
    483       1.8  christos 	(void) close(fd);
    484       1.8  christos 
    485       1.8  christos 	p = str[strlen(str) - 1];
    486       1.8  christos 
    487       1.8  christos 	if ((p - 'a') >= dl.d_npartitions)
    488       1.8  christos 		errx(1, "partition `%s' is not defined on disk", str);
    489       1.8  christos 
    490      1.13    bouyer 	if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES)
    491       1.8  christos 		errx(1, "partition `%s' is not of a legal vfstype",
    492      1.11     mikel 		    str);
    493       1.8  christos 
    494       1.8  christos 	if ((vfstype = fscknames[t]) == NULL)
    495       1.8  christos 		errx(1, "vfstype `%s' on partition `%s' is not supported",
    496       1.8  christos 		    fstypenames[t], str);
    497       1.8  christos 
    498       1.8  christos 	return vfstype;
    499       1.8  christos }
    500       1.1  christos 
    501       1.1  christos 
    502       1.1  christos static void
    503       1.1  christos usage()
    504       1.1  christos {
    505       1.1  christos 	extern char *__progname;
    506       1.2  christos 	static const char common[] =
    507       1.4  christos 	    "[-dpvlyn] [-T fstype:fsoptions] [-t fstype]";
    508       1.1  christos 
    509       1.4  christos 	(void)fprintf(stderr, "Usage: %s %s [special|node]...\n",
    510       1.4  christos 	    __progname, common);
    511       1.1  christos 	exit(1);
    512       1.1  christos }
    513