[PATCH 4/4] libfuse: enable setting iomap block device block size

Darrick J. Wong
2025-09-16T00:49:36Z

Create a means for an unprivileged fuse server to set the block size of
a block device that it previously opened and associated with the fuse
connection.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
include/fuse_kernel.h | 7 +++++++
include/fuse_lowlevel.h | 12 ++++++++++++
lib/fuse_lowlevel.c | 11 +++++++++++
lib/fuse_versionscript | 1 +
4 files changed, 31 insertions(+)

diff --git a/include/fuse_kernel.h b/include/fuse_kernel.h
index 3b88b36c04ae02..01a1372afb40b3 100644
--- a/include/fuse_kernel.h
+++ b/include/fuse_kernel.h
@@ -1163,6 +1163,11 @@ struct fuse_iomap_support {
uint64_t padding;
};

+struct fuse_iomap_backing_info {
+ uint32_t backing_id;
+ uint32_t blocksize;
+};
+
/* Device ioctls: */
#define FUSE_DEV_IOC_MAGIC 229
#define FUSE_DEV_IOC_CLONE _IOR(FUSE_DEV_IOC_MAGIC, 0, uint32_t)
@@ -1172,6 +1177,8 @@ struct fuse_iomap_support {
#define FUSE_DEV_IOC_ADD_IOMAP _IO(FUSE_DEV_IOC_MAGIC, 99)
#define FUSE_DEV_IOC_IOMAP_SUPPORT _IOR(FUSE_DEV_IOC_MAGIC, 99, \
struct fuse_iomap_support)
+#define FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE _IOW(FUSE_DEV_IOC_MAGIC, 99, \
+ struct fuse_iomap_backing_info)

struct fuse_lseek_in {
uint64_t fh;
diff --git a/include/fuse_lowlevel.h b/include/fuse_lowlevel.h
index 7a99f05e2de841..43098cb655effa 100644
--- a/include/fuse_lowlevel.h
+++ b/include/fuse_lowlevel.h
@@ -2692,6 +2692,18 @@ uint64_t fuse_lowlevel_discover_iomap(int fd);
*/
int fuse_lowlevel_add_iomap(int fd);

+/**
+ * Set the block size of an open block device that has been opened for use with
+ * iomap.
+ *
+ * @param fd open file descriptor to a fuse device
+ * @param dev_index device index returned by fuse_lowlevel_iomap_device_add
+ * @param blocksize block size in bytes
+ * @return 0 on success, -1 on failure with errno set
+ */
+int fuse_lowlevel_iomap_set_blocksize(int fd, int dev_index,
+ unsigned int blocksize);
+
#ifdef __cplusplus
}
#endif
diff --git a/lib/fuse_lowlevel.c b/lib/fuse_lowlevel.c
index 784c90d8cd1e3f..68e979e2ab334e 100644
--- a/lib/fuse_lowlevel.c
+++ b/lib/fuse_lowlevel.c
@@ -4844,3 +4844,14 @@ int fuse_lowlevel_add_iomap(int fd)
{
return ioctl(fd, FUSE_DEV_IOC_ADD_IOMAP);
}
+
+int fuse_lowlevel_iomap_set_blocksize(int fd, int dev_index,
+ unsigned int blocksize)
+{
+ struct fuse_iomap_backing_info fbi = {
+ .backing_id = dev_index,
+ .blocksize = blocksize,
+ };
+
+ return ioctl(fd, FUSE_DEV_IOC_IOMAP_SET_BLOCKSIZE, &fbi);
+}
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index 39bc1e1036007a..c45be2a92e59b9 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -255,6 +255,7 @@ FUSE_3.99 {
fuse_service_request_file;
fuse_service_send_goodbye;
fuse_service_take_fusedev;
+ fuse_lowlevel_iomap_set_blocksize;
} FUSE_3.18;