Commit Graph

3817 Commits (2b1cae7a2697ec841c41579d29cdcb0ab39ef73e)

Author SHA1 Message Date
Eric Sandeen 6d4ced2192 e2fsck: Fix leaks in error paths
fn and/or array was not freed in some error paths.

[ Also make sure the array is NULL terminated before we free it in
  get_dirlist(). --tytso]

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 19:55:55 -04:00
Eric Sandeen 2bf0739dc0 test_icount: fclose() before exit
Just to be tidy.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 19:55:55 -04:00
Eric Sandeen 5ea3c82592 libext2: Fix leaks in write_bitmaps on error returns
block_buf and/or inode_buf may not be properly freed on an error
return.

Create a new errout: target to free them as needed in error conditions.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 19:54:01 -04:00
Eric Sandeen 7adf589249 e2initrd_helper: Fix memory leak on error
Some error paths did not properly free "buf"

And the normal exit seemed to close e2_file twice (?)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:45:25 -04:00
Eric Sandeen 9f7c3afaef mke2fs: Do not let -t or -T be specified more than once
In addition to not making sense, it causes a memory leak
when fs_type gets overwritten.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:45:14 -04:00
Eric Sandeen 14ed2edb26 e2fsck: remove extraneous memset
e2fsck_allocate_memory() already sets allocated memory to 0,
so remove the explicit memset.

Especially since it was setting the wrong size (iter not *iter)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen 1e003cc77d filefrag: Fix uninitialized "expected" value
The "count" variable is only ever set if FIBMAP is used,
due to the -B switch, or a fiemap failure.  However,
we use it unconditionally to calculate "expected" for
extN files, so we can end up printing garbage.

