xref: /illumos-gate/usr/src/cmd/fs.d/df.c (revision 61b1125e)
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
5ea8dc4b6Seschrock  * Common Development and Distribution License (the "License").
6ea8dc4b6Seschrock  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
22*61b1125eSGordon Ross /*	  All Rights Reserved	*/
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate 
257c478bd9Sstevel@tonic-gate /*
26738059c5SJim Rice  * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
277c478bd9Sstevel@tonic-gate  */
287c478bd9Sstevel@tonic-gate 
290a055120SJason King /*
300a055120SJason King  * Copyright 2016 Jason King
31*61b1125eSGordon Ross  * Copyright 2019 Nexenta Systems, Inc.  All rights reserved.
320a055120SJason King  */
337c478bd9Sstevel@tonic-gate 
34fa9e4066Sahrens #include <dlfcn.h>
357c478bd9Sstevel@tonic-gate #include <stdio.h>
367c478bd9Sstevel@tonic-gate #include <stdarg.h>
377c478bd9Sstevel@tonic-gate #include <string.h>
387c478bd9Sstevel@tonic-gate #include <locale.h>
397c478bd9Sstevel@tonic-gate #include <libintl.h>
407c478bd9Sstevel@tonic-gate #include <stdlib.h>
417c478bd9Sstevel@tonic-gate #include <ftw.h>
427c478bd9Sstevel@tonic-gate #include <errno.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <unistd.h>
457c478bd9Sstevel@tonic-gate #include <sys/statvfs.h>
467c478bd9Sstevel@tonic-gate #include <sys/stat.h>
477c478bd9Sstevel@tonic-gate #include <sys/param.h>
487c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
497c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
507c478bd9Sstevel@tonic-gate #include <sys/vfstab.h>
517c478bd9Sstevel@tonic-gate #include <sys/wait.h>
527c478bd9Sstevel@tonic-gate #include <sys/mkdev.h>
537c478bd9Sstevel@tonic-gate #include <sys/int_limits.h>
547c478bd9Sstevel@tonic-gate #include <sys/zone.h>
550a055120SJason King #include <sys/debug.h>
56fa9e4066Sahrens #include <libzfs.h>
570a055120SJason King #include <libcmdutils.h>
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate #include "fslib.h"
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate extern char *default_fstype(char *);
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate /*
647c478bd9Sstevel@tonic-gate  * General notice:
657c478bd9Sstevel@tonic-gate  * String pointers in this code may point to statically allocated memory
667c478bd9Sstevel@tonic-gate  * or dynamically allocated memory. Furthermore, a dynamically allocated
677c478bd9Sstevel@tonic-gate  * string may be pointed to by more than one pointer. This does not pose
687c478bd9Sstevel@tonic-gate  * a problem because malloc'ed memory is never free'd (so we don't need
697c478bd9Sstevel@tonic-gate  * to remember which pointers point to malloc'ed memory).
707c478bd9Sstevel@tonic-gate  */
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate /*
737c478bd9Sstevel@tonic-gate  * TRANSLATION_NOTE
747c478bd9Sstevel@tonic-gate  * Only strings passed as arguments to the TRANSLATE macro need to
757c478bd9Sstevel@tonic-gate  * be translated.
767c478bd9Sstevel@tonic-gate  */
777c478bd9Sstevel@tonic-gate 
787c478bd9Sstevel@tonic-gate #ifndef MNTTYPE_LOFS
797c478bd9Sstevel@tonic-gate #define	MNTTYPE_LOFS		"lofs"
807c478bd9Sstevel@tonic-gate #endif
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate #define	EQ(s1, s2)		(strcmp(s1, s2) == 0)
837c478bd9Sstevel@tonic-gate #define	NEW(type)		xmalloc(sizeof (type))
847c478bd9Sstevel@tonic-gate #define	CLEAR(var)		(void) memset(&(var), 0, sizeof (var))
857c478bd9Sstevel@tonic-gate #define	MAX(a, b)		((a) > (b) ? (a) : (b))
867c478bd9Sstevel@tonic-gate #define	MAX3(a, b, c)		MAX(a, MAX(b, c))
877c478bd9Sstevel@tonic-gate #define	TRANSLATE(s)		new_string(gettext(s))
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate #define	MAX_OPTIONS		36
907c478bd9Sstevel@tonic-gate #define	N_FSTYPES		20
917c478bd9Sstevel@tonic-gate #define	MOUNT_TABLE_ENTRIES	40	/* initial allocation */
927c478bd9Sstevel@tonic-gate #define	MSGBUF_SIZE		1024
937c478bd9Sstevel@tonic-gate #define	LINEBUF_SIZE		256	/* either input or output lines */
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate #define	BLOCK_SIZE		512	/* when reporting in terms of blocks */
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate #define	DEVNM_CMD		"devnm"
987c478bd9Sstevel@tonic-gate #define	FS_LIBPATH		"/usr/lib/fs/"
997c478bd9Sstevel@tonic-gate #define	MOUNT_TAB		"/etc/mnttab"
1007c478bd9Sstevel@tonic-gate #define	VFS_TAB			"/etc/vfstab"
1017c478bd9Sstevel@tonic-gate #define	REMOTE_FS		"/etc/dfs/fstypes"
1027c478bd9Sstevel@tonic-gate 
1037c478bd9Sstevel@tonic-gate #define	NUL			'\0'
1047c478bd9Sstevel@tonic-gate #define	FALSE			0
1057c478bd9Sstevel@tonic-gate #define	TRUE			1
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate /*
1087c478bd9Sstevel@tonic-gate  * Formatting constants
1097c478bd9Sstevel@tonic-gate  */
1107c478bd9Sstevel@tonic-gate #define	IBCS2_FILESYSTEM_WIDTH	15	/* Truncate to match ISC/SCO */
1117c478bd9Sstevel@tonic-gate #define	IBCS2_MOUNT_POINT_WIDTH	10	/* Truncate to match ISC/SCO */
1127c478bd9Sstevel@tonic-gate #define	FILESYSTEM_WIDTH	20
1137c478bd9Sstevel@tonic-gate #define	MOUNT_POINT_WIDTH	19
1147c478bd9Sstevel@tonic-gate #define	SPECIAL_DEVICE_WIDTH	18
1157c478bd9Sstevel@tonic-gate #define	FSTYPE_WIDTH		8
1167c478bd9Sstevel@tonic-gate #define	BLOCK_WIDTH		8
1177c478bd9Sstevel@tonic-gate #define	NFILES_WIDTH		8
1187c478bd9Sstevel@tonic-gate #define	KBYTE_WIDTH		11
1197c478bd9Sstevel@tonic-gate #define	AVAILABLE_WIDTH		10
1207c478bd9Sstevel@tonic-gate #define	SCALED_WIDTH		6
1217c478bd9Sstevel@tonic-gate #define	CAPACITY_WIDTH		9
1227c478bd9Sstevel@tonic-gate #define	BSIZE_WIDTH		6
1237c478bd9Sstevel@tonic-gate #define	FRAGSIZE_WIDTH		7
1247c478bd9Sstevel@tonic-gate #define	FSID_WIDTH		7
1257c478bd9Sstevel@tonic-gate #define	FLAG_WIDTH		8
1267c478bd9Sstevel@tonic-gate #define	NAMELEN_WIDTH		7
1277c478bd9Sstevel@tonic-gate #define	MNT_SPEC_WIDTH		MOUNT_POINT_WIDTH + SPECIAL_DEVICE_WIDTH + 2
1287c478bd9Sstevel@tonic-gate 
1297c478bd9Sstevel@tonic-gate /*
1307c478bd9Sstevel@tonic-gate  * Flags for the errmsg() function
1317c478bd9Sstevel@tonic-gate  */
1327c478bd9Sstevel@tonic-gate #define	ERR_NOFLAGS		0x0
1337c478bd9Sstevel@tonic-gate #define	ERR_NONAME		0x1	/* don't include the program name */
1347c478bd9Sstevel@tonic-gate 					/* as a prefix */
1357c478bd9Sstevel@tonic-gate #define	ERR_FATAL		0x2	/* call exit after printing the */
1367c478bd9Sstevel@tonic-gate 					/* message */
1377c478bd9Sstevel@tonic-gate #define	ERR_PERROR		0x4	/* append an errno explanation to */
1387c478bd9Sstevel@tonic-gate 					/* the message */
1397c478bd9Sstevel@tonic-gate #define	ERR_USAGE		0x8	/* print the usage line after the */
1407c478bd9Sstevel@tonic-gate 					/* message */
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate #define	NUMBER_WIDTH		40
1430a055120SJason King CTASSERT(NUMBER_WIDTH >= NN_NUMBUF_SZ);
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate /*
1467c478bd9Sstevel@tonic-gate  * A numbuf_t is used when converting a number to a string representation
1477c478bd9Sstevel@tonic-gate  */
1487c478bd9Sstevel@tonic-gate typedef char numbuf_t[ NUMBER_WIDTH ];
1497c478bd9Sstevel@tonic-gate 
1507c478bd9Sstevel@tonic-gate /*
1517c478bd9Sstevel@tonic-gate  * We use bool_int instead of int to make clear which variables are
1527c478bd9Sstevel@tonic-gate  * supposed to be boolean
1537c478bd9Sstevel@tonic-gate  */
1547c478bd9Sstevel@tonic-gate typedef int bool_int;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate struct mtab_entry {
1577c478bd9Sstevel@tonic-gate 	bool_int	mte_dev_is_valid;
1587c478bd9Sstevel@tonic-gate 	dev_t		mte_dev;
1597c478bd9Sstevel@tonic-gate 	bool_int	mte_ignore;	/* the "ignore" option was set */
1607c478bd9Sstevel@tonic-gate 	struct extmnttab	*mte_mount;
1617c478bd9Sstevel@tonic-gate };
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate struct df_request {
1657c478bd9Sstevel@tonic-gate 	bool_int		dfr_valid;
1667c478bd9Sstevel@tonic-gate 	char			*dfr_cmd_arg;	/* what the user specified */
1677c478bd9Sstevel@tonic-gate 	struct mtab_entry	*dfr_mte;
1687c478bd9Sstevel@tonic-gate 	char			*dfr_fstype;
1697c478bd9Sstevel@tonic-gate 	int			dfr_index;	/* to make qsort stable	*/
1707c478bd9Sstevel@tonic-gate };
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate #define	DFR_MOUNT_POINT(dfrp)	(dfrp)->dfr_mte->mte_mount->mnt_mountp
1737c478bd9Sstevel@tonic-gate #define	DFR_SPECIAL(dfrp)	(dfrp)->dfr_mte->mte_mount->mnt_special
174fa9e4066Sahrens #define	DFR_FSTYPE(dfrp)	(dfrp)->dfr_mte->mte_mount->mnt_fstype
1757c478bd9Sstevel@tonic-gate #define	DFR_ISMOUNTEDFS(dfrp)	((dfrp)->dfr_mte != NULL)
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate #define	DFRP(p)			((struct df_request *)(p))
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate typedef void (*output_func)(struct df_request *, struct statvfs64 *);
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate struct df_output {
1827c478bd9Sstevel@tonic-gate 	output_func	dfo_func;	/* function that will do the output */
1837c478bd9Sstevel@tonic-gate 	int		dfo_flags;
1847c478bd9Sstevel@tonic-gate };
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * Output flags
1887c478bd9Sstevel@tonic-gate  */
1897c478bd9Sstevel@tonic-gate #define	DFO_NOFLAGS	0x0
1907c478bd9Sstevel@tonic-gate #define	DFO_HEADER	0x1		/* output preceded by header */
1917c478bd9Sstevel@tonic-gate #define	DFO_STATVFS	0x2		/* must do a statvfs64(2) */
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate static char	*program_name;
1957c478bd9Sstevel@tonic-gate static char	df_options[MAX_OPTIONS] = "-";
1967c478bd9Sstevel@tonic-gate static size_t	df_options_len = 1;
1977c478bd9Sstevel@tonic-gate static char	*o_option_arg;			/* arg to the -o option */
1987c478bd9Sstevel@tonic-gate static char	*FSType;
1997c478bd9Sstevel@tonic-gate static char	*remote_fstypes[N_FSTYPES+1];	/* allocate an extra one */
2007c478bd9Sstevel@tonic-gate 						/* to use as a terminator */
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate /*
2037c478bd9Sstevel@tonic-gate  * The following three variables support an in-memory copy of the mount table
2047c478bd9Sstevel@tonic-gate  * to speedup searches.
2057c478bd9Sstevel@tonic-gate  */
2067c478bd9Sstevel@tonic-gate static struct mtab_entry	*mount_table;	/* array of mtab_entry's */
2077c478bd9Sstevel@tonic-gate static size_t			mount_table_entries;
2087c478bd9Sstevel@tonic-gate static size_t			mount_table_allocated_entries;
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate static bool_int		F_option;
2117c478bd9Sstevel@tonic-gate static bool_int		V_option;
2127c478bd9Sstevel@tonic-gate static bool_int		P_option;	/* Added for XCU4 compliance */
2137c478bd9Sstevel@tonic-gate static bool_int		Z_option;
2147c478bd9Sstevel@tonic-gate static bool_int		v_option;
2157c478bd9Sstevel@tonic-gate static bool_int		a_option;
2167c478bd9Sstevel@tonic-gate static bool_int		b_option;
2177c478bd9Sstevel@tonic-gate static bool_int		e_option;
2187c478bd9Sstevel@tonic-gate static bool_int		g_option;
2197c478bd9Sstevel@tonic-gate static bool_int		h_option;
2207c478bd9Sstevel@tonic-gate static bool_int		k_option;
2217c478bd9Sstevel@tonic-gate static bool_int		l_option;
222790c646cSPaul B. Henson static bool_int		m_option;
2237c478bd9Sstevel@tonic-gate static bool_int		n_option;
2247c478bd9Sstevel@tonic-gate static bool_int		t_option;
2257c478bd9Sstevel@tonic-gate static bool_int		o_option;
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate static bool_int		tty_output;
2287c478bd9Sstevel@tonic-gate static bool_int		use_scaling;
2297c478bd9Sstevel@tonic-gate 
2307c478bd9Sstevel@tonic-gate static void usage(void);
2317c478bd9Sstevel@tonic-gate static void do_devnm(int, char **);
23208190127Sdh static void do_df(int, char **)	__NORETURN;
2337c478bd9Sstevel@tonic-gate static void parse_options(int, char **);
2347c478bd9Sstevel@tonic-gate static char *basename(char *);
2357c478bd9Sstevel@tonic-gate 
23654a91118SChris Kirby static libzfs_handle_t *(*_libzfs_init)(void);
23799653d4eSeschrock static zfs_handle_t *(*_zfs_open)(libzfs_handle_t *, const char *, int);
238fa9e4066Sahrens static void (*_zfs_close)(zfs_handle_t *);
239fa9e4066Sahrens static uint64_t (*_zfs_prop_get_int)(zfs_handle_t *, zfs_prop_t);
24099653d4eSeschrock static libzfs_handle_t *g_zfs;
241fa9e4066Sahrens 
242ea8dc4b6Seschrock /*
243ea8dc4b6Seschrock  * Dynamically check for libzfs, in case the user hasn't installed the SUNWzfs
244ea8dc4b6Seschrock  * packages.  A basic utility such as df shouldn't depend on optional
245ea8dc4b6Seschrock  * filesystems.
246ea8dc4b6Seschrock  */
24799653d4eSeschrock static boolean_t
248ea8dc4b6Seschrock load_libzfs(void)
2497c478bd9Sstevel@tonic-gate {
250fa9e4066Sahrens 	void *hdl;
251fa9e4066Sahrens 
25299653d4eSeschrock 	if (_libzfs_init != NULL)
25399653d4eSeschrock 		return (g_zfs != NULL);
2547c478bd9Sstevel@tonic-gate 
255fa9e4066Sahrens 	if ((hdl = dlopen("libzfs.so", RTLD_LAZY)) != NULL) {
25654a91118SChris Kirby 		_libzfs_init = (libzfs_handle_t *(*)(void))dlsym(hdl,
25799653d4eSeschrock 		    "libzfs_init");
258fa9e4066Sahrens 		_zfs_open = (zfs_handle_t *(*)())dlsym(hdl, "zfs_open");
259fa9e4066Sahrens 		_zfs_close = (void (*)())dlsym(hdl, "zfs_close");
260fa9e4066Sahrens 		_zfs_prop_get_int = (uint64_t (*)())
261fa9e4066Sahrens 		    dlsym(hdl, "zfs_prop_get_int");
262fa9e4066Sahrens 
26399653d4eSeschrock 		if (_libzfs_init != NULL) {
264fa9e4066Sahrens 			assert(_zfs_open != NULL);
265fa9e4066Sahrens 			assert(_zfs_close != NULL);
266fa9e4066Sahrens 			assert(_zfs_prop_get_int != NULL);
267fa9e4066Sahrens 
26854a91118SChris Kirby 			g_zfs = _libzfs_init();
269fa9e4066Sahrens 		}
270fa9e4066Sahrens 	}
271fa9e4066Sahrens 
27299653d4eSeschrock 	return (g_zfs != NULL);
273ea8dc4b6Seschrock }
274ea8dc4b6Seschrock 
275ea8dc4b6Seschrock int
276ea8dc4b6Seschrock main(int argc, char *argv[])
277ea8dc4b6Seschrock {
278ea8dc4b6Seschrock 	(void) setlocale(LC_ALL, "");
279ea8dc4b6Seschrock 
280ea8dc4b6Seschrock #if !defined(TEXT_DOMAIN)		/* Should be defined by cc -D */
281ea8dc4b6Seschrock #define	TEXT_DOMAIN "SYS_TEST"
282ea8dc4b6Seschrock #endif
283ea8dc4b6Seschrock 	(void) textdomain(TEXT_DOMAIN);
284ea8dc4b6Seschrock 
285ea8dc4b6Seschrock 	program_name = basename(argv[0]);
286ea8dc4b6Seschrock 
2877c478bd9Sstevel@tonic-gate 	if (EQ(program_name, DEVNM_CMD))
2887c478bd9Sstevel@tonic-gate 		do_devnm(argc, argv);
2897c478bd9Sstevel@tonic-gate 
2907c478bd9Sstevel@tonic-gate 	parse_options(argc, argv);
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 	/*
2937c478bd9Sstevel@tonic-gate 	 * The k_option implies SunOS 4.x compatibility: when the special
2947c478bd9Sstevel@tonic-gate 	 * device name is too long the line will be split except when the
2957c478bd9Sstevel@tonic-gate 	 * output has been redirected.
2967c478bd9Sstevel@tonic-gate 	 * This is also valid for the -h option.
2977c478bd9Sstevel@tonic-gate 	 */
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (use_scaling || k_option || P_option || v_option)
3007c478bd9Sstevel@tonic-gate 		tty_output = isatty(1);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 	do_df(argc - optind, &argv[optind]);
3037c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
3047c478bd9Sstevel@tonic-gate }
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate /*
3087c478bd9Sstevel@tonic-gate  * Prints an error message to stderr.
3097c478bd9Sstevel@tonic-gate  */
3107c478bd9Sstevel@tonic-gate /* VARARGS2 */
3117c478bd9Sstevel@tonic-gate static void
3127c478bd9Sstevel@tonic-gate errmsg(int flags, char *fmt, ...)
3137c478bd9Sstevel@tonic-gate {
3147c478bd9Sstevel@tonic-gate 	char buf[MSGBUF_SIZE];
3157c478bd9Sstevel@tonic-gate 	va_list ap;
3167c478bd9Sstevel@tonic-gate 	int cc;
3177c478bd9Sstevel@tonic-gate 	int offset;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	if (flags & ERR_NONAME)
3207c478bd9Sstevel@tonic-gate 		offset = 0;
3217c478bd9Sstevel@tonic-gate 	else
3227c478bd9Sstevel@tonic-gate 		offset = sprintf(buf, "%s: ", program_name);
3237c478bd9Sstevel@tonic-gate 
3247c478bd9Sstevel@tonic-gate 	va_start(ap, fmt);
3257c478bd9Sstevel@tonic-gate 	cc = vsprintf(&buf[offset], gettext(fmt), ap);
3267c478bd9Sstevel@tonic-gate 	offset += cc;
3277c478bd9Sstevel@tonic-gate 	va_end(ap);
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate 	if (flags & ERR_PERROR) {
3307c478bd9Sstevel@tonic-gate 		if (buf[offset-1] != ' ')
3317c478bd9Sstevel@tonic-gate 			(void) strcat(buf, " ");
3327c478bd9Sstevel@tonic-gate 		(void) strcat(buf, strerror(errno));
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "%s\n", buf);
3357c478bd9Sstevel@tonic-gate 	if (flags & ERR_USAGE)
3367c478bd9Sstevel@tonic-gate 		usage();
3377c478bd9Sstevel@tonic-gate 	if (flags & ERR_FATAL)
3387c478bd9Sstevel@tonic-gate 		exit(1);
3397c478bd9Sstevel@tonic-gate }
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate static void
34308190127Sdh usage(void)
3447c478bd9Sstevel@tonic-gate {
3457c478bd9Sstevel@tonic-gate 	errmsg(ERR_NONAME,
34690a1a135SPaul B. Henson 	    "Usage: %s [-F FSType] [-abeghklmntPVvZ]"
347790c646cSPaul B. Henson 	    " [-o FSType-specific_options]"
348990b4856Slling 	    " [directory | block_device | resource]", program_name);
3497c478bd9Sstevel@tonic-gate 	exit(1);
3507c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate static char *
3557c478bd9Sstevel@tonic-gate new_string(char *s)
3567c478bd9Sstevel@tonic-gate {
3577c478bd9Sstevel@tonic-gate 	char *p = NULL;
3587c478bd9Sstevel@tonic-gate 
3597c478bd9Sstevel@tonic-gate 	if (s) {
3607c478bd9Sstevel@tonic-gate 		p = strdup(s);
3617c478bd9Sstevel@tonic-gate 		if (p)
3627c478bd9Sstevel@tonic-gate 			return (p);
3637c478bd9Sstevel@tonic-gate 		errmsg(ERR_FATAL, "out of memory");
3647c478bd9Sstevel@tonic-gate 		/* NOTREACHED */
3657c478bd9Sstevel@tonic-gate 	}
3667c478bd9Sstevel@tonic-gate 	return (p);
3677c478bd9Sstevel@tonic-gate }
3687c478bd9Sstevel@tonic-gate 
3697c478bd9Sstevel@tonic-gate 
3707c478bd9Sstevel@tonic-gate /*
3717c478bd9Sstevel@tonic-gate  * Allocate memory using malloc but terminate if the allocation fails
3727c478bd9Sstevel@tonic-gate  */
3737c478bd9Sstevel@tonic-gate static void *
3747c478bd9Sstevel@tonic-gate xmalloc(size_t size)
3757c478bd9Sstevel@tonic-gate {
3767c478bd9Sstevel@tonic-gate 	void *p = malloc(size);
3777c478bd9Sstevel@tonic-gate 
3787c478bd9Sstevel@tonic-gate 	if (p)
3797c478bd9Sstevel@tonic-gate 		return (p);
3807c478bd9Sstevel@tonic-gate 	errmsg(ERR_FATAL, "out of memory");
3817c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
38208190127Sdh 	return (NULL);
3837c478bd9Sstevel@tonic-gate }
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate /*
3877c478bd9Sstevel@tonic-gate  * Allocate memory using realloc but terminate if the allocation fails
3887c478bd9Sstevel@tonic-gate  */
3897c478bd9Sstevel@tonic-gate static void *
3907c478bd9Sstevel@tonic-gate xrealloc(void *ptr, size_t size)
3917c478bd9Sstevel@tonic-gate {
3927c478bd9Sstevel@tonic-gate 	void *p = realloc(ptr, size);
3937c478bd9Sstevel@tonic-gate 
3947c478bd9Sstevel@tonic-gate 	if (p)
3957c478bd9Sstevel@tonic-gate 		return (p);
3967c478bd9Sstevel@tonic-gate 	errmsg(ERR_FATAL, "out of memory");
3977c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
39808190127Sdh 	return (NULL);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 
4027c478bd9Sstevel@tonic-gate /*
4037c478bd9Sstevel@tonic-gate  * fopen the specified file for reading but terminate if the fopen fails
4047c478bd9Sstevel@tonic-gate  */
4057c478bd9Sstevel@tonic-gate static FILE *
4067c478bd9Sstevel@tonic-gate xfopen(char *file)
4077c478bd9Sstevel@tonic-gate {
4087c478bd9Sstevel@tonic-gate 	FILE *fp = fopen(file, "r");
4097c478bd9Sstevel@tonic-gate 
4107c478bd9Sstevel@tonic-gate 	if (fp == NULL)
4117c478bd9Sstevel@tonic-gate 		errmsg(ERR_FATAL + ERR_PERROR, "failed to open %s:", file);
4127c478bd9Sstevel@tonic-gate 	return (fp);
4137c478bd9Sstevel@tonic-gate }
4147c478bd9Sstevel@tonic-gate 
4157c478bd9Sstevel@tonic-gate 
4167c478bd9Sstevel@tonic-gate /*
4177c478bd9Sstevel@tonic-gate  * Read remote file system types from REMOTE_FS into the
4187c478bd9Sstevel@tonic-gate  * remote_fstypes array.
4197c478bd9Sstevel@tonic-gate  */
4207c478bd9Sstevel@tonic-gate static void
42108190127Sdh init_remote_fs(void)
4227c478bd9Sstevel@tonic-gate {
4237c478bd9Sstevel@tonic-gate 	FILE	*fp;
4247c478bd9Sstevel@tonic-gate 	char	line_buf[LINEBUF_SIZE];
4257c478bd9Sstevel@tonic-gate 	size_t	fstype_index = 0;
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	if ((fp = fopen(REMOTE_FS, "r")) == NULL) {
4287c478bd9Sstevel@tonic-gate 		errmsg(ERR_NOFLAGS,
429990b4856Slling 		    "Warning: can't open %s, ignored", REMOTE_FS);
4307c478bd9Sstevel@tonic-gate 		return;
4317c478bd9Sstevel@tonic-gate 	}
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate 	while (fgets(line_buf, sizeof (line_buf), fp) != NULL) {
4347c478bd9Sstevel@tonic-gate 		char buf[LINEBUF_SIZE];
4357c478bd9Sstevel@tonic-gate 
4367c478bd9Sstevel@tonic-gate 		(void) sscanf(line_buf, "%s", buf);
4377c478bd9Sstevel@tonic-gate 		remote_fstypes[fstype_index++] = new_string(buf);
4387c478bd9Sstevel@tonic-gate 
4397c478bd9Sstevel@tonic-gate 		if (fstype_index == N_FSTYPES)
4407c478bd9Sstevel@tonic-gate 			break;
4417c478bd9Sstevel@tonic-gate 	}
4427c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate 
4467c478bd9Sstevel@tonic-gate /*
4477c478bd9Sstevel@tonic-gate  * Returns TRUE if fstype is a remote file system type;
4487c478bd9Sstevel@tonic-gate  * otherwise, returns FALSE.
4497c478bd9Sstevel@tonic-gate  */
4507c478bd9Sstevel@tonic-gate static int
4517c478bd9Sstevel@tonic-gate is_remote_fs(char *fstype)
4527c478bd9Sstevel@tonic-gate {
4537c478bd9Sstevel@tonic-gate 	char **p;
4547c478bd9Sstevel@tonic-gate 	static bool_int remote_fs_initialized;
4557c478bd9Sstevel@tonic-gate 
4567c478bd9Sstevel@tonic-gate 	if (! remote_fs_initialized) {
4577c478bd9Sstevel@tonic-gate 		init_remote_fs();
4587c478bd9Sstevel@tonic-gate 		remote_fs_initialized = TRUE;
4597c478bd9Sstevel@tonic-gate 	}
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	for (p = remote_fstypes; *p; p++)
4627c478bd9Sstevel@tonic-gate 		if (EQ(fstype, *p))
4637c478bd9Sstevel@tonic-gate 			return (TRUE);
4647c478bd9Sstevel@tonic-gate 	return (FALSE);
4657c478bd9Sstevel@tonic-gate }
4667c478bd9Sstevel@tonic-gate 
4677c478bd9Sstevel@tonic-gate 
4687c478bd9Sstevel@tonic-gate static char *
4697c478bd9Sstevel@tonic-gate basename(char *s)
4707c478bd9Sstevel@tonic-gate {
4717c478bd9Sstevel@tonic-gate 	char *p = strrchr(s, '/');
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate 	return (p ? p+1 : s);
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate 
4767c478bd9Sstevel@tonic-gate 
4777c478bd9Sstevel@tonic-gate /*
4787c478bd9Sstevel@tonic-gate  * Create a new "struct extmnttab" and make sure that its fields point
4797c478bd9Sstevel@tonic-gate  * to malloc'ed memory
4807c478bd9Sstevel@tonic-gate  */
4817c478bd9Sstevel@tonic-gate static struct extmnttab *
4827c478bd9Sstevel@tonic-gate mntdup(struct extmnttab *old)
4837c478bd9Sstevel@tonic-gate {
4847c478bd9Sstevel@tonic-gate 	struct extmnttab *new = NEW(struct extmnttab);
4857c478bd9Sstevel@tonic-gate 
4867c478bd9Sstevel@tonic-gate 	new->mnt_special = new_string(old->mnt_special);
4877c478bd9Sstevel@tonic-gate 	new->mnt_mountp  = new_string(old->mnt_mountp);
4887c478bd9Sstevel@tonic-gate 	new->mnt_fstype  = new_string(old->mnt_fstype);
4897c478bd9Sstevel@tonic-gate 	new->mnt_mntopts = new_string(old->mnt_mntopts);
4907c478bd9Sstevel@tonic-gate 	new->mnt_time    = new_string(old->mnt_time);
4917c478bd9Sstevel@tonic-gate 	new->mnt_major   = old->mnt_major;
4927c478bd9Sstevel@tonic-gate 	new->mnt_minor   = old->mnt_minor;
4937c478bd9Sstevel@tonic-gate 	return (new);
4947c478bd9Sstevel@tonic-gate }
4957c478bd9Sstevel@tonic-gate 
4967c478bd9Sstevel@tonic-gate 
4977c478bd9Sstevel@tonic-gate static void
4987c478bd9Sstevel@tonic-gate mtab_error(char *mtab_file, int status)
4997c478bd9Sstevel@tonic-gate {
5007c478bd9Sstevel@tonic-gate 	if (status == MNT_TOOLONG)
5017c478bd9Sstevel@tonic-gate 		errmsg(ERR_NOFLAGS, "a line in %s exceeds %d characters",
502990b4856Slling 		    mtab_file, MNT_LINE_MAX);
5037c478bd9Sstevel@tonic-gate 	else if (status == MNT_TOOMANY)
5047c478bd9Sstevel@tonic-gate 		errmsg(ERR_NOFLAGS,
505990b4856Slling 		    "a line in %s has too many fields", mtab_file);
5067c478bd9Sstevel@tonic-gate 	else if (status == MNT_TOOFEW)
5077c478bd9Sstevel@tonic-gate 		errmsg(ERR_NOFLAGS,
508990b4856Slling 		    "a line in %s has too few fields", mtab_file);
5097c478bd9Sstevel@tonic-gate 	else
5107c478bd9Sstevel@tonic-gate 		errmsg(ERR_NOFLAGS,
511990b4856Slling 		    "error while reading %s: %d", mtab_file, status);
5127c478bd9Sstevel@tonic-gate 	exit(1);
5137c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
5147c478bd9Sstevel@tonic-gate }
5157c478bd9Sstevel@tonic-gate 
5167c478bd9Sstevel@tonic-gate 
5177c478bd9Sstevel@tonic-gate /*
5187c478bd9Sstevel@tonic-gate  * Read the mount table from the specified file.
5197c478bd9Sstevel@tonic-gate  * We keep the table in memory for faster lookups.
5207c478bd9Sstevel@tonic-gate  */
5217c478bd9Sstevel@tonic-gate static void
52208190127Sdh mtab_read_file(void)
5237c478bd9Sstevel@tonic-gate {
5247c478bd9Sstevel@tonic-gate 	char		*mtab_file = MOUNT_TAB;
5257c478bd9Sstevel@tonic-gate 	FILE		*fp;
5267c478bd9Sstevel@tonic-gate 	struct extmnttab	mtab;
5277c478bd9Sstevel@tonic-gate 	int		status;
5287c478bd9Sstevel@tonic-gate 
5297c478bd9Sstevel@tonic-gate 	fp = xfopen(mtab_file);
5307c478bd9Sstevel@tonic-gate 
5317c478bd9Sstevel@tonic-gate 	resetmnttab(fp);
5327c478bd9Sstevel@tonic-gate 	mount_table_allocated_entries = MOUNT_TABLE_ENTRIES;
5337c478bd9Sstevel@tonic-gate 	mount_table_entries = 0;
5347c478bd9Sstevel@tonic-gate 	mount_table = xmalloc(
535990b4856Slling 	    mount_table_allocated_entries * sizeof (struct mtab_entry));
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	while ((status = getextmntent(fp, &mtab, sizeof (struct extmnttab)))
538990b4856Slling 	    == 0) {
5397c478bd9Sstevel@tonic-gate 		struct mtab_entry *mtep;
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate 		if (mount_table_entries == mount_table_allocated_entries) {
5427c478bd9Sstevel@tonic-gate 			mount_table_allocated_entries += MOUNT_TABLE_ENTRIES;
5437c478bd9Sstevel@tonic-gate 			mount_table = xrealloc(mount_table,
544990b4856Slling 			    mount_table_allocated_entries *
545990b4856Slling 			    sizeof (struct mtab_entry));
5467c478bd9Sstevel@tonic-gate 		}
5477c478bd9Sstevel@tonic-gate 		mtep = &mount_table[mount_table_entries++];
5487c478bd9Sstevel@tonic-gate 		mtep->mte_mount = mntdup(&mtab);
5497c478bd9Sstevel@tonic-gate 		mtep->mte_dev_is_valid = FALSE;
5507c478bd9Sstevel@tonic-gate 		mtep->mte_ignore = (hasmntopt((struct mnttab *)&mtab,
551990b4856Slling 		    MNTOPT_IGNORE) != NULL);
5527c478bd9Sstevel@tonic-gate 	}
5537c478bd9Sstevel@tonic-gate 
5547c478bd9Sstevel@tonic-gate 	(void) fclose(fp);
5557c478bd9Sstevel@tonic-gate 
5567c478bd9Sstevel@tonic-gate 	if (status == -1)			/* reached EOF */
5577c478bd9Sstevel@tonic-gate 		return;
5587c478bd9Sstevel@tonic-gate 	mtab_error(mtab_file, status);
5597c478bd9Sstevel@tonic-gate 	/* NOTREACHED */
5607c478bd9Sstevel@tonic-gate }
5617c478bd9Sstevel@tonic-gate 
5627c478bd9Sstevel@tonic-gate 
5637c478bd9Sstevel@tonic-gate /*
5647c478bd9Sstevel@tonic-gate  * We use this macro when we want to record the option for the purpose of
5657c478bd9Sstevel@tonic-gate  * passing it to the FS-specific df
5667c478bd9Sstevel@tonic-gate  */
5677c478bd9Sstevel@tonic-gate #define	SET_OPTION(opt)		opt##_option = TRUE, \
5687c478bd9Sstevel@tonic-gate 				df_options[df_options_len++] = arg
5697c478bd9Sstevel@tonic-gate 
5707c478bd9Sstevel@tonic-gate static void
5717c478bd9Sstevel@tonic-gate parse_options(int argc, char *argv[])
5727c478bd9Sstevel@tonic-gate {
5737c478bd9Sstevel@tonic-gate 	int arg;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	opterr = 0;	/* getopt shouldn't complain about unknown options */
5767c478bd9Sstevel@tonic-gate 
57790a1a135SPaul B. Henson 	while ((arg = getopt(argc, argv, "F:o:abehkVtgnlmPvZ")) != EOF) {
5787c478bd9Sstevel@tonic-gate 		if (arg == 'F') {
5797c478bd9Sstevel@tonic-gate 			if (F_option)
5807c478bd9Sstevel@tonic-gate 				errmsg(ERR_FATAL + ERR_USAGE,
581990b4856Slling 				    "more than one FSType specified");
5827c478bd9Sstevel@tonic-gate 			F_option = 1;
5837c478bd9Sstevel@tonic-gate 			FSType = optarg;
5847c478bd9Sstevel@tonic-gate 		} else if (arg == 'V' && ! V_option) {
5857c478bd9Sstevel@tonic-gate 			V_option = TRUE;
5867c478bd9Sstevel@tonic-gate 		} else if (arg == 'v' && ! v_option) {
5877c478bd9Sstevel@tonic-gate 			v_option = TRUE;
5887c478bd9Sstevel@tonic-gate 		} else if (arg == 'P' && ! P_option) {
5897c478bd9Sstevel@tonic-gate 			SET_OPTION(P);
5907c478bd9Sstevel@tonic-gate 		} else if (arg == 'a' && ! a_option) {
5917c478bd9Sstevel@tonic-gate 			SET_OPTION(a);
5927c478bd9Sstevel@tonic-gate 		} else if (arg == 'b' && ! b_option) {
5937c478bd9Sstevel@tonic-gate 			SET_OPTION(b);
5947c478bd9Sstevel@tonic-gate 		} else if (arg == 'e' && ! e_option) {
5957c478bd9Sstevel@tonic-gate 			SET_OPTION(e);
5967c478bd9Sstevel@tonic-gate 		} else if (arg == 'g' && ! g_option) {
5977c478bd9Sstevel@tonic-gate 			SET_OPTION(g);
5987c478bd9Sstevel@tonic-gate 		} else if (arg == 'h') {
5997c478bd9Sstevel@tonic-gate 			use_scaling = TRUE;
6007c478bd9Sstevel@tonic-gate 		} else if (arg == 'k' && ! k_option) {
6017c478bd9Sstevel@tonic-gate 			SET_OPTION(k);
6027c478bd9Sstevel@tonic-gate 		} else if (arg == 'l' && ! l_option) {
6037c478bd9Sstevel@tonic-gate 			SET_OPTION(l);
604790c646cSPaul B. Henson 		} else if (arg == 'm' && ! m_option) {
605790c646cSPaul B. Henson 			SET_OPTION(m);
6067c478bd9Sstevel@tonic-gate 		} else if (arg == 'n' && ! n_option) {
6077c478bd9Sstevel@tonic-gate 			SET_OPTION(n);
6087c478bd9Sstevel@tonic-gate 		} else if (arg == 't' && ! t_option) {
6097c478bd9Sstevel@tonic-gate 			SET_OPTION(t);
6107c478bd9Sstevel@tonic-gate 		} else if (arg == 'o') {
6117c478bd9Sstevel@tonic-gate 			if (o_option)
6127c478bd9Sstevel@tonic-gate 				errmsg(ERR_FATAL + ERR_USAGE,
6137c478bd9Sstevel@tonic-gate 				"the -o option can only be specified once");
6147c478bd9Sstevel@tonic-gate 			o_option = TRUE;
6157c478bd9Sstevel@tonic-gate 			o_option_arg = optarg;
6167c478bd9Sstevel@tonic-gate 		} else if (arg == 'Z') {
6177c478bd9Sstevel@tonic-gate 			SET_OPTION(Z);
6187c478bd9Sstevel@tonic-gate 		} else if (arg == '?') {
6197c478bd9Sstevel@tonic-gate 			errmsg(ERR_USAGE, "unknown option: %c", optopt);
6207c478bd9Sstevel@tonic-gate 		}
6217c478bd9Sstevel@tonic-gate 	}
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	/*
6247c478bd9Sstevel@tonic-gate 	 * Option sanity checks
6257c478bd9Sstevel@tonic-gate 	 */
6267c478bd9Sstevel@tonic-gate 	if (g_option && o_option)
6277c478bd9Sstevel@tonic-gate 		errmsg(ERR_FATAL, "-o and -g options are incompatible");
6287c478bd9Sstevel@tonic-gate 	if (l_option && o_option)
6297c478bd9Sstevel@tonic-gate 		errmsg(ERR_FATAL, "-o and -l options are incompatible");
6307c478bd9Sstevel@tonic-gate 	if (n_option && o_option)
6317c478bd9Sstevel@tonic-gate 		errmsg(ERR_FATAL, "-o and -n options are incompatible");
6327c478bd9Sstevel@tonic-gate 	if (use_scaling && o_option)
6337c478bd9Sstevel@tonic-gate 		errmsg(ERR_FATAL, "-o and -h options are incompatible");
6347c478bd9Sstevel@tonic-gate }
6357c478bd9Sstevel@tonic-gate 
6367c478bd9Sstevel@tonic-gate 
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate  * Check if the user-specified argument is a resource name.
6407c478bd9Sstevel@tonic-gate  * A resource name is whatever is placed in the mnt_special field of
6417c478bd9Sstevel@tonic-gate  * struct mnttab. In the case of NFS, a resource name has the form
6427c478bd9Sstevel@tonic-gate  * hostname:pathname
6437c478bd9Sstevel@tonic-gate  * We try to find an exact match between the user-specified argument
6447c478bd9Sstevel@tonic-gate  * and the mnt_special field of a mount table entry.
6457c478bd9Sstevel@tonic-gate  * We also use the heuristic of removing the basename from the user-specified
6467c478bd9Sstevel@tonic-gate  * argument and repeating the test until we get a match. This works
6477c478bd9Sstevel@tonic-gate  * fine for NFS but may fail for other remote file system types. However,
6487c478bd9Sstevel@tonic-gate  * it is guaranteed that the function will not fail if the user specifies
6497c478bd9Sstevel@tonic-gate  * the exact resource name.
6507c478bd9Sstevel@tonic-gate  * If successful, this function sets the 'dfr_mte' field of '*dfrp'
6517c478bd9Sstevel@tonic-gate  */
6527c478bd9Sstevel@tonic-gate static void
6537c478bd9Sstevel@tonic-gate resource_mount_entry(struct df_request *dfrp)
6547c478bd9Sstevel@tonic-gate {
6557c478bd9Sstevel@tonic-gate 	char *name;
6567c478bd9Sstevel@tonic-gate 
6577c478bd9Sstevel@tonic-gate 	/*
6587c478bd9Sstevel@tonic-gate 	 * We need our own copy since we will modify the string
6597c478bd9Sstevel@tonic-gate 	 */
6607c478bd9Sstevel@tonic-gate 	name = new_string(dfrp->dfr_cmd_arg);
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate 	for (;;) {
6637c478bd9Sstevel@tonic-gate 		char *p;
6647c478bd9Sstevel@tonic-gate 		int i;
6657c478bd9Sstevel@tonic-gate 
6667c478bd9Sstevel@tonic-gate 		/*
6677c478bd9Sstevel@tonic-gate 		 * Compare against all known mount points.
6687c478bd9Sstevel@tonic-gate 		 * We start from the most recent mount, which is at the
6697c478bd9Sstevel@tonic-gate 		 * end of the array.
6707c478bd9Sstevel@tonic-gate 		 */
6717c478bd9Sstevel@tonic-gate 		for (i = mount_table_entries - 1; i >= 0; i--) {
6727c478bd9Sstevel@tonic-gate 			struct mtab_entry *mtep = &mount_table[i];
6737c478bd9Sstevel@tonic-gate 
6747c478bd9Sstevel@tonic-gate 			if (EQ(name, mtep->mte_mount->mnt_special)) {
6757c478bd9Sstevel@tonic-gate 				dfrp->dfr_mte = mtep;
6767c478bd9Sstevel@tonic-gate 				break;
6777c478bd9Sstevel@tonic-gate 			}
6787c478bd9Sstevel@tonic-gate 		}
6797c478bd9Sstevel@tonic-gate 
6807c478bd9Sstevel@tonic-gate 		/*
6817c478bd9Sstevel@tonic-gate 		 * Remove the last component of the pathname.
6827c478bd9Sstevel@tonic-gate 		 * If there is no such component, this is not a resource name.
6837c478bd9Sstevel@tonic-gate 		 */
6847c478bd9Sstevel@tonic-gate 		p = strrchr(name, '/');
6857c478bd9Sstevel@tonic-gate 		if (p == NULL)
6867c478bd9Sstevel@tonic-gate 			break;
6877c478bd9Sstevel@tonic-gate 		*p = NUL;
6887c478bd9Sstevel@tonic-gate 	}
6897c478bd9Sstevel@tonic-gate }
6907c478bd9Sstevel@tonic-gate 
6917c478bd9Sstevel@tonic-gate 
6927c478bd9Sstevel@tonic-gate 
6937c478bd9Sstevel@tonic-gate /*
6947c478bd9Sstevel@tonic-gate  * Try to match the command line argument which is a block special device
6957c478bd9Sstevel@tonic-gate  * with the special device of one of the mounted file systems.
6967c478bd9Sstevel@tonic-gate  * If one is found, set the appropriate field of 'dfrp' to the mount
6977c478bd9Sstevel@tonic-gate  * table entry.
6987c478bd9Sstevel@tonic-gate  */
6997c478bd9Sstevel@tonic-gate static void
7007c478bd9Sstevel@tonic-gate bdev_mount_entry(struct df_request *dfrp)
7017c478bd9Sstevel@tonic-gate {
7027c478bd9Sstevel@tonic-gate 	int i;
7037c478bd9Sstevel@tonic-gate 	char *special = dfrp->dfr_cmd_arg;
7047c478bd9Sstevel@tonic-gate 
7057c478bd9Sstevel@tonic-gate 	/*
7067c478bd9Sstevel@tonic-gate 	 * Compare against all known mount points.
7077c478bd9Sstevel@tonic-gate 	 * We start from the most recent mount, which is at the
7087c478bd9Sstevel@tonic-gate 	 * end of the array.
7097c478bd9Sstevel@tonic-gate 	 */
7107c478bd9Sstevel@tonic-gate 	for (i = mount_table_entries - 1; i >= 0; i--) {
7117c478bd9Sstevel@tonic-gate 		struct mtab_entry *mtep = &mount_table[i];
7127c478bd9Sstevel@tonic-gate 
7137c478bd9Sstevel@tonic-gate 		if (EQ(special, mtep->mte_mount->mnt_special)) {
7147c478bd9Sstevel@tonic-gate 			dfrp->dfr_mte = mtep;
7157c478bd9Sstevel@tonic-gate 			break;
7167c478bd9Sstevel@tonic-gate 		}
7177c478bd9Sstevel@tonic-gate 	}
7187c478bd9Sstevel@tonic-gate }
7197c478bd9Sstevel@tonic-gate 
7207c478bd9Sstevel@tonic-gate static struct mtab_entry *
7217c478bd9Sstevel@tonic-gate devid_matches(int i, dev_t devno)
7227c478bd9Sstevel@tonic-gate {
7237c478bd9Sstevel@tonic-gate 	struct mtab_entry	*mtep = &mount_table[i];
7247c478bd9Sstevel@tonic-gate 	struct extmnttab	*mtp = mtep->mte_mount;
7257c478bd9Sstevel@tonic-gate 	/* int	len = strlen(mtp->mnt_mountp); */
7267c478bd9Sstevel@tonic-gate 
7277c478bd9Sstevel@tonic-gate 	if (EQ(mtp->mnt_fstype, MNTTYPE_SWAP))
7287c478bd9Sstevel@tonic-gate 		return (NULL);
7297c478bd9Sstevel@tonic-gate 	/*
7307c478bd9Sstevel@tonic-gate 	 * check if device numbers match. If there is a cached device number
7317c478bd9Sstevel@tonic-gate 	 * in the mtab_entry, use it, otherwise get the device number
7327c478bd9Sstevel@tonic-gate 	 * either from the mnttab entry or by stat'ing the mount point.
7337c478bd9Sstevel@tonic-gate 	 */
7347c478bd9Sstevel@tonic-gate 	if (! mtep->mte_dev_is_valid) {
7357c478bd9Sstevel@tonic-gate 		struct stat64 st;
7367c478bd9Sstevel@tonic-gate 		dev_t dev = NODEV;
7377c478bd9Sstevel@tonic-gate 
7387c478bd9Sstevel@tonic-gate 		dev = makedev(mtp->mnt_major, mtp->mnt_minor);
7397c478bd9Sstevel@tonic-gate 		if (dev == 0)
7407c478bd9Sstevel@tonic-gate 			dev = NODEV;
7417c478bd9Sstevel@tonic-gate 		if (dev == NODEV) {
7427c478bd9Sstevel@tonic-gate 			if (stat64(mtp->mnt_mountp, &st) == -1) {
7437c478bd9Sstevel@tonic-gate 				return (NULL);
7447c478bd9Sstevel@tonic-gate 			} else {
7457c478bd9Sstevel@tonic-gate 				dev = st.st_dev;
7467c478bd9Sstevel@tonic-gate 			}
7477c478bd9Sstevel@tonic-gate 		}
7487c478bd9Sstevel@tonic-gate 		mtep->mte_dev = dev;
7497c478bd9Sstevel@tonic-gate 		mtep->mte_dev_is_valid = TRUE;
7507c478bd9Sstevel@tonic-gate 	}
7517c478bd9Sstevel@tonic-gate 	if (mtep->mte_dev == devno) {
7527c478bd9Sstevel@tonic-gate 		return (mtep);
7537c478bd9Sstevel@tonic-gate 	}
7547c478bd9Sstevel@tonic-gate 	return (NULL);
7557c478bd9Sstevel@tonic-gate }
7567c478bd9Sstevel@tonic-gate 
7577c478bd9Sstevel@tonic-gate /*
7587c478bd9Sstevel@tonic-gate  * Find the mount point under which the user-specified path resides
7597c478bd9Sstevel@tonic-gate  * and set the 'dfr_mte' field of '*dfrp' to point to the mount table entry.
7607c478bd9Sstevel@tonic-gate  */
7617c478bd9Sstevel@tonic-gate static void
7627c478bd9Sstevel@tonic-gate path_mount_entry(struct df_request *dfrp, dev_t devno)
7637c478bd9Sstevel@tonic-gate {
7647c478bd9Sstevel@tonic-gate 	char			dirpath[MAXPATHLEN];
7657c478bd9Sstevel@tonic-gate 	char			*dir = dfrp->dfr_cmd_arg;
7667c478bd9Sstevel@tonic-gate 	struct mtab_entry	*match, *tmatch;
7677c478bd9Sstevel@tonic-gate 	int i;
7687c478bd9Sstevel@tonic-gate 
7697c478bd9Sstevel@tonic-gate 	/*
7707c478bd9Sstevel@tonic-gate 	 * Expand the given path to get a canonical version (i.e. an absolute
7717c478bd9Sstevel@tonic-gate 	 * path without symbolic links).
7727c478bd9Sstevel@tonic-gate 	 */
7737c478bd9Sstevel@tonic-gate 	if (realpath(dir, dirpath) == NULL) {
7747c478bd9Sstevel@tonic-gate 		errmsg(ERR_PERROR, "cannot canonicalize %s:", dir);
7757c478bd9Sstevel@tonic-gate 		return;
7767c478bd9Sstevel@tonic-gate 	}
7777c478bd9Sstevel@tonic-gate 	/*
7787c478bd9Sstevel@tonic-gate 	 * If the mnt point is lofs, search from the top of entries from
779738059c5SJim Rice 	 * /etc/mnttab and return the entry that best matches the pathname.
7807c478bd9Sstevel@tonic-gate 	 * For non-lofs mount points, return the first entry from the bottom
7817c478bd9Sstevel@tonic-gate 	 * of the entries in /etc/mnttab that matches on the devid field
7827c478bd9Sstevel@tonic-gate 	 */
7837c478bd9Sstevel@tonic-gate 	match = NULL;
7847c478bd9Sstevel@tonic-gate 	if (dfrp->dfr_fstype && EQ(dfrp->dfr_fstype, MNTTYPE_LOFS)) {
785738059c5SJim Rice 		struct extmnttab *entryp;
786738059c5SJim Rice 		char *path, *mountp;
787738059c5SJim Rice 		char p, m;
788738059c5SJim Rice 		int score;
789738059c5SJim Rice 		int best_score = 0;
790738059c5SJim Rice 		int best_index = -1;
791738059c5SJim Rice 
7927c478bd9Sstevel@tonic-gate 		for (i = 0; i < mount_table_entries; i++) {
793738059c5SJim Rice 			entryp = mount_table[i].mte_mount;
794738059c5SJim Rice 
795738059c5SJim Rice 			if (!EQ(entryp->mnt_fstype, MNTTYPE_LOFS))
796738059c5SJim Rice 				continue;
797738059c5SJim Rice 
798738059c5SJim Rice 			path = dirpath;
799738059c5SJim Rice 			mountp = entryp->mnt_mountp;
800738059c5SJim Rice 			score = 0;
801738059c5SJim Rice 			/*
802738059c5SJim Rice 			 * Count the number of matching characters
803738059c5SJim Rice 			 * until either path or mountpoint is exhausted
804738059c5SJim Rice 			 */
805738059c5SJim Rice 			while ((p = *path++) == (m = *mountp++)) {
806738059c5SJim Rice 				score++;
807738059c5SJim Rice 
808738059c5SJim Rice 				if (p == '\0' || m == '\0')
809738059c5SJim Rice 					break;
810738059c5SJim Rice 			}
811738059c5SJim Rice 
812738059c5SJim Rice 			/* Both exhausted so we have a match */
813738059c5SJim Rice 			if (p == '\0' && m == '\0') {
814738059c5SJim Rice 				best_index = i;
8157c478bd9Sstevel@tonic-gate 				break;
816738059c5SJim Rice 			}
817738059c5SJim Rice 
818738059c5SJim Rice 			/*
819738059c5SJim Rice 			 * We have exhausted the mountpoint and the current
820738059c5SJim Rice 			 * character in the path is a '/' hence the full path
821738059c5SJim Rice 			 * traverses this mountpoint.
822738059c5SJim Rice 			 * Record this as the best candidate so far.
823738059c5SJim Rice 			 */
824738059c5SJim Rice 			if (p == '/' && m == '\0') {
825738059c5SJim Rice 				if (score > best_score) {
826738059c5SJim Rice 					best_index = i;
827738059c5SJim Rice 					best_score = score;
828738059c5SJim Rice 				}
829738059c5SJim Rice 			}
8307c478bd9Sstevel@tonic-gate 		}
831738059c5SJim Rice 
832738059c5SJim Rice 		if (best_index > -1)
833738059c5SJim Rice 			match = &mount_table[best_index];
8347c478bd9Sstevel@tonic-gate 	} else {
8357c478bd9Sstevel@tonic-gate 		for (i = mount_table_entries - 1; i >= 0; i--) {
8367c478bd9Sstevel@tonic-gate 			if (tmatch = devid_matches(i, devno)) {
8377c478bd9Sstevel@tonic-gate 				/*
8387c478bd9Sstevel@tonic-gate 				 * If executing in a zone, there might be lofs
8397c478bd9Sstevel@tonic-gate 				 * mounts for which the real mount point is
8407c478bd9Sstevel@tonic-gate 				 * invisible; accept the "best fit" for this
8417c478bd9Sstevel@tonic-gate 				 * devid.
8427c478bd9Sstevel@tonic-gate 				 */
8437c478bd9Sstevel@tonic-gate 				match = tmatch;
8447c478bd9Sstevel@tonic-gate 				if (!EQ(match->mte_mount->mnt_fstype,
845990b4856Slling 				    MNTTYPE_LOFS)) {
8467c478bd9Sstevel@tonic-gate 					break;
8477c478bd9Sstevel@tonic-gate 				}
8487c478bd9Sstevel@tonic-gate 			}
8497c478bd9Sstevel@tonic-gate 		}
8507c478bd9Sstevel@tonic-gate 	}
8517c478bd9Sstevel@tonic-gate 	if (! match) {
8527c478bd9Sstevel@tonic-gate 		errmsg(ERR_NOFLAGS,
853990b4856Slling 		    "Could not find mount point for %s", dir);
8547c478bd9Sstevel@tonic-gate 		return;
8557c478bd9Sstevel@tonic-gate 	}
8567c478bd9Sstevel@tonic-gate 	dfrp->dfr_mte = match;
8577c478bd9Sstevel@tonic-gate }
8587c478bd9Sstevel@tonic-gate 
8597c478bd9Sstevel@tonic-gate /*
8607c478bd9Sstevel@tonic-gate  * Execute a single FS-specific df command for all given requests
8617c478bd9Sstevel@tonic-gate  * Return 0 if successful, 1 otherwise.
8627c478bd9Sstevel@tonic-gate  */
8637c478bd9Sstevel@tonic-gate static int
8647c478bd9Sstevel@tonic-gate run_fs_specific_df(struct df_request request_list[], int entries)
8657c478bd9Sstevel@tonic-gate {
8667c478bd9Sstevel@tonic-gate 	int	i;
8677c478bd9Sstevel@tonic-gate 	int	argv_index;
8687c478bd9Sstevel@tonic-gate 	char	**argv;
8697c478bd9Sstevel@tonic-gate 	size_t	size;
8707c478bd9Sstevel@tonic-gate 	pid_t	pid;
8717c478bd9Sstevel@tonic-gate 	int	status;
8727c478bd9Sstevel@tonic-gate 	char	cmd_path[MAXPATHLEN];
8737c478bd9Sstevel@tonic-gate 	char	*fstype;
8747c478bd9Sstevel@tonic-gate 
8757c478bd9Sstevel@tonic-gate 	if (entries == 0)
8767c478bd9Sstevel@tonic-gate 		return (0);
8777c478bd9Sstevel@tonic-gate 
8787c478bd9Sstevel@tonic-gate 	fstype = request_list[0].dfr_fstype;
8797c478bd9Sstevel@tonic-gate 
8807c478bd9Sstevel@tonic-gate 	if (F_option && ! EQ(FSType, fstype))
8817c478bd9Sstevel@tonic-gate 		return (0);
8827c478bd9Sstevel@tonic-gate 
8837c478bd9Sstevel@tonic-gate 	(void) sprintf(cmd_path, "%s%s/df", FS_LIBPATH, fstype);
8847c478bd9Sstevel@tonic-gate 	/*
8857c478bd9Sstevel@tonic-gate 	 * Argv entries:
8867c478bd9Sstevel@tonic-gate 	 *		1 for the path
8877c478bd9Sstevel@tonic-gate 	 *		2 for -o <options>
8887c478bd9Sstevel@tonic-gate 	 *		1 for the generic options that we propagate
8897c478bd9Sstevel@tonic-gate 	 *		1 for the terminating NULL pointer
8907c478bd9Sstevel@tonic-gate 	 *		n for the number of user-specified arguments
8917c478bd9Sstevel@tonic-gate 	 */
8927c478bd9Sstevel@tonic-gate 	size = (5 + entries) * sizeof (char *);
8937c478bd9Sstevel@tonic-gate 	argv = xmalloc(size);
8947c478bd9Sstevel@tonic-gate 	(void) memset(argv, 0, size);
8957c478bd9Sstevel@tonic-gate 
8967c478bd9Sstevel@tonic-gate 	argv[0] = cmd_path;
8977c478bd9Sstevel@tonic-gate 	argv_index = 1;
8987c478bd9Sstevel@tonic-gate 	if (o_option) {
8997c478bd9Sstevel@tonic-gate 		argv[argv_index++] = "-o";
9007c478bd9Sstevel@tonic-gate 		argv[argv_index++] = o_option_arg;
9017c478bd9Sstevel@tonic-gate 	}
9027c478bd9Sstevel@tonic-gate 
9037c478bd9Sstevel@tonic-gate 	/*
9047c478bd9Sstevel@tonic-gate 	 * Check if we need to propagate any generic options
9057c478bd9Sstevel@tonic-gate 	 */
9067c478bd9Sstevel@tonic-gate 	if (df_options_len > 1)
9077c478bd9Sstevel@tonic-gate 		argv[argv_index++] = df_options;
9087c478bd9Sstevel@tonic-gate 
9097c478bd9Sstevel@tonic-gate 	/*
9107c478bd9Sstevel@tonic-gate 	 * If there is a user-specified path, we pass that to the
9117c478bd9Sstevel@tonic-gate 	 * FS-specific df. Otherwise, we are guaranteed to have a mount
9127c478bd9Sstevel@tonic-gate 	 * point, since a request without a user path implies that
9137c478bd9Sstevel@tonic-gate 	 * we are reporting only on mounted file systems.
9147c478bd9Sstevel@tonic-gate 	 */
9157c478bd9Sstevel@tonic-gate 	for (i = 0; i < entries; i++) {
9167c478bd9Sstevel@tonic-gate 		struct df_request *dfrp = &request_list[i];
9177c478bd9Sstevel@tonic-gate 
9187c478bd9Sstevel@tonic-gate 		argv[argv_index++] = (dfrp->dfr_cmd_arg == NULL)
919990b4856Slling 		    ? DFR_MOUNT_POINT(dfrp)
920990b4856Slling 		    : dfrp->dfr_cmd_arg;
9217c478bd9Sstevel@tonic-gate 	}
9227c478bd9Sstevel@tonic-gate 
9237c478bd9Sstevel@tonic-gate 	if (V_option) {
9247c478bd9Sstevel@tonic-gate 		for (i = 0; i < argv_index-1; i++)
9257c478bd9Sstevel@tonic-gate 			(void) printf("%s ", argv[i]);
9267c478bd9Sstevel@tonic-gate 		(void) printf("%s\n", argv[i]);
9277c478bd9Sstevel@tonic-gate 		return (0);
9287c478bd9Sstevel@tonic-gate 	}
9297c478bd9Sstevel@tonic-gate 
9307c478bd9Sstevel@tonic-gate 	pid = fork();
9317c478bd9Sstevel@tonic-gate 
9327c478bd9Sstevel@tonic-gate 	if (pid == -1) {
9337c478bd9Sstevel@tonic-gate 		errmsg(ERR_PERROR, "cannot fork process:");
9347c478bd9Sstevel@tonic-gate 		return (1);
9357c478bd9Sstevel@tonic-gate 	} else if (pid == 0) {
9367c478bd9Sstevel@tonic-gate 		(void) execv(cmd_path, argv);
9377c478bd9Sstevel@tonic-gate 		if (errno == ENOENT)
9387c478bd9Sstevel@tonic-gate 			errmsg(ERR_NOFLAGS,
939990b4856Slling 			    "operation not applicable for FSType %s",
940990b4856Slling 			    fstype);
9417c478bd9Sstevel@tonic-gate 		else
9427c478bd9Sstevel@tonic-gate 			errmsg(ERR_PERROR, "cannot execute %s:", cmd_path);
9437c478bd9Sstevel@tonic-gate 		exit(2);
9447c478bd9Sstevel@tonic-gate 	}
9457c478bd9Sstevel@tonic-gate 
9467c478bd9Sstevel@tonic-gate 	/*
9477c478bd9Sstevel@tonic-gate 	 * Reap the child
9487c478bd9Sstevel@tonic-gate 	 */
9497c478bd9Sstevel@tonic-gate 	for (;;) {
9507c478bd9Sstevel@tonic-gate 		pid_t wpid = waitpid(pid, &status, 0);
9517c478bd9Sstevel@tonic-gate 
9527c478bd9Sstevel@tonic-gate 		if (wpid == -1)
9537c478bd9Sstevel@tonic-gate 			if (errno == EINTR)
9547c478bd9Sstevel@tonic-gate 				continue;
9557c478bd9Sstevel@tonic-gate 			else {
9567c478bd9Sstevel@tonic-gate 				errmsg(ERR_PERROR, "waitpid error:");
9577c478bd9Sstevel@tonic-gate 				return (1);
9587c478bd9Sstevel@tonic-gate 			}
9597c478bd9Sstevel@tonic-gate 		else
9607c478bd9Sstevel@tonic-gate 			break;
9617c478bd9Sstevel@tonic-gate 	}
9627c478bd9Sstevel@tonic-gate 
9637c478bd9Sstevel@tonic-gate 	return ((WIFEXITED(status) && WEXITSTATUS(status) == 0) ? 0 : 1);
9647c478bd9Sstevel@tonic-gate }
9657c478bd9Sstevel@tonic-gate 
9667c478bd9Sstevel@tonic-gate 
9677c478bd9Sstevel@tonic-gate 
9687c478bd9Sstevel@tonic-gate /*
9697c478bd9Sstevel@tonic-gate  * Remove from the request list all requests that do not apply.
9707c478bd9Sstevel@tonic-gate  * Notice that the subsequent processing of the requests depends on
9717c478bd9Sstevel@tonic-gate  * the sanity checking performed by this function.
9727c478bd9Sstevel@tonic-gate  */
9737c478bd9Sstevel@tonic-gate static int
9747c478bd9Sstevel@tonic-gate prune_list(struct df_request request_list[],
9750a055120SJason King     size_t n_requests, size_t *valid_requests)
9767c478bd9Sstevel@tonic-gate {
9777c478bd9Sstevel@tonic-gate 	size_t	i;
9787c478bd9Sstevel@tonic-gate 	size_t	n_valid = 0;
9797c478bd9Sstevel@tonic-gate 	int	errors = 0;
9807c478bd9Sstevel@tonic-gate 
9817c478bd9Sstevel@tonic-gate 	for (i = 0; i < n_requests; i++) {
9827c478bd9Sstevel@tonic-gate 		struct df_request *dfrp = &request_list[i];
9837c478bd9Sstevel@tonic-gate 
9847c478bd9Sstevel@tonic-gate 		/*
9857c478bd9Sstevel@tonic-gate 		 * Skip file systems that are not mounted if either the
9867c478bd9Sstevel@tonic-gate 		 * -l or -n options were specified. If none of these options
9877c478bd9Sstevel@tonic-gate 		 * are present, the appropriate FS-specific df will be invoked.
9887c478bd9Sstevel@tonic-gate 		 */
9897c478bd9Sstevel@tonic-gate 		if (! DFR_ISMOUNTEDFS(dfrp)) {
9907c478bd9Sstevel@tonic-gate 			if (l_option || n_option) {
9917c478bd9Sstevel@tonic-gate 				errmsg(ERR_NOFLAGS,
992990b4856Slling 				    "%s option incompatible with unmounted "
993990b4856Slling 				    "special device (%s)",
994990b4856Slling 				    l_option ? "-l" : "-n", dfrp->dfr_cmd_arg);
9957c478bd9Sstevel@tonic-gate 				dfrp->dfr_valid = FALSE;
9967c478bd9Sstevel@tonic-gate 				errors++;
9977c478bd9Sstevel@tonic-gate 			}
9987c478bd9Sstevel@tonic-gate 			else
9997c478bd9Sstevel@tonic-gate 				n_valid++;
10007c478bd9Sstevel@tonic-gate 			continue;
10017c478bd9Sstevel@tonic-gate 		}
10027c478bd9Sstevel@tonic-gate 
10037c478bd9Sstevel@tonic-gate 		/*
10047c478bd9Sstevel@tonic-gate 		 * Check for inconsistency between the argument of -F and
10057c478bd9Sstevel@tonic-gate 		 * the actual file system type.
10067c478bd9Sstevel@tonic-gate 		 * If there is an inconsistency and the user specified a
10077c478bd9Sstevel@tonic-gate 		 * path, this is an error since we are asked to interpret
10087c478bd9Sstevel@tonic-gate 		 * the path using the wrong file system type. If there is
10097c478bd9Sstevel@tonic-gate 		 * no path associated with this request, we quietly ignore it.
10107c478bd9Sstevel@tonic-gate 		 */
10117c478bd9Sstevel@tonic-gate 		if (F_option && ! EQ(dfrp->dfr_fstype, FSType)) {
10127c478bd9Sstevel@tonic-gate 			dfrp->dfr_valid = FALSE;
10137c478bd9Sstevel@tonic-gate 			if (dfrp->dfr_cmd_arg != NULL) {
10147c478bd9Sstevel@tonic-gate 				errmsg(ERR_NOFLAGS,
10157c478bd9Sstevel@tonic-gate 				"Warning: %s mounted as a %s file system",
1016990b4856Slling 				    dfrp->dfr_cmd_arg, dfrp->dfr_fstype);
10177c478bd9Sstevel@tonic-gate 				errors++;
10187c478bd9Sstevel@tonic-gate 			}
10197c478bd9Sstevel@tonic-gate 			continue;
10207c478bd9Sstevel@tonic-gate 		}
10217c478bd9Sstevel@tonic-gate 
10227c478bd9Sstevel@tonic-gate 		/*
10237c478bd9Sstevel@tonic-gate 		 * Skip remote file systems if the -l option is present
10247c478bd9Sstevel@tonic-gate 		 */
10257c478bd9Sstevel@tonic-gate 		if (l_option && is_remote_fs(dfrp->dfr_fstype)) {
10267c478bd9Sstevel@tonic-gate 			if (dfrp->dfr_cmd_arg != NULL) {
10277c478bd9Sstevel@tonic-gate 				errmsg(ERR_NOFLAGS,
1028990b4856Slling 				    "Warning: %s is not a local file system",
1029990b4856Slling 				    dfrp->dfr_cmd_arg);
10307c478bd9Sstevel@tonic-gate 				errors++;
10317c478bd9Sstevel@tonic-gate 			}
10327c478bd9Sstevel@tonic-gate 			dfrp->dfr_valid = FALSE;
10337c478bd9Sstevel@tonic-gate 			continue;
10347c478bd9Sstevel@tonic-gate 		}
10357c478bd9Sstevel@tonic-gate 
10367c478bd9Sstevel@tonic-gate 		/*
10377c478bd9Sstevel@tonic-gate 		 * Skip file systems mounted as "ignore" unless the -a option
10387c478bd9Sstevel@tonic-gate 		 * is present, or the user explicitly specified them on
10397c478bd9