Commit Graph

299 Commits (7ef1b8b4248ab099f4ac4c921fe8c0def831f255)

Author SHA1 Message Date
Theodore Ts'o 2ffccc82c4 Merge branch 'maint' into next
Conflicts:
	lib/ext2fs/csum.c
2013-12-26 00:30:56 -05:00
Theodore Ts'o f404167dda Clean up sparse warnings
Mostly by adding static and removing excess extern qualifiers.  Also
convert a few remaining non-ANSI function declarations to ANSI.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-16 18:56:36 -05:00
Theodore Ts'o 2d3df8dc7f Merge branch 'maint' into next
Conflicts:
	lib/ext2fs/newdir.c
2013-12-12 15:39:14 -05:00
Darrick J. Wong 3b6c0938ec libext2fs: fix tests that set LARGE_FILE
For each site where we test for a large file (> 2GB) and set the
LARGE_FILE feature, use a helper function to make the size test
consistent with the test that's in e2fsck.  This fixes the fsck
complaints when we try to create a 2GB journal (not so hard with 64k
block size) and fixes the incorrect test in fileio.c.

Reviewed-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-12 12:08:48 -05:00
Theodore Ts'o ef429f5968 Merge branch 'maint' into next 2013-12-04 00:23:19 -05:00
Andreas Dilger 2fe2d408a4 mmp: fix 64-bit handling of s_mmp_block
Fix the checking of s_mmp_block in e2fsck_pass1() and
ext2fs_mmp_read() to handle the high 32 bits of s_blocks_count.
Remove redundant check of s_mmp_block in do_dump_mmp() right before
ext2fs_mmp_read() is called.

Also fix s_blocks_count_hi in check_backup_super_block(), since it
cannot use the ext2fs_blocks_count() helper easily.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-03 20:22:16 -05:00
Theodore Ts'o 2fae17697a Merge branch 'maint' into next
Conflicts:
	e2fsck/pass2.c
	e2fsck/pass3.c
2013-12-03 00:24:39 -05:00
Theodore Ts'o 3971bfe878 e2fsck: use dgrp_t for block group numbers
Make e2fsck consistently use dgrp_t for bloc group numbers to avoid
-Wconveresion noise.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-02 23:21:31 -05:00
Theodore Ts'o 3c7c6d73f1 e2fsck: use problem_t to suppress some -Wconversion warnings
All code which stores a problem code should use the problem_t type.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-12-02 20:52:43 -05:00
Theodore Ts'o e337e7fad8 Merge branch 'maint' into next
Conflicts:
	e2fsck/problem.c
	e2fsck/rehash.c
	e2fsck/super.c
2013-10-12 22:26:28 -04:00
Darrick J. Wong 4dbfd79d14 e2fsprogs: fix blk_t <- blk64_t assignment mismatches
Fix all the places where we should be using a blk64_t instead of a
blk_t.  These fixes are more severe because 64bit values could be
truncated silently.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-10-07 09:51:48 -04:00
Theodore Ts'o fc9f162eea Merge branch 'maint' into next 2013-09-09 20:49:49 -04:00
Eric Whitney 085757fcc2 e2fsck: don't report uninit extents past EOF invalid
Commit d3f32c2db8 introduced a regression that caused e2fsck failures
in xfstests generic 013, 070, 083, 091, and 263.  Uninitialized
extents created by fallocate() at the end of file with the
FALLOC_FL_KEEP_SIZE flag were identified as invalid.  However,
because the file size is not increased when FALLOC_FL_KEEP_SIZE is
used, uninitialized extents can correctly contain blocks located past
the end of file.

Fix this by filtering out possible invalid extents if they are
uninitialized and extend past the block containing the end of file.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-09-09 10:53:06 -04:00
Theodore Ts'o dd50ef8743 e2fsck: check extent-mapped directories with really large logical blocks
E2fsck was missing a check for directories with logical blocks so
large that i_size > 2GB.  Without this check the test image found in
the new test f_toobig_extent_dir will cause e2fsck to die with a
memory allocation failure:

