e2fsprogs/e2fsck/iscan.c
Theodore Ts'o f8188fff23 Many files:
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress
  	indicator function.
  pass1.c (scan_callback): Add call to the progress feedback function
  	(if it exists).
  super.c (check_super_block): Skip the device size check if the
  	get_device_size returns EXT2_EXT_UNIMPLEMENTED.
  iscan.c (main): Don't use fatal_error() anymore.
  pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling
  	fatal_error(0).
  problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT,
  	PR_3_NO_ROOT_INODE_ABORT): New problem codes.
  problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code.
  problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code.
  problemP.h: New file which separates out the private fix_problem data
  	structures.
  util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c,
  	swapfs.c util.c: allocate_memory() now takes a e2fsck context as its
  	first argument, and rename it to be e2fsck_allocate_memory().
problemP.h:
  New file which contains the private problem abstraction definitions.
Makefile.pq:
  Remove include of MAKEFILE.STD, which doesn't exist at this point.
1997-11-14 05:23:04 +00:00

149 lines
2.7 KiB
C

/*
* Test to see how quickly we can scan the inode table (not doing
* anything else)
*/
#include <string.h>
#include <fcntl.h>
#include <ctype.h>
#include <termios.h>
#include <time.h>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <unistd.h>
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#ifdef HAVE_MNTENT_H
#include <mntent.h>
#endif
#include <sys/ioctl.h>
#include <malloc.h>
#include "et/com_err.h"
#include "e2fsck.h"
#include "../version.h"
extern int isatty(int);
const char * program_name = "iscan";
const char * device_name = NULL;
int yflag = 0;
int nflag = 0;
int preen = 0;
int inode_buffer_blocks = 0;
int invalid_bitmaps = 0;
struct resource_track global_rtrack;
static void usage(NOARGS)
{
fprintf(stderr,
"Usage: %s [-F] [-I inode_buffer_blocks] device\n",
program_name);
exit(1);
}
static void PRS(int argc, char *argv[])
{
int flush = 0;
char c;
#ifdef MTRACE
extern void *mallwatch;
#endif
setbuf(stdout, NULL);
setbuf(stderr, NULL);
initialize_ext2_error_table();
if (argc && *argv)
program_name = *argv;
while ((c = getopt (argc, argv, "FI")) != EOF)
switch (c) {
case 'F':
#ifdef BLKFLSBUF
flush = 1;
#else
fprintf(stderr, "-F not supported");
exit(1);
#endif
break;
case 'I':
inode_buffer_blocks = atoi(optarg);
break;
default:
usage ();
}
device_name = argv[optind];
if (flush) {
#ifdef BLKFLSBUF
int fd = open(device_name, O_RDONLY, 0);
if (fd < 0) {
com_err("open", errno, "while opening %s for flushing",
device_name);
exit(FSCK_ERROR);
}
if (ioctl(fd, BLKFLSBUF, 0) < 0) {
com_err("BLKFLSBUF", errno, "while trying to flush %s",
device_name);
exit(FSCK_ERROR);
}
close(fd);
#else
fprintf(stderr, "BLKFLSBUF not supported");
exit(1);
#endif /* BLKFLSBUF */
}
}
int main (int argc, char *argv[])
{
errcode_t retval = 0;
int exit_value = FSCK_OK;
ext2_filsys fs;
ino_t ino;
int num_inodes = 0;
struct ext2_inode inode;
ext2_inode_scan scan;
init_resource_track(&global_rtrack);
PRS(argc, argv);
retval = ext2fs_open(device_name, 0,
0, 0, unix_io_manager, &fs);
if (retval) {
com_err(program_name, retval, "while trying to open %s",
device_name);
exit(1);
}
ehandler_init(fs->io);
retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
if (retval) {
com_err(program_name, retval, "while opening inode scan");
exit(1);
}
while (1) {
retval = ext2fs_get_next_inode(scan, &ino, &inode);
if (retval) {
com_err(program_name, retval,
"while getting next inode");
exit(1);
}
if (ino == 0)
break;
num_inodes++;
}
print_resource_track(NULL, &global_rtrack);
printf("%d inodes scanned.\n", num_inodes);
exit(0);
}