E2fsck could to do more damage to a filesystem by trying to relocate
inode tables due to corrupted block group descriptors, and the
relocation could seriously damage the filesystem.
This patch enhances ext2fs_check_desk() so it detects more
self-inconsistent block group descriptors, including the cases where
e2sck might be tempted to relocate the inode table, and reports the
block group descriptors as invalid; this will cause e2fsck to attempt
to use the backup superblocks, which hopefully have not been trashed.
Addresses-Sourceforge-Bug: #1840291
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Mke2fs used to have special case, ugly code in
setup_lazy_bg/setup_uninit_bg flag which set the flags based on all
sorts of special cases. Change it so that it is done in libext2fs,
and fix mke2fs to use alloc_stats functions which will take care of
clearing the *_UNINIT flags automatically as needed.
This is preparatory work to make the flex_bg allocation patch much
cleaner.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Add an explanation of exactly what ext2fs_super_and_bgd_loc() and
ext2fs_reserve_super_and_bgd_loc() do, and more importantly, exactly
what they return. Note that most callers should *not* rely on the
return value since it's rarely useful, especially once the flex_bg
feature is enabled and inode table and allocation bitmap blocks may
not be in the block group.
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
the superblock and block group descriptors into two functions:
ext2fs_reserve_super_and_bgd, found in lib/ext2fs/alloc_sb.c, and
ext2fs_super_and_bgd_lock, found in lib/ext2fs/close.c.
Change e2fsck/pass1.c (mark_table_blocks), lib/ext2fs/closefs.c
(ext2fs_flush), lib/ext2fs/initialize.c (ext2fs_initialize),
and misc/dumpe2fs.c (list_desc) to use these functions.
e2fsck/ChangeLog
pass1.c (mark_table_blocks): Use the new function
ext2fs_reserve_super_and_bgd to calculate the blocks to be
reserved.
lib/ext2fs/ChangeLog
closefs.c (ext2fs_super_and_bgd_loc): New function which
centralizes the calculation of the superblock and block
group descriptors.
(ext2fs_flush): Use ext2fs_super_and_bgd_lock to figure
out where to write the superblock and block group
descriptors.
alloc_sb.c (ext2fs_reserve_super_and_bgd): New function which
reserves space in the block bitmap using
ext2fs_super_and_bgd_loc.
initialize.c (ext2fs_initialize): Use
ext2fs_reserve_super_and_bgd to initialize the block bitmap.
misc/ChangeLog
dumpe2fs.c (list_desc): Use ext2fs_super_and_bgd_loc to
determine the locations of the superblock and block group
descriptors.