Error storing directory block information (inode=12, block=0, num=475218819): Memory allocation failed
e2fsck: aborted

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reported-by: Andrey Melnikov <temnota.am@gmail.com>
2013-07-28 21:03:00 -04:00
Jan Kara 70f4632b62 libext2fs: provide functions to safely access name_len and file_type
Accessing name_len (and file_type) in ext4_dir_entry structure is
somewhat problematic because on big endian architecture we need to now
whether we are really dealing with ext4_dir_entry (which has u16
name_len which needs byte swapping) or ext4_dir_entry_2 (which has u8
name_len which must not be byte swapped).

Currently the code is somewhat surprising and name_len is always
treated as u16 and byte swapped (flag EXT2_DIRBLOCK_V2_STRUCT isn't
ever used) and then masking of name_len is used to access real
name_len or file_type. Doing things this way in applications using
libext2fs is unexpected to say the least (more natural is to type
struct ext4_dir_entry * to struct ext4_dir_entry_2 * but that gives
wrong results on big endian architectures. So provide helper functions
that give endian-safe access to these fields. Also convert users in
e2fsprogs to use these functions.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2013-06-08 17:03:05 -04:00
Theodore Ts'o e07b71f294 Merge branch 'maint' 2013-06-08 17:02:54 -04:00
David Jeffery d3f32c2db8 e2fsck: detect invalid extents at the end of an extent-block
e2fsck does not detect extents which are outside their location in the
extent tree.  This can result in a bad extent at the end of an extent-block
not being detected.

From a part of a dump_extents output:

 1/ 2  37/ 68 143960 - 146679 123826181               2720
 2/ 2   1/  2 143960 - 146679 123785816 - 123788535   2720
 2/ 2   2/  2 146680 - 147583 123788536 - 123789439    904 Uninit <-bad extent
 1/ 2  38/ 68 146680 - 149391 123826182               2712
 2/ 2   1/  2 146680 - 147583     18486 -     19389    904
 2/ 2   2/  2 147584 - 149391 123789440 - 123791247   1808

e2fsck does not detect this bad extent which both overlaps another, valid
extent, and is invalid by being beyond the end of the extent above it in
the tree.

This patch modifies e2fsck to detect this invalid extent and remove it.

Signed-off-by: David Jeffery <djeffery@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
2013-06-06 22:53:31 -04:00
Theodore Ts'o 581ecb6d88 Merge branch 'maint' into next
Conflicts:
	e2fsck/pass1b.c
	e2fsck/rehash.c
	lib/ext2fs/crc32c.c
	lib/ext2fs/gen_bitmap64.c
	misc/tune2fs.c
2013-05-19 21:45:16 -04:00
Theodore Ts'o 68477355a9 e2fsck: fix gcc -Wall nits
Perhaps the most serious fix up is a type-punning warning which could
result in miscompilation with overly enthusiastic compilers.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-05-19 21:36:31 -04:00
Theodore Ts'o 29f6dfea52 Merge branch 'maint' into next 2013-05-16 11:05:37 -04:00
Eric Sandeen 10fc3a63d9 e2fsprogs: allow 0-length xattr values in e2fsck
e2fsck thinks that this:

# touch mnt/testfile1
# setfattr -n "user.test" mnt/testfile1

results in a filesystem with corruption:

Pass 1: Checking inodes, blocks, and sizes
Extended attribute in inode 12 has a value size (0) which is invalid
Clear? yes

but as far as I can tell, there is absolutely nothing wrong with
a 0-length value on an extended attribute.  Just remove the check.

Reported-by: David Shaw <dshaw@jabberwocky.com>
Reported-by: Harald Reindl <h.reindl@thelounge.net>
Addresses-Red-Hat-Bugzilla: #557959
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2013-04-25 00:14:33 -04:00
Theodore Ts'o b9b5e43ea8 Merge branch 'maint' into next
Conflicts:
	RELEASE-NOTES
	debian/changelog
	lib/ext2fs/crc32c.c
	lib/ext2fs/rw_bitmaps.c
	resize/resize2fs.c
	version.h
2013-01-01 18:50:26 -05:00
Theodore Ts'o e3507739e4 Fix gcc -Wall nits
This fixes the last set of gcc -Wall complaints.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2013-01-01 13:28:27 -05:00
Theodore Ts'o ab83252174 Merge branch 'maint' into next
Conflicts:
	e2fsck/problem.c
	e2fsck/problem.h
2012-12-24 10:50:20 -05:00
Theodore Ts'o 29e8e74e02 e2fsck: make sure the extent tree is consistent after bogus node in the tree
Commit 789bd401c3 ("e2fsck: fix incorrect interior node logical start
values") surfaced a bug where if e2fsck finds and removed an invalid
node in the extent tree, i.e.:

Inode 12 has an invalid extent node (blk 22, lblk 0)
Clear? yes

It was possible for starting logical blocks found in the interior
nodes of the extent tree.  Commit 789bd401c3 added the ability for
e2fsck to discover this problem, which resulted in the test
f_extent_bad_node to fail when the second pass of e2fsck reported the
following complaint:

Interior extent node level 0 of inode 12:
Logical start 0 does not match logical start 3 at next level.  Fix? yes

This patch fixes this by adding a call to ext2fs_extent_fix_parents()
after deleting the bogus node in the extent tree.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-12-20 18:37:01 -05:00
Eric Sandeen 789bd401c3 e2fsck: fix incorrect interior node logical start values
An index node's logical start (ei_block) should
match the logical start of the first node (index
or leaf) below it.  If we find a node whose start
does not match its parent, fix all of its parents
accordingly.

If it finds such a problem, we'll see:

Pass 1: Checking inodes, blocks, and sizes
Interior extent node level 0 of inode 274258:
Logical start 3666 does not match logical start 4093 at next level.  Fix<y>?

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-12-20 14:07:56 -05:00
Theodore Ts'o ccea20f62d Merge branch 'maint' into next
Conflicts:
	misc/tune2fs.c
2012-11-29 19:54:46 -05:00
Theodore Ts'o 2ae49fd0cc e2fsck: optimize pass1 for CPU time
Optimize e2fsck pass 1 by marking entire extents as being in use at a
time, instead of block by block.  This optimization only works for
non-bigalloc file systems for now (it's tricky to handle bigalloc file
systems since this code is also responsible for dealing with blocks
that are not correctly aligned within a cluster).  When the
optimization works, the CPU savings can be significant: ove a full CPU
minute for a mostly full 4T disk.

Addresses-Google-Bug: #7534813

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
2012-11-27 12:37:49 -05:00
Theodore Ts'o 82372e32de ext4: fix rehashing of the lost+found directory
Commit 07307114de didn't correctly handle the lost+found directory
when it added support for metadata checksums.  First of all,
e2fsck_get_lost_and_found() assumed that the inode_dir_map bitmap was
initialized, and it wasn't when it was called earlier by a change in
that commit.  Secondly, it's important that lost+found dirctory is
processed in case its directory checksums are incorrect, but should
preserve any empty dirctory blocks so there space available for e2fsck
to reconnect any orphan inodes.

Fix these problems, to fix test failures: f_holedir2 and f_rehash_dir

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-08-15 14:49:01 -04:00
Darrick J. Wong 5e07cb280f e2fsck: check extended attribute block checksums
Verify the checksums of separate extended attribute blocks and offer
to clear it if there is a mismatch.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:44 -04:00
Darrick J. Wong 39f5659ae3 libext2fs: verify and calculate extended attribute block checksums
Calculate and verify the checksum for separate (i.e. not in the inode)
extended attribute blocks; the checksum lives in the header.

[ Merged in change from Tao so that we always use the fs checksum seed
  for the xattr blocks. ]

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Tao Ma <boyu.mt@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 20:47:44 -04:00
Darrick J. Wong 81683c6a32 libext2fs: add checksums to the end of directory leaf nodes
Introduce small structures for recording directory tree checksums, and
some API changes to support writing out directory blocks with
checksums.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-08-02 17:27:43 -04:00
Darrick J. Wong 07307114de e2fsck: verify htree root/node checksums
Check htree internal node checksums.  If broken, ask user to clear
the htree index and recreate it later.

[ Move the check for not rehashing the lost+found directory to pass1
  so that we don't end up truncating lost+found when the metadata
  checksum feature is enabled. -- TYT ]

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-08-02 17:27:30 -04:00
Darrick J. Wong 1e2372b3ae e2fsck: verify extent tree blocks and clear the bad ones
When we encounter an extent tree block that passes the header check
but fails the checksum, offer to clear just that extent block instead
of failing the whole tree, which results in the entire inode being
wiped out.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 19:18:04 -04:00
Darrick J. Wong b9cde40d4d e2fsck: verify and correct inode checksums
Detect mismatches of the inode and checksum, and prompt the user to
fix the situation.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 18:52:04 -04:00
Darrick J. Wong 91db7e206d libext2fs: read and write full size inodes
Change libext2fs to read and write full-size inodes in preparation for
the metadata checksumming patchset, which will require this.  Due to
ABI compatibility requirements, this change must be hidden from client
programs.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-30 17:42:15 -04:00
Andreas Dilger 2d2abcc646 e2fsck: rename "bool" variables
Since "bool" is a valid C type, declarations of the form "int bool"
will cause compiler errors if <stdbool.h> is included.  Rename these
variables to avoid this name clash.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-07-14 19:43:20 -04:00
Theodore Ts'o 9c40d14841 e2fsck: only check for zero-length leaf extents
The on-disk format for interior nodes in the extent tree does not
encode the length of each entry in the interior node; instead, it is
synthesized/simulated by the extent library code in libext2fs.
Unfortunately, this simulation is not perfect; in particular it does
not work for the last extent in the extent tree if there are
uninitialized blocks allocated using fallocate with
FALLOC_FL_KEEP_SIZE, and it leads to e2fsck incorrectly complaining
about an invalid zero-length extent.

We only need to worry about the extent length for the leaves of the
tree, since it is there were we are checking an on-disk value, as
opposed to a software-generated simulation.  So restrict the check of
extent length to leaf nodes in the extent tree.

Reported-by: Tao Ma <tm@tao.ma>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-06-11 00:25:45 -04:00
Theodore Ts'o 9b01faa8b2 e2fsck: fix precedence bug in built-in quota support
The operator precedence bug means that we might pay atteion to
s_grp_quota_inum even if the RO_COMPAT_QUOTA feature flag is clear.
However, fortunately, this is unlikely to happen in practice.

Cc: Aditya Kali <adityakali@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-05-21 22:08:13 -04:00
Lukas Czerner 010dc7b90d e2fsck: remove EXT4_EOFBLOCKS_FL flag handling
We've decided to remove EOFBLOCKS_FL from the ext4 file system entirely,
because it is not actually very useful and it is causing more problems
than it solves. We're going to remove it from e2fsprogs first and then
after the new e2fsprogs version is common enough we can remove the
kernel part as well.

This commit changes e2fsck to not check for EOFBLOCKS_FL. Instead we
simply search for initialized extents past the i_size as this should not
happen. Uninitialized extents can be past the i_size as we can do
fallocate with KEEP_SIZE flag.

Also remove the EXT4_EOFBLOCKS_FL from lib/ext2fs/ext2_fs.h since it is
no longer needed.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2012-03-22 19:42:11 -04:00
Theodore Ts'o 26c09eb814 e2fsck: check for zero length extent
If an extent has e_len set to zero, the kernel will oops with a
BUG_ON.  Unfortunately, e2fsck wasn't catching this case.  The kernel
needs to be fixed to notice this case and call ext4_error() instead of
failing an assertion check, but e2fsck should catch this case and
repair it (by deleting the errant extent).

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2012-03-11 23:31:38 -04:00
Theodore Ts'o 830b44f438 e2fsck: use different bitmap types as appropriate
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-18 01:12:44 -05:00
Theodore Ts'o 24c91184d6 e2fsck: fix use of uninitialized value in the MMP code
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-12-16 15:36:40 -05:00
Kazuya Mio 66df14687d e2fsck: fix the max size calculation for non-extent file
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-11-25 21:31:09 -05:00
Theodore Ts'o 0c80c44bd0 libext2fs: ext2fs_[set_]file_acl_block needs to check for 64-bit feature flag
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-10-16 20:46:49 -04:00
Theodore Ts'o 96a8afa7c1 e2fsck: check for invalid bad block inode
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-28 18:34:33 -04:00
Andreas Dilger 0f5eba7501 ext2fs: add multi-mount protection (INCOMPAT_MMP)
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-25 01:55:23 -04:00
Theodore Ts'o d1154eb460 Shorten compile commands run by the build system
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-18 17:34:37 -04:00
Eric Sandeen f85a9ae639 e2fsck: Don't store old_op from ehandler_operation if we don't restore it.
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-16 18:43:05 -04:00
Theodore Ts'o 89efc88e65 libext2fs: add metadata checksum and snapshot feature flags
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-09-16 10:24:09 -04:00
Aditya Kali 624e4a6466 e2fsck: add support for checking the built-in quota files
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-08-31 16:31:13 -04:00
Theodore Ts'o 95a7f15f46 e2fsck: teach e2fsck how to deal with bigalloc in non-extent-mapped inodes
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-10 16:25:55 -04:00
Andreas Dilger 0bd0e59320 misc: use EXT2_I_SIZE() consistently to get size
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-07-08 20:52:59 -04:00
Theodore Ts'o b2e6c86d61 mke2fs, e2fsck: fix i_blocks handling for bigalloc file systems
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-16 10:12:43 -04:00
Andreas Dilger cf5301d7f2 misc: clean up compiler warnings
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-11 10:58:25 -04:00
Theodore Ts'o 44fe08f1fa e2fsck: add basic bigalloc support to check (but not yet repair) file systems
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-06-10 18:58:16 -04:00
Theodore Ts'o b70506bffb e2fsck: Set i_blocks_hi when correcting the i_blocks field in pass #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-09-24 22:57:06 -04:00
Valerie Aurora Henson 6dc64392c0 e2fsck: Fix up to be 64-bit block number safe
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-13 17:00:00 -04:00
Theodore Ts'o 97d26ce9e3 Merge branch 'maint' into next
Conflicts:
	e2fsck/journal.c
	e2fsck/pass1.c
	e2fsck/pass2.c
	misc/mke2fs.c
2010-06-07 12:42:40 -04:00
Eric Sandeen ae2272f845 e2fsck: correct test for EOFBLOCKS
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-19 14:55:29 -04:00
Theodore Ts'o e6238d3708 e2fsck: Explicitly reject extents that begin at physical block 0 as illegal
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-14 18:06:40 -04:00
Theodore Ts'o ee74cf16b5 e2fsck: Fix segmentation fault when checking a file system
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-13 19:00:41 -04:00
Eric Sandeen 65d71894c9 e2fsck: make block counting variable in pass1 64 bits
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 8a8f36540b 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-13 13:33:53 -04:00
Theodore Ts'o a6217f5ae2 e2fsck: Fix a number of problems that were inappropriately using PROMPT_ABORT
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-12 18:58:53 -04:00
Theodore Ts'o 2291fbb035 e2fsck: Check for cases where EOFBLOCKS_FL is unnecessarily set
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-05-10 10:29:14 -04:00
Theodore Ts'o d9af85b50b Revert "e2fsck: fix spurious complaints about i_size caused by preallocated blocks"
This reverts commit 0ea910997b.

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-04-08 15:51:10 -04:00
Theodore Ts'o 19f433a521 e2fsck: Fix segmentation fault when checking a file system
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-17 13:32:52 -04:00
Theodore Ts'o c5b23f6c0e Merge branch 'maint' into next 2010-03-15 18:53:45 -04:00
Eric Sandeen 4ffafee26c e2fsck: don't complain about i_size for known blocks past EOF
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-24 11:24:37 -05:00
Theodore Ts'o cc84d866e2 Merge branch 'maint' into next
Conflicts:
	e2fsck/pass1.c
2010-02-10 18:20:58 -05:00
Nick Dokos 1ec42a00a5 e2fsck: Fix the check if a file is really a directory to understand extents
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-02-05 10:41:42 -05:00
Theodore Ts'o 2d07b3ad98 Merge branch 'maint' into next
Conflicts:
	configure
	lib/ext2fs/alloc_tables.c
	misc/mke2fs.c
2010-01-31 18:49:08 -05:00
Theodore Ts'o 2884320016 e2fsck: Remove some erroneously leftover blk_t casts
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2010-01-30 21:15:36 -05:00
Theodore Ts'o 8a2cbe2c6d e2fsck: Try to update on-disk bitmap in e2fsck_get_alloc_block() callback
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-29 01:24:06 -05:00
Theodore Ts'o 4607ef7d53 e2fsck: detect holes in extent-mapped directories
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-29 01:03:04 -05:00
Theodore Ts'o a49249d2e3 e2fsck: Move check to add an index to a directory after fixing i_size
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-29 01:03:04 -05:00
Theodore Ts'o 4dbe79bcf3 e2fsck: Fix directory with holes even when i_size is wrong
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-11-29 01:02:46 -05:00
Theodore Ts'o b49f78fe6e Convert ext2fs_group_{first,last}_block() to *block2()
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-10-25 21:24:06 -04:00
Valerie Aurora Henson d7cca6b06f Convert to use block group accessor functions
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-25 21:43:47 -04:00
Theodore Ts'o 72a729dbf9 Merge branch 'maint' into next
Conflicts:
	configure
	configure.in
2009-10-24 15:14:54 -04:00
Theodore Ts'o 8a8f36540b e2fsck: Fix handling of non-zero i_blocks_high field
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-10-12 21:59:37 -04:00
Valerie Aurora Henson 4efbac6fed Convert uses of super->s_*_blocks_count to ext2fs_*_blocks_count()
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-07 20:46:34 -04:00
Valerie Aurora Henson a63745e81c Use ext2fs_file_acl_block() instead of using .i_file_acl directly
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-07 22:29:45 -04:00
Valerie Aurora Henson 24a117abd0 Convert to use io_channel_read_blk64() and io_channel_write_blk64()
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-09-07 21:14:24 -04:00
Valerie Aurora Henson c5d2f50dee e2fsck: Convert e2fsck to new bitmap interface
Signed-off-by: Valerie Aurora Henson <vaurora@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-08-22 22:29:02 -04:00
Theodore Ts'o 9a7fe4bdc9 e2fsck: Only ask to relocate a block group's inode table once
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-18 23:14:03 -04:00
Theodore Ts'o 617446e4aa e2fsck: Teach new_table_block() to allocate new itables/bitmaps with FLEX_BG
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-08-18 23:06:30 -04:00
Theodore Ts'o 8a48035095 Fix encoding for rec_len in directories for >= 64k blocksize file systems
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-06-21 21:07:38 -04:00
number9652 84b239aea4 libext2fs: add ext2fs_extent_open2
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-28 16:33:38 -04:00
Ken Chen 9facd076ae Add empty function for init_resource_track() and print_resource_track()
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-28 09:55:10 -04:00
Theodore Ts'o 0a68b181c1 e2fsck: Don't crash if an inode with a bad extent header is not cleared
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>
2009-05-17 08:42:52 -04:00
Theodore Ts'o 911ec62615 e2fsck: On a 32-bit filesystem, make sure i_file_acl_high is zero
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2009-04-23 21:31:16 -04:00
Theodore Ts'o 7518c17686 e2fsck: Fix an unhandled corruption case in scan_extent_node()
A corrupted interior node in an extent tree would cause e2fsck to
crash with the error message:

Error1: Corrupt extent header on inode 107192
Aborted (core dumped)

Handle this and related failures when scanning an inode's extent tree
more robustly.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-12-25 22:42:38 -05:00
Theodore Ts'o d5a74ff10b e2fsck: Fix double-counting of non-contiguous extent-based inodes
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-12-22 01:23:59 -05:00
Theodore Ts'o 100d4701d5 e2fsck: Enhance fragcheck report with file/directory information
Report whether a fragmented inode is a directory or a file, as this is
highly useful for determining what is going on with an ext4 filesystem.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-12-08 22:00:13 -05:00
Theodore Ts'o ce44d8cafa e2fsck: In verbose mode, distinguish between fragmented directories/files
Track the number of non-contiguous files and directories so we can
give more detailed information in verbose mode.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-12-08 21:33:11 -05:00
Theodore Ts'o 03fa6f8ae2 Fix various signed/unsigned gcc warnings
Some of these could affect filesystems between 2^31 and 2^32-1 blocks.

Thanks to Valerie Aurora Henson for pointing out the problems in
lib/ext2fs/alloc_tables.c, which led me to do a "make gcc-wall" scan
over the source tree.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-11-16 10:06:59 -05:00
Theodore Ts'o 0eeec8ac61 Fix compiling under diet libc
Some recent changes had caused diet libc support to bitrot.  Fix up
missing header files and other portability fixups needed for dietlibc.
(Many of these changes also improve general portability.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-09-12 09:10:39 -04:00
Theodore Ts'o efc6f628e1 Remove trailing whitespace for the entire source tree
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-27 23:07:54 -04:00
Theodore Ts'o 5dd77dbe5a Add support for with empty directory blocks in 64k blocksize filesystems
The rec_len field in the directory entry is 16 bits, so if the
filesystem is completely empty, rec_len of 0 is used to designate
65536, for the case where the directory entry takes the entire 64k
block.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2008-08-25 21:08:19 -04:00