Commit Graph

1907 Commits (c733f9987e26062fcdd77ccda64ed53b87014082)

Author SHA1 Message Date
David Turner 082ed5dcd9 e2fsck: correct ext4 dates generated by old kernels
Older kernels on 64-bit machines would incorrectly encode pre-1970
ext4 dates as post-2311 dates.  Detect and correct this (assuming the
current date is before 2242).

Include tests for this, as well as changes to debugfs to correctly
set crtimes.

Signed-off-by: David Turner <novalis@novalis.org>
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-14 13:57:33 -04:00
Eric Sandeen f3745728bc resize2fs: clear uninit BG if allocating from new group
If resize2fs_get_alloc_block() allocates from a BLOCK_UNINIT group, we
need to make sure that the UNINIT flag is cleared on both file system
structures which are maintained by resize2fs.  This causes the
modified bitmaps to not get written out, which leads to post-resize2fs
e2fsck errors; used blocks in UNINIT groups, not marked in the block
bitmap.  This was seen on r_ext4_small_bg.

This patch uses clear_block_uninit() to clear the flag,
and my problem goes away.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Reviewed-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 21:51:23 -05:00
Theodore Ts'o 6d4bb11487 Merge branch 'maint' into next 2016-03-06 21:30:07 -05:00
Andreas Dilger 539d3ae3da misc: replace comparison macros with inline functions
Replace the EXT2FS_RB_EMPTY_ROOT(), EXT2FS_RB_EMPTY_NODE(),
EXT2FS_RB_CLEAR_NODE(), IS_BLOCK_BM(), IS_INODE_BM(), and
IS_INODE_TB() macros with static inline functions to avoid
suprious compiler warnings with clang:

	pass1.c:618:28: warning: equality comparison with extraneous
		parentheses [-Wparentheses-equality]
	if ((*((__u32 *)(entry)) == 0UL)) {
             ~~~~~~~~~~~~~~~~~~~~^~~~~~
	pass1.c:618:28: note: remove extraneous parentheses
		around the comparison to silence this warning
	if ((*((__u32 *)(entry)) == 0UL)) {
				 ^~
	pass1.c:618:28: note: use '=' to turn this equality
		comparison into an assignment
	if ((*((__u32 *)(entry)) == 0UL)) {
				 ^~
				 =

The static inline functions should compile identically, and allow
some extra compile-time checking for the arguments over macros.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 21:23:40 -05:00
Theodore Ts'o dcb8e1fa04 Merge branch 'maint' into next 2016-03-06 20:37:49 -05:00
Darrick J. Wong ba380eea99 libext2fs: sort keys for xattr blocks
Richard Purdie reports that libext2fs doesn't sort attribute keys in
the xattr block correctly, causing the kernel to return -ENODATA when
querying attributes that should be there.  Therefore, sort attributes
so that whatever ends up in the xattr block is sorted according to
what the kernel expects.

Cc: Darren Hart <dvhart@linux.intel.com>
Reported-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Tested-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 20:08:53 -05:00
Darrick J. Wong 2b8772f522 tests: check proper operation of metadata_csum_seed
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 20:08:53 -05:00
Darrick J. Wong 2ed0adbce6 libext2fs: store checksum seed in superblock
Allow the filesystem to store the metadata checksum seed in the
superblock and add an incompat feature to say that we're using it.
This enables tune2fs to change the UUID on a mounted metadata_csum
FS without having to (racy!) rewrite all disk metadata.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 20:08:52 -05:00
Theodore Ts'o ccf028f2e7 libe2p: add missing f[gs]etproject.c files
Li Xi's patch was missing the sources for fgetproject.c and
fsetproject.c.  I've created replacement files which will service the
purpose.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 20:08:52 -05:00
Li Xi 3627e83830 Add project ID support for chattr/lsattr
Chattr and lsattr can be used to set or get project ID:
chattr -p <project id> file
lsattr -p file

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 20:08:45 -05:00
Andreas Dilger 1e3f5c889d lsattr: treat inode generation as an unsigned int
The EXT2_GETVERSION ioctl is defined to take a "long" parameter, but
fgetversion() calls ioctl() with an "int" parameter instead.  This is
handled in the kernel correctly, but the generation is sign-extended
in fgetversion() before return on 64-bit systems and lsattr prints
it as a huge positive number for inode generation above 0x80000000:

        1635574212 -------------e-- /mnt/ost0/O/0/d0/12928
        18446744073045131735 -------------e-- /mnt/ost0/O/0/d0/166240
        782808861 -------------e-- /mnt/ost0/O/0/d0/31744
        18446744072181134840 -------------e-- /mnt/ost0/O/0/d0/135008

Correctly assign the returned generation number as an unsigned value,
and print it with a 10-character field width.  The version is printed
left-aligned for consistency with the old code and to ensure it is
always printed in the first column for use with tools like "cut":

        1635574212 -------------e-- /mnt/ost0/O/0/d0/12928
        3630547415 -------------e-- /mnt/ost0/O/0/d0/166240
        782808861  -------------e-- /mnt/ost0/O/0/d0/31744
        2766550520 -------------e-- /mnt/ost0/O/0/d0/135008

Do not return a random value from the stack as the version on error.
Clean up some style issues and consolidate some duplicate code.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 18:12:57 -05:00
Andreas Dilger 865dc0d753 blkid: fix ZFS device detection
While the main blkid functionality is in util-linux, there is still
use for blkid on non-Linux platforms.

Fix the ZFS device detection by looking at multiple uberblocks to
see if any are present, rather than looking for the ZFS boot block
which is not always present.

There are slots for up to 128 uberblocks, but the first 4 are not
written to disk on a newly-formatted filesystem, so check several
of them at different offsets within the uberblock array.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 18:11:47 -05:00
Li Xi e1cec4464b Add inherit flags for project quota
This patch add EXT4_PROJINHERIT_FL to enable inherit feature for
project ID. If an directory has its inherit flag set, all its
newly created children will inherit its project ID. Conversely,
new inodes will get a default project ID (i.e. zero). Also, no
hard link or rename is permitted if the directory and child has
different project ID.

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 17:33:45 -05:00
Li Xi 080e09b46f Add project quota support
This patch adds project quota support. An new quota type PRJQUOTA(2)
is added. EXT4_PRJ_QUOTA_INO(11) is reserved for project quota inode.
The super block reservers an field s_prj_quota_inum for saving
project quota inode. And each inode adds an internal field i_projid
for saving its project ID.

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 17:33:39 -05:00
Li Xi 0c18d0368a Add project feature flag EXT4_FEATURE_RO_COMPAT_PROJECT
This patch add project feature flag EXT4_FEATURE_RO_COMPAT_PROJECT.
Project feature is a read-only compat feature. Thus, an ext4 file
system with project feature enabled could only be read by ext4
kernel module without project feature support.

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 15:56:28 -05:00
Li Xi 2d2d799c72 Clean up codes for adding new quota type
Project quota related fields are reserved in Linux kernel.
As a preparation for it, this patch cleans up quota codes
of e2fsprogs so as to make it easier to add new quota type(s).

Signed-off-by: Li Xi <lixi@ddn.com>
Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-03-06 15:56:24 -05:00
Theodore Ts'o d030908bfc ext2fs: work around FreeBSD header breakage
FreeBSD 10.2 will blow up compiling its own header files in sys/file.h
if _XOPEN_SOURCE is defined.

In file included from tdb.c:59:
/usr/include/sys/file.h:209:2: error: unknown type name 'u_int'
        u_int   xf_flag;        /* flags (see fcntl.h) */
                ^
1 error generated.

This is despite the fact that POSIX.1 requires comforming applications
to define _XOPEN_SOURCE (to different numbers depending on the version
of POSIX.1 the program is expecting to work against).  See section
2.2.1 in POSIX.1 for chapter and verse.

Work around this by removing the _XOPEN_SOURCE declaration.  This will
cause compiler warnings (and will cause builds against some versions
of Solaris to break), so only do this for FreeBSD.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2016-01-01 20:12:22 -05:00
Theodore Ts'o 94676ef2b3 Merge branch 'maint' into next 2015-11-30 18:16:36 -05:00
Andreas Dilger e158db5377 libext2fs: fix block-mapped file punch
If ext2fs_punch() was called with "end = ~0ULL" to indicate truncate
to the end of file it tried to compute "count" for ext2fs_punch_ind()
based on "start" and "end", but incorrectly passed "count = ~0U" even
when "start" was non-zero, causing an overflow in some cases.

The calling convention for ext2fs_punch_ind() was also gratuitously
different from ext2fs_punch() and ext2fs_punch_extent(), passing
"count" instead of "end" as the last parameter.  Fix this by passing
it "end" like the other functions, and handle "count" internally.

Add checks to ext2fs_punch_ind() if "end" is at or beyond the 2^32
indirect block limit so the 32-bit internal variables don't overflow.

Signed-off-by: Andreas Dilger <andreas.dilger@intel.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-11-30 15:26:21 -05:00
Andreas Dilger f449486d63 libext2fs: fix tst_badblocks buffer overrun
The test2[] array is not 0-terminated and the create_test_list() for
loop does not terminate properly at the end of this array, but
continues until it hits the 0 at the end of test3[].

Reported-by: Hanno Boeck <hanno@hboeck.de>
Addresses: https://bugzilla.kernel.org/show_bug.cgi?id=104311
Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-11-30 12:09:44 -05:00
Theodore Ts'o 188960ea4b debugfs: add support to properly set and display extended timestamps
This code is partially derived from patches from David Turner to allow
debugfs to properly support extended timestamps.

Cc: David Turner <novalis@novalis.org>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2015-11-30 11:42:00 -05:00
Darrick J. Wong 7dce0c06e5 libext2fs: fix parents when modifying extents
In ext2fs_extent_set_bmap() and ext2fs_punch_extent(), fix the parents
when altering either end of an extent so that the parent nodes reflect
the added mapping.

There's a slight complication to using fix_parents: if there are two
mappings to an lblk in the tree, the value of handle->path->curr can
point to either extent afterwards), which is documented in a comment.

Some additional color commentary from Darrick:

  In the _set_bmap() case, I noticed that the "remapping last block in
  extent" case would produce symptoms if we are trying to remap a
  block from "extent" to "next_extent", and the two extents are
  pointed to by different index nodes.  _extent_replace(...,
  next_extent) updates e_lblk in the leaf extent, but because there's
  no _extent_fix_parents() call, the index nodes never get updated.

  In the _punch_extent() case, we conclude that we need to split an
  extent into two pieces since we're punching out the middle.  If the
  extent is the last extent in the block, the second extent will be
  inserted into a new leaf node block.  Without _fix_parents(), the
  index node doesn't seem to get updated.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
2015-11-16 06:08:17 -05:00
Darrick J. Wong 77b3e98718 libext2fs: clean up feature test macros with predicate functions
Create separate predicate functions to test/set/clear feature flags,
thereby replacing the wordy old macros.  Furthermore, clean out the
places where we open-coded feature tests.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-10-24 00:34:09 -04:00
Darrick J. Wong 03940aac54 libext2fs: automatically enable meta_bg to avoid filling up BG 0
If during formatting we'd lose more than 75% a block group to group
descriptors and other metadata, enable the meta_bg feature.  This
enables us to create >500T filesystems with default options.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-10-24 00:30:10 -04:00
Darrick J. Wong 1abdd04eb1 libext2fs: fix maximum bg overhead calculation with meta_bg enabled
When meta_bg is enabled at mkfs time, we put at most one group
descriptor block in each blockgroup.  Unfortunately, the calculation
of max overhead per bg doesn't know this, so mkfs fails when it isn't
strictly necessary.  Fix it, since Dave reported that he couldn't
create a 500TB ext4 filesystem.

Reported-by: Dave Chinner <david@fromorbit.com>
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-10-24 00:24:57 -04:00
Theodore Ts'o e695c12892 android: be able to build dumpe2fs, lsattr, and e2fsck statically
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-23 12:46:42 -04:00
Theodore Ts'o e3dd5c6f1a e2fsck: check for encrypted directory entries with too-short file names
If there are directory entries with file names which are less than 16
bytes, it turns out that passing less than the crypto block size to
the kernel's crypto layer will cause the kernel to crash.

However, since there never should be encrypted directory entries where
the file name is less than 16 bytes (the AES block size), change
e2fsck to offer to address this corruption by deleting the directory
entry.

(We need to checks for this condition into the kernel as well.)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-16 18:02:58 -04:00
Theodore Ts'o 4e222d9b88 misc: cleanup gcc -Wall warnings
Also change ext2fs_symlink() so that the target parameter is a const
char *, thus promising that we will never change the incoming string.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-13 15:36:12 -04:00
Theodore Ts'o cf491d3a64 Eliminate unused variable and unused label warnings from Android build
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-13 10:47:16 -04:00
Theodore Ts'o 25f291c9b3 Eliminate unused parameter warnings from Android build
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-13 09:12:23 -04:00
Theodore Ts'o aee40b870c Eliminate unused function warnings from Android build
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 23:09:15 -04:00
Theodore Ts'o f1644c324b Eliminate doubly defined _LARGEFILE_SOURCE warning
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 22:54:37 -04:00
Theodore Ts'o 3dca12fb62 Move dict.c from e2fsck to lib/support
The quota code required that we included dict.o in libsupport.a, so we
might as well just move dict.c and dict.h to lib/support, and then
have e2fsck use the version of dict.c in libsupport.a.  This
simplifies the build system and eliminates having two identical copies
of dict.o floating around in the build tree.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 22:43:31 -04:00
Theodore Ts'o 99ceb8ec1a Move the check_plausibility() function from misc to lib/support
The check_plausibility() function is now used all over the place, so
we should move the plausible.c file to lib/support and remove the
special case handling for that file that had been in the build system.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 22:01:17 -04:00
Theodore Ts'o 1dc16b0b95 Move the profile parsing functions from e2fsck to lib/support
The profile functions started as something specific to e2fsck.  It's
now used by mke2fs and e2fsck, so it's better to move it into
libsupport.a.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 21:39:31 -04:00
Theodore Ts'o 273c2c5dfd tune2fs: allow tune2fs to be built as a static library for Android
Sync up with aosp's e2fsprogs commits:

    d25948b9b4a9e361ef071dc8175df0407f60b7e0
    e59f7c7cedb1e07eb4dbbb66e115c14faea19f19

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 20:21:17 -04:00
Theodore Ts'o 0a332f42f9 Add fallocate.c to lib/exte2fs/Android.mk
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 16:10:58 -04:00
Theodore Ts'o f34af41b72 rename libquota.a to libsupport.a
We will be using libsupport.a for e2fsprogs's internal support
functions.  It will contain the quota support functions, but we will
also be moving code such as profile.c and plausible.c to libsupport.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-12 16:09:22 -04:00
Theodore Ts'o 9e8fcd6e01 configure: remove support to disable quota support
For the 1.43 release, quota support will be the default.  It's much
simpler if we don't try to make quota support optional.  This was done
originally because the quota feature wasn't fully tested.  It is now,
so we can remove this as an option.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-03 22:02:30 -04:00
Theodore Ts'o 149640fabc configure: remove support to disable htree support
The presence of --disable-htree is very much a legacy thing.  Remove
it since supporting the lack of htree support is pretty silly.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-03 16:29:35 -04:00
Theodore Ts'o 59a220dd9f Fix "make clean" and "make distclean"
There were some generated files that weren't getting removed by the
clean and distclean targets; fix this.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-07-01 19:40:23 -04:00
Theodore Ts'o 8f8511aba0 libext2fs: fix gcc -Wall nits
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-21 20:15:52 -04:00
Theodore Ts'o 5ea7aee425 rename configure.in to configure.ac
Some newer versions of autoconf kvetch if we are still using
configure.in.  As of this writing the only version of autoconf which I
support is autoconf 2.69, and if you try to recreate the configure
script which is shipped with e2fsprogs, and it breaks, you get to keep
both pieces.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-20 14:33:24 -04:00
Theodore Ts'o 74f2c4aa18 fix diet libc build breaks for e4crypt and fallocate
Diet libc doesn't support syscall correctly, but it does have
add_key() and keyctl() in libc (although glibc does not).  So change
e4crypt to use add_key() and keyctl() directly if they are available.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-19 19:28:25 -04:00
Darrick J. Wong eeb2bb68f8 libext2fs: remove unnecessary undo file flush calls
Remove all flushes of the undo file except for the one that happens just
prior to the file being closed; it seems that the arbitrary flushes
aren't sufficiently useful.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-10 20:08:33 -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
Darrick J. Wong 5aad5b8e0e libext2fs: implement fallocate
Create a library function to perform fallocation on arbitrary files.
This is a bit more intense than Ted's original mk_hugefiles
implementation since we have to honor any blocks that may already be
allocated to the file.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-10 19:56:46 -04:00
Darrick J. Wong 647e878615 libext2fs: add new hooks to support large allocations
Add a new get_alloc_blocks hook and a block_alloc_stats_range hook so
that e2fsck can capture allocation requests spanning more than a
block to its block_found_map.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-06-10 14:13:25 -04:00
Theodore Ts'o beb19fce8a Allow debugfs to be built for use in Android
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
2015-05-25 22:26:20 -04:00