The mke2fs program should allow creating a file system image when an
explicit file system size is specified, even if the file doesn't yet
exist. By deferring the call to check_plausible() in commit
942b00cb9d ("mke2fs: do not warn about a pre-existing partition
table when using a non-zero offset") this behaviour was broken.
Fix this regression by explicitly creating the file if the file system
size is specified.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
When encoding a POSIX ACL to the EXT4 ACL format, if an unknown tag
is encountered, that entry is silently ignored. It would be better
to return an error to inform the user that the ACL is incompatible.
Also fix the mismatched indentation in the opposite function.
Signed-off-by: Samuel Holland <samuel@sholland.org>
The acl package is needed to run the m_rootdir_acl test. The
libreadline-dev package will drag in the shared library package for
libreadline (libreadlineN) so that the developer running debugfs will
be able to use line editing.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
The GNU Hurd doesn't support Posix ACL's, so even if the acl package
is installed, the setfattr command will fail. So just skip the test
on Hurd.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
The ACL returned by the kernel in lgetxattr(2) is returned in Little
Endian, even on Big Endian systems. Fix the functions
convert_posix_acl_to_disk_buffer() and convert_disk_buffer_to_posix_acl()
to work correctly on Big Endian systems. This fixes a failure of
the test m_rootdir_acl.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
This is needed to fix a large number of test failures on GNU Hurd.
Also skip a number of tests that require creating very large test file
systems,since Hurd does not support files greater than 4GB.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
On the GNU Hurd, dd seems to be buggy and hangs if seeking beyond 4G.
Fortunately the GNU Hurd does have the truncate command, which does
work correctly. So try using the truncate command first, and fall
back to using dd only if the truncate command doesn't work.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
On the GNU Hurd both __MACH__ and __GNU__ are defined. So rearrange
the #ifdef to prioritize checking for GLIBC compatibility over BSD
compatibility.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Commit 63f44aafb1 ("e2fsck: fix ".." more gracefully if possible")
changed the check_dot() function to try to avoid resetting the '..'
entry when the '.' entry is too large.. But if we do that, then on
big-endian systems, we need to try byte swapping the rest of the
directory entries, or else the f_baddotdir test will fail on
big-endian systems.
Also add a check to avoid UBSAN warning when there is not enough space
at the end of the directory block for a directory entry, and so we can
potentially overflow some pointer arithmetic when trying to byte swap
the remainder of the (negative) space in the directory block.
Fixes: 63f44aafb1 ("e2fsck: fix ".." more gracefully if possible")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Use target.bionic.system_shared_libs when it is used to limit the
default shared libraries (as opposed to remove them completely).
This avoids attempting to add a host dependency on libc when
system_shared_libs is modified to apply to all variants.
Also remove system_shared_libs from static binaries where it has
no effect, and consolidate it into e2fsprogs-defaults.
Bug: 193559105
Test: m checkbuild
Change-Id: I2d447b006afc783f4acd6c1acd93f338a68a01ed
From AOSP commit: 48fa7248112701c30d3cabfb8d3360b2408d6491
Some "arithmetic on a void pointer is a GNU extension" warnings were
introduced into upstream e2fsprogs, but they are of questionable value,
so disable them for now.
Change-Id: I19e99382e9434828927c1b8287b91f3333110151
From AOSP commit: f203c38fd43dc384cedfcaeb155771a15906022f
Address a number of signed vs. unsigned comparison errors, unused
function parameters, casts which drop const, etc.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
If the device name in the mtab or /proc/mounts file does not match
with the device passed into ext2fs_check_if_mounted() or
ext2fs_check_mount_point(), skip the stat(2) call on the mountpoint,
since we never use the results of the stat(2) in that case. Not only
does this provide a slight performance win, but it the stat calls on
the mountpoints could potentially trigger some SELinux denials that
could stress some sysadmins out.
Google-Bug-Id: 193137337
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
If a large number of blocks move from one file to another file,
e2fsdroid will inadvertently reserve the moved blocks for the source
file. If the larger file is visited first, it can fail to acquire blocks
because they're reserved by the smaller file.
This patch only reserves the first N blocks of a file in Base FS, where N
is large enough to satisfy the |st_size| property from lstat(2). We only
consider "owned" blocks rather than deduplicated blocks, in case the new
file cannot be deduplicated.
Google-Bug-Id: 145316683
Test: e2fsdroid with dynamic partitions
Change-Id: I32e255a19550d52d90342c21d7218981108a71b1
From AOSP commit: 2985b26cdbe674084fa02b211503eef9bf970023
The existing code attempted to avoid warning about a pre-existing file
system with a non-zero offset, but because the offset was not set at
the time of the check, this intention was not actually working. So
this commit will suppress warnings about pre-existing a partition
table as well as pre-existing file system when there is a non-zero
offset.
Addresses-Debian-Bug: #989612
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Commit d2bfdc7ff1 ("Use punch hole as "discard" on regular files")
added a test to see if the storage device actually supports discard.
The intent was to try discarding the first block but since
io_channel_discard() interprets the offset and count arguments in
blocks, and not bytes, mke2fs was actually discarding the first 16
megabytes (when the block size is 4k). This is normally not a
problem, since most file systems are larger than that, and requests to
discard beyond the end of the block device are ignored.
However, when creating a small file system as part of a image
containing multiple partitions, the initial test discard can end up
discarding data beyond the file system being created.
Addresses-Debian-Bug: #989630
Reported-by: Josh Triplett <josh@joshtriplett.org>
Fixes: d2bfdc7ff1 ("Use punch hole as "discard" on regular files")
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Some devices can react badly to the EXT2_IOC_[GS]ETFLAGS ioctls, since
ioctl codes are not guaranteed to be unique across different device
drivers and file systems.
Addresses-Debian-Bug: #986332
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In dupstr(), we should check return value of malloc().
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Reviewed-by: Wu Bo <wubo40@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In ss_name(), we should check return value of malloc(),
otherwise, it may cause a segmentation fault problem.
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In scandir(), temp_list[num_dent] is allocated by calling
malloc(), we should check whether malloc() returns NULL before
accessing temp_list[num_dent].
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In argv_parse(), return value of malloc should be checked
whether it is NULL, otherwise, it may cause a segfault error.
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In append_pathname(), we need to add a new path to save the value
returned by realloc, otherwise the name->path may be NULL, causing
a segfault.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In zap_sector(), need free buf before return,
otherwise it will cause memory leak.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reviewed-by: Wu Bo <wubo40@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
In tdb_transaction_recover(), need free data before return,
otherwise it will cause memory leak.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reviewed-by: Wu Bo <wubo40@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
If new->magic != PROF_MAGIC_NODE, profile_free_node() don't free node.
This will cause the node to be unable to be released correctly and
a memory leak will occur.
Signed-off-by: Wu Guanghao <wuguanghao3@huawei.com>
Signed-off-by: Zhiqiang Liu <liuzhiqiang26@huawei.com>
Reviewed-by: Wu Bo <wubo40@huawei.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Fix all warnings about unused variables that were introduced since
e2fsprogs v1.45.4.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Fix all warnings about unused function parameters that were introduced
since e2fsprogs v1.45.4, by adding EXT2FS_ATTR((unused)) or removing
parameters as appropriate.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Since commit e8c858047b ("libext2fs: fix build issue for on
Windows/Cygwin systems"), ext2fs_get_device_size2() is available in
Windows builds of libext2fs. So there is no need for mke2fs to call
ext2fs_get_device_size() instead.
This fixes a -Wincompatible-pointer-types warning because
ext2fs_get_device_size() was being passed a 'blk64_t *', but it expected
a 'blk_t *'.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Sync the changes to fc_do_one_pass() from the kernel's recovery.c so
that e2fsck picks up the fixes to the jbd_debug() statements.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Make jbd_debug() do format string checking (but still get compiled away
to nothing) when --enable-jbd-debug isn't specified, similar to
commit d556435156b7 ("jbd2: avoid -Wempty-body warnings") on the kernel
side. This should prevent --enable-jbd-debug from getting broken due to
bad jbd_debug() statements. It also eliminates a -Wunused-variable
warning where a variable was only used in a jbd_debug() statement.
Also remove an alternative definition of jbd_debug() that was
conditional on CONFIG_JBD_DEBUG && !CONFIG_JBD_DEBUG, so was dead code.
Signed-off-by: Eric Biggers <ebiggers@google.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
When adding or removing journal from a filesystem, we also need to add /
remove journal blocks from overhead stored in the superblock. Otherwise
total number of blocks in the filesystem as reported by statfs(2) need
not match reality and could lead to odd results like negative number of
used blocks reported by df(1).
Fixes: 9046b4dfd0ce ("mke2fs: set overhead in super block")
Signed-off-by: Jan Kara <jack@suse.cz>
Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
With commit c52d930f e2fsck is no longer able to fix bad last
mount/write time by default because it is conditioned on s_checkinterval
not being zero, which it is by default.
One place where it matters is when other e2fsprogs tools require to run
full file system check before a certain operation. If the last mount
time is for any reason in future, it will not allow it to run even if
full e2fsck is ran.
Fix it by checking the last mount/write time when the e2fsck is forced,
except for the case where we know the system clock is broken.
[ Reworked the conditionals so error messages claiming that the last
write/mount time were corrupted wouldn't be always printed when the
e2fsck was run with the -f option, thus causing 299 out of 372
regression tests to fail. -- TYT ]
Fixes: c52d930f ("e2fsck: don't check for future superblock times if checkinterval == 0")
Reported-by: Dusty Mabe <dustymabe@redhat.com>
Signed-off-by: Lukas Czerner <lczerner@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
If the "." entry is corrupted, it will be reset in check_dot().
It is possible that the ".." entry can be recovered from the
directory block instead of also resetting it immediately. If
it appears that there is a valid ".." entry in the block, allow
that to be used, and let check_dotdot() verify the dirent itself.
When resetting the "." and ".." entries, use EXT2_FT_DIR as the
file type instead of EXT2_FT_UNKNOWN for the very common case of
filesystems with the "filetype" feature, to avoid later problems
that can be easily avoided. This can't always be done, even if
filesystems without "filetype" are totally obsolete, because many
old test images do not have this feature enabled.
Fixup affected tests using the new "repair-test" script that
updates the expect.[12] files from $test.[12].log for the given
tests and re-runs the test to ensure it now passes.
Signed-off-by: Andreas dilger <adilger@whamcloud.com>
Reviewed-by: Artem Blagodarenko <artem.blagodarenko@hpe.com>
Lustre-bug-Id: https://jira.whamcloud.com/browse/LU-14710
Change-Id: Ia5e579bcf31a9d9ee260d5640de6dbdb60514823
Reviewed-on: https://review.whamcloud.com/43858
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
offsetof is a standard C feature available from stddef.h, going
back all the way to ANSI C.
Signed-off-by: Michael Forney <mforney@mforney.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Functionally, the statement-expression is not necessary here; it
just gives a bit of type-safety to make sure the pointer really
does have a compatible type with the specified member of the struct.
When statement expressions are not available, we can just use a
portable fallback macro that skips this member type check.
Signed-off-by: Michael Forney <mforney@mforney.org>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
For a large partition during e2image capture process
it is possible to overflow offset at multiply operation.
This leads to the situation when data is written to the
position at the start of the image instead of the image end.
Let's use the right cast to avoid integer overflow.
Signed-off-by: Alexey Lyashkov <c17817@cray.com>
Signed-off-by: Artem Blagodarenko <c17828@cray.com>
HPE-bug-id: LUS-9368
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Commit d557b9659b ("libext2fs: fix potential races in unix_io")
contained some additional changes that were supposed to clarify the
management of the length calculations when reading and writing
non-page aligned data using Direct I/O; unfortunately, those changes
were incorrect, and actually broke the Direct I/O support.
Fix these problems by reverting those portions of that commit.
[ commit description rewritten by tytso ]
Originally from https://github.com/tytso/e2fsprogs/pull/68
Fixes: d557b9659b ("libext2fs: fix potential races in unix_io")
Signed-off-by: Alexander Kanavin <alex.kanavin@gmail.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>