1 /*
2  *  ISO 9660 filesystem backend for GRUB (GRand Unified Bootloader)
3  *  including Rock Ridge Extensions support
4  *
5  *  Copyright (C) 1998, 1999  Kousuke Takai  <tak@kmc.kyoto-u.ac.jp>
6  *
7  *  This program is free software; you can redistribute it and/or modify
8  *  it under the terms of the GNU General Public License as published by
9  *  the Free Software Foundation; either version 2 of the License, or
10  *  (at your option) any later version.
11  *
12  *  This program is distributed in the hope that it will be useful,
13  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  *  GNU General Public License for more details.
16  *
17  *  You should have received a copy of the GNU General Public License
18  *  along with this program; If not, see <http://www.gnu.org/licenses/>.
19  */
20 /*
21  *  References:
22  *	linux/fs/isofs/rock.[ch]
23  *	mkisofs-1.11.1/diag/isoinfo.c
24  *	mkisofs-1.11.1/iso9660.h
25  *		(all are written by Eric Youngdale)
26  */
27 
28 #ifndef _ISO9660_H_
29 #define _ISO9660_H_
30 
31 #define ISO_SECTOR_BITS              (11)
32 #define ISO_SECTOR_SIZE              (1<<ISO_SECTOR_BITS)
33 
34 #define	ISO_REGULAR	1	/* regular file	*/
35 #define	ISO_DIRECTORY	2	/* directory	*/
36 #define	ISO_OTHER	0	/* other file (with Rock Ridge) */
37 
38 #define	RR_FLAG_PX	0x01	/* have POSIX file attributes */
39 #define RR_FLAG_PN	0x02	/* POSIX devices */
40 #define RR_FLAG_SL	0x04	/* Symbolic link */
41 #define	RR_FLAG_NM	0x08	/* have alternate file name   */
42 #define RR_FLAG_CL	0x10	/* Child link */
43 #define RR_FLAG_PL	0x20	/* Parent link */
44 #define RR_FLAG_RE	0x40	/* Relocation directory */
45 #define RR_FLAG_TF	0x80	/* Timestamps */
46 
47 /* POSIX file attributes for Rock Ridge extensions */
48 #define	POSIX_S_IFMT	0xF000
49 #define	POSIX_S_IFREG	0x8000
50 #define	POSIX_S_IFDIR	0x4000
51 
52 /* volume descriptor types */
53 #define ISO_VD_PRIMARY 1
54 #define ISO_VD_END 255
55 
56 #define ISO_STANDARD_ID "CD001"
57 
58 #ifndef ASM_FILE
59 
60 #ifndef __sun
61 #ifndef	__BIT_TYPES_DEFINED__
62 typedef		 int	 int8_t	__attribute__((mode(QI)));
63 typedef unsigned int   u_int8_t	__attribute__((mode(QI)));
64 typedef		 int	int16_t	__attribute__((mode(HI)));
65 typedef unsigned int  u_int16_t	__attribute__((mode(HI)));
66 typedef		 int	int32_t	__attribute__((mode(SI)));
67 typedef unsigned int  u_int32_t	__attribute__((mode(SI)));
68 #endif
69 #else
70 #ifndef GRUB_UTIL
71 typedef		 char  int8_t;
72 typedef		 short int16_t;
73 typedef		 int   int32_t;
74 #endif /* ! GRUB_UTIL */
75 typedef unsigned char  u_int8_t;
76 typedef unsigned short u_int16_t;
77 typedef unsigned int   u_int32_t;
78 #endif /* __sun */
79 
80 typedef	union {
81   u_int8_t l,b;
82 }	iso_8bit_t;
83 
84 struct __iso_16bit {
85   u_int16_t l, b;
86 } __attribute__ ((packed));
87 typedef	struct __iso_16bit iso_16bit_t;
88 
89 struct __iso_32bit {
90   u_int32_t l, b;
91 } __attribute__ ((packed));
92 typedef	struct __iso_32bit iso_32bit_t;
93 
94 typedef u_int8_t		iso_date_t[7];
95 
96 struct iso_directory_record {
97   iso_8bit_t	length;
98   iso_8bit_t	ext_attr_length;
99   iso_32bit_t	extent;
100   iso_32bit_t	size;
101   iso_date_t	date;
102   iso_8bit_t	flags;
103   iso_8bit_t	file_unit_size;
104   iso_8bit_t	interleave;
105   iso_16bit_t	volume_seq_number;
106   iso_8bit_t	name_len;
107   u_int8_t	name[1];
108 } __attribute__ ((packed));
109 
110 struct iso_primary_descriptor {
111   iso_8bit_t	type;
112   u_int8_t	id[5];
113   iso_8bit_t	version;
114   u_int8_t	_unused1[1];
115   u_int8_t	system_id[32];
116   u_int8_t	volume_id[32];
117   u_int8_t	_unused2[8];
118   iso_32bit_t	volume_space_size;
119   u_int8_t	_unused3[32];
120   iso_16bit_t	volume_set_size;
121   iso_16bit_t	volume_seq_number;
122   iso_16bit_t	logical_block_size;
123   iso_32bit_t	path_table_size;
124   u_int8_t	type_l_path_table[4];
125   u_int8_t	opt_type_l_path_table[4];
126   u_int8_t	type_m_path_table[4];
127   u_int8_t	opt_type_m_path_table[4];
128   struct iso_directory_record root_directory_record;
129   u_int8_t	volume_set_id[128];
130   u_int8_t	publisher_id[128];
131   u_int8_t	preparer_id[128];
132   u_int8_t	application_id[128];
133   u_int8_t	copyright_file_id[37];
134   u_int8_t	abstract_file_id[37];
135   u_int8_t	bibliographic_file_id[37];
136   u_int8_t	creation_date[17];
137   u_int8_t	modification_date[17];
138   u_int8_t	expiration_date[17];
139   u_int8_t	effective_date[17];
140   iso_8bit_t	file_structure_version;
141   u_int8_t	_unused4[1];
142   u_int8_t	application_data[512];
143   u_int8_t	_unused5[653];
144 } __attribute__ ((packed));
145 
146 struct rock_ridge {
147   u_int16_t	signature;
148   u_int8_t	len;
149   u_int8_t	version;
150   union {
151     struct SP {
152       u_int16_t	magic;
153       u_int8_t	skip;
154     } sp;
155     struct CE {
156       iso_32bit_t	extent;
157       iso_32bit_t	offset;
158       iso_32bit_t	size;
159     } ce;
160     struct ER {
161       u_int8_t	len_id;
162       u_int8_t	len_des;
163       u_int8_t	len_src;
164       u_int8_t	ext_ver;
165       u_int8_t	data[0];
166     } er;
167     struct RR {
168       iso_8bit_t	flags;
169     } rr;
170     struct PX {
171       iso_32bit_t	mode;
172       iso_32bit_t	nlink;
173       iso_32bit_t	uid;
174       iso_32bit_t	gid;
175     } px;
176     struct PN {
177       iso_32bit_t	dev_high;
178       iso_32bit_t	dev_low;
179     } pn;
180     struct SL {
181       iso_8bit_t flags;
182       struct SL_component {
183 	iso_8bit_t	flags;
184 	u_int8_t		len;
185 	u_int8_t		text[0];
186       } link;
187     } sl;
188     struct NM {
189       iso_8bit_t	flags;
190       u_int8_t	name[0];
191     } nm;
192     struct CL {
193       iso_32bit_t	location;
194     } cl;
195     struct PL {
196       iso_32bit_t	location;
197     } pl;
198     struct TF {
199       iso_8bit_t	flags;
200       iso_date_t	times[0];
201     } tf;
202   } u;
203 } __attribute__ ((packed));
204 
205 typedef	union RR_ptr {
206   struct rock_ridge *rr;
207   char		  *ptr;
208   int		   i;
209 } RR_ptr_t;
210 
211 #define	RRMAGIC(c1, c2)	((c1)|(c2) << 8)
212 
213 #define	CHECK2(ptr, c1, c2) \
214 	(*(unsigned short *)(ptr) == (((c1) | (c2) << 8) & 0xFFFF))
215 
216 #endif /* !ASM_FILE */
217 
218 #endif /* _ISO9660_H_ */
219