Whamcloud - gitweb
tools/e2fsprogs.git
8 years agoblkid: fix ZFS device detection
Andreas Dilger [Sun, 6 Mar 2016 00:38:31 +0000 (17:38 -0700)]
blkid: fix ZFS device detection

While the main blkid functionality is in util-linux, there is still
use for blkid on non-Linux platforms.

Fix the ZFS device detection by looking at multiple uberblocks to
see if any are present, rather than looking for the ZFS boot block
which is not always present.

There are slots for up to 128 uberblocks, but the first 4 are not
written to disk on a newly-formatted filesystem, so check several
of them at different offsets within the uberblock array.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoFix build system to be compatible with BSD pmake
Theodore Ts'o [Sat, 2 Jan 2016 02:44:12 +0000 (21:44 -0500)]
Fix build system to be compatible with BSD pmake

This fixes a number of incompatibilities which caused maint branch to
fail to build on on FreeBSD.  Also fix the Makefile in the tests
directory so that "make -jN check" works correctly on FreeBSD.

Previously the Makefile in the tests directory used a construct which
was specific to GNU Make, which which silently expanded to an empty
list, which caused "make check" to be a no-op when running using BSD's
pmake.  This Makefile has been changed to use the != macro assignment
syntax which is common to GNU make and BSD pmake.  It's technically
not completely portable (it will not be recognized by Solaris's ccs
make, for example), but most other operating systems ship GNU make
(Solaris, AIX), or BSD pmake (*BSD, Mac OS) as either the primary or
alternative make utility that this should an acceptable compromise,
since it makes running all of tests using something like "make -j8
check" or "make -j16 check" run *much* faster.

There are still some caveats if using BSD pmake; in particular, if the
configure script is run on a system which has GNU make (installed as
gmake on FreeBSD for example), the configure script will find it, and
enable some GNU make features in the Makefile, and the generated
makefiles *must* be built using gmake.  However, if isolated build
jail / chroot is used which only has pmake, the Makefiles should now
work with pmake.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoext2fs: work around FreeBSD header breakage
Theodore Ts'o [Sat, 2 Jan 2016 01:12:22 +0000 (20:12 -0500)]
ext2fs: work around FreeBSD header breakage

FreeBSD 10.2 will blow up compiling its own header files in sys/file.h
if _XOPEN_SOURCE is defined.

In file included from tdb.c:59:
/usr/include/sys/file.h:209:2: error: unknown type name 'u_int'
        u_int   xf_flag;        /* flags (see fcntl.h) */
                ^
1 error generated.

This is despite the fact that POSIX.1 requires comforming applications
to define _XOPEN_SOURCE (to different numbers depending on the version
of POSIX.1 the program is expecting to work against).  See section
2.2.1 in POSIX.1 for chapter and verse.

Work around this by removing the _XOPEN_SOURCE declaration.  This will
cause compiler warnings (and will cause builds against some versions
of Solaris to break), so only do this for FreeBSD.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoe2fsck: fix e2fsck -fD directory truncation
Andreas Dilger [Mon, 30 Nov 2015 20:26:35 +0000 (15:26 -0500)]
e2fsck: fix e2fsck -fD directory truncation

When an extent-mapped directory is compacted by "e2fsck -fD" and
frees enough leaf blocks that it loses an extent tree index block,
the old e2fsck_rehash_dir->ext2fs_block_iterate3->write_dir_block()
code would not free the extent block, which would result in the
extent tree becoming corrupted when it is written out.

    Pass 1: Checking inodes, blocks, and sizes
    Inode 17825800, end of extent exceeds allowed value
            (logical block 710, physical block 570459684, len 1019)

This results in loss of a whole index block of directory leaf blocks
and maybe thousands or millions of files in lost+found.

Fix e2fsck_rehash_dir() to call ext2fs_punch() to free the blocks
at the end of the directory instead of trying to handle this itself
while writing out the directory.  That properly handles all of the
cases of updating the extent tree as well as accounting for blocks
that are released (both leaf blocks and index blocks).

Add a test case for compacting the directory to be smaller than the
index block that originally caused the corruption.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agolibext2fs: fix block-mapped file punch
Andreas Dilger [Mon, 30 Nov 2015 20:26:21 +0000 (15:26 -0500)]
libext2fs: fix block-mapped file punch

If ext2fs_punch() was called with "end = ~0ULL" to indicate truncate
to the end of file it tried to compute "count" for ext2fs_punch_ind()
based on "start" and "end", but incorrectly passed "count = ~0U" even
when "start" was non-zero, causing an overflow in some cases.

The calling convention for ext2fs_punch_ind() was also gratuitously
different from ext2fs_punch() and ext2fs_punch_extent(), passing
"count" instead of "end" as the last parameter.  Fix this by passing
it "end" like the other functions, and handle "count" internally.

Add checks to ext2fs_punch_ind() if "end" is at or beyond the 2^32
indirect block limit so the 32-bit internal variables don't overflow.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoe2fsck: zap extent-format inode with no extent header
Darrick J. Wong [Mon, 30 Nov 2015 20:22:07 +0000 (15:22 -0500)]
e2fsck: zap extent-format inode with no extent header

The kernel requires all inodes with the extent flag set to have a
valid extent tree header in i_block.  The ext2fs_extent_open2 prefers
to initialize the header if i_block is zeroed, but e2fsck never writes
the new header to disk.  Since the kernel won't create inodes with the
flag and no header anyway, zap such files.

Reported-by: Bo Branten <bosse@acc.umu.se>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agotune2fs: warn if the filesystem journal is dirty
Jim Garlick [Mon, 30 Nov 2015 17:13:39 +0000 (12:13 -0500)]
tune2fs: warn if the filesystem journal is dirty

