resize2fs: fix gcc -Wall nits and valgrind complaints

One of these fixes was triggering failures when running:

./test_scripts --valgrind r_move_itable r_inline_xattr r_resize_inode

It should be a false positive, but it fixing this makes it easier to
see real problems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
contrib/fallocate: add support for punch functionality

Also fix the -o option so it works correctly (instead of core
dumping).

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
configure: clarify message regarding checking if we can link with -static

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck: fix pass5 optimization for bigalloc file systems

Commit 53e3120c18 introduced a regression which would case e2fsck to
overrun an array boundary for bigalloc file systems, and most likely
crash.  Fix this by correctly using blocks instead of clusters when
incrementing the loop counter in the fast path optimization case.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
mke2fs: fix handling of mmp_update_interval option

Make sure the s_mmp_update_interval super block field is set
from the file system parameters block which is passed into the
ext2fs_initialize() function.

Addresses-Lustre-Bug: LU-1888

Signed-off-by: Gregoire Pichon <gregoire.pichon@bull.net>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
libext2fs: fix memory and fd leak in error path of unix_open()

Fix a potential memory leak reported by Li Xi.  In addition, there
were possible error cases where the file descriptor would not be
properly closed, so fix those as well while we're at it.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reported-by:  Li Xi <pkuelelixi@gmail.com>
libext2fs: remove m68k-specific bitops code

The current m68k code was buggy for multiple reasons; first the bfset,
et. al commands interpret the bit number as a signed number, not an
unsigned number.  Secondly, there were missing memory clobbers.  Since
there is no real benefit in using explicit asm's at this point (gcc is
smart enough to optimize the generic C code to use the set/clear/test
bit m68k instruction) fix this bug by removing the m68k specific asm
versions of these functions.

Tested on m68k-linux with e2fsprogs-1.42.6 and gcc-4.6.3 as before.
All tests pass and the debug output looks sane.

I compared the e2fsck binaries from the previous build with this
one.  They had identical .text sizes, and almost the same number
of bit field instructions (obviously compiler-generated), so this
change should have no serious performance implications.

Signed-off-by: Mikael Pettersson <mikpe@it.uu.se>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Schwab <schwab@linux-m68k.org>
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>
libext2fs: ext2fs_extents_fix_parents() should not modify the handle location

Previously, ext2fs_extent_fix_parents() would only avoid modifying the
cursor location associated with the extent handle the cursor was
pointed at a leaf node in the extent tree.  This is because it saved
the starting logical block number of the current extent, but not the
"level" of the extent (where level 0 is the leaf node, level 1 is the
interior node which points at blocks containing leaf nodes, etc.)

Fix ext2fs_extent_fix_parents() so it is guaranteed to not change the
current extent in the handle even if the current extent is not at the
bottom of the tree.

Also add a fix_extent command to the tst_extents program to make it
easier to test this function.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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>
tests: add test of an incorrect interior node in an extent tree

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs: add the ability to manipulate the extent tree directly

This commit adds the functionality which had previously only been in
the tst_extents command to debugfs.  The debugfs command extent_open
will open extent tree of a particular inode, and enables a series of
commands which will allow the user to interact with the extent tree
directly.  Once the extent tree is closed via extent_open(), these
additional commands will be disabled again.

This commit exports two new functions from lib/ext2fs/extent.c which
had previously been statically defined: ext2fs_extent_node_split() and
ext2fs_extent_goto2().

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs: add a makefile rule to build debugfs.static

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: link the test programs with static libraries

Force the use of the static libraries when linking the test program so
that "make check" works when the shared libraries have not been
installed, and so that we test against the version of the libraries in
the source tree.

Reported-by: g.esp@free.fr
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
configure.in: require at least autoconf 2.54

AC_PROG_EGREP requires autoconf 2.54, so bump up the AC_PREREQ
accordingly.

Reported-by: g.esp@free.fr
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: fix spelling typo in texinfo docs

Signed-off-by: Darren Hart <dvhart@infradead.org>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Andreas Dilger <adilger@dilger.ca>
debugfs: add the commands "zap_block" and "block_dump"

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: add make variable to prevent building e2fsck.static package

Setting BUILD_E2FSCK_STATIC=no in rules.custom will prevent the
debian/rules makefile from building a statically-linked e2fsck and
from creating a deb package for it.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: add make variable to pass extra parameters to configure

Setting EXTRA_CONF_FLAGS in rules.custom will pass the extra arguments
to calls of ./configure when building e2fsprogs. This can be used, for
instance, to pass a --libdir argument or similar to the configure
script.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: look for quota.pc and libquota.a from root of install tree

The rules makefile was already using `find' in order to cope with
multi-arch directories under /usr/lib. This patch changes it to look for
those files from the root of the install tree. This allows for
installing to libdirs of /usr/lib64 or /lib or /lib64. There are no
other files with the same names in the package so it's not a problem to
find from the root of the tree.

Signed-off-by: Filipe Brandenburger <filbranden@google.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>