fix: dnode cache syncing for pseudo fs
[lunaix-os.git] / lunaix-os / kernel / device / devfs.c
index ac674b4ac77ebb4e5f4b5cee6f1b4794c2c92ad0..012f9190f7b1b54433eba624adf4fca4987dd07a 100644 (file)
@@ -1,4 +1,5 @@
 #include <lunaix/device.h>
+#include <lunaix/dirent.h>
 #include <lunaix/fs.h>
 #include <lunaix/fs/devfs.h>
 #include <lunaix/spike.h>
@@ -49,6 +50,18 @@ devfs_get_itype(struct device* dev)
     return itype;
 }
 
+int
+devfs_get_dtype(struct device* dev)
+{
+    switch (dev->dev_type & DEV_MSKIF) {
+        case DEV_IFCAT:
+            return DT_DIR;
+
+        default:
+            return DT_FILE;
+    }
+}
+
 int
 devfs_mknod(struct v_dnode* dnode, struct device* dev)
 {
@@ -74,7 +87,8 @@ devfs_mknod(struct v_dnode* dnode, struct device* dev)
 int
 devfs_dirlookup(struct v_inode* this, struct v_dnode* dnode)
 {
-    struct device* dev = device_getbyhname(this->data, &dnode->name);
+    struct device* dev =
+      device_getbyhname((struct device*)this->data, &dnode->name);
     if (!dev) {
         return ENOENT;
     }
@@ -84,14 +98,13 @@ devfs_dirlookup(struct v_inode* this, struct v_dnode* dnode)
 int
 devfs_readdir(struct v_file* file, struct dir_context* dctx)
 {
-    struct device* holder = (struct device*)(file->inode->data);
     struct device* dev =
-      device_getbyoffset(holder ? &holder->children : NULL, dctx->index);
+      device_getbyoffset((struct device*)(file->inode->data), dctx->index);
     if (!dev) {
         return 0;
     }
     dctx->read_complete_callback(
-      dctx, dev->name.value, dev->name.len, devfs_get_itype(dev));
+      dctx, dev->name.value, dev->name.len, devfs_get_dtype(dev));
     return 1;
 }