feat: kprintf now goes into dedicated pseudo-dev rather than flooding the framebuffer
[lunaix-os.git] / lunaix-os / kernel / fs / mount.c
index ca8023805fc19435d1b6c61294721e007abf3356..97ef359f40351c22acb2f8937bc27f82cd3c37b0 100644 (file)
@@ -3,8 +3,12 @@
 #include <lunaix/mm/valloc.h>
 #include <lunaix/process.h>
 #include <lunaix/spike.h>
+#include <lunaix/syscall_utils.h>
+#include <lunaix/syslog.h>
 #include <lunaix/types.h>
 
+LOG_MODULE("fs")
+
 struct llist_header all_mnts = { .next = &all_mnts, .prev = &all_mnts };
 
 struct v_mount*
@@ -129,7 +133,11 @@ vfs_mount_at(const char* fs_name,
              struct v_dnode* mnt_point,
              int options)
 {
-    if (mnt_point->inode && !(mnt_point->inode->itype & VFS_IFDIR)) {
+    if (device && device->dev_type != DEV_IFVOL) {
+        return ENOTBLK;
+    }
+
+    if (mnt_point->inode && (mnt_point->inode->itype & F_MFILE)) {
         return ENOTDIR;
     }
 
@@ -138,11 +146,20 @@ vfs_mount_at(const char* fs_name,
         return ENODEV;
     }
 
+    if (fs->types == FSTYPE_ROFS) {
+        options |= MNT_RO;
+    }
+
+    char* dev_name = "sys";
     struct v_mount* parent_mnt = mnt_point->mnt;
     struct v_superblock *sb = vfs_sb_alloc(), *old_sb = mnt_point->super_block;
     sb->dev = device;
     mnt_point->super_block = sb;
 
+    if (device) {
+        dev_name = device->name_val;
+    }
+
     int errno = 0;
     if (!(errno = fs->mount(sb, mnt_point))) {
         sb->fs = fs;
@@ -153,6 +170,8 @@ vfs_mount_at(const char* fs_name,
             goto cleanup;
         }
 
+        kprintf("mount: dev=%s, fs=%s, mode=%d", dev_name, fs_name, options);
+
         mnt_point->mnt->flags = options;
     } else {
         goto cleanup;
@@ -161,6 +180,11 @@ vfs_mount_at(const char* fs_name,
     return errno;
 
 cleanup:
+    kprintf(KERROR "mount: dev=%s, fs=%s, mode=%d, err=%d",
+            dev_name,
+            fs_name,
+            options,
+            errno);
     mnt_point->super_block = old_sb;
     vfs_sb_free(sb);
     return errno;