xref: /titanic_44/usr/src/cmd/fs.d/ufs/lockfs/lockfs.c (revision d1a180b0452ce86577a43be3245d2eacdeec1a34)
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
5*d1a180b0Smaheshvs  * Common Development and Distribution License (the "License").
6*d1a180b0Smaheshvs  * 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 /*
22*d1a180b0Smaheshvs  * 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
297c478bd9Sstevel@tonic-gate  * lockfs
307c478bd9Sstevel@tonic-gate  *	user interface to lockfs functionality
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate #include <sys/types.h>
337c478bd9Sstevel@tonic-gate #include <stdio.h>
347c478bd9Sstevel@tonic-gate #include <string.h>
357c478bd9Sstevel@tonic-gate #include <unistd.h>
367c478bd9Sstevel@tonic-gate #include <fcntl.h>
377c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
387c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
397c478bd9Sstevel@tonic-gate #include <errno.h>
407c478bd9Sstevel@tonic-gate #include <sys/lockfs.h>
417c478bd9Sstevel@tonic-gate #include <sys/filio.h>
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate #define	bzero(s, n)	memset(s, 0, n);
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /*
467c478bd9Sstevel@tonic-gate  * command line processing
477c478bd9Sstevel@tonic-gate  */
487c478bd9Sstevel@tonic-gate extern char	*optarg;
497c478bd9Sstevel@tonic-gate extern int	optind;
507c478bd9Sstevel@tonic-gate extern int	opterr;
517c478bd9Sstevel@tonic-gate 
527c478bd9Sstevel@tonic-gate extern void exit();
537c478bd9Sstevel@tonic-gate 
547c478bd9Sstevel@tonic-gate static void exitusage();
55*d1a180b0Smaheshvs static void printstatusline(char *, char *, char *);
56*d1a180b0Smaheshvs static void printstatus(char *);
57*d1a180b0Smaheshvs static void flushfs(char *);
58*d1a180b0Smaheshvs static void lockfs(char *);
597c478bd9Sstevel@tonic-gate static void getmntnames();
60*d1a180b0Smaheshvs static void getcmdnames(int, char **, int);
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * -a = all
647c478bd9Sstevel@tonic-gate  * -v = verbose
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate int all		= 0;
677c478bd9Sstevel@tonic-gate int verbose	= 0;
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate /*
707c478bd9Sstevel@tonic-gate  * exitstatus
717c478bd9Sstevel@tonic-gate  *	0 all ok
727c478bd9Sstevel@tonic-gate  *	1 internal error
737c478bd9Sstevel@tonic-gate  *	2 system call error
747c478bd9Sstevel@tonic-gate  */
757c478bd9Sstevel@tonic-gate int exitstatus	= 0;
767c478bd9Sstevel@tonic-gate 
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * list of filenames
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate struct filename {
817c478bd9Sstevel@tonic-gate 	struct filename	*fn_next;
827c478bd9Sstevel@tonic-gate 	char		*fn_name;
837c478bd9Sstevel@tonic-gate };
847c478bd9Sstevel@tonic-gate struct filename	*fnanchor	= 0;
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate /*
877c478bd9Sstevel@tonic-gate  * default request is `file system lock status'
887c478bd9Sstevel@tonic-gate  * default lock type is `unlock'
897c478bd9Sstevel@tonic-gate  * -wnduhfe changes them
907c478bd9Sstevel@tonic-gate  */
917c478bd9Sstevel@tonic-gate int request	= _FIOLFSS;
92*d1a180b0Smaheshvs ushort_t	lock	= LOCKFS_ULOCK;
937c478bd9Sstevel@tonic-gate 
947c478bd9Sstevel@tonic-gate /*
957c478bd9Sstevel@tonic-gate  * default comment is null
967c478bd9Sstevel@tonic-gate  *	-c changes it
977c478bd9Sstevel@tonic-gate  */
987c478bd9Sstevel@tonic-gate caddr_t comment	= 0;
99*d1a180b0Smaheshvs ulong_t	comlen	= 0;
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate /*
1027c478bd9Sstevel@tonic-gate  * for prettyprint
1037c478bd9Sstevel@tonic-gate  */
1047c478bd9Sstevel@tonic-gate int firsttime	= 0;
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate  * no unlocks printed
1087c478bd9Sstevel@tonic-gate  */
1097c478bd9Sstevel@tonic-gate int no_unlocks_printed	= 0;
1107c478bd9Sstevel@tonic-gate 
1117c478bd9Sstevel@tonic-gate /*
1127c478bd9Sstevel@tonic-gate  * file system was modified during hlock/wlock/elock
1137c478bd9Sstevel@tonic-gate  */
1147c478bd9Sstevel@tonic-gate #define	LOCKWARN(FN, S)	\
1157c478bd9Sstevel@tonic-gate { \
1167c478bd9Sstevel@tonic-gate 	if (verbose) \
1177c478bd9Sstevel@tonic-gate 		printf("WARNING: %s was modified while %s locked\n", FN, S); \
1187c478bd9Sstevel@tonic-gate 	exitstatus = 2; \
1197c478bd9Sstevel@tonic-gate }
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate /*
1227c478bd9Sstevel@tonic-gate  * forward reference
1237c478bd9Sstevel@tonic-gate  */
1247c478bd9Sstevel@tonic-gate char	*malloc();
1257c478bd9Sstevel@tonic-gate 
126*d1a180b0Smaheshvs int
main(int argc,char * argv[])127*d1a180b0Smaheshvs main(int argc, char *argv[])
1287c478bd9Sstevel@tonic-gate {
1297c478bd9Sstevel@tonic-gate 	int		c;
1307c478bd9Sstevel@tonic-gate 	struct filename	*fnp;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	exitstatus = 0;
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate 	/*
1357c478bd9Sstevel@tonic-gate 	 * process command line
1367c478bd9Sstevel@tonic-gate 	 */
1377c478bd9Sstevel@tonic-gate 	opterr = 0;
1387c478bd9Sstevel@tonic-gate 	optarg = 0;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "vfwnduheac:")) != -1)
1417c478bd9Sstevel@tonic-gate 		switch (c) {
1427c478bd9Sstevel@tonic-gate 		case 'v':
1437c478bd9Sstevel@tonic-gate 			verbose = 1;
1447c478bd9Sstevel@tonic-gate 			break;
1457c478bd9Sstevel@tonic-gate 		case 'f':
1467c478bd9Sstevel@tonic-gate 			request = _FIOFFS;
1477c478bd9Sstevel@tonic-gate 			break;
1487c478bd9Sstevel@tonic-gate 		case 'w':
1497c478bd9Sstevel@tonic-gate 			lock    = LOCKFS_WLOCK;
1507c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1517c478bd9Sstevel@tonic-gate 			break;
1527c478bd9Sstevel@tonic-gate 		case 'n':
1537c478bd9Sstevel@tonic-gate 			lock    = LOCKFS_NLOCK;
1547c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1557c478bd9Sstevel@tonic-gate 			break;
1567c478bd9Sstevel@tonic-gate 		case 'd':
1577c478bd9Sstevel@tonic-gate 			lock    = LOCKFS_DLOCK;
1587c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1597c478bd9Sstevel@tonic-gate 			break;
1607c478bd9Sstevel@tonic-gate 		case 'h':
1617c478bd9Sstevel@tonic-gate 			lock    = LOCKFS_HLOCK;
1627c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1637c478bd9Sstevel@tonic-gate 			break;
1647c478bd9Sstevel@tonic-gate 		case 'e':
1657c478bd9Sstevel@tonic-gate 			lock	= LOCKFS_ELOCK;
1667c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1677c478bd9Sstevel@tonic-gate 			break;
1687c478bd9Sstevel@tonic-gate 		case 'u':
1697c478bd9Sstevel@tonic-gate 			lock    = LOCKFS_ULOCK;
1707c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1717c478bd9Sstevel@tonic-gate 			break;
1727c478bd9Sstevel@tonic-gate 		case 'a':
1737c478bd9Sstevel@tonic-gate 			all = 1;
1747c478bd9Sstevel@tonic-gate 			break;
1757c478bd9Sstevel@tonic-gate 		case 'c':
1767c478bd9Sstevel@tonic-gate 			comment = optarg;
1777c478bd9Sstevel@tonic-gate 			comlen  = strlen(optarg)+1;
1787c478bd9Sstevel@tonic-gate 			request = _FIOLFS;
1797c478bd9Sstevel@tonic-gate 			break;
1807c478bd9Sstevel@tonic-gate 		default:
1817c478bd9Sstevel@tonic-gate 			exitusage();
1827c478bd9Sstevel@tonic-gate 			break;
1837c478bd9Sstevel@tonic-gate 		}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (argc == 1) {
1867c478bd9Sstevel@tonic-gate 		no_unlocks_printed = 1;
1877c478bd9Sstevel@tonic-gate 		all = 1;
1887c478bd9Sstevel@tonic-gate 	}
1897c478bd9Sstevel@tonic-gate 
1907c478bd9Sstevel@tonic-gate 	if (all)
1917c478bd9Sstevel@tonic-gate 		/*
1927c478bd9Sstevel@tonic-gate 		 * use /etc/mtab
1937c478bd9Sstevel@tonic-gate 		 */
1947c478bd9Sstevel@tonic-gate 		getmntnames();
1957c478bd9Sstevel@tonic-gate 	else
1967c478bd9Sstevel@tonic-gate 		/*
1977c478bd9Sstevel@tonic-gate 		 * use command line
1987c478bd9Sstevel@tonic-gate 		 */
1997c478bd9Sstevel@tonic-gate 		getcmdnames(argc, argv, optind);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * for each filename, doit
2037c478bd9Sstevel@tonic-gate 	 */
2047c478bd9Sstevel@tonic-gate 	for (fnp = fnanchor; fnp; fnp = fnp->fn_next) {
2057c478bd9Sstevel@tonic-gate 		switch (request) {
2067c478bd9Sstevel@tonic-gate 		case _FIOLFSS:
2077c478bd9Sstevel@tonic-gate 			printstatus(fnp->fn_name);
2087c478bd9Sstevel@tonic-gate 			break;
2097c478bd9Sstevel@tonic-gate 		case _FIOLFS:
2107c478bd9Sstevel@tonic-gate 			lockfs(fnp->fn_name);
2117c478bd9Sstevel@tonic-gate 			break;
2127c478bd9Sstevel@tonic-gate 		case _FIOFFS:
2137c478bd9Sstevel@tonic-gate 			flushfs(fnp->fn_name);
2147c478bd9Sstevel@tonic-gate 			break;
2157c478bd9Sstevel@tonic-gate 		default:
2167c478bd9Sstevel@tonic-gate 			break;
2177c478bd9Sstevel@tonic-gate 		}
2187c478bd9Sstevel@tonic-gate 	}
2197c478bd9Sstevel@tonic-gate 
2207c478bd9Sstevel@tonic-gate 	/*
2217c478bd9Sstevel@tonic-gate 	 * all done
2227c478bd9Sstevel@tonic-gate 	 */
223*d1a180b0Smaheshvs 	return (exitstatus);
2247c478bd9Sstevel@tonic-gate }
2257c478bd9Sstevel@tonic-gate /*
2267c478bd9Sstevel@tonic-gate  * exitusage
2277c478bd9Sstevel@tonic-gate  *	bad command line, give hint
2287c478bd9Sstevel@tonic-gate  */
2297c478bd9Sstevel@tonic-gate void
exitusage()2307c478bd9Sstevel@tonic-gate exitusage()
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	printf("usage: lockfs [-dfhnuw] [-c string] [-a] [file system ...]\n");
2337c478bd9Sstevel@tonic-gate 	exit(1);
2347c478bd9Sstevel@tonic-gate }
2357c478bd9Sstevel@tonic-gate /*
2367c478bd9Sstevel@tonic-gate  * printstatusline
2377c478bd9Sstevel@tonic-gate  * 	prettyprint the status line
2387c478bd9Sstevel@tonic-gate  */
2397c478bd9Sstevel@tonic-gate void
printstatusline(char * fn,char * locktype,char * comment)240*d1a180b0Smaheshvs printstatusline(char *fn, char *locktype, char *comment)
2417c478bd9Sstevel@tonic-gate {
2427c478bd9Sstevel@tonic-gate 	if (firsttime++ == 0)
2437c478bd9Sstevel@tonic-gate 		printf("%-20s %-10s %s\n", "Filesystem", "Locktype", "Comment");
2447c478bd9Sstevel@tonic-gate 	printf("%-20s %-10s %s\n", fn, locktype, comment);
2457c478bd9Sstevel@tonic-gate }
2467c478bd9Sstevel@tonic-gate /*
2477c478bd9Sstevel@tonic-gate  * printstatus
2487c478bd9Sstevel@tonic-gate  *	get and prettyprint file system lock status
2497c478bd9Sstevel@tonic-gate  */
2507c478bd9Sstevel@tonic-gate void
printstatus(char * fn)251*d1a180b0Smaheshvs printstatus(char *fn)
2527c478bd9Sstevel@tonic-gate {
2537c478bd9Sstevel@tonic-gate 	int		fd;
2547c478bd9Sstevel@tonic-gate 	int		fsmod	= 0;
2557c478bd9Sstevel@tonic-gate 	char		*locktype;
2567c478bd9Sstevel@tonic-gate 	char		commentbuffer[LOCKFS_MAXCOMMENTLEN+1];
2577c478bd9Sstevel@tonic-gate 	struct lockfs	lf;
2587c478bd9Sstevel@tonic-gate 
2597c478bd9Sstevel@tonic-gate 	fd = open64(fn, O_RDONLY);
2607c478bd9Sstevel@tonic-gate 	if (fd == -1) {
2617c478bd9Sstevel@tonic-gate 		if (errno == EIO)
2627c478bd9Sstevel@tonic-gate 			printstatusline(fn, "EIO", "May be hard locked");
2637c478bd9Sstevel@tonic-gate 		else
2647c478bd9Sstevel@tonic-gate 			perror(fn);
2657c478bd9Sstevel@tonic-gate 		exitstatus = 2;
2667c478bd9Sstevel@tonic-gate 		return;
2677c478bd9Sstevel@tonic-gate 	}
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&lf, sizeof (struct lockfs));
2707c478bd9Sstevel@tonic-gate 
2717c478bd9Sstevel@tonic-gate 	lf.lf_flags   = LOCKFS_MOD;
2727c478bd9Sstevel@tonic-gate 	lf.lf_comlen  = LOCKFS_MAXCOMMENTLEN;
2737c478bd9Sstevel@tonic-gate 	lf.lf_comment = commentbuffer;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	if (ioctl(fd, _FIOLFSS, &lf) == -1) {
2767c478bd9Sstevel@tonic-gate 		perror(fn);
2777c478bd9Sstevel@tonic-gate 		close(fd);
2787c478bd9Sstevel@tonic-gate 		exitstatus = 2;
2797c478bd9Sstevel@tonic-gate 		return;
2807c478bd9Sstevel@tonic-gate 	}
2817c478bd9Sstevel@tonic-gate 	switch (lf.lf_lock) {
2827c478bd9Sstevel@tonic-gate 	case LOCKFS_ULOCK:
2837c478bd9Sstevel@tonic-gate 		if (no_unlocks_printed)
2847c478bd9Sstevel@tonic-gate 			goto out;
2857c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
2867c478bd9Sstevel@tonic-gate 			locktype = "(unlock)";
2877c478bd9Sstevel@tonic-gate 		else
2887c478bd9Sstevel@tonic-gate 			locktype = "unlock";
2897c478bd9Sstevel@tonic-gate 		break;
2907c478bd9Sstevel@tonic-gate 	case LOCKFS_WLOCK:
2917c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
2927c478bd9Sstevel@tonic-gate 			locktype = "(write)";
2937c478bd9Sstevel@tonic-gate 		else {
2947c478bd9Sstevel@tonic-gate 			locktype = "write";
2957c478bd9Sstevel@tonic-gate 			fsmod = LOCKFS_IS_MOD(&lf);
2967c478bd9Sstevel@tonic-gate 		}
2977c478bd9Sstevel@tonic-gate 		break;
2987c478bd9Sstevel@tonic-gate 	case LOCKFS_NLOCK:
2997c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
3007c478bd9Sstevel@tonic-gate 			locktype = "(name)";
3017c478bd9Sstevel@tonic-gate 		else
3027c478bd9Sstevel@tonic-gate 			locktype = "name";
3037c478bd9Sstevel@tonic-gate 		break;
3047c478bd9Sstevel@tonic-gate 	case LOCKFS_DLOCK:
3057c478bd9Sstevel@tonic-gate 		locktype = "delete";
3067c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
3077c478bd9Sstevel@tonic-gate 			locktype = "(delete)";
3087c478bd9Sstevel@tonic-gate 		else
3097c478bd9Sstevel@tonic-gate 			locktype = "delete";
3107c478bd9Sstevel@tonic-gate 		break;
3117c478bd9Sstevel@tonic-gate 	case LOCKFS_HLOCK:
3127c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
3137c478bd9Sstevel@tonic-gate 			locktype = "(hard)";
3147c478bd9Sstevel@tonic-gate 		else {
3157c478bd9Sstevel@tonic-gate 			locktype = "hard";
3167c478bd9Sstevel@tonic-gate 			fsmod = LOCKFS_IS_MOD(&lf);
3177c478bd9Sstevel@tonic-gate 		}
3187c478bd9Sstevel@tonic-gate 		break;
3197c478bd9Sstevel@tonic-gate 	case LOCKFS_ELOCK:
3207c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
3217c478bd9Sstevel@tonic-gate 			locktype = "(error)";
3227c478bd9Sstevel@tonic-gate 		else {
3237c478bd9Sstevel@tonic-gate 			locktype = "error";
3247c478bd9Sstevel@tonic-gate 			fsmod = LOCKFS_IS_MOD(&lf);
3257c478bd9Sstevel@tonic-gate 		}
3267c478bd9Sstevel@tonic-gate 		break;
3277c478bd9Sstevel@tonic-gate 	default:
3287c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_BUSY(&lf))
3297c478bd9Sstevel@tonic-gate 			locktype = "(unknown)";
3307c478bd9Sstevel@tonic-gate 		else
3317c478bd9Sstevel@tonic-gate 			locktype = "unknown";
3327c478bd9Sstevel@tonic-gate 		break;
3337c478bd9Sstevel@tonic-gate 	}
3347c478bd9Sstevel@tonic-gate 	lf.lf_comment[lf.lf_comlen] = '\0';
3357c478bd9Sstevel@tonic-gate 	printstatusline(fn, locktype, lf.lf_comment);
3367c478bd9Sstevel@tonic-gate 	if (fsmod)
3377c478bd9Sstevel@tonic-gate 		LOCKWARN(fn, locktype);
3387c478bd9Sstevel@tonic-gate out:
3397c478bd9Sstevel@tonic-gate 	close(fd);
3407c478bd9Sstevel@tonic-gate }
3417c478bd9Sstevel@tonic-gate /*
3427c478bd9Sstevel@tonic-gate  * flushfs
3437c478bd9Sstevel@tonic-gate  *	push and invalidate at least the data that is *currently* dirty
3447c478bd9Sstevel@tonic-gate  */
3457c478bd9Sstevel@tonic-gate void
flushfs(char * fn)346*d1a180b0Smaheshvs flushfs(char *fn)
3477c478bd9Sstevel@tonic-gate {
3487c478bd9Sstevel@tonic-gate 	int		fd;
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	fd = open64(fn, O_RDONLY);
3517c478bd9Sstevel@tonic-gate 	if (fd == -1) {
3527c478bd9Sstevel@tonic-gate 		perror(fn);
3537c478bd9Sstevel@tonic-gate 		exitstatus = 2;
3547c478bd9Sstevel@tonic-gate 		return;
3557c478bd9Sstevel@tonic-gate 	}
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	if (ioctl(fd, _FIOFFS, NULL) == -1) {
3587c478bd9Sstevel@tonic-gate 		perror(fn);
3597c478bd9Sstevel@tonic-gate 		close(fd);
3607c478bd9Sstevel@tonic-gate 		exitstatus = 2;
3617c478bd9Sstevel@tonic-gate 		return;
3627c478bd9Sstevel@tonic-gate 	}
3637c478bd9Sstevel@tonic-gate 	close(fd);
3647c478bd9Sstevel@tonic-gate }
3657c478bd9Sstevel@tonic-gate /*
3667c478bd9Sstevel@tonic-gate  * lockfs
3677c478bd9Sstevel@tonic-gate  *	lock the file system
3687c478bd9Sstevel@tonic-gate  */
3697c478bd9Sstevel@tonic-gate void
lockfs(char * fn)370*d1a180b0Smaheshvs lockfs(char *fn)
3717c478bd9Sstevel@tonic-gate {
3727c478bd9Sstevel@tonic-gate 	int		fd;
3737c478bd9Sstevel@tonic-gate 	struct lockfs	lf;
3747c478bd9Sstevel@tonic-gate 
3757c478bd9Sstevel@tonic-gate 	fd = open64(fn, O_RDONLY);
3767c478bd9Sstevel@tonic-gate 	if (fd == -1) {
3777c478bd9Sstevel@tonic-gate 		perror(fn);
3787c478bd9Sstevel@tonic-gate 		exitstatus = 2;
3797c478bd9Sstevel@tonic-gate 		return;
3807c478bd9Sstevel@tonic-gate 	}
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 	bzero((caddr_t)&lf, sizeof (struct lockfs));
3837c478bd9Sstevel@tonic-gate 
3847c478bd9Sstevel@tonic-gate 	lf.lf_flags = LOCKFS_MOD;
3857c478bd9Sstevel@tonic-gate 	if (ioctl(fd, _FIOLFSS, &lf) == -1) {
3867c478bd9Sstevel@tonic-gate 		perror(fn);
3877c478bd9Sstevel@tonic-gate 		close(fd);
3887c478bd9Sstevel@tonic-gate 		exitstatus = 2;
3897c478bd9Sstevel@tonic-gate 		return;
3907c478bd9Sstevel@tonic-gate 	}
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 	if (!LOCKFS_IS_BUSY(&lf) && LOCKFS_IS_MOD(&lf)) {
3937c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_HLOCK(&lf))
3947c478bd9Sstevel@tonic-gate 			LOCKWARN(fn, "hard");
3957c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_ELOCK(&lf))
3967c478bd9Sstevel@tonic-gate 			LOCKWARN(fn, "error");
3977c478bd9Sstevel@tonic-gate 		if (LOCKFS_IS_WLOCK(&lf))
3987c478bd9Sstevel@tonic-gate 			LOCKWARN(fn, "write");
3997c478bd9Sstevel@tonic-gate 	}
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate 	lf.lf_lock	= lock;
4027c478bd9Sstevel@tonic-gate 	lf.lf_flags	= 0;
4037c478bd9Sstevel@tonic-gate 	lf.lf_key	= lf.lf_key;
4047c478bd9Sstevel@tonic-gate 	lf.lf_comment	= comment;
4057c478bd9Sstevel@tonic-gate 	lf.lf_comlen	= (comment) ? strlen(comment)+1 : 0;
4067c478bd9Sstevel@tonic-gate 
4077c478bd9Sstevel@tonic-gate 	if (ioctl(fd, _FIOLFS, &lf) == -1) {
4087c478bd9Sstevel@tonic-gate 		perror(fn);
4097c478bd9Sstevel@tonic-gate 		close(fd);
4107c478bd9Sstevel@tonic-gate 		exitstatus = 2;
4117c478bd9Sstevel@tonic-gate 		return;
4127c478bd9Sstevel@tonic-gate 	}
4137c478bd9Sstevel@tonic-gate 	close(fd);
4147c478bd9Sstevel@tonic-gate }
4157c478bd9Sstevel@tonic-gate /*
4167c478bd9Sstevel@tonic-gate  * getmntnames
4177c478bd9Sstevel@tonic-gate  *	file names from /etc/mtab
4187c478bd9Sstevel@tonic-gate  */
4197c478bd9Sstevel@tonic-gate void
getmntnames()4207c478bd9Sstevel@tonic-gate getmntnames()
4217c478bd9Sstevel@tonic-gate {
4227c478bd9Sstevel@tonic-gate 	int		fnlen;
4237c478bd9Sstevel@tonic-gate 	struct filename	*fnp;
4247c478bd9Sstevel@tonic-gate 	struct filename	*fnpc;
4257c478bd9Sstevel@tonic-gate 	FILE		*mnttab;
4267c478bd9Sstevel@tonic-gate 	struct mnttab	mnt, *mntp = &mnt;
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	fnpc = fnanchor;
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	if ((mnttab = fopen(MNTTAB, "r")) == NULL) {
4317c478bd9Sstevel@tonic-gate 		fprintf(stderr, "Can't open %s\n", MNTTAB);
4327c478bd9Sstevel@tonic-gate 		perror(MNTTAB);
4337c478bd9Sstevel@tonic-gate 		exit(32);
4347c478bd9Sstevel@tonic-gate 	}
4357c478bd9Sstevel@tonic-gate 	while ((getmntent(mnttab, mntp)) == 0) {
4367c478bd9Sstevel@tonic-gate 		if (strcmp(mntp->mnt_fstype, MNTTYPE_UFS) != 0)
4377c478bd9Sstevel@tonic-gate 			continue;
4387c478bd9Sstevel@tonic-gate 		fnlen = strlen(mntp->mnt_mountp) + 1;
4397c478bd9Sstevel@tonic-gate 		fnp = (struct filename *)malloc(sizeof (struct filename));
440*d1a180b0Smaheshvs 		fnp->fn_name = malloc((uint_t)fnlen);
4417c478bd9Sstevel@tonic-gate 		strcpy(fnp->fn_name, mntp->mnt_mountp);
4427c478bd9Sstevel@tonic-gate 		fnp->fn_next = NULL;
4437c478bd9Sstevel@tonic-gate 		if (fnpc)
4447c478bd9Sstevel@tonic-gate 			fnpc->fn_next = fnp;
4457c478bd9Sstevel@tonic-gate 		else
4467c478bd9Sstevel@tonic-gate 			fnanchor = fnp;
4477c478bd9Sstevel@tonic-gate 		fnpc = fnp;
4487c478bd9Sstevel@tonic-gate 	}
4497c478bd9Sstevel@tonic-gate 	fclose(mnttab);
4507c478bd9Sstevel@tonic-gate }
4517c478bd9Sstevel@tonic-gate /*
4527c478bd9Sstevel@tonic-gate  * getcmdnames
4537c478bd9Sstevel@tonic-gate  *	file names from command line
4547c478bd9Sstevel@tonic-gate  */
4557c478bd9Sstevel@tonic-gate void
getcmdnames(int argc,char ** argv,int i)456*d1a180b0Smaheshvs getcmdnames(int argc, char **argv, int i)
4577c478bd9Sstevel@tonic-gate {
4587c478bd9Sstevel@tonic-gate 	struct filename	*fnp;
4597c478bd9Sstevel@tonic-gate 	struct filename	*fnpc;
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	for (fnpc = fnanchor; i < argc; ++i) {
4627c478bd9Sstevel@tonic-gate 		fnp = (struct filename *)malloc(sizeof (struct filename));
4637c478bd9Sstevel@tonic-gate 		fnp->fn_name = *(argv+i);
4647c478bd9Sstevel@tonic-gate 		fnp->fn_next = NULL;
4657c478bd9Sstevel@tonic-gate 		if (fnpc)
4667c478bd9Sstevel@tonic-gate 			fnpc->fn_next = fnp;
4677c478bd9Sstevel@tonic-gate 		else
4687c478bd9Sstevel@tonic-gate 			fnanchor = fnp;
4697c478bd9Sstevel@tonic-gate 		fnpc = fnp;
4707c478bd9Sstevel@tonic-gate 	}
4717c478bd9Sstevel@tonic-gate }
472