Merge branch 'iso-9660' into block-io
[lunaix-os.git] / lunaix-os / includes / lunaix / fs / iso9660.h
1 /**
2  * @file iso9660.h
3  * @author Lunaixsky (zelong56@gmail.com)
4  * @brief ISO9660 File system header file. (Reference: ECMA-119, 4th ed.)
5  * @version 0.1
6  * @date 2022-10-03
7  *
8  * @copyright Copyright (c) 2022
9  *
10  */
11
12 #ifndef __LUNAIX_ISO9660_H
13 #define __LUNAIX_ISO9660_H
14
15 #include <lunaix/types.h>
16
17 // Volume Types
18 #define ISO_VOLBOOT 0   // Boot Record
19 #define ISO_VOLPRIM 1   // Primary
20 #define ISO_VOLSUPP 2   // Supplementary
21 #define ISO_VOLPART 3   // Partition
22 #define ISO_VOLTERM 255 // Volume descriptor set terminator
23
24 #define ISO_FHIDDEN 0x1   // a hidden file
25 #define ISO_FDIR 0x2      // a directory file
26 #define ISO_FASSOC 0x4    // a associated file
27 #define ISO_FRECORD 0x8   // file store in iso record fashion
28 #define ISO_FPROTECT 0x10 // file being protected by access control
29 #define ISO_FEXTENTS 0x80 // the extent by this record is a file partial
30
31 // NOTES:
32 // Each Descriptor sized 1 logical block (2048 bytes in common cases)
33 // ISO9660 store number in both-byte order. That is, for a d-bits number, it
34 //   will result in 2d bits of storage. The lower d-bits are little-endian and
35 //   upper d-bits are big-endian.
36
37 struct iso_vol
38 {
39     u8_t type;
40     u8_t std_id[5]; // CD001
41     u8_t version;
42 } PACKED;
43
44 struct iso_vol_boot
45 {
46     struct iso_vol header;
47     u8_t sys_id[32];
48     u8_t boot_id[32];
49     u8_t reserved; // align to data line width
50 } PACKED;
51
52 struct iso_datetime
53 {
54     u8_t year[4];
55     u8_t month[2];
56     u8_t day[2];
57     u8_t hour[2];
58     u8_t min[2];
59     u8_t sec[2];
60     u8_t ms[2];
61     u8_t gmt;
62 } PACKED;
63
64 // (8.4) Describe a primary volume space
65 struct iso_vol_primary
66 {
67     struct iso_vol header;
68     u8_t reserved_1;
69     u8_t sys_id[32];
70     u8_t vol_id[32];
71     u8_t reserved_2;
72     u32_t sz_lo; // (8.4.8) only lower portion is valid.
73     u32_t sz_hi;
74     u8_t reserved_2;
75     u32_t set_size;
76     u32_t seq_num;
77     u32_t lb_size;
78     u32_t path_tbl_sz_lo; // lower partition - LE.
79     u32_t path_tbl_sz_hi;
80     u32_t lpath_tbl_ptr; // Type L Path table location (LBA)
81     u32_t reserved_3[3]; // use type M if big endian machine.
82     u8_t root_record[34];
83     u8_t set_id[128];
84     u8_t publisher_id[128];
85     u8_t preparer_id[128];
86     u8_t app_id[128];
87     u8_t copyright_id[128];
88     u8_t asbtract_id[128];
89     u8_t bib_id[128];
90     struct iso_datetime ctime;   // creation
91     struct iso_datetime mtime;   // modification
92     struct iso_datetime ex_time; // expiration
93     struct iso_datetime ef_time; // effective
94     u8_t fstruct_ver;            // file structure version, don't care!
95 } PACKED;                        // size 1124
96
97 // Layout for Supplementary Vol. is almost identical to primary vol.
98 // We ignore it for now. (see section 8.5, table 6)
99
100 // (8.6) Describe a volume partition within a volume space
101 struct iso_partition
102 {
103     struct iso_vol header;
104     u8_t reserved;
105     u8_t sys_id[32];
106     u8_t part_id[32];
107     u32_t part_addr_lo; // (8.6.7) only lower portion is valid.
108     u32_t part_addr_hi;
109     u32_t part_sz_lo; // (8.6.8) only lower portion is valid.
110     u32_t part_sz_hi;
111 } PACKED;
112
113 // (6.10.4) MDU with variable record
114 struct iso_var_mdu
115 {
116     u8_t len;
117     u8_t content[0];
118 } PACKED;
119
120 // (9.1) Directory Record [Embedded into Variable MDU]
121 struct iso_drecord
122 {
123     u8_t xattr_len;
124     u32_t extent_lo; // location of extent, lower 32 bits is valid.
125     u32_t extent_hi;
126     u32_t data_sz_lo; // size of extent, lower 32 bits is valid.
127     u32_t data_sz_hi;
128     struct
129     {
130         u8_t year;
131         u8_t month;
132         u8_t hour;
133         u8_t min;
134         u8_t sec;
135         u8_t gmt;
136     } PACKED mktime; // Time the record is made, see 9.1.5
137     u8_t flags;
138     u8_t fu_sz;  // size of file unit (FU)
139     u8_t gap_sz; // size of gap if FU is interleaved.
140     u32_t vol_seq;
141     struct iso_var_mdu name;
142 } PACKED;
143
144 // (9.4) Path Table Record. [Embedded into Variable MDU]
145 struct iso_precord
146 {
147     u8_t xattr_len;
148     u32_t extent_addr;
149     u8_t parent; // indexed into path table
150     u8_t id[0];  // length = iso_var_mdu::len
151 } PACKED;
152
153 struct iso_xattr
154 {
155     u32_t owner;
156     u32_t group;
157     u16_t perm;
158     struct iso_datetime ctime;
159     struct iso_datetime mtime;
160     struct iso_datetime ex_time;
161     struct iso_datetime ef_time;
162     u8_t record_fmt;
163     u8_t record_attr;
164     u8_t record_len;
165     u32_t sys_id;
166     u8_t reserved1[64];
167     u8_t version;
168     u8_t len_esc;
169     u8_t reserved2[64];
170     u32_t payload_sz;
171     u8_t payload[0];
172     // There is also a escape sequence after payload,
173     // It however marked as optional, hence we ignore it.
174 } PACKED;
175
176 #endif /* __LUNAIX_ISO9660_H */