Commit Graph

1509 Commits (master)

Author SHA1 Message Date
Richard Yao 97e9b97076 misc: remove broken whole device check
Modern Linux major/minor numbering on block devices no longer conform to
the divisible by 64 rule for minor numbering. On my development system,
the correct number is 16. Consequently, this applies only to every 4th
drive on a modern system, which is inconsistent. That caused the
following bug to be filed against Flocker:

https://clusterhq.atlassian.net/browse/FLOC-2041

We could unconditionally pass -F to override this check whenever it
triggers, but that it would also override the libblkid check that
determines whether there are existing partitions, logical volumes or
filesystems on the disk, which seems unwise.

I propose that this check be removed because passing a whole disk to
mke2fs is a valid use case and given how long this has been broken,
users are already accustomed to the behavior where -F is not necessary
to format a whole disk as ext4.

Signed-off-by: Richard Yao <ryao@gentoo.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
2015-06-14 14:50:58 -04:00
Theodore Ts'o 58354a38e2 e4crypt: fix hexidecimal salt parsing
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-10 22:52:48 -04:00
Darrick J. Wong 81cbf1ef4f misc: add fuse2fs, a FUSE server for e2fsprogs
This is the initial implementation of a FUSE server based on
e2fsprogs.  The point of this program is to enable ext4 to run on any
OS that FUSE supports (and doesn't already have a native driver), such
as MacOS X, BSDs, and Windows.  The code requires FUSE API v28, which
is available in Linux fuse and osxfuse releases that are available as
of August 2013.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-10 20:07:48 -04:00
Darrick J. Wong 4f868703f6 libext2fs: use fallocate for creating journals and hugefiles
Use the new fallocate API for creating the journal and the mk_hugefile
feature.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-10 19:57:52 -04:00
Theodore Ts'o 81f95d43d5 libext2fs, libe2p, misc: git rid of jfs_user.h
Having multiple versions of jfs_user.h was confusing the Android
build.  Clean up things by removing the lib/ext2fs/jfs_user.h and
misc/jfs_user.h and simplifying how we emulate the kernel
infrastructure needed by journal replay code and removing the
kernel-specific lines from kernel-jbd.h.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-25 21:18:15 -04:00
Theodore Ts'o 2df733facd Update Android build files so the 1.43 branch builds on AOSP
Recent changes in the 1.43 branch as well as the latest AOSP caused
the Android build to break; fix them.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-25 20:25:28 -04:00
Theodore Ts'o 8beba812a9 e2fsck,misc: include ext2fs.h to avoid clang warnings
e2fsck/dirinfo.c and misc/e4crypt.c use functions from libext2fs, so
we need to include its header file or clang will complain.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-23 18:08:35 -04:00
Theodore Ts'o cd27af3ecb mke2fs: enable the metadata_csum and 64bit features by default
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-18 01:49:00 -04:00
Theodore Ts'o 344c043b38 create_inode: handle source symlinks with extended attributes
We need to use lgetxattr(2) instead of getxattr(2) or attempts to
create file systems with extended attributes will fail:

set_inode_xattr: No data available while reading attribute "trusted.link" of "link"
__populate_fs: No data available while setting xattrs for "link"
mke2fs: No data available while populating file system

Reported-by: Jack_Fewx@Dell.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-17 15:06:45 -04:00
Darrick J. Wong f008143cf5 filefrag: fix broken extent emulation and uninitialized variables
This started with the fm_ext being uninitialized, but upon closer
analysis I discovered that forcing extent emulation in FIBMAP mode
was reporting an extent for every block in the file.  Fix both
problems.

The Coverity bug was 1297512.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-16 20:22:43 -04:00
Darrick J. Wong b085139224 misc: fix undo file setup
Fix Coverity bugs 1297094-1297101 by fixing all the mutations in the
*_setup_tdb() functions, fixing buffer overflows, and checking
return values.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-16 20:19:52 -04:00
Darrick J. Wong 63cd76d6ac misc: fix Coverity bugs
Fix Coverity bugs 1297093, 1297096, 1297489, 1297491, 1297493,
1297506, 1297507, 1297514, 1297516, and 1297517.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-16 18:32:33 -04:00
Darrick J. Wong 4407ea3b19 mke2fs: add simple tests and re-alphabetize mke2fs manpage options
Add some simple tests for mke2fs -d (create image from dir) and make
the manpage options appear in alphabetic order.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:52:01 -04:00
Darrick J. Wong b04af4fe04 copyin: fix error handling
Save errno (in retval) before doing anything else, because the
"anything else" (usually com_err()) can call library functions, which
will reset errno.

Fix the error messages to use the message catalog, and don't _ever_
print an error without providing context.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:51:02 -04:00
Darrick J. Wong 76f1323491 copy-in: for files, only iterate file blocks that are mapped
Rewrite the file copy-in algorithm to detect smaller holes in the
files we're copying in.  Use SEEK_DATA/SEEK_HOLE/FIEMAP when available
to skip known empty parts.  This fixes the particular bug where zeroed
blocks on a system with 64k pages are needlessly copied into a
4k-block filesystem.  It also saves time by skipping parts we know to
be zeroed.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:46:48 -04:00
Darrick J. Wong a433db04d0 copy-in: create hardlinks with the correct directory filetype
When we're creating hard links via ext2fs_link, the (misnamed?) flags
argument specifies the filetype for the directory entry.  This is
*derived* from i_mode, so provide a translator.  Otherwise, fsck will
complain about unset file types.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:46:06 -04:00
Darrick J. Wong 2d291b3c6b mke2fs: optionally create undo file
Provide the user with an option to create an undo file so that they
can roll back a failed tuning operation.  Previously, one would be
created if force_undo was set in the configuration file and a bunch of
(undocumented) conditions were met.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:41:40 -04:00
Darrick J. Wong f7d055945e tune2fs: optionally create undo file
Provide the user with an option to create an undo file so that they
can roll back a failed tuning operation.  Previously, one would be
created for inode resize if a bunch of (undocumented) conditions were
met.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:41:19 -04:00
Darrick J. Wong 4892bce3c4 e2undo: ditch tdb file, write everything to a flat file
The existing undo file format (which is based on tdb) has many
problems.  First, its comparison of superblock fields is ineffective,
since the last mount time is only written by the kernel, not the tools
(which means that undo files can be applied out of order, thus
corrupting the filesystem); block numbers are written in CPU byte
order, which will cause silent failures if an undo file is moved from
one type of system to another; using the tdb database costs us an
enormous amount of CPU overhead to maintain the key data structure,
and finally, the tdb database is unable to deal with databases larger
than 2GB.  (Upstream tdb 1.2.12 can handle 4GB, but upgrading a 2TB FS
to 64bit,metadata_csum easily produces 2.9GB of undo files, so we
might as well move off of tdb now.)

The last problem is fatal if you want to use tune2fs to turn on
metadata checksumming, since that rewrites every block on the
filesystem, which can easily produce a many-gigabyte undo file, which
of course is unreadable and therefore the operation cannot be undone.

Therefore, rip all of that out in favor of writing to a flat file.
Old blocks are appended to a file and the index is written to the end
when we're done.  This implementation is much faster than wasting a
considerable amount of time trying to maintain a hash index, which
drops the runtime overhead of tune2fs -O metadata_csum from ~45min
to ~20 seconds on a 2TB filesystem.

I have a few reasons that factored in my decision not to repurpose the
jbd2 file format for undo files.  First, undo files are limited to
2^32 blocks (16TB) which some day might not serve us well.  Second,
the journal block size is tied to the file system block size, but
mke2fs wants to be able to back up big chunks of old device contents.
This would require large changes to the e2fsck journal replay code,
which itself is derived from the kernel jbd2 driver, which I'd rather
not destabilize.  Third, I want to require undo files to store the FS
superblock at the end of undo file creation so that e2undo can be
reasonably sure that an undo file is supposed to apply against the
given block device, and doing so would require changes to the jbd2
format.  Fourth, it didn't seem like a good idea that external
journals should resemble undo files so closely.

v2: Provide a state bit that is only set when the undo channel is
closed correctly so we can warn the user about potentially incomplete
undo files.  Straighten out the superblock handling so that undo files
won't be confused for real ext* FS images.  Record multi-block runs in
each block key to reduce overhead even further.  Support reopening an
undo file so that we can combine multiple FS operations into one
(overall smaller) transaction file, which will be easier to manage.
Flush the undo index data if the program should terminate
unexpectedly.  Update the ext4 superblock bits if errors or -f is
found to encourage fsck to do a full run the next time it's invoked.
Enable undoing the undo.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:40:16 -04:00
Darrick J. Wong ec2019d109 e2undo: fix memory leaks and tweak the error messages somewhat
Fix memory leaks and improve the error messages to make it easier
to figure out why e2undo went wrong.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-05 10:39:51 -04:00
Theodore Ts'o 437651ad23 Update ext4 encryption format to final v4.1 version
The directory hash is now calculated using the on-disk encrypted
filename, and we no longer use the digest encoding or the SHA-256
encoding, so remove them from the ext2fs library until there is some
reason we need them.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-03 17:01:59 -04:00
Darrick J. Wong e0d5dd3602 e2fuzz: fuzz harder
Once we've "fixed" the filesystem, try mounting and modifying it to see
if we can break the kernel.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-20 21:47:18 -04:00
Theodore Ts'o a0556bd8e1 e4crypt: add the get_policy command
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:43:24 -04:00
Theodore Ts'o 654531df2a tune2fs: add ability to enable the encrypt feature
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:42:58 -04:00
Theodore Ts'o f7257a93f9 Change filename encryption to use CTS mode
Previously we were using a weird hybrid CBC/CTS.  Switch things so we
are using straight CTS; this corresponds to changes made in the latest
ext4 encryption patches.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-04-05 20:39:57 -04:00
Theodore Ts'o 4fb758aa4b Clean up and fix Android build files
Add missing new lib/ext2fs source files that were added for encryption
support.  Also move configuration #define's from individual Android.mk
to the android_config.h file, since we've moved away from specifying
configuration #define's on the command-line upstream.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-30 14:50:55 -04:00
Theodore Ts'o 1e734e72e1 e4crypt: change the UI to use a subcommand style
Also add a new subcommand "new_session", which works much like keyctl
new_session does.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-30 02:13:09 -04:00
Theodore Ts'o 41f2210131 Add support for a password salt stored in the superblock
Previously, e4crypt required the user to manually specify the salt
used for their passphrase.  This was user unfriendly to say the least.
The e4crypt program can now request the salt using an ioctl, which
will automatically generate the salt if necessary, and keep it in the
ext4 superblock.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-28 20:15:02 -04:00
Ildar Muslukhov bfa4b350b1 misc: add e4crypt tool
This patch adds new e4crypt tool for encryption management in the ext4
filesystem.

Signed-off-by: Ildar Muslukhov <muslukhovi@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-26 09:30:03 -04:00
Ildar Muslukhov bbb859496a misc: teach mke2fs to create encrypted file systems
Also enable support for encryption in e2fsprogs.

Signed-off-by: Ildar Muslukhov <muslukhovi@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-03-08 23:29:04 -04:00
Theodore Ts'o 321f3446f3 Add files to build on Android
The Android.mk files were taken from the Android AOSP sources, and
updated for the 1.43 next branch.  The intention is that this will
allow the repository which is currently located in external/e2fsprogs
with one which is based off of the upstream e2fsprogs.  Right now
external/e2fsprogs was not created using "git clone", so it means that
git merges don't work.  After the external/e2fsprogs Android
repository is replaced, with one based off the upstream repository,
Android will be able to synchronize with the upstream repository by
pulling and merging from upstream, and then running the script
"./util/gen-android-files" to update any generated files.  (This is
necessary because in the Android build system, the Android.mk files
are rather stylized and don't make it easy to run arbitrary shell
scripts during the build phase.)

Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2015-03-01 15:45:11 -05:00
Theodore Ts'o 8b39e4cf77 Add support for the read-only feature
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-02-23 13:04:47 -05:00
Darrick J. Wong fac0c8ead8 e2fsck: on read error, don't rewrite blocks past the end of the fs
If e2fsck encounters a read error on a block past the end of the
filesystem, don't bother trying to "rewrite" the block.  We might
still want to re-try the read to capture FS data marooned past the end
of the filesystem, but in that case e2fsck ought to move the block
back inside the filesystem.

This enables e2fuzz to detect writes past the end of the FS due to
software bugs.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:37 -05:00
Darrick J. Wong e263765505 tune2fs: direct user to resize2fs for 64bit conversion
If the user tries to enable or disable the 64bit feature via tune2fs,
tell them how to use resize2fs to effect the conversion.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:12:07 -05:00
Darrick J. Wong f2a96b6eb9 tune2fs: abort when trying to enable/disable metadata_csum on mounted fs
Earlier, I tried to make tune2fs abort if the user tried to enable or
disable metadata_csum on a mounted FS, but forgot the exit() call.
Supply it now.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:11:41 -05:00
Darrick J. Wong dd3ffbc918 tune2fs: disable csum verification before resizing inode
When we're turning on metadata checksumming /and/ resizing the inode
at the same time, disable checksum verification during the
resize_inode() call because the subroutines it calls will try to
verify the checksums (which have not yet been set), causing the
operation to fail unnecessarily.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-27 13:11:18 -05:00
Theodore Ts'o 22f22ab1d2 Reserve the codepoints for the new INCOMPAT feature ENCRYPT
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-26 10:27:41 -05:00
Darrick J. Wong 32ed2b085c e2fuzz: fix clang warning
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-01-19 16:38:14 -05:00
Darrick J. Wong fe12931f8f resize2fs: convert fs to and from 64bit mode
resize2fs does its magic by loading a filesystem, duplicating the
in-memory image of that fs, moving relevant blocks out of the way of
whatever new metadata get created, and finally writing everything back
out to disk.  Enabling 64bit mode enlarges the group descriptors,
which makes resize2fs a reasonable vehicle for taking care of the rest
of the bookkeeping requirements, so add to resize2fs the ability to
convert a filesystem to 64bit mode and back.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-15 12:45:05 -05:00
Theodore Ts'o 0698ecc1e2 Merge branch 'maint' into next 2014-12-14 20:57:09 -05:00
Jan Kara fcc19b4aa3 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>
2014-12-14 20:55:44 -05:00
Darrick J. Wong 5effd0a022 mke2fs: don't zero inode table blocks that are already zeroed
At mke2fs time, if we discard the device and discard zeroes data,
don't bother zeroing the inode table blocks a second time.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-13 22:01:15 -05:00
Darrick J. Wong 052795e630 tune2fs: enable uninit_bg when disabling metadata_csum
If we're disabling metadata_csum and the user doesn't provide explicit
instructions to enable or disable uninit_bg, assume that they want
uninit_bg to be turned on by default.  Otherwise, we lose all block
group flags and unused inode count, which is a big hit to performance.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-13 21:58:26 -05:00
Darrick J. Wong a742a128a0 tune2fs: warn if extents are not enabled when turning on metadata_csum
Warn the user if we're trying to enable metadata_csum on a FS that
doesn't support extents (since block maps cannot contain checksums).

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-13 21:57:20 -05:00
Darrick J. Wong 492084ffb2 dumpe2fs: output cleanup
Don't display unused inodes twice, and make it clear that we're
printing a descriptor checksum.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-13 21:52:48 -05:00
Darrick J. Wong 6aa8cff3ee dumpe2fs: reduce dumpe2fs output to 80 columns or less
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-13 21:51:48 -05:00
Darrick J. Wong fc4f5b2240 misc: don't allow mk_hugefiles unless the fs supports extents
The current mk_hugefile code in mke2fs doesn't support creating
non-extent files, so disable the functionality when we're mkfs'ing
without extent support.

The fallocate patches further on will eliminate the need for this.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-13 21:50:13 -05:00
Darrick J. Wong 3548bb64b5 libext2fs: refactor extent head creation
Don't open-code the creation of the extent tree header, since
ext2fs_extent_open2() knows how to take care of this.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-12-02 22:55:04 -05:00
Xiaoguang Wang ad4eafb28d tune2fs: fix memory write overflow
If we apply this patch 'e2fsprogs/tune2fs: rewrite metadata checksums
when resizing inode size', we will trigger a segfault, this is because
of the inode cache issues.

Firstly we should notice that in expand_inode_table(), we have change
the super block's s_inode_size to new inode size(for example, 256).

Then we re-compute metadata checksums, see below code flow:
|-->rewrite_metadata_checksums
|----->rewrite_inodes
|-------->ext2fs_write_inode_full
In ext2fs_write_inode_full(), if an inode cache is hit, the below code will be executed:
	/* Check to see if the inode cache needs to be updated */
	if (fs->icache) {
		for (i=0; i < fs->icache->cache_size; i++) {
			if (fs->icache->cache[i].ino == ino) {
				memcpy(fs->icache->cache[i].inode, inode,
				       (bufsize > length) ? length : bufsize);
				break;
			}
		}
	}

Before executing rewrite_inodes(), actually the inode in inode cache
is allocated by old inode size(for example, 128), but here the memcpy
will obviously write overflow, '(bufsize > length) ? length : bufsize'
here will return 256(new inode size), so this is wrong, we need to fix
this.  I think we should call ext2fs_free_inode_cache() in
expand_inode_table(), to drop the inode cache, because inode size has
changed, if necessary, we will re-create this inode cache.

Steps to reproduce this bug (apply 'tune2fs: rewrite metadata checksums
when resizing inode size' first):
	dd if=/dev/zero of=file.img bs=1M count=128
	device_name=$(/sbin/losetup -f)
	/sbin/losetup -f file.img
	mkfs.ext4 -I 128 -O ^flex_bg $device_name
	tune2fs -I 256 $device_name

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>
2014-12-02 22:31:15 -05:00
Xiaoguang Wang 8386a42146 tune2fs: rewrite metadata checksums when resizing inode size
When we use tune2fs -I new_ino_size to change inode size, if
everything is OK, the corresponding ext4_group_desc.bg_free_blocks_count
will be decreased, so obviously, we need to re-compute the group
descriptor checksums, and the inode 's size has also changed, we also
need to recompute the checksums of inodes for metadata_csum
filesystem, so here we choose to call a rewrite_metadata_checksums(),
this will fix checksum issues.

Meanwhile, the patch will trigger an existing memory write overflow,
which will casue segfault, please see the next patch.

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>
2014-12-02 22:29:32 -05:00
Theodore Ts'o bbf29ce6e9 Merge branch 'maint' into next 2014-12-02 22:15:25 -05:00
Darrick J. Wong 63b4cbb8bc 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>
2014-12-02 22:14:34 -05:00
Xiaoguang Wang 5da8912008 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>
2014-12-02 21:06:45 -05:00
Darrick J. Wong fecb231f6f 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>
2014-11-07 21:26:14 -05:00
Darrick J. Wong 210baa5d8a mke2fs: warn if enabling metadata_csum on a pre-3.18 kernel
The metadata_csum feature (really, the journal checksum disk format)
didn't stabilize until the 3.18 kernel, at which point the companion
journal_csum feature was turned on by default if metadata_csum was
enabled.  Therefore, warn the user if they try to create such a
filesystem on a pre-3.18 kernel.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-11-05 11:16:57 -05:00
Darrick J. Wong a4b528692e tune2fs: don't change metadata_csum on a mounted fs
Don't let users change metadata_csum on a mounted filesystem because
there's no way to tell the kernel to turn on the feature; there's no
way to prevent the kernel from rewriting on-disk structures while
tune2fs is also rewriting them; and there's no way to tell the kernel
to reload them after tune2fs is finished.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-11-04 11:52:26 -05:00
Darrick J. Wong 8302e2e688 tune2fs: speed up rewriting extent tree when enabling metadata_csum
When enabling checksums, tune2fs naively rewrites every extent in the
entire tree!  This is unnecessary since we only need to rewrite each
extent tree block; therefore, only rewrite the extent if it's the
first one in an internal extent tree block.

Also, don't bother iterating the extent tree when clearing checksums.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-11-04 11:52:03 -05:00
Darrick J. Wong e49b03e341 misc: fix broken libmagic interaction with plausibility check
If we get as far as calling libmagic, return the correct error code so
that mkfs asks for confirmation if libmagic finds something and
doesn't ask if nothing is found.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-11-04 11:49:39 -05:00
Darrick J. Wong be2ad9ed2c e2fuzz: exercise fuzzed blocks more aggressively
Exercise fuzzed metadata blocks more aggressively by expanding up to
50000 files (instead of just test.1, which might not hit anything).
Fix a typo while we're at it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-11-04 11:36:28 -05:00
Theodore Ts'o 8b779489ea Merge branch 'maint' into next
Conflicts:
	configure
2014-11-04 11:20:09 -05:00
Theodore Ts'o 831aa869e8 debugfs: fix build on systems that don't have gettext built-in
Debugfs (unlike all of the other programs in e2fsprogs) is not set up
to use translated strings.  So when building misc/plausible.c for
debugfs, we need to disable NLS.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-10-18 09:13:09 -04:00
Darrick J. Wong 08c8e319e3 libext2fs/e2fsck: refactor everyone who writes zero blocks to disk
Convert all call sites that write zero blocks to disk to use
ext2fs_zero_blocks2() since it can use Linux's zero out feature to do
the writes more quickly.  Reclaim the zero buffer at freefs time and
make the write-zeroes fallback use a larger buffer.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-10-13 04:31:17 -04:00
Eric Whitney 0745e78741 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>
2014-10-13 04:19:24 -04:00
Artemiy Volkov d50fd63369 misc: fix build on absence of magic.h
If magic.h is not present, there will be unresolved references to the magic_t
type in plausible.c. Fix that by moving the protecting #ifdef directive.

Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-10-04 13:22:52 -04:00
Eric Whitney 5ae83d6593 mke2fs: clarify inline data inode size error message
The existing error message can be made more helpful by more clearly
implying the attempt to make a file system with undersized inodes is
failing and suggesting a corrective action.

Signed-off-by: Eric Whitney <enwlinux@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-10-01 08:36:36 -04:00
Theodore Ts'o 3d78d037ec Merge branch 'maint' into next 2014-10-01 08:36:28 -04:00
Eric Sandeen c6889a6430 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>
2014-10-01 08:33:54 -04:00
Theodore Ts'o d2e3c0dc60 misc: if dlopen() is available, use it to load the libmagic library
This prevents the libmagic library from being a hard dependency; if
it's not there, we can simply do without it.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: Darrick J. Wong <darrick.wong@oracle.com>
2014-09-21 01:25:58 -04:00
Darrick J. Wong b291c11f08 misc: use libmagic when libblkid can't identify something
If we're using check_plausibility() to try to identify something that
obviously isn't an ext* filesystem and libblkid doesn't know what it
is, try libmagic instead.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-20 23:42:19 -04:00
Darrick J. Wong c8b20b40eb misc: add plausibility checks to debugfs/tune2fs/dumpe2fs/e2fsck
If any of these utilities detect a bad superblock magic, call
check_plausibility to see if blkid can identify the passed-in argument
as something else (xfs, partition, etc.) in the hopes of catching a
user error.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-19 23:44:31 -04:00
Darrick J. Wong b598c517b3 misc: move check_plausibility into a separate file
Move check_plausibility() into a separate file so that various
programs can use it without having to declare useless global variables
that the util.c functions seem to require.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-19 13:10:21 -04:00
Darrick J. Wong 0858268dff dumpe2fs: provide a machine-readable group-only mode
Spit out just the group descriptor data in a machine readable format.
This is most useful for testing and scripting purposes.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-19 12:16:44 -04:00
Theodore Ts'o cc0d983303 Fix build failures due to missing $(SYSLIBS)
Two link lines were missing $(SYSLIBS), which is needed for dietlibc.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-19 01:05:14 -04:00
Theodore Ts'o 0c49965fb6 create_inode: don't indiscriminately #include "nls-enable.h"
The create_inode.h header file is pulled in by debugfs, which is not
internationalized.  It had no business pulling in nls-enable.h; that
header file should only be used in specific .c files that support
internationalization.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-19 00:46:41 -04:00
Theodore Ts'o a133c81d06 Merge branch 'maint' into next 2014-09-19 00:28:46 -04:00
Theodore Ts'o 17c1fa6e26 misc: fix build breakage with configure --disable-uuidd --enable-profile
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-19 00:26:56 -04:00
Theodore Ts'o ceec1709f7 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>
2014-09-19 00:04:24 -04:00
Theodore Ts'o 1bbea9c909 Merge branch 'maint' into next 2014-09-18 21:28:59 -04:00
Darrick J. Wong d9112409a2 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>
2014-09-18 21:24:26 -04:00
Darrick J. Wong 3f4c407997 tune2fs: always check disable_uninit_bg() return code
Enhance disable_uninit_bg() to return error codes -- if something goes
wrong, we want to flag the FS as needing a fsck and exit.  Mr. Reardon
discovered that tune2fs -O ^metadata_csum on a FS with a corrupt
bitmap would leave the FS in a weird state.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 18:06:31 -04:00
Darrick J. Wong e690eae513 misc: zero s_jnl_blocks when removing internal journal
When we're removing the internal journal (broken journal, turning it
off, or adding an external journal), zero s_jnl_blocks so that they
can't be picked up by accident later.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:55 -04:00
Darrick J. Wong 3727a0e745 dumpe2fs: display external journal feature flags
Display the feature flags of an external journal.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:55 -04:00
Darrick J. Wong 811bccef89 tune2fs: explicitly disallow tuning of journal devices
Spit out a more specific error if someone tries to modify an
external journal device.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:55 -04:00
Darrick J. Wong 7a8f497356 mke2fs: allow creation of journal device with superblock checksum
Enable mke2fs to create an external journal device with a superblock
checksum.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Cc: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:55 -04:00
Darrick J. Wong 4f769f4c03 misc: don't return ENOMEM if we run out of disk space
If there aren't enough blocks in the FS to allocate all of the
hugefiles, return ENOSPC, not ENOMEM.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:54 -04:00
Darrick J. Wong 38d5adf339 e2fsck/debugfs: fix descriptor block size handling errors with journal_csum
It turns out that there are some serious problems with the on-disk
format of journal checksum v2.  The foremost is that the function to
calculate descriptor tag size returns sizes that are too big.  This
causes alignment issues on some architectures and is compounded by the
fact that some parts of jbd2 use the structure size (incorrectly) to
determine the presence of a 64bit journal instead of checking the
feature flags.  These errors regrettably lead to the journal
corruption reported by Mr. Reardon.

Therefore, introduce journal checksum v3, which enlarges the
descriptor block tag format to allow for full 32-bit checksums of
journal blocks, fix the journal tag function to return the correct
sizes, and fix the jbd2 recovery code to use feature flags to
determine 64bitness.

Add a few function helpers so we don't have to open-code quite so
many pieces.

Switching to a 16-byte block size was found to increase journal size
overhead by a maximum of 0.1%, to convert a 32-bit journal with no
checksumming to a 32-bit journal with checksum v3 enabled.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reported-by: TR Reardon <thomas_reardon@hotmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-09-11 12:40:54 -04:00
Theodore Ts'o b874d24629 v1.42.12
-----BEGIN PGP SIGNATURE-----
 Version: GnuPG v2
 
 iQIcBAABCAAGBQJUAIPFAAoJENNvdpvBGATwoZ8P/AxCEVC90Cj+lz8ayEJ/v0RB
 Q61qScNMuzgzPLA6xfFUQqnnAzLFIvhlLazGbOJFDDrIc9Ek4HZZqTldsJTK+B3l
 V5X+o66E1U9+gL64qBKuJz+anS09jGLLrKvH1Ok+vMtD35xPxkrPa0Egrw5/q2gD
 3YXxvQHSuTGx3qHwTJ6MNpBM2O7DSNRV3lARLRY3rkIkRUPPBLPiqYaL2tTE7Er1
 9I5ENKURrHu4uZ3b0OLD3SGhdesLWsguzMzrep0vOZ7PSfmLSZiiURA3puyHj2hl
 Ixxk+qFqv9mUq86rUo+we9N0qU4dKbfdOxMCbY7DyGJdoDzDQany3zw5EG/XO+Ws
 MKJ1qUm30l32FrqkFkFwL0PWzCssV86lfwsIt4f3My3v61C91B9YbxMR2magzmB5
 B1yTCyEWu4hgPld98fgq1cVVpeWtxCejG7llg4gsDbRwJYlv+hSVVBBPmEofr4F7
 j2GdRm5KXKIBETx1WWqLeTHhDrD68rpU8RISrCPOYUBmFdyNA3H38ret23GvF6BT
 Im/xlxhAWL/EzBEYA6OyvckWA2VUvYH3jEoSZwtgpxeSIFP0ABInPrmsTLHY2kdI
 cx9VWV9+0GdVUc/ObSud4FHYcdc7IyGaKZp0M2YlYTQTqDIBZDiy1liyHYQ4/rvb
 20I2th2DbtdTpMiPlHgJ
 =igQE
 -----END PGP SIGNATURE-----

Merge tag 'v1.42.12' into next

v1.42.12

Conflicts:
	version.h
2014-08-29 11:38:33 -04:00
Theodore Ts'o 725502de19 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>
2014-08-27 09:27:54 -04:00
Eric Sandeen e92beaac10 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>
2014-08-25 21:02:18 -04:00
Theodore Ts'o c1c8800b71 Merge branch 'maint' into next
Conflicts:
	RELEASE-NOTES
	debian/changelog
	version.h
2014-08-25 18:37:37 -04:00
Theodore Ts'o ce2e295d7b 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>
2014-08-24 23:54:37 -04:00
Theodore Ts'o 9ac2930cc9 mke2fs.8.in: explain how the fs-size parameter is interpreted
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-24 23:53:33 -04:00
Theodore Ts'o 20d6b381a1 dumpe2fs: complain if extra arguments are given on the command line
Addresses-Debian-Bug: #758074

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-24 22:31:03 -04:00
Darrick J. Wong 7248e265c7 e2fuzz: fix pwrite64/pwrite usage
Select pwrite64 or pwrite depending on what autoconf finds.  This
makes e2fuzz find a suitable pwrite variant regardless of platform.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-24 19:55:42 -04:00
Darrick J. Wong c4c9bc590c misc: fix gcc warnings
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-24 12:22:11 -04:00
Theodore Ts'o aef977196a Merge branch 'maint' into next 2014-08-15 19:01:24 -04:00
Theodore Ts'o c47cd4f287 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>
2014-08-13 15:59:20 -04:00
Darrick J. Wong 0165cfadfa e2fuzz: fix build problems on macosx and i386 linux
Fix clang warnings about forgotten header files, dead code, and pwrite
support on OS X.  The unistd.h inclusion also fixes a parameter
truncation bug on i386.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-10 18:21:14 -04:00
Darrick J. Wong 3466e95f0d dumpe2fs: complain when checksum verification fails
Warn the user to run e2fsck if the superblock or bitmaps fails
checksum verification.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-02 22:26:15 -04:00
Darrick J. Wong 8375a881f9 e2fuzz: fix fs handle cleanup when closing fails
Fix the handling of 'fs' when closing the FS fails so that we don't
dereference a NULL pointer.  Adapt to use ext2fs_close_free while
we're at it.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Fixes-Coverity-Bug: 1229241
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-02 22:18:29 -04:00
Theodore Ts'o 14207cf60e Merge branch 'maint' into next
Conflicts:
	configure
	misc/Makefile.in
2014-08-02 22:05:03 -04:00
Artemiy Volkov bf140bf298 debugfs: fix argument parsing in do_freefrag()
When do_freefrag() is called from debugfs, the value of optind is
not reset. Rectify that by calling reset_getopt().

Signed-off-by: Artemiy Volkov <artemiyv@acm.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-02 19:53:04 -04:00
Theodore Ts'o 3b9904967b misc: fix Makefile for profiled build
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-02 19:43:10 -04:00
Andreas Dilger af7dbe3a11 filefrag: minor code fixes and cleanups
Print filefrag_fiemap() error message to stderr instead of stdout.

Only call ioctl(EXT3_IOC_GETFLAGS) for ext{2,3,4} filesystems to
decide if the ext2 indirect block allocation heuristic shold be used.

Properly handle the the force_bmap (-B) option.

Exit with a positive error number instead of a negative one.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-01 22:09:23 -04:00
Andreas Dilger 0befec4e24 misc: quiet signed/unsigned charactr compiler warnings
Quiet warnings about signed vs. unsigned character mismatch.
Use __u8 for storing UUIDs instead of char to match the superblock
s_uuid field.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-08-01 21:39:27 -04:00
Theodore Ts'o 7d0109c085 tune2fs: fix uninitialized variable in remove_journal_device
This bug was introduced by commit 7dfefaf413 ("tune2fs: update
journal super block when changing UUID for fs").

Fixes-Coverity-Bug: 1229243

Reported-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-31 11:49:48 -04:00
Theodore Ts'o 643fd7e7aa Merge branch 'maint' into next 2014-07-29 10:53:49 -04:00
Azat Khuzhin 9c2c1e9a3d tune2fs: update journal users while updating fs UUID (with external journal)
When we have fs with external journal device, and updating it's UUID, we
should update UUID in users list for that external journal device.

Before:
$ tune2fs -U clear /tmp/dev
tune2fs 1.42.10 (18-May-2014)
$ dumpe2fs /tmp/dev | fgrep UUID
dumpe2fs 1.42.10 (18-May-2014)
Filesystem UUID:          <none>
Journal UUID:             da1f2ed0-60f6-aaaa-92fd-738701418523
$ dumpe2fs /tmp/journal | fgrep users -A10
dumpe2fs 1.42.10 (18-May-2014)
Journal number of users:  2
Journal users:            0707762d-638e-4bc6-944e-ae8ee7a3359e
                          0ad849df-1041-4f0a-b1c1-2f949d6a1e37

After:
$ sudo tune2fs -U clear /tmp/dev
tune2fs 1.43-WIP (18-May-2014)
$ dumpe2fs /tmp/dev | fgrep UUID
dumpe2fs 1.42.10 (18-May-2014)
Filesystem UUID:          <none>
Journal UUID:             da1f2ed0-60f6-aaaa-92fd-738701418523
$ dumpe2fs /tmp/journal | fgrep users -A10
dumpe2fs 1.42.10 (18-May-2014)
Journal number of users:  2
Journal users:            0707762d-638e-4bc6-944e-ae8ee7a3359e
                          00000000-0000-0000-0000-000000000000

Also add some consts to avoid *magic numbers*:
- UUID_STR_SIZE
- UUID_SIZE
- JFS_USERS_MAX
- JFS_USERS_SIZE

Proposed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-28 20:21:59 -04:00
Azat Khuzhin 7dfefaf413 tune2fs: update journal super block when changing UUID for fs.
Using -U option you can change the UUID for fs, however it will not work
for journal device, since it have a copy of this UUID inside jsb (i.e.
journal super block). So copy UUID on change into that block.

Here is the initial thread:
http://comments.gmane.org/gmane.comp.file-systems.ext4/44532

You can reproduce this by executing following commands:
$ fallocate -l100M /tmp/dev
$ fallocate -l100M /tmp/journal
$ sudo /sbin/losetup /dev/loop1 /tmp/dev
$ sudo /sbin/losetup /dev/loop0 /tmp/journal
$ mke2fs -O journal_dev /tmp/journal
$ tune2fs -U da1f2ed0-60f6-aaaa-92fd-738701418523 /tmp/journal
$ sudo mke2fs -t ext4 -J device=/dev/loop0 /dev/loop1
$ dumpe2fs -h /tmp/dev | fgrep UUID
dumpe2fs 1.43-WIP (18-May-2014)
Filesystem UUID:          8a776be9-12eb-411f-8e88-b873575ecfb6
Journal UUID:             e3d02151-e776-4865-af25-aecb7291e8e5
$ sudo e2fsck /dev/vdc
e2fsck 1.43-WIP (18-May-2014)
External journal does not support this filesystem

/dev/loop1: ********** WARNING: Filesystem still has errors **********

Reported-by: Chin Tzung Cheng <chintzung@gmail.com>
Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-28 20:21:59 -04:00
Azat Khuzhin 3e077c357c tune2fs: remove_journal_device(): use the correct block to find jsb
Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-28 20:21:59 -04:00
Azat Khuzhin 7f33024ac2 journal: use consts instead of 1024 and add helper for journal with 1k blocksize
Use EXT2_MIN_BLOCK_SIZE, JFS_MIN_JOURNAL_BLOCKS, SUPERBLOCK_SIZE, and
SUPERBLOCK_OFFSET instead of hardcoded 1024 when it is okay, and also
add a helper ext2fs_journal_sb_start() that will return start of
journal sb with special case for fs with 1k block size.

Signed-off-by: Azat Khuzhin <a3at.mail@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-28 20:21:47 -04:00
Theodore Ts'o 8f5e2b6045 Merge branch 'maint' into next 2014-07-28 16:03:55 -04:00
Ross Burton c84da2eed0 misc: copy extended attributes in populate_fs
When creating a file system using a source directory, also copy any extended
attributes that have been set.

[ Add configure tests for Linux-specific xattr syscalls and add fallback
  when compiling on non-Linux systems. --tytso ]

Signed-off-by: Ross Burton <ross.burton@intel.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-27 21:19:24 -04:00
Rakesh Pandit 01824c9bbc filefrag: fix block size value
ioctl(FIGETBSZ) was used to get block size earlier but 2508eaa7
(filefrag: improvements to filefrag FIEMAP handling) moved to fstatfs
f_bsize which doesn't work well for many files systems.

Block size returned using fstatfs isn't block size but "optimal
transfer block size" as per man page.  Even stat st_blksize is
"preferred I/O block size" and in may file systems it may even vary
from file to file (POSIX).  This patch changes filefrag to use
FIGETBSZ preferentially over f_bsize.

[ Modified by tytso to add the fallback to f_bsize if FIGETBSZ fails
  for some reason ]

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-27 20:24:23 -04:00
Rakesh Pandit abc4697d5a filefrag: fix -B option and extents calculation for FIBMAP
29758d2 broke -B option which is useful for filesystems not supporting
FIEMAP. Also, fix extents calculation for -B which is broken since
2508eaa7.

Signed-off-by: Rakesh Pandit <rakesh@tuxera.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-27 19:56:27 -04:00
Theodore Ts'o 22302aa320 Merge branch 'maint' into next
Conflicts:
	debugfs/debugfs.c
	e2fsck/pass1.c
2014-07-26 15:57:42 -04:00
Darrick J. Wong 97c607b1a2 libext2fs: provide a function to set inode size
Provide an API to set i_size in an inode and take care of all required
feature flag modifications.  Refactor the code to use this new
function.

[ Moved the function to lib/ext2fs/blk_num.c, which is the rest of
  these sorts of functions live, and renamed it to be
  ext2fs_inode_size_set() instead of ext2fs_inode_set_size() to be
  consistent with the other functions in in blk_num.c -- tytso ]

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-26 14:34:56 -04:00
Theodore Ts'o 50972e1f7d Merge branch 'maint' into next
Conflicts:
	debugfs/debugfs.c
	e2fsck/pass5.c
2014-07-26 09:46:50 -04:00
Theodore Ts'o 1e33a8b408 Fix 32/64-bit overflow when multiplying by blocks/clusters per group
There are a number of places where we need convert groups to blocks or
clusters by multiply the groups by blocks/clusters per group.
Unfortunately, both quantities are 32-bit, but the result needs to be
64-bit, and very often the cast to 64-bit gets lost.

Fix this by adding new macros, EXT2_GROUPS_TO_BLOCKS() and
EXT2_GROUPS_TO_CLUSTERS().

This should fix a bug where resizing a 64bit file system can result in
calculate_minimum_resize_size() looping forever.

Addresses-Launchpad-Bug: #1321958

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-26 07:40:36 -04:00
Andreas Dilger 8b90ab2b1c build: fix unused/uninitialized variable warnings
Fix a few warnings about unused and uninitialized variables.

Also fix util/subst.c to include <sys/time.h> to avoid using
undeclared functions gettimeofday() and futimes().

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-25 22:48:01 -04:00
Darrick J. Wong bf191f274b e2fuzz: Create a tool to fuzz ext* filesystems
Creates a program that fuzzes only the metadata blocks (or optionally
all in-use blocks) of an ext* filesystem.  There's also a script to
automate fuzz testing of the kernel and e2fsck in a loop.

[ Modified by tytso to add e2fuzz to the clean makefile rule ]

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-25 09:15:28 -04:00
Darrick J. Wong cd32129d89 mke2fs: set error behavior at initialization time
Port tune2fs' -e flag to mke2fs so that we can set error behavior at
format time, and introduce the equivalent errors= setting into
mke2fs.conf.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-25 08:58:29 -04:00
Theodore Ts'o 60203cb171 Merge branch 'maint' into next
Conflicts:
	e2fsck/pass1.c
2014-07-25 08:38:39 -04:00
Darrick J. Wong c3470fcd60 misc: fix problems with strncat
The third argument to strncat is the maximum number of characters to
copy out of the second argument; it is not the maximum length of the
first argument.

Therefore, code in a check just in case we ever find a /sys/block/X
path long enough to hit the end of the buffer.  FWIW the longest path
I could find on my machine was 133 bytes.

Fixes-Coverity-Bug: 1252003
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-25 07:21:47 -04:00
Theodore Ts'o f9f3050a0a Merge branch 'maint' into next
Conflicts:
	debian/changelog
	e2fsck/pass1.c
	lib/ext2fs/Makefile.in
2014-07-22 14:57:40 -04:00
Darrick J. Wong c7c539e8fd e4defrag: backwards-allocated files should be defragmented too
Currently, e4defrag avoids increasing file fragmentation by comparing
the number of runs of physical extents of both the original and the
donor files.  Unfortunately, there is a bug in the routine that counts
physical extents, since it doesn't look at the logical block offsets
of the extents.  Therefore, a file whose blocks were allocated in
reverse order will be seen as only having one big physical extent, and
therefore will not be defragmented.

Fix the counting routine to consider logical extent offset so that we
defragment backwards-allocated files.  This could be problematic if we
ever gain the ability to lay out logically sparse extents in a
physically contiguous manner, but presumably one wouldn't call defrag
on such a file.

Reported-by: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-22 12:40:56 -04:00
Theodore Ts'o 30db7954c7 mke2fs: fix fencepost error when calling strncat
There were other protections which would prevent a buffer overflow
from happening, but we should fix this nevertheless.

Addresses-Coverity-Bug: #1225003
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-10 15:33:57 -04:00
Theodore Ts'o f10554e1c2 Merge remote-tracking branch 'origin/maint' into next
Conflicts:
	RELEASE-NOTES
	debian/changelog
	version.h
2014-07-10 01:07:39 -04:00
Theodore Ts'o a93a4c724f Fix nroff macro issue in chattr man page
The single quote character must not be in the first character in a
line, or else it can get mistaken as a macro call.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-10 00:48:57 -04:00
Theodore Ts'o c42de75b2f mke2fs: add support to align hugefiles relative to beginning of the disk
Add the mke2fs.conf configuration option which causes the hugefiles to
be aligned to the beginning of the disk.  This is important if the the
reason for aligning the hugefiles is to support hard-drive specific
features such as Shingled Magnetic Recording (SMR).

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-09 10:42:13 -04:00
Theodore Ts'o 7f7d1cb462 Merge branch 'maint' into next
Conflicts:
	debugfs/set_fields.c
	tests/f_mmp/script
	tests/f_mmp_garbage/script
	tests/m_mmp/script
	tests/t_mmp_1on/script
	tests/t_mmp_2off/script
2014-07-06 00:09:27 -04:00
Akira Fujita d0de4c9540 mke2fs: add get_uint_from_profile to mke2fs.c
We can set flex_bg count only up to 2^30 with profile
because get_int_from_profile can handle it to 2^31-1.
Add get_uint_from_profile to read unsigned int value
so that mke2fs with profile can handle up to 2^31 flex_bg same as -G option.

Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-05 22:34:54 -04:00
Akira Fujita a131053ef0 mke2fs: set upper limit to flex_bg count
mke2fs -G option allows root user to set flex_bg count (power of 2).
However ext4 has bad metadata layout if we specify more than or equal to
2^32 to mke2fs -G, because of the 32bit shift operation
in ext2fs_allocate_group_table().

And the maximum block group count of ext4 is 2^32 -1 (ext4_group_t
s_groups_count), so diallow more than 2^32 flex_bg count.

Steps to reproduce:

   # mke2fs -t ext4 -G 4294967296 DEV

   # dumpe2fs DEV
   ...
   Flex block group size:    1          <----- flex_bg is 1!
   ...
   Group 0: (Blocks 0-32767)
     Checksum 0x4afd, unused inodes 7541
     Primary superblock at 0, Group descriptors at 1-1
     Reserved GDT blocks at 2-59
     Block bitmap at 60 (+60), Inode bitmap at 61 (+61)
     Inode table at 62-533 (+62)
     32228 free blocks, 7541 free inodes, 2 directories, 7541 unused inodes
     Free blocks: 540-32767
     Free inodes: 12-7552
   Group 1: (Blocks 32768-65535) [INODE_UNINIT]
     Checksum 0xc890, unused inodes 7552
     Backup superblock at 32768, Group descriptors at 32769-32769
     Reserved GDT blocks at 32770-32827
     Block bitmap at 32828 (+60), Inode bitmap at 32829 (+61)
     Inode table at 32830-33301 (+62)
     32234 free blocks, 7552 free inodes, 0 directories, 7552 unused inodes
     Free blocks: 33302-65535
     Free inodes: 7553-15104
   ...

Signed-off-by: Akira Fujita <a-fujita@rs.jp.nec.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: "Darrick J. Wong" <darrick.wong@oracle.com>
2014-07-05 22:14:57 -04:00
Lukas Czerner 7584b8db32 mke2fs: enable lazy_itable_init on newer kernel by default
Currently is used did not specified lazy_itable_init option we rely on
information from ext4 module exported via sysfs interface. However if
the ext4 module is not loaded it will not be enabled even though kernel
might support it.

With this commit we set the default according to the kernel version,
however we still allow it to be set manually via extended option or be
enabled in case that ext4 module advertise that it supports this
feature.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
2014-07-05 21:08:38 -04:00
Lukas Czerner d27a559c71 mke2fs: add revision to the is_before_linux_ver()
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-05 21:08:02 -04:00
Lukas Czerner 47fee2ef6a e2fsprogs: introduce ext2fs_close_free() helper
Currently there are many uses of ext2fs_close() which might be wrong.
First of all ext2fs_close() does not set the ext2_filsys pointer to NULL
so the caller is responsible for clearing it, however there are some
cases there we do not do it.

Second of all very small number of users of ext2fs_close() actually
check the return value. If there is a problem in ext2fs_close() it will
not even free the ext2_filsys structure, but majority of users expect it
to do so.

To fix both problems this commit introduces a new helper
ext2fs_close_free() which will not only check for the return value and
free the ext2_filsys structure if the call to ext2fs_close2() failed,
but it will also set the ext2_filsys pointer to NULL.

Replace every use of ext2fs_close() in e2fsprogs tools with
ext2fs_close_free() - there is no real reason to keep using
ext2fs_close().

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
2014-07-05 21:06:48 -04:00
Eric Sandeen 3e500a8f11 e2fsprogs: add mount options to ext4.5
This is a straight cut and paste from the util-linux
mount manpage to ext4.5 (with commented-out lines
removed).

It's pretty much impossible for util-linux to keep up
with every filesystem out there, and Karel has more than
once expressed a wish that mount options move into fs-specific
manpages.

So, here we go.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-04 23:59:45 -04:00
Eric Sandeen 272258e1df e2fsprogs: revise and extend chattr(1) and chattr usage()
The chattr(1) manpage and chattr usage() output were missing some flags.

Add those, and make some other minor cosmetic fixes.

(I've left out the 'B' (EXT2_COMPRBLK_FL) flag, because
it's not actually used anywhere, and I can't figure out
how it differs from 'c' (EXT2_COMPR_FL))

Also, because the matrix of filesystems & flags is quite large,
refer to filesystem-specific manpages for detailed discussion
of flags supported by those filesystems, rather than trying to
cover it all in this manpage.  I'll send those manpage
updates to the appropriate lists a bit later.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
2014-07-04 23:59:45 -04:00
Eric Sandeen 5b9aaae742 e2fsprogs: reorder flags in chattr(1)
The flags described in chattr usage() and the chattr(1) manpage
were in semi-random order, which makes it hard to ascertain
which flags might be missing or undocumented, and to locate
flags within the manpage.

Re-order the list of flags in alphanumeric order, and do
the same for the flag descriptions in the body of the manpage.

There should be no content changes here, just reordering
for consistency.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
2014-07-04 23:59:45 -04:00
Frank Sorenson 4b59352edb mke2fs: prevent creation of filesystem with unsupported revision
It's a bit strange to accept revision levels higher than
the code creating the filesystem can understand, so don't
allow it.

At least the kernel will mount the fs readonly if it's too
high, but no other utility will touch it, so you can't
fix the error.

Just reject anything > EXT2_MAX_SUPP_REV at mkfs time.

Signed-off-by: Frank Sorenson <fsorenso@redhat.com>
[sandeen@redhat.com: Add more verbose commit log]
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-04 23:59:44 -04:00
Andreas Dilger 3120a50e1a misc: quiet minor build warnings, ignore generated files
Quiet a couple of build warnings in tst_libext2fs.c
Add missing unistd.h header for misc/util.c.

Ignore generated files for lib/ext2fs/tst_libext2fs and intl/ files.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-07-04 16:39:44 -04:00
Theodore Ts'o bb9cca2ca9 Merge branch 'maint' into next 2014-06-01 21:49:21 -04:00
Eric Sandeen f2ca701c1c filefrag: fix issues with 29758d2
29758d2 filefrag: exit with error code if an error is hit

introduced a couple errors; in one case it missed returning
a value, and possibly picked up errno from (unchecked) close(),
and in the other used a test where it needed an
assignment.  So capture the error, move perror() directly
after the failed call in both cases, and fix the assignment.

Also fix a precedence problem with:

	if (fe_flags & mask == 0)

which is equivalent to:

	if (fe_flags & (mask == 0))

but we need:

	if ((fe_flags & mask) == 0)

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
2014-06-01 21:27:43 -04:00
Benno Schulenberg d7f786c893 mke2fs: gettextize an overlooked error message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-06-01 21:23:44 -04:00
Benno Schulenberg 35a0bdd7e2 mke2fs: fix a typo in an error message
Signed-off-by: Benno Schulenberg <bensberg@justemail.net>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-06-01 21:12:47 -04:00
Andreas Dilger bbccc6f3c6 misc: fix compile warnings on master branch
Fix compile warnings found on the master branch when using LLVM.

- Add missing format string when using the libintl _() macro
- include <limits.h> header to get PATH_MAX definition
- fix format vs. variable mismatches
- add header block for create_inode.c file
- remove use of bzero(), use ext2fs_get_memzero() instead

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-05-27 13:14:18 -04:00
Theodore Ts'o 4230096682 Merge branch 'maint' into next 2014-05-27 13:08:52 -04:00
Darrick J. Wong ec3a42b192 Misc coverity fixes
Fix various small resource leaks and error code handling issues that
Coverity pointed out.

Fixes-Coverity-Bugs: 1215250, 1193379, 119194[2-4], 1049160
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-05-27 13:02:19 -04:00
Andreas Dilger 29758d2fc5 filefrag: exit with error code if an error is hit
If an error is hit during filefrag operation, it will continue to run
(if multiple files are specified on the command-line), but will exit
with a non-zero value, so that callers can determine that some error
was hit.

Clean up the printing of FIEMAP flags and print some newer flags that
were missing.  Also print unknown flags as hex values.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2014-05-27 12:56:45 -04:00
Andreas Dilger 3cbb51f91d misc: fix create_inode warnings with LLVM
Fix name clash in do_mknod_internal() due to local variables named
"major" and "minor" shadowing identical macro names.

Also, no need to set the major and minor device for a FIFO inode.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
2014-05-27 12:50:48 -04:00