1 #include <klibc/string.h>
3 #include <lunaix/fs/iso9660.h>
4 #include <lunaix/mm/cake.h>
5 #include <lunaix/mm/valloc.h>
6 #include <lunaix/spike.h>
8 extern struct cake_pile* drec_cache_pile;
10 static struct v_inode_ops iso_inode_ops = {
11 .dir_lookup = iso9660_dir_lookup,
15 static struct v_file_ops iso_file_ops = { .close = iso9660_close,
17 .read_page = iso9660_read,
18 .write = iso9660_write,
19 .write_page = iso9660_write,
21 .readdir = iso9660_readdir };
24 iso9660_inode_destruct(struct v_inode* inode)
26 struct iso_inode* isoino = inode->data;
28 struct iso_drecache *pos, *n;
29 llist_for_each(pos, n, &isoino->drecaches, caches)
31 cake_release(drec_cache_pile, pos);
38 iso9660_init_inode(struct v_superblock* vsb, struct v_inode* inode)
40 struct iso_inode* isoino = vzalloc(sizeof(struct iso_inode));
41 llist_init_head(&isoino->drecaches);
43 inode->destruct = iso9660_inode_destruct;
47 iso9660_fill_inode(struct v_inode* inode, struct iso_drecache* dir, int ino)
50 struct device* dev = inode->sb->dev;
51 struct iso_inode* isoino = (struct iso_inode*)inode->data;
53 // In the spec, there is a differentiation in how file section organized
54 // between interleaving and non-interleaving mode. To simplify this, we
55 // treat the non-interleaving as an interleaving with gap size = 0 and fu
57 isoino->fu_size = dir->fu_size;
58 isoino->gap_size = dir->gap_size;
60 u32_t fu_len = isoino->fu_size * ISO9660_BLKSZ;
63 inode->lb_addr = dir->extent_addr;
64 inode->ops = &iso_inode_ops;
65 inode->default_fops = &iso_file_ops;
67 // xattr_len is in unit of FU. Each FU comprise <fu_sz> block(s).
68 inode->fsize = dir->data_size - dir->xattr_len * fu_len;
70 if ((dir->flags & ISO_FDIR)) {
71 inode->itype = VFS_IFDIR;
73 inode->itype = VFS_IFFILE;
77 struct iso_xattr* xattr = (struct iso_xattr*)valloc(ISO9660_BLKSZ);
78 // Only bring in single FU, as we only care about the attributes.
80 dev->read(dev, xattr, ISO9660_BLKSZ * inode->lb_addr, ISO9660_BLKSZ);
84 isoino->record_fmt = xattr->record_fmt;
86 inode->ctime = iso9660_dt2unix(&xattr->ctime);
87 inode->mtime = iso9660_dt2unix(&xattr->mtime);
89 inode->lb_addr += dir->xattr_len * dir->fu_size;
94 inode->ctime = dir->ctime ? dir->ctime : inode->ctime;
95 inode->mtime = dir->mtime ? dir->mtime : inode->mtime;
96 inode->atime = dir->atime ? dir->atime : inode->atime;