Eric Sandeen [Sat, 22 Nov 2008 15:02:48 +0000 (09:02 -0600)]
e2fsck: ignore differing NEEDS_RECOVERY flag on backup sbs
When we resize online, the primary superblock gets copied to all
the backups, and of course since we're mounted the NEEDS_RECOVERY
flag is set. A subsequent fsck will find the backups have the
NEEDS_RECOVERY flag set while the primary does not, and this
forces a full fsck pass.
I think this flag can be safely ignored in the flag comparisons.
Addresses-Red-Hat-Bugzilla: #471925
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Theodore Ts'o [Tue, 17 Mar 2009 02:16:44 +0000 (22:16 -0400)]
libext2fs: external journal devices should not cause ext2fs_open2 to fail
This fixes a regression introduced in commit 79a9ab14 which caused
attempts to open external journals to fail due to overly strict
filesystem consistency checks.
Jim Meyering [Mon, 23 Feb 2009 17:07:50 +0000 (18:07 +0100)]
remove useless if-before-free tests
In case you're wondering about whether this change is safe from a
portability standpoint, fear not. This has been beaten to death
in other forums. Here are a few threads:
There has been debate about whether it's a good idea from a
performance standpoint, too, but imho you'll have a hard time
finding an instance where this sort of change induces a
measurable performance penalty. If you do, please let me know.
Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Sandeen [Thu, 29 Jan 2009 22:52:13 +0000 (17:52 -0500)]
fix libext2fs info page name
In Red Hat bug #481620 Jerry reported that the libext2fs info page
is not accesable via "info libext2fs" but is via "info libext2fs.info"
and suggested that the following change should fix it.
Additional info from Jerry:
The problem is that makeinfo 4.12 interprets the dot in "libext2fs.info"
to be the end of the description portion of the info entry, even though
it hasn't seen the closing parenthesis yet. Making the reference be to
just "libext2fs" works.
Addresses-Red-Hat-Bugzilla: #481620
Reported-by: Jerry James <loganjerry@gmail.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Sandeen [Thu, 29 Jan 2009 22:46:28 +0000 (17:46 -0500)]
debugfs: fix segfault on "stat" command with no open fs
This is a regression from commit 8fdf29117f922419bd5b3f741e5d554b1d5b8893, which attempts to access
current_fs via a feature check before we check that it's open.
Just moving the feature check below the open check should fix it.
Reported-by: Andrew Hecox <ahecox@redhat.com> Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Sun, 8 Mar 2009 22:56:41 +0000 (18:56 -0400)]
blkid: Add fallback to ext4 for 2.6.29+ kernels if ext2 is not present
Starting in 2.6.29, ext4 can be used to support filesystems without a
journal. So if ext2 is not present, and the kernel version is greater
than 2.6.29, and ext4 is present, return a filesystme type of ext4.
Theodore Ts'o [Fri, 6 Mar 2009 00:40:20 +0000 (19:40 -0500)]
Add support for a new superblock field: s_kbytes_written
This field tracks the lifetime amount of writes to the filesystem. It
will be updated by the kernel as well as by e2fsprogs programs which
write to the filesystem.
Theodore Ts'o [Thu, 22 Jan 2009 21:05:29 +0000 (16:05 -0500)]
e2fsck: Change PR_3_CREATE_LPF_ERROR to be a non-fatal problem
The other problem codes associated with failing to create the
lost+found directory are non-fatal, and this one should be non-fatal
as well. The two places which call e2fsck_get_lost_and_found()
already deal with a failure to create the directory, so there's no
point making this be a fatal error.
Theodore Ts'o [Thu, 22 Jan 2009 21:01:38 +0000 (16:01 -0500)]
libext2fs: Add sanity checks to ext2fs_{block,inode}_alloc_stats
If ext2fs_inode_alloc_stats2() or ext2fs_block_alloc_stats() is passed
an insanely large inode or block number, it's possible for these
functions to overrun an array boundary and cause the calling program
to crash with a memory error.
Detect this case, and since these functions don't return an error
code, print a warning message, much like we do in ext2fs_warn_bitmap2().
Theodore Ts'o [Thu, 22 Jan 2009 20:55:49 +0000 (15:55 -0500)]
ext2fs_new_inode(): Add sanity check to assure a valid inode number
Add a sanity check to makesure that even if the superblock field
s_first_inode is insane, that we won't return an invalid inode number.
(The function will return the error EXT2_ET_INODE_ALLOC_FAIL in that
case.)
Theodore Ts'o [Tue, 20 Jan 2009 18:37:47 +0000 (13:37 -0500)]
ext2fs_get_device_size: Fix error handling
The previous patch would return EFBIG for any failure called from
ext2fs_get_device_size2(). (I didn't merge this fix with the
preceeding commit to allow merges to happen more easily.)
Theodore Ts'o [Tue, 20 Jan 2009 16:49:17 +0000 (11:49 -0500)]
tune2fs: Fix tune2fs -I so it won't corrupt RAID filesystems
If a filesystem is built with the stride extended-option (which is
often used in RAID filesystems to make sure the block and inode
allocation bitmaps don't end up hitting one disk platter harder than
the rest), this can cause tune2fs -I to corrupt the filesystem because
it fails to handle the case where the allocation bitmaps are located
after the inode table, where the inode table needs to grow. Handle
this case correctly.
Theodore Ts'o [Tue, 20 Jan 2009 06:50:07 +0000 (01:50 -0500)]
tune2fs: Don't allow the -I option if the flex_bg feature is enabled
With flex_bg usually the inode table for most block groups are packed
right against each other, so expanding the inode table size needs
special handling that's not currently in tune2fs.
Theodore Ts'o [Tue, 20 Jan 2009 05:46:06 +0000 (00:46 -0500)]
resize2fs: Reserve some extra space for -P/-M for ext4 filesystems
Some extra blocks may be needed to expand some extent allocation trees
while we are shrinking the filesystem. We don't know exactly how
much, so we use a hueristic.
Theodore Ts'o [Tue, 20 Jan 2009 00:30:59 +0000 (19:30 -0500)]
ext2fs_block_iterate2: Preserve the uninit flag in extents
When modifying a block via the block_iterate interface, preserve the
uninit flag in the extent. Resize2fs uses this interface, so we have
to preserve the uninit status when relocating a block.
Theodore Ts'o [Mon, 19 Jan 2009 19:22:52 +0000 (14:22 -0500)]
ext2fs_block_iterate2: Reflect errors from ext2fs_extent_set_bmap to caller
If the callback function tries to change a block, and
ext2fs_extent_set_bmap() fails for some reason (for example, there
isn't enough disk space to split a node and expand the extent tree,
make sure that error is reflected back up to the caller.
Theodore Ts'o [Mon, 19 Jan 2009 14:02:55 +0000 (09:02 -0500)]
resize2fs: Release bitmap and itable blocks in flex_bg filesystems
Previously resize2fs assumed that bitmap and inode table blocks were
always located in their respective block group. However, this is no
longer true with flex_bg. So it is necessary to check all of the
block groups which will be truncated to see if they have metadata
blocks that need to be marked as no longer being in use in the new,
shrunk filesystem.
This bug fixes resize2fs -M, which would otherwise fail because
without the released blocks, there would not be enough space in the
filesystem. This bug also avoids (mostly harmless) filesystem
corruptions reported by e2fsck regarding blocks marked in use but not
actually used (these being the bitmap and inode table blocks
associated with the truncated block groups).
Note: in theory it is possible to have block group N utilize bitmap
and inode table blocks in block group N+X with flex_bg. At the moment
neither mke2fs nor e2fsck will create filesystems like this, which is
good, because resize2fs doesn't handle this case correctly.
Theodore Ts'o [Mon, 19 Jan 2009 13:43:36 +0000 (08:43 -0500)]
resize2fs: Move all required blocks for ext4 filesystems
In the function blocks_to_move(), when checking to see if a block
group's block bitmap is initialized, we need to check the old_fs's
block group descriptors, not the new file system's (already truncated)
group descriptor data structures. Otherwise we will end up
derferencing past the end of the array boundary, and the resulting
garbage value may indicate that the bitmap is uninitialized, and so
all of the blocks in that block group will be skipped, resulting in
some blocks not getting marked as needing relocation.
Theodore Ts'o [Fri, 2 Jan 2009 23:14:42 +0000 (18:14 -0500)]
e2fsck: Fix journal replay for block sizes greater than 8k
E2fsck was using a fixed-size 8k buffer for replaying blocks from the
journal. So attempts to replay a journal on filesystems greater than
8k would cause e2fsck to crash with a segfault.
Thanks to Miao Xie <miaox@cn.fujitsu.com> for reporting this problem.
Theodore Ts'o [Wed, 24 Dec 2008 00:10:43 +0000 (19:10 -0500)]
e2fsck: When repacking directories, leave slack space for more efficiency
If the directory is packed with no slack space, as soon as any new
directory entries are added, leaf nodes end up getting split and
directory ends up getting very inefficient.
Theodore Ts'o [Sun, 16 Nov 2008 15:03:00 +0000 (10:03 -0500)]
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.
Theodore Ts'o [Sat, 15 Nov 2008 05:32:39 +0000 (00:32 -0500)]
tune2fs: Fix inefficient O(n**2) algorithms when expanding the inode size
When running "tune2fs -I 256" on moderate to large filesystems, the
time required to run tune2fs can take many hours (20+ before some
users gave up in disgust). This was due to some O(n**2) and O(n*m)
algorithms in move_block() and inode_scan_and_fix(), respectively.
Theodore Ts'o [Fri, 14 Nov 2008 22:42:27 +0000 (17:42 -0500)]
tune2fs: Update the block group checksums when changing the UUID
Since the block group checksums depend on the UUID, we need to update
the block group checksums when setting the UUID. We only do so if all
of the checksums are correct, however.
Eric Sandeen [Tue, 14 Oct 2008 17:27:15 +0000 (12:27 -0500)]
blkid: recognize ext3 with test_fs set as ext3
It seems that if we have the test_filesystem flag set on an ext3
filesystem(!) on a system which provides ext4, blkid gets confused.
According to the current logic:
* It's not an ext4dev filesystem, because the system provides ext4.
* It's not an ext4 filesystem, because it has no ext4 features.
* It's not an ext3 filesystem, because the test flag is set.
In the end, it's nothing.
blkid should return *something* that is mountable... I'm inclined to
think that ext3 should be the right answer, if no ext4-specific features
are set.
This would mean just dropping the EXT2_FLAGS_TEST_FILESYS test in
probe_ext3(), because ext4 & ext4dev probes have come first already.
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Sandeen [Fri, 10 Oct 2008 22:14:08 +0000 (17:14 -0500)]
e2fsck: exit from preenhalt if IO errors were encountered
If a block device is read-only, e2fsck -p gets into an infinite loop
trying to preenhalt, closing and flushing the fs, which tries to flush
the cache, which gets a write error and calls preenhalt which tries to
close and flush the fs ... ad infinitum.
Per Ted's suggestion just flag the ctx as "exiting" and short-circuit
the infinite loop.
Tested by running e2fsck -p on a block device set read-only by BLKROSET.
Thanks to Vlado Potisk for reporting this.
Addresses-Red-Hat-Bugzilla: #465679
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Sandeen [Fri, 10 Oct 2008 22:38:15 +0000 (17:38 -0500)]
resize2fs: check for bogus new_size
If we don't check for new_size == 0, bogus values send resize2fs into
a tailspin:
resize2fs 1.41.0 (10-Jul-2008)
Illegal block number passed to ext2fs_test_block_bitmap #1 for block bitmap for
/tmp/tmp.lntZtMFvz8/fake-disk
...the same message repeated zillion times...
Probably should see where that loop is, but at any rate we should
error-check parse_num_blocks.
Thanks to Petr Muller for reporting this.
Addresses-Red-Hat-Bugzilla: #465984
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Eric Sandeen [Wed, 8 Oct 2008 18:34:09 +0000 (13:34 -0500)]
e2fsprogs: fix blkid detection of ext4dev as ext4
If only ext4 is available (as a module or in /proc/filesystems)
blkid wasn't properly testing for it, because the time checks
were backwards and always failed. This caused old ext4dev
filesystems to fail to mount as ext4. With this patch it works
fine.
Also, don't try to check for modules on a non-Linux system.
Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Theodore Ts'o [Thu, 2 Oct 2008 00:45:26 +0000 (20:45 -0400)]
libcom_err: Fix file descriptor leak after an exec
Some applications repeatedly re-exec themselves, and if they use the
com_err library, they can leak a file descriptor for each re-exec.
Fix this by setting the close-on-exec flag on the debug file
descriptor. In addition, if the COMERR_DEBUG environment variable
isn't set, don't open the file handle at all.
Theodore Ts'o [Wed, 1 Oct 2008 23:14:06 +0000 (19:14 -0400)]
debugfs: Fix ncheck to print all pathnames for the inodes
The ncheck command in debugfs had a bug where some inodes would not
have their pathnames printed if other inodes had more than one hard
link. Fix this bug and simplify the code by printing all of the
pathnames for the requested inodes.
libcom_err: Use sem_post/sem_init to prevent race conditions
SuSE has been carrying a patch for a long time to prevent a largely
theoretical race condition if a multi-threaded application adds and
removes error tables in multiple threads. Unfortunately SuSE's
approach breaks compatibility by forcing applications to link and
compile with the -pthread option; using pthread mutexes has
historically been problematic.
This commit fixes things in a more portable way by using
sem_post/sem_wait instead, which is an older interface that doesn't
require the pthreads library. Linux happens to implement
sem_post/sem_init using futexes, and -lrt ends up pulling in
-lpthread, but the advantage of using POSIX semaphores is that
applications don't have to be built using -pthread, unlike the use of
pthread mutexes.
The add_error_table() and remove_error_table() interfaces are the
preferred interfaces and locking protection have been added to only
these interfaces. I have not added locking protection to the
generated initialize_xxx_error_table and initialize_xxx_error_table_r
interfaces, to avoid adding symbol dependencies that would cause a
library to fail to work when linking against older com_err libraries
that do not export et_list_lock() and et_list_unlock(). Threaded
applications shouldn't be using these interfaces in any case.
debian: Use dietlibc when possible for building e2fsck.static
This fixes a regression introduced in commit 4f2e8f19 where we
inadvertently disabled the use of dietlibc on all architectures,
instead of just on those architectures which didn't support dietlibc.
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.)
This fixes a regression that was introduced in commit dcc91e10 (it
showed up first in e2fsprogs 1.40.7). Since we weren't freeing the
filesystem handle, ext2fs_open2() was returning EBUSY, and so this
caused a failure in the code that would automatically determine the
filesystem block size when only the superblock number was specified by
the user.
This was discussed in http://ubuntuforums.org/showthread.php?t=789323,
and Matthias Bannach pointed this out to me, for which I am very
grateful.
Unbreak build if directory renamed from e2fsprogs.
gen-tarball currently assumes that the top-level directory is called
e2fsprogs, which breaks building the tarball if it's named differently.
Since we have already computed the basename, let's use it.