blob: 52cad11e341095665db586f5861abb0c0d153a8c [file] [log] [blame]
Theodore Ts'o50e1e101997-04-26 13:58:21 +00001/*
2 * Test to see how quickly we can scan the inode table (not doing
3 * anything else)
4 */
5
Theodore Ts'od1154eb2011-09-18 17:34:37 -04006#include "config.h"
Theodore Ts'o50e1e101997-04-26 13:58:21 +00007#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'o50e1e101997-04-26 13:58:21 +000019#include <sys/ioctl.h>
Theodore Ts'oe71d8732003-03-14 02:13:48 -050020#ifdef HAVE_MALLOC_H
Theodore Ts'o50e1e101997-04-26 13:58:21 +000021#include <malloc.h>
Theodore Ts'oe71d8732003-03-14 02:13:48 -050022#endif
Theodore Ts'o50e1e101997-04-26 13:58:21 +000023
24#include "et/com_err.h"
25#include "e2fsck.h"
26#include "../version.h"
27
28extern int isatty(int);
29
30const char * program_name = "iscan";
31const char * device_name = NULL;
32
33int yflag = 0;
34int nflag = 0;
35int preen = 0;
36int inode_buffer_blocks = 0;
37int invalid_bitmaps = 0;
38
39struct resource_track global_rtrack;
40
Theodore Ts'o5ba23cb2001-01-11 19:15:02 +000041static void usage(void)
Theodore Ts'o50e1e101997-04-26 13:58:21 +000042{
43 fprintf(stderr,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000044 _("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
Theodore Ts'o50e1e101997-04-26 13:58:21 +000045 program_name);
46 exit(1);
47}
48
49static void PRS(int argc, char *argv[])
50{
51 int flush = 0;
Mike Frysingerb887f082010-01-04 23:15:32 -050052 int c;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000053#ifdef MTRACE
54 extern void *mallwatch;
55#endif
Theodore Ts'od4cac022001-08-08 16:10:23 -040056 errcode_t retval;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000057
58 setbuf(stdout, NULL);
59 setbuf(stderr, NULL);
60 initialize_ext2_error_table();
Theodore Ts'oefc6f622008-08-27 23:07:54 -040061
Theodore Ts'o50e1e101997-04-26 13:58:21 +000062 if (argc && *argv)
63 program_name = *argv;
64 while ((c = getopt (argc, argv, "FI")) != EOF)
65 switch (c) {
66 case 'F':
Theodore Ts'o50e1e101997-04-26 13:58:21 +000067 flush = 1;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000068 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'o50e1e101997-04-26 13:58:21 +000077 int fd = open(device_name, O_RDONLY, 0);
78
79 if (fd < 0) {
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000080 com_err("open", errno,
81 _("while opening %s for flushing"), device_name);
Theodore Ts'o50e1e101997-04-26 13:58:21 +000082 exit(FSCK_ERROR);
83 }
Theodore Ts'o5ba23cb2001-01-11 19:15:02 +000084 if ((retval = ext2fs_sync_device(fd, 1))) {
85 com_err("ext2fs_sync_device", retval,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000086 _("while trying to flush %s"), device_name);
Theodore Ts'o50e1e101997-04-26 13:58:21 +000087 exit(FSCK_ERROR);
88 }
89 close(fd);
Theodore Ts'o50e1e101997-04-26 13:58:21 +000090 }
91}
Theodore Ts'oefc6f622008-08-27 23:07:54 -040092
Theodore Ts'o50e1e101997-04-26 13:58:21 +000093int main (int argc, char *argv[])
94{
95 errcode_t retval = 0;
96 int exit_value = FSCK_OK;
97 ext2_filsys fs;
Theodore Ts'o86c627e2001-01-11 15:12:14 +000098 ext2_ino_t ino;
Eric Sandeend0ff90d2006-09-12 14:56:15 -040099 __u32 num_inodes = 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000100 struct ext2_inode inode;
101 ext2_inode_scan scan;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400102
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000103 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 Dilger2bc30412013-12-23 16:04:46 -0500110 com_err(program_name, retval, _("while trying to open '%s'"),
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000111 device_name);
112 exit(1);
113 }
114
115 ehandler_init(fs->io);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400116
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000117 retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
118 if (retval) {
Theodore Ts'o0c4a0722000-02-07 03:11:03 +0000119 com_err(program_name, retval, _("while opening inode scan"));
Theodore Ts'of8188ff1997-11-14 05:23:04 +0000120 exit(1);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000121 }
122
123 while (1) {
124 retval = ext2fs_get_next_inode(scan, &ino, &inode);
125 if (retval) {
126 com_err(program_name, retval,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +0000127 _("while getting next inode"));
Theodore Ts'of8188ff1997-11-14 05:23:04 +0000128 exit(1);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000129 }
130 if (ino == 0)
131 break;
132 num_inodes++;
133 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400134
Theodore Ts'o1b6bf171997-10-03 17:48:10 +0000135 print_resource_track(NULL, &global_rtrack);
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400136 printf(_("%u inodes scanned.\n"), num_inodes);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400137
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000138 exit(0);
139}