xref: /onnv-gate/usr/src/cmd/fs.d/ufs/ff/ff.c (revision 1051:ce6da8f4b892)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1051Smaheshvs  * Common Development and Distribution License (the "License").
6*1051Smaheshvs  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22757Svsakar  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
270Sstevel@tonic-gate /*	  All Rights Reserved  	*/
280Sstevel@tonic-gate 
290Sstevel@tonic-gate /*
300Sstevel@tonic-gate  * Portions of this source code were derived from Berkeley 4.3 BSD
310Sstevel@tonic-gate  * under license from the Regents of the University of California.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
350Sstevel@tonic-gate 
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate  * ff -- obtain file names from reading filesystem
380Sstevel@tonic-gate  */
390Sstevel@tonic-gate 
400Sstevel@tonic-gate #define	NB		500
410Sstevel@tonic-gate #define	MAXNINDIR	(MAXBSIZE / sizeof (daddr32_t))
420Sstevel@tonic-gate 
430Sstevel@tonic-gate #include <sys/param.h>
440Sstevel@tonic-gate #include <sys/types.h>
450Sstevel@tonic-gate #include <sys/mntent.h>
460Sstevel@tonic-gate #include <sys/vnode.h>
470Sstevel@tonic-gate #include <sys/fs/ufs_inode.h>
480Sstevel@tonic-gate #include <sys/stat.h>
490Sstevel@tonic-gate #include <sys/fs/ufs_fs.h>
500Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h>
510Sstevel@tonic-gate #include <stdio.h>
520Sstevel@tonic-gate #include <stdlib.h>
530Sstevel@tonic-gate #include <strings.h>
540Sstevel@tonic-gate #include <errno.h>
550Sstevel@tonic-gate #include <fcntl.h>
560Sstevel@tonic-gate #include <unistd.h>
570Sstevel@tonic-gate #include <pwd.h>
580Sstevel@tonic-gate #include "roll_log.h"
590Sstevel@tonic-gate 
600Sstevel@tonic-gate #define	MIN_PHYS_READ	BBSIZE
610Sstevel@tonic-gate #define	DAY		(24*60*60)
620Sstevel@tonic-gate 
630Sstevel@tonic-gate 
640Sstevel@tonic-gate union {
650Sstevel@tonic-gate 	struct	fs	sblk;
660Sstevel@tonic-gate 	char xxx[SBSIZE];	/* because fs is variable length */
670Sstevel@tonic-gate } real_fs;
680Sstevel@tonic-gate #define	sblock real_fs.sblk
690Sstevel@tonic-gate 
700Sstevel@tonic-gate struct	dinode  *itab;	/*  = (struct dinode *)itab; */
710Sstevel@tonic-gate 
720Sstevel@tonic-gate struct 	dinode	*gip;
730Sstevel@tonic-gate 
740Sstevel@tonic-gate struct ilist {
750Sstevel@tonic-gate 	ino_t	ino;
760Sstevel@tonic-gate 	ushort_t	mode;
770Sstevel@tonic-gate 	uid_t	uid;
780Sstevel@tonic-gate 	gid_t	gid;
790Sstevel@tonic-gate } ilist[NB];
800Sstevel@tonic-gate 
810Sstevel@tonic-gate struct	htab
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	ino_t	h_ino;
840Sstevel@tonic-gate 	ino_t	h_pino;
850Sstevel@tonic-gate 	int	h_name_index;		/* index into string table */
860Sstevel@tonic-gate } *htab;
870Sstevel@tonic-gate char *strngtab;
880Sstevel@tonic-gate long hsize;
890Sstevel@tonic-gate int strngloc;
900Sstevel@tonic-gate int strngtab_size;
910Sstevel@tonic-gate #define	STRNGTAB_INCR	(1024*16)	/* amount to grow strngtab */
920Sstevel@tonic-gate #define	MAX_STRNGTAB_INDEX()	(strngtab_size - 1)
930Sstevel@tonic-gate #define	AVG_PATH_LEN	30		/* average (?) length of name */
940Sstevel@tonic-gate 
950Sstevel@tonic-gate struct dirstuff {
960Sstevel@tonic-gate 	int loc;
970Sstevel@tonic-gate 	struct dinode *ip;
980Sstevel@tonic-gate 	char dbuf[MAXBSIZE];
990Sstevel@tonic-gate };
1000Sstevel@tonic-gate int	Aflg = 0;	/* accessed in n days */
1010Sstevel@tonic-gate int	Mflg = 0;	/* modified in n days */
1020Sstevel@tonic-gate int	Nflg = 0;	/* modified more recently than 'file' */
1030Sstevel@tonic-gate int	Cflg = 0;	/* changed within n days */
1040Sstevel@tonic-gate int	aflg = 0;	/* print the names `.'  and  `..' */
1050Sstevel@tonic-gate int	sflg = 0; /* print only special files and files with set-user-ID mode */
1060Sstevel@tonic-gate int	Sflg = 0;	/* print file size */
1070Sstevel@tonic-gate int	iflg = 0;	/* number of inodes being searched for */
1080Sstevel@tonic-gate int	Iflg = 0;	/* do not print i-number */
1090Sstevel@tonic-gate int	Lflg = 0;	/* supplementary list of multiply linked files */
1100Sstevel@tonic-gate int	mflg = 0;
1110Sstevel@tonic-gate int	pflg = 0;	/* a prefix exists */
1120Sstevel@tonic-gate int	uflg = 0;	/* print the owner's login name */
1130Sstevel@tonic-gate int	fi;
1140Sstevel@tonic-gate ino_t	ino;
1150Sstevel@tonic-gate int	nhent;
1160Sstevel@tonic-gate int	nxfile;
1170Sstevel@tonic-gate int	imax;		/* highest inode number */
1180Sstevel@tonic-gate int	inode_reads;
1190Sstevel@tonic-gate int	passwd_lookups;
1200Sstevel@tonic-gate int	Adelay;		/* Access delay */
1210Sstevel@tonic-gate int	Asign;		/* Access sign */
1220Sstevel@tonic-gate int	Mdelay;		/* Modify delay */
1230Sstevel@tonic-gate int	Msign;		/* Modify sign */
1240Sstevel@tonic-gate int	Cdelay;		/* change delay */
1250Sstevel@tonic-gate int	Csign;		/* change sign */
1260Sstevel@tonic-gate time_t	Nage;		/* Last modification time of the file */
1270Sstevel@tonic-gate char	*Lname;		/* filename for supplementary list */
1280Sstevel@tonic-gate FILE	*Lfile;		/* file for supplementary list */
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate /*
1310Sstevel@tonic-gate  * Function prototypes
1320Sstevel@tonic-gate  */
1330Sstevel@tonic-gate void check(char *file);
1340Sstevel@tonic-gate void pass1(struct dinode *ip);
1350Sstevel@tonic-gate void pass2(struct dinode *ip);
1360Sstevel@tonic-gate void pass3(struct dinode *ip);
1370Sstevel@tonic-gate struct direct *dreaddir(struct dirstuff *dirp);
1380Sstevel@tonic-gate int dotname(struct direct *dp);
1390Sstevel@tonic-gate void pname(FILE *stream, ino_t i, int lev);
1400Sstevel@tonic-gate struct htab *lookup(ino_t i, int ef);
1410Sstevel@tonic-gate void bread(diskaddr_t bno, char *buf, int cnt);
1420Sstevel@tonic-gate diskaddr_t bmap(diskaddr_t i);
1430Sstevel@tonic-gate struct dinode *ginode(ino_t inumber);
1440Sstevel@tonic-gate char *user_name(int uid);
1450Sstevel@tonic-gate int cmp(int a, int b, int s);
1460Sstevel@tonic-gate time_t mod_time(char *file);
1470Sstevel@tonic-gate void out_multilinks();
1480Sstevel@tonic-gate void usage();
1490Sstevel@tonic-gate int extend_strngtab(unsigned int size);
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate long	atol();
1520Sstevel@tonic-gate offset_t llseek();
1530Sstevel@tonic-gate char 	*strcpy();
1540Sstevel@tonic-gate 
1550Sstevel@tonic-gate char	*prefix;
1560Sstevel@tonic-gate time_t	Today;
1570Sstevel@tonic-gate int	nerror;
1580Sstevel@tonic-gate 
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate extern int	optind;
1610Sstevel@tonic-gate extern char	*optarg;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate char *subopts [] = {
1640Sstevel@tonic-gate #define	A_FLAG		0
1650Sstevel@tonic-gate 	"a",
1660Sstevel@tonic-gate #define	M_FLAG		1
1670Sstevel@tonic-gate 	"m",
1680Sstevel@tonic-gate #define	S_FLAG		2
1690Sstevel@tonic-gate 	"s",
1700Sstevel@tonic-gate 	NULL
1710Sstevel@tonic-gate 	};
1720Sstevel@tonic-gate 
1730Sstevel@tonic-gate int
main(int argc,char * argv[])174*1051Smaheshvs main(int argc, char *argv[])
1750Sstevel@tonic-gate {
1760Sstevel@tonic-gate 	long n;
1770Sstevel@tonic-gate 	int	opt;
1780Sstevel@tonic-gate 	char	*suboptions,	*value;
1790Sstevel@tonic-gate 	char *p;
1800Sstevel@tonic-gate 	int first = 0;
1810Sstevel@tonic-gate 
1820Sstevel@tonic-gate 	Today = time((time_t *)0);
1830Sstevel@tonic-gate 	while ((opt = getopt(argc, argv, "Ia:c:i:lm:n:o:p:su")) != EOF) {
1840Sstevel@tonic-gate 		switch (opt) {
1850Sstevel@tonic-gate 
1860Sstevel@tonic-gate 		case 'a':
1870Sstevel@tonic-gate 			Aflg++;
1880Sstevel@tonic-gate 			Adelay = atoi(optarg);
1890Sstevel@tonic-gate 			Asign = optarg[0];
1900Sstevel@tonic-gate 			break;
1910Sstevel@tonic-gate 
1920Sstevel@tonic-gate 		case 'I':
1930Sstevel@tonic-gate 			Iflg++;
1940Sstevel@tonic-gate 			break;
1950Sstevel@tonic-gate 
1960Sstevel@tonic-gate 		case 'c':
1970Sstevel@tonic-gate 			Cflg++;
1980Sstevel@tonic-gate 			Cdelay = atoi(optarg);
1990Sstevel@tonic-gate 			Csign = optarg[0];
2000Sstevel@tonic-gate 			break;
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate 		case 'l':
2030Sstevel@tonic-gate 			Lflg++;
2040Sstevel@tonic-gate 			Lname = tmpnam((char *)0);
2050Sstevel@tonic-gate 			if ((Lfile = fopen(Lname, "w+")) == NULL) {
2060Sstevel@tonic-gate 				perror("open");
2070Sstevel@tonic-gate 				(void) fprintf(stderr,
2080Sstevel@tonic-gate 				"ff: unable to open temp file, -l ignored\n");
2090Sstevel@tonic-gate 				Lflg = 0;
2100Sstevel@tonic-gate 			}
2110Sstevel@tonic-gate 			break;
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 		case 'm':
2140Sstevel@tonic-gate 			Mflg++;
2150Sstevel@tonic-gate 			Mdelay = atoi(optarg);
2160Sstevel@tonic-gate 			Msign = optarg[0];
2170Sstevel@tonic-gate 			break;
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 		case 'n':
2200Sstevel@tonic-gate 			Nflg++;
2210Sstevel@tonic-gate 			Nage = mod_time(optarg);
2220Sstevel@tonic-gate 			break;
2230Sstevel@tonic-gate 
2240Sstevel@tonic-gate 		case 'o':
2250Sstevel@tonic-gate 			/*
2260Sstevel@tonic-gate 			 * ufs specific options.
2270Sstevel@tonic-gate 			 */
2280Sstevel@tonic-gate 			suboptions = optarg;
2290Sstevel@tonic-gate 
2300Sstevel@tonic-gate 			if (*suboptions == '\0')
2310Sstevel@tonic-gate 				usage();
2320Sstevel@tonic-gate 			while (*suboptions != '\0') {
2330Sstevel@tonic-gate 				switch ((getsubopt(&suboptions,
2340Sstevel@tonic-gate 							subopts, &value))) {
2350Sstevel@tonic-gate 
2360Sstevel@tonic-gate 				case A_FLAG:
2370Sstevel@tonic-gate 					aflg++;
2380Sstevel@tonic-gate 					break;
2390Sstevel@tonic-gate 
2400Sstevel@tonic-gate 				case M_FLAG:
2410Sstevel@tonic-gate 					mflg++;
2420Sstevel@tonic-gate 					break;
2430Sstevel@tonic-gate 
2440Sstevel@tonic-gate 				case S_FLAG:
2450Sstevel@tonic-gate 					sflg++;
2460Sstevel@tonic-gate 					break;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 				default:
2490Sstevel@tonic-gate 					usage();
2500Sstevel@tonic-gate 				}
2510Sstevel@tonic-gate 			}
2520Sstevel@tonic-gate 			break;
2530Sstevel@tonic-gate 
2540Sstevel@tonic-gate 		case 'i':
2550Sstevel@tonic-gate 			while ((p = (char *)strtok(((first++ == 0) ?
2560Sstevel@tonic-gate 			optarg: ((char *)0)), ", ")) != NULL) {
2570Sstevel@tonic-gate 				if ((n = atoi(p)) == 0)
2580Sstevel@tonic-gate 					break;
2590Sstevel@tonic-gate 				ilist[iflg].ino = n;
2600Sstevel@tonic-gate 				nxfile = iflg;
2610Sstevel@tonic-gate 				iflg++;
2620Sstevel@tonic-gate 			}
2630Sstevel@tonic-gate 			break;
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 		case 'p':
2660Sstevel@tonic-gate 			prefix = optarg;
2670Sstevel@tonic-gate 			pflg++;
2680Sstevel@tonic-gate 			break;
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 		case 's':
2710Sstevel@tonic-gate 			Sflg++;
2720Sstevel@tonic-gate 			break;
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate 		case 'u':
2750Sstevel@tonic-gate 			uflg++;
2760Sstevel@tonic-gate 			break;
2770Sstevel@tonic-gate 
2780Sstevel@tonic-gate 		case '?':
2790Sstevel@tonic-gate 			usage();
2800Sstevel@tonic-gate 		}
2810Sstevel@tonic-gate 	}
2820Sstevel@tonic-gate 	argc -= optind;
2830Sstevel@tonic-gate 	argv = &argv[optind];
2840Sstevel@tonic-gate 	while (argc--) {
2850Sstevel@tonic-gate 		check(*argv);
2860Sstevel@tonic-gate 		argv++;
2870Sstevel@tonic-gate 	}
2880Sstevel@tonic-gate 	if (Lflg) {
2890Sstevel@tonic-gate 		out_multilinks();
2900Sstevel@tonic-gate 	}
2910Sstevel@tonic-gate 	if (nerror)
2920Sstevel@tonic-gate 		return (32);
2930Sstevel@tonic-gate 	return (0);
2940Sstevel@tonic-gate }
2950Sstevel@tonic-gate 
2960Sstevel@tonic-gate void
check(char * file)2970Sstevel@tonic-gate check(char *file)
2980Sstevel@tonic-gate {
299*1051Smaheshvs 	int i, j, c;
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	fi = open64(file, 0);
3020Sstevel@tonic-gate 	if (fi < 0) {
3030Sstevel@tonic-gate 		(void) fprintf(stderr, "ff: cannot open %s\n", file);
3040Sstevel@tonic-gate 		nerror++;
3050Sstevel@tonic-gate 		return;
3060Sstevel@tonic-gate 	}
3070Sstevel@tonic-gate 	nhent = 0;
3080Sstevel@tonic-gate 	(void) printf("%s:\n", file);
3090Sstevel@tonic-gate 	sync();
3100Sstevel@tonic-gate 	bread(SBLOCK, (char *)&sblock, SBSIZE);
3110Sstevel@tonic-gate 	if ((sblock.fs_magic != FS_MAGIC) &&
3120Sstevel@tonic-gate 	    (sblock.fs_magic != MTB_UFS_MAGIC)) {
3130Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: not a ufs file system\n", file);
3140Sstevel@tonic-gate 		nerror++;
3150Sstevel@tonic-gate 		return;
3160Sstevel@tonic-gate 	}
3170Sstevel@tonic-gate 
318757Svsakar 	if (sblock.fs_magic == FS_MAGIC &&
319757Svsakar 	    (sblock.fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 &&
320757Svsakar 	    sblock.fs_version != UFS_VERSION_MIN)) {
321757Svsakar 		(void) fprintf(stderr, "%s: unrecognized version of UFS: %d\n",
322757Svsakar 		    file, sblock.fs_version);
323757Svsakar 		nerror++;
324757Svsakar 		return;
325757Svsakar 	}
326757Svsakar 
3270Sstevel@tonic-gate 	if (sblock.fs_magic == MTB_UFS_MAGIC &&
3280Sstevel@tonic-gate 	    (sblock.fs_version > MTB_UFS_VERSION_1 ||
3290Sstevel@tonic-gate 	    sblock.fs_version < MTB_UFS_VERSION_MIN)) {
3300Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: unrecognized version of UFS: %d\n",
3310Sstevel@tonic-gate 		    file, sblock.fs_version);
3320Sstevel@tonic-gate 		nerror++;
3330Sstevel@tonic-gate 		return;
3340Sstevel@tonic-gate 	}
3350Sstevel@tonic-gate 
3360Sstevel@tonic-gate 	/* If fs is logged, roll the log. */
3370Sstevel@tonic-gate 	if (sblock.fs_logbno) {
3380Sstevel@tonic-gate 		switch (rl_roll_log(file)) {
3390Sstevel@tonic-gate 		case RL_SUCCESS:
3400Sstevel@tonic-gate 			/*
3410Sstevel@tonic-gate 			 * Reread the superblock.  Rolling the log may have
3420Sstevel@tonic-gate 			 * changed it.
3430Sstevel@tonic-gate 			 */
3440Sstevel@tonic-gate 			bread(SBLOCK, (char *)&sblock, SBSIZE);
3450Sstevel@tonic-gate 			break;
3460Sstevel@tonic-gate 		case RL_SYSERR:
3470Sstevel@tonic-gate 			(void) printf("Warning: Cannot roll log for %s.  %s\n",
3480Sstevel@tonic-gate 				file, strerror(errno));
3490Sstevel@tonic-gate 			break;
3500Sstevel@tonic-gate 		default:
3510Sstevel@tonic-gate 			(void) printf("Warning: Cannot roll log for %s.\n ",
3520Sstevel@tonic-gate 				file);
3530Sstevel@tonic-gate 			break;
3540Sstevel@tonic-gate 		}
3550Sstevel@tonic-gate 	}
3560Sstevel@tonic-gate 
3570Sstevel@tonic-gate 
3580Sstevel@tonic-gate 	itab = (struct dinode *)calloc(sblock.fs_ipg, sizeof (struct dinode));
3590Sstevel@tonic-gate 	imax = sblock.fs_ncg * sblock.fs_ipg;
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 	hsize = sblock.fs_ipg * sblock.fs_ncg - sblock.fs_cstotal.cs_nifree + 1;
3620Sstevel@tonic-gate 	htab = (struct htab *)calloc(hsize, sizeof (struct htab));
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate 	if (!extend_strngtab(AVG_PATH_LEN * hsize)) {
3650Sstevel@tonic-gate 		(void) printf("not enough memory to allocate tables\n");
3660Sstevel@tonic-gate 		nerror++;
3670Sstevel@tonic-gate 		return;
3680Sstevel@tonic-gate 	}
3690Sstevel@tonic-gate 	strngloc = 0;
3700Sstevel@tonic-gate 
3710Sstevel@tonic-gate 	if ((itab == NULL) || (htab == NULL)) {
3720Sstevel@tonic-gate 		(void) printf("not enough memory to allocate tables\n");
3730Sstevel@tonic-gate 		nerror++;
3740Sstevel@tonic-gate 		return;
3750Sstevel@tonic-gate 	}
3760Sstevel@tonic-gate 	ino = 0;
3770Sstevel@tonic-gate 	for (c = 0; c < sblock.fs_ncg; c++) {
3780Sstevel@tonic-gate 		bread(fsbtodb(&sblock, cgimin(&sblock, c)), (char *)itab,
3790Sstevel@tonic-gate 		    (int)(sblock.fs_ipg * sizeof (struct dinode)));
3800Sstevel@tonic-gate 		for (j = 0; j < sblock.fs_ipg; j++) {
3810Sstevel@tonic-gate 			if (itab[j].di_smode != 0) {
3820Sstevel@tonic-gate 				itab[j].di_mode = itab[j].di_smode;
3830Sstevel@tonic-gate 				if (itab[j].di_suid != (o_uid_t)UID_LONG)
3840Sstevel@tonic-gate 				itab[j].di_uid = (unsigned int)itab[j].di_suid;
3850Sstevel@tonic-gate 				if (itab[j].di_sgid != GID_LONG)
3860Sstevel@tonic-gate 				itab[j].di_gid = (unsigned int)itab[j].di_sgid;
3870Sstevel@tonic-gate 				pass1(&itab[j]);
3880Sstevel@tonic-gate 			}
3890Sstevel@tonic-gate 			ino++;
3900Sstevel@tonic-gate 		}
3910Sstevel@tonic-gate 	}
3920Sstevel@tonic-gate 	ilist[nxfile+1].ino = 0;
3930Sstevel@tonic-gate 	ino = 0;
3940Sstevel@tonic-gate 	for (c = 0; c < sblock.fs_ncg; c++) {
3950Sstevel@tonic-gate 		bread(fsbtodb(&sblock, cgimin(&sblock, c)), (char *)itab,
3960Sstevel@tonic-gate 		    (int)(sblock.fs_ipg * sizeof (struct dinode)));
3970Sstevel@tonic-gate 		for (j = 0; j < sblock.fs_ipg; j++) {
3980Sstevel@tonic-gate 			if (itab[j].di_smode != 0) {
3990Sstevel@tonic-gate 				itab[j].di_mode = itab[j].di_smode;
4000Sstevel@tonic-gate 				pass2(&itab[j]);
4010Sstevel@tonic-gate 			}
4020Sstevel@tonic-gate 			ino++;
4030Sstevel@tonic-gate 		}
4040Sstevel@tonic-gate 	}
4050Sstevel@tonic-gate 	ino = 0;
4060Sstevel@tonic-gate 	for (c = 0; c < sblock.fs_ncg; c++) {
4070Sstevel@tonic-gate 		bread(fsbtodb(&sblock, cgimin(&sblock, c)), (char *)itab,
4080Sstevel@tonic-gate 		    (int)(sblock.fs_ipg * sizeof (struct dinode)));
4090Sstevel@tonic-gate 		for (j = 0; j < sblock.fs_ipg; j++) {
4100Sstevel@tonic-gate 			if (itab[j].di_smode != 0) {
4110Sstevel@tonic-gate 				itab[j].di_mode = itab[j].di_smode;
4120Sstevel@tonic-gate 				pass3(&itab[j]);
4130Sstevel@tonic-gate 			}
4140Sstevel@tonic-gate 			ino++;
4150Sstevel@tonic-gate 		}
4160Sstevel@tonic-gate 	}
4170Sstevel@tonic-gate 	(void) close(fi);
4180Sstevel@tonic-gate 	for (i = iflg; i < NB; i++)
4190Sstevel@tonic-gate 		ilist[i].ino = 0;
4200Sstevel@tonic-gate 	nxfile = iflg;
4210Sstevel@tonic-gate 	free(itab);
4220Sstevel@tonic-gate 	free(htab);
4230Sstevel@tonic-gate 	free(strngtab);
4240Sstevel@tonic-gate }
4250Sstevel@tonic-gate 
4260Sstevel@tonic-gate void
pass1(struct dinode * ip)4270Sstevel@tonic-gate pass1(struct dinode *ip)
4280Sstevel@tonic-gate {
4290Sstevel@tonic-gate 	int i;
4300Sstevel@tonic-gate 
4310Sstevel@tonic-gate 	if (mflg)
4320Sstevel@tonic-gate 		for (i = 0; i < iflg; i++)
4330Sstevel@tonic-gate 			if (ino == ilist[i].ino) {
4340Sstevel@tonic-gate 				ilist[i].mode = ip->di_mode;
4350Sstevel@tonic-gate 				ilist[i].uid = ip->di_uid;
4360Sstevel@tonic-gate 				ilist[i].gid = ip->di_gid;
4370Sstevel@tonic-gate 			}
4380Sstevel@tonic-gate 	if ((ip->di_mode & IFMT) != IFDIR) {
4390Sstevel@tonic-gate 		if (sflg == 0 || nxfile >= NB)
4400Sstevel@tonic-gate 			return;
4410Sstevel@tonic-gate 		if ((ip->di_mode&IFMT) == IFBLK ||
4420Sstevel@tonic-gate 		    (ip->di_mode&IFMT) == IFCHR || ip->di_mode&(ISUID|ISGID)) {
4430Sstevel@tonic-gate 			ilist[nxfile].ino = ino;
4440Sstevel@tonic-gate 			ilist[nxfile].mode = ip->di_mode;
4450Sstevel@tonic-gate 			ilist[nxfile].uid = ip->di_uid;
4460Sstevel@tonic-gate 			ilist[nxfile++].gid = ip->di_gid;
4470Sstevel@tonic-gate 			return;
4480Sstevel@tonic-gate 		}
4490Sstevel@tonic-gate 	}
4500Sstevel@tonic-gate 	(void) lookup(ino, 1);
4510Sstevel@tonic-gate }
4520Sstevel@tonic-gate 
4530Sstevel@tonic-gate void
pass2(struct dinode * ip)4540Sstevel@tonic-gate pass2(struct dinode *ip)
4550Sstevel@tonic-gate {
456*1051Smaheshvs 	struct direct *dp;
4570Sstevel@tonic-gate 	struct dirstuff dirp;
4580Sstevel@tonic-gate 	struct htab *hp;
4590Sstevel@tonic-gate 
4600Sstevel@tonic-gate 	if ((ip->di_mode&IFMT) != IFDIR)
4610Sstevel@tonic-gate 		return;
4620Sstevel@tonic-gate 	dirp.loc = 0;
4630Sstevel@tonic-gate 	dirp.ip = ip;
4640Sstevel@tonic-gate 	gip = ip;
4650Sstevel@tonic-gate 	for (dp = dreaddir(&dirp); dp != NULL; dp = dreaddir(&dirp)) {
4660Sstevel@tonic-gate 		int nmlen;
4670Sstevel@tonic-gate 
4680Sstevel@tonic-gate 		if (dp->d_ino == 0)
4690Sstevel@tonic-gate 			continue;
4700Sstevel@tonic-gate 		hp = lookup(dp->d_ino, 0);
4710Sstevel@tonic-gate 		if (hp == 0)
4720Sstevel@tonic-gate 			continue;
4730Sstevel@tonic-gate 		if (dotname(dp))
4740Sstevel@tonic-gate 			continue;
4750Sstevel@tonic-gate 		hp->h_pino = ino;
4760Sstevel@tonic-gate 		nmlen = strlen(dp->d_name);
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 		if (strngloc + nmlen + 1 > MAX_STRNGTAB_INDEX()) {
4790Sstevel@tonic-gate 			if (!extend_strngtab(STRNGTAB_INCR)) {
4800Sstevel@tonic-gate 				perror("ncheck: can't grow string table\n");
4810Sstevel@tonic-gate 				exit(32);
4820Sstevel@tonic-gate 			}
4830Sstevel@tonic-gate 		}
4840Sstevel@tonic-gate 
4850Sstevel@tonic-gate 		hp->h_name_index = strngloc;
4860Sstevel@tonic-gate 		(void) strcpy(&strngtab[strngloc], dp->d_name);
4870Sstevel@tonic-gate 		strngloc += nmlen + 1;
4880Sstevel@tonic-gate 	}
4890Sstevel@tonic-gate }
4900Sstevel@tonic-gate 
4910Sstevel@tonic-gate void
pass3(struct dinode * ip)4920Sstevel@tonic-gate pass3(struct dinode *ip)
4930Sstevel@tonic-gate {
494*1051Smaheshvs 	struct direct *dp;
4950Sstevel@tonic-gate 	struct dirstuff dirp;
4960Sstevel@tonic-gate 	struct dinode   *dip;
4970Sstevel@tonic-gate 	int k;
4980Sstevel@tonic-gate 
4990Sstevel@tonic-gate 	if ((ip->di_mode&IFMT) != IFDIR)
5000Sstevel@tonic-gate 		return;
5010Sstevel@tonic-gate 	dirp.loc = 0;
5020Sstevel@tonic-gate 	dirp.ip = ip;
5030Sstevel@tonic-gate 	gip = ip;
5040Sstevel@tonic-gate 	for (dp = dreaddir(&dirp); dp != NULL; dp = dreaddir(&dirp)) {
5050Sstevel@tonic-gate 		if (aflg == 0 && dotname(dp))
5060Sstevel@tonic-gate 			continue;
5070Sstevel@tonic-gate 		if (sflg == 0 && iflg == 0)
5080Sstevel@tonic-gate 			goto pr;
5090Sstevel@tonic-gate 		for (k = 0; ilist[k].ino != 0; k++)
5100Sstevel@tonic-gate 			if (ilist[k].ino == dp->d_ino)
5110Sstevel@tonic-gate 				break;
5120Sstevel@tonic-gate 		if (ilist[k].ino == 0)
5130Sstevel@tonic-gate 			continue;
5140Sstevel@tonic-gate 		if (mflg)
5150Sstevel@tonic-gate 			(void) printf("mode %-6o uid %-5ld gid %-5ld ino ",
5160Sstevel@tonic-gate 			    ilist[k].mode, ilist[k].uid, ilist[k].gid);
5170Sstevel@tonic-gate 	pr:
5180Sstevel@tonic-gate 		if (Sflg || uflg || Aflg || Mflg || Cflg || Nflg || Lflg)
5190Sstevel@tonic-gate 			dip = ginode(dp->d_ino);
5200Sstevel@tonic-gate 		if ((!Aflg ||
5210Sstevel@tonic-gate 		cmp((Today - dip->di_un.di_icom.ic_atime)/DAY, Adelay,
5220Sstevel@tonic-gate 		    Asign)) &&
5230Sstevel@tonic-gate 		    (!Mflg || cmp((Today - dip->di_un.di_icom.ic_mtime)/DAY,
5240Sstevel@tonic-gate 			Mdelay, Msign)) &&
5250Sstevel@tonic-gate 		    (!Cflg || cmp((Today - dip->di_un.di_icom.ic_mtime)/DAY,
5260Sstevel@tonic-gate 			Cdelay, Csign)) &&
5270Sstevel@tonic-gate 		    (!Nflg || cmp(dip->di_un.di_icom.ic_mtime, Nage, '+'))) {
5280Sstevel@tonic-gate 			if (Iflg == 0)
5290Sstevel@tonic-gate 				(void) printf("%-5u\t", dp->d_ino);
5300Sstevel@tonic-gate 			pname(stdout, ino, 0);
5310Sstevel@tonic-gate 			(void) printf("/%s", dp->d_name);
5320Sstevel@tonic-gate 			if (lookup(dp->d_ino, 0))
5330Sstevel@tonic-gate 				(void) printf("/.");
5340Sstevel@tonic-gate 			if (Sflg)
5350Sstevel@tonic-gate 				(void) printf("\t%6lld",
5360Sstevel@tonic-gate 				    dip->di_un.di_icom.ic_lsize);
5370Sstevel@tonic-gate 			if (uflg)
5380Sstevel@tonic-gate 				(void) printf("\t%s",
5390Sstevel@tonic-gate 				    user_name(dip->di_un.di_icom.ic_uid));
5400Sstevel@tonic-gate 			(void) printf("\n");
5410Sstevel@tonic-gate 			if (Lflg && (dip->di_un.di_icom.ic_nlink > 1)) {
5420Sstevel@tonic-gate 				(void) fprintf(Lfile, "%-5u\t",
5430Sstevel@tonic-gate 					dp->d_ino);
5440Sstevel@tonic-gate 				(void) fprintf(Lfile, "%-5u\t",
5450Sstevel@tonic-gate 					dip->di_un.di_icom.ic_nlink);
5460Sstevel@tonic-gate 				pname(Lfile, ino, 0);
5470Sstevel@tonic-gate 				(void) fprintf(Lfile, "/%s\n", dp->d_name);
5480Sstevel@tonic-gate 			}
5490Sstevel@tonic-gate 		}
5500Sstevel@tonic-gate 	}
5510Sstevel@tonic-gate }
5520Sstevel@tonic-gate 
5530Sstevel@tonic-gate 
5540Sstevel@tonic-gate 
5550Sstevel@tonic-gate /*
5560Sstevel@tonic-gate  * get next entry in a directory.
5570Sstevel@tonic-gate  */
5580Sstevel@tonic-gate struct direct *
dreaddir(struct dirstuff * dirp)5590Sstevel@tonic-gate dreaddir(struct dirstuff *dirp)
5600Sstevel@tonic-gate {
561*1051Smaheshvs 	struct direct *dp;
5620Sstevel@tonic-gate 	diskaddr_t lbn, d;
5630Sstevel@tonic-gate 
5640Sstevel@tonic-gate 	for (;;) {
5650Sstevel@tonic-gate 		if (dirp->loc >= (int)dirp->ip->di_size)
5660Sstevel@tonic-gate 			return (NULL);
5670Sstevel@tonic-gate 		if (blkoff(&sblock, dirp->loc) == 0) {
5680Sstevel@tonic-gate 			lbn = lblkno(&sblock, dirp->loc);
5690Sstevel@tonic-gate 			d = bmap(lbn);
5700Sstevel@tonic-gate 			if (d == 0)
5710Sstevel@tonic-gate 				return (NULL);
5720Sstevel@tonic-gate 			bread(fsbtodb(&sblock, d), dirp->dbuf,
5730Sstevel@tonic-gate 			    (int)dblksize(&sblock, dirp->ip, (int)lbn));
5740Sstevel@tonic-gate 		}
5750Sstevel@tonic-gate 		dp = (struct direct *)
5760Sstevel@tonic-gate 		    (dirp->dbuf + blkoff(&sblock, dirp->loc));
5770Sstevel@tonic-gate 		dirp->loc += dp->d_reclen;
5780Sstevel@tonic-gate 		if (dp->d_ino == 0)
5790Sstevel@tonic-gate 			continue;
5800Sstevel@tonic-gate 		return (dp);
5810Sstevel@tonic-gate 	}
5820Sstevel@tonic-gate }
5830Sstevel@tonic-gate 
5840Sstevel@tonic-gate int
dotname(struct direct * dp)5850Sstevel@tonic-gate dotname(struct direct *dp)
5860Sstevel@tonic-gate {
5870Sstevel@tonic-gate 
5880Sstevel@tonic-gate 	if (dp->d_name[0] == '.')
5890Sstevel@tonic-gate 		if (dp->d_name[1] == 0 ||
5900Sstevel@tonic-gate 		    (dp->d_name[1] == '.' && dp->d_name[2] == 0))
5910Sstevel@tonic-gate 			return (1);
5920Sstevel@tonic-gate 	return (0);
5930Sstevel@tonic-gate }
5940Sstevel@tonic-gate 
5950Sstevel@tonic-gate void
pname(FILE * stream,ino_t i,int lev)5960Sstevel@tonic-gate pname(FILE *stream, ino_t i, int lev)
5970Sstevel@tonic-gate {
598*1051Smaheshvs 	struct htab *hp;
5990Sstevel@tonic-gate 
6000Sstevel@tonic-gate 	if (i == UFSROOTINO)
6010Sstevel@tonic-gate 		return;
6020Sstevel@tonic-gate 	if ((hp = lookup(i, 0)) == 0) {
6030Sstevel@tonic-gate 		(void) fprintf(stream, "???");
6040Sstevel@tonic-gate 		return;
6050Sstevel@tonic-gate 	}
6060Sstevel@tonic-gate 	if (lev > 10) {
6070Sstevel@tonic-gate 		(void) fprintf(stream, "...");
6080Sstevel@tonic-gate 		return;
6090Sstevel@tonic-gate 	}
6100Sstevel@tonic-gate 	pname(stream, hp->h_pino, ++lev);
6110Sstevel@tonic-gate 	if (pflg)
6120Sstevel@tonic-gate 		(void) fprintf(stream, "%s/%s", prefix,
6130Sstevel@tonic-gate 			&(strngtab[hp->h_name_index]));
6140Sstevel@tonic-gate 	else
6150Sstevel@tonic-gate 		(void) fprintf(stream, "/%s",
6160Sstevel@tonic-gate 			&(strngtab[hp->h_name_index]));
6170Sstevel@tonic-gate }
6180Sstevel@tonic-gate 
6190Sstevel@tonic-gate struct htab *
lookup(ino_t i,int ef)6200Sstevel@tonic-gate lookup(ino_t i, int ef)
6210Sstevel@tonic-gate {
622*1051Smaheshvs 	struct htab *hp;
6230Sstevel@tonic-gate 
6240Sstevel@tonic-gate 	for (hp = &htab[(int)i%hsize]; hp->h_ino; ) {
6250Sstevel@tonic-gate 		if (hp->h_ino == i)
6260Sstevel@tonic-gate 			return (hp);
6270Sstevel@tonic-gate 		if (++hp >= &htab[hsize])
6280Sstevel@tonic-gate 			hp = htab;
6290Sstevel@tonic-gate 	}
6300Sstevel@tonic-gate 	if (ef == 0)
6310Sstevel@tonic-gate 		return (0);
6320Sstevel@tonic-gate 	if (++nhent >= hsize) {
6330Sstevel@tonic-gate 		(void) fprintf(stderr,
6340Sstevel@tonic-gate 		    "ff: hsize of %ld is too small\n", hsize);
6350Sstevel@tonic-gate 		exit(32);
6360Sstevel@tonic-gate 	}
6370Sstevel@tonic-gate 	hp->h_ino = i;
6380Sstevel@tonic-gate 	return (hp);
6390Sstevel@tonic-gate }
6400Sstevel@tonic-gate 
6410Sstevel@tonic-gate void
bread(diskaddr_t bno,char * buf,int cnt)6420Sstevel@tonic-gate bread(diskaddr_t bno, char *buf, int cnt)
6430Sstevel@tonic-gate {
644*1051Smaheshvs 	int i;
6450Sstevel@tonic-gate 	int got;
6460Sstevel@tonic-gate 	offset_t offset;
6470Sstevel@tonic-gate 
6480Sstevel@tonic-gate 	offset = (offset_t)bno * DEV_BSIZE;
6490Sstevel@tonic-gate 	if (llseek(fi, offset, 0) == (offset_t)-1) {
6500Sstevel@tonic-gate 		(void) fprintf(stderr,
6510Sstevel@tonic-gate 		    "ff: llseek error %lx %lx\n",
6520Sstevel@tonic-gate 		    ((long *)&offset)[0], ((long *)&offset)[1]);
6530Sstevel@tonic-gate 		for (i = 0; i < cnt; i++)
6540Sstevel@tonic-gate 			buf[i] = 0;
6550Sstevel@tonic-gate 		return;
6560Sstevel@tonic-gate 	}
6570Sstevel@tonic-gate 
6580Sstevel@tonic-gate 	got = read((int)fi, buf, cnt);
6590Sstevel@tonic-gate 	if (got != cnt) {
6600Sstevel@tonic-gate 		perror("read");
6610Sstevel@tonic-gate 		(void) fprintf(stderr,
6620Sstevel@tonic-gate 			"ff: (wanted %d got %d blk %lld)\n", cnt, got, bno);
6630Sstevel@tonic-gate 		for (i = 0; i < cnt; i++)
6640Sstevel@tonic-gate 			buf[i] = 0;
6650Sstevel@tonic-gate 	}
6660Sstevel@tonic-gate }
6670Sstevel@tonic-gate 
6680Sstevel@tonic-gate diskaddr_t
bmap(diskaddr_t i)6690Sstevel@tonic-gate bmap(diskaddr_t i)
6700Sstevel@tonic-gate {
6710Sstevel@tonic-gate 	daddr32_t ibuf[MAXNINDIR];
6720Sstevel@tonic-gate 
6730Sstevel@tonic-gate 	if (i < NDADDR)
6740Sstevel@tonic-gate 		return ((diskaddr_t)gip->di_db[i]);
6750Sstevel@tonic-gate 	i -= NDADDR;
6760Sstevel@tonic-gate 	if (i > NINDIR(&sblock)) {
6770Sstevel@tonic-gate 		(void) fprintf(stderr, "ff    : %lu - huge directory\n", ino);
6780Sstevel@tonic-gate 		return ((diskaddr_t)0);
6790Sstevel@tonic-gate 	}
6800Sstevel@tonic-gate 	bread(fsbtodb(&sblock, gip->di_ib[0]), (char *)ibuf, sizeof (ibuf));
6810Sstevel@tonic-gate 	return ((diskaddr_t)ibuf[i]);
6820Sstevel@tonic-gate }
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate struct dinode *
ginode(ino_t inumber)6850Sstevel@tonic-gate ginode(ino_t inumber)
6860Sstevel@tonic-gate {
6870Sstevel@tonic-gate 	diskaddr_t		iblk;
6880Sstevel@tonic-gate 	diskaddr_t		dblk;
6890Sstevel@tonic-gate 	int		ioff;
6900Sstevel@tonic-gate 	static diskaddr_t	curr_dblk;
6910Sstevel@tonic-gate 	static char	buf[MIN_PHYS_READ];
6920Sstevel@tonic-gate 	struct dinode	*ibuf;
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate 	if (inumber < UFSROOTINO || (int)inumber > imax) {
6950Sstevel@tonic-gate 		(void) fprintf(stderr,
6960Sstevel@tonic-gate 		    "bad inode number %ld to ginode\n", inumber);
6970Sstevel@tonic-gate 		exit(32);
6980Sstevel@tonic-gate 	}
6990Sstevel@tonic-gate 	iblk = itod(&sblock, (int)inumber);
7000Sstevel@tonic-gate 	dblk = fsbtodb(&sblock, iblk);
7010Sstevel@tonic-gate 	ioff = itoo(&sblock, (int)inumber);
7020Sstevel@tonic-gate 	if (dblk != curr_dblk) {
7030Sstevel@tonic-gate 		bread(dblk, &buf[0], sizeof (buf));
7040Sstevel@tonic-gate 		curr_dblk = dblk;
7050Sstevel@tonic-gate 		inode_reads++;
7060Sstevel@tonic-gate 	}
7070Sstevel@tonic-gate 	ibuf = (struct dinode *)&buf[0];
7080Sstevel@tonic-gate 	ibuf += ioff;
7090Sstevel@tonic-gate 	return (ibuf);
7100Sstevel@tonic-gate }
7110Sstevel@tonic-gate 
7120Sstevel@tonic-gate #define	HASHNAMESIZE 16
7130Sstevel@tonic-gate 
7140Sstevel@tonic-gate struct name_ent {
7150Sstevel@tonic-gate 	struct name_ent	*name_nxt;
7160Sstevel@tonic-gate 	int		name_uid;
7170Sstevel@tonic-gate 	char		*name_string;
7180Sstevel@tonic-gate };
7190Sstevel@tonic-gate struct name_ent *hashtable[HASHNAMESIZE];
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate char *
user_name(int uid)7220Sstevel@tonic-gate user_name(int uid)
7230Sstevel@tonic-gate {
7240Sstevel@tonic-gate 	int		h_index;
7250Sstevel@tonic-gate 	struct name_ent	*hp;
7260Sstevel@tonic-gate 	struct passwd	*pwent;
7270Sstevel@tonic-gate 
7280Sstevel@tonic-gate 	h_index = uid % HASHNAMESIZE;
7290Sstevel@tonic-gate 	for (hp = hashtable[h_index]; hp != NULL; hp = hp->name_nxt) {
7300Sstevel@tonic-gate 		if (hp->name_uid == uid) {
7310Sstevel@tonic-gate 			return (hp->name_string);
7320Sstevel@tonic-gate 		}
7330Sstevel@tonic-gate 	}
7340Sstevel@tonic-gate 	hp = (struct name_ent *)calloc(1, sizeof (struct name_ent));
7350Sstevel@tonic-gate 	hp->name_nxt = hashtable[h_index];
7360Sstevel@tonic-gate 	hp->name_uid = uid;
7370Sstevel@tonic-gate 	hashtable[h_index] = hp;
7380Sstevel@tonic-gate 	if ((pwent = getpwuid(uid)) == NULL) {
7390Sstevel@tonic-gate 		hp->name_string = "unknown";
7400Sstevel@tonic-gate 	} else {
7410Sstevel@tonic-gate 		hp->name_string = (char *)strdup(pwent->pw_name);
7420Sstevel@tonic-gate 	}
7430Sstevel@tonic-gate 	passwd_lookups++;
7440Sstevel@tonic-gate 
7450Sstevel@tonic-gate 	return (hp->name_string);
7460Sstevel@tonic-gate }
7470Sstevel@tonic-gate 
7480Sstevel@tonic-gate int
cmp(int a,int b,int s)7490Sstevel@tonic-gate cmp(int a, int b, int s)
7500Sstevel@tonic-gate {
7510Sstevel@tonic-gate 	if (s == '+')
7520Sstevel@tonic-gate 		return (a > b);
7530Sstevel@tonic-gate 	if (s == '-')
7540Sstevel@tonic-gate 		return (a < -(b));
7550Sstevel@tonic-gate 	return (a == b);
7560Sstevel@tonic-gate }
7570Sstevel@tonic-gate 
7580Sstevel@tonic-gate /*
7590Sstevel@tonic-gate  * We can't do this one by reading the disk directly, since there
7600Sstevel@tonic-gate  * is no guarantee that the file is even on a local disk.
7610Sstevel@tonic-gate  */
7620Sstevel@tonic-gate time_t
mod_time(char * file)7630Sstevel@tonic-gate mod_time(char *file)
7640Sstevel@tonic-gate {
7650Sstevel@tonic-gate 	struct stat64	stat_buf;
7660Sstevel@tonic-gate 
7670Sstevel@tonic-gate 	if (stat64(file, &stat_buf) < 0) {
7680Sstevel@tonic-gate 		(void) fprintf(stderr, "ff: can't stat '%s' - ignored\n", file);
7690Sstevel@tonic-gate 		return (0);
7700Sstevel@tonic-gate 	}
7710Sstevel@tonic-gate 	return (stat_buf.st_mtime);
7720Sstevel@tonic-gate }
7730Sstevel@tonic-gate 
7740Sstevel@tonic-gate void
out_multilinks()7750Sstevel@tonic-gate out_multilinks()
7760Sstevel@tonic-gate {
7770Sstevel@tonic-gate 	int	length;
7780Sstevel@tonic-gate 
7790Sstevel@tonic-gate 	if ((length = fseek(Lfile, 0L, 2)) < 0) {
7800Sstevel@tonic-gate 		perror("fseek");
7810Sstevel@tonic-gate 		exit(32);
7820Sstevel@tonic-gate 	} else
7830Sstevel@tonic-gate 		if ((length = ftell(Lfile)) > 0) {
7840Sstevel@tonic-gate 			(void) fprintf(stdout,
7850Sstevel@tonic-gate 			    "\nmultilink files\nIno\tLinks\tPathname\n\n");
7860Sstevel@tonic-gate 			rewind(Lfile);
7870Sstevel@tonic-gate 			while (length-- > 0)
7880Sstevel@tonic-gate 				(void) putc(getc(Lfile), stdout);
7890Sstevel@tonic-gate 		} else
7900Sstevel@tonic-gate 			(void) fprintf(stdout, "No multilink files\n");
7910Sstevel@tonic-gate 	(void) fclose(Lfile);
7920Sstevel@tonic-gate }
7930Sstevel@tonic-gate 
7940Sstevel@tonic-gate void
usage()7950Sstevel@tonic-gate usage()
7960Sstevel@tonic-gate {
7970Sstevel@tonic-gate 	(void) fprintf(stderr,
7980Sstevel@tonic-gate 	    "ufs usage: ff [-F ufs] [generic options] [-o a,m,s] special\n");
7990Sstevel@tonic-gate 	exit(32);
8000Sstevel@tonic-gate }
8010Sstevel@tonic-gate 
8020Sstevel@tonic-gate /*
8030Sstevel@tonic-gate  * Extend or create the string table.
8040Sstevel@tonic-gate  * Preserves contents.
8050Sstevel@tonic-gate  * Return non-zero for success.
8060Sstevel@tonic-gate  */
8070Sstevel@tonic-gate int
extend_strngtab(unsigned int size)8080Sstevel@tonic-gate extend_strngtab(unsigned int size)
8090Sstevel@tonic-gate {
8100Sstevel@tonic-gate 	strngtab_size += size;
8110Sstevel@tonic-gate 	strngtab = (char *)realloc(strngtab, strngtab_size);
8120Sstevel@tonic-gate 
8130Sstevel@tonic-gate 	return ((int)strngtab);
8140Sstevel@tonic-gate }
815