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 /* 226451fdbcSvsakar * 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) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ 277c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate /* 307c478bd9Sstevel@tonic-gate * Portions of this source code were derived from Berkeley 4.3 BSD 317c478bd9Sstevel@tonic-gate * under license from the Regents of the University of California. 327c478bd9Sstevel@tonic-gate */ 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate /* 377c478bd9Sstevel@tonic-gate * ff -- obtain file names from reading filesystem 387c478bd9Sstevel@tonic-gate */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #define NB 500 417c478bd9Sstevel@tonic-gate #define MAXNINDIR (MAXBSIZE / sizeof (daddr32_t)) 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #include <sys/param.h> 447c478bd9Sstevel@tonic-gate #include <sys/types.h> 457c478bd9Sstevel@tonic-gate #include <sys/mntent.h> 467c478bd9Sstevel@tonic-gate #include <sys/vnode.h> 477c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_inode.h> 487c478bd9Sstevel@tonic-gate #include <sys/stat.h> 497c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fs.h> 507c478bd9Sstevel@tonic-gate #include <sys/fs/ufs_fsdir.h> 517c478bd9Sstevel@tonic-gate #include <stdio.h> 527c478bd9Sstevel@tonic-gate #include <stdlib.h> 537c478bd9Sstevel@tonic-gate #include <strings.h> 547c478bd9Sstevel@tonic-gate #include <errno.h> 557c478bd9Sstevel@tonic-gate #include <fcntl.h> 567c478bd9Sstevel@tonic-gate #include <unistd.h> 577c478bd9Sstevel@tonic-gate #include <pwd.h> 587c478bd9Sstevel@tonic-gate #include "roll_log.h" 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate #define MIN_PHYS_READ BBSIZE 617c478bd9Sstevel@tonic-gate #define DAY (24*60*60) 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate union { 657c478bd9Sstevel@tonic-gate struct fs sblk; 667c478bd9Sstevel@tonic-gate char xxx[SBSIZE]; /* because fs is variable length */ 677c478bd9Sstevel@tonic-gate } real_fs; 687c478bd9Sstevel@tonic-gate #define sblock real_fs.sblk 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate struct dinode *itab; /* = (struct dinode *)itab; */ 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate struct dinode *gip; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate struct ilist { 757c478bd9Sstevel@tonic-gate ino_t ino; 767c478bd9Sstevel@tonic-gate ushort_t mode; 777c478bd9Sstevel@tonic-gate uid_t uid; 787c478bd9Sstevel@tonic-gate gid_t gid; 797c478bd9Sstevel@tonic-gate } ilist[NB]; 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate struct htab 827c478bd9Sstevel@tonic-gate { 837c478bd9Sstevel@tonic-gate ino_t h_ino; 847c478bd9Sstevel@tonic-gate ino_t h_pino; 857c478bd9Sstevel@tonic-gate int h_name_index; /* index into string table */ 867c478bd9Sstevel@tonic-gate } *htab; 877c478bd9Sstevel@tonic-gate char *strngtab; 887c478bd9Sstevel@tonic-gate long hsize; 897c478bd9Sstevel@tonic-gate int strngloc; 907c478bd9Sstevel@tonic-gate int strngtab_size; 917c478bd9Sstevel@tonic-gate #define STRNGTAB_INCR (1024*16) /* amount to grow strngtab */ 927c478bd9Sstevel@tonic-gate #define MAX_STRNGTAB_INDEX() (strngtab_size - 1) 937c478bd9Sstevel@tonic-gate #define AVG_PATH_LEN 30 /* average (?) length of name */ 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate struct dirstuff { 967c478bd9Sstevel@tonic-gate int loc; 977c478bd9Sstevel@tonic-gate struct dinode *ip; 987c478bd9Sstevel@tonic-gate char dbuf[MAXBSIZE]; 997c478bd9Sstevel@tonic-gate }; 1007c478bd9Sstevel@tonic-gate int Aflg = 0; /* accessed in n days */ 1017c478bd9Sstevel@tonic-gate int Mflg = 0; /* modified in n days */ 1027c478bd9Sstevel@tonic-gate int Nflg = 0; /* modified more recently than 'file' */ 1037c478bd9Sstevel@tonic-gate int Cflg = 0; /* changed within n days */ 1047c478bd9Sstevel@tonic-gate int aflg = 0; /* print the names `.' and `..' */ 1057c478bd9Sstevel@tonic-gate int sflg = 0; /* print only special files and files with set-user-ID mode */ 1067c478bd9Sstevel@tonic-gate int Sflg = 0; /* print file size */ 1077c478bd9Sstevel@tonic-gate int iflg = 0; /* number of inodes being searched for */ 1087c478bd9Sstevel@tonic-gate int Iflg = 0; /* do not print i-number */ 1097c478bd9Sstevel@tonic-gate int Lflg = 0; /* supplementary list of multiply linked files */ 1107c478bd9Sstevel@tonic-gate int mflg = 0; 1117c478bd9Sstevel@tonic-gate int pflg = 0; /* a prefix exists */ 1127c478bd9Sstevel@tonic-gate int uflg = 0; /* print the owner's login name */ 1137c478bd9Sstevel@tonic-gate int fi; 1147c478bd9Sstevel@tonic-gate ino_t ino; 1157c478bd9Sstevel@tonic-gate int nhent; 1167c478bd9Sstevel@tonic-gate int nxfile; 1177c478bd9Sstevel@tonic-gate int imax; /* highest inode number */ 1187c478bd9Sstevel@tonic-gate int inode_reads; 1197c478bd9Sstevel@tonic-gate int passwd_lookups; 1207c478bd9Sstevel@tonic-gate int Adelay; /* Access delay */ 1217c478bd9Sstevel@tonic-gate int Asign; /* Access sign */ 1227c478bd9Sstevel@tonic-gate int Mdelay; /* Modify delay */ 1237c478bd9Sstevel@tonic-gate int Msign; /* Modify sign */ 1247c478bd9Sstevel@tonic-gate int Cdelay; /* change delay */ 1257c478bd9Sstevel@tonic-gate int Csign; /* change sign */ 1267c478bd9Sstevel@tonic-gate time_t Nage; /* Last modification time of the file */ 1277c478bd9Sstevel@tonic-gate char *Lname; /* filename for supplementary list */ 1287c478bd9Sstevel@tonic-gate FILE *Lfile; /* file for supplementary list */ 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate /* 1317c478bd9Sstevel@tonic-gate * Function prototypes 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate void check(char *file); 1347c478bd9Sstevel@tonic-gate void pass1(struct dinode *ip); 1357c478bd9Sstevel@tonic-gate void pass2(struct dinode *ip); 1367c478bd9Sstevel@tonic-gate void pass3(struct dinode *ip); 1377c478bd9Sstevel@tonic-gate struct direct *dreaddir(struct dirstuff *dirp); 1387c478bd9Sstevel@tonic-gate int dotname(struct direct *dp); 1397c478bd9Sstevel@tonic-gate void pname(FILE *stream, ino_t i, int lev); 1407c478bd9Sstevel@tonic-gate struct htab *lookup(ino_t i, int ef); 1417c478bd9Sstevel@tonic-gate void bread(diskaddr_t bno, char *buf, int cnt); 1427c478bd9Sstevel@tonic-gate diskaddr_t bmap(diskaddr_t i); 1437c478bd9Sstevel@tonic-gate struct dinode *ginode(ino_t inumber); 1447c478bd9Sstevel@tonic-gate char *user_name(int uid); 1457c478bd9Sstevel@tonic-gate int cmp(int a, int b, int s); 1467c478bd9Sstevel@tonic-gate time_t mod_time(char *file); 1477c478bd9Sstevel@tonic-gate void out_multilinks(); 1487c478bd9Sstevel@tonic-gate void usage(); 1497c478bd9Sstevel@tonic-gate int extend_strngtab(unsigned int size); 1507c478bd9Sstevel@tonic-gate 1517c478bd9Sstevel@tonic-gate long atol(); 1527c478bd9Sstevel@tonic-gate offset_t llseek(); 1537c478bd9Sstevel@tonic-gate char *strcpy(); 1547c478bd9Sstevel@tonic-gate 1557c478bd9Sstevel@tonic-gate char *prefix; 1567c478bd9Sstevel@tonic-gate time_t Today; 1577c478bd9Sstevel@tonic-gate int nerror; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate extern int optind; 1617c478bd9Sstevel@tonic-gate extern char *optarg; 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate char *subopts [] = { 1647c478bd9Sstevel@tonic-gate #define A_FLAG 0 1657c478bd9Sstevel@tonic-gate "a", 1667c478bd9Sstevel@tonic-gate #define M_FLAG 1 1677c478bd9Sstevel@tonic-gate "m", 1687c478bd9Sstevel@tonic-gate #define S_FLAG 2 1697c478bd9Sstevel@tonic-gate "s", 1707c478bd9Sstevel@tonic-gate NULL 1717c478bd9Sstevel@tonic-gate }; 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate int 174*d1a180b0Smaheshvs main(int argc, char *argv[]) 1757c478bd9Sstevel@tonic-gate { 1767c478bd9Sstevel@tonic-gate long n; 1777c478bd9Sstevel@tonic-gate int opt; 1787c478bd9Sstevel@tonic-gate char *suboptions, *value; 1797c478bd9Sstevel@tonic-gate char *p; 1807c478bd9Sstevel@tonic-gate int first = 0; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate Today = time((time_t *)0); 1837c478bd9Sstevel@tonic-gate while ((opt = getopt(argc, argv, "Ia:c:i:lm:n:o:p:su")) != EOF) { 1847c478bd9Sstevel@tonic-gate switch (opt) { 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate case 'a': 1877c478bd9Sstevel@tonic-gate Aflg++; 1887c478bd9Sstevel@tonic-gate Adelay = atoi(optarg); 1897c478bd9Sstevel@tonic-gate Asign = optarg[0]; 1907c478bd9Sstevel@tonic-gate break; 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate case 'I': 1937c478bd9Sstevel@tonic-gate Iflg++; 1947c478bd9Sstevel@tonic-gate break; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate case 'c': 1977c478bd9Sstevel@tonic-gate Cflg++; 1987c478bd9Sstevel@tonic-gate Cdelay = atoi(optarg); 1997c478bd9Sstevel@tonic-gate Csign = optarg[0]; 2007c478bd9Sstevel@tonic-gate break; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate case 'l': 2037c478bd9Sstevel@tonic-gate Lflg++; 2047c478bd9Sstevel@tonic-gate Lname = tmpnam((char *)0); 2057c478bd9Sstevel@tonic-gate if ((Lfile = fopen(Lname, "w+")) == NULL) { 2067c478bd9Sstevel@tonic-gate perror("open"); 2077c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 2087c478bd9Sstevel@tonic-gate "ff: unable to open temp file, -l ignored\n"); 2097c478bd9Sstevel@tonic-gate Lflg = 0; 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate break; 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate case 'm': 2147c478bd9Sstevel@tonic-gate Mflg++; 2157c478bd9Sstevel@tonic-gate Mdelay = atoi(optarg); 2167c478bd9Sstevel@tonic-gate Msign = optarg[0]; 2177c478bd9Sstevel@tonic-gate break; 2187c478bd9Sstevel@tonic-gate 2197c478bd9Sstevel@tonic-gate case 'n': 2207c478bd9Sstevel@tonic-gate Nflg++; 2217c478bd9Sstevel@tonic-gate Nage = mod_time(optarg); 2227c478bd9Sstevel@tonic-gate break; 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate case 'o': 2257c478bd9Sstevel@tonic-gate /* 2267c478bd9Sstevel@tonic-gate * ufs specific options. 2277c478bd9Sstevel@tonic-gate */ 2287c478bd9Sstevel@tonic-gate suboptions = optarg; 2297c478bd9Sstevel@tonic-gate 2307c478bd9Sstevel@tonic-gate if (*suboptions == '\0') 2317c478bd9Sstevel@tonic-gate usage(); 2327c478bd9Sstevel@tonic-gate while (*suboptions != '\0') { 2337c478bd9Sstevel@tonic-gate switch ((getsubopt(&suboptions, 2347c478bd9Sstevel@tonic-gate subopts, &value))) { 2357c478bd9Sstevel@tonic-gate 2367c478bd9Sstevel@tonic-gate case A_FLAG: 2377c478bd9Sstevel@tonic-gate aflg++; 2387c478bd9Sstevel@tonic-gate break; 2397c478bd9Sstevel@tonic-gate 2407c478bd9Sstevel@tonic-gate case M_FLAG: 2417c478bd9Sstevel@tonic-gate mflg++; 2427c478bd9Sstevel@tonic-gate break; 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate case S_FLAG: 2457c478bd9Sstevel@tonic-gate sflg++; 2467c478bd9Sstevel@tonic-gate break; 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate default: 2497c478bd9Sstevel@tonic-gate usage(); 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate break; 2537c478bd9Sstevel@tonic-gate 2547c478bd9Sstevel@tonic-gate case 'i': 2557c478bd9Sstevel@tonic-gate while ((p = (char *)strtok(((first++ == 0) ? 2567c478bd9Sstevel@tonic-gate optarg: ((char *)0)), ", ")) != NULL) { 2577c478bd9Sstevel@tonic-gate if ((n = atoi(p)) == 0) 2587c478bd9Sstevel@tonic-gate break; 2597c478bd9Sstevel@tonic-gate ilist[iflg].ino = n; 2607c478bd9Sstevel@tonic-gate nxfile = iflg; 2617c478bd9Sstevel@tonic-gate iflg++; 2627c478bd9Sstevel@tonic-gate } 2637c478bd9Sstevel@tonic-gate break; 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate case 'p': 2667c478bd9Sstevel@tonic-gate prefix = optarg; 2677c478bd9Sstevel@tonic-gate pflg++; 2687c478bd9Sstevel@tonic-gate break; 2697c478bd9Sstevel@tonic-gate 2707c478bd9Sstevel@tonic-gate case 's': 2717c478bd9Sstevel@tonic-gate Sflg++; 2727c478bd9Sstevel@tonic-gate break; 2737c478bd9Sstevel@tonic-gate 2747c478bd9Sstevel@tonic-gate case 'u': 2757c478bd9Sstevel@tonic-gate uflg++; 2767c478bd9Sstevel@tonic-gate break; 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate case '?': 2797c478bd9Sstevel@tonic-gate usage(); 2807c478bd9Sstevel@tonic-gate } 2817c478bd9Sstevel@tonic-gate } 2827c478bd9Sstevel@tonic-gate argc -= optind; 2837c478bd9Sstevel@tonic-gate argv = &argv[optind]; 2847c478bd9Sstevel@tonic-gate while (argc--) { 2857c478bd9Sstevel@tonic-gate check(*argv); 2867c478bd9Sstevel@tonic-gate argv++; 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate if (Lflg) { 2897c478bd9Sstevel@tonic-gate out_multilinks(); 2907c478bd9Sstevel@tonic-gate } 2917c478bd9Sstevel@tonic-gate if (nerror) 2927c478bd9Sstevel@tonic-gate return (32); 2937c478bd9Sstevel@tonic-gate return (0); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate void 2977c478bd9Sstevel@tonic-gate check(char *file) 2987c478bd9Sstevel@tonic-gate { 299*d1a180b0Smaheshvs int i, j, c; 3007c478bd9Sstevel@tonic-gate 3017c478bd9Sstevel@tonic-gate fi = open64(file, 0); 3027c478bd9Sstevel@tonic-gate if (fi < 0) { 3037c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "ff: cannot open %s\n", file); 3047c478bd9Sstevel@tonic-gate nerror++; 3057c478bd9Sstevel@tonic-gate return; 3067c478bd9Sstevel@tonic-gate } 3077c478bd9Sstevel@tonic-gate nhent = 0; 3087c478bd9Sstevel@tonic-gate (void) printf("%s:\n", file); 3097c478bd9Sstevel@tonic-gate sync(); 3107c478bd9Sstevel@tonic-gate bread(SBLOCK, (char *)&sblock, SBSIZE); 3117c478bd9Sstevel@tonic-gate if ((sblock.fs_magic != FS_MAGIC) && 3127c478bd9Sstevel@tonic-gate (sblock.fs_magic != MTB_UFS_MAGIC)) { 3137c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: not a ufs file system\n", file); 3147c478bd9Sstevel@tonic-gate nerror++; 3157c478bd9Sstevel@tonic-gate return; 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate 3186451fdbcSvsakar if (sblock.fs_magic == FS_MAGIC && 3196451fdbcSvsakar (sblock.fs_version != UFS_EFISTYLE4NONEFI_VERSION_2 && 3206451fdbcSvsakar sblock.fs_version != UFS_VERSION_MIN)) { 3216451fdbcSvsakar (void) fprintf(stderr, "%s: unrecognized version of UFS: %d\n", 3226451fdbcSvsakar file, sblock.fs_version); 3236451fdbcSvsakar nerror++; 3246451fdbcSvsakar return; 3256451fdbcSvsakar } 3266451fdbcSvsakar 3277c478bd9Sstevel@tonic-gate if (sblock.fs_magic == MTB_UFS_MAGIC && 3287c478bd9Sstevel@tonic-gate (sblock.fs_version > MTB_UFS_VERSION_1 || 3297c478bd9Sstevel@tonic-gate sblock.fs_version < MTB_UFS_VERSION_MIN)) { 3307c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "%s: unrecognized version of UFS: %d\n", 3317c478bd9Sstevel@tonic-gate file, sblock.fs_version); 3327c478bd9Sstevel@tonic-gate nerror++; 3337c478bd9Sstevel@tonic-gate return; 3347c478bd9Sstevel@tonic-gate } 3357c478bd9Sstevel@tonic-gate 3367c478bd9Sstevel@tonic-gate /* If fs is logged, roll the log. */ 3377c478bd9Sstevel@tonic-gate if (sblock.fs_logbno) { 3387c478bd9Sstevel@tonic-gate switch (rl_roll_log(file)) { 3397c478bd9Sstevel@tonic-gate case RL_SUCCESS: 3407c478bd9Sstevel@tonic-gate /* 3417c478bd9Sstevel@tonic-gate * Reread the superblock. Rolling the log may have 3427c478bd9Sstevel@tonic-gate * changed it. 3437c478bd9Sstevel@tonic-gate */ 3447c478bd9Sstevel@tonic-gate bread(SBLOCK, (char *)&sblock, SBSIZE); 3457c478bd9Sstevel@tonic-gate break; 3467c478bd9Sstevel@tonic-gate case RL_SYSERR: 3477c478bd9Sstevel@tonic-gate (void) printf("Warning: Cannot roll log for %s. %s\n", 3487c478bd9Sstevel@tonic-gate file, strerror(errno)); 3497c478bd9Sstevel@tonic-gate break; 3507c478bd9Sstevel@tonic-gate default: 3517c478bd9Sstevel@tonic-gate (void) printf("Warning: Cannot roll log for %s.\n ", 3527c478bd9Sstevel@tonic-gate file); 3537c478bd9Sstevel@tonic-gate break; 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate } 3567c478bd9Sstevel@tonic-gate 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate itab = (struct dinode *)calloc(sblock.fs_ipg, sizeof (struct dinode)); 3597c478bd9Sstevel@tonic-gate imax = sblock.fs_ncg * sblock.fs_ipg; 3607c478bd9Sstevel@tonic-gate 3617c478bd9Sstevel@tonic-gate hsize = sblock.fs_ipg * sblock.fs_ncg - sblock.fs_cstotal.cs_nifree + 1; 3627c478bd9Sstevel@tonic-gate htab = (struct htab *)calloc(hsize, sizeof (struct htab)); 3637c478bd9Sstevel@tonic-gate 3647c478bd9Sstevel@tonic-gate if (!extend_strngtab(AVG_PATH_LEN * hsize)) { 3657c478bd9Sstevel@tonic-gate (void) printf("not enough memory to allocate tables\n"); 3667c478bd9Sstevel@tonic-gate nerror++; 3677c478bd9Sstevel@tonic-gate return; 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate strngloc = 0; 3707c478bd9Sstevel@tonic-gate 3717c478bd9Sstevel@tonic-gate if ((itab == NULL) || (htab == NULL)) { 3727c478bd9Sstevel@tonic-gate (void) printf("not enough memory to allocate tables\n"); 3737c478bd9Sstevel@tonic-gate nerror++; 3747c478bd9Sstevel@tonic-gate return; 3757c478bd9Sstevel@tonic-gate } 3767c478bd9Sstevel@tonic-gate ino = 0; 3777c478bd9Sstevel@tonic-gate for (c = 0; c < sblock.fs_ncg; c++) { 3787c478bd9Sstevel@tonic-gate bread(fsbtodb(&sblock, cgimin(&sblock, c)), (char *)itab, 3797c478bd9Sstevel@tonic-gate (int)(sblock.fs_ipg * sizeof (struct dinode))); 3807c478bd9Sstevel@tonic-gate for (j = 0; j < sblock.fs_ipg; j++) { 3817c478bd9Sstevel@tonic-gate if (itab[j].di_smode != 0) { 3827c478bd9Sstevel@tonic-gate itab[j].di_mode = itab[j].di_smode; 3837c478bd9Sstevel@tonic-gate if (itab[j].di_suid != (o_uid_t)UID_LONG) 3847c478bd9Sstevel@tonic-gate itab[j].di_uid = (unsigned int)itab[j].di_suid; 3857c478bd9Sstevel@tonic-gate if (itab[j].di_sgid != GID_LONG) 3867c478bd9Sstevel@tonic-gate itab[j].di_gid = (unsigned int)itab[j].di_sgid; 3877c478bd9Sstevel@tonic-gate pass1(&itab[j]); 3887c478bd9Sstevel@tonic-gate } 3897c478bd9Sstevel@tonic-gate ino++; 3907c478bd9Sstevel@tonic-gate } 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate ilist[nxfile+1].ino = 0; 3937c478bd9Sstevel@tonic-gate ino = 0; 3947c478bd9Sstevel@tonic-gate for (c = 0; c < sblock.fs_ncg; c++) { 3957c478bd9Sstevel@tonic-gate bread(fsbtodb(&sblock, cgimin(&sblock, c)), (char *)itab, 3967c478bd9Sstevel@tonic-gate (int)(sblock.fs_ipg * sizeof (struct dinode))); 3977c478bd9Sstevel@tonic-gate for (j = 0; j < sblock.fs_ipg; j++) { 3987c478bd9Sstevel@tonic-gate if (itab[j].di_smode != 0) { 3997c478bd9Sstevel@tonic-gate itab[j].di_mode = itab[j].di_smode; 4007c478bd9Sstevel@tonic-gate pass2(&itab[j]); 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate ino++; 4037c478bd9Sstevel@tonic-gate } 4047c478bd9Sstevel@tonic-gate } 4057c478bd9Sstevel@tonic-gate ino = 0; 4067c478bd9Sstevel@tonic-gate for (c = 0; c < sblock.fs_ncg; c++) { 4077c478bd9Sstevel@tonic-gate bread(fsbtodb(&sblock, cgimin(&sblock, c)), (char *)itab, 4087c478bd9Sstevel@tonic-gate (int)(sblock.fs_ipg * sizeof (struct dinode))); 4097c478bd9Sstevel@tonic-gate for (j = 0; j < sblock.fs_ipg; j++) { 4107c478bd9Sstevel@tonic-gate if (itab[j].di_smode != 0) { 4117c478bd9Sstevel@tonic-gate itab[j].di_mode = itab[j].di_smode; 4127c478bd9Sstevel@tonic-gate pass3(&itab[j]); 4137c478bd9Sstevel@tonic-gate } 4147c478bd9Sstevel@tonic-gate ino++; 4157c478bd9Sstevel@tonic-gate } 4167c478bd9Sstevel@tonic-gate } 4177c478bd9Sstevel@tonic-gate (void) close(fi); 4187c478bd9Sstevel@tonic-gate for (i = iflg; i < NB; i++) 4197c478bd9Sstevel@tonic-gate ilist[i].ino = 0; 4207c478bd9Sstevel@tonic-gate nxfile = iflg; 4217c478bd9Sstevel@tonic-gate free(itab); 4227c478bd9Sstevel@tonic-gate free(htab); 4237c478bd9Sstevel@tonic-gate free(strngtab); 4247c478bd9Sstevel@tonic-gate } 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate void 4277c478bd9Sstevel@tonic-gate pass1(struct dinode *ip) 4287c478bd9Sstevel@tonic-gate { 4297c478bd9Sstevel@tonic-gate int i; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate if (mflg) 4327c478bd9Sstevel@tonic-gate for (i = 0; i < iflg; i++) 4337c478bd9Sstevel@tonic-gate if (ino == ilist[i].ino) { 4347c478bd9Sstevel@tonic-gate ilist[i].mode = ip->di_mode; 4357c478bd9Sstevel@tonic-gate ilist[i].uid = ip->di_uid; 4367c478bd9Sstevel@tonic-gate ilist[i].gid = ip->di_gid; 4377c478bd9Sstevel@tonic-gate } 4387c478bd9Sstevel@tonic-gate if ((ip->di_mode & IFMT) != IFDIR) { 4397c478bd9Sstevel@tonic-gate if (sflg == 0 || nxfile >= NB) 4407c478bd9Sstevel@tonic-gate return; 4417c478bd9Sstevel@tonic-gate if ((ip->di_mode&IFMT) == IFBLK || 4427c478bd9Sstevel@tonic-gate (ip->di_mode&IFMT) == IFCHR || ip->di_mode&(ISUID|ISGID)) { 4437c478bd9Sstevel@tonic-gate ilist[nxfile].ino = ino; 4447c478bd9Sstevel@tonic-gate ilist[nxfile].mode = ip->di_mode; 4457c478bd9Sstevel@tonic-gate ilist[nxfile].uid = ip->di_uid; 4467c478bd9Sstevel@tonic-gate ilist[nxfile++].gid = ip->di_gid; 4477c478bd9Sstevel@tonic-gate return; 4487c478bd9Sstevel@tonic-gate } 4497c478bd9Sstevel@tonic-gate } 4507c478bd9Sstevel@tonic-gate (void) lookup(ino, 1); 4517c478bd9Sstevel@tonic-gate } 4527c478bd9Sstevel@tonic-gate 4537c478bd9Sstevel@tonic-gate void 4547c478bd9Sstevel@tonic-gate pass2(struct dinode *ip) 4557c478bd9Sstevel@tonic-gate { 456*d1a180b0Smaheshvs struct direct *dp; 4577c478bd9Sstevel@tonic-gate struct dirstuff dirp; 4587c478bd9Sstevel@tonic-gate struct htab *hp; 4597c478bd9Sstevel@tonic-gate 4607c478bd9Sstevel@tonic-gate if ((ip->di_mode&IFMT) != IFDIR) 4617c478bd9Sstevel@tonic-gate return; 4627c478bd9Sstevel@tonic-gate dirp.loc = 0; 4637c478bd9Sstevel@tonic-gate dirp.ip = ip; 4647c478bd9Sstevel@tonic-gate gip = ip; 4657c478bd9Sstevel@tonic-gate for (dp = dreaddir(&dirp); dp != NULL; dp = dreaddir(&dirp)) { 4667c478bd9Sstevel@tonic-gate int nmlen; 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate if (dp->d_ino == 0) 4697c478bd9Sstevel@tonic-gate continue; 4707c478bd9Sstevel@tonic-gate hp = lookup(dp->d_ino, 0); 4717c478bd9Sstevel@tonic-gate if (hp == 0) 4727c478bd9Sstevel@tonic-gate continue; 4737c478bd9Sstevel@tonic-gate if (dotname(dp)) 4747c478bd9Sstevel@tonic-gate continue; 4757c478bd9Sstevel@tonic-gate hp->h_pino = ino; 4767c478bd9Sstevel@tonic-gate nmlen = strlen(dp->d_name); 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate if (strngloc + nmlen + 1 > MAX_STRNGTAB_INDEX()) { 4797c478bd9Sstevel@tonic-gate if (!extend_strngtab(STRNGTAB_INCR)) { 4807c478bd9Sstevel@tonic-gate perror("ncheck: can't grow string table\n"); 4817c478bd9Sstevel@tonic-gate exit(32); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate } 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate hp->h_name_index = strngloc; 4867c478bd9Sstevel@tonic-gate (void) strcpy(&strngtab[strngloc], dp->d_name); 4877c478bd9Sstevel@tonic-gate strngloc += nmlen + 1; 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate } 4907c478bd9Sstevel@tonic-gate 4917c478bd9Sstevel@tonic-gate void 4927c478bd9Sstevel@tonic-gate pass3(struct dinode *ip) 4937c478bd9Sstevel@tonic-gate { 494*d1a180b0Smaheshvs struct direct *dp; 4957c478bd9Sstevel@tonic-gate struct dirstuff dirp; 4967c478bd9Sstevel@tonic-gate struct dinode *dip; 4977c478bd9Sstevel@tonic-gate int k; 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate if ((ip->di_mode&IFMT) != IFDIR) 5007c478bd9Sstevel@tonic-gate return; 5017c478bd9Sstevel@tonic-gate dirp.loc = 0; 5027c478bd9Sstevel@tonic-gate dirp.ip = ip; 5037c478bd9Sstevel@tonic-gate gip = ip; 5047c478bd9Sstevel@tonic-gate for (dp = dreaddir(&dirp); dp != NULL; dp = dreaddir(&dirp)) { 5057c478bd9Sstevel@tonic-gate if (aflg == 0 && dotname(dp)) 5067c478bd9Sstevel@tonic-gate continue; 5077c478bd9Sstevel@tonic-gate if (sflg == 0 && iflg == 0) 5087c478bd9Sstevel@tonic-gate goto pr; 5097c478bd9Sstevel@tonic-gate for (k = 0; ilist[k].ino != 0; k++) 5107c478bd9Sstevel@tonic-gate if (ilist[k].ino == dp->d_ino) 5117c478bd9Sstevel@tonic-gate break; 5127c478bd9Sstevel@tonic-gate if (ilist[k].ino == 0) 5137c478bd9Sstevel@tonic-gate continue; 5147c478bd9Sstevel@tonic-gate if (mflg) 5157c478bd9Sstevel@tonic-gate (void) printf("mode %-6o uid %-5ld gid %-5ld ino ", 5167c478bd9Sstevel@tonic-gate ilist[k].mode, ilist[k].uid, ilist[k].gid); 5177c478bd9Sstevel@tonic-gate pr: 5187c478bd9Sstevel@tonic-gate if (Sflg || uflg || Aflg || Mflg || Cflg || Nflg || Lflg) 5197c478bd9Sstevel@tonic-gate dip = ginode(dp->d_ino); 5207c478bd9Sstevel@tonic-gate if ((!Aflg || 5217c478bd9Sstevel@tonic-gate cmp((Today - dip->di_un.di_icom.ic_atime)/DAY, Adelay, 5227c478bd9Sstevel@tonic-gate Asign)) && 5237c478bd9Sstevel@tonic-gate (!Mflg || cmp((Today - dip->di_un.di_icom.ic_mtime)/DAY, 5247c478bd9Sstevel@tonic-gate Mdelay, Msign)) && 5257c478bd9Sstevel@tonic-gate (!Cflg || cmp((Today - dip->di_un.di_icom.ic_mtime)/DAY, 5267c478bd9Sstevel@tonic-gate Cdelay, Csign)) && 5277c478bd9Sstevel@tonic-gate (!Nflg || cmp(dip->di_un.di_icom.ic_mtime, Nage, '+'))) { 5287c478bd9Sstevel@tonic-gate if (Iflg == 0) 5297c478bd9Sstevel@tonic-gate (void) printf("%-5u\t", dp->d_ino); 5307c478bd9Sstevel@tonic-gate pname(stdout, ino, 0); 5317c478bd9Sstevel@tonic-gate (void) printf("/%s", dp->d_name); 5327c478bd9Sstevel@tonic-gate if (lookup(dp->d_ino, 0)) 5337c478bd9Sstevel@tonic-gate (void) printf("/."); 5347c478bd9Sstevel@tonic-gate if (Sflg) 5357c478bd9Sstevel@tonic-gate (void) printf("\t%6lld", 5367c478bd9Sstevel@tonic-gate dip->di_un.di_icom.ic_lsize); 5377c478bd9Sstevel@tonic-gate if (uflg) 5387c478bd9Sstevel@tonic-gate (void) printf("\t%s", 5397c478bd9Sstevel@tonic-gate user_name(dip->di_un.di_icom.ic_uid)); 5407c478bd9Sstevel@tonic-gate (void) printf("\n"); 5417c478bd9Sstevel@tonic-gate if (Lflg && (dip->di_un.di_icom.ic_nlink > 1)) { 5427c478bd9Sstevel@tonic-gate (void) fprintf(Lfile, "%-5u\t", 5437c478bd9Sstevel@tonic-gate dp->d_ino); 5447c478bd9Sstevel@tonic-gate (void) fprintf(Lfile, "%-5u\t", 5457c478bd9Sstevel@tonic-gate dip->di_un.di_icom.ic_nlink); 5467c478bd9Sstevel@tonic-gate pname(Lfile, ino, 0); 5477c478bd9Sstevel@tonic-gate (void) fprintf(Lfile, "/%s\n", dp->d_name); 5487c478bd9Sstevel@tonic-gate } 5497c478bd9Sstevel@tonic-gate } 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate } 5527c478bd9Sstevel@tonic-gate 5537c478bd9Sstevel@tonic-gate 5547c478bd9Sstevel@tonic-gate 5557c478bd9Sstevel@tonic-gate /* 5567c478bd9Sstevel@tonic-gate * get next entry in a directory. 5577c478bd9Sstevel@tonic-gate */ 5587c478bd9Sstevel@tonic-gate struct direct * 5597c478bd9Sstevel@tonic-gate dreaddir(struct dirstuff *dirp) 5607c478bd9Sstevel@tonic-gate { 561*d1a180b0Smaheshvs struct direct *dp; 5627c478bd9Sstevel@tonic-gate diskaddr_t lbn, d; 5637c478bd9Sstevel@tonic-gate 5647c478bd9Sstevel@tonic-gate for (;;) { 5657c478bd9Sstevel@tonic-gate if (dirp->loc >= (int)dirp->ip->di_size) 5667c478bd9Sstevel@tonic-gate return (NULL); 5677c478bd9Sstevel@tonic-gate if (blkoff(&sblock, dirp->loc) == 0) { 5687c478bd9Sstevel@tonic-gate lbn = lblkno(&sblock, dirp->loc); 5697c478bd9Sstevel@tonic-gate d = bmap(lbn); 5707c478bd9Sstevel@tonic-gate if (d == 0) 5717c478bd9Sstevel@tonic-gate return (NULL); 5727c478bd9Sstevel@tonic-gate bread(fsbtodb(&sblock, d), dirp->dbuf, 5737c478bd9Sstevel@tonic-gate (int)dblksize(&sblock, dirp->ip, (int)lbn)); 5747c478bd9Sstevel@tonic-gate } 5757c478bd9Sstevel@tonic-gate dp = (struct direct *) 5767c478bd9Sstevel@tonic-gate (dirp->dbuf + blkoff(&sblock, dirp->loc)); 5777c478bd9Sstevel@tonic-gate dirp->loc += dp->d_reclen; 5787c478bd9Sstevel@tonic-gate if (dp->d_ino == 0) 5797c478bd9Sstevel@tonic-gate continue; 5807c478bd9Sstevel@tonic-gate return (dp); 5817c478bd9Sstevel@tonic-gate } 5827c478bd9Sstevel@tonic-gate } 5837c478bd9Sstevel@tonic-gate 5847c478bd9Sstevel@tonic-gate int 5857c478bd9Sstevel@tonic-gate dotname(struct direct *dp) 5867c478bd9Sstevel@tonic-gate { 5877c478bd9Sstevel@tonic-gate 5887c478bd9Sstevel@tonic-gate if (dp->d_name[0] == '.') 5897c478bd9Sstevel@tonic-gate if (dp->d_name[1] == 0 || 5907c478bd9Sstevel@tonic-gate (dp->d_name[1] == '.' && dp->d_name[2] == 0)) 5917c478bd9Sstevel@tonic-gate return (1); 5927c478bd9Sstevel@tonic-gate return (0); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate 5957c478bd9Sstevel@tonic-gate void 5967c478bd9Sstevel@tonic-gate pname(FILE *stream, ino_t i, int lev) 5977c478bd9Sstevel@tonic-gate { 598*d1a180b0Smaheshvs struct htab *hp; 5997c478bd9Sstevel@tonic-gate 6007c478bd9Sstevel@tonic-gate if (i == UFSROOTINO) 6017c478bd9Sstevel@tonic-gate return; 6027c478bd9Sstevel@tonic-gate if ((hp = lookup(i, 0)) == 0) { 6037c478bd9Sstevel@tonic-gate (void) fprintf(stream, "???"); 6047c478bd9Sstevel@tonic-gate return; 6057c478bd9Sstevel@tonic-gate } 6067c478bd9Sstevel@tonic-gate if (lev > 10) { 6077c478bd9Sstevel@tonic-gate (void) fprintf(stream, "..."); 6087c478bd9Sstevel@tonic-gate return; 6097c478bd9Sstevel@tonic-gate } 6107c478bd9Sstevel@tonic-gate pname(stream, hp->h_pino, ++lev); 6117c478bd9Sstevel@tonic-gate if (pflg) 6127c478bd9Sstevel@tonic-gate (void) fprintf(stream, "%s/%s", prefix, 6137c478bd9Sstevel@tonic-gate &(strngtab[hp->h_name_index])); 6147c478bd9Sstevel@tonic-gate else 6157c478bd9Sstevel@tonic-gate (void) fprintf(stream, "/%s", 6167c478bd9Sstevel@tonic-gate &(strngtab[hp->h_name_index])); 6177c478bd9Sstevel@tonic-gate } 6187c478bd9Sstevel@tonic-gate 6197c478bd9Sstevel@tonic-gate struct htab * 6207c478bd9Sstevel@tonic-gate lookup(ino_t i, int ef) 6217c478bd9Sstevel@tonic-gate { 622*d1a180b0Smaheshvs struct htab *hp; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate for (hp = &htab[(int)i%hsize]; hp->h_ino; ) { 6257c478bd9Sstevel@tonic-gate if (hp->h_ino == i) 6267c478bd9Sstevel@tonic-gate return (hp); 6277c478bd9Sstevel@tonic-gate if (++hp >= &htab[hsize]) 6287c478bd9Sstevel@tonic-gate hp = htab; 6297c478bd9Sstevel@tonic-gate } 6307c478bd9Sstevel@tonic-gate if (ef == 0) 6317c478bd9Sstevel@tonic-gate return (0); 6327c478bd9Sstevel@tonic-gate if (++nhent >= hsize) { 6337c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 6347c478bd9Sstevel@tonic-gate "ff: hsize of %ld is too small\n", hsize); 6357c478bd9Sstevel@tonic-gate exit(32); 6367c478bd9Sstevel@tonic-gate } 6377c478bd9Sstevel@tonic-gate hp->h_ino = i; 6387c478bd9Sstevel@tonic-gate return (hp); 6397c478bd9Sstevel@tonic-gate } 6407c478bd9Sstevel@tonic-gate 6417c478bd9Sstevel@tonic-gate void 6427c478bd9Sstevel@tonic-gate bread(diskaddr_t bno, char *buf, int cnt) 6437c478bd9Sstevel@tonic-gate { 644*d1a180b0Smaheshvs int i; 6457c478bd9Sstevel@tonic-gate int got; 6467c478bd9Sstevel@tonic-gate offset_t offset; 6477c478bd9Sstevel@tonic-gate 6487c478bd9Sstevel@tonic-gate offset = (offset_t)bno * DEV_BSIZE; 6497c478bd9Sstevel@tonic-gate if (llseek(fi, offset, 0) == (offset_t)-1) { 6507c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 6517c478bd9Sstevel@tonic-gate "ff: llseek error %lx %lx\n", 6527c478bd9Sstevel@tonic-gate ((long *)&offset)[0], ((long *)&offset)[1]); 6537c478bd9Sstevel@tonic-gate for (i = 0; i < cnt; i++) 6547c478bd9Sstevel@tonic-gate buf[i] = 0; 6557c478bd9Sstevel@tonic-gate return; 6567c478bd9Sstevel@tonic-gate } 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate got = read((int)fi, buf, cnt); 6597c478bd9Sstevel@tonic-gate if (got != cnt) { 6607c478bd9Sstevel@tonic-gate perror("read"); 6617c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 6627c478bd9Sstevel@tonic-gate "ff: (wanted %d got %d blk %lld)\n", cnt, got, bno); 6637c478bd9Sstevel@tonic-gate for (i = 0; i < cnt; i++) 6647c478bd9Sstevel@tonic-gate buf[i] = 0; 6657c478bd9Sstevel@tonic-gate } 6667c478bd9Sstevel@tonic-gate } 6677c478bd9Sstevel@tonic-gate 6687c478bd9Sstevel@tonic-gate diskaddr_t 6697c478bd9Sstevel@tonic-gate bmap(diskaddr_t i) 6707c478bd9Sstevel@tonic-gate { 6717c478bd9Sstevel@tonic-gate daddr32_t ibuf[MAXNINDIR]; 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate if (i < NDADDR) 6747c478bd9Sstevel@tonic-gate return ((diskaddr_t)gip->di_db[i]); 6757c478bd9Sstevel@tonic-gate i -= NDADDR; 6767c478bd9Sstevel@tonic-gate if (i > NINDIR(&sblock)) { 6777c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "ff : %lu - huge directory\n", ino); 6787c478bd9Sstevel@tonic-gate return ((diskaddr_t)0); 6797c478bd9Sstevel@tonic-gate } 6807c478bd9Sstevel@tonic-gate bread(fsbtodb(&sblock, gip->di_ib[0]), (char *)ibuf, sizeof (ibuf)); 6817c478bd9Sstevel@tonic-gate return ((diskaddr_t)ibuf[i]); 6827c478bd9Sstevel@tonic-gate } 6837c478bd9Sstevel@tonic-gate 6847c478bd9Sstevel@tonic-gate struct dinode * 6857c478bd9Sstevel@tonic-gate ginode(ino_t inumber) 6867c478bd9Sstevel@tonic-gate { 6877c478bd9Sstevel@tonic-gate diskaddr_t iblk; 6887c478bd9Sstevel@tonic-gate diskaddr_t dblk; 6897c478bd9Sstevel@tonic-gate int ioff; 6907c478bd9Sstevel@tonic-gate static diskaddr_t curr_dblk; 6917c478bd9Sstevel@tonic-gate static char buf[MIN_PHYS_READ]; 6927c478bd9Sstevel@tonic-gate struct dinode *ibuf; 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate if (inumber < UFSROOTINO || (int)inumber > imax) { 6957c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 6967c478bd9Sstevel@tonic-gate "bad inode number %ld to ginode\n", inumber); 6977c478bd9Sstevel@tonic-gate exit(32); 6987c478bd9Sstevel@tonic-gate } 6997c478bd9Sstevel@tonic-gate iblk = itod(&sblock, (int)inumber); 7007c478bd9Sstevel@tonic-gate dblk = fsbtodb(&sblock, iblk); 7017c478bd9Sstevel@tonic-gate ioff = itoo(&sblock, (int)inumber); 7027c478bd9Sstevel@tonic-gate if (dblk != curr_dblk) { 7037c478bd9Sstevel@tonic-gate bread(dblk, &buf[0], sizeof (buf)); 7047c478bd9Sstevel@tonic-gate curr_dblk = dblk; 7057c478bd9Sstevel@tonic-gate inode_reads++; 7067c478bd9Sstevel@tonic-gate } 7077c478bd9Sstevel@tonic-gate ibuf = (struct dinode *)&buf[0]; 7087c478bd9Sstevel@tonic-gate ibuf += ioff; 7097c478bd9Sstevel@tonic-gate return (ibuf); 7107c478bd9Sstevel@tonic-gate } 7117c478bd9Sstevel@tonic-gate 7127c478bd9Sstevel@tonic-gate #define HASHNAMESIZE 16 7137c478bd9Sstevel@tonic-gate 7147c478bd9Sstevel@tonic-gate struct name_ent { 7157c478bd9Sstevel@tonic-gate struct name_ent *name_nxt; 7167c478bd9Sstevel@tonic-gate int name_uid; 7177c478bd9Sstevel@tonic-gate char *name_string; 7187c478bd9Sstevel@tonic-gate }; 7197c478bd9Sstevel@tonic-gate struct name_ent *hashtable[HASHNAMESIZE]; 7207c478bd9Sstevel@tonic-gate 7217c478bd9Sstevel@tonic-gate char * 7227c478bd9Sstevel@tonic-gate user_name(int uid) 7237c478bd9Sstevel@tonic-gate { 7247c478bd9Sstevel@tonic-gate int h_index; 7257c478bd9Sstevel@tonic-gate struct name_ent *hp; 7267c478bd9Sstevel@tonic-gate struct passwd *pwent; 7277c478bd9Sstevel@tonic-gate 7287c478bd9Sstevel@tonic-gate h_index = uid % HASHNAMESIZE; 7297c478bd9Sstevel@tonic-gate for (hp = hashtable[h_index]; hp != NULL; hp = hp->name_nxt) { 7307c478bd9Sstevel@tonic-gate if (hp->name_uid == uid) { 7317c478bd9Sstevel@tonic-gate return (hp->name_string); 7327c478bd9Sstevel@tonic-gate } 7337c478bd9Sstevel@tonic-gate } 7347c478bd9Sstevel@tonic-gate hp = (struct name_ent *)calloc(1, sizeof (struct name_ent)); 7357c478bd9Sstevel@tonic-gate hp->name_nxt = hashtable[h_index]; 7367c478bd9Sstevel@tonic-gate hp->name_uid = uid; 7377c478bd9Sstevel@tonic-gate hashtable[h_index] = hp; 7387c478bd9Sstevel@tonic-gate if ((pwent = getpwuid(uid)) == NULL) { 7397c478bd9Sstevel@tonic-gate hp->name_string = "unknown"; 7407c478bd9Sstevel@tonic-gate } else { 7417c478bd9Sstevel@tonic-gate hp->name_string = (char *)strdup(pwent->pw_name); 7427c478bd9Sstevel@tonic-gate } 7437c478bd9Sstevel@tonic-gate passwd_lookups++; 7447c478bd9Sstevel@tonic-gate 7457c478bd9Sstevel@tonic-gate return (hp->name_string); 7467c478bd9Sstevel@tonic-gate } 7477c478bd9Sstevel@tonic-gate 7487c478bd9Sstevel@tonic-gate int 7497c478bd9Sstevel@tonic-gate cmp(int a, int b, int s) 7507c478bd9Sstevel@tonic-gate { 7517c478bd9Sstevel@tonic-gate if (s == '+') 7527c478bd9Sstevel@tonic-gate return (a > b); 7537c478bd9Sstevel@tonic-gate if (s == '-') 7547c478bd9Sstevel@tonic-gate return (a < -(b)); 7557c478bd9Sstevel@tonic-gate return (a == b); 7567c478bd9Sstevel@tonic-gate } 7577c478bd9Sstevel@tonic-gate 7587c478bd9Sstevel@tonic-gate /* 7597c478bd9Sstevel@tonic-gate * We can't do this one by reading the disk directly, since there 7607c478bd9Sstevel@tonic-gate * is no guarantee that the file is even on a local disk. 7617c478bd9Sstevel@tonic-gate */ 7627c478bd9Sstevel@tonic-gate time_t 7637c478bd9Sstevel@tonic-gate mod_time(char *file) 7647c478bd9Sstevel@tonic-gate { 7657c478bd9Sstevel@tonic-gate struct stat64 stat_buf; 7667c478bd9Sstevel@tonic-gate 7677c478bd9Sstevel@tonic-gate if (stat64(file, &stat_buf) < 0) { 7687c478bd9Sstevel@tonic-gate (void) fprintf(stderr, "ff: can't stat '%s' - ignored\n", file); 7697c478bd9Sstevel@tonic-gate return (0); 7707c478bd9Sstevel@tonic-gate } 7717c478bd9Sstevel@tonic-gate return (stat_buf.st_mtime); 7727c478bd9Sstevel@tonic-gate } 7737c478bd9Sstevel@tonic-gate 7747c478bd9Sstevel@tonic-gate void 7757c478bd9Sstevel@tonic-gate out_multilinks() 7767c478bd9Sstevel@tonic-gate { 7777c478bd9Sstevel@tonic-gate int length; 7787c478bd9Sstevel@tonic-gate 7797c478bd9Sstevel@tonic-gate if ((length = fseek(Lfile, 0L, 2)) < 0) { 7807c478bd9Sstevel@tonic-gate perror("fseek"); 7817c478bd9Sstevel@tonic-gate exit(32); 7827c478bd9Sstevel@tonic-gate } else 7837c478bd9Sstevel@tonic-gate if ((length = ftell(Lfile)) > 0) { 7847c478bd9Sstevel@tonic-gate (void) fprintf(stdout, 7857c478bd9Sstevel@tonic-gate "\nmultilink files\nIno\tLinks\tPathname\n\n"); 7867c478bd9Sstevel@tonic-gate rewind(Lfile); 7877c478bd9Sstevel@tonic-gate while (length-- > 0) 7887c478bd9Sstevel@tonic-gate (void) putc(getc(Lfile), stdout); 7897c478bd9Sstevel@tonic-gate } else 7907c478bd9Sstevel@tonic-gate (void) fprintf(stdout, "No multilink files\n"); 7917c478bd9Sstevel@tonic-gate (void) fclose(Lfile); 7927c478bd9Sstevel@tonic-gate } 7937c478bd9Sstevel@tonic-gate 7947c478bd9Sstevel@tonic-gate void 7957c478bd9Sstevel@tonic-gate usage() 7967c478bd9Sstevel@tonic-gate { 7977c478bd9Sstevel@tonic-gate (void) fprintf(stderr, 7987c478bd9Sstevel@tonic-gate "ufs usage: ff [-F ufs] [generic options] [-o a,m,s] special\n"); 7997c478bd9Sstevel@tonic-gate exit(32); 8007c478bd9Sstevel@tonic-gate } 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate /* 8037c478bd9Sstevel@tonic-gate * Extend or create the string table. 8047c478bd9Sstevel@tonic-gate * Preserves contents. 8057c478bd9Sstevel@tonic-gate * Return non-zero for success. 8067c478bd9Sstevel@tonic-gate */ 8077c478bd9Sstevel@tonic-gate int 8087c478bd9Sstevel@tonic-gate extend_strngtab(unsigned int size) 8097c478bd9Sstevel@tonic-gate { 8107c478bd9Sstevel@tonic-gate strngtab_size += size; 8117c478bd9Sstevel@tonic-gate strngtab = (char *)realloc(strngtab, strngtab_size); 8127c478bd9Sstevel@tonic-gate 8137c478bd9Sstevel@tonic-gate return ((int)strngtab); 8147c478bd9Sstevel@tonic-gate } 815