From: Giuseppe Scrivano <gscrivan@redhat.com>
To: linux-erofs@lists.ozlabs.org
Cc: linux-fsdevel@vger.kernel.org, linux-api@vger.kernel.org
Subject: [PATCH 2/2] erofs: add ioctl to retrieve the backing source file descriptor
Date: Wed, 8 Jul 2026 11:34:27 +0200 [thread overview]
Message-ID: <20260708093446.3370200-3-gscrivan@redhat.com> (raw)
In-Reply-To: <20260708093446.3370200-1-gscrivan@redhat.com>
Add EROFS_IOC_GET_SOURCE_FD ioctl that returns a file descriptor to the
backing image file for file-backed erofs mounts.
Returns -ENOENT for block-device-backed erofs mounts where there is no
backing file.
The UAPI constant is defined in include/uapi/linux/erofs.h.
Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
---
fs/erofs/inode.c | 25 +++++++++++++++++++++++++
include/uapi/linux/erofs.h | 9 +++++++++
2 files changed, 34 insertions(+)
create mode 100644 include/uapi/linux/erofs.h
diff --git a/fs/erofs/inode.c b/fs/erofs/inode.c
index 45afe5c50de8..0a38cb5cfc5d 100644
--- a/fs/erofs/inode.c
+++ b/fs/erofs/inode.c
@@ -6,6 +6,8 @@
*/
#include "xattr.h"
#include <linux/compat.h>
+#include <linux/file.h>
+#include <uapi/linux/erofs.h>
#include <trace/events/erofs.h>
static int erofs_fill_symlink(struct inode *inode, void *bptr, unsigned int ofs)
@@ -356,6 +358,27 @@ static int erofs_ioctl_get_volume_label(struct inode *inode, void __user *arg)
return ret ? -EFAULT : 0;
}
+static int erofs_ioctl_get_source_fd(struct file *filp)
+{
+ struct erofs_sb_info *sbi = EROFS_I_SB(file_inode(filp));
+ struct file *f;
+ int fd;
+
+ if (!capable(CAP_SYS_ADMIN))
+ return -EPERM;
+
+ if (!erofs_is_fileio_mode(sbi))
+ return -ENOENT;
+
+ fd = get_unused_fd_flags(O_CLOEXEC);
+ if (fd < 0)
+ return fd;
+
+ f = get_file(sbi->dif0.file);
+ fd_install(fd, f);
+ return fd;
+}
+
long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
{
struct inode *inode = file_inode(filp);
@@ -364,6 +387,8 @@ long erofs_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
switch (cmd) {
case FS_IOC_GETFSLABEL:
return erofs_ioctl_get_volume_label(inode, argp);
+ case EROFS_IOC_GET_SOURCE_FD:
+ return erofs_ioctl_get_source_fd(filp);
default:
return -ENOTTY;
}
diff --git a/include/uapi/linux/erofs.h b/include/uapi/linux/erofs.h
new file mode 100644
index 000000000000..17c835785ea9
--- /dev/null
+++ b/include/uapi/linux/erofs.h
@@ -0,0 +1,9 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+#ifndef _UAPI_LINUX_EROFS_H
+#define _UAPI_LINUX_EROFS_H
+
+#include <linux/ioctl.h>
+
+#define EROFS_IOC_GET_SOURCE_FD _IO('e', 1)
+
+#endif /* _UAPI_LINUX_EROFS_H */
--
2.55.0
next prev parent reply other threads:[~2026-07-08 9:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-08 9:34 [PATCH 0/2] erofs: fd-based source and backing file introspection Giuseppe Scrivano
2026-07-08 9:34 ` [PATCH 1/2] erofs: accept source file descriptor via fsconfig Giuseppe Scrivano
2026-07-08 12:45 ` Gao Xiang
2026-07-08 9:34 ` Giuseppe Scrivano [this message]
2026-07-08 12:51 ` [PATCH 2/2] erofs: add ioctl to retrieve the backing source file descriptor Gao Xiang
2026-07-08 14:55 ` Andy Lutomirski
2026-07-08 15:20 ` Giuseppe Scrivano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260708093446.3370200-3-gscrivan@redhat.com \
--to=gscrivan@redhat.com \
--cc=linux-api@vger.kernel.org \
--cc=linux-erofs@lists.ozlabs.org \
--cc=linux-fsdevel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox