xref: /illumos-gate/usr/src/cmd/fs.d/udfs/fsck/main.c (revision bfbf29e2)
17c478bd9Sstevel@tonic-gate /*
2fe0e7ec4Smaheshvs  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
37c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
7*bfbf29e2SToomas Soome /*	  All Rights Reserved	*/
87c478bd9Sstevel@tonic-gate 
97c478bd9Sstevel@tonic-gate /*
107c478bd9Sstevel@tonic-gate  * Copyright (c) 1980, 1986, 1990 The Regents of the University of California.
117c478bd9Sstevel@tonic-gate  * All rights reserved.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * Redistribution and use in source and binary forms are permitted
147c478bd9Sstevel@tonic-gate  * provided that: (1) source distributions retain this entire copyright
157c478bd9Sstevel@tonic-gate  * notice and comment, and (2) distributions including binaries display
167c478bd9Sstevel@tonic-gate  * the following acknowledgement:  ``This product includes software
177c478bd9Sstevel@tonic-gate  * developed by the University of California, Berkeley and its contributors''
187c478bd9Sstevel@tonic-gate  * in the documentation or other materials provided with the distribution
197c478bd9Sstevel@tonic-gate  * and in all advertising materials mentioning features or use of this
207c478bd9Sstevel@tonic-gate  * software. Neither the name of the University nor the names of its
217c478bd9Sstevel@tonic-gate  * contributors may be used to endorse or promote products derived
227c478bd9Sstevel@tonic-gate  * from this software without specific prior written permission.
237c478bd9Sstevel@tonic-gate  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
247c478bd9Sstevel@tonic-gate  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
257c478bd9Sstevel@tonic-gate  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <stdio.h>
297c478bd9Sstevel@tonic-gate #include <string.h>
307c478bd9Sstevel@tonic-gate #include <ctype.h>	/* use isdigit macro rather than 4.1 libc routine */
317c478bd9Sstevel@tonic-gate #include <unistd.h>
327c478bd9Sstevel@tonic-gate #include <stdlib.h>
337c478bd9Sstevel@tonic-gate #include <signal.h>
347c478bd9Sstevel@tonic-gate #include <malloc.h>
357c478bd9Sstevel@tonic-gate #include <ustat.h>
367c478bd9Sstevel@tonic-gate #include <sys/param.h>
377c478bd9Sstevel@tonic-gate #include <sys/types.h>
387c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
397c478bd9Sstevel@tonic-gate #include <sys/mntent.h>
407c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
417c478bd9Sstevel@tonic-gate #include <sys/stat.h>
427c478bd9Sstevel@tonic-gate #include <sys/wait.h>
437c478bd9Sstevel@tonic-gate #include <sys/mnttab.h>
447c478bd9Sstevel@tonic-gate #include <sys/signal.h>
457c478bd9Sstevel@tonic-gate #include <sys/vfstab.h>
467c478bd9Sstevel@tonic-gate #include <sys/fs/udf_volume.h>
477c478bd9Sstevel@tonic-gate #include "fsck.h"
487c478bd9Sstevel@tonic-gate #include <locale.h>
497c478bd9Sstevel@tonic-gate 
50*bfbf29e2SToomas Soome int	debug;
51*bfbf29e2SToomas Soome char	nflag;
52*bfbf29e2SToomas Soome char	yflag;
53*bfbf29e2SToomas Soome int	rflag;
54*bfbf29e2SToomas Soome static int	wflag;		/* check only writable filesystems */
55*bfbf29e2SToomas Soome int	fflag;
56*bfbf29e2SToomas Soome static int	sflag;		/* print status flag */
57*bfbf29e2SToomas Soome int	isdirty;
58*bfbf29e2SToomas Soome int	fsmodified;
59*bfbf29e2SToomas Soome int	iscorrupt;
60*bfbf29e2SToomas Soome int	exitstat;
61*bfbf29e2SToomas Soome uint32_t part_len;
62*bfbf29e2SToomas Soome daddr_t	n_blks;
63*bfbf29e2SToomas Soome daddr_t	n_files;
64*bfbf29e2SToomas Soome daddr_t	n_dirs;
65*bfbf29e2SToomas Soome char	preen;
66*bfbf29e2SToomas Soome char	mountpoint[100];
67*bfbf29e2SToomas Soome char	mountedfs;
68*bfbf29e2SToomas Soome char	*devname;
69*bfbf29e2SToomas Soome struct log_vol_int_desc *lvintp;
70*bfbf29e2SToomas Soome 
717c478bd9Sstevel@tonic-gate extern int32_t	writable(char *);
727c478bd9Sstevel@tonic-gate extern void	pfatal(char *, ...);
737c478bd9Sstevel@tonic-gate extern void	printfree();
747c478bd9Sstevel@tonic-gate extern void	pwarn(char *, ...);
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate extern void	pass1();
777c478bd9Sstevel@tonic-gate extern void	dofreemap();
787c478bd9Sstevel@tonic-gate extern void	dolvint();
797c478bd9Sstevel@tonic-gate extern char	*getfullblkname();
807c478bd9Sstevel@tonic-gate extern char	*getfullrawname();
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate static int	mflag = 0;		/* sanity check only */
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate char	*mntopt();
857c478bd9Sstevel@tonic-gate void	catch(), catchquit(), voidquit();
867c478bd9Sstevel@tonic-gate int	returntosingle;
877c478bd9Sstevel@tonic-gate static void	checkfilesys();
887c478bd9Sstevel@tonic-gate static void	check_sanity();
897c478bd9Sstevel@tonic-gate static void	usage();
907c478bd9Sstevel@tonic-gate 
917c478bd9Sstevel@tonic-gate static char *subopts [] = {
927c478bd9Sstevel@tonic-gate #define	PREEN		0
937c478bd9Sstevel@tonic-gate 	"p",
947c478bd9Sstevel@tonic-gate #define	DEBUG		1
957c478bd9Sstevel@tonic-gate 	"d",
967c478bd9Sstevel@tonic-gate #define	READ_ONLY	2
977c478bd9Sstevel@tonic-gate 	"r",
987c478bd9Sstevel@tonic-gate #define	ONLY_WRITES	3
997c478bd9Sstevel@tonic-gate 	"w",
1007c478bd9Sstevel@tonic-gate #define	FORCE		4	/* force checking, even if clean */
1017c478bd9Sstevel@tonic-gate 	"f",
1027c478bd9Sstevel@tonic-gate #define	STATS		5	/* print time and busy stats */
1037c478bd9Sstevel@tonic-gate 	"s",
1047c478bd9Sstevel@tonic-gate 	NULL
1057c478bd9Sstevel@tonic-gate };
1067c478bd9Sstevel@tonic-gate 
1077c478bd9Sstevel@tonic-gate uint32_t ecma_version = 2;
1087c478bd9Sstevel@tonic-gate 
109fe0e7ec4Smaheshvs int
main(int argc,char * argv[])110fe0e7ec4Smaheshvs main(int argc, char *argv[])
1117c478bd9Sstevel@tonic-gate {
1127c478bd9Sstevel@tonic-gate 	int	c;
1137c478bd9Sstevel@tonic-gate 	char	*suboptions,	*value;
1147c478bd9Sstevel@tonic-gate 	int	suboption;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	(void) setlocale(LC_ALL, "");
1177c478bd9Sstevel@tonic-gate 
1187c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "mnNo:VyYz")) != EOF) {
1197c478bd9Sstevel@tonic-gate 		switch (c) {
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 		case 'm':
1227c478bd9Sstevel@tonic-gate 			mflag++;
1237c478bd9Sstevel@tonic-gate 			break;
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate 		case 'n':	/* default no answer flag */
1267c478bd9Sstevel@tonic-gate 		case 'N':
1277c478bd9Sstevel@tonic-gate 			nflag++;
1287c478bd9Sstevel@tonic-gate 			yflag = 0;
1297c478bd9Sstevel@tonic-gate 			break;
1307c478bd9Sstevel@tonic-gate 
1317c478bd9Sstevel@tonic-gate 		case 'o':
1327c478bd9Sstevel@tonic-gate 			/*
1337c478bd9Sstevel@tonic-gate 			 * udfs specific options.
1347c478bd9Sstevel@tonic-gate 			 */
1357c478bd9Sstevel@tonic-gate 			suboptions = optarg;
1367c478bd9Sstevel@tonic-gate 			while (*suboptions != '\0') {
1377c478bd9Sstevel@tonic-gate 				suboption = getsubopt(&suboptions,
1387c478bd9Sstevel@tonic-gate 						subopts, &value);
1397c478bd9Sstevel@tonic-gate 				switch (suboption) {
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate 				case PREEN:
1427c478bd9Sstevel@tonic-gate 					preen++;
1437c478bd9Sstevel@tonic-gate 					break;
1447c478bd9Sstevel@tonic-gate 
1457c478bd9Sstevel@tonic-gate 				case DEBUG:
1467c478bd9Sstevel@tonic-gate 					debug++;
1477c478bd9Sstevel@tonic-gate 					break;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 				case READ_ONLY:
1507c478bd9Sstevel@tonic-gate 					break;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 				case ONLY_WRITES:
1537c478bd9Sstevel@tonic-gate 					/* check only writable filesystems */
1547c478bd9Sstevel@tonic-gate 					wflag++;
1557c478bd9Sstevel@tonic-gate 					break;
1567c478bd9Sstevel@tonic-gate 
1577c478bd9Sstevel@tonic-gate 				case FORCE:
1587c478bd9Sstevel@tonic-gate 					fflag++;
1597c478bd9Sstevel@tonic-gate 					break;
1607c478bd9Sstevel@tonic-gate 
1617c478bd9Sstevel@tonic-gate 				case STATS:
1627c478bd9Sstevel@tonic-gate 					sflag++;
1637c478bd9Sstevel@tonic-gate 					break;
1647c478bd9Sstevel@tonic-gate 
1657c478bd9Sstevel@tonic-gate 				default:
1667c478bd9Sstevel@tonic-gate 					usage();
1677c478bd9Sstevel@tonic-gate 				}
1687c478bd9Sstevel@tonic-gate 			}
1697c478bd9Sstevel@tonic-gate 			break;
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 		case 'V':
1727c478bd9Sstevel@tonic-gate 			{
1737c478bd9Sstevel@tonic-gate 				int	opt_count;
1747c478bd9Sstevel@tonic-gate 				char	*opt_text;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate 				(void) fprintf(stdout, "fsck -F udfs ");
1777c478bd9Sstevel@tonic-gate 				for (opt_count = 1; opt_count < argc;
1787c478bd9Sstevel@tonic-gate 								opt_count++) {
1797c478bd9Sstevel@tonic-gate 					opt_text = argv[opt_count];
1807c478bd9Sstevel@tonic-gate 					if (opt_text)
1817c478bd9Sstevel@tonic-gate 						(void) fprintf(stdout, " %s ",
1827c478bd9Sstevel@tonic-gate 								opt_text);
1837c478bd9Sstevel@tonic-gate 				}
1847c478bd9Sstevel@tonic-gate 				(void) fprintf(stdout, "\n");
1857c478bd9Sstevel@tonic-gate 			}
1867c478bd9Sstevel@tonic-gate 			break;
1877c478bd9Sstevel@tonic-gate 
1887c478bd9Sstevel@tonic-gate 		case 'y':	/* default yes answer flag */
1897c478bd9Sstevel@tonic-gate 		case 'Y':
1907c478bd9Sstevel@tonic-gate 			yflag++;
1917c478bd9Sstevel@tonic-gate 			nflag = 0;
1927c478bd9Sstevel@tonic-gate 			break;
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 		case '?':
1957c478bd9Sstevel@tonic-gate 			usage();
1967c478bd9Sstevel@tonic-gate 		}
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 	argc -= optind;
1997c478bd9Sstevel@tonic-gate 	argv = &argv[optind];
2007c478bd9Sstevel@tonic-gate 	rflag++; /* check raw devices */
2017c478bd9Sstevel@tonic-gate 	if (signal(SIGINT, SIG_IGN) != SIG_IGN) {
2027c478bd9Sstevel@tonic-gate 		(void) signal(SIGINT, catch);
2037c478bd9Sstevel@tonic-gate 	}
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	if (preen) {
2067c478bd9Sstevel@tonic-gate 		(void) signal(SIGQUIT, catchquit);
2077c478bd9Sstevel@tonic-gate 	}
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	if (argc) {
2107c478bd9Sstevel@tonic-gate 		while (argc-- > 0) {
2117c478bd9Sstevel@tonic-gate 			if (wflag && !writable(*argv)) {
2127c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr,
2137c478bd9Sstevel@tonic-gate 					gettext("not writeable '%s'\n"), *argv);
2147c478bd9Sstevel@tonic-gate 				argv++;
2157c478bd9Sstevel@tonic-gate 			} else
2167c478bd9Sstevel@tonic-gate 				checkfilesys(*argv++);
2177c478bd9Sstevel@tonic-gate 		}
2187c478bd9Sstevel@tonic-gate 		exit(exitstat);
2197c478bd9Sstevel@tonic-gate 	}
220fe0e7ec4Smaheshvs 	return (0);
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate static void
checkfilesys(char * filesys)225fe0e7ec4Smaheshvs checkfilesys(char *filesys)
2267c478bd9Sstevel@tonic-gate {
2277c478bd9Sstevel@tonic-gate 	char *devstr;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	mountedfs = 0;
2307c478bd9Sstevel@tonic-gate 	iscorrupt = 1;
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate 	if ((devstr = setup(filesys)) == 0) {
2337c478bd9Sstevel@tonic-gate 		if (iscorrupt == 0)
2347c478bd9Sstevel@tonic-gate 			return;
2357c478bd9Sstevel@tonic-gate 		if (preen)
2367c478bd9Sstevel@tonic-gate 			pfatal(gettext("CAN'T CHECK FILE SYSTEM."));
2377c478bd9Sstevel@tonic-gate 		if ((exitstat == 0) && (mflag))
2387c478bd9Sstevel@tonic-gate 			exitstat = 32;
2397c478bd9Sstevel@tonic-gate 		exit(exitstat);
2407c478bd9Sstevel@tonic-gate 	}
2417c478bd9Sstevel@tonic-gate 	else
2427c478bd9Sstevel@tonic-gate 		devname = devstr;
2437c478bd9Sstevel@tonic-gate 	if (mflag)
2447c478bd9Sstevel@tonic-gate 		check_sanity(filesys);	/* this never returns */
2457c478bd9Sstevel@tonic-gate 	iscorrupt = 0;
2467c478bd9Sstevel@tonic-gate 	/*
2477c478bd9Sstevel@tonic-gate 	 * 1: scan inodes tallying blocks used
2487c478bd9Sstevel@tonic-gate 	 */
2497c478bd9Sstevel@tonic-gate 	if (preen == 0) {
2507c478bd9Sstevel@tonic-gate 		if (mountedfs)
2517c478bd9Sstevel@tonic-gate 			(void) printf(gettext("** Currently Mounted on %s\n"),
2527c478bd9Sstevel@tonic-gate 				mountpoint);
2537c478bd9Sstevel@tonic-gate 		if (mflag) {
2547c478bd9Sstevel@tonic-gate 			(void) printf(
2557c478bd9Sstevel@tonic-gate 				gettext("** Phase 1 - Sanity Check only\n"));
2567c478bd9Sstevel@tonic-gate 			return;
2577c478bd9Sstevel@tonic-gate 		} else
2587c478bd9Sstevel@tonic-gate 			(void) printf(
2597c478bd9Sstevel@tonic-gate 				gettext("** Phase 1 - Check Directories "
2607c478bd9Sstevel@tonic-gate 				"and Blocks\n"));
2617c478bd9Sstevel@tonic-gate 	}
2627c478bd9Sstevel@tonic-gate 	pass1();
2637c478bd9Sstevel@tonic-gate 	if (sflag) {
2647c478bd9Sstevel@tonic-gate 		if (preen)
2657c478bd9Sstevel@tonic-gate 			(void) printf("%s: ", devname);
2667c478bd9Sstevel@tonic-gate 		else
2677c478bd9Sstevel@tonic-gate 			(void) printf("** ");
2687c478bd9Sstevel@tonic-gate 	}
2697c478bd9Sstevel@tonic-gate 	if (debug)
2707c478bd9Sstevel@tonic-gate 		(void) printf("pass1 isdirty %d\n", isdirty);
2717c478bd9Sstevel@tonic-gate 	if (debug)
2727c478bd9Sstevel@tonic-gate 		printfree();
2737c478bd9Sstevel@tonic-gate 	dofreemap();
2747c478bd9Sstevel@tonic-gate 	dolvint();
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 	/*
2777c478bd9Sstevel@tonic-gate 	 * print out summary statistics
2787c478bd9Sstevel@tonic-gate 	 */
2797c478bd9Sstevel@tonic-gate 	pwarn(gettext("%d files, %d dirs, %d used, %d free\n"), n_files, n_dirs,
2807c478bd9Sstevel@tonic-gate 		n_blks, part_len - n_blks);
2817c478bd9Sstevel@tonic-gate 	if (iscorrupt)
2827c478bd9Sstevel@tonic-gate 		exitstat = 36;
2837c478bd9Sstevel@tonic-gate 	if (!fsmodified)
2847c478bd9Sstevel@tonic-gate 		return;
2857c478bd9Sstevel@tonic-gate 	if (!preen)
2867c478bd9Sstevel@tonic-gate 		(void) printf(
2877c478bd9Sstevel@tonic-gate 			gettext("\n***** FILE SYSTEM WAS MODIFIED *****\n"));
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate 	if (mountedfs) {
2907c478bd9Sstevel@tonic-gate 		exitstat = 40;
2917c478bd9Sstevel@tonic-gate 	}
2927c478bd9Sstevel@tonic-gate }
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * exit 0 - file system is unmounted and okay
2977c478bd9Sstevel@tonic-gate  * exit 32 - file system is unmounted and needs checking
2987c478bd9Sstevel@tonic-gate  * exit 33 - file system is mounted
2997c478bd9Sstevel@tonic-gate  *	for root file system
3007c478bd9Sstevel@tonic-gate  * exit 34 - cannot stat device
3017c478bd9Sstevel@tonic-gate  */
3027c478bd9Sstevel@tonic-gate 
3037c478bd9Sstevel@tonic-gate static void
check_sanity(char * filename)304fe0e7ec4Smaheshvs check_sanity(char *filename)
3057c478bd9Sstevel@tonic-gate {
3067c478bd9Sstevel@tonic-gate 	struct stat stbd, stbr;
3077c478bd9Sstevel@tonic-gate 	struct ustat usb;
3087c478bd9Sstevel@tonic-gate 	char *devname;
3097c478bd9Sstevel@tonic-gate 	struct vfstab vfsbuf;
3107c478bd9Sstevel@tonic-gate 	FILE *vfstab;
3117c478bd9Sstevel@tonic-gate 	int is_root = 0;
3127c478bd9Sstevel@tonic-gate 	int is_usr = 0;
3137c478bd9Sstevel@tonic-gate 	int is_block = 0;
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	if (stat(filename, &stbd) < 0) {
3167c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3177c478bd9Sstevel@tonic-gate 			gettext("udfs fsck: sanity check failed : cannot stat "
3187c478bd9Sstevel@tonic-gate 			"%s\n"), filename);
3197c478bd9Sstevel@tonic-gate 		exit(34);
3207c478bd9Sstevel@tonic-gate 	}
3217c478bd9Sstevel@tonic-gate 
3227c478bd9Sstevel@tonic-gate 	if ((stbd.st_mode & S_IFMT) == S_IFBLK)
3237c478bd9Sstevel@tonic-gate 		is_block = 1;
3247c478bd9Sstevel@tonic-gate 	else if ((stbd.st_mode & S_IFMT) == S_IFCHR)
3257c478bd9Sstevel@tonic-gate 		is_block = 0;
3267c478bd9Sstevel@tonic-gate 	else {
3277c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3287c478bd9Sstevel@tonic-gate 			gettext("udfs fsck: sanity check failed: %s not "
3297c478bd9Sstevel@tonic-gate 			"block or character device\n"), filename);
3307c478bd9Sstevel@tonic-gate 		exit(34);
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	/*
3347c478bd9Sstevel@tonic-gate 	 * Determine if this is the root file system via vfstab. Give up
3357c478bd9Sstevel@tonic-gate 	 * silently on failures. The whole point of this is not to care
3367c478bd9Sstevel@tonic-gate 	 * if the root file system is already mounted.
3377c478bd9Sstevel@tonic-gate 	 *
3387c478bd9Sstevel@tonic-gate 	 * XXX - similar for /usr. This should be fixed to simply return
3397c478bd9Sstevel@tonic-gate 	 * a new code indicating, mounted and needs to be checked.
3407c478bd9Sstevel@tonic-gate 	 */
3417c478bd9Sstevel@tonic-gate 	if ((vfstab = fopen(VFSTAB, "r")) != 0) {
3427c478bd9Sstevel@tonic-gate 		if (getvfsfile(vfstab, &vfsbuf, "/") == 0) {
3437c478bd9Sstevel@tonic-gate 			if (is_block)
3447c478bd9Sstevel@tonic-gate 				devname = vfsbuf.vfs_special;
3457c478bd9Sstevel@tonic-gate 			else
3467c478bd9Sstevel@tonic-gate 				devname = vfsbuf.vfs_fsckdev;
3477c478bd9Sstevel@tonic-gate 			if (stat(devname, &stbr) == 0)
3487c478bd9Sstevel@tonic-gate 				if (stbr.st_rdev == stbd.st_rdev)
3497c478bd9Sstevel@tonic-gate 					is_root = 1;
3507c478bd9Sstevel@tonic-gate 		}
3517c478bd9Sstevel@tonic-gate 		if (getvfsfile(vfstab, &vfsbuf, "/usr") == 0) {
3527c478bd9Sstevel@tonic-gate 			if (is_block)
3537c478bd9Sstevel@tonic-gate 				devname = vfsbuf.vfs_special;
3547c478bd9Sstevel@tonic-gate 			else
3557c478bd9Sstevel@tonic-gate 				devname = vfsbuf.vfs_fsckdev;
3567c478bd9Sstevel@tonic-gate 			if (stat(devname, &stbr) == 0)
3577c478bd9Sstevel@tonic-gate 				if (stbr.st_rdev == stbd.st_rdev)
3587c478bd9Sstevel@tonic-gate 					is_usr = 1;
3597c478bd9Sstevel@tonic-gate 		}
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate 
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	/*
3647c478bd9Sstevel@tonic-gate 	 * XXX - only works if filename is a block device or if
3657c478bd9Sstevel@tonic-gate 	 * character and block device has the same dev_t value
3667c478bd9Sstevel@tonic-gate 	 */
3677c478bd9Sstevel@tonic-gate 	if (is_root == 0 && is_usr == 0 && ustat(stbd.st_rdev, &usb) == 0) {
3687c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3697c478bd9Sstevel@tonic-gate 			gettext("udfs fsck: sanity check: %s "
3707c478bd9Sstevel@tonic-gate 			"already mounted\n"), filename);
3717c478bd9Sstevel@tonic-gate 		exit(33);
3727c478bd9Sstevel@tonic-gate 	}
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	if (lvintp->lvid_int_type == LVI_CLOSE) {
3757c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3767c478bd9Sstevel@tonic-gate 			gettext("udfs fsck: sanity check: %s okay\n"),
3777c478bd9Sstevel@tonic-gate 			filename);
3787c478bd9Sstevel@tonic-gate 	} else {
3797c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr,
3807c478bd9Sstevel@tonic-gate 			gettext("udfs fsck: sanity check: %s needs checking\n"),
3817c478bd9Sstevel@tonic-gate 			filename);
3827c478bd9Sstevel@tonic-gate 		exit(32);
3837c478bd9Sstevel@tonic-gate 	}
3847c478bd9Sstevel@tonic-gate 	exit(0);
3857c478bd9Sstevel@tonic-gate }
3867c478bd9Sstevel@tonic-gate 
3877c478bd9Sstevel@tonic-gate char *
unrawname(char * name)388fe0e7ec4Smaheshvs unrawname(char *name)
3897c478bd9Sstevel@tonic-gate {
3907c478bd9Sstevel@tonic-gate 	char *dp;
3917c478bd9Sstevel@tonic-gate 
3927c478bd9Sstevel@tonic-gate 
3937c478bd9Sstevel@tonic-gate 	if ((dp = getfullblkname(name)) == NULL)
3947c478bd9Sstevel@tonic-gate 		return ("");
3957c478bd9Sstevel@tonic-gate 	return (dp);
3967c478bd9Sstevel@tonic-gate }
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate char *
rawname(char * name)399fe0e7ec4Smaheshvs rawname(char *name)
4007c478bd9Sstevel@tonic-gate {
4017c478bd9Sstevel@tonic-gate 	char *dp;
4027c478bd9Sstevel@tonic-gate 
4037c478bd9Sstevel@tonic-gate 	if ((dp = getfullrawname(name)) == NULL)
4047c478bd9Sstevel@tonic-gate 		return ("");
4057c478bd9Sstevel@tonic-gate 	return (dp);
4067c478bd9Sstevel@tonic-gate }
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate char *
hasvfsopt(struct vfstab * vfs,char * opt)409fe0e7ec4Smaheshvs hasvfsopt(struct vfstab *vfs, char *opt)
4107c478bd9Sstevel@tonic-gate {
4117c478bd9Sstevel@tonic-gate 	char *f, *opts;
4127c478bd9Sstevel@tonic-gate 	static char *tmpopts;
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	if (vfs->vfs_mntopts == NULL)
4157c478bd9Sstevel@tonic-gate 		return (NULL);
4167c478bd9Sstevel@tonic-gate 	if (tmpopts == 0) {
4177c478bd9Sstevel@tonic-gate 		tmpopts = (char *)calloc(256, sizeof (char));
4187c478bd9Sstevel@tonic-gate 		if (tmpopts == 0)
4197c478bd9Sstevel@tonic-gate 			return (0);
4207c478bd9Sstevel@tonic-gate 	}
4217c478bd9Sstevel@tonic-gate 	(void) strncpy(tmpopts, vfs->vfs_mntopts, (sizeof (tmpopts) - 1));
4227c478bd9Sstevel@tonic-gate 	opts = tmpopts;
4237c478bd9Sstevel@tonic-gate 	f = mntopt(&opts);
4247c478bd9Sstevel@tonic-gate 	for (; *f; f = mntopt(&opts)) {
4257c478bd9Sstevel@tonic-gate 		if (strncmp(opt, f, strlen(opt)) == 0)
4267c478bd9Sstevel@tonic-gate 			return (f - tmpopts + vfs->vfs_mntopts);
4277c478bd9Sstevel@tonic-gate 	}
4287c478bd9Sstevel@tonic-gate 	return (NULL);
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate static void
usage()4327c478bd9Sstevel@tonic-gate usage()
4337c478bd9Sstevel@tonic-gate {
4347c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, gettext("udfs usage: fsck [-F udfs] "
4357c478bd9Sstevel@tonic-gate 		"[generic options] [-o p,w,s] [special ....]\n"));
4367c478bd9Sstevel@tonic-gate 	exit(31+1);
4377c478bd9Sstevel@tonic-gate }
438