feat: fstat now handle symbolic link
[lunaix-os.git] / lunaix-os / kernel / fs / iso9660 / inode.c
index f88eee5e4d0cc684fe060adcdaee6ea4b3ca6a3a..ac151b32d10759697d05b06bdadcf0afc4c1dd5b 100644 (file)
@@ -1,9 +1,12 @@
 #include <klibc/string.h>
 #include <lunaix/fs.h>
 #include <lunaix/fs/iso9660.h>
+#include <lunaix/mm/cake.h>
 #include <lunaix/mm/valloc.h>
 #include <lunaix/spike.h>
 
+extern struct cake_pile* drec_cache_pile;
+
 static struct v_inode_ops iso_inode_ops = {
     .dir_lookup = iso9660_dir_lookup,
     .open = iso9660_open,
@@ -17,10 +20,27 @@ static struct v_file_ops iso_file_ops = { .close = iso9660_close,
                                           .seek = iso9660_seek,
                                           .readdir = iso9660_readdir };
 
+void
+iso9660_inode_destruct(struct v_inode* inode)
+{
+    struct iso_inode* isoino = inode->data;
+
+    struct iso_drecache *pos, *n;
+    llist_for_each(pos, n, &isoino->drecaches, caches)
+    {
+        cake_release(drec_cache_pile, pos);
+    }
+
+    vfree(isoino);
+}
+
 void
 iso9660_init_inode(struct v_superblock* vsb, struct v_inode* inode)
 {
-    inode->data = vzalloc(sizeof(struct iso_inode));
+    struct iso_inode* isoino = vzalloc(sizeof(struct iso_inode));
+    llist_init_head(&isoino->drecaches);
+    inode->data = isoino;
+    inode->destruct = iso9660_inode_destruct;
 }
 
 int
@@ -41,6 +61,7 @@ iso9660_fill_inode(struct v_inode* inode, struct iso_drecache* dir, int ino)
 
     inode->id = ino;
     inode->lb_addr = dir->extent_addr;
+    inode->lb_usage = ICEIL(dir->data_size, fu_len);
     inode->ops = &iso_inode_ops;
     inode->default_fops = &iso_file_ops;
 
@@ -56,19 +77,24 @@ iso9660_fill_inode(struct v_inode* inode, struct iso_drecache* dir, int ino)
     if (dir->xattr_len) {
         struct iso_xattr* xattr = (struct iso_xattr*)valloc(ISO9660_BLKSZ);
         // Only bring in single FU, as we only care about the attributes.
-        errno =
-          dev->read(dev, xattr, ISO9660_BLKSZ * inode->lb_addr, ISO9660_BLKSZ);
+        errno = dev->ops.read(
+          dev, xattr, ISO9660_BLKSZ * inode->lb_addr, ISO9660_BLKSZ);
         if (errno < 0) {
             return EIO;
         }
         isoino->record_fmt = xattr->record_fmt;
-        isoino->ctime = iso9660_dt2unix(&xattr->ctime);
-        isoino->mtime = iso9660_dt2unix(&xattr->mtime);
+
+        inode->ctime = iso9660_dt2unix(&xattr->ctime);
+        inode->mtime = iso9660_dt2unix(&xattr->mtime);
 
         inode->lb_addr += dir->xattr_len * dir->fu_size;
 
         vfree(xattr);
     }
 
+    inode->ctime = dir->ctime ? dir->ctime : inode->ctime;
+    inode->mtime = dir->mtime ? dir->mtime : inode->mtime;
+    inode->atime = dir->atime ? dir->atime : inode->atime;
+
     return 0;
 }
\ No newline at end of file