]> git.ipfire.org Git - thirdparty/e2fsprogs.git/blame - e2fsck/iscan.c
Improve future compatibility for the 64-bit I/O channel functions
[thirdparty/e2fsprogs.git] / e2fsck / iscan.c
CommitLineData
50e1e10f
TT
1/*
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
18#ifdef HAVE_MNTENT_H
19#include <mntent.h>
20#endif
21#include <sys/ioctl.h>
e71d8731 22#ifdef HAVE_MALLOC_H
50e1e10f 23#include <malloc.h>
e71d8731 24#endif
50e1e10f
TT
25
26#include "et/com_err.h"
27#include "e2fsck.h"
28#include "../version.h"
29
30extern int isatty(int);
31
32const char * program_name = "iscan";
33const char * device_name = NULL;
34
35int yflag = 0;
36int nflag = 0;
37int preen = 0;
38int inode_buffer_blocks = 0;
39int invalid_bitmaps = 0;
40
41struct resource_track global_rtrack;
42
5ba23cb1 43static void usage(void)
50e1e10f
TT
44{
45 fprintf(stderr,
0c4a0726 46 _("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
50e1e10f
TT
47 program_name);
48 exit(1);
49}
50
51static void PRS(int argc, char *argv[])
52{
53 int flush = 0;
54 char c;
55#ifdef MTRACE
56 extern void *mallwatch;
57#endif
d4cac023 58 errcode_t retval;
50e1e10f
TT
59
60 setbuf(stdout, NULL);
61 setbuf(stderr, NULL);
62 initialize_ext2_error_table();
63
64 if (argc && *argv)
65 program_name = *argv;
66 while ((c = getopt (argc, argv, "FI")) != EOF)
67 switch (c) {
68 case 'F':
50e1e10f 69 flush = 1;
50e1e10f
TT
70 break;
71 case 'I':
72 inode_buffer_blocks = atoi(optarg);
73 break;
74 default:
75 usage ();
76 }
77 device_name = argv[optind];
78 if (flush) {
50e1e10f
TT
79 int fd = open(device_name, O_RDONLY, 0);
80
81 if (fd < 0) {
0c4a0726
TT
82 com_err("open", errno,
83 _("while opening %s for flushing"), device_name);
50e1e10f
TT
84 exit(FSCK_ERROR);
85 }
5ba23cb1
TT
86 if ((retval = ext2fs_sync_device(fd, 1))) {
87 com_err("ext2fs_sync_device", retval,
0c4a0726 88 _("while trying to flush %s"), device_name);
50e1e10f
TT
89 exit(FSCK_ERROR);
90 }
91 close(fd);
50e1e10f
TT
92 }
93}
94
95int main (int argc, char *argv[])
96{
97 errcode_t retval = 0;
98 int exit_value = FSCK_OK;
99 ext2_filsys fs;
86c627ec 100 ext2_ino_t ino;
d0ff90d5 101 __u32 num_inodes = 0;
50e1e10f
TT
102 struct ext2_inode inode;
103 ext2_inode_scan scan;
104
105 init_resource_track(&global_rtrack);
106
107 PRS(argc, argv);
108
109 retval = ext2fs_open(device_name, 0,
110 0, 0, unix_io_manager, &fs);
111 if (retval) {
0c4a0726 112 com_err(program_name, retval, _("while trying to open %s"),
50e1e10f
TT
113 device_name);
114 exit(1);
115 }
116
117 ehandler_init(fs->io);
118
119 retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
120 if (retval) {
0c4a0726 121 com_err(program_name, retval, _("while opening inode scan"));
f8188fff 122 exit(1);
50e1e10f
TT
123 }
124
125 while (1) {
126 retval = ext2fs_get_next_inode(scan, &ino, &inode);
127 if (retval) {
128 com_err(program_name, retval,
0c4a0726 129 _("while getting next inode"));
f8188fff 130 exit(1);
50e1e10f
TT
131 }
132 if (ino == 0)
133 break;
134 num_inodes++;
135 }
136
1b6bf175 137 print_resource_track(NULL, &global_rtrack);
d0ff90d5 138 printf(_("%u inodes scanned.\n"), num_inodes);
50e1e10f
TT
139
140 exit(0);
141}