e2image: pass the correct size write_header

Commit bf0449b1a654, which added the ability to write qcow2 files,
generalized the write_header() file to take the size of the header
structure which it writes out.  Unfortunately, it changed the call
which supported original e2image format to pass in fs->blocksize,
instead of the actual size of the e2image header structure (which is
substantially smaller than fs->blocksize).  This meant that we copied
in stack garbage into the e2image file, and it made valgrind quite
unhappy.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: set the fs block size to new_io in ext2fs_rewrite_to_io()

e2image manually opens a new IO channel, and then sets the file system
to use this new IO channel via ext2fs_rewrite+to_io().  We need to
make sure the IO channel is set to the file system's block size to
avoid some nasty buffer overruns.

[ Modified by tytso to use io_channel_set_blksize() ]

Signed-off-by: Kit Westneat <kwestneat@ddn.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Andreas Dilger <andreas.dilger@intel.com>
libext2fs: fix some memory leaks with image file handling

These memory leaks were discovered by using "valgrind
--leak-check=full" while running "e2image -I bar.img foo.e2i"

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck: use ext2fs_write_dir_block3() instead of ext2fs_write_dir_block()

The use of ext2fs_write_dir_block() meant that attempts to fix
deleted/unused inodes in a directory would not be fixed for file
systems with 64-bit block numbers.  (And some random block with the
high 32-bits cleared would get corrupted.)

Fix a similar problem when expanding directories and when creating the
lost+found dirctory.

Signed-off-by: Kit Westneat <kwestneat@ddn.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
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>
e2fsck: use errcode_t to suppress some -Wconversion warnings

We need to store some error codes using an int to keep recovery.c as
close as possible to the recovery.c source file in the kernel.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck: use blk_t instead of blk64_t in check_resize_inode()

The resize inode only works on 32-bit block numbers, so use blk_t
instead of blk64_t.  This avoids some -Wconversion noise, and slims
the compiled code slightly, especially on 32-bit platforms.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
dumpe2fs: fix printing of block offsets for 64-bit file systems

Use ext2fs_group_first_block2() instead of ext2fs_group_first_block()
to avoid dumpe2fs from printing crazy block offsets when we have block
numbers which are larger than 32 bits.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: add explicit casts to ext2fs.h

Add some explicit casts to silence some -Wconversion noise.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
libext2fs: add explicit casts to bitops.h

Add some explicit casts to silence some -Wconversion noise.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck: fix j_maxlen if the file system is exactly 1 << 32 blocks

If the external journal device has exactly 1 << 32 blocks,
journal->j_maxlen would get set to zero, which would cause e2fsck to
declare the journal to be invalid.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
e2fsck: add support for 64-bit extended attribute block refcounting

If we have a 64-bit file system with extended attribute blocks, e2fsck
would not correctly handle EA blocks that were located beyond the
32-bit block number boundary.  Fix this by teaching
e2fsck/ea_refcount.c to use 64-bit block numbers.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
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>
libext2fs: fix printf conversion spec in tst_iscan.c

A recent patch to fix blk_t to blk64_t assignment mismatches in
e2fsprogs (commit 4dbfd79d1458ce1259b951377e341aeb6197f8c1) created
a printf conversion spec / argument type mismatch in tst_iscan.c.
Fix this to avoid truncation of the printed value and to silence
a compiler warning seen when "make check" is run.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
tests: check backing filesystem can handle large file

The new resize tests create 2TB test files, but tmpfs in kernels
before 3.1 have a max file size of 256GB.  Ext3 may also have
a size limit for smaller blocksize filesystems.

Fix the resize_test script to verify that $TMPFILE can be resized
to the final test size, and if that fails try creating the file on
the local filesystem instead of in $TMPDIR.  If that cannot hold
the large filesystem, skip the test.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Tested-by: Zheng Liu <wenqing.lz@taobao.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Merge branch 'maint' into next

Conflicts:
	e2fsck/pass2.c
	e2fsck/pass3.c