3 * @author Lunaixsky (zelong56@gmail.com)
4 * @brief ISO9660 File system header file. (Reference: ECMA-119, 4th ed.)
8 * @copyright Copyright (c) 2022
12 #ifndef __LUNAIX_ISO9660_H
13 #define __LUNAIX_ISO9660_H
15 #include <lunaix/clock.h>
16 #include <lunaix/device.h>
17 #include <lunaix/types.h>
19 #define ISO_SIGNATURE_LO 0x30304443UL
20 #define ISO_SIGNATURE_HI 0x31
23 #define ISO_VOLBOOT 0 // Boot Record
24 #define ISO_VOLPRIM 1 // Primary
25 #define ISO_VOLSUPP 2 // Supplementary
26 #define ISO_VOLPART 3 // Partition
27 #define ISO_VOLTERM 255 // Volume descriptor set terminator
29 #define ISO_FHIDDEN 0x1 // a hidden file
30 #define ISO_FDIR 0x2 // a directory file
31 #define ISO_FASSOC 0x4 // a associated file
32 #define ISO_FRECORD 0x8 // file store in iso record fashion
33 #define ISO_FPROTECT 0x10 // file being protected by access control
34 #define ISO_FEXTENTS 0x80 // the extent by this record is a file partial
36 #define ISO9660_BLKSZ 2048
37 #define ISO9660_IDLEN 256
40 // Each Descriptor sized 1 logical block (2048 bytes in common cases)
41 // ISO9660 store number in both-byte order. That is, for a d-bits number, it
42 // will result in 2d bits of storage. The lower d-bits are little-endian and
43 // upper d-bits are big-endian.
48 u8_t std_id[5]; // CD001
54 struct iso_vol header;
57 u8_t reserved; // align to data line width
72 // 32bits both-byte-order integer
73 typedef struct iso_bbo32
75 u32_t le; // little-endian
76 u32_t be; // big-endian
79 // 16bits both-byte-order integer
80 typedef struct iso_bbo16
82 u16_t le; // little-endian
83 u16_t be; // big-endian
86 // (8.4) Describe a primary volume space
87 struct iso_vol_primary
89 struct iso_vol header;
99 iso_bbo32_t ptable_size;
100 u32_t lpath_tbl_ptr; // Type L Path table location (LBA)
101 u32_t reserved_4[3]; // use type M if big endian machine.
102 u8_t root_record[34];
104 u8_t publisher_id[128];
105 u8_t preparer_id[128];
107 u8_t copyright_id[128];
108 u8_t asbtract_id[128];
110 struct iso_datetime ctime; // creation
111 struct iso_datetime mtime; // modification
112 struct iso_datetime ex_time; // expiration
113 struct iso_datetime ef_time; // effective
114 u8_t fstruct_ver; // file structure version, don't care!
115 } PACKED; // size 1124
117 // Layout for Supplementary Vol. is almost identical to primary vol.
118 // We ignore it for now. (see section 8.5, table 6)
120 // (8.6) Describe a volume partition within a volume space
123 struct iso_vol header;
127 iso_bbo32_t part_addr;
128 iso_bbo32_t part_size;
131 // (6.10.4) MDU with variable record
138 // (9.1) Directory Record [Embedded into Variable MDU]
142 iso_bbo32_t extent_addr;
143 iso_bbo32_t data_size;
153 } PACKED mktime; // Time the record is made, see 9.1.5
155 u8_t fu_sz; // size of file unit (FU)
156 u8_t gap_sz; // size of gap if FU is interleaved.
158 struct iso_var_mdu name;
161 // (9.4) L-Path Table Record. [Embedded into Variable MDU]
166 u8_t parent; // indexed into path table
167 u8_t id[0]; // length = iso_var_mdu::len
175 struct iso_datetime ctime;
176 struct iso_datetime mtime;
177 struct iso_datetime ex_time;
178 struct iso_datetime ef_time;
181 iso_bbo16_t record_len;
187 iso_bbo16_t payload_sz;
189 // There is also a escape sequence after payload,
190 // It however marked as optional, hence we ignore it.
210 struct llist_header* drecaches;
215 struct llist_header caches;
223 char name_val[ISO9660_IDLEN];
226 struct iso_superblock
233 iso9660_get_drecord(struct iso_var_mdu* drecord_mdu);
236 iso9660_fill_inode(struct v_inode* inode, struct iso_drecache* dir, int ino);
239 iso9660_dt2unix(struct iso_datetime* isodt);
245 iso9660_setup_dnode(struct v_dnode* dnode, struct v_inode* inode);
248 iso9660_fill_drecache(struct iso_drecache* cache, struct iso_drecord* drec);
251 iso9660_dir_lookup(struct v_inode* this, struct v_dnode* dnode);
254 iso9660_readdir(struct v_file* file, struct dir_context* dctx);
257 iso9660_open(struct v_inode* this, struct v_file* file);
260 iso9660_close(struct v_file* file);
263 iso9660_read(struct v_inode* inode, void* buffer, size_t len, size_t fpos);
266 iso9660_write(struct v_inode* inode, void* buffer, size_t len, size_t fpos);
269 iso9660_seek(struct v_inode* inode, size_t offset);
271 #endif /* __LUNAIX_ISO9660_H */