ncheck.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) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* ncheck -- obtain file names from reading filesystem
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include "roll_log.h"
union {
} real_fs;
unsigned itab_size;
/* inode list */
struct ilist {
} *ilist;
int ilist_size = 0; /* size of ilist[] */
int ilist_index = 0; /* current index for storing into ilist; */
struct htab
{
int h_name_index; /* index into string table */
} *htab;
unsigned htab_size; /* how much malloc'd for htab */
/*
* string table: used to hold filenames.
*/
char *strngtab;
int strngloc;
int strngtab_size;
long hsize;
struct dirstuff {
int loc;
};
int aflg = 0;
int sflg = 0;
int iflg = 0; /* number of inodes being searched for */
int mflg = 0;
int fi;
int nhent;
int nerror;
long atol();
char *strcpy();
void usage();
void extend_ilist();
int extend_strngtab(unsigned int size);
unsigned int new_size);
extern int optind;
extern char *optarg;
char *subopts [] = {
#define M_FLAG 0
"m",
};
int argc;
char *argv[];
{
long n;
int opt;
char *suboptions, *value;
int suboption;
char *p;
int first = 0;
extend_ilist();
switch (opt) {
case 'a':
aflg++;
break;
case 'o':
/*
* ufs specific options.
*/
suboptions = optarg;
while (*suboptions != '\0') {
switch (suboption) {
case M_FLAG:
mflg++;
break;
default:
usage();
}
}
break;
case 'i':
", ")) != NULL) {
if ((n = atoi(p)) == 0)
break;
iflg++;
ilist_index = iflg;
if (iflg > MAX_ILIST_INDEX())
extend_ilist();
}
break;
case 's':
sflg++;
break;
#if 0
case 'V':
{
int opt_count;
char *opt_text;
opt_count++) {
if (opt_text)
opt_text);
}
}
break;
#endif
case '?':
usage();
}
}
while (argc--) {
argv++;
}
return (nerror);
}
void
char *file;
{
register int i, j, c;
if (fi < 0) {
nerror++;
return;
}
nhent = 0;
sync();
nerror++;
return;
}
(void) printf("%s: unrecognized ufs version number %d\n",
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;
}
}
if (itab == 0) {
"ncheck: not enough memory for itab table\n");
nerror++;
return;
}
if (htab == 0) {
"ncheck: not enough memory for htab table\n");
nerror++;
return;
}
(void) printf("not enough memory to allocate tables\n");
nerror++;
return;
}
strngloc = 0;
ino = 0;
}
ino++;
}
}
if (ilist_index > MAX_ILIST_INDEX())
extend_ilist();
ino = 0;
}
ino++;
}
}
ino = 0;
}
ino++;
}
}
/*
* Clear those elements after inodes specified by "-i" out of
* ilist.
*/
for (i = iflg; i < ilist_index; i++) {
}
ilist_index = iflg;
}
void
{
int i;
if (mflg) {
for (i = 0; i < iflg; i++)
}
}
if (sflg == 0)
return;
if (++ilist_index > MAX_ILIST_INDEX())
extend_ilist();
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:
(void) printf("/.");
(void) printf("\n");
}
}
/*
* get next entry in a directory.
*/
struct direct *
{
for (;;) {
return (NULL);
if (d == 0)
return (NULL);
}
continue;
}
return (dp);
}
}
{
return (1);
}
return (0);
}
void
ino_t i;
int lev;
{
if (i == UFSROOTINO)
return;
(void) printf("???");
return;
}
if (lev > 10) {
(void) printf("...");
return;
}
}
struct htab *
ino_t i;
int ef;
{
return (hp);
}
if (ef == 0)
return (0);
hsize);
exit(32);
}
return (hp);
}
void
char *buf;
int cnt;
{
register i;
int got;
for (i = 0; i < cnt; i++) {
buf[i] = 0;
}
return;
}
"ncheck: read error at block %lld (wanted %d got %d)\n",
for (i = 0; i < cnt; i++)
buf[i] = 0;
}
}
bmap(i)
daddr_t i;
{
if (i < NDADDR)
i -= NDADDR;
return ((daddr_t)0);
}
return (ibuf[i]);
}
void
usage()
{
/*CSTYLED*/
"ufs usage: ncheck [-F ufs] [generic options] [-a -i #list -s] [-o m] special\n");
exit(32);
}
/*
* Extend or create the inode list;
* this is used to contains the list of inodes we've been
* asked to check using the "-i" flag and to hold the
* inode numbers of files which we detect as being
* blk|char|setuid|setgid ("-s" flag support).
* Preserves contents.
*/
void
{
(ilist_size * sizeof (struct ilist)));
perror("ncheck: not enough memory to grow ilist\n");
exit(32);
}
}
/*
* Extend or create the string table.
* Preserves contents.
* Return non-zero for success.
*/
int
unsigned int size;
{
strngtab_size += size;
return ((int)strngtab);
}
/*
* Extend or create a table, throwing away previous
* contents.
* Return null on failure.
*/
uchar_t *
unsigned int *current_size; /* current size */
unsigned int new_size; /* bytes required */
{
/*
* if we've already allocated tbl,
* but it is too small, free it.
* we don't realloc because we are throwing
* away its contents.
*/
}
if (tbl == 0)
return ((uchar_t *)0);
*current_size = new_size;
}
return (tbl);
}