iscan.c revision 8558eab78390d1924cd6b255686ceef133f294d5
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>
22#ifdef HAVE_MALLOC_H
23#include <malloc.h>
24#endif
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
43static void usage(void)
44{
45	fprintf(stderr,
46		_("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
47		program_name);
48	exit(1);
49}
50
51static void PRS(int argc, char *argv[])
52{
53	int		flush = 0;
54	int		c;
55#ifdef MTRACE
56	extern void	*mallwatch;
57#endif
58	errcode_t	retval;
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':
69			flush = 1;
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) {
79		int	fd = open(device_name, O_RDONLY, 0);
80
81		if (fd < 0) {
82			com_err("open", errno,
83			    _("while opening %s for flushing"), device_name);
84			exit(FSCK_ERROR);
85		}
86		if ((retval = ext2fs_sync_device(fd, 1))) {
87			com_err("ext2fs_sync_device", retval,
88				_("while trying to flush %s"), device_name);
89			exit(FSCK_ERROR);
90		}
91		close(fd);
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;
100	ext2_ino_t	ino;
101	__u32	num_inodes = 0;
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) {
112		com_err(program_name, retval, _("while trying to open %s"),
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) {
121		com_err(program_name, retval, _("while opening inode scan"));
122		exit(1);
123	}
124
125	while (1) {
126		retval = ext2fs_get_next_inode(scan, &ino, &inode);
127		if (retval) {
128			com_err(program_name, retval,
129				_("while getting next inode"));
130			exit(1);
131		}
132		if (ino == 0)
133			break;
134		num_inodes++;
135	}
136
137	print_resource_track(NULL, &global_rtrack);
138	printf(_("%u inodes scanned.\n"), num_inodes);
139
140	exit(0);
141}
142