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/fs.h>
18 #include <lunaix/types.h>
20 #define ISO_SIGNATURE_LO 0x30304443UL
21 #define ISO_SIGNATURE_HI 0x31
24 #define ISO_VOLBOOT 0 // Boot Record
25 #define ISO_VOLPRIM 1 // Primary
26 #define ISO_VOLSUPP 2 // Supplementary
27 #define ISO_VOLPART 3 // Partition
28 #define ISO_VOLTERM 255 // Volume descriptor set terminator
30 #define ISO_FHIDDEN 0x1 // a hidden file
31 #define ISO_FDIR 0x2 // a directory file
32 #define ISO_FASSOC 0x4 // a associated file
33 #define ISO_FRECORD 0x8 // file store in iso record fashion
34 #define ISO_FPROTECT 0x10 // file being protected by access control
35 #define ISO_FEXTENTS 0x80 // the extent by this record is a file partial
37 #define ISO9660_BLKSZ 2048
38 #define ISO9660_IDLEN 256
41 // Each Descriptor sized 1 logical block (2048 bytes in common cases)
42 // ISO9660 store number in both-byte order. That is, for a d-bits number, it
43 // will result in 2d bits of storage. The lower d-bits are little-endian and
44 // upper d-bits are big-endian.
49 u8_t std_id[5]; // CD001
55 struct iso_vol header;
58 u8_t reserved; // align to data line width
73 // 32bits both-byte-order integer
74 typedef struct iso_bbo32
76 u32_t le; // little-endian
77 u32_t be; // big-endian
80 // 16bits both-byte-order integer
81 typedef struct iso_bbo16
83 u16_t le; // little-endian
84 u16_t be; // big-endian
87 // (8.4) Describe a primary volume space
88 struct iso_vol_primary
90 struct iso_vol header;
100 iso_bbo32_t ptable_size;
101 u32_t lpath_tbl_ptr; // Type L Path table location (LBA)
102 u32_t reserved_4[3]; // use type M if big endian machine.
103 u8_t root_record[34];
105 u8_t publisher_id[128];
106 u8_t preparer_id[128];
108 u8_t copyright_id[128];
109 u8_t asbtract_id[128];
111 struct iso_datetime ctime; // creation
112 struct iso_datetime mtime; // modification
113 struct iso_datetime ex_time; // expiration
114 struct iso_datetime ef_time; // effective
115 u8_t fstruct_ver; // file structure version, don't care!
116 } PACKED; // size 1124
118 // Layout for Supplementary Vol. is almost identical to primary vol.
119 // We ignore it for now. (see section 8.5, table 6)
121 // (8.6) Describe a volume partition within a volume space
124 struct iso_vol header;
128 iso_bbo32_t part_addr;
129 iso_bbo32_t part_size;
132 // (6.10.4) MDU with variable record
150 // (9.1) Directory Record [Embedded into Variable MDU]
154 iso_bbo32_t extent_addr;
155 iso_bbo32_t data_size;
156 struct iso_datetime2 PACKED mktime; // Time the record is made, see 9.1.5
158 u8_t fu_sz; // size of file unit (FU)
159 u8_t gap_sz; // size of gap if FU is interleaved.
161 struct iso_var_mdu name;
169 struct iso_datetime ctime;
170 struct iso_datetime mtime;
171 struct iso_datetime ex_time;
172 struct iso_datetime ef_time;
175 iso_bbo16_t record_len;
181 iso_bbo16_t payload_sz;
183 // There is also a escape sequence after payload,
184 // It however marked as optional, hence we ignore it.
188 /// -------- IEEE P1281 SUSP ---------
191 #define ISOSU_ER 0x5245
192 #define ISOSU_ST 0x5453
203 struct isosu_base header;
212 /// -------- Rock Ridge Extension --------
215 #define ISORR_PX 0x5850
216 #define ISORR_PN 0x4e50
217 #define ISORR_SL 0x4c53
218 #define ISORR_NM 0x4d4e
219 #define ISORR_TF 0x4654
221 #define ISORR_NM_CONT 0x1
223 #define ISORR_TF_CTIME 0x1
224 #define ISORR_TF_MTIME 0x2
225 #define ISORR_TF_ATIME 0x4
226 #define ISORR_TF_LONG_FORM 0x80
230 struct isosu_base header;
240 struct isosu_base header;
247 struct isosu_base header;
254 struct isosu_base header;
261 struct isosu_base header;
267 /// -------- VFS integration ---------
275 struct llist_header drecaches;
280 struct llist_header caches;
292 char name_val[ISO9660_IDLEN];
295 struct iso_superblock
302 iso9660_get_drecord(struct iso_var_mdu* drecord_mdu);
305 iso9660_fill_inode(struct v_inode* inode, struct iso_drecache* dir, int ino);
308 iso9660_dt2unix(struct iso_datetime* isodt);
311 iso9660_dt22unix(struct iso_datetime2* isodt2);
317 iso9660_setup_dnode(struct v_dnode* dnode, struct v_inode* inode);
320 iso9660_fill_drecache(struct iso_drecache* cache,
321 struct iso_drecord* drec,
325 iso9660_dir_lookup(struct v_inode* this, struct v_dnode* dnode);
328 iso9660_readdir(struct v_file* file, struct dir_context* dctx);
331 iso9660_open(struct v_inode* this, struct v_file* file);
334 iso9660_close(struct v_file* file);
337 iso9660_read(struct v_inode* inode, void* buffer, size_t len, size_t fpos);
340 iso9660_write(struct v_inode* inode, void* buffer, size_t len, size_t fpos);
343 iso9660_seek(struct v_inode* inode, size_t offset);
346 isorr_parse_px(struct iso_drecache* cache, void* px_start);
349 isorr_parse_nm(struct iso_drecache* cache, void* nm_start);
352 isorr_parse_tf(struct iso_drecache* cache, void* tf_start);
354 #endif /* __LUNAIX_ISO9660_H */