From: Minep Date: Sun, 13 Nov 2022 23:42:08 +0000 (+0000) Subject: feat: (iso9660) finishing up unmount X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/commitdiff_plain/f4c2f90eddf42f1cc73a2a12ff1435cd4357fa60?ds=sidebyside feat: (iso9660) finishing up unmount fix: (vfs) no need to do sync when inode getting evicted --- diff --git a/lunaix-os/includes/lunaix/fs.h b/lunaix-os/includes/lunaix/fs.h index 8e6961d..5a5cb79 100644 --- a/lunaix-os/includes/lunaix/fs.h +++ b/lunaix-os/includes/lunaix/fs.h @@ -218,6 +218,8 @@ struct v_inode struct pcache* pg_cache; struct v_inode_ops* ops; struct v_file_ops* default_fops; + + void (*destruct)(struct v_inode* inode); }; struct v_mount diff --git a/lunaix-os/includes/lunaix/fs/iso9660.h b/lunaix-os/includes/lunaix/fs/iso9660.h index 9d16961..3392af3 100644 --- a/lunaix-os/includes/lunaix/fs/iso9660.h +++ b/lunaix-os/includes/lunaix/fs/iso9660.h @@ -272,7 +272,7 @@ struct iso_inode u32_t record_fmt; u32_t fu_size; u32_t gap_size; - struct llist_header* drecaches; + struct llist_header drecaches; }; struct iso_drecache diff --git a/lunaix-os/kernel/fs/iso9660/directory.c b/lunaix-os/kernel/fs/iso9660/directory.c index e1b3789..c3150dc 100644 --- a/lunaix-os/kernel/fs/iso9660/directory.c +++ b/lunaix-os/kernel/fs/iso9660/directory.c @@ -68,16 +68,19 @@ iso9660_setup_dnode(struct v_dnode* dnode, struct v_inode* inode) return 0; } + struct iso_inode* isoino = inode->data; + if (!llist_empty(&isoino->drecaches)) { + dnode->data = &isoino->drecaches; + vfs_assign_inode(dnode, inode); + return 0; + } + int errno = 0; struct device* dev = dnode->super_block->dev; - struct iso_inode* isoino = inode->data; - struct llist_header* lead = valloc(sizeof(*lead)); void* records = valloc(ISO9660_BLKSZ); u32_t current_pos = -ISO9660_BLKSZ, max_pos = inode->fsize, blk = inode->lb_addr * ISO9660_BLKSZ, blk_offset = (u32_t)-1; - llist_init_head(lead); - // As per 6.8.1, Directory structure shall NOT recorded in interleave mode. do { if (blk_offset >= ISO9660_BLKSZ - sizeof(struct iso_drecord)) { @@ -105,13 +108,12 @@ iso9660_setup_dnode(struct v_dnode* dnode, struct v_inode* inode) struct iso_drecache* cache = cake_grab(drec_cache_pile); iso9660_fill_drecache(cache, drec, mdu->len); - llist_append(lead, &cache->caches); + llist_append(&isoino->drecaches, &cache->caches); cont: blk_offset += mdu->len; } while (current_pos + blk_offset < max_pos); - dnode->data = lead; - isoino->drecaches = lead; + dnode->data = &isoino->drecaches; vfs_assign_inode(dnode, inode); @@ -126,10 +128,9 @@ int iso9660_dir_lookup(struct v_inode* this, struct v_dnode* dnode) { struct iso_inode* isoino = this->data; - struct llist_header* lead = isoino->drecaches; struct iso_drecache *pos, *n; - llist_for_each(pos, n, lead, caches) + llist_for_each(pos, n, &isoino->drecaches, caches) { if (HSTR_EQ(&dnode->name, &pos->name)) { goto found; diff --git a/lunaix-os/kernel/fs/iso9660/inode.c b/lunaix-os/kernel/fs/iso9660/inode.c index e564910..fa3337b 100644 --- a/lunaix-os/kernel/fs/iso9660/inode.c +++ b/lunaix-os/kernel/fs/iso9660/inode.c @@ -1,9 +1,12 @@ #include #include #include +#include #include #include +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 diff --git a/lunaix-os/kernel/fs/iso9660/mount.c b/lunaix-os/kernel/fs/iso9660/mount.c index 5d7fdc9..35ebb4b 100644 --- a/lunaix-os/kernel/fs/iso9660/mount.c +++ b/lunaix-os/kernel/fs/iso9660/mount.c @@ -92,7 +92,7 @@ done: int iso9660_unmount(struct v_superblock* vsb) { - // TODO clean up + vfree(vsb->data); } void diff --git a/lunaix-os/kernel/fs/vfs.c b/lunaix-os/kernel/fs/vfs.c index cc751b6..eff233a 100644 --- a/lunaix-os/kernel/fs/vfs.c +++ b/lunaix-os/kernel/fs/vfs.c @@ -500,7 +500,12 @@ vfs_i_free(struct v_inode* inode) pcache_release(inode->pg_cache); vfree(inode->pg_cache); } - inode->ops->sync(inode); + // we don't need to sync inode. + // If an inode can be free, then it must be properly closed. + // Hence it must be synced already! + if (inode->destruct) { + inode->destruct(inode); + } hlist_delete(&inode->hash_list); cake_release(inode_pile, inode); }