Running tune2fs on a filesystem with an unrecovered journal can
cause the tune2fs settings changes in the superblock to be reverted
when the journal is replayed if it contains an uncommitted copy of
the superblock.  Print a warning if this is detected so that the
user isn't surprised if it happens.

Signed-off-by: Jim Garlick <garlick@llnl.gov>
Updated message printed to include steps to replay journal.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agolibext2fs: fix tst_badblocks buffer overrun
Andreas Dilger [Mon, 30 Nov 2015 17:09:44 +0000 (12:09 -0500)]
libext2fs: fix tst_badblocks buffer overrun

The test2[] array is not 0-terminated and the create_test_list() for
loop does not terminate properly at the end of this array, but
continues until it hits the 0 at the end of test3[].

Reported-by: Hanno Boeck <hanno@hboeck.de>
Addresses: https://bugzilla.kernel.org/show_bug.cgi?id=104311
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoe2fsck: do not read EA header beyond the end of an inode
Artemiy Volkov [Mon, 30 Nov 2015 17:03:52 +0000 (12:03 -0500)]
e2fsck: do not read EA header beyond the end of an inode

In check_inode_extra_space(), if we attempt to read an EA header at
the end of the extra space, in a corrupted filesystem it may result in
a read beyond the bounds of the inode. Add a check to prevent this.

Reproduced by running ./test_one --valgrind f_write_ea_toobig_extra_isize.

Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Acked-by: Darrick J. Wong <darrick.wong@oracle.com>
8 years agochattr: fix typo in a manpage
Jan Kara [Mon, 30 Nov 2015 16:56:55 +0000 (11:56 -0500)]
chattr: fix typo in a manpage

Signed-off-by: Jan Kara <jack@suse.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoe2fsck: skip quota update when interrupted
Andreas Dilger [Sat, 14 Nov 2015 01:10:27 +0000 (18:10 -0700)]
e2fsck: skip quota update when interrupted

There is a bug in how e2fsck handles being interrupted by CTRL-C.
If CTRL-C is pressed to kill e2fsck rather than e.g. kill -9, then
the interrupt handler sets E2F_FLAG_CANCEL in the context but doesn't
actually kill the process.  Instead, e2fsck_pass1() checks this flag
before processing the next inode.

If a filesystem is running in fix mode (e2fsck -fy) is interrupted,
and the quota feature is enabled, then the quota file will still be
written to disk even though the inode scan was not complete and the
quota information is totally inaccurate.  Even worse, if the Pass 1
inode and block scan was not finished, then the in-memory block
bitmaps (which are used for block allocation during e2fsck) are also
invalid, so any blocks allocated to the quota files may corrupt other
files if those blocks were actually used.

  e2fsck 1.42.13.wc3 (28-Aug-2015)
  Pass 1: Checking inodes, blocks, and sizes
  ^C[QUOTA WARNING] Usage inconsistent for ID 0:
      actual (6455296, 168) != expected (8568832, 231)
  [QUOTA WARNING] Usage inconsistent for ID 695:
      actual (614932320256, 63981) != expected (2102405386240, 176432)
  Update quota info for quota type 0? yes

  [QUOTA WARNING] Usage inconsistent for ID 0:
      actual (6455296, 168) != expected (8568832, 231)
  [QUOTA WARNING] Usage inconsistent for ID 538:
      actual (614932320256, 63981) != expected (2102405386240, 176432)
  Update quota info for quota type 1? yes

  myth-OST0001: e2fsck canceled.
  myth-OST0001: ***** FILE SYSTEM WAS MODIFIED *****

There may be a desire to flush out modified inodes and such that have
been repaired, so that restarting an interrupted e2fsck will make
progress, but the quota file update is plain wrong unless at least
pass1 has finished, and the journal recreation is also dangerous if
the block bitmaps have not been fully updated.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agolibext2fs: fix parents when modifying extents
Darrick J. Wong [Sat, 15 Mar 2014 15:36:34 +0000 (11:36 -0400)]
libext2fs: fix parents when modifying extents

In ext2fs_extent_set_bmap() and ext2fs_punch_extent(), fix the parents
when altering either end of an extent so that the parent nodes reflect
the added mapping.

There's a slight complication to using fix_parents: if there are two
mappings to an lblk in the tree, the value of handle->path->curr can
point to either extent afterwards), which is documented in a comment.

Some additional color commentary from Darrick:

  In the _set_bmap() case, I noticed that the "remapping last block in
  extent" case would produce symptoms if we are trying to remap a
  block from "extent" to "next_extent", and the two extents are
  pointed to by different index nodes.  _extent_replace(...,
  next_extent) updates e_lblk in the leaf extent, but because there's
  no _extent_fix_parents() call, the index nodes never get updated.

  In the _punch_extent() case, we conclude that we need to split an
  extent into two pieces since we're punching out the middle.  If the
  extent is the last extent in the block, the second extent will be
  inserted into a new leaf node block.  Without _fix_parents(), the
  index node doesn't seem to get updated.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
8 years agoFix typo in the ext4(5) man page
Theodore Ts'o [Wed, 9 Sep 2015 14:53:49 +0000 (10:53 -0400)]
Fix typo in the ext4(5) man page

Addresses-Debian-Bug: #798425

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agodebugfs: handle out of memory condition
Tobias Stoeckmann [Mon, 20 Jul 2015 14:52:28 +0000 (10:52 -0400)]
debugfs: handle out of memory condition

If malloc fails, properly handle the error condition.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
8 years agoutil: avoid off-by-one on long symlinks
Tobias Stoeckmann [Mon, 20 Jul 2015 14:42:40 +0000 (10:42 -0400)]
util: avoid off-by-one on long symlinks

