xref: /illumos-gate/usr/src/cmd/fs.d/ufs/quotaon/quotaon.c (revision 8509e9ca)
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
5d1a180b0Smaheshvs  * Common Development and Distribution License (the "License").
6d1a180b0Smaheshvs  * 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 /*
22d1a180b0Smaheshvs  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
27*8509e9caSToomas Soome /*	  All Rights Reserved	*/
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate  * University Copyright- Copyright (c) 1982, 1986, 1988
317c478bd9Sstevel@tonic-gate  * The Regents of the University of California
327c478bd9Sstevel@tonic-gate  * All Rights Reserved
337c478bd9Sstevel@tonic-gate  *
347c478bd9Sstevel@tonic-gate  * University Acknowledgment- Portions of this document are derived from
357c478bd9Sstevel@tonic-gate  * software developed by the University of California, Berkeley, and its
367c478bd9Sstevel@tonic-gate  * contributors.
377c478bd9Sstevel@tonic-gate  */
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /*
407c478bd9Sstevel@tonic-gate  * Turn quota on/off for a filesystem.
417c478bd9Sstevel@tonic-gate  */
427c478bd9Sstevel@tonic-gate #include <sys/param.h>
437c478bd9Sstevel@tonic-gate #include <sys/types.h>
447c478bd9Sstevel@tonic-gate #include <sys/stat.h>
457c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #define	bcopy(f, t, n)    memcpy(t, f, n)
487c478bd9Sstevel@tonic-gate #define	bzero(s, n)	memset(s, 0, n)
497c478bd9Sstevel@tonic-gate #define	bcmp(s, d, n)	memcmp(s, d, n)
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate #define	index(s, r)	strchr(s, r)
527c478bd9Sstevel@tonic-gate #define	rindex(s, r)	strrchr(s, r)
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate #include <string.h>
557c478bd9Sstevel@tonic-gate #include <stdlib.h>
567c478bd9Sstevel@tonic-gate #include <unistd.h>
577c478bd9Sstevel@tonic-gate #include <sys/file.h>
587c478bd9Sstevel@tonic-gate #include <signal.h>
597c478bd9Sstevel@tonic-gate #include <fcntl.h>
607c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_quota.h>
617c478bd9Sstevel@tonic-gate #include <stdio.h>
627c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
637c478bd9Sstevel@tonic-gate #include <errno.h>
647c478bd9Sstevel@tonic-gate #include <sys/vfstab.h>
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate int	vflag;		/* verbose */
677c478bd9Sstevel@tonic-gate int	aflag;		/* all file systems */
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate #define	QFNAME "quotas"
707c478bd9Sstevel@tonic-gate #define	CHUNK	50
717c478bd9Sstevel@tonic-gate char	**listbuf;
727c478bd9Sstevel@tonic-gate char	*mntopt(), *hasvfsopt(), *hasmntopt();
737c478bd9Sstevel@tonic-gate char	*whoami;
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate static void fixmntent();
767c478bd9Sstevel@tonic-gate static void mnterror();
77d1a180b0Smaheshvs static void usage(char *);
787c478bd9Sstevel@tonic-gate static int oneof();
797c478bd9Sstevel@tonic-gate static int quotaonoff();
80d1a180b0Smaheshvs static int quotactl(int, char *, uid_t, caddr_t);
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate extern int	optind;
837c478bd9Sstevel@tonic-gate extern char	*optarg;
847c478bd9Sstevel@tonic-gate 
85d1a180b0Smaheshvs int
main(int argc,char ** argv)86d1a180b0Smaheshvs main(int argc, char **argv)
877c478bd9Sstevel@tonic-gate {
887c478bd9Sstevel@tonic-gate 	struct mnttab mntp;
897c478bd9Sstevel@tonic-gate 	struct vfstab vfsbuf;
907c478bd9Sstevel@tonic-gate 	char **listp;
917c478bd9Sstevel@tonic-gate 	int listcnt;
927c478bd9Sstevel@tonic-gate 	FILE *mtab, *vfstab, *tmp;
937c478bd9Sstevel@tonic-gate 	int offmode = 0;
947c478bd9Sstevel@tonic-gate 	int listmax = 0;
957c478bd9Sstevel@tonic-gate 	int errs = 0;
967c478bd9Sstevel@tonic-gate 	char *tmpname = "/etc/mnttab.temp";
977c478bd9Sstevel@tonic-gate 	int		status;
987c478bd9Sstevel@tonic-gate 	int		opt;
997c478bd9Sstevel@tonic-gate 	mode_t		oldumask;
1007c478bd9Sstevel@tonic-gate 	struct stat	statbuf;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	whoami = (char *)rindex(*argv, '/') + 1;
1037c478bd9Sstevel@tonic-gate 	if (whoami == (char *)1)
1047c478bd9Sstevel@tonic-gate 		whoami = *argv;
1057c478bd9Sstevel@tonic-gate 	if (strcmp(whoami, "quotaoff") == 0)
1067c478bd9Sstevel@tonic-gate 		offmode++;
1077c478bd9Sstevel@tonic-gate 	else if (strcmp(whoami, "quotaon") != 0) {
1087c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Name must be quotaon or quotaoff not %s\n",
1097c478bd9Sstevel@tonic-gate 			whoami);
1107c478bd9Sstevel@tonic-gate 		exit(31+1);
1117c478bd9Sstevel@tonic-gate 	}
1127c478bd9Sstevel@tonic-gate 	if ((listbuf = (char **)malloc(sizeof (char *) * CHUNK)) == NULL) {
1137c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Can't alloc lisbuf array.");
1147c478bd9Sstevel@tonic-gate 		exit(31+1);
1157c478bd9Sstevel@tonic-gate 	}
1167c478bd9Sstevel@tonic-gate 	listmax = CHUNK;
1177c478bd9Sstevel@tonic-gate 	while ((opt = getopt(argc, argv, "avV")) != EOF) {
1187c478bd9Sstevel@tonic-gate 		switch (opt) {
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 		case 'v':
1217c478bd9Sstevel@tonic-gate 			vflag++;
1227c478bd9Sstevel@tonic-gate 			break;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 		case 'a':
1257c478bd9Sstevel@tonic-gate 			aflag++;
1267c478bd9Sstevel@tonic-gate 			break;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 		case 'V':		/* Print command line */
1297c478bd9Sstevel@tonic-gate 			{
1307c478bd9Sstevel@tonic-gate 				char		*opt_text;
1317c478bd9Sstevel@tonic-gate 				int		opt_cnt;
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 				(void) fprintf(stdout, "%s -F UFS ", whoami);
1347c478bd9Sstevel@tonic-gate 				for (opt_cnt = 1; opt_cnt < argc; opt_cnt++) {
1357c478bd9Sstevel@tonic-gate 					opt_text = argv[opt_cnt];
1367c478bd9Sstevel@tonic-gate 					if (opt_text)
1377c478bd9Sstevel@tonic-gate 						(void) fprintf(stdout, " %s ",
1387c478bd9Sstevel@tonic-gate 							opt_text);
1397c478bd9Sstevel@tonic-gate 				}
1407c478bd9Sstevel@tonic-gate 				(void) fprintf(stdout, "\n");
1417c478bd9Sstevel@tonic-gate 			}
1427c478bd9Sstevel@tonic-gate 			break;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 		case '?':
1457c478bd9Sstevel@tonic-gate 			usage(whoami);
1467c478bd9Sstevel@tonic-gate 		}
1477c478bd9Sstevel@tonic-gate 	}
1487c478bd9Sstevel@tonic-gate 	if (argc <= optind && !aflag) {
1497c478bd9Sstevel@tonic-gate 		usage(whoami);
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate 	/*
1527c478bd9Sstevel@tonic-gate 	 * If aflag go through vfstab and make a list of appropriate
1537c478bd9Sstevel@tonic-gate 	 * filesystems.
1547c478bd9Sstevel@tonic-gate 	 */
1557c478bd9Sstevel@tonic-gate 	if (aflag) {
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 		listp = listbuf;
1587c478bd9Sstevel@tonic-gate 		listcnt = 0;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 		vfstab = fopen(VFSTAB, "r");
1617c478bd9Sstevel@tonic-gate 		if (vfstab == NULL) {
1627c478bd9Sstevel@tonic-gate 			fprintf(stderr, "Can't open %s\n", VFSTAB);
1637c478bd9Sstevel@tonic-gate 			perror(VFSTAB);
1647c478bd9Sstevel@tonic-gate 			exit(31+1);
1657c478bd9Sstevel@tonic-gate 		}
1667c478bd9Sstevel@tonic-gate 
167*8509e9caSToomas Soome 		while ((status = getvfsent(vfstab, &vfsbuf)) == 0) {
1687c478bd9Sstevel@tonic-gate 			if (strcmp(vfsbuf.vfs_fstype, MNTTYPE_UFS) != 0 ||
1697c478bd9Sstevel@tonic-gate 			    (vfsbuf.vfs_mntopts == 0) ||
1707c478bd9Sstevel@tonic-gate 			    hasvfsopt(&vfsbuf, MNTOPT_RO) ||
1717c478bd9Sstevel@tonic-gate 			    (!hasvfsopt(&vfsbuf, MNTOPT_RQ) &&
1727c478bd9Sstevel@tonic-gate 			    !hasvfsopt(&vfsbuf, MNTOPT_QUOTA)))
1737c478bd9Sstevel@tonic-gate 				continue;
1747c478bd9Sstevel@tonic-gate 			*listp = malloc(strlen(vfsbuf.vfs_special) + 1);
1757c478bd9Sstevel@tonic-gate 			strcpy(*listp, vfsbuf.vfs_special);
1767c478bd9Sstevel@tonic-gate 			listp++;
1777c478bd9Sstevel@tonic-gate 			listcnt++;
1787c478bd9Sstevel@tonic-gate 			/* grow listbuf if needed */
1797c478bd9Sstevel@tonic-gate 			if (listcnt >= listmax) {
1807c478bd9Sstevel@tonic-gate 				listmax += CHUNK;
1817c478bd9Sstevel@tonic-gate 				listbuf = (char **)realloc(listbuf,
1827c478bd9Sstevel@tonic-gate 					sizeof (char *) * listmax);
1837c478bd9Sstevel@tonic-gate 				if (listbuf == NULL) {
1847c478bd9Sstevel@tonic-gate 					fprintf(stderr,
1857c478bd9Sstevel@tonic-gate 						"Can't grow listbuf.\n");
1867c478bd9Sstevel@tonic-gate 					exit(31+1);
1877c478bd9Sstevel@tonic-gate 				}
1887c478bd9Sstevel@tonic-gate 				listp = &listbuf[listcnt];
1897c478bd9Sstevel@tonic-gate 			}
1907c478bd9Sstevel@tonic-gate 		}
1917c478bd9Sstevel@tonic-gate 		fclose(vfstab);
1927c478bd9Sstevel@tonic-gate 		*listp = (char *)0;
1937c478bd9Sstevel@tonic-gate 		listp = listbuf;
1947c478bd9Sstevel@tonic-gate 	} else {
1957c478bd9Sstevel@tonic-gate 		listp = &argv[optind];
1967c478bd9Sstevel@tonic-gate 		listcnt = argc - optind;
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	/*
2007c478bd9Sstevel@tonic-gate 	 * Open real mnttab
2017c478bd9Sstevel@tonic-gate 	 */
2027c478bd9Sstevel@tonic-gate 	mtab = fopen(MNTTAB, "r");
2037c478bd9Sstevel@tonic-gate 	if (mtab == NULL) {
2047c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Can't open %s\n", MNTTAB);
2057c478bd9Sstevel@tonic-gate 		perror(whoami);
2067c478bd9Sstevel@tonic-gate 		exit(31+1);
2077c478bd9Sstevel@tonic-gate 	}
2087c478bd9Sstevel@tonic-gate 	/* check every entry for validity before we change mnttab */
2097c478bd9Sstevel@tonic-gate 	while ((status = getmntent(mtab, &mntp)) == 0)
2107c478bd9Sstevel@tonic-gate 		;
2117c478bd9Sstevel@tonic-gate 	if (status > 0)
2127c478bd9Sstevel@tonic-gate 		mnterror(status);
2137c478bd9Sstevel@tonic-gate 	rewind(mtab);
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate 	signal(SIGHUP,  SIG_IGN);
2167c478bd9Sstevel@tonic-gate 	signal(SIGQUIT, SIG_IGN);
2177c478bd9Sstevel@tonic-gate 	signal(SIGINT,  SIG_IGN);
2187c478bd9Sstevel@tonic-gate 
2197c478bd9Sstevel@tonic-gate 	/*
2207c478bd9Sstevel@tonic-gate 	 * Loop through mnttab, if a file system gets turned on or off
2217c478bd9Sstevel@tonic-gate 	 * do the quota call.
2227c478bd9Sstevel@tonic-gate 	 */
223*8509e9caSToomas Soome 	while ((status = getmntent(mtab, &mntp)) == 0) {
2247c478bd9Sstevel@tonic-gate 		if (strcmp(mntp.mnt_fstype, MNTTYPE_UFS) == 0 &&
2257c478bd9Sstevel@tonic-gate 		    !hasmntopt(&mntp, MNTOPT_RO) &&
2267c478bd9Sstevel@tonic-gate 		    (oneof(mntp.mnt_special, listp, listcnt) ||
2277c478bd9Sstevel@tonic-gate 		    oneof(mntp.mnt_mountp, listp, listcnt))) {
2287c478bd9Sstevel@tonic-gate 			errs += quotaonoff(&mntp, offmode);
2297c478bd9Sstevel@tonic-gate 		}
2307c478bd9Sstevel@tonic-gate 	}
2317c478bd9Sstevel@tonic-gate 	fclose(mtab);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	while (listcnt--) {
2347c478bd9Sstevel@tonic-gate 		if (*listp) {
2357c478bd9Sstevel@tonic-gate 			fprintf(stderr, "Cannot do %s\n", *listp);
2367c478bd9Sstevel@tonic-gate 			errs++;
2377c478bd9Sstevel@tonic-gate 		}
2387c478bd9Sstevel@tonic-gate 		listp++;
2397c478bd9Sstevel@tonic-gate 	}
2407c478bd9Sstevel@tonic-gate 	if (errs > 0)
2417c478bd9Sstevel@tonic-gate 		errs += 31;
242d1a180b0Smaheshvs 	return (errs);
2437c478bd9Sstevel@tonic-gate }
2447c478bd9Sstevel@tonic-gate 
2457c478bd9Sstevel@tonic-gate int
quotaonoff(struct mnttab * mntp,int offmode)246d1a180b0Smaheshvs quotaonoff(struct mnttab *mntp, int offmode)
2477c478bd9Sstevel@tonic-gate {
2487c478bd9Sstevel@tonic-gate 
2497c478bd9Sstevel@tonic-gate 	if (offmode) {
2507c478bd9Sstevel@tonic-gate 		if (quotactl(Q_QUOTAOFF, mntp->mnt_mountp, (uid_t)0, NULL) < 0)
2517c478bd9Sstevel@tonic-gate 			goto bad;
2527c478bd9Sstevel@tonic-gate 		if (vflag)
2537c478bd9Sstevel@tonic-gate 			printf("%s: quotas turned off\n", mntp->mnt_mountp);
2547c478bd9Sstevel@tonic-gate 	} else {
2557c478bd9Sstevel@tonic-gate 		if (quotactl(Q_QUOTAON, mntp->mnt_mountp, (uid_t)0, NULL) <
2567c478bd9Sstevel@tonic-gate 		    0)
2577c478bd9Sstevel@tonic-gate 			goto bad;
2587c478bd9Sstevel@tonic-gate 		if (vflag)
2597c478bd9Sstevel@tonic-gate 			printf("%s: quotas turned on\n", mntp->mnt_mountp);
2607c478bd9Sstevel@tonic-gate 	}
2617c478bd9Sstevel@tonic-gate 	return (0);
2627c478bd9Sstevel@tonic-gate bad:
2637c478bd9Sstevel@tonic-gate 	fprintf(stderr, "quotactl: ");
2647c478bd9Sstevel@tonic-gate 	perror(mntp->mnt_special);
2657c478bd9Sstevel@tonic-gate 	return (1);
2667c478bd9Sstevel@tonic-gate }
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate int
oneof(char * target,char ** olistp,int on)269d1a180b0Smaheshvs oneof(char *target, char **olistp, int on)
2707c478bd9Sstevel@tonic-gate {
2717c478bd9Sstevel@tonic-gate 	int n = on;
2727c478bd9Sstevel@tonic-gate 	char **listp = olistp;
2737c478bd9Sstevel@tonic-gate 
2747c478bd9Sstevel@tonic-gate 	while (n--) {
2757c478bd9Sstevel@tonic-gate 		if (*listp && strcmp(target, *listp) == 0) {
2767c478bd9Sstevel@tonic-gate 			*listp = (char *)0;
2777c478bd9Sstevel@tonic-gate 			return (1);
2787c478bd9Sstevel@tonic-gate 		}
2797c478bd9Sstevel@tonic-gate 		listp++;
2807c478bd9Sstevel@tonic-gate 	}
2817c478bd9Sstevel@tonic-gate 	return (0);
2827c478bd9Sstevel@tonic-gate }
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate void
usage(char * whoami)285d1a180b0Smaheshvs usage(char *whoami)
2867c478bd9Sstevel@tonic-gate {
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	fprintf(stderr, "ufs usage:\n");
2897c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t%s [-v] -a\n", whoami);
2907c478bd9Sstevel@tonic-gate 	fprintf(stderr, "\t%s [-v] filesys ...\n", whoami);
2917c478bd9Sstevel@tonic-gate 		exit(31+1);
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate int
quotactl(int cmd,char * mountpt,uid_t uid,caddr_t addr)296d1a180b0Smaheshvs quotactl(int cmd, char *mountpt, uid_t uid, caddr_t addr)
2977c478bd9Sstevel@tonic-gate {
2987c478bd9Sstevel@tonic-gate 	int		fd;
2997c478bd9Sstevel@tonic-gate 	int		status;
3007c478bd9Sstevel@tonic-gate 	struct quotctl	quota;
3017c478bd9Sstevel@tonic-gate 	char		qfile[MAXPATHLEN];
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate 	if (mountpt == NULL || mountpt[0] == '\0') {
3047c478bd9Sstevel@tonic-gate 		errno = ENOENT;
3057c478bd9Sstevel@tonic-gate 		return (-1);
3067c478bd9Sstevel@tonic-gate 	}
3077c478bd9Sstevel@tonic-gate 	if ((strlcpy(qfile, mountpt, sizeof (qfile)) >= sizeof (qfile)) ||
3087c478bd9Sstevel@tonic-gate 	    (strlcat(qfile, "/" QFNAME, sizeof (qfile)) >= sizeof (qfile))) {
3097c478bd9Sstevel@tonic-gate 		errno = ENOENT;
3107c478bd9Sstevel@tonic-gate 		return (-1);
3117c478bd9Sstevel@tonic-gate 	}
3127c478bd9Sstevel@tonic-gate 	if ((fd = open64(qfile, O_RDWR)) < 0) {
3137c478bd9Sstevel@tonic-gate 		fprintf(stderr, "quotactl: %s ", qfile);
3147c478bd9Sstevel@tonic-gate 		perror("open");
3157c478bd9Sstevel@tonic-gate 		exit(31+1);
3167c478bd9Sstevel@tonic-gate 	}
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	quota.op = cmd;
3197c478bd9Sstevel@tonic-gate 	quota.uid = uid;
3207c478bd9Sstevel@tonic-gate 	quota.addr = addr;
3217c478bd9Sstevel@tonic-gate 	status = ioctl(fd, Q_QUOTACTL, &quota);
3227c478bd9Sstevel@tonic-gate 	close(fd);
3237c478bd9Sstevel@tonic-gate 	return (status);
3247c478bd9Sstevel@tonic-gate }
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate char *
hasvfsopt(struct vfstab * vfs,char * opt)327d1a180b0Smaheshvs hasvfsopt(struct vfstab *vfs, char *opt)
3287c478bd9Sstevel@tonic-gate {
3297c478bd9Sstevel@tonic-gate 	char *f, *opts;
3307c478bd9Sstevel@tonic-gate 	static char *tmpopts;
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate 	if (tmpopts == 0) {
3337c478bd9Sstevel@tonic-gate 		tmpopts = (char *)calloc(256, sizeof (char));
3347c478bd9Sstevel@tonic-gate 		if (tmpopts == 0)
3357c478bd9Sstevel@tonic-gate 			return (0);
3367c478bd9Sstevel@tonic-gate 	}
3377c478bd9Sstevel@tonic-gate 	strcpy(tmpopts, vfs->vfs_mntopts);
3387c478bd9Sstevel@tonic-gate 	opts = tmpopts;
3397c478bd9Sstevel@tonic-gate 	f = mntopt(&opts);
3407c478bd9Sstevel@tonic-gate 	for (; *f; f = mntopt(&opts)) {
3417c478bd9Sstevel@tonic-gate 		if (strncmp(opt, f, strlen(opt)) == 0)
3427c478bd9Sstevel@tonic-gate 			return (f - tmpopts + vfs->vfs_mntopts);
3437c478bd9Sstevel@tonic-gate 	}
3447c478bd9Sstevel@tonic-gate 	return (NULL);
3457c478bd9Sstevel@tonic-gate }
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate void
mnterror(int flag)348d1a180b0Smaheshvs mnterror(int flag)
3497c478bd9Sstevel@tonic-gate {
3507c478bd9Sstevel@tonic-gate 	switch (flag) {
3517c478bd9Sstevel@tonic-gate 	case MNT_TOOLONG:
3527c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: line in mnttab exceeds %d characters\n",
3537c478bd9Sstevel@tonic-gate 			whoami, MNT_LINE_MAX-2);
3547c478bd9Sstevel@tonic-gate 		break;
3557c478bd9Sstevel@tonic-gate 	case MNT_TOOFEW:
3567c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: line in mnttab has too few entries\n",
3577c478bd9Sstevel@tonic-gate 			whoami);
3587c478bd9Sstevel@tonic-gate 		break;
3597c478bd9Sstevel@tonic-gate 	case MNT_TOOMANY:
3607c478bd9Sstevel@tonic-gate 		fprintf(stderr, "%s: line in mnttab has too many entries\n",
3617c478bd9Sstevel@tonic-gate 			whoami);
3627c478bd9Sstevel@tonic-gate 		break;
3637c478bd9Sstevel@tonic-gate 	}
3647c478bd9Sstevel@tonic-gate 	exit(1);
3657c478bd9Sstevel@tonic-gate }
366