[PATCH 3/8] init: let filesystems ask whether they are mounting the root device
From: Ismael Luceno
Date: Mon Nov 16 2026 - 17:43:48 EST
A filesystem that wants to treat the root mount differently from any
other mount has no way to tell which one it is being asked for, and no
way to find out how long the user is willing to wait for it. Expose
both.
root_wait becomes a global so a filesystem can read the value the user
gave rootwait=, and is_root_dev() reports whether a device is the one
the root filesystem is being mounted from. mount_root() is the only
thing that mounts from /dev/root, and that name exists for the root
mount alone, so a filesystem handed that device is being asked to be
the root filesystem.
No behaviour changes. This is here so a filesystem can act on the
root mount, which btrfs does next.
Signed-off-by: Ismael Luceno <ismael@xxxxxxxxxxx>
Signed-off-by: Ismael Luceno <iluceno@xxxxxxx>
---
include/linux/root_dev.h | 14 ++++++++++++++
init/do_mounts.c | 18 +++++++++++++++++-
2 files changed, 31 insertions(+), 1 deletion(-)
diff --git a/include/linux/root_dev.h b/include/linux/root_dev.h
index 847c9a06101b..b5a0181d1967 100644
--- a/include/linux/root_dev.h
+++ b/include/linux/root_dev.h
@@ -15,4 +15,18 @@ #define _ROOT_DEV_H_
extern dev_t ROOT_DEV;
+/*
+ * Milliseconds to wait for the root device, from the rootwait= parameter.
+ * Negative means wait indefinitely, zero means do not wait.
+ */
+extern int root_wait;
+
+/*
+ * True if @dev is the device the root filesystem is being mounted from, or
+ * was mounted from. The root mount names the device /dev/root, which is
+ * created for it alone, so a filesystem can tell the root mount from any
+ * other it is asked to do.
+ */
+bool is_root_dev(dev_t dev);
+
#endif
diff --git a/init/do_mounts.c b/init/do_mounts.c
index febcc37f9128..f1dcb18201eb 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -30,9 +30,9 @@
int root_mountflags = MS_RDONLY | MS_SILENT;
static char __initdata saved_root_name[64];
-static int root_wait;
dev_t ROOT_DEV;
+int root_wait;
static int __init readonly(char *str)
{
@@ -372,10 +372,26 @@ #define CIFSROOT_RETRY_MAX 5
pr_emerg("Failed to create /dev/root: %d\n", err);
mount_root_generic("/dev/root", root_device_name, root_mountflags);
}
+
+/*
+ * Was the filesystem on @dev mounted as the root filesystem? mount_root()
+ * above is the only thing that mounts from /dev/root, and that name is given
+ * to the root mount alone, so a filesystem being handed that device is being
+ * asked to be the root filesystem.
+ */
+bool is_root_dev(dev_t dev)
+{
+ return dev && dev == ROOT_DEV;
+}
#else
static inline void mount_block_root(char *root_device_name)
{
}
+
+static inline bool is_root_dev(dev_t dev)
+{
+ return false;
+}
#endif /* CONFIG_BLOCK */
void __init mount_root(char *root_device_name)