summaryrefslogtreecommitdiff
path: root/na/fs/super.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:24:56 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-07-10 11:24:56 +0800
commit1767d390fbf3d0c65389de46caf0b6d43ef3b6ad (patch)
tree0f5e01cd7c7a05abb6b1c7472d7f00f49caf02cc /na/fs/super.cc
parent63dc025705f6533b91fb1a7d26e6ed864efd9900 (diff)
downloadlume-1767d390fbf3d0c65389de46caf0b6d43ef3b6ad.tar.gz
lume-1767d390fbf3d0c65389de46caf0b6d43ef3b6ad.tar.xz
feat: establish bootable new architecture checkpoint
Replace the compressed boot path with a relocatable higher-half RISC-V entry, expand memory and SMP support, and add the driver, TTY, VFS, exec, signal, syscall, initramfs, and self-test infrastructure needed for a bootable kernel checkpoint.
Diffstat (limited to 'na/fs/super.cc')
-rw-r--r--na/fs/super.cc95
1 files changed, 95 insertions, 0 deletions
diff --git a/na/fs/super.cc b/na/fs/super.cc
new file mode 100644
index 0000000..231b57c
--- /dev/null
+++ b/na/fs/super.cc
@@ -0,0 +1,95 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/* Copyright (C) 2026 Richard Qin */
+
+/*
+ * super.cc — Superblock lifecycle + filesystem type registry
+ */
+
+#include <lume/fs.h>
+#include <lume/dcache.h>
+#include <lume/mount.h>
+#include <lume/klog.h>
+#include <lume/slab.h>
+#include <lume/errno.h>
+
+/* Global root filesystem entry points */
+vfsmount* g_root_mnt = nullptr;
+dentry* g_root_dentry = nullptr;
+
+/* ================================================================== */
+/* Filesystem type registry */
+/* ================================================================== */
+
+namespace {
+
+list_head g_fs_types;
+Spinlock g_fs_type_lock;
+
+} // namespace
+
+int register_filesystem(file_system_type* fs)
+{
+ LockGuard guard(g_fs_type_lock);
+ list_add_tail(&fs->fs_list, &g_fs_types);
+ printk("[vfs] registered filesystem: %s\n", fs->name);
+ return 0;
+}
+
+file_system_type* get_fs_type(const char* name)
+{
+ LockGuard guard(g_fs_type_lock);
+ list_node* pos;
+ list_for_each(pos, &g_fs_types) {
+ auto* fs = list_entry(pos, file_system_type, fs_list);
+ /* Simple strcmp */
+ const char* a = fs->name;
+ const char* b = name;
+ while (*a && *a == *b) { a++; b++; }
+ if (*a == '\0' && *b == '\0')
+ return fs;
+ }
+ return nullptr;
+}
+
+/* ================================================================== */
+/* Superblock allocation */
+/* ================================================================== */
+
+super_block* alloc_super(file_system_type* type)
+{
+ auto* sb = new super_block{};
+ if (!sb) return nullptr;
+
+ list_init(&sb->s_list);
+ list_init(&sb->s_inodes);
+ sb->s_type = type;
+ sb->s_op = nullptr;
+ sb->s_root = nullptr;
+ sb->s_fs_info = nullptr;
+ sb->s_blocksize = 4096;
+ sb->s_blocksize_bits = 12;
+ sb->s_maxbytes = 0x7FFFFFFFFFFFFFFFLL;
+ sb->s_time_gran = 1;
+ sb->s_time_min = 0;
+ sb->s_time_max = 0x7FFFFFFFFFFFFFFFLL;
+ sb->s_flags = 0;
+ sb->s_magic = 0;
+ sb->s_active.store(1);
+ sb->s_count = 1;
+ sb->s_max_links = 0;
+ sb->s_d_op = nullptr;
+ sb->s_mounts = nullptr;
+ sb->s_dev = 0;
+ for (int i = 0; i < 32; i++) sb->s_id[i] = 0;
+
+ return sb;
+}
+
+/* ================================================================== */
+/* Init */
+/* ================================================================== */
+
+void super_init()
+{
+ list_init(&g_fs_types);
+}