[PATCH 4/4] fs: devfs: make the default automount reachable under cdev aliases
Sascha Hauer
s.hauer at pengutronix.de
Mon Aug 31 02:48:28 PDT 2026
A cdev with a default automount is mounted by walking into
/mnt/<cdevname>, so /mnt only ever knows a cdev under its real name. With
a USB disk registered as "disk0" and aliased to "usbdisk0" you can read
/dev/usbdisk0.data, but mounting it still requires knowing that it really
is disk0.0.
Link the aliases next to the automount directory, so that /mnt/usbdisk0.data
points to disk0.0 and walking into it triggers the same automount as
/mnt/disk0.0 does. This also covers the aliases a partition has always
had: /mnt/disk0.data did not exist so far even though /dev/disk0.data
did.
The links are created and removed along with the alias itself, hence
devfs_remove() has to remove the aliases before dropping the automount -
cdev_mnt_unlink() needs DEVFS_HAS_AUTOMOUNT to still be set to know that
there is anything to unlink.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Assisted-by: Claude:claude-opus-5
---
fs/devfs-core.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index d647be9b9d..35a4bdfdc4 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -520,6 +520,35 @@ static void devfs_unlink(const char *name)
free(path);
}
+/*
+ * A cdev with a default automount is mounted by walking into
+ * /mnt/<cdevname>. Link the aliases next to it so that an alias can be used
+ * for mounting just as well.
+ */
+static void cdev_mnt_symlink(struct cdev *cdev, const char *linkname)
+{
+ char *path;
+
+ if (!(cdev->flags & DEVFS_HAS_AUTOMOUNT))
+ return;
+
+ path = xasprintf("/mnt/%s", linkname);
+ symlink(cdev->name, path);
+ free(path);
+}
+
+static void cdev_mnt_unlink(struct cdev *cdev, const char *linkname)
+{
+ char *path;
+
+ if (!(cdev->flags & DEVFS_HAS_AUTOMOUNT))
+ return;
+
+ path = xasprintf("/mnt/%s", linkname);
+ unlink(path);
+ free(path);
+}
+
void devfs_init(void)
{
struct cdev *cdev;
@@ -588,6 +617,7 @@ static int __devfs_add_alias(struct cdev *cdev, const char *name,
list_add_tail(&alias->list, &cdev->aliases);
cdev_symlink(cdev, name);
+ cdev_mnt_symlink(cdev, name);
return 0;
}
@@ -686,6 +716,7 @@ static void devfs_remove_aliases(struct cdev *cdev)
list_for_each_entry_safe(alias, tmp, &cdev->aliases, list) {
devfs_unlink(alias->name);
+ cdev_mnt_unlink(cdev, alias->name);
list_del(&alias->list);
free(alias->name);
free(alias);
@@ -706,6 +737,7 @@ int devfs_remove(struct cdev *cdev)
devfs_unlink(cdev->name);
+ /* Must happen before the automount is dropped below */
devfs_remove_aliases(cdev);
cdev_remove_default_automount(cdev);
--
2.47.3
More information about the barebox
mailing list