ff.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2003 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ff -- obtain file names from reading filesystem
*/
#define NB 500
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
#include "roll_log.h"
#define MIN_PHYS_READ BBSIZE
union {
} real_fs;
struct ilist {
struct htab
{
int h_name_index; /* index into string table */
} *htab;
char *strngtab;
long hsize;
int strngloc;
int strngtab_size;
struct dirstuff {
int loc;
};
int Aflg = 0; /* accessed in n days */
int Mflg = 0; /* modified in n days */
int Nflg = 0; /* modified more recently than 'file' */
int Cflg = 0; /* changed within n days */
int aflg = 0; /* print the names `.' and `..' */
int sflg = 0; /* print only special files and files with set-user-ID mode */
int Sflg = 0; /* print file size */
int iflg = 0; /* number of inodes being searched for */
int Iflg = 0; /* do not print i-number */
int Lflg = 0; /* supplementary list of multiply linked files */
int mflg = 0;
int pflg = 0; /* a prefix exists */
int uflg = 0; /* print the owner's login name */
int fi;
int nhent;
int nxfile;
int imax; /* highest inode number */
int inode_reads;
int passwd_lookups;
int Adelay; /* Access delay */
int Asign; /* Access sign */
int Mdelay; /* Modify delay */
int Msign; /* Modify sign */
int Cdelay; /* change delay */
int Csign; /* change sign */
char *Lname; /* filename for supplementary list */
/*
* Function prototypes
*/
int cmp(int a, int b, int s);
void out_multilinks();
void usage();
int extend_strngtab(unsigned int size);
long atol();
char *strcpy();
char *prefix;
int nerror;
extern int optind;
extern char *optarg;
char *subopts [] = {
#define A_FLAG 0
"a",
#define M_FLAG 1
"m",
#define S_FLAG 2
"s",
};
int
int argc;
char *argv[];
{
long n;
int opt;
char *suboptions, *value;
char *p;
int first = 0;
switch (opt) {
case 'a':
Aflg++;
break;
case 'I':
Iflg++;
break;
case 'c':
Cflg++;
break;
case 'l':
Lflg++;
perror("open");
"ff: unable to open temp file, -l ignored\n");
Lflg = 0;
}
break;
case 'm':
Mflg++;
break;
case 'n':
Nflg++;
break;
case 'o':
/*
* ufs specific options.
*/
suboptions = optarg;
if (*suboptions == '\0')
usage();
while (*suboptions != '\0') {
switch ((getsubopt(&suboptions,
case A_FLAG:
aflg++;
break;
case M_FLAG:
mflg++;
break;
case S_FLAG:
sflg++;
break;
default:
usage();
}
}
break;
case 'i':
if ((n = atoi(p)) == 0)
break;
iflg++;
}
break;
case 'p':
pflg++;
break;
case 's':
Sflg++;
break;
case 'u':
uflg++;
break;
case '?':
usage();
}
}
while (argc--) {
argv++;
}
if (Lflg) {
}
if (nerror)
return (32);
return (0);
}
void
{
register int i, j, c;
if (fi < 0) {
nerror++;
return;
}
nhent = 0;
sync();
nerror++;
return;
}
nerror++;
return;
}
/* If fs is logged, roll the log. */
switch (rl_roll_log(file)) {
case RL_SUCCESS:
/*
* Reread the superblock. Rolling the log may have
* changed it.
*/
break;
case RL_SYSERR:
(void) printf("Warning: Cannot roll log for %s. %s\n",
break;
default:
(void) printf("Warning: Cannot roll log for %s.\n ",
file);
break;
}
}
(void) printf("not enough memory to allocate tables\n");
nerror++;
return;
}
strngloc = 0;
(void) printf("not enough memory to allocate tables\n");
nerror++;
return;
}
ino = 0;
}
ino++;
}
}
ino = 0;
}
ino++;
}
}
ino = 0;
}
ino++;
}
}
}
void
{
int i;
if (mflg)
for (i = 0; i < iflg; i++)
}
return;
return;
}
}
}
void
{
return;
int nmlen;
continue;
if (hp == 0)
continue;
continue;
if (!extend_strngtab(STRNGTAB_INCR)) {
perror("ncheck: can't grow string table\n");
exit(32);
}
}
}
}
void
{
int k;
return;
continue;
goto pr;
break;
continue;
if (mflg)
(void) printf("mode %-6o uid %-5ld gid %-5ld ino ",
pr:
if ((!Aflg ||
Asign)) &&
if (Iflg == 0)
(void) printf("/.");
if (Sflg)
(void) printf("\t%6lld",
if (uflg)
(void) printf("\t%s",
(void) printf("\n");
}
}
}
}
/*
* get next entry in a directory.
*/
struct direct *
{
diskaddr_t lbn, d;
for (;;) {
return (NULL);
if (d == 0)
return (NULL);
}
continue;
return (dp);
}
}
int
{
return (1);
return (0);
}
void
{
if (i == UFSROOTINO)
return;
return;
}
if (lev > 10) {
return;
}
if (pflg)
else
}
struct htab *
{
return (hp);
}
if (ef == 0)
return (0);
"ff: hsize of %ld is too small\n", hsize);
exit(32);
}
return (hp);
}
void
{
register i;
int got;
"ff: llseek error %lx %lx\n",
for (i = 0; i < cnt; i++)
buf[i] = 0;
return;
}
perror("read");
for (i = 0; i < cnt; i++)
buf[i] = 0;
}
}
bmap(diskaddr_t i)
{
if (i < NDADDR)
i -= NDADDR;
return ((diskaddr_t)0);
}
return ((diskaddr_t)ibuf[i]);
}
struct dinode *
{
int ioff;
static diskaddr_t curr_dblk;
static char buf[MIN_PHYS_READ];
"bad inode number %ld to ginode\n", inumber);
exit(32);
}
inode_reads++;
}
return (ibuf);
}
#define HASHNAMESIZE 16
struct name_ent {
int name_uid;
char *name_string;
};
char *
{
int h_index;
return (hp->name_string);
}
}
} else {
}
return (hp->name_string);
}
int
cmp(int a, int b, int s)
{
if (s == '+')
return (a > b);
if (s == '-')
return (a < -(b));
return (a == b);
}
/*
* We can't do this one by reading the disk directly, since there
* is no guarantee that the file is even on a local disk.
*/
{
return (0);
}
}
void
{
int length;
perror("fseek");
exit(32);
} else
"\nmultilink files\nIno\tLinks\tPathname\n\n");
while (length-- > 0)
} else
}
void
usage()
{
"ufs usage: ff [-F ufs] [generic options] [-o a,m,s] special\n");
exit(32);
}
/*
* Extend or create the string table.
* Preserves contents.
* Return non-zero for success.
*/
int
extend_strngtab(unsigned int size)
{
strngtab_size += size;
return ((int)strngtab);
}