blob: 3d33c1f2c0007d691aab3cef71b789f767c689b8 [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
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
Theodore Ts'o50e1e101997-04-26 13:58:21 +000018#include <sys/ioctl.h>
Theodore Ts'oe71d8732003-03-14 02:13:48 -050019#ifdef HAVE_MALLOC_H
Theodore Ts'o50e1e101997-04-26 13:58:21 +000020#include <malloc.h>
Theodore Ts'oe71d8732003-03-14 02:13:48 -050021#endif
Theodore Ts'o50e1e101997-04-26 13:58:21 +000022
23#include "et/com_err.h"
24#include "e2fsck.h"
25#include "../version.h"
26
27extern int isatty(int);
28
29const char * program_name = "iscan";
30const char * device_name = NULL;
31
32int yflag = 0;
33int nflag = 0;
34int preen = 0;
35int inode_buffer_blocks = 0;
36int invalid_bitmaps = 0;
37
38struct resource_track global_rtrack;
39
Theodore Ts'o5ba23cb2001-01-11 19:15:02 +000040static void usage(void)
Theodore Ts'o50e1e101997-04-26 13:58:21 +000041{
42 fprintf(stderr,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000043 _("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
Theodore Ts'o50e1e101997-04-26 13:58:21 +000044 program_name);
45 exit(1);
46}
47
48static void PRS(int argc, char *argv[])
49{
50 int flush = 0;
Mike Frysingerb887f082010-01-04 23:15:32 -050051 int c;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000052#ifdef MTRACE
53 extern void *mallwatch;
54#endif
Theodore Ts'od4cac022001-08-08 16:10:23 -040055 errcode_t retval;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000056
57 setbuf(stdout, NULL);
58 setbuf(stderr, NULL);
59 initialize_ext2_error_table();
Theodore Ts'oefc6f622008-08-27 23:07:54 -040060
Theodore Ts'o50e1e101997-04-26 13:58:21 +000061 if (argc && *argv)
62 program_name = *argv;
63 while ((c = getopt (argc, argv, "FI")) != EOF)
64 switch (c) {
65 case 'F':
Theodore Ts'o50e1e101997-04-26 13:58:21 +000066 flush = 1;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000067 break;
68 case 'I':
69 inode_buffer_blocks = atoi(optarg);
70 break;
71 default:
72 usage ();
73 }
74 device_name = argv[optind];
75 if (flush) {
Theodore Ts'o50e1e101997-04-26 13:58:21 +000076 int fd = open(device_name, O_RDONLY, 0);
77
78 if (fd < 0) {
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000079 com_err("open", errno,
80 _("while opening %s for flushing"), device_name);
Theodore Ts'o50e1e101997-04-26 13:58:21 +000081 exit(FSCK_ERROR);
82 }
Theodore Ts'o5ba23cb2001-01-11 19:15:02 +000083 if ((retval = ext2fs_sync_device(fd, 1))) {
84 com_err("ext2fs_sync_device", retval,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +000085 _("while trying to flush %s"), device_name);
Theodore Ts'o50e1e101997-04-26 13:58:21 +000086 exit(FSCK_ERROR);
87 }
88 close(fd);
Theodore Ts'o50e1e101997-04-26 13:58:21 +000089 }
90}
Theodore Ts'oefc6f622008-08-27 23:07:54 -040091
Theodore Ts'o50e1e101997-04-26 13:58:21 +000092int main (int argc, char *argv[])
93{
94 errcode_t retval = 0;
95 int exit_value = FSCK_OK;
96 ext2_filsys fs;
Theodore Ts'o86c627e2001-01-11 15:12:14 +000097 ext2_ino_t ino;
Eric Sandeend0ff90d2006-09-12 14:56:15 -040098 __u32 num_inodes = 0;
Theodore Ts'o50e1e101997-04-26 13:58:21 +000099 struct ext2_inode inode;
100 ext2_inode_scan scan;
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400101
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000102 init_resource_track(&global_rtrack);
103
104 PRS(argc, argv);
105
106 retval = ext2fs_open(device_name, 0,
107 0, 0, unix_io_manager, &fs);
108 if (retval) {
JP Abgralle0ed7402014-03-19 19:08:39 -0700109 com_err(program_name, retval, _("while trying to open '%s'"),
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000110 device_name);
111 exit(1);
112 }
113
114 ehandler_init(fs->io);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400115
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000116 retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
117 if (retval) {
Theodore Ts'o0c4a0722000-02-07 03:11:03 +0000118 com_err(program_name, retval, _("while opening inode scan"));
Theodore Ts'of8188ff1997-11-14 05:23:04 +0000119 exit(1);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000120 }
121
122 while (1) {
123 retval = ext2fs_get_next_inode(scan, &ino, &inode);
124 if (retval) {
125 com_err(program_name, retval,
Theodore Ts'o0c4a0722000-02-07 03:11:03 +0000126 _("while getting next inode"));
Theodore Ts'of8188ff1997-11-14 05:23:04 +0000127 exit(1);
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000128 }
129 if (ino == 0)
130 break;
131 num_inodes++;
132 }
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400133
Theodore Ts'o1b6bf171997-10-03 17:48:10 +0000134 print_resource_track(NULL, &global_rtrack);
Eric Sandeend0ff90d2006-09-12 14:56:15 -0400135 printf(_("%u inodes scanned.\n"), num_inodes);
Theodore Ts'oefc6f622008-08-27 23:07:54 -0400136
Theodore Ts'o50e1e101997-04-26 13:58:21 +0000137 exit(0);
138}