[Concept,06/34] vfs: Add UCLASS_MOUNT for the virtual filesystem

Message ID 20260403140523.1998228-7-sjg@u-boot.org
State New
Headers
Series Add a virtual filesystem (VFS) layer to U-Boot |

Commit Message

Simon Glass April 3, 2026, 2:04 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

Add the mount uclass which tracks filesystem mount points. Each mount
device holds a struct vfsmount with the mount point name and a
reference to the mounted UCLASS_FS device.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 configs/sandbox_defconfig |  1 +
 fs/Kconfig                |  7 +++++++
 fs/Makefile               |  1 +
 fs/mount-uclass.c         | 18 ++++++++++++++++++
 include/dm/uclass-id.h    |  1 +
 include/vfs.h             | 31 +++++++++++++++++++++++++++++++
 6 files changed, 59 insertions(+)
 create mode 100644 fs/mount-uclass.c
 create mode 100644 include/vfs.h
  

Patch

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index a08a838303b..76113ce711e 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -113,6 +113,7 @@  CONFIG_CMD_WDT=y
 CONFIG_CMD_WRITE=y
 CONFIG_CMD_AXI=y
 CONFIG_CMD_CAT=y
+CONFIG_VFS=y
 CONFIG_CMD_SETEXPR_FMT=y
 CONFIG_CMD_XXD=y
 CONFIG_CMD_DHCP6=y
diff --git a/fs/Kconfig b/fs/Kconfig
index 13f7d084c09..6a55bd71adc 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -29,6 +29,13 @@  config FILE
 	  (UCLASS_FS). Note that a UCLASS_FILE device is only created when it
 	  is opened.
 
+config VFS
+	bool "Virtual filesystem support"
+	depends on FS && DIR
+	help
+	  Provides a virtual filesystem layer with a mount table and
+	  unified path namespace. Includes a root filesystem at "/".
+
 config FS_LEGACY
 	def_bool y
 	help
diff --git a/fs/Makefile b/fs/Makefile
index 969888a81da..ffb6bbce737 100644
--- a/fs/Makefile
+++ b/fs/Makefile
@@ -8,6 +8,7 @@  obj-$(CONFIG_$(PHASE_)FS_LEGACY) += fs_legacy.o fs_internal.o
 obj-$(CONFIG_$(PHASE_)FS) += fs-uclass.o
 obj-$(CONFIG_$(PHASE_)DIR) += dir-uclass.o
 obj-$(CONFIG_$(PHASE_)FILE) += file-uclass.o
+obj-$(CONFIG_$(PHASE_)VFS) += mount-uclass.o
 
 ifdef CONFIG_XPL_BUILD
 obj-$(CONFIG_SPL_FS_FAT) += fat/
diff --git a/fs/mount-uclass.c b/fs/mount-uclass.c
new file mode 100644
index 00000000000..4cfc1d0ed02
--- /dev/null
+++ b/fs/mount-uclass.c
@@ -0,0 +1,18 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Virtual Filesystem layer
+ *
+ * Manages a mount table using UCLASS_MOUNT devices, providing unified
+ * path resolution across mounted filesystems. Inspired by the Linux VFS.
+ *
+ * Copyright 2026 Simon Glass <sjg@chromium.org>
+ */
+
+#include <dm.h>
+#include <vfs.h>
+
+UCLASS_DRIVER(mount) = {
+	.name			= "mount",
+	.id			= UCLASS_MOUNT,
+	.per_device_auto	= sizeof(struct vfsmount),
+};
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 6425ee88fa7..de79343904d 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -105,6 +105,7 @@  enum uclass_id {
 	UCLASS_MISC,		/* Miscellaneous device */
 	UCLASS_MMC,		/* SD / MMC card or chip */
 	UCLASS_MOD_EXP,		/* RSA Mod Exp device */
+	UCLASS_MOUNT,		/* Filesystem mount point */
 	UCLASS_MOUSE,		/* Mouse, trackpad or other pointing device */
 	UCLASS_MTD,		/* Memory Technology Device (MTD) device */
 	UCLASS_MUX,		/* Multiplexer device */
diff --git a/include/vfs.h b/include/vfs.h
new file mode 100644
index 00000000000..7c31caace25
--- /dev/null
+++ b/include/vfs.h
@@ -0,0 +1,31 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Virtual Filesystem layer for U-Boot
+ *
+ * Provides a unified path namespace with mount points, inspired by the
+ * Linux VFS but heavily cut down for U-Boot's needs.
+ *
+ * Copyright 2026 Simon Glass <sjg@chromium.org>
+ */
+
+#ifndef __VFS_H
+#define __VFS_H
+
+struct udevice;
+
+/**
+ * struct vfsmount - A mount point in the VFS
+ *
+ * This is the UCLASS_MOUNT per-device uclass-private data. All mount
+ * devices are children of the VFS root FS device. Each links a mount-point
+ * directory to a UCLASS_FS device.
+ *
+ * @dir: UCLASS_DIR device that is the mount point
+ * @target: UCLASS_FS device that is mounted here
+ */
+struct vfsmount {
+	struct udevice *dir;
+	struct udevice *target;
+};
+
+#endif