[PATCH 09/10] libext2fs: allow callers to disallow I/O to file data blocks

Darrick J. Wong
2025-08-21T01:15:26Z

Add a flag to ext2_file_t to disallow read and write I/O to file data
blocks. This supports fuse2fs iomap support, which will keep all the
file data I/O inside the kerne.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
lib/ext2fs/ext2fs.h | 3 +++
lib/ext2fs/fileio.c | 12 +++++++++++-
2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h
index dee9feb02624ed..7d36b1a839dc57 100644
--- a/lib/ext2fs/ext2fs.h
+++ b/lib/ext2fs/ext2fs.h
@@ -178,6 +178,9 @@ typedef struct ext2_struct_dblist *ext2_dblist;
#define EXT2_FILE_WRITE 0x0001
#define EXT2_FILE_CREATE 0x0002

+/* no file I/O to disk blocks, only to inline data */
+#define EXT2_FILE_NOBLOCKIO 0x0004
+
#define EXT2_FILE_MASK 0x00FF

#define EXT2_FILE_BUF_DIRTY 0x4000
diff --git a/lib/ext2fs/fileio.c b/lib/ext2fs/fileio.c
index 3a36e9e7fff43b..95ee45ec7371ae 100644
--- a/lib/ext2fs/fileio.c
+++ b/lib/ext2fs/fileio.c
@@ -314,6 +314,11 @@ errcode_t ext2fs_file_read(ext2_file_t file, void *buf,
if (file->inode.i_flags & EXT4_INLINE_DATA_FL)
return ext2fs_file_read_inline_data(file, buf, wanted, got);

+ if (file->flags & EXT2_FILE_NOBLOCKIO) {
+ retval = EXT2_ET_OP_NOT_SUPPORTED;
+ goto fail;
+ }
+
while ((file->pos < EXT2_I_SIZE(&file->inode)) && (wanted > 0)) {
retval = sync_buffer_position(file);
if (retval)
@@ -441,6 +446,11 @@ errcode_t ext2fs_file_write(ext2_file_t file, const void *buf,
retval = 0;
}

+ if (file->flags & EXT2_FILE_NOBLOCKIO) {
+ retval = EXT2_ET_OP_NOT_SUPPORTED;
+ goto fail;
+ }
+
while (nbytes > 0) {
retval = sync_buffer_position(file);
if (retval)
@@ -609,7 +619,7 @@ static errcode_t ext2fs_file_zero_past_offset(ext2_file_t file,
int ret_flags;
errcode_t retval;

- if (off == 0)
+ if (off == 0 || (file->flags & EXT2_FILE_NOBLOCKIO))
return 0;

retval = sync_buffer_position(file);