Initialize count to 0, and unless we go through the FIBMAP
path, expected will be 0 as well, and in that case do not
print the message.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen d5c1d82ed8 subst: Fix free of uninit pointers
in add_subst(), if the malloc of ent->name fails, we goto fail;
which will free ent->name (which is null, so OK) but also free
ent->value (which is uninitialized).  There is no case where
we must free ent->value on an error (it is allocated last, and
if it fails it of course doesn't need to be freed) so just
remove it.

Also "retval" is only assigned once to the constant ENOMEM,
so we can just return that explicitly in the failure case.

Signed-off-by: Eric Saneeen <sandeen@redhat.com>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen 624e8ebe30 e2fsprogs: Fix some error cleanup path bugs
In inode_open(), if the allocation of &io fails, we go to cleanup
and dereference io to test io->name, which is a bug.

Similarly in undo_open()  if allocation of &data fails, we
go to cleanup and dereference data to test data->real.

In the test_open() case we explicitly set retval to the only
possible error return from ext2fs_get_mem(), so remove that
for tidiness.

The other changes just make make earlier returns go through
the error goto for consistency.

In many cases we returned directly from the first error, but
"goto cleanup" etc for every subsequent error.  In some
cases this leads to "impossible" tests such as:

	if (ptr)
		ext2fs_free_mem(&ptr)

on paths where ptr cannot be null because we would have
returned directly earlier, and Coverity flags this.

This isn't really indicative of an error in most cases, but
I think it can be clearer to always exit through the error goto
if it's used later in the function.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen f85a9ae639 e2fsck: Don't store old_op from ehandler_operation if we don't restore it.
old_op is set but never used, because we restore "0"
not old_op.  So don't bother with it.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen 06e41ddea9 libe2p: reach unreachable code
The EOPNOTSUPP case is unreachable, being outside a set of:
 #if
	...
	return;
 #else
	...
	return;
 #endif

Fix this up so that if neither HAVE_CHFLAGS nor
HAVE_EXT2_IOCTLS applies, we set EOPNOTSUPP.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen 4ebbc0a310 freefrag: fix up getopt case statement
There is no need to print out a "bad option" message; getopt
does that for us, and in fact will change "c" to "?" so
it's not even useful.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen 6a1dfb3b62 uuidd: Add missing break to option case statement
Specifying the "-n" option to uuidd would incorrectly
fall through to the "-p" case, and assign that number to
the pidfile_path.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen 9e30fb23ef e2fsprogs: annotate intentional fallthroughs in case statements
Using the /* fallthrough */ comment lets Coverity (and humans)
know that we really do want to fall through in these case statements.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:05 -04:00
Eric Sandeen da05d14130 e2fsck: handle null fs in print_pathname()
testing fs for NULL in expand_percent_expression():

	e2fsck_ctx = fs ? (e2fsck_t) fs->priv_data : NULL;

implies that fs could be NULL, but it's passed to print_pathname()
which defererences it without further testing.

So make this safe by returning "???" for a nul fs.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Eric Sandeen 665563b825 libext2fs: Potential null ptr deref in undo_err_handler_init
In the !undo_io_backing_manager case, undo_err_handler_init
will be passed a null data->real, which will be dereferenced.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Eric Sandeen d0f196d867 libext2: move buf variable completely under ifdef
If !WORDS_BIGENDIAN, it is pointless to test whether buf
is NULL, because it is initialized to NULL and never changed.
This makes Coverity complain, so we can just move all handling
of "buf" under the #ifdef.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Eric Sandeen 4d5cf8b166 mke2fs: remove impossible tests for null usage_types
parse_fs_type explicitly sets usage_types if it is null,
so there is no need to test for null later.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Eric Sandeen 80f4b3ae49 fsck: fix -C option parsing
The i++; statement is unreachable; fix same as commit
f1c2eaac535bd9172a35ce39b6d8f392321f274d in util-linux

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Eric Sandeen 11ba79b3a6 e2fsprogs: Remove impossible name_len tests.
The name_len field in ext2_dir_entry is actually comprised of
the name length in the lower 8 bytes, and the filetype in the
high 8 bytes.  So in places, we mask name_len with 0xFF to
get the actual length.

But once we have masked name_len with 0xFF, there is no point
in testing whether it is greater than EXT2_NAME_LEN, which
is 255 - or 0xFF.  So all of these tests are extraneous.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Eric Sandeen bc28abc537 libext2: Fix EXT2_LIB_SOFTSUPP masking
EXT2_LIB_SOFTSUPP_INCOMPAT_* are supposed to be bitmasks
of features which can be opened even though they are
under development.  The intent is that these are masked
out of the features list, so that they will be ignored
on open.

However, the code does a logical not vs. a bitwise not:

	features &= !EXT2_LIB_SOFTSUPP_INCOMPAT;

which will not have the desired effect...

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 18:43:04 -04:00
Theodore Ts'o ae96c678e1 libext2s: fix swapfs.c so it builds on big endian systems
Also cleaned up ext2_fs.h, and improved the byte swapping code so the
extra fields in the large inode are properly byte swapped.

Addresses-Debian-Bug: #641838

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 17:51:03 -04:00
Theodore Ts'o 3694bf1cd0 debian: use 1.41.99 hack so that lintain doesn't complain
We'll have to fix this up before 1.42 ships.  And the quota library
badly needs to be cleaned up...

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 12:15:17 -04:00
Theodore Ts'o 2406de5440 Update for e2fsprogs 1.42-WIP-0916 release
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 11:13:33 -04:00
Theodore Ts'o cd0b97ed93 libquota: indicate in the ELF library image that it requires libext2fs
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 11:12:59 -04:00
Theodore Ts'o 16c581d0e8 debugfs: add 64-bit support to the set_field commands
The set_fields commands (set_super_value, set_inode_field,
set_block_group) now handle fields which store in split fields on
ext4's on-disk format.  For example, the superblock fields
s_blocks_count and s_blocks_count_hi.

The user can either set the low or high part of the field via
"blocks_count_lo" or "blocks_count_hi", or both parts can be set via
"blocks_count".

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 10:32:02 -04:00
Theodore Ts'o 89efc88e65 libext2fs: add metadata checksum and snapshot feature flags
Reserve EXT4_FEATURE_RO_COMPAT_METADATA_CSUM and
EXT2_FEATURE_COMPAT_EXCLUDE_BITMAP.  Also reserve fields in the
superblock and the inode for the checksums.  In the block group
descriptor, reserve the exclude bitmap field for the snapshot feature,
and checksums for the inode and block allocation bitmaps.

With this commit, the metadata checksum and exclude bitmap features
should have reserved all of the fields they need in ext4's on-disk
format.

This commit also fixes an a missing byte swap for s_overhead_blocks.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
Cc: Darrick J. Wong <djwong@us.ibm.com>
Cc: Amir Goldstein <amir73il@gmail.com>
2011-09-16 10:24:09 -04:00
Theodore Ts'o 2418dfd7b9 dumpe2fs: display "free blocks" as "free clusters" for bigalloc file systems
Change this for the equivalent function in debugfs as well.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 10:13:41 -04:00
Eric Sandeen f314bb0821 libext2fs: remove redundant last-group check in ext2fs_check_desc()
ext2fs_group_last_block2() already properly calculates
the last block in the last group, so there is no need
to special-case this after the call.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 09:32:18 -04:00
Yongqiang Yang 32318ff20f e2fsck: fix error in computing blocks of the ending group
If the blocks of a filesystem is a multiple of blocks_per_group,
blocks of the ending group is computed wrongly.  Use the
new ext2fs_group_blocks_count() helper instead.

Eric Sandeen: Converted to use new blocks per group helper

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 09:28:44 -04:00
Eric Sandeen 98f4547198 e2fsprogs: add ext2fs_group_blocks_count helper
Code to count the number of blocks in the last partial
group is cut and pasted around the e2fsprogs codebase
a few times.

Making this a helper function should improve matters.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-16 09:28:43 -04:00
Theodore Ts'o 65b7a463da libext2fs: fix size check in tst_inode_size
Also add run tst_inode_size automaically from "make check"

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-16 09:27:06 -04:00
Theodore Ts'o 75405ffde6 Merge branch 'maint' into next 2011-09-16 00:00:04 -04:00
Lukas Czerner 765e03f037 e2fsck: do not attempt to discard if -n was specified
If '-n' option is specified there should be no changes made to the file
system hence we should not attempt to discard the file system. This
commit adds a check into the e2fsck_discard_blocks() condition so it skip
discard if E2F_OPT_NO flag is set.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:55:23 -04:00
Lukas Czerner 2fa1679adb tests: Print out list of failed tests
Currently we need to grep, list or just search for failed tests when
running 'make check' which is annoying. This commit simply prints out
the list of failed test names at the end of the output.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:54:49 -04:00
Lukas Czerner d2bfdc7ff1 e2fsprogs: Use punch hole as "discard" on regular files
If e2fsprogs tools (mke2fs, e2fsck) is run on regular file instead of
on block device, we can use punch hole instead of regular discard
command which would not work on regular file anyway. This gives us
several advantages. First of all when e2fsck is run with '-E discard'
parameter it will punch out all ununsed space from the image, hence
trimming down the file system image. And secondly, when creating an
file system on regular file (with '-E discard' which is default), we
can use punch hole to clear the file content, hence we can skip inode
table initialization, because reads from sparse area returns zeros. This
will result in faster file system creation (without the need to specify
lazy_itable_init) and smaller images.

This commit also fixes some tests that would fail due to mke2fs showing
discard progress, hence the output would differ.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:49:20 -04:00
Lukas Czerner c859cb1de0 e2fsprogs: create open() and stat() helpers
In many places we are using #ifdef HAVE_OPEN64 to determine if we can
use open64() but that's ugly. This commit creates two new helpers
ext2fs_open_file() for open() and ext2fs_stat() for stat(). Also we need
new typedef ext2fs_struct_stat for struct stat.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:46:57 -04:00
Darrick J. Wong db8bbf27c9 libext2fs: Add crc32c implementation for metadata checksumming
Add a slicing-by-8 CRC32c implementation for metadata checksumming.
Adapted from Bob Pearson's kernel patch.

Also added a self-test mechanism so we can verify that the crc32c
implementation is working correctly.

Signed-off-by: Darrick J. Wong <djwong@us.ibm.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:46:51 -04:00
Yury V. Zaytsev 45792c1276 mke2fs: check that auto-detected blocksize <= sys_page_size
Block size can be specified manually via the -b option or deduced
automatically. Unfortunately, the check that it is still smaller than
the system page size is only performed right after the command line
options are parsed.

Therefore, if buggy or inappropriately installed/configured hardware
hints that larger block sizes have to be used, mkfs will silently create
a file system which can not be mounted on the system in question.

By moving the check beyond the last assignment to blocksize it is now
ensured, that mkfs will issue a warning even if inappropriate blocksize
was auto-detected.

The new behavior can be easily tested, by exporting the following
variables before running mkfs:

    export MKE2FS_DEVICE_SECTSIZE=8192
    export MKE2FS_DEVICE_PHYS_SECTSIZE=8192

Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:46:27 -04:00
Surbhi Palande 57cb271642 mke2fs.8: Fix the documentation of maximum journal size
Fix the max journal size in mke2fs man page.

Signed-off-by: Surbhi Palande <csurbhi@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 23:35:18 -04:00
Amir Goldstein 15749d7da9 libext2fs: fix the range validation in bitmap_range2 funcs
The condition ((start+num) & ~0xffffffffULL) in bitmap_range2
and generic_bmap_range funcs in get_bitmap64.c was wrong and
inconsistent with the condition (start+num-1 > bmap->real_end)
in generic_bitmap_range funcs in get_bitmap.c.

I got the following error from tune2fs on a 16TB fs:
Illegal block number passed to ext2fs_unmark_block_bitmap #4294967295
for block bitmap for 16TB.img
tune2fs: Invalid argument while reading bitmaps

Fix to condition to ((start+num-1) & ~0xffffffffULL), because
the bit (start+num) is not going to be changed by the funcs.

Signed-off-by: Amir Goldstein <amir73il@users.sf.net>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2011-09-15 22:23:24 -04:00
Theodore Ts'o 7fef2bb11f badblocks: update man page's description of the -v option
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-15 19:33:34 -04:00
Theodore Ts'o 8595c5bfe6 debian: update the e2fslibs and e2fslibs-dev files for the quota library
We will include the quota library in e2fslibs for now.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-15 19:12:30 -04:00
Theodore Ts'o 3fbfad558e libext2fs: fix binary and source compatibility with the dump program
The dump program relies on fs->frag_size and the
EXT2_FRAGS_PER_BLOCK() macro.  Kind of silly for it to do so, but it's
part of the kludgy way the dump program (which was originally written
for the BSD FFS was ported over to support ext2/3.)  Given how it
makes assumptions about the ext2/3/4 file system being similar to the
BSD FFS, it's a bit of a miracle it works for ext4 --- or at least
appears to work...

Addresses-Debian-Bug: #636418

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-15 15:44:56 -04:00
Theodore Ts'o b715080757 mke2fs: use "extent" consistently as a feature name in the man page
Addresses-Debian-Bug: #639411

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-15 14:25:51 -04:00
Theodore Ts'o 63165136ea libe2p: fix bug so that MNTOPT_ options can be successfully parsed
Thanks to Israel G. Lugo for pointing this out.

Addresses-Debian-Bug: #641667

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-15 14:25:45 -04:00
Lukas Czerner 9d10f017e2 e2image: fix invalid lseek error detection
In flush_l2_cache() we are using ext2fs_llseek() however we do not
properly detect the error code returned from the function, because we
are assigning it into ULL variable, hence we will not see negative
values.

Fix this by changing the type of the variable to ext2_loff_t which is
signed and hence will store negative values.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14 13:49:04 -04:00
Theodore Ts'o 449c87a49c libquota: fix "make install" so it works in with a VPATH build directory
Also fix up the name of the header file which we are installing so it
is correct.

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14 13:47:35 -04:00
Theodore Ts'o 897fbaac7d libext2fs: add new test: tst_inode_size
This test makes sure the size of the ext2_inode is what we expect

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14 13:47:35 -04:00
Yongqiang Yang 9f6ba888f0 resize2fs: add support for new in-kernel online resize ioctl
This is needed to support online resizing for > 32-bit file systems

Signed-off-by: Yongqiang Yang <xiaoqiangnk@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2011-09-14 13:26:57 -04:00