readlink does not nul terminate its result, therefore one extra byte
has to be taken into account.

Signed-off-by: Tobias Stoeckmann <tobias@stoeckmann.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agotune2fs.8: update maximum journal size
Phillip Susi [Sat, 23 May 2015 20:49:45 +0000 (16:49 -0400)]
tune2fs.8: update maximum journal size

The man page for tune2fs still listed the upper limit for the journal
as 102,400 blocks.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodebugfs: fix several errors and add assertions in the set_fields command
Konstantin Khlebnikov [Sat, 20 Jun 2015 01:54:09 +0000 (21:54 -0400)]
debugfs: fix several errors and add assertions in the set_fields command

Fix copy-n-paste errors:
* remove duplicate "lastcheck" and "min_extra_isize"
* fix pointer for "first_error_line" and "last_error_line"
* remove superblock field "inodes_count" from inode fields
* add null-termination for mmp_fields

Add assertions for catching such errors in the future.
Mark true aliases with flag "FLAG_ALIAS" and suppress assert for them.

Signed-off-by: Konstantin Khlebnikov <khlebnikov@yandex-team.ru>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomke2fs: prompt for user verification for "-S"
Andreas Dilger [Sat, 20 Jun 2015 01:34:02 +0000 (21:34 -0400)]
mke2fs: prompt for user verification for "-S"

Prompt for user verification before rewriting the filesystem
superblocks using the "-S" (super-only) option.  This should
not normally be used at all, so adding the extra verification
will probably save a few user filesystems in the future.  Since
this is something that should only be done in rare cases under
user supervision, wait for user input rather than proceeding
automatically after a timeout.

Update the mke2fs man page to more fully explain the many
dangers of this option.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomisc: fix alignment warnings on ARM
Andreas Dilger [Fri, 22 May 2015 22:40:51 +0000 (16:40 -0600)]
misc: fix alignment warnings on ARM

Some temporary char buffers allocated on the stack are not properly
aligned when typecast to a structure containing __u32 or __u64 types,
and this can cause alignment warnings on ARM and other alignment
sensitive architectures, and potential slowdowns to do fixups.

Fix the buffer alignment to avoid such issues.

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=680090

Reported-by: Gordan Bobic <gordan.bobic@gmail.com>
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsprogs: use $DUMPE2FS in resize_test script
Eric Sandeen [Sat, 23 May 2015 22:39:04 +0000 (18:39 -0400)]
e2fsprogs: use $DUMPE2FS in resize_test script

Use $DUMPE2FS in resize tests to be sure it's testing
the in-tree dumpe2fs, not the system dumpe2fs (which may
not even be there...)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodebian: remove trailing spaces from control.in file
Theodore Ts'o [Mon, 18 May 2015 06:14:55 +0000 (02:14 -0400)]
debian: remove trailing spaces from control.in file

This were causing lintian failures.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoUpdate release notes, etc. for final 1.42.13 release v1.42.13
Theodore Ts'o [Mon, 18 May 2015 01:10:07 +0000 (21:10 -0400)]
Update release notes, etc. for final 1.42.13 release

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoMerge remote-tracking branch 'origin/maint' into maint
Theodore Ts'o [Mon, 18 May 2015 01:25:45 +0000 (21:25 -0400)]
Merge remote-tracking branch 'origin/maint' into maint

9 years agoUpdate translation template file
Theodore Ts'o [Mon, 18 May 2015 00:34:58 +0000 (20:34 -0400)]
Update translation template file

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoAdd the Danish translation file from the Translation Project
Theodore Ts'o [Mon, 18 May 2015 00:27:50 +0000 (20:27 -0400)]
Add the Danish translation file from the Translation Project

The Danish translation is now up to 829/1317 messages, which is much
better than it had been before, and better than some of the current
translations which we are including in the e2fsprogs distribution.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update es.po (from translationproject.org)
Antonio Ceballos [Mon, 18 May 2015 00:21:40 +0000 (20:21 -0400)]
po: update es.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update eo.po (from translationproject.org)
Benno Schulenberg [Mon, 18 May 2015 00:21:39 +0000 (20:21 -0400)]
po: update eo.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update de.po (from translationproject.org)
Philipp Thomas [Mon, 18 May 2015 00:21:39 +0000 (20:21 -0400)]
po: update de.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update ca.po (from translationproject.org)
Àngel Mompó [Mon, 18 May 2015 00:21:39 +0000 (20:21 -0400)]
po: update ca.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: use PROMPT_NONE for FUTURE_SB_LAST_*_FUDGED problems
Theodore Ts'o [Sun, 29 Mar 2015 01:39:54 +0000 (21:39 -0400)]
e2fsck: use PROMPT_NONE for FUTURE_SB_LAST_*_FUDGED problems

This allows us to print a message warning the user that there is
something funny going on with their hardware clock (probably time zone
issues caused by trying to be compatible with legacy OS's such as
Windows), without triggering a full file system check.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: fix potential buffer overflow in closefs()
Theodore Ts'o [Fri, 6 Feb 2015 17:46:39 +0000 (12:46 -0500)]
libext2fs: fix potential buffer overflow in closefs()

The bug fix in f66e6ce4446: "libext2fs: avoid buffer overflow if
s_first_meta_bg is too big" had a typo in the fix for
ext2fs_closefs().  In practice most of the security exposure was from
the openfs path, since this meant if there was a carefully crafted
file system, buffer overrun would be triggered when the file system was
opened.

