* [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well
@ 2025-12-11 15:18 Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 2/3] treewide: replace open-coded variants of devpath_to_name Ahmad Fatoum
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 15:18 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Functions like imx6_bbu_internal_mmcboot_register_handler() are called
with devicefile either being the cdev name or with a full path.
There is no harm in trying to detect the devicefile in the former case
as well, so do it unconditionally and simplify the function as a result.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
common/bbu.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
diff --git a/common/bbu.c b/common/bbu.c
index 39db87e823d9..00d415bcf826 100644
--- a/common/bbu.c
+++ b/common/bbu.c
@@ -43,27 +43,19 @@ void bbu_append_handlers_to_file_list(struct file_list *files)
struct bbu_handler *handler;
list_for_each_entry(handler, &bbu_image_handlers, list) {
- const char *cdevname, *devpath;
- char *buf = NULL;
+ const char *devicefile;
struct stat s;
- devpath = handler->devicefile;
+ devicefile = handler->devicefile;
- if (strstarts(devpath, "/dev/")) {
- cdevname = devpath_to_name(devpath);
- device_detect_by_name(cdevname);
+ device_detect_by_name(devpath_to_name(devicefile));
- devpath = buf = basprintf("/dev/%s", cdevname);
- }
-
- if (stat(devpath, &s) == 0) {
- append_bbu_entry(handler->name, devpath, files);
+ if (stat(devicefile, &s) == 0) {
+ append_bbu_entry(handler->name, devicefile, files);
} else {
pr_info("Skipping handler bbu-%s: %s unavailable\n",
- handler->name, devpath);
+ handler->name, devicefile);
}
-
- free(buf);
}
}
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 2/3] treewide: replace open-coded variants of devpath_to_name
2025-12-11 15:18 [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Ahmad Fatoum
@ 2025-12-11 15:18 ` Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 3/3] fs: implement new resolve_fsdevice_path helper Ahmad Fatoum
2025-12-15 10:18 ` [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 15:18 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
Instead of opencoding this at multiple places, use the helper we have
for it.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
commands/findmnt.c | 2 +-
common/bootscan.c | 2 +-
common/imx-bbu-nand-fcb.c | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/commands/findmnt.c b/commands/findmnt.c
index a531b1a95a83..b1c323ebbff2 100644
--- a/commands/findmnt.c
+++ b/commands/findmnt.c
@@ -92,7 +92,7 @@ static int do_findmnt(int argc, char *argv[])
continue;
backingstore = target->backingstore;
- backingstore += str_has_prefix(backingstore, "/dev/");
+ backingstore = devpath_to_name(backingstore);
if (streq_ptr(backingstore, cdev->name)) {
print_header(&header_printed);
diff --git a/common/bootscan.c b/common/bootscan.c
index 813d6d242a08..faaceaa22152 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -145,7 +145,7 @@ static int boot_scan_devicename(struct bootscanner *scanner,
pr_debug("%s(%s): %s\n", __func__, scanner->name, devname);
/* Support both boot /dev/disk0.rootfs and boot disk0.rootfs */
- devname += str_has_prefix(devname, "/dev/");
+ devname = devpath_to_name(devname);
device_detect_by_name(devname);
diff --git a/common/imx-bbu-nand-fcb.c b/common/imx-bbu-nand-fcb.c
index 7593cd27fec9..0ca5782a702e 100644
--- a/common/imx-bbu-nand-fcb.c
+++ b/common/imx-bbu-nand-fcb.c
@@ -1232,7 +1232,7 @@ static int imx_bbu_nand_update(struct bbu_handler *handler, struct bbu_data *dat
}
/* Support both boot /dev/nand0.barebox and boot nand0.barebox */
- devname += str_has_prefix(devname, "/dev/");
+ devname = devpath_to_name(devname);
device_detect_by_name(devname);
--
2.47.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH 3/3] fs: implement new resolve_fsdevice_path helper
2025-12-11 15:18 [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 2/3] treewide: replace open-coded variants of devpath_to_name Ahmad Fatoum
@ 2025-12-11 15:18 ` Ahmad Fatoum
2025-12-15 10:18 ` [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Ahmad Fatoum @ 2025-12-11 15:18 UTC (permalink / raw)
To: barebox; +Cc: Ahmad Fatoum
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@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
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well
2025-12-11 15:18 [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 2/3] treewide: replace open-coded variants of devpath_to_name Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 3/3] fs: implement new resolve_fsdevice_path helper Ahmad Fatoum
@ 2025-12-15 10:18 ` Sascha Hauer
2 siblings, 0 replies; 4+ messages in thread
From: Sascha Hauer @ 2025-12-15 10:18 UTC (permalink / raw)
To: barebox, Ahmad Fatoum
On Thu, 11 Dec 2025 16:18:14 +0100, Ahmad Fatoum wrote:
> Functions like imx6_bbu_internal_mmcboot_register_handler() are called
> with devicefile either being the cdev name or with a full path.
>
> There is no harm in trying to detect the devicefile in the former case
> as well, so do it unconditionally and simplify the function as a result.
>
>
> [...]
Applied, thanks!
[1/3] bbu: detect devices when devicefile has no /dev/ prefix as well
https://git.pengutronix.de/cgit/barebox/commit/?id=56811a330c77 (link may not be stable)
[2/3] treewide: replace open-coded variants of devpath_to_name
https://git.pengutronix.de/cgit/barebox/commit/?id=e9304ba3e0f1 (link may not be stable)
[3/3] fs: implement new resolve_fsdevice_path helper
https://git.pengutronix.de/cgit/barebox/commit/?id=feb5291006ec (link may not be stable)
Best regards,
--
Sascha Hauer <s.hauer@pengutronix.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-12-15 10:18 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-12-11 15:18 [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 2/3] treewide: replace open-coded variants of devpath_to_name Ahmad Fatoum
2025-12-11 15:18 ` [PATCH 3/3] fs: implement new resolve_fsdevice_path helper Ahmad Fatoum
2025-12-15 10:18 ` [PATCH 1/3] bbu: detect devices when devicefile has no /dev/ prefix as well Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox