Whamcloud - gitweb
tools/e2fsprogs.git
3 years agolibext2fs: provide APIs to configure fast commit blocks
Harshad Shirwadkar [Wed, 20 Jan 2021 21:26:30 +0000 (13:26 -0800)]
libext2fs: provide APIs to configure fast commit blocks

This patch adds new libext2fs that allow configuring number of fast
commit blocks in journal superblock. We also add a struct
ext2fs_journal_params which contains number of fast commit blocks and
number of normal journal blocks. With this patch, the preferred way
for configuring number of blocks with and without fast commits is:

struct ext2fs_journal_params params;

ext2fs_get_journal_params(&params, ...);
params.num_journal_blocks = ...;
params.num_fc_blocks = ...;
ext2fs_create_journal_superblock2(..., &params, ...);
         OR
ext2fs_add_journal_inode3(..., &params, ...);

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoe2fsck: port fc changes from kernel's recovery.c to e2fsck
Harshad Shirwadkar [Wed, 20 Jan 2021 21:26:29 +0000 (13:26 -0800)]
e2fsck: port fc changes from kernel's recovery.c to e2fsck

This patch makes recovery.c identical with fast commit kernel changes.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoe2fsck: add kernel endian-ness conversion macros
Harshad Shirwadkar [Wed, 20 Jan 2021 21:26:28 +0000 (13:26 -0800)]
e2fsck: add kernel endian-ness conversion macros

In order to make recovery.c identical with kernel, we need endianness
conversion macros (such as cpu_to_be32 and friends) defined in
e2fsprogs. This patch defines these macros and also fixes recovery.c
to use these. These macros are also needed for fast commit recovery
patches later in this series.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoext2fs: move calculate_summary_stats to ext2fs lib
Harshad Shirwadkar [Wed, 20 Jan 2021 21:26:27 +0000 (13:26 -0800)]
ext2fs: move calculate_summary_stats to ext2fs lib

The function calculate_summary_stats sets the global metadata of the
file system. Tune2fs had this function defined statically in
tune2fs.c. Fast commit replay needs this function to set global
metadata at the end of the replay phase. So, move this function to
libext2fs.

Signed-off-by: Harshad Shirwadkar <harshadshirwadkar@gmail.com>
Reviewed-by: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoEnable threaded support for e2fsprogs' applications.
Theodore Ts'o [Thu, 14 Jan 2021 00:27:23 +0000 (16:27 -0800)]
Enable threaded support for e2fsprogs' applications.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoext2fs: parallel bitmap loading
Wang Shilong [Thu, 14 Jan 2021 00:27:22 +0000 (16:27 -0800)]
ext2fs: parallel bitmap loading

In our benchmarking for PiB size filesystem, pass5 takes
10446s to finish and 99.5% of time takes on reading bitmaps.

It makes sense to reading bitmaps using multiple threads,
a quickly benchmark show 10446s to 626s with 64 threads.

[ This has all of many bug fixes for rw_bitmaps.c from the original
  luster patch set collapsed into a single commit.   In addition it has
  the new ext2fs_rw_bitmaps() api proposed by Ted. ]

Signed-off-by: Wang Shilong <wshilong@ddn.com>
Signed-off-by: Saranya Muruganandam <saranyamohan@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agolibext2fs: allow the unix_io manager's cache to be disabled and re-enabled
Theodore Ts'o [Thu, 14 Jan 2021 00:27:21 +0000 (16:27 -0800)]
libext2fs: allow the unix_io manager's cache to be disabled and re-enabled

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agolibext2fs: add threading support to the I/O manager abstraction
Theodore Ts'o [Thu, 14 Jan 2021 00:27:20 +0000 (16:27 -0800)]
libext2fs: add threading support to the I/O manager abstraction

Add initial implementation support for the unix_io manager.
Applications which want to use threading should pass in
IO_FLAG_THREADS when opening the channel.  Channels which support
threading (which as of this commit is unix_io and test_io if the
backing io_manager supports threading) will set the
CHANNEL_FLAGS_THREADS bit in io->flags.  Library code or applications
can test if threading is enabled by checking this flag.

Applications using libext2fs can pass in EXT2_FLAG_THREADS to
ext2fs_open() or ext2fs_open2() to request threading support.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoAdd configure and build support for the pthreads library
Theodore Ts'o [Thu, 14 Jan 2021 00:27:19 +0000 (16:27 -0800)]
Add configure and build support for the pthreads library

Support for pthreads can be forcibly disabled by passing
"--without-pthread" to the configure script.

The actual changes in this commit are in configure.ac and MCONFIG.in;
the other files were generated as a result of running aclocal,
autoconf, and autoheader on a Debian testing system.

Note: the autoconf-archive package must now be installed before
rerunning aclocal, to supply the AX_PTHREAD macro.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoMerge branch 'maint' into next
Theodore Ts'o [Wed, 20 Jan 2021 04:58:57 +0000 (23:58 -0500)]
Merge branch 'maint' into next

3 years agomke2fs: Escape double quotes when parsing mke2fs.conf
Lukas Czerner [Mon, 2 Nov 2020 14:26:31 +0000 (15:26 +0100)]
mke2fs: Escape double quotes when parsing mke2fs.conf

Currently, when constructing the <default> configuration pseudo-file using
the profile-to-c.awk script we will just pass the double quotes as they
appear in the mke2fs.conf.

This is problematic, because the resulting default_profile.c will either
fail to compile because of syntax error, or leave the resulting
configuration invalid.

It can be reproduced by adding the following line somewhere into
mke2fs.conf configuration and forcing mke2fs to use the <default>
configuration by specifying nonexistent mke2fs.conf

MKE2FS_CONFIG="nonexistent" ./misc/mke2fs -T ext4 /dev/device

default_mntopts = "acl,user_xattr"
^ this will fail to compile

default_mntopts = ""
^ this will result in invalid config file

