xref: /illumos-gate/usr/src/cmd/fs.d/ff.c (revision f45bbb21)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
57c478bd9Sstevel@tonic-gate  * Common Development and Distribution License, Version 1.0 only
67c478bd9Sstevel@tonic-gate  * (the "License").  You may not use this file except in compliance
77c478bd9Sstevel@tonic-gate  * with the License.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
107c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
117c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
127c478bd9Sstevel@tonic-gate  * and limitations under the License.
137c478bd9Sstevel@tonic-gate  *
147c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
157c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
167c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
177c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
187c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
197c478bd9Sstevel@tonic-gate  *
207c478bd9Sstevel@tonic-gate  * CDDL HEADER END
217c478bd9Sstevel@tonic-gate  */
227c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
237c478bd9Sstevel@tonic-gate /*	  All Rights Reserved  	*/
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*
2708190127Sdh  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  */
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include	<stdio.h>
32*f45bbb21SToomas Soome #include	<stdlib.h>
337c478bd9Sstevel@tonic-gate #include 	<limits.h>
347c478bd9Sstevel@tonic-gate #include	<string.h>
357c478bd9Sstevel@tonic-gate #include	<sys/fstyp.h>
367c478bd9Sstevel@tonic-gate #include	<errno.h>
377c478bd9Sstevel@tonic-gate #include	<sys/vfstab.h>
387c478bd9Sstevel@tonic-gate #include	<sys/wait.h>
397c478bd9Sstevel@tonic-gate #include	<sys/types.h>
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate #define	FSTYPE_MAX	8
427c478bd9Sstevel@tonic-gate #define	FULLPATH_MAX	64
437c478bd9Sstevel@tonic-gate #define	ARGV_MAX	1024
447c478bd9Sstevel@tonic-gate #define	VFS_PATH	"/usr/lib/fs"
457c478bd9Sstevel@tonic-gate 
467c478bd9Sstevel@tonic-gate extern char	*default_fstype();
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate char	*special = NULL;  /*  device special name  */
497c478bd9Sstevel@tonic-gate char	*fstype = NULL;	  /*  fstype name is filled in here  */
507c478bd9Sstevel@tonic-gate char	*cbasename;	  /* name of command */
517c478bd9Sstevel@tonic-gate char	*newargv[ARGV_MAX]; 	/* args for the fstype specific command  */
527c478bd9Sstevel@tonic-gate char	vfstab[] = VFSTAB;
537c478bd9Sstevel@tonic-gate 	char	full_path[FULLPATH_MAX];
547c478bd9Sstevel@tonic-gate 	char	*vfs_path = VFS_PATH;
557c478bd9Sstevel@tonic-gate int	newargc = 2;
567c478bd9Sstevel@tonic-gate 
577c478bd9Sstevel@tonic-gate struct commands {
587c478bd9Sstevel@tonic-gate 	char *c_basename;
597c478bd9Sstevel@tonic-gate 	char *c_optstr;
607c478bd9Sstevel@tonic-gate 	char *c_usgstr;
617c478bd9Sstevel@tonic-gate } cmd_data[] = {
627c478bd9Sstevel@tonic-gate 	"ff", "F:o:p:a:m:c:n:i:?IlsuV",
637c478bd9Sstevel@tonic-gate 	"[-F FSType] [-V] [current_options] [-o specific_options] special ...",
647c478bd9Sstevel@tonic-gate 	"ncheck", "F:o:?i:asV",
657c478bd9Sstevel@tonic-gate "[-F FSType] [-V] [current_options] [-o specific_options] [special ...]",
667c478bd9Sstevel@tonic-gate 	NULL, "F:o:?V",
677c478bd9Sstevel@tonic-gate 	"[-F FSType] [-V] [current_options] [-o specific_options] special ..."
687c478bd9Sstevel@tonic-gate 	};
697c478bd9Sstevel@tonic-gate struct 	commands *c_ptr;
707c478bd9Sstevel@tonic-gate 
7108190127Sdh static void usage(char *cmd, char *usg);
7208190127Sdh static void exec_specific(void);
7308190127Sdh static void lookup(void);
7408190127Sdh 
7508190127Sdh int
7608190127Sdh main(int argc, char *argv[])
777c478bd9Sstevel@tonic-gate {
787c478bd9Sstevel@tonic-gate 	FILE *fp;
797c478bd9Sstevel@tonic-gate 	struct vfstab	vfsbuf;
8008190127Sdh 	char *ptr;
817c478bd9Sstevel@tonic-gate 	int	i;
827c478bd9Sstevel@tonic-gate 	int	verbose = 0;		/* set if -V is specified */
837c478bd9Sstevel@tonic-gate 	int	F_flg = 0;
847c478bd9Sstevel@tonic-gate 	int	usgflag = 0;
857c478bd9Sstevel@tonic-gate 	int	fs_flag = 0;
867c478bd9Sstevel@tonic-gate 	int	arg;			/* argument from getopt() */
877c478bd9Sstevel@tonic-gate 	extern	char *optarg;		/* getopt specific */
887c478bd9Sstevel@tonic-gate 	extern	int optind;
897c478bd9Sstevel@tonic-gate 	extern	int opterr;
907c478bd9Sstevel@tonic-gate 	size_t	strlen();
917c478bd9Sstevel@tonic-gate 
927c478bd9Sstevel@tonic-gate 	cbasename = ptr = argv[0];
937c478bd9Sstevel@tonic-gate 	while (*ptr) {
947c478bd9Sstevel@tonic-gate 		if (*ptr++ == '/')
957c478bd9Sstevel@tonic-gate 			cbasename = ptr;
967c478bd9Sstevel@tonic-gate 	}
977c478bd9Sstevel@tonic-gate 	/*
987c478bd9Sstevel@tonic-gate 	 * If there are no arguments and command is ncheck then the generic
997c478bd9Sstevel@tonic-gate 	 * reads the VFSTAB and executes the specific module of
1007c478bd9Sstevel@tonic-gate 	 * each entry which has a numeric fsckpass field.
1017c478bd9Sstevel@tonic-gate 	 */
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate 	if (argc == 1) {		/* no arguments or options */
1047c478bd9Sstevel@tonic-gate 		if (strcmp(cbasename, "ncheck") == 0) {
1057c478bd9Sstevel@tonic-gate 			/* open VFSTAB */
1067c478bd9Sstevel@tonic-gate 			if ((fp = fopen(VFSTAB, "r")) == NULL) {
1077c478bd9Sstevel@tonic-gate 				fprintf(stderr, "%s: cannot open vfstab\n",
1087c478bd9Sstevel@tonic-gate 				    cbasename);
1097c478bd9Sstevel@tonic-gate 				exit(2);
1107c478bd9Sstevel@tonic-gate 			}
1117c478bd9Sstevel@tonic-gate 			while ((i = getvfsent(fp, &vfsbuf)) == 0) {
1127c478bd9Sstevel@tonic-gate 				if (numbers(vfsbuf.vfs_fsckpass)) {
1137c478bd9Sstevel@tonic-gate 					fstype = vfsbuf.vfs_fstype;
1147c478bd9Sstevel@tonic-gate 					newargv[newargc]  = vfsbuf.vfs_special;
1157c478bd9Sstevel@tonic-gate 					exec_specific();
1167c478bd9Sstevel@tonic-gate 				}
1177c478bd9Sstevel@tonic-gate 			}
1187c478bd9Sstevel@tonic-gate 			exit(0);
1197c478bd9Sstevel@tonic-gate 		}
1207c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Usage:\n");
1217c478bd9Sstevel@tonic-gate 		fprintf(stderr,
1227c478bd9Sstevel@tonic-gate "%s [-F FSType] [-V] [current_options] [-o specific_options] special ...\n",
1237c478bd9Sstevel@tonic-gate 		    cbasename);
1247c478bd9Sstevel@tonic-gate 		exit(2);
1257c478bd9Sstevel@tonic-gate 	}
1267c478bd9Sstevel@tonic-gate 
1277c478bd9Sstevel@tonic-gate 	for (c_ptr = cmd_data; ((c_ptr->c_basename != NULL) &&
1287c478bd9Sstevel@tonic-gate 	    (strcmp(c_ptr->c_basename, cbasename) != 0));  c_ptr++)
1297c478bd9Sstevel@tonic-gate 		;
1307c478bd9Sstevel@tonic-gate 	while ((arg = getopt(argc, argv, c_ptr->c_optstr)) != -1) {
1317c478bd9Sstevel@tonic-gate 			switch (arg) {
1327c478bd9Sstevel@tonic-gate 			case 'V':	/* echo complete command line */
1337c478bd9Sstevel@tonic-gate 				verbose = 1;
1347c478bd9Sstevel@tonic-gate 				break;
1357c478bd9Sstevel@tonic-gate 			case 'F':	/* FSType specified */
1367c478bd9Sstevel@tonic-gate 				F_flg++;
1377c478bd9Sstevel@tonic-gate 				fstype = optarg;
1387c478bd9Sstevel@tonic-gate 				break;
1397c478bd9Sstevel@tonic-gate 			case 'o':	/* FSType specific arguments */
1407c478bd9Sstevel@tonic-gate 				newargv[newargc++] = "-o";
1417c478bd9Sstevel@tonic-gate 				newargv[newargc++] = optarg;
1427c478bd9Sstevel@tonic-gate 				break;
1437c478bd9Sstevel@tonic-gate 			case '?':	/* print usage message */
1447c478bd9Sstevel@tonic-gate 				newargv[newargc++] = "-?";
1457c478bd9Sstevel@tonic-gate 				usgflag = 1;
1467c478bd9Sstevel@tonic-gate 				break;
1477c478bd9Sstevel@tonic-gate 			default:
1487c478bd9Sstevel@tonic-gate 				newargv[newargc] = (char *)malloc(3);
1497c478bd9Sstevel@tonic-gate 				sprintf(newargv[newargc++], "-%c", arg);
1507c478bd9Sstevel@tonic-gate 				if (optarg)
1517c478bd9Sstevel@tonic-gate 					newargv[newargc++] = optarg;
1527c478bd9Sstevel@tonic-gate 				break;
1537c478bd9Sstevel@tonic-gate 			}
1547c478bd9Sstevel@tonic-gate 			optarg = NULL;
1557c478bd9Sstevel@tonic-gate 	}
1567c478bd9Sstevel@tonic-gate 	if (F_flg > 1) {
1577c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: more than one FSType specified\n",
1587c478bd9Sstevel@tonic-gate 			cbasename);
1597c478bd9Sstevel@tonic-gate 		usage(cbasename, c_ptr->c_usgstr);
1607c478bd9Sstevel@tonic-gate 	}
1617c478bd9Sstevel@tonic-gate 	if (F_flg && (strlen(fstype) > (size_t)FSTYPE_MAX)) {
1627c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: FSType %s exceeds %d characters\n",
1637c478bd9Sstevel@tonic-gate 			cbasename, fstype, FSTYPE_MAX);
1647c478bd9Sstevel@tonic-gate 		exit(2);
1657c478bd9Sstevel@tonic-gate 	}
1667c478bd9Sstevel@tonic-gate 	if (optind == argc) {
1677c478bd9Sstevel@tonic-gate 		/* all commands except ncheck must exit now */
1687c478bd9Sstevel@tonic-gate 		if (strcmp(cbasename, "ncheck") != 0) {
1697c478bd9Sstevel@tonic-gate 			if ((F_flg) && (usgflag)) {
1707c478bd9Sstevel@tonic-gate 				exec_specific();
1717c478bd9Sstevel@tonic-gate 				exit(0);
1727c478bd9Sstevel@tonic-gate 			}
1737c478bd9Sstevel@tonic-gate 			usage(cbasename, c_ptr->c_usgstr);
1747c478bd9Sstevel@tonic-gate 		}
1757c478bd9Sstevel@tonic-gate 		if ((F_flg) && (usgflag)) {
1767c478bd9Sstevel@tonic-gate 			exec_specific();
1777c478bd9Sstevel@tonic-gate 			exit(0);
1787c478bd9Sstevel@tonic-gate 		}
1797c478bd9Sstevel@tonic-gate 		if (usgflag)
1807c478bd9Sstevel@tonic-gate 			usage(cbasename, c_ptr->c_usgstr);
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 		/* open VFSTAB */
1837c478bd9Sstevel@tonic-gate 		if ((fp = fopen(VFSTAB, "r")) == NULL) {
1847c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: cannot open vfstab\n", cbasename);
1857c478bd9Sstevel@tonic-gate 			exit(2);
1867c478bd9Sstevel@tonic-gate 		}
1877c478bd9Sstevel@tonic-gate 		while ((i = getvfsent(fp, &vfsbuf)) == 0) {
1887c478bd9Sstevel@tonic-gate 			if (!numbers(vfsbuf.vfs_fsckpass))
1897c478bd9Sstevel@tonic-gate 				continue;
1907c478bd9Sstevel@tonic-gate 			if ((F_flg) && (strcmp(fstype, vfsbuf.vfs_fstype) != 0))
1917c478bd9Sstevel@tonic-gate 				continue;
1927c478bd9Sstevel@tonic-gate 			fs_flag++;
1937c478bd9Sstevel@tonic-gate 			fstype = vfsbuf.vfs_fstype;
1947c478bd9Sstevel@tonic-gate 			newargv[newargc] = vfsbuf.vfs_special;
1957c478bd9Sstevel@tonic-gate 			if (verbose) {
1967c478bd9Sstevel@tonic-gate 				printf("%s -F %s ", cbasename,
1977c478bd9Sstevel@tonic-gate 				    vfsbuf.vfs_fstype);
1987c478bd9Sstevel@tonic-gate 				for (i = 2; newargv[i]; i++)
1997c478bd9Sstevel@tonic-gate 					printf("%s\n", newargv[i]);
2007c478bd9Sstevel@tonic-gate 				continue;
2017c478bd9Sstevel@tonic-gate 			}
2027c478bd9Sstevel@tonic-gate 			exec_specific();
2037c478bd9Sstevel@tonic-gate 		}
2047c478bd9Sstevel@tonic-gate 		/*
2057c478bd9Sstevel@tonic-gate 		 * if (! fs_flag) {
2067c478bd9Sstevel@tonic-gate 		 *	if (sysfs(GETFSIND, fstype) == (-1)) {
2077c478bd9Sstevel@tonic-gate 		 *		fprintf(stderr,
2087c478bd9Sstevel@tonic-gate 		 *		"%s: FSType %s not installed in the kernel\n",
2097c478bd9Sstevel@tonic-gate 		 *			cbasename, fstype);
2107c478bd9Sstevel@tonic-gate 		 *		exit(1);
2117c478bd9Sstevel@tonic-gate 		 *	}
2127c478bd9Sstevel@tonic-gate 		 * }
2137c478bd9Sstevel@tonic-gate 		 */
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 		exit(0);
2167c478bd9Sstevel@tonic-gate 	}
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	/* All other arguments must be specials */
2197c478bd9Sstevel@tonic-gate 	/*  perform a lookup if fstype is not specified  */
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	for (; optind < argc; optind++)  {
2227c478bd9Sstevel@tonic-gate 		newargv[newargc] = argv[optind];
2237c478bd9Sstevel@tonic-gate 		special = newargv[newargc];
2247c478bd9Sstevel@tonic-gate 		if ((F_flg) && (usgflag)) {
2257c478bd9Sstevel@tonic-gate 			exec_specific();
2267c478bd9Sstevel@tonic-gate 			exit(0);
2277c478bd9Sstevel@tonic-gate 		}
2287c478bd9Sstevel@tonic-gate 		if (usgflag)
2297c478bd9Sstevel@tonic-gate 			usage(cbasename, c_ptr->c_usgstr);
2307c478bd9Sstevel@tonic-gate 		if (fstype == NULL)
2317c478bd9Sstevel@tonic-gate 			lookup();
2327c478bd9Sstevel@tonic-gate 		if (verbose) {
2337c478bd9Sstevel@tonic-gate 			printf("%s -F %s ", cbasename, fstype);
2347c478bd9Sstevel@tonic-gate 			for (i = 2; newargv[i]; i++)
2357c478bd9Sstevel@tonic-gate 				printf("%s ", newargv[i]);
2367c478bd9Sstevel@tonic-gate 			printf("\n");
2377c478bd9Sstevel@tonic-gate 			continue;
2387c478bd9Sstevel@tonic-gate 		}
2397c478bd9Sstevel@tonic-gate 		exec_specific();
2407c478bd9Sstevel@tonic-gate 		if (!F_flg)
2417c478bd9Sstevel@tonic-gate 			fstype = NULL;
2427c478bd9Sstevel@tonic-gate 	}
24308190127Sdh 	return (0);
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate /* see if all numbers */
24708190127Sdh int
24808190127Sdh numbers(char *yp)
2497c478bd9Sstevel@tonic-gate {
2507c478bd9Sstevel@tonic-gate 	if (yp == NULL)
2517c478bd9Sstevel@tonic-gate 		return (0);
2527c478bd9Sstevel@tonic-gate 	while ('0' <= *yp && *yp <= '9')
2537c478bd9Sstevel@tonic-gate 		yp++;
2547c478bd9Sstevel@tonic-gate 	if (*yp)
2557c478bd9Sstevel@tonic-gate 		return (0);
2567c478bd9Sstevel@tonic-gate 	return (1);
2577c478bd9Sstevel@tonic-gate }
2587c478bd9Sstevel@tonic-gate 
25908190127Sdh static void
26008190127Sdh usage(char *cmd, char *usg)
2617c478bd9Sstevel@tonic-gate {
2627c478bd9Sstevel@tonic-gate 	fprintf(stderr, "Usage:\n");
2637c478bd9Sstevel@tonic-gate 	fprintf(stderr, "%s %s\n", cmd, usg);
2647c478bd9Sstevel@tonic-gate 	exit(2);
2657c478bd9Sstevel@tonic-gate }
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate /*
2697c478bd9Sstevel@tonic-gate  *  This looks up the /etc/vfstab entry given the device 'special'.
2707c478bd9Sstevel@tonic-gate  *  It is called when the fstype is not specified on the command line.
2717c478bd9Sstevel@tonic-gate  *
2727c478bd9Sstevel@tonic-gate  *  The following global variables are used:
2737c478bd9Sstevel@tonic-gate  *	special, fstype
2747c478bd9Sstevel@tonic-gate  */
2757c478bd9Sstevel@tonic-gate 
27608190127Sdh static void
27708190127Sdh lookup(void)
2787c478bd9Sstevel@tonic-gate {
2797c478bd9Sstevel@tonic-gate 	FILE	*fd;
2807c478bd9Sstevel@tonic-gate 	int	ret;
2817c478bd9Sstevel@tonic-gate 	struct vfstab	vget, vref;
2827c478bd9Sstevel@tonic-gate 
2837c478bd9Sstevel@tonic-gate 	if ((fd = fopen(vfstab, "r")) == NULL) {
2847c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: cannot open vfstab\n", cbasename);
2857c478bd9Sstevel@tonic-gate 		exit(1);
2867c478bd9Sstevel@tonic-gate 	}
2877c478bd9Sstevel@tonic-gate 	vfsnull(&vref);
2887c478bd9Sstevel@tonic-gate 	vref.vfs_special = special;
2897c478bd9Sstevel@tonic-gate 	ret = getvfsany(fd, &vget, &vref);
2907c478bd9Sstevel@tonic-gate 	if (ret == -1) {
2917c478bd9Sstevel@tonic-gate 		rewind(fd);
2927c478bd9Sstevel@tonic-gate 		vfsnull(&vref);
2937c478bd9Sstevel@tonic-gate 		vref.vfs_fsckdev = special;
2947c478bd9Sstevel@tonic-gate 		ret = getvfsany(fd, &vget, &vref);
2957c478bd9Sstevel@tonic-gate 	}
2967c478bd9Sstevel@tonic-gate 	fclose(fd);
2977c478bd9Sstevel@tonic-gate 
2987c478bd9Sstevel@tonic-gate 	switch (ret) {
2997c478bd9Sstevel@tonic-gate 	case -1:
3007c478bd9Sstevel@tonic-gate 		fstype = default_fstype(special);
3017c478bd9Sstevel@tonic-gate 		break;
3027c478bd9Sstevel@tonic-gate 	case 0:
3037c478bd9Sstevel@tonic-gate 		fstype = vget.vfs_fstype;
3047c478bd9Sstevel@tonic-gate 		break;
3057c478bd9Sstevel@tonic-gate 	case VFS_TOOLONG:
3067c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: line in vfstab exceeds %d characters\n",
3077c478bd9Sstevel@tonic-gate 			cbasename, VFS_LINE_MAX-2);
3087c478bd9Sstevel@tonic-gate 		exit(1);
3097c478bd9Sstevel@tonic-gate 		break;
3107c478bd9Sstevel@tonic-gate 	case VFS_TOOFEW:
3117c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: line in vfstab has too few entries\n",
3127c478bd9Sstevel@tonic-gate 			cbasename);
3137c478bd9Sstevel@tonic-gate 		exit(1);
3147c478bd9Sstevel@tonic-gate 		break;
3157c478bd9Sstevel@tonic-gate 	case VFS_TOOMANY:
3167c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: line in vfstab has too many entries\n",
3177c478bd9Sstevel@tonic-gate 			cbasename);
3187c478bd9Sstevel@tonic-gate 		exit(1);
3197c478bd9Sstevel@tonic-gate 		break;
3207c478bd9Sstevel@tonic-gate 	}
3217c478bd9Sstevel@tonic-gate }
32208190127Sdh 
32308190127Sdh static void
32408190127Sdh exec_specific(void)
3257c478bd9Sstevel@tonic-gate {
3267c478bd9Sstevel@tonic-gate int status, pid, ret;
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 	sprintf(full_path, "%s/%s/%s", vfs_path, fstype, cbasename);
3297c478bd9Sstevel@tonic-gate 	newargv[1] = &full_path[FULLPATH_MAX];
3307c478bd9Sstevel@tonic-gate 	while (*newargv[1]-- != '/');
3317c478bd9Sstevel@tonic-gate 	newargv[1] += 2;
3327c478bd9Sstevel@tonic-gate 	switch (pid = fork()) {
3337c478bd9Sstevel@tonic-gate 	case 0:
3347c478bd9Sstevel@tonic-gate 		execv(full_path, &newargv[1]);
3357c478bd9Sstevel@tonic-gate 		if (errno == ENOEXEC) {
3367c478bd9Sstevel@tonic-gate 			newargv[0] = "sh";
3377c478bd9Sstevel@tonic-gate 			newargv[1] = full_path;
3387c478bd9Sstevel@tonic-gate 			execv("/sbin/sh", &newargv[0]);
3397c478bd9Sstevel@tonic-gate 		}
3407c478bd9Sstevel@tonic-gate 		if (errno != ENOENT) {
3417c478bd9Sstevel@tonic-gate 			perror(cbasename);
3427c478bd9Sstevel@tonic-gate 			fprintf(stderr, "%s: cannot execute %s\n", cbasename,
3437c478bd9Sstevel@tonic-gate 			    full_path);
3447c478bd9Sstevel@tonic-gate 			exit(1);
3457c478bd9Sstevel@tonic-gate 		}
3467c478bd9Sstevel@tonic-gate 		if (sysfs(GETFSIND, fstype) == (-1)) {
3477c478bd9Sstevel@tonic-gate 			fprintf(stderr,
3487c478bd9Sstevel@tonic-gate 				"%s: FSType %s not installed in the kernel\n",
3497c478bd9Sstevel@tonic-gate 				cbasename, fstype);
3507c478bd9Sstevel@tonic-gate 			exit(1);
3517c478bd9Sstevel@tonic-gate 		}
3527c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: operation not applicable for FSType %s\n",
3537c478bd9Sstevel@tonic-gate 		    cbasename, fstype);
3547c478bd9Sstevel@tonic-gate 		exit(1);
3557c478bd9Sstevel@tonic-gate 	case -1:
3567c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: cannot fork process\n", cbasename);
3577c478bd9Sstevel@tonic-gate 		exit(2);
3587c478bd9Sstevel@tonic-gate 	default:
3597c478bd9Sstevel@tonic-gate 		/*
3607c478bd9Sstevel@tonic-gate 		 * if cannot exec specific, or fstype is not installed, exit
3617c478bd9Sstevel@tonic-gate 		 * after first 'exec_specific' to avoid printing duplicate
3627c478bd9Sstevel@tonic-gate 		 * error messages
3637c478bd9Sstevel@tonic-gate 		 */
3647c478bd9Sstevel@tonic-gate 
3657c478bd9Sstevel@tonic-gate 		if (wait(&status) == pid) {
3667c478bd9Sstevel@tonic-gate 			ret = WHIBYTE(status);
3677c478bd9Sstevel@tonic-gate 			if (ret > 0) {
3687c478bd9Sstevel@tonic-gate 				exit(ret);
3697c478bd9Sstevel@tonic-gate 			}
3707c478bd9Sstevel@tonic-gate 		}
3717c478bd9Sstevel@tonic-gate 	}
3727c478bd9Sstevel@tonic-gate }
373