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