Syntax error in mke2fs config file (<default>, line #4)
       Unknown code prof 17

Fix it by escaping the double quotes with a backslash in
profile-to-c.awk script.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agolibext2fs: add gnu.translator support
Romain Naour [Mon, 2 Nov 2020 13:03:19 +0000 (14:03 +0100)]
libext2fs: add gnu.translator support

The support of setting (and reading) of passive translators from
GNU/Linux has been added to the Linux kernel by the commit [1].
The name index '10' has been reserved for GNU/Hurd.

Hurd passive translators are stored as a xattr value with name
"gnu.translator" [2].

If "gnu.translator" xattr value has been set before calling
mkfs.ext2, it will segfault since "gnu." is not present in
ea_names[].

$ setfattr -n gnu.translator -v "/hurd/exec\0" ${TARGET_DIR}/servers/exec
$ mkfs.ext2 -d ${TARGET_DIR} -o hurd -O ext_attr rootfs.ext2 "1G"

Adding "gnu." to ea_names[], allow to create ext2 filesystem
for GNU/Hurd with passive translator already set.

[1] https://git.savannah.gnu.org/cgit/hurd/hurd.git/commit/?id=a04c7bf83172faa7cb080fbe3b6c04a8415ca645
[2] https://lists.gnu.org/archive/html/bug-hurd/2016-08/msg00075.html

Signed-off-by: Romain Naour <romain.naour@gmail.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agofilefrag: handle invalid st_dev and blksize cases
Luis Henriques [Wed, 28 Oct 2020 15:55:50 +0000 (15:55 +0000)]
filefrag: handle invalid st_dev and blksize cases

It is possible to crash filefrag with a "Floating point exception" in
two different scenarios:

1. When fstat() returns a device ID set to 0
2. When FIGETBSZ ioctl returns a blocksize of 0

In both scenarios a divide-by-zero will occur in frag_report() because
variable blksize will be set to zero.

I've managed to trigger this crash with an old CephFS kernel client,
using xfstest generic/519.  The first scenario has been fixed by kernel
commit 75c9627efb72 ("ceph: map snapid to anonymous bdev ID").  The
second scenario is also fixed with commit 8f97d1e99149 ("vfs: fix
FIGETBSZ ioctl on an overlayfs file").

However, it is desirable to handle these two scenarios gracefully by
checking these conditions explicitly.

Signed-off-by: Luis Henriques <lhenriques@suse.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agocreate_inode: set xattrs to the root directory as well
Antoine Tenart [Fri, 17 Jul 2020 10:08:46 +0000 (12:08 +0200)]
create_inode: set xattrs to the root directory as well

populate_fs do copy the xattrs for all files and directories, but the
root directory is skipped and as a result its extended attributes aren't
set. This is an issue when using mkfs to build a full system image that
can be used with SElinux in enforcing mode without making any runtime
fix at first boot.

This patch adds logic to set the root directory's extended attributes.

Signed-off-by: Antoine Tenart <antoine.tenart@bootlin.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agopo: reapply local e2fsprogs chages to po/Makefile.in.in
Theodore Ts'o [Wed, 25 Nov 2020 13:47:54 +0000 (08:47 -0500)]
po: reapply local e2fsprogs chages to po/Makefile.in.in

These are the changes which are needed after running gettextize to
update to gettext 0.19.8 in the previous commit.

 * Add support for maintainer mode (which doesn't do as much given
     that gettext now has settings in Makevars which allows us to
     suppress automatic updates of the po and gmo files)
 * Add support to expand the '@' abbreviations in e2fsck/problem.c
     and give an explanation of how they work for translators
 * Add support for configure --enable-verbose-makecmds and default to
     "kernel-style" quieter make output --- this makes it easier
     to see warnings and errors by suppressing the distracting
     details.
 * Teach the makefile where to find the generated error table C files
     in the build directory.
 * Add make targets (e.g., all-static, fullcheck, coverage.txt) which
     are required by the top-level Makefile.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoUpdate gettext files to version 0.19.8
Theodore Ts'o [Wed, 25 Nov 2020 04:00:57 +0000 (23:00 -0500)]
Update gettext files to version 0.19.8

This also removes the built-in "intl" directory as this is now
considered deprecated by the gettext package.  This means that we
won't try to use an internal version of gettext if it's not installed
on the build system.  We will simply disable NLS support in that case.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agopo: update sr.po (from translationproject.org)
Мирослав Николић [Wed, 25 Nov 2020 03:36:54 +0000 (22:36 -0500)]
po: update sr.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agopo: update nl.po (from translationproject.org)
Benno Schulenberg [Wed, 25 Nov 2020 03:36:54 +0000 (22:36 -0500)]
po: update nl.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agopo: update ms.po (from translationproject.org)
Sharuzzaman Ahmat Raslan [Wed, 25 Nov 2020 03:36:54 +0000 (22:36 -0500)]
po: update ms.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agorelease notes: delete two files that are fully contained within v1.41.txt
Benno Schulenberg [Wed, 28 Oct 2020 03:41:06 +0000 (23:41 -0400)]
release notes: delete two files that are fully contained within v1.41.txt

They are pure duplicates.

Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agodebugfs: fix parse_uint for 64-bit fields
Theodore Ts'o [Tue, 6 Oct 2020 12:29:09 +0000 (08:29 -0400)]
debugfs: fix parse_uint for 64-bit fields

The logic for handling 64-bit structure elements was reversed, which
caused attempts to set fields like kbytes_written to fail:

    % debugfs -w /tmp/foo.img
    debugfs 1.45.6 (20-Mar-2020)
    debugfs:  set_super_value kbytes_written 1024
    64-bit field kbytes_written has a second 64-bit field
    defined; BUG?!?

https://github.com/tytso/e2fsprogs/issues/36

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoDefine MKDIR_P in the Makefile.in files instead in MCONFIG.in
Theodore Ts'o [Mon, 5 Oct 2020 03:05:01 +0000 (23:05 -0400)]
Define MKDIR_P in the Makefile.in files instead in MCONFIG.in

In the case where mkdir -p is not thread-safe (for example, if the
build environment is using busybox's mkdir) the configure script will
fall back to the slow (but safe) install-sh script.  In that case
MKDIR_P will be using a relative pathname; so we can't use speed
optimization of defining configure substitutions in MCONFIG.in, since
the substitution will be different depending on depth of the
subdirectory in the Makefile.in file.

https://github.com/tytso/e2fsprogs/issues/51

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoresize2fs: prevent block group descriptors from overflowing the first bg
Theodore Ts'o [Fri, 2 Oct 2020 18:47:25 +0000 (14:47 -0400)]
resize2fs: prevent block group descriptors from overflowing the first bg

For 1k block file systems, resizing a file system larger than
1073610752 blocks will result in the size of the block group
descriptors to be so large that it will overlap with the backup
superblock in block group #1.   This problem can be reproduced via:

    mke2fs -t ext4 /tmp/foo.img 200M
    resize2fs /tmp/foo.img 1T
    e2fsck -f /tmp/foo.img

https://github.com/tytso/e2fsprogs/issues/50

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoAOSP: Fix a trivial type error
Yi Kong [Tue, 7 Jul 2020 14:32:12 +0000 (22:32 +0800)]
AOSP: Fix a trivial type error

Comparing unsigned int with ULONG_MAX is always false.

Signed-off-by: Yi Kong <yikong@google.com>
Change-Id: Iae02aad1bcb271d3468828977be288ad04333821
From AOSP commit: 757a4d672dae1a15c57f5f0705ba90ed007da7e6

3 years agoAOSP: Include private/fs_config.h directly when needed
Tom Cherry [Wed, 4 Mar 2020 21:41:14 +0000 (13:41 -0800)]
AOSP: Include private/fs_config.h directly when needed

This is no longer a transitive include of android_filesystem_config.h

Bug: 149785767
Test: build
Change-Id: I954adf7879fa811eb2b290a0983c84d47ecae26c
From AOSP commit: 9fa6bed983d5ddd7226af647a0c4c0d922227be4

3 years agoMerge branch 'maint' into next
Theodore Ts'o [Thu, 1 Oct 2020 21:13:27 +0000 (17:13 -0400)]
Merge branch 'maint' into next

3 years agochattr/lsattr: Support dax attribute
Xiao Yang [Tue, 28 Jul 2020 05:33:21 +0000 (13:33 +0800)]
chattr/lsattr: Support dax attribute

Use the letter 'x' to set/get dax attribute on a directory/file.

Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agomke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF
Hongxu Jia [Wed, 22 Jul 2020 01:25:03 +0000 (18:25 -0700)]
mke2fs: fix up check for hardlinks always false if inode > 0xFFFFFFFF

While file has a large inode number (> 0xFFFFFFFF), mkfs.ext4 could
not parse hardlink correctly.

Prepare three hardlink files for mkfs.ext4

$ ls -il rootfs_ota/a rootfs_ota/boot/b rootfs_ota/boot/c
11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/a
11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/boot/b
11026675846 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 rootfs_ota/boot/c

$ truncate -s 1M rootfs_ota.ext4

$ mkfs.ext4 -F -i 8192 rootfs_ota.ext4 -L otaroot -U fd5f8768-c779-4dc9-adde-165a3d863349 -d rootfs_ota

$ mkdir mnt && sudo mount rootfs_ota.ext4 mnt

$ ls -il mnt/a mnt/boot/b mnt/boot/c
12 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/a
14 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/boot/b
15 -rw-r--r-- 1 hjia users 0 Jul 20 17:44 mnt/boot/c

After applying this fix
$ ls -il mnt/a mnt/boot/b mnt/boot/c
12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/a
12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/boot/b
12 -rw-r--r-- 3 hjia users 0 Jul 20 17:44 mnt/boot/c

Since commit [382ed4a1 e2fsck: use proper types for variables][1]
applied, it used ext2_ino_t instead of ino_t for referencing inode
numbers, but the type of is_hardlink's `ino' should not be instead,
The ext2_ino_t is 32bit, if inode > 0xFFFFFFFF, its value will be
truncated.

Add a debug printf to show the value of inode, when it check for hardlink
files, it will always return false if inode > 0xFFFFFFFF
|--- a/misc/create_inode.c
|+++ b/misc/create_inode.c
|@@ -605,6 +605,7 @@ static int is_hardlink(struct hdlinks_s *hdlinks, dev_t dev, ext2_ino_t ino)
| {
|        int i;
|
|+       printf("%s %d, %lX, %lX\n", __FUNCTION__, __LINE__, hdlinks->hdl[i].src_ino, ino);
|        for (i = 0; i < hdlinks->count; i++) {
|                if (hdlinks->hdl[i].src_dev == dev &&
|                    hdlinks->hdl[i].src_ino == ino)

Here is debug message:
is_hardlink 608, 2913DB886913DB886

The length of ext2_ino_t is 32bit (typedef __u32 __bitwise ext2_ino_t;),
and ino_t is 64bit on 64bit system (such as x86-64), recover `ino' to ino_t.

[1] https://git.kernel.org/pub/scm/fs/ext2/e2fsprogs.git/commit/?id=382ed4a1c2b60acb9db7631e86dda207bde6076e

Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agomke2fs: Warn if fs block size is incompatible with DAX
Jan Kara [Thu, 9 Jul 2020 14:40:57 +0000 (16:40 +0200)]
mke2fs: Warn if fs block size is incompatible with DAX

If we are creating filesystem on DAX capable device, warn if set block
size is incompatible with DAX to give admin some hint why DAX might not
be available.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoe4crypt: if salt is explicitly provided to add_key, then use it
Florian Schmaus [Tue, 7 Jul 2020 08:27:30 +0000 (10:27 +0200)]
e4crypt: if salt is explicitly provided to add_key, then use it

Providing -S and a path to 'add_key' previously exhibited an
unintuitive behavior: instead of using the salt explicitly provided by
the user, e4crypt would use the salt obtained via
EXT4_IOC_GET_ENCRYPTION_PWSALT on the path. This was because
set_policy() was still called with NULL as salt.

With this change we now remember the explicitly provided salt (if any)
and use it as argument for set_policy().

Eventually

e4crypt add_key -S s:my-spicy-salt /foo

will now actually use 'my-spicy-salt' and not something else as salt
for the policy set on /foo.

Signed-off-by: Florian Schmaus <flo@geekplace.eu>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agotune2fs: reset MMP state on error exit
Andreas Dilger [Wed, 17 Jun 2020 11:40:49 +0000 (05:40 -0600)]
tune2fs: reset MMP state on error exit

If tune2fs cannot perform the requested change, ensure that the MMP
block is reset to the unused state before exiting.  Otherwise, the
filesystem will be left with mmp_seq = EXT4_MMP_SEQ_FSCK set, which
prevents it from being mounted afterward:

    EXT4-fs warning (device dm-9): ext4_multi_mount_protect:311:
        fsck is running on the filesystem

Add a test to try some failed tune2fs operations and verify that the
MMP block is left in a clean state afterward.

Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13672
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoext2fs: remove unused variable 'left'
Lukas Czerner [Fri, 5 Jun 2020 08:14:42 +0000 (10:14 +0200)]
ext2fs: remove unused variable 'left'

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoe2fsck: use the right conversion specifier in e2fsck_allocate_memory()
Lukas Czerner [Fri, 5 Jun 2020 08:14:41 +0000 (10:14 +0200)]
e2fsck: use the right conversion specifier in e2fsck_allocate_memory()

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agoe2fsck: use size_t instead of int in string_copy()
Lukas Czerner [Fri, 5 Jun 2020 08:14:40 +0000 (10:14 +0200)]
e2fsck: use size_t instead of int in string_copy()

len argument in string_copy() is int, but it is used with malloc(),
strlen(), strncpy() and some callers use sizeof() to pass value in. So
it really ought to be size_t rather than int. Fix it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agotests: remove unnecessary uncompressed image file
Theodore Ts'o [Wed, 30 Sep 2020 21:18:35 +0000 (17:18 -0400)]
tests: remove unnecessary uncompressed image file

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agolibext2fs: fix potential buffer overrun in __get_dirent_tail()
Theodore Ts'o [Wed, 26 Aug 2020 20:29:29 +0000 (16:29 -0400)]
libext2fs: fix potential buffer overrun in __get_dirent_tail()

If the file system is corrupted, there is a potential of a read-only
buffer overrun.  Fortunately, we don't actually use the result of that
pointer dereference, and the overrun is at most 64k.

Google-Bug-Id: #158564737
Fixes: eb88b751745b ("libext2fs: make ext2fs_dirent_has_tail() more strict")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
3 years agodebugfs: fix building rdebugfs (with READ_ONLY define)
Theodore Ts'o [Thu, 18 Jun 2020 01:43:37 +0000 (21:43 -0400)]
debugfs: fix building rdebugfs (with READ_ONLY define)

Fix bitrot for building a restricted version of debugfs, which does
not require read/write access to the file system, and which only
allows access to the file system metadata.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: retry reading superblock on open when checksum is bad
Theodore Ts'o [Mon, 18 May 2020 03:05:11 +0000 (23:05 -0400)]
libext2fs: retry reading superblock on open when checksum is bad

When opening a file system which is mounted, it's possible that when
ext2fs_open2() is racing with the kernel modifying the orphaned inode
list, the superblock's checksum could be incorrect.  So retry reading
the superblock in the hopes that the problem will self-correct.

Google-Bug-Id: 151453112
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: batch calls to ext2fs_zero_blocks2()
Theodore Ts'o [Sat, 25 Apr 2020 15:41:24 +0000 (11:41 -0400)]
libext2fs: batch calls to ext2fs_zero_blocks2()

When allocating blocks for an indirect block mapped file, accumulate
blocks to be zero'ed and then call ext2fs_zero_blocks2() to zero them
in large chunks instead of block by block.

This significantly speeds up mkfs.ext3 since we don't send a large
number of ZERO_RANGE requests to the kernel, and while the kernel does
batch write requests, it is not batching ZERO_RANGE requests.  It's
more efficient to batch in userspace in any case, since it avoids
unnecessary system calls.

Reported-by: Mario Schuknecht <mario.schuknecht@dresearch-fe.de>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: fix off-by-one check when validating depth of an htree
Theodore Ts'o [Fri, 10 Apr 2020 04:30:52 +0000 (00:30 -0400)]
e2fsck: fix off-by-one check when validating depth of an htree

Fixes: 3f0cf6475399 ("e2fsprogs: add support for 3-level htree")

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: avoid pointer arithmetic on `void *`
Michael Forney [Sun, 5 Apr 2020 04:53:46 +0000 (21:53 -0700)]
libext2fs: avoid pointer arithmetic on `void *`

The pointer operand to the binary `+` operator must be to a complete
object type.

Signed-off-by: Michael Forney <mforney@mforney.org>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotune2fs.8: document the stable_inodes feature
Eric Biggers [Wed, 1 Apr 2020 20:32:39 +0000 (13:32 -0700)]
tune2fs.8: document the stable_inodes feature

Signed-off-by: Eric Biggers <ebiggers@google.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoext4.5: document the stable_inodes feature
Eric Biggers [Wed, 1 Apr 2020 20:32:38 +0000 (13:32 -0700)]
ext4.5: document the stable_inodes feature

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotune2fs: prevent stable_inodes feature from being cleared
Eric Biggers [Wed, 1 Apr 2020 20:32:37 +0000 (13:32 -0700)]
tune2fs: prevent stable_inodes feature from being cleared

Similar to encrypt and verity, once the stable_inodes feature has been
enabled there may be files anywhere on the filesystem that require this
feature.  Therefore, in general it's unsafe to allow clearing it.  Don't
allow tune2fs to do so.  Like encrypt and verity, it can still be
cleared with debugfs if someone really knows what they're doing.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotune2fs: prevent changing UUID of fs with stable_inodes feature
Eric Biggers [Wed, 1 Apr 2020 20:32:36 +0000 (13:32 -0700)]
tune2fs: prevent changing UUID of fs with stable_inodes feature

The stable_inodes feature is intended to indicate that it's safe to use
IV_INO_LBLK_64 encryption policies, where the encryption depends on the
inode numbers and thus filesystem shrinking is not allowed.  However
since inode numbers are not unique across filesystems, the encryption
also depends on the filesystem UUID, and I missed that there is a
supported way to change the filesystem UUID (tune2fs -U).

So, make 'tune2fs -U' report an error if stable_inodes is set.

We could add a separate stable_uuid feature flag, but it seems unlikely
it would be useful enough on its own to warrant another flag.

Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoext2fs: fix off-by-one in dx_grow_tree()
Jan Kara [Mon, 30 Mar 2020 09:09:32 +0000 (11:09 +0200)]
ext2fs: fix off-by-one in dx_grow_tree()

There is an off-by-one error in dx_grow_tree() when checking whether we
can add another level to the tree. Thus we can grow tree too much
leading to possible crashes in the library or corrupted filesystem. Fix
the bug.

Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoext2fs: fix error checking in dx_link()
Jan Kara [Mon, 30 Mar 2020 09:09:31 +0000 (11:09 +0200)]
ext2fs: fix error checking in dx_link()

dx_lookup() uses errcode_t return values. As such anything non-zero is
an error, not values less than zero. Fix the error checking to avoid
crashes on corrupted filesystems.

Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoTeach makefiles to build all static programs using the target all-static
Theodore Ts'o [Sat, 28 Mar 2020 21:56:56 +0000 (17:56 -0400)]
Teach makefiles to build all static programs using the target all-static

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoext4: add support for printing the error code associated with an error
Theodore Ts'o [Sat, 28 Mar 2020 20:51:52 +0000 (16:51 -0400)]
ext4: add support for printing the error code associated with an error

The error code allows the kernel to bucket the possible cause of an
ext4 corruption by Unix errno codes (e.g., EIO, EFSBADCRC, ESHUTDOWN,
etc.)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotests: use grep -E for better portability in r_inline_xattr
Theodore Ts'o [Mon, 23 Mar 2020 03:56:14 +0000 (23:56 -0400)]
tests: use grep -E for better portability in r_inline_xattr

Since r_inline_xattr is using an extended regexp, we need grep -E on
some implementations of grep.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: fix various gcc -Wall nits
Theodore Ts'o [Mon, 23 Mar 2020 03:47:12 +0000 (23:47 -0400)]
e2fsck: fix various gcc -Wall nits

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoUse ext2_loff_t instead of loff_t
Theodore Ts'o [Mon, 23 Mar 2020 03:30:14 +0000 (23:30 -0400)]
Use ext2_loff_t instead of loff_t

The loff_t type is a glibc'ism and is not fully portable.  Use
ext2_loff_t instead.

Fixes: 382ed4a1c2b6 ("e2fsck: use proper types for variables")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Reported-by: Matthias Andree <matthias.andree@gmx.de>
4 years agoMerge tag 'v1.45.6' into next
Theodore Ts'o [Sun, 22 Mar 2020 02:34:30 +0000 (22:34 -0400)]
Merge tag 'v1.45.6' into next

v1.45.6

4 years agoUpdate release notes, etc., for the 1.45.6 release v1.45.6
Theodore Ts'o [Sat, 21 Mar 2020 03:51:07 +0000 (23:51 -0400)]
Update release notes, etc., for the 1.45.6 release

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoAOSP: tune2fs, resize2fs: make ramdisk binaries.
Jaegeuk Kim [Wed, 12 Feb 2020 19:34:49 +0000 (11:34 -0800)]
AOSP: tune2fs, resize2fs: make ramdisk binaries.

Bug: 149391799
Change-Id: I5183755915710e28a603e3f718f16813ea9991a0
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
From AOSP commit: a13a88d0d557a396f63702fb8db008487e2384d7

4 years agoAOSP: e2fsdroid: Don't skip unusable blocks in BaseFS.
David Anderson [Fri, 14 Feb 2020 20:44:48 +0000 (12:44 -0800)]
AOSP: e2fsdroid: Don't skip unusable blocks in BaseFS.

Currently, basefs_allocator will iterate through blocks owned by an
inode until it finds a block that is free. This effectively ignores the
logical to physical block mapping, which can lead to a bigger delta in
the final image.

An example of how this can happen is if the BaseFS has a deduplicated
block (D), that is not deduplicated in the new image:

  Old image: 1 2 3 D 4 5
  New image: 1 2 3 ? 4 5

If the allocator sees that "D" is not usable, and skips to block "4",
we will have a non-ideal assignment.

  Bad image: 1 2 3 4 5 ?

This patch refactors get_next_block() to acquire at most one block. It's
called a single time, and then only called in a loop if absolutely no
blocks can be acquired from anywhere else.

In a Virtual A/B simulation, this reduces the COW snapshot size by about
90MB.

Bug: 139201772
Test: manual test
Change-Id: I354f0dee1ee191dba0e1f90491ed591dba388f7f
From AOSP commit: a495b54f89b2ec0e46be8e3564e4852c6434687c

4 years agoAOSP: e2fsdroid: Fix logical block sequencing in BaseFS.
David Anderson [Fri, 14 Feb 2020 03:20:32 +0000 (19:20 -0800)]
AOSP: e2fsdroid: Fix logical block sequencing in BaseFS.

By iterating over blocks to write BaseFS, holes in the extent tree are
skipped. This is problematic because the purpose of BaseFS is to
preserve the logical to physical block assignment between builds. By not
preserving the location of holes, the assignment can be incorrect.

For example, consider the following block list for a file:
   1 2 3 0 4 5

If this is recorded as:
   1 2 3 4 5

If the first block changes to a hole, the intended mapping will not be
preserved at all:
   0 1 2 0 3

This patch makes two changes to e2fsdroid to fix this. The first change
is that holes are now recorded in BaseFS, by iterating over the extent
tree rather than the block list, and inserting zeroes where appropriate.

The second change is that the block allocator now recognizes when blocks
have been skipped (either to deduplication or to holes), and skips the
same number of logical blocks in BaseFS as well.

In a Virtual A/B simulation, this reduces the COW snapshot size by
approximately 100MB.

Bug: 139201772
Test: m target-files-package, inspect .map files
From AOSP commit: d391f3bf38cbe51718d5c3c0bb3e72b1a9978625

4 years agoAOSP: e2fsdroid: Properly free the dedup block map.
David Anderson [Wed, 29 Jan 2020 23:31:14 +0000 (15:31 -0800)]
AOSP: e2fsdroid: Properly free the dedup block map.

When BaseFS specifies the same block for two files, it gets added to a
separate "dedup" bitmap, and removed from the free block bitmap. If the
new build does not use every block in this bitmap, there will be an
inconsistency: the block bitmap marks blocks as in-use when they are
actually free. Although this doesn't matter for AOSP's read-only file
systems, it does cause e2fsck to complain, which breaks the build.

Fix the inconsistency by properly freeing all unused blocks within the
dedup block set.

Bug: 139201772
Test: build AOSP using BaseFS
Change-Id: I6b6511eb713a56fec932f1d5668f1766d64d9479
From AOSP commit: 346bee6f8b97aefe7714688f738606c116099fbc

4 years agoAOSP: Build e2freefrag
Alessio Balsini [Fri, 24 Jan 2020 16:04:44 +0000 (16:04 +0000)]
AOSP: Build e2freefrag

Enable the build of e2freefrag to monitor the free space fragmentation
in ext2/3/4 filesystems.

Bug: 146078546
Test: m + e2freefrag on device
Change-Id: Ia56e443a789ae881a03bdaeae1093567e1736c4c
Signed-off-by: Alessio Balsini <balsini@google.com>
From AOSP commit: ab77f6c79f3dab697cd56ad3b793e7d555ac9415

4 years agoAOSP: Add -e2fsprogs to the e2fsprogs chattr and lsattr.
Elliott Hughes [Thu, 23 Jan 2020 23:44:10 +0000 (15:44 -0800)]
AOSP: Add -e2fsprogs to the e2fsprogs chattr and lsattr.

We want to start shipping the toybox chattr and lsattr on the device all
the time, so the build system rightly complains that then we'd have two
modules with the same name.

I went with a suffix rather than a prefix so that tab completion works
for folks still wanting to use the e2fsprogs versions.

Bug: http://b/147769529
Test: builds
Change-Id: Ib904fa6c709d29ce709302c61e452383c02cb9a3
From AOSP commit: 8525a455e7410461560a99a42feb0dbfabab5c8e

4 years agoAOSP: Make ramdisk_available.
Yifan Hong [Wed, 22 Jan 2020 00:44:20 +0000 (16:44 -0800)]
AOSP: Make ramdisk_available.

Test: pass
Bug: 147347110
Change-Id: Ie800ba1b56773dcc1b6563c4f19c27eccb9ffc1a
From AOSP commit: f5a8e8fdefd78deae971a475a7fa43734eef205e

4 years agoAOSP: Change #define to _BLKID_TYPES_H
Kousik Kumar [Fri, 10 Jan 2020 00:15:30 +0000 (16:15 -0800)]
AOSP: Change #define to _BLKID_TYPES_H

blkid_types.h and ext_types.h having the exact same content results in
mismatches in remote RBE builds. Given blkid_types.h is actually
supposed to be different, changing this to remove the mismatch.

Test: Ran a build, and all e2fsprogs mismatches went away between
local/remote.

Change-Id: I63ab1719ee1d0ccd28907f0bc99531260251fa99
From AOSP commit: ec10b513c283706f984edeec47301b0661f7d283

4 years agoAOSP: Allow resize2fs to compile with BUILD_HOST_static
Dario Freni [Mon, 6 Jan 2020 15:57:14 +0000 (15:57 +0000)]
AOSP: Allow resize2fs to compile with BUILD_HOST_static

Bug: 144477678
Test: BUILD_HOST_static=1 m resize2fs; m resize2fs
Change-Id: I0986deccfe496153e662dcc3cc2fb1ffb6973c21
From AOSP commit: 2c767b86591c64cd7b84c5619e8d8b8a0afd557e

4 years agoAOSP: Allow debugfs_static to be compiled as host tool.
Dario Freni [Thu, 2 Jan 2020 12:59:39 +0000 (12:59 +0000)]
AOSP: Allow debugfs_static to be compiled as host tool.

Bug: 144477678
Test: m debugfs_static
Change-Id: I7c360a2a381f8508578d14c32bbb280f386dd925
From AOSP commit: 742bb05a401eb2feb6caaee1c8d66fc1c37eef77

4 years agopo: update ms.po (from translationproject.org)
Sharuzzaman Ahmat Raslan [Sat, 21 Mar 2020 02:31:25 +0000 (22:31 -0400)]
po: update ms.po (from translationproject.org)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agomisc: add text describing the impact of an inode size < 128 bytes in man pages
Theodore Ts'o [Sat, 21 Mar 2020 01:35:03 +0000 (21:35 -0400)]
misc: add text describing the impact of an inode size < 128 bytes in man pages

Addresses-Debian-Bug: #953493
Addresses-Debian-Bug: #953494
Addresses-Debian-Bug: #951808
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibe2p: add a thread-safe variant of e2p_feature2string
Theodore Ts'o [Fri, 20 Mar 2020 21:57:38 +0000 (17:57 -0400)]
libe2p: add a thread-safe variant of e2p_feature2string

This commit adds the function e2p_feature_to_string() which allows the
caller to pass in a preallocated buffer.

Google-Bug-Id: 16978603
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: fix the {set_get}_bitmap_range functions when bitmap->start > 7
Theodore Ts'o [Fri, 20 Mar 2020 19:24:18 +0000 (15:24 -0400)]
libext2fs: fix the {set_get}_bitmap_range functions when bitmap->start > 7

The bitmap array's set/get bitmap_range functions were not subtracting
out bitmap->start.  This doesn't matter for normal file systems, since
the bitmap->start is zero or one, and the passed-in starting range is
a multiple of eight, and the starting range is then divided by 8.

But with a non-standard/fuzzed file system, bitmap->start could be
significantly larger, and this could then lead to a array out of
bounds memory reference.

Google-Bug-Id: 147849134
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: clarify overflow link count error message
Jan Kara [Thu, 13 Feb 2020 10:15:56 +0000 (11:15 +0100)]
e2fsck: clarify overflow link count error message

When directory link count is set to overflow value (1) but during pass 4
we find out the exact link count would fit, we either silently fix this
(which is not great because e2fsck then reports the fs was modified but
output doesn't indicate why in any way), or we report that link count is
wrong and ask whether we should fix it (in case -n option was
specified). The second case is even more misleading because it suggests
non-trivial fs corruption which then gets silently fixed on the next
run. Similarly to how we fix up other non-problems, just create a new
error message for the case directory link count is not overflown anymore
and always report it to clarify what is going on.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
(cherry picked from commit 4ebce13292f54c96f43dcb1bd1d5b8df5dc8749d)

4 years agoMerge branch 'maint' into next
Theodore Ts'o [Mon, 16 Mar 2020 11:59:08 +0000 (07:59 -0400)]
Merge branch 'maint' into next

4 years agotune2fs: update dir checksums when clearing dir_index feature
Jan Kara [Thu, 13 Feb 2020 10:16:02 +0000 (11:16 +0100)]
tune2fs: update dir checksums when clearing dir_index feature

When clearing dir_index feature while metadata_csum is enabled, we have
to rewrite checksums of all indexed directories to update checksums of
internal tree nodes.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotests: add test to excercise indexed directories with metadata_csum
Jan Kara [Thu, 13 Feb 2020 10:16:01 +0000 (11:16 +0100)]
tests: add test to excercise indexed directories with metadata_csum

Indexed directories have somewhat different format when metadata_csum is
enabled. Add test to excercise linking in indexed directories and e2fsck
rehash code in this case.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotests: modify f_large_dir test to excercise indexed dir handling
Jan Kara [Thu, 13 Feb 2020 10:16:00 +0000 (11:16 +0100)]
tests: modify f_large_dir test to excercise indexed dir handling

Modify f_large_dir test to create indexed directory and create entries
in it. That way the new code in ext2fs_link() for addition of entries
into indexed directories gets executed including various special cases
when growing htree.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoext2fs: implement dir entry creation in htree directories
Jan Kara [Thu, 13 Feb 2020 10:15:59 +0000 (11:15 +0100)]
ext2fs: implement dir entry creation in htree directories

Implement proper creation of new directory entries in htree directories
in ext2fs_link(). So far we just cleared EXT2_INDEX_FL and treated
directory as unindexed however this results in mismatched checksums if
metadata checksums are in use because checksums are placed in different
places depending on htree node type.

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoext2fs: update allocation info earlier in ext2fs_mkdir() and ext2fs_symlink()
Jan Kara [Thu, 13 Feb 2020 10:15:58 +0000 (11:15 +0100)]
ext2fs: update allocation info earlier in ext2fs_mkdir() and ext2fs_symlink()

Currently, ext2fs_mkdir() and ext2fs_symlink() update allocation bitmaps
and other information only close to the end of the function, in
particular after calling to ext2fs_link(). When ext2fs_link() will
support indexed directories, it will also need to allocate blocks and
that would cause filesystem corruption in case allocation info isn't
properly updated. So make sure ext2fs_mkdir() and ext2fs_symlink()
update allocation info before calling into ext2fs_link().

[ Added error handling so the calls to ext2fs_{block,inode}_alloc_stats()
  can be undone if the newly created directory or symlink can not be linked
  into the directory. -- TYT ]

Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agodebian: drop libattr1-dev from the build dependencies list
Theodore Ts'o [Sun, 15 Mar 2020 04:56:01 +0000 (00:56 -0400)]
debian: drop libattr1-dev from the build dependencies list

The libattr has stopped providing attr/xattr.h; we now use
sys/xattr.h.  So there is no longer any reason to require that the
libattr1-dev package be present when building e2fsprogs, so drop it.

Addresses-Debian-Bug: #953926
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: fix "make check" when using static libraries
Theodore Ts'o [Sun, 15 Mar 2020 04:26:22 +0000 (00:26 -0400)]
e2fsck: fix "make check" when using static libraries

Fixes: 70303df16ca6 ("e2fsck: consistently use ext2fs_get_mem()")

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: make ext2fs_dirent_has_tail() more strict
Theodore Ts'o [Sun, 15 Mar 2020 03:24:39 +0000 (23:24 -0400)]
libext2fs: make ext2fs_dirent_has_tail() more strict

Previously ext2fs_dirent_has_tail() would return true if the directory
was corrupted.  If the directory is corrupted, then by definition it
doesn't have a valid checksum tail.

(This fixes a big-endian failure on the master branch.)

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agomisc: fix typos in chattr's man page
Sawood Alam [Tue, 10 Mar 2020 02:47:29 +0000 (22:47 -0400)]
misc: fix typos in chattr's man page

Plural form "directories" should be used along with "files".
"id's" should be "ids" (i.e., plural form, not apostrophe).
"much" should "must".

Signed-off-by: Sawood Alam <ibnesayeed@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agomke2fs.conf: remove options.fname_encoding
Pino Toscano [Mon, 9 Mar 2020 16:36:10 +0000 (12:36 -0400)]
mke2fs.conf: remove options.fname_encoding

Introduced with commit e7236a9476cd1fa5296fbc4aa573b36426901a08,
it was later renamed to encoding, and turned into a fs_type-only
option with commit 28887533bb64db318e74c38cd9c0ad6d0bb2ced2.

Hence, remove an option that does not exist in the default
configuration.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: fix indexed dir rehash failure with metadata_csum enabled
Jan Kara [Thu, 13 Feb 2020 10:15:57 +0000 (11:15 +0100)]
e2fsck: fix indexed dir rehash failure with metadata_csum enabled

E2fsck directory rehashing code can fail with ENOSPC due to a bug in
ext2fs_htree_intnode_maxrecs() which fails to take metadata checksum
into account and thus e.g. e2fsck can decide to create 1 indirect level
of index tree when two are actually needed. Fix the logic to account for
metadata checksum.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: clarify overflow link count error message
Jan Kara [Thu, 13 Feb 2020 10:15:56 +0000 (11:15 +0100)]
e2fsck: clarify overflow link count error message

When directory link count is set to overflow value (1) but during pass 4
we find out the exact link count would fit, we either silently fix this
(which is not great because e2fsck then reports the fs was modified but
output doesn't indicate why in any way), or we report that link count is
wrong and ask whether we should fix it (in case -n option was
specified). The second case is even more misleading because it suggests
non-trivial fs corruption which then gets silently fixed on the next
run. Similarly to how we fix up other non-problems, just create a new
error message for the case directory link count is not overflown anymore
and always report it to clarify what is going on.

Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoMerge branch 'maint' into next
Theodore Ts'o [Sat, 7 Mar 2020 18:13:55 +0000 (13:13 -0500)]
Merge branch 'maint' into next

4 years agolibext2fs: check open(O_EXCL) first in ismounted.c
Lukas Czerner [Tue, 3 Mar 2020 13:53:48 +0000 (14:53 +0100)]
libext2fs: check open(O_EXCL) first in ismounted.c

Currently the ext2fs_check_mount_point() will use the open(O_EXCL) check
on linux after all the other checks are done. However it is not
necessary to check mntent if open(O_EXCL) succeeds because it means that
the device is not mounted.

Moreover the commit ea4d53b7 introduced a regression where a following
set of commands fails:

vgcreate mygroup /dev/sda
lvcreate -L 1G -n lvol0 mygroup
mkfs.ext4 /dev/mygroup/lvol0
mount /dev/mygroup/lvol0 /mnt
lvrename /dev/mygroup/lvol0 /dev/mygroup/lvol1
lvcreate -L 1G -n lvol0 mygroup
mkfs.ext4 /dev/mygroup/lvol0   <<<--- This fails

It fails because it thinks that /dev/mygroup/lvol0 is mounted because
the device name in /proc/mounts is not updated following the lvrename.

Move the open(O_EXCL) check before the mntent check and return
immediatelly if the device is not busy.

Fixes: ea4d53b7 ("libext2fs/ismounted.c: check device id in advance to skip false device names")
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reported-by: Zdenek Kabelac <zkabelac@redhat.com>
Reported-by: Karel Zak <kzak@redhat.com>
Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agomke2fs: fix permissions setting with "mke2fs -d /path/files"
Theodore Ts'o [Sat, 7 Mar 2020 17:35:48 +0000 (12:35 -0500)]
mke2fs: fix permissions setting with "mke2fs -d /path/files"

Set the directory for directories in cases where the owner permissions
is not rwx.  This was reported[1] by Robert Yang but we are using a
different approach to fixing the issue.

[1] https://lore.kernel.org/r/1582542522-97508-1-git-send-email-liezhi.yang@windriver.com

Also set the permissions in a more portable way by making a
distinction between the host OS's permissions stats and Linux's
permissions.  We still assume the low 12 bits are the historical Unix
assignments, but we don't assume ST_IFMT bits are the same as Linux's.

Reported-by: Robert Yang <liezhi.yang@windriver.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: don't use O_DIRECT for files on tmpfs
Andreas Dilger [Fri, 21 Feb 2020 21:40:56 +0000 (14:40 -0700)]
libext2fs: don't use O_DIRECT for files on tmpfs

If a filesystem image is on tmpfs, opening it with O_DIRECT for
reading the MMP will fail.  This is unnecessary, since the image
file can't really be open on another node at this point.  If the
open with O_DIRECT fails, retry without it when plausible.

Remove the special-casing of tmpfs from the mmp test cases.

Change-Id: I41f4b31657b06f62f10be8d6e524d303dd36a321
Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: avoid overflow with very large dirs
Andreas Dilger [Wed, 12 Feb 2020 01:07:21 +0000 (18:07 -0700)]
e2fsck: avoid overflow with very large dirs

In alloc_size_dir() it multiples signed ints when allocating the
buffer for rehashing an htree-indexed directory.  This will overflow
when the directory size is above 4GB, which is possible with largedir
directories having about 100M entries, assuming an average 3/4 leaf
fullness and 24-byte filenames, or fewer with longer filenames.
The same problem exisgs in get_next_block().

Similarly, the out_dir struct used a signed int for the number of
blocks in the directory, which may result in a negative size if the
directory is over 2GB (about 50M entries or fewer).

Use appropriate unsigned variables for block counts, and use larger
types for calculating the byte count for memory offsets/sizes.

Such large directories not been seen yet, but are not too far away.
The ext2fs_get_array() function will properly calculate the needed
memory allocation, and detect overflow on 32-bit systems.
Add ext2fs_resize_array() to do the same for array resize.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agomisc: handle very large files with filefrag
Andreas Dilger [Fri, 7 Feb 2020 01:09:46 +0000 (18:09 -0700)]
misc: handle very large files with filefrag

Avoid overflowing the column-width calc printing files over 4B blocks.

Document the [KMG] suffixes for the "-b <blocksize>" option.

The blocksize is limited to at most 1GiB blocksize to avoid shifting
all extents down to zero GB in size.  Even the use of 1GB blocksize
is unlikely, but non-ext4 filesystems may use multi-GB extents.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: consistently use ext2fs_get_mem()
Andreas Dilger [Fri, 7 Feb 2020 01:09:45 +0000 (18:09 -0700)]
e2fsck: consistently use ext2fs_get_mem()

Consistently use ext2fs_get_mem() and ext2fs_free_mem() instead of
calling malloc() and free() directly in e2fsck.  In several places
it is possible to use ext2fs_get_memzero() instead of explicitly
calling memset() on the memory afterward.

This is just a code cleanup, and does not fix any specific bugs.

[ Fix up library dependencies in e2fsck/Makefile.in to fix "make
  check" breakages. -- TYT ]

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: fix overflow if more than 4B inodes
Andreas Dilger [Fri, 7 Feb 2020 01:09:44 +0000 (18:09 -0700)]
e2fsck: fix overflow if more than 4B inodes

Even though we don't have support for filesystems with over 4B inodes
in the current e2fsprogs, this may happen in the future.  There are
latent overflow bugs when calculating the number of inodes in the
filesystem that can trivially be fixed now, rather than waiting for
them to be hit at some point in the future.  The block number calcs
are already correct in this code.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agodebugfs: print inode numbers as unsigned
Andreas Dilger [Fri, 7 Feb 2020 01:09:43 +0000 (18:09 -0700)]
debugfs: print inode numbers as unsigned

Print inode numbers as unsigned values, to avoid printing negative
numbers for inodes above 2B.

Flags should be printed as hex instead of signed decimal values.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agodebugfs: allow comment lines in command file
Andreas Dilger [Fri, 7 Feb 2020 01:09:42 +0000 (18:09 -0700)]
debugfs: allow comment lines in command file

Allow comment lines with '#' at the start of the line in the command
file passed in to debugfs via the "-f" option or from standard input.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: reduce memory usage for many directories
Andreas Dilger [Fri, 7 Feb 2020 01:09:41 +0000 (18:09 -0700)]
e2fsck: reduce memory usage for many directories

Pack struct dx_dir_info and dx_dirblock_info properly in memory, to
avoid holes, and fields are not larger than necessary.  This reduces
the memory needed for each hashed dir, according to pahole(1) from:

    struct dx_dir_info {
        /* size: 32, cachelines: 1, members: 6 */
        /* sum members: 26, holes: 1, sum holes: 2 */
        /* padding: 4 */
    };
    struct dx_dirblock_info {
        /* size: 56, cachelines: 1, members: 9 */
        /* sum members: 48, holes: 2, sum holes: 8 */
        /* last cacheline: 56 bytes */
    };

to 8 bytes less for each directory and directory block, and leaves
space for future use if needed (e.g. larger numblocks):

    struct dx_dir_info {
        /* size: 24, cachelines: 1, members: 6 */
        /* sum members: 20, holes: 1, sum holes: 4 */
        /* bit holes: 1, sum bit holes: 7 bits */
    };
    struct dx_dirblock_info {
        /* size: 48, cachelines: 1, members: 9 */
    };

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: avoid mallinfo() if over 2GB allocated
Andreas Dilger [Fri, 7 Feb 2020 01:09:40 +0000 (18:09 -0700)]
e2fsck: avoid mallinfo() if over 2GB allocated

Don't use mallinfo() for determining the amount of memory used if it
is over 2GB.  Otherwise, the signed ints used by this interface can
can overflow and return garbage values.  This makes the actual amount
of memory used by e2fsck misleading and hard to determine.

Instead, use brk() to get the total amount of memory allocated, and print
this if the more detailed mallinfo() information is not suitable for use.

There does not appear to be a mallinfo64() variant of this function.
There does appear to be an abomination named malloc_info() that writes
XML-formatted malloc stats to a FILE stream that would need to be read
and parsed in order to get these stats, but that doesn't seem worthwhile.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Shilong Wang <wshilong@ddn.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: use proper types for variables
Andreas Dilger [Fri, 7 Feb 2020 01:09:39 +0000 (18:09 -0700)]
e2fsck: use proper types for variables

Use ext2_ino_t instead of ino_t for referencing inode numbers.
Use loff_t for for file offsets, and dgrp_t for group numbers.

Cast products to ssize_t before multiplication to avoid overflow.

Signed-off-by: Andreas Dilger <adilger@dilger.ca>
Reviewed-by: Shilong Wang <wshilong@ddn.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agoe2fsck: fix e2fsck_allocate_memory() overflow
Andreas Dilger [Fri, 7 Feb 2020 01:09:38 +0000 (18:09 -0700)]
e2fsck: fix e2fsck_allocate_memory() overflow

e2fsck_allocate_memory() takes an "unsigned int size" argument, which
will overflow for allocations above 4GB.  This happens for dir_info
and dx_dir_info arrays when there are more than 350M directories in a
filesystem, and for the dblist array above 180M directories.

There is also a risk of overflow during the binary search in both
e2fsck_get_dir_info() and e2fsck_get_dx_dir_info() when the midpoint
of the array is calculated, if there would be more than 2B directories
in the filesystem and working above the half way point.

Also, in some places inode numbers are "int" instead of "ext2_ino_t",
which can also cause problems with the array size calculations, and
makes it hard to identify where inode numbers are used.

Fix e2fsck_allocate_memory() to take an "unsigned long" argument to
match ext2fs_get_mem(), so that it can do single memory allocations
over 4GB.

Fix e2fsck_get_dir_info() and e2fsck_get_dx_dir_info() to temporarily
use an unsigned long long value to calculate the midpoint (which will
always fit into an ext2_ino_t again afterward).

Change variables that hold inode numbers to be ext2_ino_t, and print
them as unsigned values instead of printing negative inode numbers.

Signed-off-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Shilong Wang <wshilong@ddn.com>
Lustre-bug-id: https://jira.whamcloud.com/browse/LU-13197
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agotst_libext2fs: Avoid multiple definition of global variables
Lukas Czerner [Mon, 10 Feb 2020 15:24:59 +0000 (16:24 +0100)]
tst_libext2fs: Avoid multiple definition of global variables

gcc version 10 changed the default from -fcommon to -fno-common and as a
result e2fsprogs make check tests fail because tst_libext2fs.c end up
with a build error.

This is because it defines two global variables debug_prog_name and
extra_cmds that are already defined in debugfs/debugfs.c. With -fcommon
linker was able to resolve those into the same object, however with
-fno-common it's no longer able to do it and we end up with multiple
definition errors.

Fix the problem by using SKIP_GLOBDEFS macro to skip the variables
definition in debugfs.c. Note that debug_prog_name is also defined in
lib/ext2fs/extent.c when DEBUG macro is used, but this does not work even
with older gcc versions and is never used regardless so I am not going to
bother with it.

Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Reviewed-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agochattr.1: improve attribute formatting with labels and indented paragraphs
Jeremy Visser [Mon, 3 Feb 2020 02:37:41 +0000 (13:37 +1100)]
chattr.1: improve attribute formatting with labels and indented paragraphs

By convention, lists of options in man pages use a label followed by an
indented description, such as this example from the Options section:

     -R     Recursively change attributes of directories and
            their contents.

But the Attributes section places the available attributes mid-sentence,
which makes it visually more difficult to parse:

     A file with the 'a' attribute set can only be opened
     in append mode for writing.  [...]

     When a file with the 'A' attribute set is accessed, its
     atime record is not modified.  [...]

This patch places a label beside each attribute description, which (in
my opinion) improves readability, especially when visually skimming the
list.  For example:

     a      A file with the 'a' attribute set can only be
            opened in append mode for writing.

     A      When a file with the 'A' attribute set is accessed,
            its atime record is not modified.

Signed-off-by: Jeremy Visser <jeremyvisser@google.com>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: avoid array buffer overruns caused by insane directory blocks
Theodore Ts'o [Sun, 16 Feb 2020 00:10:01 +0000 (19:10 -0500)]
libext2fs: avoid array buffer overruns caused by insane directory blocks

Reported-by: canardo909@gmx.com
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
4 years agolibext2fs: fix potential OOB read check_for_inode_bad_blocks()
Theodore Ts'o [Thu, 16 Jan 2020 23:14:37 +0000 (18:14 -0500)]
libext2fs: fix potential OOB read check_for_inode_bad_blocks()

If the bad block list has been reset in the middle of an inode scan,
it's possible for bb->list[scan->bad_blocks_ptr] to result in an
out-of-bounds read access.

This is highly unlikely to happen under normal circumstances; in
particular, we generally don't use bad block inodes any more.  In
addition, this would only happen if the bad block inode itself is
corrupt so e2fsck needs to wipe it out.  This might cause e2fsck to
crash, but it will more likely cause a part of the inode table to be
wrongly considered invalid, causing file system to be incorrectly
fixed.

This was reported by TALOS as TALOS-2020-0974 and CVE-2020-6057, but
after closer examination, we don't believe this can be used in any way
to exploit the system or release information about the system, since
all this can do is to cause part of the inode table to be skipped when
it shouldn't be, and this can't be leveraged since any information
about the ASLR of the process is obsolete once e2fsck exits.

Signed-off-by: Theodore Ts'o <tytso@mit.edu>