FAT big endian changes
[coreboot.git] / src / include / fs / iso9660.h
1 #ifndef _ISO9660_H
2 #define _ISO9660_H
3
4 /*
5  * The isofs filesystem constants/structures
6  */
7
8 /* This part borrowed from the bsd386 isofs */
9 #define ISODCL(from, to) (to - from + 1)
10
11 struct iso_volume_descriptor {
12         char type[ISODCL(1,1)]; /* 711 */
13         char id[ISODCL(2,6)];
14         char version[ISODCL(7,7)];
15         char data[ISODCL(8,2048)];
16 };
17
18 #define ISO_SECTOR_BITS              (11)
19 #define ISO_SECTOR_SIZE              (1<<ISO_SECTOR_BITS)
20
21 #define ISO_REGULAR     1       /* regular file */
22 #define ISO_DIRECTORY   2       /* directory    */
23 #define ISO_OTHER       0       /* other file (with Rock Ridge) */
24
25 #define RR_FLAG_PX      0x01    /* have POSIX file attributes */
26 #define RR_FLAG_NM      0x08    /* have alternate file name   */
27
28 /* POSIX file attributes for Rock Ridge extensions */
29 #define POSIX_S_IFMT    0xF000
30 #define POSIX_S_IFREG   0x8000
31 #define POSIX_S_IFDIR   0x4000
32
33 /* volume descriptor types */
34 #define ISO_VD_PRIMARY 1
35 #define ISO_VD_SUPPLEMENTARY 2
36 #define ISO_VD_END 255
37
38 #define ISO_STANDARD_ID "CD001"
39
40 struct iso_primary_descriptor {
41         char type                       [ISODCL (  1,   1)]; /* 711 */
42         char id                         [ISODCL (  2,   6)];
43         char version                    [ISODCL (  7,   7)]; /* 711 */
44         char unused1                    [ISODCL (  8,   8)];
45         char system_id                  [ISODCL (  9,  40)]; /* achars */
46         char volume_id                  [ISODCL ( 41,  72)]; /* dchars */
47         char unused2                    [ISODCL ( 73,  80)];
48         char volume_space_size          [ISODCL ( 81,  88)]; /* 733 */
49         char unused3                    [ISODCL ( 89, 120)];
50         char volume_set_size            [ISODCL (121, 124)]; /* 723 */
51         char volume_sequence_number     [ISODCL (125, 128)]; /* 723 */
52         char logical_block_size         [ISODCL (129, 132)]; /* 723 */
53         char path_table_size            [ISODCL (133, 140)]; /* 733 */
54         char type_l_path_table          [ISODCL (141, 144)]; /* 731 */
55         char opt_type_l_path_table      [ISODCL (145, 148)]; /* 731 */
56         char type_m_path_table          [ISODCL (149, 152)]; /* 732 */
57         char opt_type_m_path_table      [ISODCL (153, 156)]; /* 732 */
58         char root_directory_record      [ISODCL (157, 190)]; /* 9.1 */
59         char volume_set_id              [ISODCL (191, 318)]; /* dchars */
60         char publisher_id               [ISODCL (319, 446)]; /* achars */
61         char preparer_id                [ISODCL (447, 574)]; /* achars */
62         char application_id             [ISODCL (575, 702)]; /* achars */
63         char copyright_file_id          [ISODCL (703, 739)]; /* 7.5 dchars */
64         char abstract_file_id           [ISODCL (740, 776)]; /* 7.5 dchars */
65         char bibliographic_file_id      [ISODCL (777, 813)]; /* 7.5 dchars */
66         char creation_date              [ISODCL (814, 830)]; /* 8.4.26.1 */
67         char modification_date          [ISODCL (831, 847)]; /* 8.4.26.1 */
68         char expiration_date            [ISODCL (848, 864)]; /* 8.4.26.1 */
69         char effective_date             [ISODCL (865, 881)]; /* 8.4.26.1 */
70         char file_structure_version     [ISODCL (882, 882)]; /* 711 */
71         char unused4                    [ISODCL (883, 883)];
72         char application_data           [ISODCL (884, 1395)];
73         char unused5                    [ISODCL (1396, 2048)];
74 };
75
76 /* Almost the same as the primary descriptor but two fields are specified */
77 struct iso_supplementary_descriptor {
78         char type                       [ISODCL (  1,   1)]; /* 711 */
79         char id                         [ISODCL (  2,   6)];
80         char version                    [ISODCL (  7,   7)]; /* 711 */
81         char flags                      [ISODCL (  8,   8)]; /* 853 */
82         char system_id                  [ISODCL (  9,  40)]; /* achars */
83         char volume_id                  [ISODCL ( 41,  72)]; /* dchars */
84         char unused2                    [ISODCL ( 73,  80)];
85         char volume_space_size          [ISODCL ( 81,  88)]; /* 733 */
86         char escape                     [ISODCL ( 89, 120)]; /* 856 */
87         char volume_set_size            [ISODCL (121, 124)]; /* 723 */
88         char volume_sequence_number     [ISODCL (125, 128)]; /* 723 */
89         char logical_block_size         [ISODCL (129, 132)]; /* 723 */
90         char path_table_size            [ISODCL (133, 140)]; /* 733 */
91         char type_l_path_table          [ISODCL (141, 144)]; /* 731 */
92         char opt_type_l_path_table      [ISODCL (145, 148)]; /* 731 */
93         char type_m_path_table          [ISODCL (149, 152)]; /* 732 */
94         char opt_type_m_path_table      [ISODCL (153, 156)]; /* 732 */
95         char root_directory_record      [ISODCL (157, 190)]; /* 9.1 */
96         char volume_set_id              [ISODCL (191, 318)]; /* dchars */
97         char publisher_id               [ISODCL (319, 446)]; /* achars */
98         char preparer_id                [ISODCL (447, 574)]; /* achars */
99         char application_id             [ISODCL (575, 702)]; /* achars */
100         char copyright_file_id          [ISODCL (703, 739)]; /* 7.5 dchars */
101         char abstract_file_id           [ISODCL (740, 776)]; /* 7.5 dchars */
102         char bibliographic_file_id      [ISODCL (777, 813)]; /* 7.5 dchars */
103         char creation_date              [ISODCL (814, 830)]; /* 8.4.26.1 */
104         char modification_date          [ISODCL (831, 847)]; /* 8.4.26.1 */
105         char expiration_date            [ISODCL (848, 864)]; /* 8.4.26.1 */
106         char effective_date             [ISODCL (865, 881)]; /* 8.4.26.1 */
107         char file_structure_version     [ISODCL (882, 882)]; /* 711 */
108         char unused4                    [ISODCL (883, 883)];
109         char application_data           [ISODCL (884, 1395)];
110         char unused5                    [ISODCL (1396, 2048)];
111 };
112
113
114 #define HS_STANDARD_ID "CDROM"
115
116 struct  hs_volume_descriptor {
117         char foo                        [ISODCL (  1,   8)]; /* 733 */
118         char type                       [ISODCL (  9,   9)]; /* 711 */
119         char id                         [ISODCL ( 10,  14)];
120         char version                    [ISODCL ( 15,  15)]; /* 711 */
121         char data[ISODCL(16,2048)];
122 };
123
124
125 struct hs_primary_descriptor {
126         char foo                        [ISODCL (  1,   8)]; /* 733 */
127         char type                       [ISODCL (  9,   9)]; /* 711 */
128         char id                         [ISODCL ( 10,  14)];
129         char version                    [ISODCL ( 15,  15)]; /* 711 */
130         char unused1                    [ISODCL ( 16,  16)]; /* 711 */
131         char system_id                  [ISODCL ( 17,  48)]; /* achars */
132         char volume_id                  [ISODCL ( 49,  80)]; /* dchars */
133         char unused2                    [ISODCL ( 81,  88)]; /* 733 */
134         char volume_space_size          [ISODCL ( 89,  96)]; /* 733 */
135         char unused3                    [ISODCL ( 97, 128)]; /* 733 */
136         char volume_set_size            [ISODCL (129, 132)]; /* 723 */
137         char volume_sequence_number     [ISODCL (133, 136)]; /* 723 */
138         char logical_block_size         [ISODCL (137, 140)]; /* 723 */
139         char path_table_size            [ISODCL (141, 148)]; /* 733 */
140         char type_l_path_table          [ISODCL (149, 152)]; /* 731 */
141         char unused4                    [ISODCL (153, 180)]; /* 733 */
142         char root_directory_record      [ISODCL (181, 214)]; /* 9.1 */
143 };
144
145 /* We use this to help us look up the parent inode numbers. */
146
147 struct iso_path_table{
148         unsigned char  name_len[2];     /* 721 */
149         char extent[4];         /* 731 */
150         char  parent[2];        /* 721 */
151         char name[0];
152 } __attribute__((packed));
153
154 /* high sierra is identical to iso, except that the date is only 6 bytes, and
155    there is an extra reserved byte after the flags */
156
157 struct iso_directory_record {
158         char length                     [ISODCL (1, 1)]; /* 711 */
159         char ext_attr_length            [ISODCL (2, 2)]; /* 711 */
160         char extent                     [ISODCL (3, 10)]; /* 733 */
161         char size                       [ISODCL (11, 18)]; /* 733 */
162         char date                       [ISODCL (19, 25)]; /* 7 by 711 */
163         char flags                      [ISODCL (26, 26)];
164         char file_unit_size             [ISODCL (27, 27)]; /* 711 */
165         char interleave                 [ISODCL (28, 28)]; /* 711 */
166         char volume_sequence_number     [ISODCL (29, 32)]; /* 723 */
167         unsigned char name_len          [ISODCL (33, 33)]; /* 711 */
168         char name                       [0];
169 } __attribute__((packed));
170
171 struct SU_SP{
172   unsigned char magic[2];
173   unsigned char skip;
174 } __attribute__((packed));
175
176 struct SU_CE{
177   char extent[8];
178   char offset[8];
179   char size[8];
180 };
181
182 struct SU_ER{
183   unsigned char len_id;
184   unsigned char len_des;
185   unsigned char len_src;
186   unsigned char ext_ver;
187   char data[0];
188 } __attribute__((packed));
189
190 struct RR_RR{
191   char flags[1];
192 } __attribute__((packed));
193
194 struct RR_PX{
195   char mode[8];
196   char n_links[8];
197   char uid[8];
198   char gid[8];
199 };
200
201 struct RR_PN{
202   char dev_high[8];
203   char dev_low[8];
204 };
205
206
207 struct SL_component{
208   unsigned char flags;
209   unsigned char len;
210   char text[0];
211 } __attribute__((packed));
212
213 struct RR_SL{
214   unsigned char flags;
215   struct SL_component link;
216 } __attribute__((packed));
217
218 struct RR_NM{
219   unsigned char flags;
220   char name[0];
221 } __attribute__((packed));
222
223 struct RR_CL{
224   char location[8];
225 };
226
227 struct RR_PL{
228   char location[8];
229 };
230
231 struct stamp{
232   char time[7];
233 } __attribute__((packed));
234
235 struct RR_TF{
236   char flags;
237   struct stamp times[0];  /* Variable number of these beasts */
238 } __attribute__((packed));
239
240 /* Linux-specific extension for transparent decompression */
241 struct RR_ZF{
242   char algorithm[2];
243   char parms[2];
244   char real_size[8];
245 };
246
247 struct rock_ridge{
248   char signature[2];
249   unsigned char len;
250   unsigned char version;
251   union{
252     struct SU_SP SP;
253     struct SU_CE CE;
254     struct SU_ER ER;
255     struct RR_RR RR;
256     struct RR_PX PX;
257     struct RR_PN PN;
258     struct RR_SL SL;
259     struct RR_NM NM;
260     struct RR_CL CL;
261     struct RR_PL PL;
262     struct RR_TF TF;
263     struct RR_ZF ZF;
264   } u;
265 };
266
267 typedef union RR_ptr {
268         struct rock_ridge *rr;
269         char              *ptr;
270         int                i;
271 } RR_ptr_t;
272
273 #include <arch/byteorder.h>
274
275 static inline int isonum_711(char *p)
276 {
277         unsigned char x = *(unsigned char *)p;
278         return x;
279 }
280 static inline int isonum_712(char *p)
281 {
282         return *(char *)p;
283 }
284 static inline int isonum_721(char *p)
285 {
286         return le16_to_cpu(*(unsigned short *)p);
287 }
288 static inline int isonum_722(char *p)
289 {
290         return be16_to_cpu(*(unsigned short *)p);
291 }
292 static inline int isonum_723(char *p)
293 {
294         /* Ignore bigendian datum due to broken mastering programs */
295         return le16_to_cpu(*(unsigned short *)p);
296 }
297 static inline int isonum_731(char *p)
298 {
299         return le32_to_cpu(*(unsigned int *)p);
300 }
301 static inline int isonum_732(char *p)
302 {
303         return be32_to_cpu(*(unsigned int *)p);
304 }
305 static inline int isonum_733(char *p)
306 {
307         /* Ignore bigendian datum due to broken mastering programs */
308         return le32_to_cpu(*(unsigned int *)p);
309 }
310 #endif /* _ISO9660_H */