However, if corrupted file system didn't trip over some corruption
check, and then the file system was modified via tune2fs or debugfs,
such that the superblock was marked dirty and then written out via the
closefs() path, it's possible that the buffer overrun could be
triggered when the file system is closed.

Also clear up a signed vs unsigned warning while we're at it.

Thanks to Nick Kralevich <nnk@google.com> for asking me to look at
compiler warning in the code in question, which led me to notice the
bug in f66e6ce4446.

Addresses: CVE-2015-1572

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agobuildsystem: use 'chmod a-w' instead of 'chmod -w'
Enrico Scholz [Fri, 23 Jan 2015 17:05:17 +0000 (12:05 -0500)]
buildsystem: use 'chmod a-w' instead of 'chmod -w'

'chmod -w' is not portable and can break the build:

| chmod: chmod: ss_err.h: new permissions are r--rw-r--, not r--r--r--
| ss_err.h: new permissions are r--rw-r--, not r--r--r--
| chmod: ss_err.c: new permissions are r--rw-r--, not r--r--r--
| make[2]: *** [ss_err.h] Error 1

This happens because 'chmod -w' is affected by umask. Issue can be
reproduced e.g. by

$ mkdir /tmp/foo
$ setfacl -m d:m:rwx /tmp/foo

$ umask 022
$ touch /tmp/foo/x
$ chmod -w /tmp/foo/x
chmod: /tmp/foo/x: new permissions are r--rw-r--, not r--r--r--

Signed-off-by: Enrico Scholz <enrico.scholz@sigma-chemnitz.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: fix corruption of Hurd filesystems
Justus Winter [Fri, 23 Jan 2015 15:15:57 +0000 (10:15 -0500)]
e2fsck: fix corruption of Hurd filesystems

Previously, e2fsck accessed the field osd2.linux2.l_i_file_acl_high
field without checking that the filesystem is indeed created for
Linux.  This lead to e2fsck constantly complaining about certain
nodes:

i_file_acl_hi for inode XXX (/dev/console) is 32, should be zero.

By "correcting" this problem, e2fsck would clobber the field
osd2.hurd2.h_i_mode_high.

Properly guard access to the OS dependent fields.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoFix clang warning and a resource leak
Darrick J. Wong [Mon, 19 Jan 2015 21:31:49 +0000 (16:31 -0500)]
Fix clang warning and a resource leak

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: close the progress_fd in the logfile child process
Theodore Ts'o [Tue, 13 Jan 2015 00:42:29 +0000 (19:42 -0500)]
e2fsck: close the progress_fd in the logfile child process

If e2fsck.conf's logging feature is enabled, and e2fsck is being run
via systemd-fsck, there will be a deadlock since systemd-fsck is
waiting for progress_fd pipe to be closed, instead of waiting for the
fsck process to exit --- and so the logfile child process won't exit
until it can write out the logfile, and systemd won't continue the
boot process so that the file system can be remounted read-write.
Oops.

Addresses-Debian-Bug: #775234

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: add sanity check for an invalid itable_used value in inode scan code
Theodore Ts'o [Fri, 26 Dec 2014 04:18:32 +0000 (23:18 -0500)]
libext2fs: add sanity check for an invalid itable_used value in inode scan code

If the number of unused inodes is greater than number of inodes a
block group, this can cause an e2fsck -n run of the file system to
crash.

We should add more checks to e2fsck to detect this case directly, but
this will at least protect progams (tune2fs, dump, etc.) which use the
inode_scan abstraction from crashing on an invalid file system.

Addresses-Debian-Bug: #773795

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agobadblocks: Limit maximum number of bad blocks
Jan Kara [Mon, 15 Dec 2014 01:55:44 +0000 (20:55 -0500)]
badblocks: Limit maximum number of bad blocks

Currently maximum number of bad blocks is not limited in any way.
However our code can really handle at most INT_MAX/2 bad blocks (for
larger numbers binary search indexes start overflowing). So report
number of bad blocks is just too big instead of plain segfaulting.

It won't be too hard to raise the limit but I don't think there's any
real use for disks with over 1 billion of bad blocks...

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoresize2fs: don't require fsck to print min size
Eric Sandeen [Mon, 15 Dec 2014 00:08:59 +0000 (19:08 -0500)]
resize2fs: don't require fsck to print min size

My previous change ended up requiring that the filesystem
be fsck'd after the last mount, even if we are only querying
the minimum size.  This is a bit draconian, and it burned
the Fedora installer, which wants to calculate minimum size
for every filesystem in the box at install time, which in turn
requires a full fsck of every filesystem.

Try this one more time, and separate out the tests to make things
a bit more clear.  If we're only printing the min size, don't
require the fsck, as this is a bit less dangerous/critical.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomisc: fix infinite loop when finding the start of the hugefile start range
Darrick J. Wong [Wed, 3 Dec 2014 03:00:04 +0000 (22:00 -0500)]
misc: fix infinite loop when finding the start of the hugefile start range

When looking for the start of the hugefile range, the 'next' variable
is incorrectly decremented.  If we happened to find a single free
block, the effect of this decrement is that blk == next, which means
that we never modify the loop control variable, so get_start_block
never returns.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agotune2fs: fix memory leak in inode_scan_and_fix()
Xiaoguang Wang [Wed, 3 Dec 2014 02:06:40 +0000 (21:06 -0500)]
tune2fs: fix memory leak in inode_scan_and_fix()

When we use ext2fs_open_inode_scan() to iterate inodes and finish
jobs, we also need a ext2fs_close_inode_scan(scan) operation, but in
inode_scan_and_fix(), we forgot to call it, fix this error.

Signed-off-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodebugfs: fix typo in message
Bernhard M. Wiedemann [Tue, 2 Dec 2014 20:23:55 +0000 (15:23 -0500)]
debugfs: fix typo in message

Signed-off-by: Bernhard M. Wiedemann <bwiedemann@suse.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: don't allow alloc_stats on bad inode/block numbers
Darrick J. Wong [Mon, 17 Nov 2014 22:59:42 +0000 (17:59 -0500)]
libext2fs: don't allow alloc_stats on bad inode/block numbers

Don't allow callers to feed bad block/inode numbers to
ext2fs_*_alloc_stats2, because evil callers (<cough>resize2fs<cough>)
can corrupt library state this way, leading to a crash.

(There will be a subsequent patch to resize2fs to fix its bad
behavior.)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: fix endian handling error; reduce fragmentation some
Darrick J. Wong [Sat, 8 Nov 2014 02:27:53 +0000 (21:27 -0500)]
libext2fs: fix endian handling error; reduce fragmentation some

If we're going to read the "nr - 1" entry in an indirect block for use
as a "goal" input to the block allocator, we need to byteswap the
entry.  While we're at it, if we're allocating blocks for the zeroth
entry in the indirect block, we might as well use the indirect block
as the starting point to try to reduce fragmentation.

(d_fallocate_blkmap will test this...)

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodumpe2fs: don't crash when the user provides no block device argument
Darrick J. Wong [Sat, 8 Nov 2014 02:26:14 +0000 (21:26 -0500)]
dumpe2fs: don't crash when the user provides no block device argument

If the user doesn't provide any arguments, the guard fails to run and
the whole thing segfaults on ext2fs_open2().  Don't do that.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: fix dangling pointer when dir_info array is resized
Darrick J. Wong [Wed, 5 Nov 2014 16:14:26 +0000 (11:14 -0500)]
e2fsck: fix dangling pointer when dir_info array is resized

e2fsck uses an array to store directory usage information during pass
3; the usage context also contains a pointer to the last directory
looked up.  When expanding the dir_info array, this cache pointer
needs to be cleared if the array resize changed the pointer location,
or else we'll later walk off the end of this dead pointer.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Sami Liedes <sami.liedes@iki.fi>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: fix reporting of unknown htree block inode number
Darrick J. Wong [Wed, 5 Nov 2014 16:10:31 +0000 (11:10 -0500)]
e2fsck: fix reporting of unknown htree block inode number

Sami Liedes reports that e2fsck fails to report the correct directory
inode number during a pass2 check for unexpected HTREE blocks.
Provide the inode number in the problem report.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Sami Liedes <sami.liedes@iki.fi>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: don't memcpy identical pointers when writing a cache block
Darrick J. Wong [Tue, 4 Nov 2014 16:43:08 +0000 (11:43 -0500)]
libext2fs: don't memcpy identical pointers when writing a cache block

Sami Liedes found a scenario where we could memcpy incorrectly:

If a block read fails during an e2fsck run, the UNIX IO manager will
call the io->read_error routine with a pointer to the internal block
cache.  The e2fsck read error handler immediately tries to write the
buffer back out to disk(!), at which point the block write code will
try to copy the buffer contents back into the block cache.  Normally
this is fine, but not when the write buffer is the cache itself!

So, plumb in a trivial check for this condition.  A more thorough
solution would pass a duplicated buffer to the IO error handlers, but
I don't know if that happens frequently enough to be worth the extra
point of failure.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Sami Liedes <sami.liedes@iki.fi>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: directory iteration mustn't walk off the buffer end
Darrick J. Wong [Sat, 25 Oct 2014 20:56:42 +0000 (13:56 -0700)]
libext2fs: directory iteration mustn't walk off the buffer end

When we're iterating a directory, the loop control code reads the
length of the next directory record, failing to account for the fact
that there must be at least 8 bytes (the minimum size of a directory
entry) left in the buffer to read the next directory record.  Fix the
loop conditional so that we don't read off the end of the buffer.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: Sami Liedes <sami.liedes@iki.fi>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: fix endian handling of ext3_extent_header
Eric Sandeen [Thu, 23 Oct 2014 21:27:32 +0000 (16:27 -0500)]
libext2fs: fix endian handling of ext3_extent_header

This turned up when trying to resize a filesystem containing
a file with many extents on PPC64.

Fix all locations where ext3_extent_header members aren't
handled in an endian-safe manner.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
9 years agoutil: allow subst to build on systems that do not have utimes()
Theodore Ts'o [Mon, 20 Oct 2014 02:02:48 +0000 (22:02 -0400)]
util: allow subst to build on systems that do not have utimes()

Make subst more portable so it can deal with such oler systems that do
not have utimes().  Note that it is important that subst build
correctly without an autoconf-generated config.h (since that is what
happens on a cross-compile), as well as using whatever features are
available as determined by autoconf when doing a native build.  We
currently assume the presence of utime(), but not utimes() or
futimes().

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomke2fs: fix man page discussion of usage type defaults
Eric Whitney [Mon, 13 Oct 2014 08:19:24 +0000 (04:19 -0400)]
mke2fs: fix man page discussion of usage type defaults

The man page description of the file system size thresholds used by
mke2fs to select a usage type when not otherwise specified by the -T
switch does not match the code.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoresize2fs: fix fs->blocksize dereference after fs has been freed
Theodore Ts'o [Wed, 8 Oct 2014 16:09:35 +0000 (12:09 -0400)]
resize2fs: fix fs->blocksize dereference after fs has been freed

Commit 77255cf36944b introduced a use after free bug.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: fix free pointer dereferences
Theodore Ts'o [Wed, 8 Oct 2014 15:18:41 +0000 (11:18 -0400)]
e2fsck: fix free pointer dereferences

