[PATCH 06/18] libfuse: add upper-level iomap add device function

Darrick J. Wong
2025-09-16T00:43:21Z

Make it so that the upper level fuse library can add iomap devices too.

Signed-off-by: "Darrick J. Wong" <djwong@kernel.org>
---
include/fuse.h | 19 +++++++++++++++++++
lib/fuse.c | 16 ++++++++++++++++
lib/fuse_versionscript | 2 ++
3 files changed, 37 insertions(+)

diff --git a/include/fuse.h b/include/fuse.h
index 958034a539abe6..524b77b5d7bbd0 100644
--- a/include/fuse.h
+++ b/include/fuse.h
@@ -1381,6 +1381,25 @@ void fuse_fs_init(struct fuse_fs *fs, struct fuse_conn_info *conn,
struct fuse_config *cfg);
void fuse_fs_destroy(struct fuse_fs *fs);

+/**
+ * Attach an open file descriptor to a fuse+iomap mount. Currently must be
+ * a block device.
+ *
+ * @param fd file descriptor of an open block device
+ * @param flags flags for the operation; none defined so far
+ * @return positive nonzero device id on success, or negative errno on failure
+ */
+int fuse_fs_iomap_device_add(int fd, unsigned int flags);
+
+/**
+ * Detach an open file from a fuse+iomap mount. Must be a device id returned
+ * by fuse_lowlevel_iomap_device_add.
+ *
+ * @param device_id device index as returned by fuse_lowlevel_iomap_device_add
+ * @return 0 on success, or negative errno on failure
+ */
+int fuse_fs_iomap_device_remove(int device_id);
+
int fuse_notify_poll(struct fuse_pollhandle *ph);

/**
diff --git a/lib/fuse.c b/lib/fuse.c
index eef0967f796ed6..632e935b8dff3e 100644
--- a/lib/fuse.c
+++ b/lib/fuse.c
@@ -2832,6 +2832,22 @@ static int fuse_fs_iomap_end(struct fuse_fs *fs, const char *path,
written, iomap);
}

+int fuse_fs_iomap_device_add(int fd, unsigned int flags)
+{
+ struct fuse_context *ctxt = fuse_get_context();
+ struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+ return fuse_lowlevel_iomap_device_add(se, fd, flags);
+}
+
+int fuse_fs_iomap_device_remove(int device_id)
+{
+ struct fuse_context *ctxt = fuse_get_context();
+ struct fuse_session *se = fuse_get_session(ctxt->fuse);
+
+ return fuse_lowlevel_iomap_device_remove(se, device_id);
+}
+
static void fuse_lib_setattr(fuse_req_t req, fuse_ino_t ino, struct stat *attr,
int valid, struct fuse_file_info *fi)
{
diff --git a/lib/fuse_versionscript b/lib/fuse_versionscript
index e796100c5ee414..c42fae5d4a3c50 100644
--- a/lib/fuse_versionscript
+++ b/lib/fuse_versionscript
@@ -224,6 +224,8 @@ FUSE_3.99 {
fuse_reply_iomap_begin;
fuse_lowlevel_iomap_device_add;
fuse_lowlevel_iomap_device_remove;
+ fuse_fs_iomap_device_add;
+ fuse_fs_iomap_device_remove;
} FUSE_3.18;