libext2fs: make fs->group_desc opaque

To prevent direct array indexing of fs->group_desc[i] (because the
group_desc may be a different size for different filesystems) make it
an opaque pointer that may only be accessed through the accessor
functions in blknum.c.  The type itself is still available in a public
header; if we have a group_desc that we know is one type or another,
it's ok to access its fields directly.  This change only prevents us
from indexing off fs->group_desc[i] directly.

Old-style applications who don't want to change their source code can
(as a temporary short-term hack) #define EXT2FS_OLD_32_COMPAT before
including ext2fs.h.

Change the accessors in blknum.c to use ext4fs_group_desc(), a version
of ext2fs_group_desc() which returns a ext4_group_desc pointer.

This simplifies and collapses a fair bit of code in blknum.c

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Add support for Next3 snapshot superblock fields to dumpe2fs and debugfs

We also support for byte-swapping the Next3 fields, although the
current Next3 implementation doesn't support big-endian systems.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Fix Makefile dependencies for test programs in lib/ext2fs

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Add superblock fields which track first and most recent fs errors

Add superblock fields which track where and when the first and most
recent file system errors occured.  These fields are displayed by
dumpe2fs and cleared by e2fsck.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Enhance tst_super_size so that it checks the superblock fields as well

The test now checks to make sure the superblock fields are correctly
aligned and prints them out so they can be manually checked to make
sure they are where we expect them to be.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2freefrag: Display the total number of free extents

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2freefrag: Fix getopt bug on machines with unsigned chars

The getopt() function returns an int, not a char.  On systems where the
default char is unsigned (like ppc), we get weird behavior where -1 is
truncated to 0xff but compared to (int)-1.

Also fix this same bug for two test programs, test_rel and iscan,
which aren't currently used at the moment.

Addresses-Gentoo-Bug: #299386

Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck: Add missing ext2fs_close() call when going back to original superblock

In the case where the original superblock and the backup superblock
are both invalid in some way, e2fsck will try to go back to the
orignal superblock.  To do that, it must close the attempted open
using the backup superblock first (since otherwise the exclusive open
will prevent the subsequent open from succeding).

Signed-off-by: Dmitry Monakhov <dmonakhov@openvz.org>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck, resize2fs: fix a fp precision error that can lead to a seg fault

Commit 641b66b fixed a floating point precision error which can result
in a search algorithm looping forever.  It can also result in an array
index being out of bounds and causing a segfault.  Here are two more
cases in e2fsck and resize2fs that need to be fixed.  I've just used
the same fix from the that commit.

Signed-off-by: Lachlan McIlroy <lmcilroy@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: Remove obsolete initrd script

Addresses-Debian-Bug: #585041

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
resize2fs: relax requirements for -P output a bit

Requiring an immediate pre-fsck before printing a minimum
resize size seems a bit draconian; if the fs isn't clean or marked
with error, then certainly, but for an informational minimum
size, I don't think we need to require a fsck since last mount.

I had simply copied the checks from the actual resize path,
previously.

Installers use this option (-P) to gather minimum resize info,
and requiring an actual fsck before use just seems to go too far.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
resize2fs.8: Update man page to indicate ext4 supports on-line resize

Addresses-Debian-Bug: #589345

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debian: Fix outdated description: /sbin/fsck has moved to util-linux

Addresses-Debian-Bug: #588726

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Merge branch 'maint' into next

Conflicts:
	resize/extent.c
tst_extents: Fix 64-bit bugs in do_goto_block()

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: Fix ext2fs_iblk_{add,sub}_blocks() when the i_blocks_hi is non-zero

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: Don't make a copy of the inode in ext2fs_extent_open2()

Previously, ext2fs_extent_open2() copied the passed-in inode structure
into the extent handle, and the extent functions modified the copy of
the inode structure if necessary due to extent splits, etc.  Change
ext2fs_extent_open2() so that the extent functions use the inode
structure passed into ext2fs_extent_open2().  Otherwise the passed-in
inode structure could become out of date due to changes made by the
extent functions.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: Add new function ext2fs_punch()

This function deallocates a range of blocks from a passed-in file.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
debugfs: Add new debugfs command punch (aka truncate)

This uses the newly added ext2fs_punch() function.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: Add new function ext2fs_file_get_inode()

This patch adds a very simple function:

	struct ext2_inode *ext2fs_file_get_inode(ext2_file_t file);

which is useful for fuse-ext2 when it needs to read the inode of an
open file.

Signed-off-by: renzo davoli <renzo@cs.unibo.it>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>