1997-04-26 17:58:21 +04:00
|
|
|
/*
|
|
|
|
* Test to see how quickly we can scan the inode table (not doing
|
|
|
|
* anything else)
|
|
|
|
*/
|
|
|
|
|
2011-09-19 01:34:37 +04:00
|
|
|
#include "config.h"
|
1997-04-26 17:58:21 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <time.h>
|
|
|
|
#ifdef HAVE_GETOPT_H
|
|
|
|
#include <getopt.h>
|
|
|
|
#endif
|
|
|
|
#include <unistd.h>
|
|
|
|
#ifdef HAVE_ERRNO_H
|
|
|
|
#include <errno.h>
|
|
|
|
#endif
|
|
|
|
#include <sys/ioctl.h>
|
2003-03-14 10:13:48 +03:00
|
|
|
#ifdef HAVE_MALLOC_H
|
1997-04-26 17:58:21 +04:00
|
|
|
#include <malloc.h>
|
2003-03-14 10:13:48 +03:00
|
|
|
#endif
|
1997-04-26 17:58:21 +04:00
|
|
|
|
|
|
|
#include "et/com_err.h"
|
|
|
|
#include "e2fsck.h"
|
|
|
|
#include "../version.h"
|
|
|
|
|
|
|
|
extern int isatty(int);
|
|
|
|
|
|
|
|
const char * program_name = "iscan";
|
|
|
|
const char * device_name = NULL;
|
|
|
|
|
|
|
|
int yflag = 0;
|
|
|
|
int nflag = 0;
|
|
|
|
int preen = 0;
|
|
|
|
int inode_buffer_blocks = 0;
|
|
|
|
int invalid_bitmaps = 0;
|
|
|
|
|
|
|
|
struct resource_track global_rtrack;
|
|
|
|
|
2001-01-11 22:15:02 +03:00
|
|
|
static void usage(void)
|
1997-04-26 17:58:21 +04:00
|
|
|
{
|
|
|
|
fprintf(stderr,
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 06:11:03 +03:00
|
|
|
_("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
|
1997-04-26 17:58:21 +04:00
|
|
|
program_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void PRS(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int flush = 0;
|
2010-01-05 07:15:32 +03:00
|
|
|
int c;
|
1997-04-26 17:58:21 +04:00
|
|
|
#ifdef MTRACE
|
|
|
|
extern void *mallwatch;
|
|
|
|
#endif
|
2001-08-09 00:10:23 +04:00
|
|
|
errcode_t retval;
|
1997-04-26 17:58:21 +04:00
|
|
|
|
|
|
|
setbuf(stdout, NULL);
|
|
|
|
setbuf(stderr, NULL);
|
|
|
|
initialize_ext2_error_table();
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
if (argc && *argv)
|
|
|
|
program_name = *argv;
|
|
|
|
while ((c = getopt (argc, argv, "FI")) != EOF)
|
|
|
|
switch (c) {
|
|
|
|
case 'F':
|
|
|
|
flush = 1;
|
|
|
|
break;
|
|
|
|
case 'I':
|
|
|
|
inode_buffer_blocks = atoi(optarg);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage ();
|
|
|
|
}
|
|
|
|
device_name = argv[optind];
|
|
|
|
if (flush) {
|
|
|
|
int fd = open(device_name, O_RDONLY, 0);
|
|
|
|
|
|
|
|
if (fd < 0) {
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 06:11:03 +03:00
|
|
|
com_err("open", errno,
|
|
|
|
_("while opening %s for flushing"), device_name);
|
1997-04-26 17:58:21 +04:00
|
|
|
exit(FSCK_ERROR);
|
|
|
|
}
|
2001-01-11 22:15:02 +03:00
|
|
|
if ((retval = ext2fs_sync_device(fd, 1))) {
|
|
|
|
com_err("ext2fs_sync_device", retval,
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 06:11:03 +03:00
|
|
|
_("while trying to flush %s"), device_name);
|
1997-04-26 17:58:21 +04:00
|
|
|
exit(FSCK_ERROR);
|
|
|
|
}
|
|
|
|
close(fd);
|
|
|
|
}
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
int main (int argc, char *argv[])
|
|
|
|
{
|
|
|
|
errcode_t retval = 0;
|
|
|
|
int exit_value = FSCK_OK;
|
|
|
|
ext2_filsys fs;
|
Many files:
dirinfo.c, e2fsck.h, emptydir.c, iscan.c, jfs_user.h, journal.c,
message.c, pass1.c, pass1b.c, pass2.c, pass3.c, pass4.c, pass5.c,
problem.h, scantest.c, super.c, swapfs.c: Change ino_t to ext2_ino_t.
2001-01-11 18:12:14 +03:00
|
|
|
ext2_ino_t ino;
|
2006-09-12 22:56:15 +04:00
|
|
|
__u32 num_inodes = 0;
|
1997-04-26 17:58:21 +04:00
|
|
|
struct ext2_inode inode;
|
|
|
|
ext2_inode_scan scan;
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
init_resource_track(&global_rtrack);
|
|
|
|
|
|
|
|
PRS(argc, argv);
|
|
|
|
|
|
|
|
retval = ext2fs_open(device_name, 0,
|
|
|
|
0, 0, unix_io_manager, &fs);
|
|
|
|
if (retval) {
|
debugfs, e2fsck: fix s_desc_size handling
The s_desc_size in the superblock specifies the group descriptor
size in bytes, but in various places the EXT4_FEATURE_INCOMPAT_64BIT
flag implies that the descriptor size is EXT2_MIN_DESC_SIZE_64BIT
(64 bytes) instead of checking the actual size. In other places,
the s_desc_size field is used without checking for INCOMPAT_64BIT.
In the case of ext2fs_group_desc() the s_desc_size was being ignored,
and assumed to be sizeof(struct ext4_group_desc), which would result
in garbage for any but the first group descriptor. Similarly, in
ext2fs_group_desc_csum() and print_csum() they assumed that the
maximum group descriptor size was sizeof(struct ext4_group_desc).
Fix these functions to use the actual superblock s_desc_size if
INCOMPAT_64BIT.
Conversely, in ext2fs_swap_group_desc2() s_desc_size was used
without checking for INCOMPAT_64BIT being set.
The e2fsprogs behaviour is different than that of the kernel,
which always checks INCOMPAT_64BIT, and only uses s_desc_size to
determine the offset of group descriptors and what range of bytes
to checksum.
Allow specifying the s_desc_size field at mke2fs time with the
"-E desc_size=NNN" option. Allow a power-of-two s_desc_size
value up to s_blocksize if INCOMPAT_64BIT is specified. This
is not expected to be used by regular users at this time, so it
is not currently documented in the mke2fs usage or man page.
Add m_desc_size_128, f_desc_size_128, and f_desc_bad test cases to
verify mke2fs and e2fsck handling of larger group descriptor sizes.
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-24 01:04:46 +04:00
|
|
|
com_err(program_name, retval, _("while trying to open '%s'"),
|
1997-04-26 17:58:21 +04:00
|
|
|
device_name);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
ehandler_init(fs->io);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
|
|
|
|
if (retval) {
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 06:11:03 +03:00
|
|
|
com_err(program_name, retval, _("while opening inode scan"));
|
Many files:
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress
indicator function.
pass1.c (scan_callback): Add call to the progress feedback function
(if it exists).
super.c (check_super_block): Skip the device size check if the
get_device_size returns EXT2_EXT_UNIMPLEMENTED.
iscan.c (main): Don't use fatal_error() anymore.
pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling
fatal_error(0).
problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT,
PR_3_NO_ROOT_INODE_ABORT): New problem codes.
problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code.
problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code.
problemP.h: New file which separates out the private fix_problem data
structures.
util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c,
swapfs.c util.c: allocate_memory() now takes a e2fsck context as its
first argument, and rename it to be e2fsck_allocate_memory().
problemP.h:
New file which contains the private problem abstraction definitions.
Makefile.pq:
Remove include of MAKEFILE.STD, which doesn't exist at this point.
1997-11-14 08:23:04 +03:00
|
|
|
exit(1);
|
1997-04-26 17:58:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
|
|
|
if (retval) {
|
|
|
|
com_err(program_name, retval,
|
Many files:
badblocks.c, e2fsck.h, ehandler.c, emptydir.c, extend.c, flushb.c,
iscan.c, message.c, pass1.c, pass1b.c, pass3.c pass4.c, pass5.c,
problem.c, scantest.c, swapfs.c, unix.c, util.c: Add
Internationalization support as suggested by Marco d'Itri
<md@linux.it>.
2000-02-07 06:11:03 +03:00
|
|
|
_("while getting next inode"));
|
Many files:
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c: Add calls to the progress
indicator function.
pass1.c (scan_callback): Add call to the progress feedback function
(if it exists).
super.c (check_super_block): Skip the device size check if the
get_device_size returns EXT2_EXT_UNIMPLEMENTED.
iscan.c (main): Don't use fatal_error() anymore.
pass1b.c, swapfs.c, badblocks.c: Set E2F_FLAG_ABORT instead of calling
fatal_error(0).
problem.c, pass3.c (PR_3_ROOT_NOT_DIR_ABORT,
PR_3_NO_ROOT_INODE_ABORT): New problem codes.
problem.c, pass2.c (PR_2_SPLIT_DOT): New problem code.
problem.c, pass1.c (PR_1_SUPPRESS_MESSAGES): New problem code.
problemP.h: New file which separates out the private fix_problem data
structures.
util.c, dirinfo.c, pass1.c, pass1b.c, pass2.c, pass5.c, super.c,
swapfs.c util.c: allocate_memory() now takes a e2fsck context as its
first argument, and rename it to be e2fsck_allocate_memory().
problemP.h:
New file which contains the private problem abstraction definitions.
Makefile.pq:
Remove include of MAKEFILE.STD, which doesn't exist at this point.
1997-11-14 08:23:04 +03:00
|
|
|
exit(1);
|
1997-04-26 17:58:21 +04:00
|
|
|
}
|
|
|
|
if (ino == 0)
|
|
|
|
break;
|
|
|
|
num_inodes++;
|
|
|
|
}
|
2008-08-28 07:07:54 +04:00
|
|
|
|
Many files:
pass*.c, super.c: Massive changes to avoid using printf and com_err
routines. All diagnostic messages are now routed through the
fix_problem interface.
pass2.c (check_dir_block): Check for duplicate '.' and '..' entries.
problem.c, problem.h: Add new problem codes PR_2_DUP_DOT and
PR_2_DUP_DOT_DOT.
problem.c: Added new problem codes for some of the superblock
corruption checks, and for the pass header messages. ("Pass
1: xxxxx")
util.c (print_resource_track): Now takes a description argument.
super.c, unix.c, e2fsck.c: New files to separate out the
operating-specific operations out from e2fsck.c. e2fsck.c now
contains the global e2fsck context management routines, and
super.c contains the "pass 0" initial validation of the
superblock and global block group descriptors.
pass1.c, pass2.c, pass3.c, pass4.c, pass5.c, util.c: Eliminate
(nearly) all global variables and moved them to the e2fsck
context structure.
problem.c, problem.h: Added new problem codes PR_0_SB_CORRUPT,
PR_0_FS_SIZE_WRONG, PR_0_NO_FRAGMENTS, PR_0_BLOCKS_PER_GROUP,
PR_0_FIRST_DATA_BLOCK
expect.1, expect.2:
Updated tests to align with e2fsck problem.c changes.
1997-10-03 21:48:10 +04:00
|
|
|
print_resource_track(NULL, &global_rtrack);
|
2006-09-12 22:56:15 +04:00
|
|
|
printf(_("%u inodes scanned.\n"), num_inodes);
|
2008-08-28 07:07:54 +04:00
|
|
|
|
1997-04-26 17:58:21 +04:00
|
|
|
exit(0);
|
|
|
|
}
|