[PATCH 3/3] fs: implement new resolve_fsdevice_path helper
Ahmad Fatoum
a.fatoum at pengutronix.de
Thu Dec 11 07:18:16 PST 2025
For use by the EFI loader, we will want to split off the file path
within a device from the device path.
As we have no function that generates a path relative to a mountpoint's
root, add a function that does this.
Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
fs/fs.c | 25 +++++++++++++++++++++++++
include/fs.h | 1 +
2 files changed, 26 insertions(+)
diff --git a/fs/fs.c b/fs/fs.c
index 28378989f91b..77f22d69ea49 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -2454,6 +2454,31 @@ struct fs_device *get_fsdevice_by_path(int dirfd, const char *pathname)
return fsdev;
}
+struct fs_device *resolve_fsdevice_path(int dirfd, const char *pathname, char **filepath)
+{
+ struct fs_device *fsdev;
+ char *res = NULL;
+ struct path path;
+ int ret;
+
+ fsdev = get_fsdevice_by_path(dirfd, pathname);
+ if (!fsdev)
+ return NULL;
+
+ ret = filename_lookup(dirfd, getname(pathname), LOOKUP_FOLLOW, &path);
+ if (ret)
+ goto out;
+
+ res = dpath(path.dentry, fsdev->vfsmount.mnt_root);
+ if (res)
+ *filepath = res;
+
+ path_put(&path);
+out:
+ errno_set(ret);
+ return res ? fsdev : NULL;
+}
+
static int vfs_rmdir(struct inode *dir, struct dentry *dentry)
{
int error;
diff --git a/include/fs.h b/include/fs.h
index b9bd14da81a7..9c3c8d95123a 100644
--- a/include/fs.h
+++ b/include/fs.h
@@ -141,6 +141,7 @@ void cdev_print(const struct cdev *cdev);
char *canonicalize_path(int dirfd, const char *pathname);
struct fs_device *get_fsdevice_by_path(int dirfd, const char *path);
+struct fs_device *resolve_fsdevice_path(int dirfd, const char *pathname, char **filepath);
const char *get_mounted_path(const char *path);
--
2.47.3
More information about the barebox
mailing list