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 | |
Theodore Ts'o | d1154eb | 2011-09-18 17:34:37 -0400 | [diff] [blame] | 6 | #include "config.h" |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 7 | #include <string.h> |
| 8 | #include <fcntl.h> |
| 9 | #include <ctype.h> |
| 10 | #include <termios.h> |
| 11 | #include <time.h> |
| 12 | #ifdef HAVE_GETOPT_H |
| 13 | #include <getopt.h> |
| 14 | #endif |
| 15 | #include <unistd.h> |
| 16 | #ifdef HAVE_ERRNO_H |
| 17 | #include <errno.h> |
| 18 | #endif |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 19 | #include <sys/ioctl.h> |
Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 20 | #ifdef HAVE_MALLOC_H |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 21 | #include <malloc.h> |
Theodore Ts'o | e71d873 | 2003-03-14 02:13:48 -0500 | [diff] [blame] | 22 | #endif |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 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 | |
Theodore Ts'o | 5ba23cb | 2001-01-11 19:15:02 +0000 | [diff] [blame] | 41 | static void usage(void) |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 42 | { |
| 43 | fprintf(stderr, |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 44 | _("Usage: %s [-F] [-I inode_buffer_blocks] device\n"), |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 45 | program_name); |
| 46 | exit(1); |
| 47 | } |
| 48 | |
| 49 | static void PRS(int argc, char *argv[]) |
| 50 | { |
| 51 | int flush = 0; |
Mike Frysinger | b887f08 | 2010-01-04 23:15:32 -0500 | [diff] [blame] | 52 | int c; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 53 | #ifdef MTRACE |
| 54 | extern void *mallwatch; |
| 55 | #endif |
Theodore Ts'o | d4cac02 | 2001-08-08 16:10:23 -0400 | [diff] [blame] | 56 | errcode_t retval; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 57 | |
| 58 | setbuf(stdout, NULL); |
| 59 | setbuf(stderr, NULL); |
| 60 | initialize_ext2_error_table(); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 61 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 62 | if (argc && *argv) |
| 63 | program_name = *argv; |
| 64 | while ((c = getopt (argc, argv, "FI")) != EOF) |
| 65 | switch (c) { |
| 66 | case 'F': |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 67 | flush = 1; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 68 | break; |
| 69 | case 'I': |
| 70 | inode_buffer_blocks = atoi(optarg); |
| 71 | break; |
| 72 | default: |
| 73 | usage (); |
| 74 | } |
| 75 | device_name = argv[optind]; |
| 76 | if (flush) { |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 77 | int fd = open(device_name, O_RDONLY, 0); |
| 78 | |
| 79 | if (fd < 0) { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 80 | com_err("open", errno, |
| 81 | _("while opening %s for flushing"), device_name); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 82 | exit(FSCK_ERROR); |
| 83 | } |
Theodore Ts'o | 5ba23cb | 2001-01-11 19:15:02 +0000 | [diff] [blame] | 84 | if ((retval = ext2fs_sync_device(fd, 1))) { |
| 85 | com_err("ext2fs_sync_device", retval, |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 86 | _("while trying to flush %s"), device_name); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 87 | exit(FSCK_ERROR); |
| 88 | } |
| 89 | close(fd); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 90 | } |
| 91 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 92 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 93 | int main (int argc, char *argv[]) |
| 94 | { |
| 95 | errcode_t retval = 0; |
| 96 | int exit_value = FSCK_OK; |
| 97 | ext2_filsys fs; |
Theodore Ts'o | 86c627e | 2001-01-11 15:12:14 +0000 | [diff] [blame] | 98 | ext2_ino_t ino; |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 99 | __u32 num_inodes = 0; |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 100 | struct ext2_inode inode; |
| 101 | ext2_inode_scan scan; |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 102 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 103 | init_resource_track(&global_rtrack); |
| 104 | |
| 105 | PRS(argc, argv); |
| 106 | |
| 107 | retval = ext2fs_open(device_name, 0, |
| 108 | 0, 0, unix_io_manager, &fs); |
| 109 | if (retval) { |
Andreas Dilger | 2bc3041 | 2013-12-23 16:04:46 -0500 | [diff] [blame] | 110 | com_err(program_name, retval, _("while trying to open '%s'"), |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 111 | device_name); |
| 112 | exit(1); |
| 113 | } |
| 114 | |
| 115 | ehandler_init(fs->io); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 116 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 117 | retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan); |
| 118 | if (retval) { |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 119 | com_err(program_name, retval, _("while opening inode scan")); |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 120 | exit(1); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | while (1) { |
| 124 | retval = ext2fs_get_next_inode(scan, &ino, &inode); |
| 125 | if (retval) { |
| 126 | com_err(program_name, retval, |
Theodore Ts'o | 0c4a072 | 2000-02-07 03:11:03 +0000 | [diff] [blame] | 127 | _("while getting next inode")); |
Theodore Ts'o | f8188ff | 1997-11-14 05:23:04 +0000 | [diff] [blame] | 128 | exit(1); |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 129 | } |
| 130 | if (ino == 0) |
| 131 | break; |
| 132 | num_inodes++; |
| 133 | } |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 134 | |
Theodore Ts'o | 1b6bf17 | 1997-10-03 17:48:10 +0000 | [diff] [blame] | 135 | print_resource_track(NULL, &global_rtrack); |
Eric Sandeen | d0ff90d | 2006-09-12 14:56:15 -0400 | [diff] [blame] | 136 | printf(_("%u inodes scanned.\n"), num_inodes); |
Theodore Ts'o | efc6f62 | 2008-08-27 23:07:54 -0400 | [diff] [blame] | 137 | |
Theodore Ts'o | 50e1e10 | 1997-04-26 13:58:21 +0000 | [diff] [blame] | 138 | exit(0); |
| 139 | } |