fuse2fs: fix build failure on systems which don't define EUCLEAN
MacOS doesn't have EUCLEAN, so we use EIO as the closest error code.
But then we need to avoid a compile error caused by a duplicate case
labels of EUCLEAN and EIO.
libsupport: add a portable get_thread_id() function
The gettid() system call is only available on Linux. So create a new
function, get_thread_id() which implements a number of different ways
of providing a thread id as an integer.
Use get_thread_id() instead of gettid() in fuse2fs.
libsupport: fix portability issues with the bthread.c
The function pthread_setname_np() is non-portable; that's what the
"np" means. In particular, on Mac systems, the function takes only a
single argument, while on most other systems which have the function,
it takes two arguments.
Also fix a problem where a 1-bit signed integer can only accept values
of 0 or -1. Change it to be a 1-bit unsigned integer, which can
accept values of 0 or 1. Clang will issue a warning if 1-bit signed
integer are used incorrectly, and fail with -Werror.
Merge tag 'tags/fuse2fs-writability_2026-03-12' into next
fuse2fs: better tracking of writable state [07/18]
There are multiple mutability variables in play in fuse2fs -- first,
EXT2_FLAG_RW tracks whether or not we can write anything to the
filesystem. However, there's a second state, which is whether or not
we actually want to write to the filesystem, regardless of the library
state. This can happen if we open libext2fs for writing, but then
discover something about the filesystem that makes us not want to write
to it after all.
Split out this second variable into an explicit variable in fuse2fs.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Merge tag 'tags/fuse2fs-tracing_2026-03-12' into next
fuse2fs: improve operation tracing [06/18]
This series improves the ability for developers to trace the activities
of fuse2fs by adding more debugging printfs and tracing abilities of
fuse2fs. It also registers a com_err handler for libext2fs so we can
capture errors coming out of there, and changes filesystem error
reporting to tell us the function name instead of just fuse2fs.c.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Merge tag 'tags/fuse2fs-refactor-mounting_2026-03-12' into next
fuse2fs: refactor mount code [05/18]
Here, we hoist the mounting code out of main() into a pile of separate
helper functions to reduce the complexity of understanding the mount
code. This isn't strictly required for iomap, but it makes main() a lot
easier to understand.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Merge tag 'tags/fuse2fs-refactor-unmounting_2026-03-12' into next
fuse2fs: refactor unmount code [04/18]
In this series, we refactor the code around ext2fs_close to get ready
for iomap mode. The significant part of this series is moving the
unmount code to op_destroy, because we want to release the block device
as a part of the umount(2) process to maintain expected behavior of the
in-kernel local filesystem drivers.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Merge tag 'tags/fuse2fs-refactor-operation-startup_2026-03-12' into next
fuse2fs: clean up operation startup [03/18]
Reduce the amount of boilerplate in fuse2fs by creating helper functions
to start and finish a file operation instead of open-coding the logic
all over the place. This also fixes a couple of theoretical races.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
tests: update tests after improving dir_index support
Commit f3c5e16bc36c ("libext2fs: initialize htree when expanding
directory") allows libext2fs to better support htree directories.
This breaks a number of e2fsprogs regression tests because it changes
the expected output. Fix these up.
Theodore Ts'o [Thu, 19 Mar 2026 14:58:13 +0000 (10:58 -0400)]
Merge tag 'fuse2fs-new-features_2026-03-13' into next
fuse2fs: add some easy new features [02/18]
As of 2025, libfuse is a lot more capable than it was in 2013.
Implement some new features such as readdirplus and directory seeking
for better directory performance, and reduce the amount of filesystem
flushing so that it only happens when userspace explicitly asks for it.
Now we also can add htree indices to large directories, support MMP in
fuse2fs, and link count overflows are handled correctly.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Theodore Ts'o [Thu, 19 Mar 2026 14:42:27 +0000 (10:42 -0400)]
Merge tag 'fuse2fs-locking_2026-03-12' into next
fuse2fs: fix locking problems [01/18]
Teach fuse2fs to flock the file(s) underlying the filesystem if the fs
is stored in a regular file, so that we don't have to create and
maintain separate lockfiles.
For block devices, fix a weird race between mount and unmount that is
causing testing failures by waiting a small amount of time to grab a
lock.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Due to missing parenthesis around the #defines for
EXT4_{MAX,DEFAULT}_ORPHAN_FILE_SIZE, the default number of blocks
assigned to the orphan file was calculated as 2 when the file system
has more than 2**21 blocks:
% mke2fs -t ext4 -Fq /tmp/foo.img 8191M
/tmp/foo.img contains a ext4 file system
created on Wed Mar 11 09:54:04 2026
% debugfs -R "extents <12>" /tmp/foo.img
debugfs 1.47.4 (6-Mar-2025)
Level Entries Logical Physical Length Flags
0/ 0 1/ 1 0 - 510 9255 - 9765 511
% mke2fs -t ext4 -Fq /tmp/foo.img 8192M
/tmp/foo.img contains a ext4 file system
created on Wed Mar 11 09:54:11 2026
% debugfs -R "extents <12>" /tmp/foo.img
debugfs 1.47.4 (6-Mar-2025)
Level Entries Logical Physical Length Flags
0/ 0 1/ 1 0 - 1 9255 - 9256 2 <======
The problem addressed by the reverted commit will fixed via the next
commit.
Darrick J. Wong [Thu, 28 Aug 2025 17:30:45 +0000 (10:30 -0700)]
fuse2fs: enable the shutdown ioctl
Implement a bastardized version of EXT4_IOC_SHUTDOWN, because the people
who invented the ioctl got the direction wrong, so we can't actually
read the flags. So all we do is flush the filesystem, clear the
writable flags, and hope that's what the user wanted.
Since we change __FUSE2FS_CHECK_CONTEXT to return an error code on a
shut down filesystem, remove FUSE2FS_CHECK_CONTEXT_RETURN so that
op_destroy always tears everything down and logs the unmount message.
Later on in the iomap patchset this will become critical because we need
to try to close the block device before unmount completes to avoid
problems with fstests.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:45 +0000 (10:30 -0700)]
fuse2fs: track our own writable state
Track our own willingness to write to the filesystem in a separate
variable from that of libext2fs. There's a small window between opening
the filesystem and mounting it where the library is rw but we might fail
a mount task and therefore don't want to write anything more.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Wed, 22 Oct 2025 16:52:52 +0000 (09:52 -0700)]
fuse2fs: adjust OOM killer score if possible
Users don't like it when their filesystems go down unexpectedly. Set
the OOM score adjustment to -500 to try to prevent this, particularly
because fuse2fs doesn't support journal transactions.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:42 +0000 (10:30 -0700)]
fuse2fs: hoist unmount code from main
Hoist the unmount code into a separate function so that we can reduce
the complexity of main(). This also sets us up for unmounting the
filesystem from op_destroy, which we'll need for fuse2fs+iomap mode to
maintain the expected behavior that the block device is free when
umount(8) returns.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:44 +0000 (10:30 -0700)]
fuse2fs: improve tracing for file range operations
Improve the tracing for read, write, readdir, and fallocate by reporting
the inode number and the file range in all tracepoints relating to file
IO. Make the file ranges hexadecimal to make it easier for the
programmer to convert bytes to block numbers and back.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:43 +0000 (10:30 -0700)]
fuse2fs: register as an IO flusher thread
fuse2fs is involved in the filesystem I/O path and can allocate memory
while processing I/O requests. Therefore, we need to register that fact
with the kernel so that memory allocations done by libext2fs don't start
a round of filesystem memory reclaim, which could cause more writeout to
get dumped on fuse2fs.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:44 +0000 (10:30 -0700)]
fuse2fs: print the function name in error messages, not the file name
It would be nice to know which fuse op actually causes failures such as:
FUSE2FS (sda4): Directory block checksum does not match directory block at ../../misc/fuse2fs.c:819.
The filename is utterly pointless, there's only one for the whole
daemon.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:42 +0000 (10:30 -0700)]
fuse2fs: split filesystem mounting into helper functions
Break up main() by moving the filesystem mounting logic into separate
helper functions. This originally made it easier to move that part
around for fuseblk support, and I kept it around because splitting up
the mounting code into multiple smaller functions makes them easier to
understand.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:44 +0000 (10:30 -0700)]
fuse2fs: hook library error message printing
Hook the com_err library so that error messages coming from libext2fs
such as:
Illegal block number passed to ext2fs_test_block_bitmap #9462 for block bitmap for /dev/sda
are actually printed with the standard "FUSE2FS (sda):" prefix.
Libraries shouldn't be printing that kind of stuff, but it is what it
is, and what it is is against the normal conventions.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Mon, 6 Oct 2025 22:48:35 +0000 (15:48 -0700)]
fuse2fs: implement MMP updates
Periodically rewrite the MMP block while we're mounted like the Linux
driver does, so that other potential users don't see EXT4_MMP_SEQ_FSCK
and erroneously report that the ext4 filesystem is being fscked.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:41 +0000 (10:30 -0700)]
fuse2fs: clean up operation startup
Create a helper to take the BFL and give us a reference to the
ext2_filsys that we're protecting with the BFL. This eliminates a
theoretical race with any code that sets or clears fuse2fs:fs. But
really it just cuts down on the boilerplate.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Fri, 3 Oct 2025 22:14:40 +0000 (15:14 -0700)]
fuse2fs: fix link count overflows on dir_nlink filesystems
On a dir_nlink filesystem, a dir with more than 65000 subdirs ends up
with i_links_count (aka nlink) of 1. libext2fs wraps around and does
the wrong thing, which may have caused a lot of havoc over the years.
The kernel actually knows how to do this properly (it freezes the link
count at 1 when it would overflow) so use the helpers we added in the
previous patch to make fuse2fs behave the same as the kernel.
This is a convenient time to fix the annoying behavior that one has to
call remove_inode twice to rmdir a directory, and actually check for
link count overflows when renaming or hardlinking files.
Found via ext4/045.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:40 +0000 (10:30 -0700)]
fuse2fs: improve error handling behaviors
Make the behavior of fuse2fs on filesystem errors consistent with what
the kernel driver does. Sort of. We can't panic the kernel, but we can
abort the server, which leaves a dead mount.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:40 +0000 (10:30 -0700)]
fuse2fs: rework fallocate file handle extraction
Move the context and file handle checking to op_fallocate so that we can
pass them to the alloc/punch/zero helpers. This eliminates redundant
checking in the zero_range path.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 20:45:41 +0000 (13:45 -0700)]
fuse2fs: constrain worker thread count
fuse2fs isn't all that scalable -- there's a big kernel lock around all
the libext2fs code. Constrain the fuse worker thread count to reduce
unnecessary lock contention.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:40 +0000 (10:30 -0700)]
fuse2fs: rework checking file handles
We only use FUSE2FS_CHECK_MAGIC for one thing -- to check the magic
number of file handles. Make the whole macro more specific to file
handles, and move it to the top of each function so that we don't take
locks or any other silly stuff like that.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:40 +0000 (10:30 -0700)]
fuse2fs: rework FUSE2FS_CHECK_CONTEXT not to rely on global_fs
If the fuse2fs object that libfuse hands to us has the wrong magic
number, something is clearly wrong. In that case, we don't really want
to rely on the global_fs variable actually pointing to a valid
ext2_filsys object because something could be wrong there too. Instead,
try to emit an error on stderr and just bail out.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:40 +0000 (10:30 -0700)]
fuse2fs: improve want_extra_isize handling
System administrators can set the {min,want}_extra_isize fields in the
superblock to try to influence the allocation of extra space in an
inode. Currently fuse2fs ignores any such value and sets it to the
minimum possible size; let's actually follow it, like the kernel does.
Note: fuse2fs isn't quite as flexible as the kernel is about changing
extra_isize, so this isn't quite good enough to pass ext4/022.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Fri, 12 Sep 2025 22:07:00 +0000 (15:07 -0700)]
fuse2fs: check root directory while mounting
The kernel will fail a mount attempt if the root directory inode isn't
even minimally readable at mount time. Do the same for fuse2fs so that
we can pass ext4/008.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Tue, 27 Jan 2026 01:28:45 +0000 (17:28 -0800)]
fuse2fs: enable more caching
Don't flush the pagecache when we open a file, and cache dirents when
someone asks for readdir. Our fuse server assumes that the filesystem
isn't mounted anywhere else, so file and directory data cannot change
out from under the kernel.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Wed, 28 Jan 2026 18:00:23 +0000 (10:00 -0800)]
fuse2fs: disable write access when cluster size > block size
The libext2fs punch functions do not handle cluster deallocation
correctly when the bigalloc cluster size is larger than a single
fsblock. To avoid trashing these filesystems until we can fix it, mount
the filesystem in readonly mode.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Tue, 7 Oct 2025 17:41:58 +0000 (10:41 -0700)]
libext2fs: always use ext2fs_mmp_get_mem to allocate fs->mmp_buf
Always use our special allocator function to allocate the MMP buffer.
This will be useful in case we ever pass that buffer to ext2fs_mmp_write
on a filesystem that is opened with O_DIRECT.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Tue, 21 Oct 2025 01:08:26 +0000 (18:08 -0700)]
fuse2fs: try to grab block device O_EXCL repeatedly
generic/646 keeps failing to mount in this fashion:
run fstests generic/646 at 2025-10-20 17:10:26
[U] FUSE2FS (sda4): mounted filesystem f8f21d10-2ec9-4aef-a509-b32659b4e6b0.
fuse: EXPERIMENTAL iomap feature enabled. Use at your own risk!
[U] FUSE2FS (sda4): shut down requested.
[U] FUSE2FS (sda4): unmounted filesystem f8f21d10-2ec9-4aef-a509-b32659b4e6b0.
[U] FUSE2FS (sda4): mounted filesystem 9efc6297-74c0-448c-b253-cecffd947239.
fuse: EXPERIMENTAL iomap feature enabled. Use at your own risk!
[U] FUSE2FS (sda4): shut down requested.
[U] FUSE2FS (sda4): unmounted filesystem 9efc6297-74c0-448c-b253-cecffd947239.
[U] FUSE2FS (sda4): mounted filesystem 9efc6297-74c0-448c-b253-cecffd947239.
[U] FUSE2FS (sda4): Warning: Mounting unchecked fs, running e2fsck is recommended.
[U] FUSE2FS (sda4): Device or resource busy.
[U] FUSE2FS (sda4): Please run e2fsck -fy.
[U] Mount failed while opening filesystem. Check dmesg(1) for details.
[U] FUSE2FS (sda4): unmounted filesystem 9efc6297-74c0-448c-b253-cecffd947239.
It turns out that one can mount a fuse filesystem and unmount it before
the kernel even has a chance to send FUSE_INIT to the fuse server. If
this occurs, the unmount code will abort the FUSE_INIT request and tear
down the fs mount immediately.
Unfortunately for fstests, the fuse server may have already opened the
block device with O_EXCL and will keep running with the bdev open until
libfuse notices that the connection to the kernel died and tells the
fuse server to destroy itself. That might not happen for a long time
after the unmount program exits, in which case a subsequent invocation
of the fuse server can race with the dying fuse server to open the block
device. When this happens, the new invocation fails with "Device or
resource busy".
This is exactly what's happening in this test, which is only noticeable
because it cycles the scratch mount so quickly.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Mon, 6 Oct 2025 23:00:15 +0000 (16:00 -0700)]
libext2fs: fix ext2fs_mmp_update
ext2fs_mmp_read has this undocumented behavior that it updates
fs->mmp_cmp and not fs->mmp_buf. Therefore, ext2fs_mmp_update2 actually
updates a stale version of the MMP buffer and writes that out to disk.
Fortunately the only two fields that get updated regularly mmp_time and
mmp_seq so the behavior was never incorrect, but this confused me for a
while, so let's fix it.
Darrick J. Wong [Fri, 3 Oct 2025 21:56:10 +0000 (14:56 -0700)]
libext2fs: create link count adjustment helpers for dir_nlink
Create some helpers to deal with link count adjustments for directories
on dir_nlink filesystems that become large enough to have an htree
index. In other words, fix the problem that creating a new child
subdirectory can overflow the link count of the parent directory.
The unused library functions created by this patch will be used in the
next patch to fix problems with fuse2fs.
Cc: <linux-ext4@vger.kernel.org> # v1.40 Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:52 +0000 (10:30 -0700)]
fuse2fs: try to lock filesystem image files before using them
Originally, this patch added support for using flock() to protect the
files opened by the Unix IO manager so that systemd and udev could not
access the block device while e2fsprogs is doing something with the
device. However, flocking block devices for the duration of a mount
creates stalling problems with udev, because it will not process a
uevent for a block device until it can flock(LOCK_SH) the block device.
As a result, udevsettle blocks for 2 minutes until it times out and
exits with failure.
Since libext2fs generally opens block devices (on Linux) with O_EXCL,
fuse2fs is guaranteed to be the only program accessing the filesystem if
it's on a block device. However, O_EXCL doesn't do anything for
non-block devices, so we need a way to coordinate write access to
filesystem image files. Use the locking code, but only if we have a
non-block device.
Darrick J. Wong [Fri, 3 Oct 2025 16:24:20 +0000 (09:24 -0700)]
libext2fs: initialize htree when expanding directory
Teach ext2fs_link to initialize the htree when we're expanding a
directory beyond the first block. This brings fuse2fs' behavior in line
with the kernel and dramatically improves performance. It also is the
start of a bunch of bug fixing for ext4/045. This is a straight port of
fs/ext4/namei.c.
This patch is needed for the next patch, which fixes the dir_nlink
functionality, because apparently the two features are intertwined.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Tue, 21 Oct 2025 00:29:48 +0000 (17:29 -0700)]
libext2fs: add POSIX advisory locking to the unix IO manager
Add support for using flock() to protect the files opened by the Unix IO
manager so that other fuse2fs servers cannot stomp all over the
filesystem. We may some day want to adopt this in e2fsck.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Theodore Ts'o [Fri, 6 Mar 2026 17:13:08 +0000 (12:13 -0500)]
misc: fix a dropped line in the mke2fs.conf man page
The transformation ".I proceed_delay" to "/fIProceed_delay/fR" left a
leading period behind, and "./fIproceed_delay/fR" was treated a
undefined roff macro.
Theodore Ts'o [Fri, 6 Mar 2026 00:14:38 +0000 (19:14 -0500)]
ci.yml: drop building e2fsprogs on mingw32
A change in the github actions' runtime infrastructgure means that it
now take over 4 hours to run "mke2fs.exe -T ext4 image.ext4 128M".
The importance of 32-bit Windows support is much less now, so just
drop mingw32.
Theodore Ts'o [Fri, 16 Jan 2026 23:01:09 +0000 (18:01 -0500)]
e4defrag: don't try to defragment files which have 0 or 1 blocks
This fixes a crash in e4defrag when the file is using the inline_data
feature, and so the file data is stored in the inode table.
Technically speaking, such a file does not consume any data blocks,
but when an application program calls stat(2) on such a file, and
st_blocks is set to 0, it might confuse the program into thinking the
file did not contain any data. For this reason, ext4 returns 1 in
st_blocks. (For other files or directories, st_blocks will be a
multiple of the file system block size divided by 512, since st_blocks
is denominated in units of 512 sectors on Linux --- and most other Unix
systems with the notable exception of HP-UX[1].)
Unfortunately, when e4defrag tries to defragment a inline data file,
it divides st_blocks by (fs->block_size / 512) resulting in e4defrag
(correctly) concluding that the file uses 0 data blocks; but since
files were skipped only when st_blocks == 0, e4defrag will then divide
the number of blocks that were defragmented (0) with the number of
blocks in the file (0), triggering a divide by zero crash.
As it turns out, it's pointless to try to defrag a file with 0 or 1
data blocks (include files with inline data). So fix this by skipping
any file where st_blocks <= block_size / 512.
Boian Berberov [Mon, 12 Jan 2026 21:55:45 +0000 (15:55 -0600)]
doc: Updated `ext4`, `mke2fs`, `mke2fs.conf` and `tune2fs` man pages #2
- Rewrote man pages for easier readability in raw form
- Reduce vertical whitespace by combining lines
- Added two spaces between sentences where missing
Thomas Petazzoni [Sat, 22 Nov 2025 20:12:23 +0000 (21:12 +0100)]
configure: check for FS_IOC_READ_VERITY_METADATA availability
Commit 6bfa843b4435334ac073e42950b48d8bacb54977 ("mke2fs: enable
copying of fs-verity metadata") introduced support for reading
fs-verity metadata, which requires using the
FS_IOC_READ_VERITY_METADATA.
The code is conditionally compiled when the kernel headers have
<linux/fsverity.h> available. Unfortunately, this check is not
sufficient: <linux/fsverity.h> was introduced in Linux 5.10, but the
FS_IOC_READ_VERITY_METADATA was not introduced before 5.12, so if one
is using 5.10 or 5.11 kernel headers, the build fails with:
./../misc/create_inode.c: In function ‘copy_fs_verity_data’:
./../misc/create_inode.c:589:10: error: variable ‘arg’ has initializer but incomplete type
589 | struct fsverity_read_metadata_arg arg = {
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
[...]
./../misc/create_inode.c:600:20: error: ‘FS_IOC_READ_VERITY_METADATA’ undeclared (first use in this function)
600 | size = ioctl(fd, FS_IOC_READ_VERITY_METADATA, &arg);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
This commit therefore extends the configure.ac check to ensure that
not only <linux/fsverity.h> exists but also that it defines the
FS_IOC_READ_VERITY_METADATA ioctl.
Closes: https://github.com/tytso/e2fsprogs/pull/256 Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Robert Yang [Sun, 30 Nov 2025 13:47:50 +0000 (21:47 +0800)]
misc/create_inode.c: Fix for file larger than 2GB
Fixed:
$ dd if=/dev/zero of=../image.ext4 bs=1M count=4k
$ dd if=/dev/random of=../rootfs/largefile bs=1M count=3k
$ ./misc/mke2fs -t ext4 -d ../rootfs/ ../image.ext4
__populate_fs: Ext2 file too big while writing file "largefile"
mke2fs: Ext2 file too big while populating file system
This was because the offset is overflow, use __u64 to fix the problem.
Another code which uses ext2_off_t is copy_fs_verity_data(), but it only copies
the metadata, so it should be enough large for it, just leave it there.
Signed-off-by: Robert Yang <liezhi.yang@windriver.com>
Theodore Ts'o [Tue, 11 Nov 2025 20:53:46 +0000 (15:53 -0500)]
mke2fs: if the kernel supports bs > gt, skip the large blockize check
There are patches which alow ext4 to support file systems where the
block size is larger than the page size. For such kernels, skip the
test for large block sizes, which would require the user to explicitly
answer give permission to proceed.
Ralph Siemsen [Wed, 10 Sep 2025 13:51:47 +0000 (09:51 -0400)]
mke2fs: add root_selinux option for root inode label
This option allows setting the SELinux security context (label) for the
root directory. A common value would be system_u:object_r:root_t
possibly with a level/range such as :s0 suffix (for MCS/MLS policy).
Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Message-ID: <20250910-mke2fs-small-fixes-v2-3-55c9842494e0@linaro.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Ralph Siemsen [Wed, 10 Sep 2025 13:51:46 +0000 (09:51 -0400)]
mke2fs: support multiple '-E' options
The '-E' option for specifying extended attributes can now be used
multiple times. The existing support for multiple attributes encoded
as comma-separated string is maintained for each '-E' option.
Prior to this change, if multiple '-E' options were specified, then
only the last one was used. Earlier ones were silently ignored.
Signed-off-by: Ralph Siemsen <ralph.siemsen@linaro.org> Reviewed-by: Andreas Dilger <adilger@dilger.ca>
Message-ID: <20250910-mke2fs-small-fixes-v2-2-55c9842494e0@linaro.org> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Andreas Dilger [Fri, 8 Aug 2025 08:04:27 +0000 (02:04 -0600)]
ext2fs: fix fast symlink blocks check
Use ext4_inode_is_fast_symlink() in ext2fs_inode_has_valid_blocks2()
instead of depending exclusively on i_blocks == 0 to determine
if an inode is a fast symlink. Otherwise, if a fast symlink has a
large external xattr inode that increases i_blocks, it will be
incorrectly reported as having invalid blocks.
e2fsck: check for extended attributes with ea_inode but a zero ea_size
The combination of e_value_inum != 0 and e_value_size == 0 is invalid
and can trigger kernel warnings. This should only happen with
delierately corrupted extended attribute entries; so if we come across
one, just clear the xattrs.
Darrick J. Wong [Thu, 28 Aug 2025 17:30:43 +0000 (10:30 -0700)]
fuse2fs: mount norecovery if main block device is readonly
If the main block device is read-only, downgrade the mount to an ro
norecovery mount to match what the kernel does. This will make
generic/050 somewhat less grouchy.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:43 +0000 (10:30 -0700)]
fuse2fs: make norecovery behavior consistent with the kernel
Amazingly, norecovery/noload on the kernel ext4 driver allows a
read-write mount even for journalled filesystems. The one case where
mounting fails is if there's a journal and it's dirty AND you didn't
specify norecovery. Make the fuse2fs option behave the same as the
kernel.
Also, ext2fs_run_ext3_journal doesn't explicitly check EXT2_FILE_RW
state, which means fuse2fs must do that.
Found via ext4/271.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Thu, 28 Aug 2025 17:30:43 +0000 (10:30 -0700)]
fuse2fs: recheck support after replaying journal
The journal could have contained a new primary superblock, so we need to
recheck feature support after recovering it, because otherwise fuse2fs
could blow up on an unsupported feature that was enabled by a journal
transaction.
We also don't need to clear needsrecovery or dirty the superblock after
recovering the journal because ext2fs_run_ext3_journal does that for us.
Remove those lines.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Tue, 7 Oct 2025 21:10:18 +0000 (14:10 -0700)]
fuse2fs: spot check clean journals
Even though fuse2fs doesn't (yet) support writing new transactions to
the journal, we ought at least to check that the superblock is ok when
we mount a clean filesystem. This fixes complaints by ext4/012 about
mount failing to notice a corrupt journal.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Fri, 12 Sep 2025 22:26:01 +0000 (15:26 -0700)]
fuse2fs: check free space when creating a symlink
Make sure we have enough space to create the symlink and its remote
block.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Fri, 5 Sep 2025 22:25:34 +0000 (15:25 -0700)]
fuse2fs: work around EBUSY discard returns from dm-thinp
generic/500 has this interesting failure mode when fuse2fs is running in
fuseblk mode:
--- /run/fstests/bin/tests/generic/500.out 2025-07-15 14:45:15.092576090 -0700
+++ /var/tmp/fstests/generic/500.out.bad 2025-09-05 15:09:35.211499883 -0700
@@ -1,2 +1,22 @@
QA output created by 500
+fstrim: /opt: FITRIM ioctl failed: Device or resource busy
Apparently you can overwhelm dm-thinp with a large number of discard
requests, at which point it starts returning EBUSY. This is unexpected
behavior but let's mask that off because discard is advisory anyways.
Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Fri, 5 Sep 2025 21:17:14 +0000 (14:17 -0700)]
fuse2fs: fix in_file_group missing the primary process gid
I forgot that Unix processes have both a primary group id and a list of
supplementary group ids. The primary is provided by the fuse client;
the supplemental groups are noted by the Groups: field of
/proc/self/status.
If a process does not have /any/ supplemental group ids, then
in_file_group returns the wrong answer if the inode gid matches the
group id provided by the fuse client because it doesn't check that
anymore. Make it so the primary group id check always happens.
Found by generic/375.
Cc: <linux-ext4@vger.kernel.org> # v1.47.3 Fixes: 3469e6ff606af8 ("fuse2fs: fix group membership checking in op_chmod") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
Darrick J. Wong [Fri, 5 Sep 2025 20:52:24 +0000 (13:52 -0700)]
fuse2fs: don't update atime when reading executable file content
The kernel doesn't update the atime of program files when it's paging
their content into memory, so fuse2fs shouldn't either. Found by
generic/120.
Cc: <linux-ext4@vger.kernel.org> # v1.43 Fixes: 81cbf1ef4f5dab ("misc: add fuse2fs, a FUSE server for e2fsprogs") Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>