]>
Commit | Line | Data |
---|---|---|
50e1e10f TT |
1 | /* |
2 | * Test to see how quickly we can scan the inode table (not doing | |
3 | * anything else) | |
4 | */ | |
5 | ||
d1154eb4 | 6 | #include "config.h" |
50e1e10f TT |
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 | |
50e1e10f | 19 | #include <sys/ioctl.h> |
e71d8731 | 20 | #ifdef HAVE_MALLOC_H |
50e1e10f | 21 | #include <malloc.h> |
e71d8731 | 22 | #endif |
50e1e10f TT |
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 | ||
5ba23cb1 | 41 | static void usage(void) |
50e1e10f TT |
42 | { |
43 | fprintf(stderr, | |
0c4a0726 | 44 | _("Usage: %s [-F] [-I inode_buffer_blocks] device\n"), |
50e1e10f TT |
45 | program_name); |
46 | exit(1); | |
47 | } | |
48 | ||
49 | static void PRS(int argc, char *argv[]) | |
50 | { | |
51 | int flush = 0; | |
b887f08f | 52 | int c; |
50e1e10f TT |
53 | #ifdef MTRACE |
54 | extern void *mallwatch; | |
55 | #endif | |
d4cac023 | 56 | errcode_t retval; |
50e1e10f TT |
57 | |
58 | setbuf(stdout, NULL); | |
59 | setbuf(stderr, NULL); | |
60 | initialize_ext2_error_table(); | |
efc6f628 | 61 | |
50e1e10f TT |
62 | if (argc && *argv) |
63 | program_name = *argv; | |
64 | while ((c = getopt (argc, argv, "FI")) != EOF) | |
65 | switch (c) { | |
66 | case 'F': | |
50e1e10f | 67 | flush = 1; |
50e1e10f TT |
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) { | |
50e1e10f TT |
77 | int fd = open(device_name, O_RDONLY, 0); |
78 | ||
79 | if (fd < 0) { | |
0c4a0726 TT |
80 | com_err("open", errno, |
81 | _("while opening %s for flushing"), device_name); | |
50e1e10f TT |
82 | exit(FSCK_ERROR); |
83 | } | |
5ba23cb1 TT |
84 | if ((retval = ext2fs_sync_device(fd, 1))) { |
85 | com_err("ext2fs_sync_device", retval, | |
0c4a0726 | 86 | _("while trying to flush %s"), device_name); |
50e1e10f TT |
87 | exit(FSCK_ERROR); |
88 | } | |
89 | close(fd); | |
50e1e10f TT |
90 | } |
91 | } | |
efc6f628 | 92 | |
50e1e10f TT |
93 | int main (int argc, char *argv[]) |
94 | { | |
95 | errcode_t retval = 0; | |
96 | int exit_value = FSCK_OK; | |
97 | ext2_filsys fs; | |
86c627ec | 98 | ext2_ino_t ino; |
d0ff90d5 | 99 | __u32 num_inodes = 0; |
50e1e10f TT |
100 | struct ext2_inode inode; |
101 | ext2_inode_scan scan; | |
efc6f628 | 102 | |
50e1e10f TT |
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) { | |
2bc30417 | 110 | com_err(program_name, retval, _("while trying to open '%s'"), |
50e1e10f TT |
111 | device_name); |
112 | exit(1); | |
113 | } | |
114 | ||
115 | ehandler_init(fs->io); | |
efc6f628 | 116 | |
50e1e10f TT |
117 | retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan); |
118 | if (retval) { | |
0c4a0726 | 119 | com_err(program_name, retval, _("while opening inode scan")); |
f8188fff | 120 | exit(1); |
50e1e10f TT |
121 | } |
122 | ||
123 | while (1) { | |
124 | retval = ext2fs_get_next_inode(scan, &ino, &inode); | |
125 | if (retval) { | |
126 | com_err(program_name, retval, | |
0c4a0726 | 127 | _("while getting next inode")); |
f8188fff | 128 | exit(1); |
50e1e10f TT |
129 | } |
130 | if (ino == 0) | |
131 | break; | |
132 | num_inodes++; | |
133 | } | |
efc6f628 | 134 | |
1b6bf175 | 135 | print_resource_track(NULL, &global_rtrack); |
d0ff90d5 | 136 | printf(_("%u inodes scanned.\n"), num_inodes); |
efc6f628 | 137 | |
50e1e10f TT |
138 | exit(0); |
139 | } |