Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Test to see how quickly we can scan the inode table (not doing |
| 3 | * anything else) |
| 4 | */ |
| 5 | |
| 6 | #include <string.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <ctype.h> |
| 9 | #include <termios.h> |
| 10 | #include <time.h> |
| 11 | #ifdef HAVE_GETOPT_H |
| 12 | #include <getopt.h> |
| 13 | #endif |
| 14 | #include <unistd.h> |
| 15 | #ifdef HAVE_ERRNO_H |
| 16 | #include <errno.h> |
| 17 | #endif |
| 18 | #ifdef HAVE_MNTENT_H |
| 19 | #include <mntent.h> |
| 20 | #endif |
| 21 | #include <sys/ioctl.h> |
| 22 | #include <malloc.h> |
| 23 | |
| 24 | #include "et/com_err.h" |
| 25 | #include "e2fsck.h" |
| 26 | #include "../version.h" |
| 27 | |
| 28 | extern int isatty(int); |
| 29 | |
| 30 | const char * program_name = "iscan"; |
| 31 | const char * device_name = NULL; |
| 32 | |
| 33 | int yflag = 0; |
| 34 | int nflag = 0; |
| 35 | int preen = 0; |
| 36 | int inode_buffer_blocks = 0; |
| 37 | int invalid_bitmaps = 0; |
| 38 | |
| 39 | struct resource_track global_rtrack; |
| 40 | |
| 41 | static void usage(NOARGS) |
| 42 | { |
| 43 | fprintf(stderr, |
| 44 | "Usage: %s [-F] [-I inode_buffer_blocks] device\n", |
| 45 | program_name); |
| 46 | exit(1); |
| 47 | } |
| 48 | |
| 49 | static void PRS(int argc, char *argv[]) |
| 50 | { |
| 51 | int flush = 0; |
| 52 | char c; |
| 53 | #ifdef MTRACE |
| 54 | extern void *mallwatch; |
| 55 | #endif |
| 56 | |
| 57 | setbuf(stdout, NULL); |
| 58 | setbuf(stderr, NULL); |
| 59 | initialize_ext2_error_table(); |
| 60 | |
| 61 | if (argc && *argv) |
| 62 | program_name = *argv; |
| 63 | while ((c = getopt (argc, argv, "FI")) != EOF) |
| 64 | switch (c) { |
| 65 | case 'F': |
| 66 | #ifdef BLKFLSBUF |
| 67 | flush = 1; |
| 68 | #else |
| 69 | fatal_error ("-F not supported"); |
| 70 | #endif |
| 71 | break; |
| 72 | case 'I': |
| 73 | inode_buffer_blocks = atoi(optarg); |
| 74 | break; |
| 75 | default: |
| 76 | usage (); |
| 77 | } |
| 78 | device_name = argv[optind]; |
| 79 | if (flush) { |
| 80 | #ifdef BLKFLSBUF |
| 81 | int fd = open(device_name, O_RDONLY, 0); |
| 82 | |
| 83 | if (fd < 0) { |
| 84 | com_err("open", errno, "while opening %s for flushing", |
| 85 | device_name); |
| 86 | exit(FSCK_ERROR); |
| 87 | } |
| 88 | if (ioctl(fd, BLKFLSBUF, 0) < 0) { |
| 89 | com_err("BLKFLSBUF", errno, "while trying to flush %s", |
| 90 | device_name); |
| 91 | exit(FSCK_ERROR); |
| 92 | } |
| 93 | close(fd); |
| 94 | #else |
| 95 | fatal_error ("BLKFLSBUF not supported"); |
| 96 | #endif /* BLKFLSBUF */ |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | int main (int argc, char *argv[]) |
| 101 | { |
| 102 | errcode_t retval = 0; |
| 103 | int exit_value = FSCK_OK; |
| 104 | ext2_filsys fs; |
| 105 | ino_t ino; |
| 106 | int num_inodes = 0; |
| 107 | struct ext2_inode inode; |
| 108 | ext2_inode_scan scan; |
| 109 | |
| 110 | init_resource_track(&global_rtrack); |
| 111 | |
| 112 | PRS(argc, argv); |
| 113 | |
| 114 | retval = ext2fs_open(device_name, 0, |
| 115 | 0, 0, unix_io_manager, &fs); |
| 116 | if (retval) { |
| 117 | com_err(program_name, retval, "while trying to open %s", |
| 118 | device_name); |
| 119 | exit(1); |
| 120 | } |
| 121 | |
| 122 | ehandler_init(fs->io); |
| 123 | |
| 124 | retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan); |
| 125 | if (retval) { |
| 126 | com_err(program_name, retval, "while opening inode scan"); |
| 127 | fatal_error(0); |
| 128 | } |
| 129 | |
| 130 | while (1) { |
| 131 | retval = ext2fs_get_next_inode(scan, &ino, &inode); |
| 132 | if (retval) { |
| 133 | com_err(program_name, retval, |
| 134 | "while getting next inode"); |
| 135 | fatal_error(0); |
| 136 | } |
| 137 | if (ino == 0) |
| 138 | break; |
| 139 | num_inodes++; |
| 140 | } |
| 141 | |
| 142 | print_resource_track(&global_rtrack); |
| 143 | printf("%d inodes scanned.\n", num_inodes); |
| 144 | |
| 145 | exit(0); |
| 146 | } |