Whamcloud - gitweb
tune2fs: Compute quota usage when turning on the 'quota' feature
[tools/e2fsprogs.git] / e2fsck / iscan.c
1 /*
2  * Test to see how quickly we can scan the inode table (not doing
3  * anything else)
4  */
5
6 #include "config.h"
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
19 #ifdef HAVE_MNTENT_H
20 #include <mntent.h>
21 #endif
22 #include <sys/ioctl.h>
23 #ifdef HAVE_MALLOC_H
24 #include <malloc.h>
25 #endif
26
27 #include "et/com_err.h"
28 #include "e2fsck.h"
29 #include "../version.h"
30
31 extern int isatty(int);
32
33 const char * program_name = "iscan";
34 const char * device_name = NULL;
35
36 int yflag = 0;
37 int nflag = 0;
38 int preen = 0;
39 int inode_buffer_blocks = 0;
40 int invalid_bitmaps = 0;
41
42 struct resource_track   global_rtrack;
43
44 static void usage(void)
45 {
46         fprintf(stderr,
47                 _("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
48                 program_name);
49         exit(1);
50 }
51
52 static void PRS(int argc, char *argv[])
53 {
54         int             flush = 0;
55         int             c;
56 #ifdef MTRACE
57         extern void     *mallwatch;
58 #endif
59         errcode_t       retval;
60
61         setbuf(stdout, NULL);
62         setbuf(stderr, NULL);
63         initialize_ext2_error_table();
64
65         if (argc && *argv)
66                 program_name = *argv;
67         while ((c = getopt (argc, argv, "FI")) != EOF)
68                 switch (c) {
69                 case 'F':
70                         flush = 1;
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                 int     fd = open(device_name, O_RDONLY, 0);
81
82                 if (fd < 0) {
83                         com_err("open", errno,
84                             _("while opening %s for flushing"), device_name);
85                         exit(FSCK_ERROR);
86                 }
87                 if ((retval = ext2fs_sync_device(fd, 1))) {
88                         com_err("ext2fs_sync_device", retval,
89                                 _("while trying to flush %s"), device_name);
90                         exit(FSCK_ERROR);
91                 }
92                 close(fd);
93         }
94 }
95
96 int main (int argc, char *argv[])
97 {
98         errcode_t       retval = 0;
99         int             exit_value = FSCK_OK;
100         ext2_filsys     fs;
101         ext2_ino_t      ino;
102         __u32   num_inodes = 0;
103         struct ext2_inode inode;
104         ext2_inode_scan scan;
105
106         init_resource_track(&global_rtrack);
107
108         PRS(argc, argv);
109
110         retval = ext2fs_open(device_name, 0,
111                              0, 0, unix_io_manager, &fs);
112         if (retval) {
113                 com_err(program_name, retval, _("while trying to open %s"),
114                         device_name);
115                 exit(1);
116         }
117
118         ehandler_init(fs->io);
119
120         retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
121         if (retval) {
122                 com_err(program_name, retval, _("while opening inode scan"));
123                 exit(1);
124         }
125
126         while (1) {
127                 retval = ext2fs_get_next_inode(scan, &ino, &inode);
128                 if (retval) {
129                         com_err(program_name, retval,
130                                 _("while getting next inode"));
131                         exit(1);
132                 }
133                 if (ino == 0)
134                         break;
135                 num_inodes++;
136         }
137
138         print_resource_track(NULL, &global_rtrack);
139         printf(_("%u inodes scanned.\n"), num_inodes);
140
141         exit(0);
142 }