1 #include <klibc/string.h>
2 #include <lunaix/fs/api.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_page,
18 .write = iso9660_write,
19 .write_page = iso9660_write_page,
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->lb_usage = ICEIL(dir->data_size, fu_len);
65 inode->ops = &iso_inode_ops;
66 inode->default_fops = &iso_file_ops;
68 // xattr_len is in unit of FU. Each FU comprise <fu_sz> block(s).
69 inode->fsize = dir->data_size - dir->xattr_len * fu_len;
71 if ((dir->flags & ISO_FDIR)) {
72 inode->itype = VFS_IFDIR;
74 inode->itype = VFS_IFFILE;
78 struct iso_xattr* xattr = (struct iso_xattr*)valloc(ISO9660_BLKSZ);
79 // Only bring in single FU, as we only care about the attributes.
80 errno = dev->ops.read(
81 dev, xattr, ISO9660_BLKSZ * inode->lb_addr, ISO9660_BLKSZ);
85 isoino->record_fmt = xattr->record_fmt;
87 inode->ctime = iso9660_dt2unix(&xattr->ctime);
88 inode->mtime = iso9660_dt2unix(&xattr->mtime);
90 fsapi_inode_setaccess(inode, xattr->perm);
91 fsapi_inode_setowner(inode, xattr->owner.le, xattr->group.le);
93 inode->lb_addr += dir->xattr_len * dir->fu_size;
98 fsapi_inode_setaccess(inode, FSACL_u(R, W, _) | FSACL_g(R, W, _));
99 fsapi_inode_setowner(inode, 0, 0);
102 inode->ctime = dir->ctime ? dir->ctime : inode->ctime;
103 inode->mtime = dir->mtime ? dir->mtime : inode->mtime;
104 inode->atime = dir->atime ? dir->atime : inode->atime;