mirror of
https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git
synced 2024-11-23 18:14:25 +08:00
2bc3041754
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>
140 lines
2.5 KiB
C
140 lines
2.5 KiB
C
/*
|
|
* Test to see how quickly we can scan the inode table (not doing
|
|
* anything else)
|
|
*/
|
|
|
|
#include "config.h"
|
|
#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>
|
|
#ifdef HAVE_MALLOC_H
|
|
#include <malloc.h>
|
|
#endif
|
|
|
|
#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;
|
|
|
|
static void usage(void)
|
|
{
|
|
fprintf(stderr,
|
|
_("Usage: %s [-F] [-I inode_buffer_blocks] device\n"),
|
|
program_name);
|
|
exit(1);
|
|
}
|
|
|
|
static void PRS(int argc, char *argv[])
|
|
{
|
|
int flush = 0;
|
|
int c;
|
|
#ifdef MTRACE
|
|
extern void *mallwatch;
|
|
#endif
|
|
errcode_t retval;
|
|
|
|
setbuf(stdout, NULL);
|
|
setbuf(stderr, NULL);
|
|
initialize_ext2_error_table();
|
|
|
|
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) {
|
|
com_err("open", errno,
|
|
_("while opening %s for flushing"), device_name);
|
|
exit(FSCK_ERROR);
|
|
}
|
|
if ((retval = ext2fs_sync_device(fd, 1))) {
|
|
com_err("ext2fs_sync_device", retval,
|
|
_("while trying to flush %s"), device_name);
|
|
exit(FSCK_ERROR);
|
|
}
|
|
close(fd);
|
|
}
|
|
}
|
|
|
|
int main (int argc, char *argv[])
|
|
{
|
|
errcode_t retval = 0;
|
|
int exit_value = FSCK_OK;
|
|
ext2_filsys fs;
|
|
ext2_ino_t ino;
|
|
__u32 num_inodes = 0;
|
|
struct ext2_inode inode;
|
|
ext2_inode_scan scan;
|
|
|
|
init_resource_track(&global_rtrack);
|
|
|
|
PRS(argc, argv);
|
|
|
|
retval = ext2fs_open(device_name, 0,
|
|
0, 0, unix_io_manager, &fs);
|
|
if (retval) {
|
|
com_err(program_name, retval, _("while trying to open '%s'"),
|
|
device_name);
|
|
exit(1);
|
|
}
|
|
|
|
ehandler_init(fs->io);
|
|
|
|
retval = ext2fs_open_inode_scan(fs, inode_buffer_blocks, &scan);
|
|
if (retval) {
|
|
com_err(program_name, retval, _("while opening inode scan"));
|
|
exit(1);
|
|
}
|
|
|
|
while (1) {
|
|
retval = ext2fs_get_next_inode(scan, &ino, &inode);
|
|
if (retval) {
|
|
com_err(program_name, retval,
|
|
_("while getting next inode"));
|
|
exit(1);
|
|
}
|
|
if (ino == 0)
|
|
break;
|
|
num_inodes++;
|
|
}
|
|
|
|
print_resource_track(NULL, &global_rtrack);
|
|
printf(_("%u inodes scanned.\n"), num_inodes);
|
|
|
|
exit(0);
|
|
}
|