summaryrefslogtreecommitdiff
path: root/e2fsck/pass1.c
AgeCommit message (Collapse)AuthorFilesLines
2011-12-18e2fsck: use different bitmap types as appropriateTheodore Ts'o1-24/+38
Now that we have multiple backend implementations of the bitmap code, this commit teaches e2fsck to use either the most appropriate backend for each use case. Since we don't know for sure if we will get it all right, the default choices can be overridden via e2fsck.conf. The various definitions are shown here, with the current defaults (which may change as we add more bitmap implementations and as learn what works better). ; EXT2FS_BAMP64_BITARRAY is 1 ; EXT2FS_BMAP64_RBTREE is 2 ; EXT2FS_BMAP64_AUTODIR is 3 [bitmaps] inode_used_map = 2 ; pass1 inode_dir_map = 3 ; pass1 inode_reg_map = 2 ; pass1 block_found_map = 2 ; pass1 inode_bad_map = 2 ; pass1 inode_imagic_map = 2 ; pass1 block_dup_map = 2 ; pass1 block_ea_map = 2 ; pass1 inode_link_info = 2 ; pass1 inode_dup_map = 2 ; pass1b inode_done_map = 3 ; pass3 inode_loop_detect = 3 ; pass3 fs_bitmaps = 2 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-12-16e2fsck: fix use of uninitialized value in the MMP codeTheodore Ts'o1-1/+1
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-11-25e2fsck: fix the max size calculation for non-extent fileKazuya Mio1-1/+1
When I create a non-extent file with the maximum size in ext4, e2fsck detects the following error: Pass 1: Checking inodes, blocks, and sizes Inode 12, i_size is 4402345721856, should be 4402345721856. Fix? As we know, e2fsck checks the size field of the inode in pass 1. However, in case of the ext4 with the feature of ^extent and huge_file, the maximum file size calculated in e2fsck is less than the real one. The patch fixes this problem. Signed-off-by: Kazuya Mio <k-mio@sx.jp.nec.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-10-16libext2fs: ext2fs_[set_]file_acl_block needs to check for 64-bit feature flagTheodore Ts'o1-10/+15
The ext2fs_file_acl_block() and ext2fs_set_file_acl_block() needs to only check i_file_acl_high if the 64-bit flag is set. This is needed because otherwise we will run into problems on Hurd systems which actually use that field for h_i_mode_high. This involves an ABI change since we need to pass ext2_filsys to these functions. Fortunately these functions were first included in the 1.42-WIP series, so it's OK for us to change them now. (This is why we have 1.42-WIP releases. :-) Addresses-Sourceforge-Bug: #3379227 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-28e2fsck: check for invalid bad block inodeTheodore Ts'o1-0/+11
In some cases the bad block inode gets corrupted. If it looks insane, offer to clear it before trying to interpret it does more harm than good. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-25ext2fs: add multi-mount protection (INCOMPAT_MMP)Andreas Dilger1-0/+10
Multi-mount protection is feature that allows mke2fs, e2fsck, and others to detect if the filesystem is mounted on a remote node (on SAN disks) and avoid corrupting the filesystem. For e2fsprogs this means that it checks the MMP block to see if the filesystem is in use, and marks the filesystem busy while e2fsck is running on the system. This is useful on SAN disks that are shared between high-availability servers, or accessible by multiple nodes that aren't in HA pairs. MMP isn't intended to serve as a primary HA exclusion mechanism, but as a failsafe to protect against user, software, or hardware errors. There is no requirement that e2fsck updates the MMP block at regular intervals, but e2fsck does this occasionally to provide useful information to the sysadmin in case of a detected conflict. For the kernel (since Linux 3.0) MMP adds a "heartbeat" mechanism to periodically write to disk (every few seconds by default) to notify other nodes that the filesystem is still in use and unsafe to modify. Originally-by: Kalpak Shah <kalpak@clusterfs.com> Signed-off-by: Johann Lombardi <johann@whamcloud.com> Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-18Shorten compile commands run by the build systemTheodore Ts'o1-0/+1
The DEFS line in MCONFIG had gotten so long that it exceeded 4k, and this was starting to cause some tools heartburn. It also made "make V=1" almost useless, since trying to following the individual commands run by make was lost in the noise of all of the defines. So fix this by putting the configure-generated defines in lib/config.h and the directory pathnames to lib/dirpaths.h. In addition, clean up some vestigal defines in configure.in and in the Makefiles to further shorten the cc command lines. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16e2fsck: Don't store old_op from ehandler_operation if we don't restore it.Eric Sandeen1-2/+1
old_op is set but never used, because we restore "0" not old_op. So don't bother with it. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16libext2fs: add metadata checksum and snapshot feature flagsTheodore Ts'o1-2/+2
Reserve EXT4_FEATURE_RO_COMPAT_METADATA_CSUM and EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP. Also reserve fields in the superblock and the inode for the checksums. In the block group descriptor, reserve the exclude bitmap field for the snapshot feature, and checksums for the inode and block allocation bitmaps. With this commit, the metadata checksum and exclude bitmap features should have reserved all of the fields they need in ext4's on-disk format. This commit also fixes an a missing byte swap for s_overhead_blocks. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu> Cc: Darrick J. Wong <djwong@us.ibm.com> Cc: Amir Goldstein <amir73il@gmail.com>
2011-08-31e2fsck: add support for checking the built-in quota filesAditya Kali1-0/+34
This patch adds support for doing quota accounting during full e2fsck scan if the 'quota' feature was set on the superblock. If user-visible quota inodes are in use, they will be hidden and converted to the reserved quota inodes. Signed-off-by: Aditya Kali <adityakali@google.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-07-10e2fsck: teach e2fsck how to deal with bigalloc in non-extent-mapped inodesTheodore Ts'o1-3/+10
Currently the bigalloc implementation in the kernel requires extents, but this restriction might get relaxed in the future. Also, old versions of mke2fs that supported bigalloc during early testing created the root and lost+found directories without using extent-mapped inodes. This makes it possible for e2fsck to better support these old legacy file systems if it comes across them. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-07-08misc: use EXT2_I_SIZE() consistently to get sizeAndreas Dilger1-3/+2
Use the EXT2_I_SIZE() macro consistently to access the inode size. The i_size/i_size_high combination is open coded in several places. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-06-16mke2fs, e2fsck: fix i_blocks handling for bigalloc file systemsTheodore Ts'o1-3/+5
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-11misc: clean up compiler warningsAndreas Dilger1-2/+3
Fix several types of compiler warnings (unused variables/labels), uninitialized variables, etc that are hit with gcc -Wall. Signed-off-by: Andreas Dilger <adilger@whamcloud.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-06-10e2fsck: add basic bigalloc support to check (but not yet repair) file systemsTheodore Ts'o1-3/+20
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-09-24e2fsck: Set i_blocks_hi when correcting the i_blocks field in pass #1Theodore Ts'o1-1/+1
For file systems with 64-bit block numbers, we need to make sure we correct the i_blocks_hi field as well as the i_blocks field when setting it to the correct value. Thanks to Justin Maggard for pointing this out. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-06-13e2fsck: Fix up to be 64-bit block number safeValerie Aurora Henson1-45/+44
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: Nick Dokos <nicholas.dokos@hp.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-06-07Merge branch 'maint' into nextTheodore Ts'o1-16/+33
Conflicts: e2fsck/journal.c e2fsck/pass1.c e2fsck/pass2.c misc/mke2fs.c
2010-05-19e2fsck: correct test for EOFBLOCKSEric Sandeen1-1/+1
This test, added to e2fsprogs-1.41.12, is backwards. If EOFBLOCKS is set, then the size -should- be less than the last physical block... xfstests 013 caught this. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-05-14e2fsck: Explicitly reject extents that begin at physical block 0 as illegalTheodore Ts'o1-1/+2
In the case where s_first_data_block is 1, we need to explictly reject an extent whose starting physical block is zero. Thanks to Jiaying Zhang <jiayingz@google.com> for finding this bug. Addresses-Google-Bug: #2573806 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-05-13e2fsck: Fix segmentation fault when checking a file systemTheodore Ts'o1-0/+1
If a corrupted file system causes us to want to delete an extent, and that causes us to want to release a block in e2fsck pass #1, it would be preferable if e2fsck didn't seg fault. This tends to get users craky, as users are wont to do. :-) Thanks to Dirk Reiners for reporting this bug: e2fsck crashes fixing a corrupted 3.5 TB filesystem: 0x0000000000432002 in ext2fs_unmark_generic_bitmap (bitmap=0x0, bitno=623386749) at gen_bitmap.c:183 183 if ((bitno < bitmap->start) || (bitno > bitmap->end)) { (gdb) bt bitno=623386749) at gen_bitmap.c:183 block=623386749) at ../../lib/ext2fs/bitops.h:319 inuse=-1) at alloc_stats.c:78 extent.c:1509 pb=0x7fffffffdfe0, start_block=0, ehandle=0x6dcf50) at pass1.c:1709 pb=0x7fffffffdfe0, start_block=0, ehandle=0x6dcf50) at pass1.c:1737 pctx=0x7fffffffe100, pb=0x7fffffffdfe0) at pass1.c:1842 block_buf=0x6c4330 "\373\212#") at pass1.c:1920 The source of the NULL bitmap is fs on stack frame 2: (gdb) up 2 inuse=-1) at alloc_stats.c:78 78 ext2fs_unmark_block_bitmap(fs->block_map, blk); Addresses-SourceForge-Bug: #2971800 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-05-13e2fsck: make block counting variable in pass1 64 bitsEric Sandeen1-1/+1
Justin reported that creating a 4T file with posix_fallocate led to fsck errors: e2fsck 1.41.10 (10-Feb-2009) Pass 1: Checking inodes, blocks, and sizes Inode 12, i_blocks is 8589935432, should be 840. Fix? yes This looks like a 32-bit overflow. commmit 8a8f36540bbf5d4397cf476e216e9a720b5c1d8e added handling of the high i_blocks number, but we accumulate blocks in the num_blocks field, and that's still just 32 bits. Note: we don't need to expand max_blocks for now, that's only used in the non-extents case, and those files have smaller max sizes. I haven't been able to replicate the problem, oddly, but Justin reports that this patch fixed his situation. Reported-by: Justin Maggard <jmaggard10@gmail.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2010-05-12e2fsck: Fix a number of problems that were inappropriately using PROMPT_ABORTTheodore Ts'o1-11/+16
There were a number of problems that were prompting the user whether or not to ABORT, but then would abort regardless of whether the user answered yes or no. Change those to be PROMPT_NONE, PR_FATAL. Also, fix PR_1_RESIZE_INODE_CREATE so that it recovers appropriately after failing to create the resize inode. This problem now uses PROMPT_CONTINUE instead of PROMPT_ABORT, and if the user says, "no", the code will abort. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-05-10e2fsck: Check for cases where EOFBLOCKS_FL is unnecessarily setTheodore Ts'o1-0/+13
Some kernels will crash if EOFBLOCKS_FL is set when it is it not needed, and this if it is left set when it isn't needed, it is a sign of a kernel bug. Addresses-Google-Bug: #2604224 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-04-08Revert "e2fsck: fix spurious complaints about i_size caused by preallocated ↵Theodore Ts'o1-3/+1
blocks" This reverts commit 0ea910997b3c2ba09b65b852b9bb4dd7b4d68999. Since the Linux kernel now has support for the EXT4_EOFBLOCKS_FL flag starting in 2.6.34, we don't need this workaround any more. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-03-17e2fsck: Fix segmentation fault when checking a file systemTheodore Ts'o1-0/+1
If a corrupted file system causes us to want to delete an extent, and that causes us to want to release a block in e2fsck pass #1, it would be preferable if e2fsck didn't seg fault. This tends to get users craky, as users are wont to do. :-) Thanks to Dirk Reiners for reporting this bug: e2fsck crashes fixing a corrupted 3.5 TB filesystem: 0x0000000000432002 in ext2fs_unmark_generic_bitmap (bitmap=0x0, bitno=623386749) at gen_bitmap.c:183 183 if ((bitno < bitmap->start) || (bitno > bitmap->end)) { (gdb) bt bitno=623386749) at gen_bitmap.c:183 block=623386749) at ../../lib/ext2fs/bitops.h:319 inuse=-1) at alloc_stats.c:78 extent.c:1509 pb=0x7fffffffdfe0, start_block=0, ehandle=0x6dcf50) at pass1.c:1709 pb=0x7fffffffdfe0, start_block=0, ehandle=0x6dcf50) at pass1.c:1737 pctx=0x7fffffffe100, pb=0x7fffffffdfe0) at pass1.c:1842 block_buf=0x6c4330 "\373\212#") at pass1.c:1920 The source of the NULL bitmap is fs on stack frame 2: (gdb) up 2 inuse=-1) at alloc_stats.c:78 78 ext2fs_unmark_block_bitmap(fs->block_map, blk); Addresses-SourceForge-Bug: #2971800 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-03-15Merge branch 'maint' into nextTheodore Ts'o1-1/+2
2010-02-24e2fsck: don't complain about i_size for known blocks past EOFEric Sandeen1-1/+2
This is the userspace side of Jiaying's EOFBLOCKS patch. With Aneesh's patches for .33, Jiaying's patch, and this one, xfstests 013/fsstress (even with direct IO enabled) has held up through many runs. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-02-10Merge branch 'maint' into nextTheodore Ts'o1-11/+55
Conflicts: e2fsck/pass1.c
2010-02-05e2fsck: Fix the check if a file is really a directory to understand extentsNick Dokos1-11/+55
Pass 1 has a test to see if a special file is really a directory. Signed-off-by: Nick Dokos <nicholas.dokos@hp.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-01-31Merge branch 'maint' into nextTheodore Ts'o1-48/+38
Conflicts: configure lib/ext2fs/alloc_tables.c misc/mke2fs.c
2010-01-30e2fsck: Remove some erroneously leftover blk_t castsTheodore Ts'o1-7/+5
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-29e2fsck: Try to update on-disk bitmap in e2fsck_get_alloc_block() callbackTheodore Ts'o1-0/+4
The e2fsck_get_alloc_block() callback is used so that if the ext2fs library needs to allocate blocks internally (most notably by the extents functions), e2fsck's internal block usage map is consulted since it is the only thing that can be trusted during a large part of e2fsck's operation. Change it to update the on-disk bitmap if it is loaded. This reduces the number of spurious differences found in pass #5. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-29e2fsck: detect holes in extent-mapped directoriesTheodore Ts'o1-0/+13
Directories are not allowed to be sparse; the code for scanning extent-mapped directories was not calling ext2fs_add_dir_block() for missing directory blocks, so we weren't catching this form of file system corruption. Fix this. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-29e2fsck: Move check to add an index to a directory after fixing i_sizeTheodore Ts'o1-4/+6
The check that determines whether an directory needs to be have an index added to it depends on i_size. So move it after we have fixed up i_size so that we reliable will rehash a directory that needs it, even if its i_size field was originally incorrect. Otherwise, a second run of e2fsck would be needed before the directory gets an index added. Thanks to Mikulas Patocka for providing a sample file system which demonstrated this problem. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-11-29e2fsck: Fix directory with holes even when i_size is wrongTheodore Ts'o1-44/+15
The old method for detecting directories with holes depended on i_size being correct, even though the correct value of i_size hadn't been calculated yet. Hence, a directory inode with holes and an i_size of 0 would require two e2fsck passes to fix completely. The replacement method for determining whether or not ext2fs_add_dir_block() should be called is more reliable, and reduces the size of e2fsck and makes the code more readable as a bonus. Thanks to Mikulas Patocka for providing a sample file system which demonstrated this problem. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-25Convert ext2fs_group_{first,last}_block() to *block2()Theodore Ts'o1-5/+5
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-25Convert to use block group accessor functionsValerie Aurora Henson1-18/+18
Convert direct accesses to use the following block group accessor functions: ext2fs_block_bitmap_loc(), ext2fs_inode_bitmap_loc(), ext2fs_inode_table_loc(), ext2fs_bg_itable_unused(), ext2fs_block_bitmap_loc_set(), ext2fs_inode_bitmap_loc_set(), ext2fs_inode_table_loc_set(), ext2fs_bg_free_inodes_count(), ext2fs_ext2fs_bg_used_dirs_count(), ext2fs_bg_free_inodes_count_set(), ext2fs_bg_free_blocks_count_set(), ext2fs_bg_used_dirs_count_set() Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: Nick Dokos <nicholas.dokos@hp.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-24Merge branch 'maint' into nextTheodore Ts'o1-1/+1
Conflicts: configure configure.in
2009-10-12e2fsck: Fix handling of non-zero i_blocks_high fieldTheodore Ts'o1-1/+10
E2fsck was not properly printing the i_blocks field in filesystem corruption messages, and it was not properly checking i_blocks_hi and i_blocks_lo, either. This commit fixes this. Thanks to Felipe Conteras for pointing this out. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07Convert uses of super->s_*_blocks_count to ext2fs_*_blocks_count()Valerie Aurora Henson1-12/+12
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: Nick Dokos <nicholas.dokos@hp.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07Use ext2fs_file_acl_block() instead of using .i_file_acl directlyValerie Aurora Henson1-6/+8
This provides support for 48-bit file acl blocks. Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07Convert to use io_channel_read_blk64() and io_channel_write_blk64()Valerie Aurora Henson1-4/+4
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-08-22e2fsck: Convert e2fsck to new bitmap interfaceValerie Aurora Henson1-48/+55
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-08-18e2fsck: Only ask to relocate a block group's inode table onceTheodore Ts'o1-1/+2
If multiple blocks of a block group's inode table overlaps with other file system blocks, only ask once for each block group. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-08-18e2fsck: Teach new_table_block() to allocate new itables/bitmaps with FLEX_BGTheodore Ts'o1-3/+29
If the filesystem feature FLEX_BG is enabled, the inode table and bitmap blocks can be located anywhere in the inode table. So for FLEX_BG filesystems, new_table_block() now tries allocate in the block group's flex_bg first, and if there is no space in the local flex_bg, then try to allocate from the whole filesystem. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-06-21Fix encoding for rec_len in directories for >= 64k blocksize file systemsTheodore Ts'o1-4/+6
Previously e2fsprogs interpreted 0 for a rec_len of 65536 (which could occur if the directory block is completely empty in 64k blocksize filesystems), while the kernel interpreted 65535 to mean 65536. The kernel will accept both to mean 65536, and encodes 65535 to be 65536. This commit changes e2fsprogs to match. We add the encoding agreed upon for 128k and 256k filesystems, but we don't enable support for these larger block sizes, since they haven't been fully tested. Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-28libext2fs: add ext2fs_extent_open2number96521-2/+2
The patch below adds a function, ext2fs_extent_open2(), that behaves as ext2fs_extent_open(), but will use the user-supplied inode structure when opening an extent instead of reading the inode from disk. It also changes several of the calls to extent_open() to use this enhancement. Signed-off-by: Nic Case <number9652@yahoo.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-28Add empty function for init_resource_track() and print_resource_track()Ken Chen1-8/+1
in the case of ! defined RESOURCE_TRACK, so that we can clean up #ifdef throughout e2fsck source. Signed-off-by: Ken Chen <kenchen@google.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-05-17e2fsck: Don't crash if an inode with a bad extent header is not clearedTheodore Ts'o1-3/+4
If ext2fs_extent_open() fails due to a corrupt extent header, and the user declines to clear the inode, check_blocks_extents() should bail out; otherwise, it will cause a core dump due a null pointer dereference. Addresses-Sourceforge-Bug: #2791794 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>