]> Projects (at) Tadryanom (dot) Me - AdrOS.git/commitdiff
vfs: route virtual mounts through fs registry
authorTulio A M Mendes <[email protected]>
Sat, 6 Jun 2026 18:35:43 +0000 (15:35 -0300)
committerTulio A M Mendes <[email protected]>
Sat, 6 Jun 2026 18:35:43 +0000 (15:35 -0300)
src/kernel/init.c
src/kernel/kconsole.c
src/kernel/syscall.c

index f2140ad936de337320dc859a1915190f1f6e08bf..21126663c0097bc7deeee194e2f95bc86ff7ba31 100644 (file)
@@ -48,6 +48,12 @@ static void init_build_mount_source_name(const char* source_name, block_device_t
     if (!out || out_size == 0) return;
 
     if (source_name && source_name[0] != '\0') {
+        if (!bdev) {
+            strncpy(out, source_name, out_size - 1);
+            out[out_size - 1] = '\0';
+            return;
+        }
+
         if (strncmp(source_name, "/dev/", 5) == 0) {
             strncpy(out, source_name, out_size - 1);
             out[out_size - 1] = '\0';
@@ -116,6 +122,11 @@ int init_mount_fs(const char* fstype, block_device_t* bdev, uint32_t lba, const
         return -EINVAL;
     }
 
+    if ((fst->flags & FS_NEEDS_BDEV) && !bdev) {
+        kprintf("[MOUNT] Filesystem %s requires a block device\n", fstype);
+        return -ENODEV;
+    }
+
     char devname[32];
     init_build_mount_source_name(source_name, bdev, devname, sizeof(devname));
 
@@ -153,7 +164,7 @@ int init_mount_fs(const char* fstype, block_device_t* bdev, uint32_t lba, const
     }
 
     kprintf("[MOUNT] %s on /dev/%s -> %s\n",
-            fstype, bdev ? bdev->name : "?",
+            fstype, devname,
             mountpoint);
     return 0;
 }
@@ -276,6 +287,8 @@ int init_start(const struct boot_info* bi) {
      * mounts ensure the system is functional. */
     {
         int rc;
+        rc = vfs_mkdir("/tmp");
+        if (rc < 0 && rc != -EEXIST) kprintf("[INIT] mkdir /tmp failed: %d\n", rc);
         rc = vfs_mkdir("/dev");
         if (rc < 0 && rc != -EEXIST) kprintf("[INIT] mkdir /dev failed: %d\n", rc);
         rc = vfs_mkdir("/proc");
@@ -284,10 +297,7 @@ int init_start(const struct boot_info* bi) {
         if (rc < 0 && rc != -EEXIST) kprintf("[INIT] mkdir /disk failed: %d\n", rc);
     }
 
-    fs_node_t* tmp = tmpfs_create_root();
-    if (tmp) {
-        (void)vfs_mount_full("/tmp", tmp, "tmpfs", "none", 0, NULL, NULL);
-    }
+    (void)init_mount_fs("tmpfs", NULL, 0, "/tmp", 0, "none");
 
     /* Register hardware drivers with HAL and init in priority order */
     pci_driver_register();      /* priority 10: bus */
@@ -311,18 +321,12 @@ int init_start(const struct boot_info* bi) {
      * (including fulltest) has /dev available.  When /sbin/init runs
      * it re-mounts devfs via mount() syscall; vfs_mount replaces the
      * existing entry so this is a harmless overlap. */
-    fs_node_t* dev = devfs_create_root();
-    if (dev) {
-        (void)vfs_mount_full("/dev", dev, "devfs", "none", 0, NULL, NULL);
-    }
+    (void)init_mount_fs("devfs", NULL, 0, "/dev", 0, "none");
 
     vbe_register_devfs();
     keyboard_register_devfs();
 
-    fs_node_t* proc = procfs_create_root();
-    if (proc) {
-        (void)vfs_mount_full("/proc", proc, "procfs", "none", 0, NULL, NULL);
-    }
+    (void)init_mount_fs("procfs", NULL, 0, "/proc", 0, "none");
 
     /* Initialize ATA subsystem — probe all 4 drives
      * (primary/secondary x master/slave). */
index 336b0b786910c48ea411e84bbd6fbc287b996249..05ea815ded83706d194b61e50938f37df7af364d 100644 (file)
@@ -364,9 +364,11 @@ static void kconsole_mount(const char* args) {
 
     block_device_t* bdev = NULL;
     uint32_t lba = 0;
-    if (init_resolve_mount_device(device, &bdev, &lba) < 0) {
-        kprintf("mount: unknown device: %s\n", device);
-        return;
+    if (strcmp(fstype, "tmpfs") != 0 && strcmp(fstype, "devfs") != 0 && strcmp(fstype, "procfs") != 0) {
+        if (init_resolve_mount_device(device, &bdev, &lba) < 0) {
+            kprintf("mount: unknown device: %s\n", device);
+            return;
+        }
     }
 
     (void)init_mount_fs(fstype, bdev, lba, mountpoint, 0, device);
index fb98c29f28c2be43570573bb115563fcbe4813f6..55a9afd53a63a76dbc9a1c8bd1faccbb63ee1d95 100644 (file)
@@ -5269,33 +5269,13 @@ static void extended_syscall_dispatch(struct registers* regs, uint32_t syscall_n
         if (!mp_node) { sc_ret(regs) = (uint32_t)-ENOENT; return; }
         if (!(mp_node->flags & FS_DIRECTORY)) { sc_ret(regs) = (uint32_t)-ENOTDIR; return; }
 
-        /* Virtual filesystems — no device argument needed */
-        if (strcmp(ktype, "tmpfs") == 0) {
-            fs_node_t* tmp = tmpfs_create_root();
-            if (!tmp) { sc_ret(regs) = (uint32_t)-ENOMEM; return; }
-            sc_ret(regs) = (uint32_t)vfs_mount_full(kmp, tmp, "tmpfs", kdev, mount_flags, NULL, NULL);
-            return;
-        }
-        if (strcmp(ktype, "devfs") == 0) {
-            extern fs_node_t* devfs_create_root(void);
-            fs_node_t* dev = devfs_create_root();
-            if (!dev) { sc_ret(regs) = (uint32_t)-ENOMEM; return; }
-            sc_ret(regs) = (uint32_t)vfs_mount_full(kmp, dev, "devfs", kdev, mount_flags, NULL, NULL);
-            return;
-        }
-        if (strcmp(ktype, "procfs") == 0) {
-            extern fs_node_t* procfs_create_root(void);
-            fs_node_t* proc = procfs_create_root();
-            if (!proc) { sc_ret(regs) = (uint32_t)-ENOMEM; return; }
-            sc_ret(regs) = (uint32_t)vfs_mount_full(kmp, proc, "procfs", kdev, mount_flags, NULL, NULL);
-            return;
-        }
-
         block_device_t* bdev = NULL;
         uint32_t lba = 0;
-        if (init_resolve_mount_device(kdev, &bdev, &lba) < 0) {
-            sc_ret(regs) = (uint32_t)-ENODEV;
-            return;
+        if (strcmp(ktype, "tmpfs") != 0 && strcmp(ktype, "devfs") != 0 && strcmp(ktype, "procfs") != 0) {
+            if (init_resolve_mount_device(kdev, &bdev, &lba) < 0) {
+                sc_ret(regs) = (uint32_t)-ENODEV;
+                return;
+            }
         }
 
         int rc = init_mount_fs(ktype, bdev, lba, kmp, mount_flags, kdev);