From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 4/4] fs: devfs: make the default automount reachable under cdev aliases
Date: Mon, 31 Aug 2026 11:48:28 +0200 [thread overview]
Message-ID: <20260831-usbdisk-aliases-v1-4-0a2e40a35f3d@pengutronix.de> (raw)
In-Reply-To: <20260831-usbdisk-aliases-v1-0-0a2e40a35f3d@pengutronix.de>
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@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
prev parent reply other threads:[~2026-08-31 9:49 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-31 9:48 [PATCH 0/4] extend cdev alias support Sascha Hauer
2026-08-31 9:48 ` [PATCH 1/4] fs: devfs: remove aliases from the list when freeing them Sascha Hauer
2026-08-31 9:48 ` [PATCH 2/4] fs: remove the default automount when a cdev is removed Sascha Hauer
2026-08-31 9:48 ` [PATCH 3/4] fs: devfs: propagate cdev aliases to the partitions Sascha Hauer
2026-08-31 9:48 ` Sascha Hauer [this message]
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=20260831-usbdisk-aliases-v1-4-0a2e40a35f3d@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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