Commit 47fee2ef6a23a introduces some free pointer dereference bugs by
not clearing ctx->fs after calling ext2fs_close_free().

Reported-by: Matthias Andree <mandree@FreeBSD.org>
Cc: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsprogs: add large_file to base mkfs features
Eric Sandeen [Wed, 1 Oct 2014 12:33:54 +0000 (08:33 -0400)]
e2fsprogs: add large_file to base mkfs features

large_file (> 2G) support has been around since at least kernel 2.4;
mkfs of any sufficiently large filesystem sets it "accidentally"
when the resize inode exceeds 2G.  This leaves very small
filesystems lacking the feature, which potentially changes
their behavior & codepaths the first time a > 2G file gets
written.

There's really no reason to be making fresh filesystems which
strive to keep compatibility with 10 year old kernels; just
enable large_file at mkfs time.  This is particularly obvious
for ext4 fielsystems, which set huge_file by default, but not
necessarily large_file.

If old-kernel compatibility is desired, mke2fs.conf can be
modified locally to remove the feature.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomisc: fix build breakage with configure --disable-uuidd --enable-profile
Theodore Ts'o [Fri, 19 Sep 2014 04:26:56 +0000 (00:26 -0400)]
misc: fix build breakage with configure --disable-uuidd --enable-profile

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoconfigure: disable uuidd by default if libuuid is disabled
Theodore Ts'o [Fri, 19 Sep 2014 04:26:26 +0000 (00:26 -0400)]
configure: disable uuidd by default if libuuid is disabled

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomke2fs: don't depend on <linux/version.h>
Theodore Ts'o [Fri, 19 Sep 2014 04:04:24 +0000 (00:04 -0400)]
mke2fs: don't depend on <linux/version.h>

Define the KERNEL_VERSION macro explicitly instead of using
<linux/version.h>, since it's not available when using dietlibc.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomisc: zero s_jnl_blocks when adding journal online or removing external journal
Darrick J. Wong [Fri, 19 Sep 2014 01:24:26 +0000 (21:24 -0400)]
misc: zero s_jnl_blocks when adding journal online or removing external journal

Erase s_jnl_blocks when removing an external journal, or adding an
internal journal online.  We can't add the backup for the internal
journal because we have no good way to get the indirect block or ETB
addresses, so the best we can do is hope that the user runs e2fsck,
which will correct that.  We are motivated to erase during external
journal removal to state emphatically that there's no journal.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: thomas_reardon@hotmail.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agofix build with configure --disable-uuid --disable-blkid --enable-profile
Theodore Ts'o [Fri, 19 Sep 2014 01:11:33 +0000 (21:11 -0400)]
fix build with configure --disable-uuid --disable-blkid --enable-profile

We need to make sure PROFILED_LIBUUID and PROFILED_LIBBLKID are
defined when we are using the system uuid and blkid libraries.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoDon't clear BUILD_CFLAGS and BUILD_LDFLAGS when cross-compiling
Michael Forney [Mon, 15 Sep 2014 18:30:00 +0000 (14:30 -0400)]
Don't clear BUILD_CFLAGS and BUILD_LDFLAGS when cross-compiling

Signed-off-by: Michael Forney <forney@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoMerge remote-tracking branch 'origin/maint' into maint
Theodore Ts'o [Thu, 11 Sep 2014 16:26:27 +0000 (12:26 -0400)]
Merge remote-tracking branch 'origin/maint' into maint

9 years agoe2fsck: notice when the realloc of dir_info fails
Theodore Ts'o [Thu, 11 Sep 2014 16:24:07 +0000 (12:24 -0400)]
e2fsck: notice when the realloc of dir_info fails

If the reallocation of dir_info fails, we will eventually cause e2fsck
to fail with an internal error.  So if the realloc fails, print a
message and bail out with a fatal error early when at the time of the
reallocation failure.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agocompile_et: Allow user to override ET_DIR
Michael Forney [Fri, 5 Sep 2014 22:43:07 +0000 (15:43 -0700)]
compile_et: Allow user to override ET_DIR

Signed-off-by: Michael Forney <forney@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoApply LDFLAGS when building tests
Michael Forney [Fri, 5 Sep 2014 22:42:32 +0000 (15:42 -0700)]
Apply LDFLAGS when building tests

Signed-off-by: Michael Forney <forney@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agotests: Add to LD_LIBRARY_PATH instead of overriding
Michael Forney [Fri, 5 Sep 2014 22:35:13 +0000 (15:35 -0700)]
tests: Add to LD_LIBRARY_PATH instead of overriding

Signed-off-by: Michael Forney <forney@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodebugfs: add better error checking when printing extended attributes
Theodore Ts'o [Fri, 29 Aug 2014 18:20:21 +0000 (14:20 -0400)]
debugfs: add better error checking when printing extended attributes

Check to make sure the length of the name and value fields in the
extended attribute don't result in overrun the bounds of the inode.

Addresses-Coverity-Bug: #709517

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoUpdate release notes, etc. for final 1.42.12 release v1.42.12
Theodore Ts'o [Fri, 29 Aug 2014 12:58:27 +0000 (08:58 -0400)]
Update release notes, etc. for final 1.42.12 release

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update vi.po (from translationproject.org)
Trần Ngọc Quân [Fri, 29 Aug 2014 12:46:03 +0000 (08:46 -0400)]
po: update vi.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update uk.po (from translationproject.org)
Yuri Chornoivan [Fri, 29 Aug 2014 12:46:03 +0000 (08:46 -0400)]
po: update uk.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update sv.po (from translationproject.org)
Göran Uddeborg [Fri, 29 Aug 2014 12:46:03 +0000 (08:46 -0400)]
po: update sv.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update pl.po (from translationproject.org)
Jakub Bogusz [Fri, 29 Aug 2014 12:46:03 +0000 (08:46 -0400)]
po: update pl.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update nl.po (from translationproject.org)
Benno Schulenberg [Fri, 29 Aug 2014 12:46:03 +0000 (08:46 -0400)]
po: update nl.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update fr.po (from translationproject.org)
Samuel Thibault [Fri, 29 Aug 2014 12:46:02 +0000 (08:46 -0400)]
po: update fr.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update cs.po (from translationproject.org)
Petr Pisar [Fri, 29 Aug 2014 12:46:02 +0000 (08:46 -0400)]
po: update cs.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomke2fs: complain if bigalloc and hugefiles_align_disk is incompatible
Theodore Ts'o [Wed, 27 Aug 2014 13:27:54 +0000 (09:27 -0400)]
mke2fs: complain if bigalloc and hugefiles_align_disk is incompatible

If the starting partition offset is incompatible with the bigalloc
cluster size, complain and exit, instead of creating a file which
would have a logical to physical block mapping which breaks the
cluster alignment requirement.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsprogs.pot: update POT-Creation-Date
Theodore Ts'o [Tue, 26 Aug 2014 20:34:24 +0000 (16:34 -0400)]
e2fsprogs.pot: update POT-Creation-Date

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: fix spelling error (strage vs storage)
Theodore Ts'o [Tue, 26 Aug 2014 13:40:06 +0000 (09:40 -0400)]
e2fsck: fix spelling error (strage vs storage)

Reported-by: Philipp Thomas <pth@suse.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsprogs: add supported file attributes to ext4.5 manpage
Eric Sandeen [Tue, 26 Aug 2014 01:02:18 +0000 (21:02 -0400)]
e2fsprogs: add supported file attributes to ext4.5 manpage

The chattr(1) manpage now refers users to filesystem-specific
manpages for details on supported attributes, so add those to
ext4.5.

I've left out oddities like being able to set the compressed
or no-tail-packing flags, or setting data journaling on ext2.

That behavior seems like a bug, not a feature.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoInterim updates of release notes, etc. in preparation for 1.42.12 release
Theodore Ts'o [Mon, 25 Aug 2014 14:30:53 +0000 (10:30 -0400)]
Interim updates of release notes, etc. in preparation for 1.42.12 release

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update sv.po (from translationproject.org)
Göran Uddeborg [Mon, 25 Aug 2014 14:05:34 +0000 (10:05 -0400)]
po: update sv.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update fr.po (from translationproject.org)
Samuel Thibault [Mon, 25 Aug 2014 14:05:34 +0000 (10:05 -0400)]
po: update fr.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update es.po (from translationproject.org)
Antonio Ceballos [Mon, 25 Aug 2014 14:05:34 +0000 (10:05 -0400)]
po: update es.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agopo: update cs.po (from translationproject.org)
Petr Pisar [Mon, 25 Aug 2014 14:05:34 +0000 (10:05 -0400)]
po: update cs.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomke2fs: improve the error message when a non-existent file is specified
Theodore Ts'o [Mon, 25 Aug 2014 03:54:37 +0000 (23:54 -0400)]
mke2fs: improve the error message when a non-existent file is specified

If the user does not specify the file system size, and the file does
not exist, give an error message like this:

   The file /tmp/foo.img does not exist and no size was specified.

instead of this:

    Creating regular file /tmp/foo.img
    mke2fs: Device size reported to be zero.  Invalid partition specified, or
    partition table wasn't reread after running fdisk, due to
    a modified partition being busy and in use.  You may need to reboot
    to re-read your partition table.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agomke2fs.8.in: explain how the fs-size parameter is interpreted
Theodore Ts'o [Mon, 25 Aug 2014 03:53:33 +0000 (23:53 -0400)]
mke2fs.8.in: explain how the fs-size parameter is interpreted

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoresize2fs: clarify the size of blocks in resize2fs's messages
Theodore Ts'o [Mon, 25 Aug 2014 03:23:41 +0000 (23:23 -0400)]
resize2fs: clarify the size of blocks in resize2fs's messages

Addresses-Debian-Bug: #758029

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoresize2fs.8.in: clarify when on-line resizing is supported
Theodore Ts'o [Mon, 25 Aug 2014 02:40:43 +0000 (22:40 -0400)]
resize2fs.8.in: clarify when on-line resizing is supported

Addresses-Debian-Bug: #726760

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodumpe2fs: complain if extra arguments are given on the command line
Theodore Ts'o [Mon, 25 Aug 2014 02:31:03 +0000 (22:31 -0400)]
dumpe2fs: complain if extra arguments are given on the command line

Addresses-Debian-Bug: #758074

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agodebugfs: fix set_inode_field block[IND|DIND|TIND]
Theodore Ts'o [Tue, 19 Aug 2014 12:27:59 +0000 (08:27 -0400)]
debugfs: fix set_inode_field block[IND|DIND|TIND]

After we determine that we can't parse the array value as an integer,
we need to restore the square brackets to the field name, so that we
can find a match with block[IND], block[DIND], and block[TIND] in the
inode field table.

Reported-by: Jun He <jhe@cs.wisc.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agofilefrag: fix extent count calculation when using FIBMAP
Theodore Ts'o [Wed, 13 Aug 2014 19:59:20 +0000 (15:59 -0400)]
filefrag: fix extent count calculation when using FIBMAP

The extent count calculation works correctly with the FIBMAP ioctl in
verbose (-v) mode, but without the verbose option, the calculation was
broken because we weren't properly updating the fm_ext data structures
in non-verbose mode.

