From c9ee6467183b224b40ca437fd23eeabe0ae6a158 Mon Sep 17 00:00:00 2001 From: Kent Overstreet Date: Sun, 13 Apr 2025 18:39:23 -0400 Subject: Add support for FS_IOC_GETFSSYSFSPATH With single device mode we won't always show up in sysfs by UUID, but the new VFS ioctl handles this nicely. Signed-off-by: Kent Overstreet --- c_src/libbcachefs.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/c_src/libbcachefs.c b/c_src/libbcachefs.c index c8503839..31644ea1 100644 --- a/c_src/libbcachefs.c +++ b/c_src/libbcachefs.c @@ -16,6 +16,7 @@ #include +#include #include #include "libbcachefs.h" @@ -447,12 +448,19 @@ int bcache_fs_open_fallible(const char *path, struct bchfs_handle *fs) fs->uuid = uuid.uuid; - char uuid_str[40]; - uuid_unparse(uuid.uuid.b, uuid_str); + struct fs_sysfs_path fs_sysfs_path; + if (!ioctl(path_fd, FS_IOC_GETFSSYSFSPATH, &fs_sysfs_path)) { + char *sysfs = mprintf("/sys/fs/%s", fs_sysfs_path.name); + fs->sysfs_fd = xopen(sysfs, O_RDONLY); + free(sysfs); + } else { + char uuid_str[40]; + uuid_unparse(uuid.uuid.b, uuid_str); - char *sysfs = mprintf(SYSFS_BASE "%s", uuid_str); - fs->sysfs_fd = xopen(sysfs, O_RDONLY); - free(sysfs); + char *sysfs = mprintf(SYSFS_BASE "%s", uuid_str); + fs->sysfs_fd = xopen(sysfs, O_RDONLY); + free(sysfs); + } return 0; } -- cgit v1.2.3