From: Darrick J. Wong <djwong@xxxxxxxxxx> 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@xxxxxxxxxx> --- 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 22d56ad7554496..2c8e2cc2b55416 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 1b7e88d990036b..229ae6da7f448b 100644 --- a/lib/ext2fs/fileio.c +++ b/lib/ext2fs/fileio.c @@ -300,6 +300,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) @@ -416,6 +421,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) @@ -584,7 +594,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);