Addresses-Launchpad-Bug: #1356496

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agotests: convert use of md5sum to crcsum
Theodore Ts'o [Tue, 12 Aug 2014 18:37:19 +0000 (14:37 -0400)]
tests: convert use of md5sum to crcsum

The following tests were using md5sum: i_e2image, u_mke2fs, and
u_tune2fs.  Convert them to use crcsum for better portability (not all
environments have md5sum; some might have sha1sum instead :-)

For our purposes crcsum is quite sufficient.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: don't flush the FS unless it's actually dirty
Darrick J. Wong [Tue, 12 Aug 2014 18:19:37 +0000 (14:19 -0400)]
e2fsck: don't flush the FS unless it's actually dirty

ext2fs_flush2() unconditionally writes the block group descriptors to
disk even if the underlying FS isn't marked dirty.  This causes the
following error message on a fsck -n run:

e2fsck 1.43-WIP (09-Jul-2014)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
Error writing block 2 (Attempt to write block to filesystem resulted in short write).  Ignore error? no

Error writing block 2 (Attempt to write block to filesystem resulted in short write).  Ignore error? no

Error writing file system info: Attempt to write block to filesystem resulted in short write

Since ext2fs_close2() only calls flush if the dirty flag is set,
modify e2fsck to exhibit the same behavior so that we don't spit out
write errors for a read only check.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoe2fsck: flush out the superblock and bitmaps before printing final messages
Theodore Ts'o [Sun, 10 Aug 2014 21:20:36 +0000 (17:20 -0400)]
e2fsck: flush out the superblock and bitmaps before printing final messages

A user who sees the message

***** REBOOT LINUX *****

or

***** FILE SYSTEM WAS MODIFIED *****

might think that e2fsck was complete even though we haven't finished
writing out the superblock or bitmap blocks, and then either forcibly
reboot or power cycle the box, or yank the USB key out while the
storage device is still being written (before e2fsck exits).

So rearrange the exit path of e2fsck so that we flush out the dirty
superblock/bg descriptors/bitmaps before we print the final message.
Also clean up this code so that the flow of control is easier to
understand, and add error checking to catch any errors (normally
caused by I/O errors writing to the disk) for these final writebacks.

Addresses-Debian-Bugs: #757543, #757544
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: Dan Jacobson <jidanni@jidanni.org>
9 years agotests: add the r_meta_bg_shrink test
Theodore Ts'o [Sat, 9 Aug 2014 17:05:21 +0000 (13:05 -0400)]
tests: add the r_meta_bg_shrink test

This test checks to make sure resize2fs can properly handle a file
system which started life as a normal ext4 file system and then was
grown to a size where meta_bg was enabled, and then shrunk back below
the point where the meta_bg format is still needed.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agotests: add f_first_meta_bg_too_big test
Theodore Ts'o [Sat, 9 Aug 2014 17:03:43 +0000 (13:03 -0400)]
tests: add f_first_meta_bg_too_big test

The test verifies that e2fsck can properly fix a file system where the
value of s_first_meta_bg in the superblock is larger than the number
of block group descriptors in the file system.  E2fsck will fix this
by clearing the meta_bg feature.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agotests: make sure MKE2FS_FIRST_META_BG is unset while running tests
Theodore Ts'o [Sat, 9 Aug 2014 17:02:36 +0000 (13:02 -0400)]
tests: make sure MKE2FS_FIRST_META_BG is unset while running tests

If the developer has set the MKE2FS_FIRST_META_BG environment
variable, this can cause test failures.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agoresize2fs: disable the meta_bg feature if necessary
Theodore Ts'o [Sat, 9 Aug 2014 16:33:11 +0000 (12:33 -0400)]
resize2fs: disable the meta_bg feature if necessary

When shrinking a file system, if the number block groups drops below
the point where we started using the meta_bg layout, disable the
meta_bg feature and set s_first_meta_bg to zero.  This is necessary to
avoid creating an invalid/corrupted file system after the shrink.

Addresses-Debian-Bug: #756922

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reported-by: Marcin Wolcendorf <antymat+debian@chelmska.waw.pl>
Tested-by: Marcin Wolcendorf <antymat+debian@chelmska.waw.pl>
9 years agoe2fsck: fix file systems with an overly large s_first_meta_bg
Theodore Ts'o [Sat, 9 Aug 2014 16:31:04 +0000 (12:31 -0400)]
e2fsck: fix file systems with an overly large s_first_meta_bg

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: avoid buffer overflow if s_first_meta_bg is too big
Theodore Ts'o [Sat, 9 Aug 2014 16:24:54 +0000 (12:24 -0400)]
libext2fs: avoid buffer overflow if s_first_meta_bg is too big

If s_first_meta_bg is greater than the of number block group
descriptor blocks, then reading or writing the block group descriptors
will end up overruning the memory buffer allocated for the
descriptors.  Fix this by limiting first_meta_bg to no more than
fs->desc_blocks.  This doesn't correct the bad s_first_meta_bg value,
but it avoids causing the e2fsprogs userspace programs from
potentially crashing.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
9 years agolibext2fs: have UNIX IO manager use pread64/pwrite64
Theodore Ts'o [Fri, 8 Aug 2014 20:42:05 +0000 (16:42 -0400)]
libext2fs: have UNIX IO manager use pread64/pwrite64

Commit baa3544609da3c ("libext2fs: have UNIX IO manager use
pread/pwrite) causes a breakage on 32-bit systems where off_t is
32-bits for file systems larger than 4GB.  Fix this by using
pread64/pwrite64 if possible, and if pread64/pwrite64 is not present,
using pread/pwrite only if the size of off_t is at least as big as
ext2_loff_t.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>