xref: /freebsd/sys/fs/cd9660/iso.h (revision 17ee9d00bc1ae1e598c38f25826f861e4bc6c3ce)
1 /*-
2  * Copyright (c) 1994
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley
6  * by Pace Willisson (pace@blitz.com).  The Rock Ridge Extension
7  * Support code is derived from software contributed to Berkeley
8  * by Atsushi Murai (amurai@spec.co.jp).
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  * 3. All advertising materials mentioning features or use of this software
19  *    must display the following acknowledgement:
20  *	This product includes software developed by the University of
21  *	California, Berkeley and its contributors.
22  * 4. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *	@(#)iso.h	8.2 (Berkeley) 1/23/94
39  * $Id: iso.h,v 1.3 1994/09/09 11:11:01 dfr Exp $
40  */
41 
42 #define ISODCL(from, to) (to - from + 1)
43 
44 struct iso_volume_descriptor {
45 	char type[ISODCL(1,1)]; /* 711 */
46 	char id[ISODCL(2,6)];
47 	char version[ISODCL(7,7)];
48 	char unused[ISODCL(8,8)];
49 	char type_sierra[ISODCL(9,9)]; /* 711 */
50 	char id_sierra[ISODCL(10,14)];
51 	char version_sierra[ISODCL(15,15)];
52 	char data[ISODCL(16,2048)];
53 };
54 
55 /* volume descriptor types */
56 #define ISO_VD_PRIMARY 1
57 #define ISO_VD_END 255
58 
59 #define ISO_STANDARD_ID "CD001"
60 #define ISO_ECMA_ID	"CDW01"
61 
62 #define ISO_SIERRA_ID	"CDROM"
63 
64 struct iso_primary_descriptor {
65 	char type			[ISODCL (  1,	1)]; /* 711 */
66 	char id				[ISODCL (  2,	6)];
67 	char version			[ISODCL (  7,	7)]; /* 711 */
68 	char unused1			[ISODCL (  8,	8)];
69 	char system_id			[ISODCL (  9,  40)]; /* achars */
70 	char volume_id			[ISODCL ( 41,  72)]; /* dchars */
71 	char unused2			[ISODCL ( 73,  80)];
72 	char volume_space_size		[ISODCL ( 81,  88)]; /* 733 */
73 	char unused3			[ISODCL ( 89, 120)];
74 	char volume_set_size		[ISODCL (121, 124)]; /* 723 */
75 	char volume_sequence_number	[ISODCL (125, 128)]; /* 723 */
76 	char logical_block_size		[ISODCL (129, 132)]; /* 723 */
77 	char path_table_size		[ISODCL (133, 140)]; /* 733 */
78 	char type_l_path_table		[ISODCL (141, 144)]; /* 731 */
79 	char opt_type_l_path_table	[ISODCL (145, 148)]; /* 731 */
80 	char type_m_path_table		[ISODCL (149, 152)]; /* 732 */
81 	char opt_type_m_path_table	[ISODCL (153, 156)]; /* 732 */
82 	char root_directory_record	[ISODCL (157, 190)]; /* 9.1 */
83 	char volume_set_id		[ISODCL (191, 318)]; /* dchars */
84 	char publisher_id		[ISODCL (319, 446)]; /* achars */
85 	char preparer_id		[ISODCL (447, 574)]; /* achars */
86 	char application_id		[ISODCL (575, 702)]; /* achars */
87 	char copyright_file_id		[ISODCL (703, 739)]; /* 7.5 dchars */
88 	char abstract_file_id		[ISODCL (740, 776)]; /* 7.5 dchars */
89 	char bibliographic_file_id	[ISODCL (777, 813)]; /* 7.5 dchars */
90 	char creation_date		[ISODCL (814, 830)]; /* 8.4.26.1 */
91 	char modification_date		[ISODCL (831, 847)]; /* 8.4.26.1 */
92 	char expiration_date		[ISODCL (848, 864)]; /* 8.4.26.1 */
93 	char effective_date		[ISODCL (865, 881)]; /* 8.4.26.1 */
94 	char file_structure_version	[ISODCL (882, 882)]; /* 711 */
95 	char unused4			[ISODCL (883, 883)];
96 	char application_data		[ISODCL (884, 1395)];
97 	char unused5			[ISODCL (1396, 2048)];
98 };
99 #define ISO_DEFAULT_BLOCK_SIZE		2048
100 
101 struct iso_sierra_primary_descriptor {
102 	char unknown1			[ISODCL (  1,	8)]; /* 733 */
103 	char type			[ISODCL (  9,	9)]; /* 711 */
104 	char id				[ISODCL ( 10,  14)];
105 	char version			[ISODCL ( 15,  15)]; /* 711 */
106 	char unused1			[ISODCL ( 16,  16)];
107 	char system_id			[ISODCL ( 17,  48)]; /* achars */
108 	char volume_id			[ISODCL ( 49,  80)]; /* dchars */
109 	char unused2			[ISODCL ( 81,  88)];
110 	char volume_space_size		[ISODCL ( 89,  96)]; /* 733 */
111 	char unused3			[ISODCL ( 97, 128)];
112 	char volume_set_size		[ISODCL (129, 132)]; /* 723 */
113 	char volume_sequence_number	[ISODCL (133, 136)]; /* 723 */
114 	char logical_block_size		[ISODCL (137, 140)]; /* 723 */
115 	char path_table_size		[ISODCL (141, 148)]; /* 733 */
116 	char type_l_path_table		[ISODCL (149, 152)]; /* 731 */
117 	char opt_type_l_path_table	[ISODCL (153, 156)]; /* 731 */
118 	char unknown2			[ISODCL (157, 160)]; /* 731 */
119 	char unknown3			[ISODCL (161, 164)]; /* 731 */
120 	char type_m_path_table		[ISODCL (165, 168)]; /* 732 */
121 	char opt_type_m_path_table	[ISODCL (169, 172)]; /* 732 */
122 	char unknown4			[ISODCL (173, 176)]; /* 732 */
123 	char unknown5			[ISODCL (177, 180)]; /* 732 */
124 	char root_directory_record	[ISODCL (181, 214)]; /* 9.1 */
125 	char volume_set_id		[ISODCL (215, 342)]; /* dchars */
126 	char publisher_id		[ISODCL (343, 470)]; /* achars */
127 	char preparer_id		[ISODCL (471, 598)]; /* achars */
128 	char application_id		[ISODCL (599, 726)]; /* achars */
129 	char copyright_id		[ISODCL (727, 790)]; /* achars */
130 	char creation_date		[ISODCL (791, 806)]; /* ? */
131 	char modification_date		[ISODCL (807, 822)]; /* ? */
132 	char expiration_date		[ISODCL (823, 838)]; /* ? */
133 	char effective_date		[ISODCL (839, 854)]; /* ? */
134 	char file_structure_version	[ISODCL (855, 855)]; /* 711 */
135 	char unused4			[ISODCL (856, 2048)];
136 };
137 
138 struct iso_directory_record {
139 	char length			[ISODCL (1, 1)]; /* 711 */
140 	char ext_attr_length		[ISODCL (2, 2)]; /* 711 */
141 	unsigned char extent		[ISODCL (3, 10)]; /* 733 */
142 	unsigned char size		[ISODCL (11, 18)]; /* 733 */
143 	char date			[ISODCL (19, 25)]; /* 7 by 711 */
144 	char flags			[ISODCL (26, 26)];
145 	char file_unit_size		[ISODCL (27, 27)]; /* 711 */
146 	char interleave			[ISODCL (28, 28)]; /* 711 */
147 	char volume_sequence_number	[ISODCL (29, 32)]; /* 723 */
148 	char name_len			[ISODCL (33, 33)]; /* 711 */
149 	char name			[0];
150 };
151 /* can't take sizeof(iso_directory_record), because of possible alignment
152    of the last entry (34 instead of 33) */
153 #define ISO_DIRECTORY_RECORD_SIZE	33
154 
155 struct iso_extended_attributes {
156 	unsigned char owner		[ISODCL (1, 4)]; /* 723 */
157 	unsigned char group		[ISODCL (5, 8)]; /* 723 */
158 	unsigned char perm		[ISODCL (9, 10)]; /* 9.5.3 */
159 	char ctime			[ISODCL (11, 27)]; /* 8.4.26.1 */
160 	char mtime			[ISODCL (28, 44)]; /* 8.4.26.1 */
161 	char xtime			[ISODCL (45, 61)]; /* 8.4.26.1 */
162 	char ftime			[ISODCL (62, 78)]; /* 8.4.26.1 */
163 	char recfmt			[ISODCL (79, 79)]; /* 711 */
164 	char recattr			[ISODCL (80, 80)]; /* 711 */
165 	unsigned char reclen		[ISODCL (81, 84)]; /* 723 */
166 	char system_id			[ISODCL (85, 116)]; /* achars */
167 	char system_use			[ISODCL (117, 180)];
168 	char version			[ISODCL (181, 181)]; /* 711 */
169 	char len_esc			[ISODCL (182, 182)]; /* 711 */
170 	char reserved			[ISODCL (183, 246)];
171 	unsigned char len_au		[ISODCL (247, 250)]; /* 723 */
172 };
173 
174 /* CD-ROM Format type */
175 enum ISO_FTYPE	{ ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP,
176 		  ISO_FTYPE_ECMA, ISO_FTYPE_HIGH_SIERRA };
177 
178 #ifndef	ISOFSMNT_ROOT
179 #define	ISOFSMNT_ROOT	0
180 #endif
181 
182 struct iso_mnt {
183 	int im_flags;
184 
185 	struct mount *im_mountp;
186 	dev_t im_dev;
187 	struct vnode *im_devvp;
188 
189 	int logical_block_size;
190 	int im_bshift;
191 	int im_bmask;
192 
193 	int volume_space_size;
194 	char im_fsmnt[50];
195 	struct netexport im_export;
196 
197 	char root[ISODCL (157, 190)];
198 	int root_extent;
199 	int root_size;
200 	enum ISO_FTYPE	iso_ftype;
201 
202 	int rr_skip;
203 	int rr_skip0;
204 };
205 
206 #define VFSTOISOFS(mp)	((struct iso_mnt *)((mp)->mnt_data))
207 
208 #define iso_blkoff(imp, loc) ((loc) & (imp)->im_bmask)
209 #define iso_lblkno(imp, loc) ((loc) >> (imp)->im_bshift)
210 #define iso_blksize(imp, ip, lbn) ((imp)->logical_block_size)
211 #define iso_lblktosize(imp, blk) ((blk) << (imp)->im_bshift)
212 #define iso_lblktodaddr(imp, lbn) btodb(iso_lblktosize(imp, lbn))
213 #define iso_dblkinc(imp, lbn) ((lbn) + iso_lblktodaddr(imp, 1))
214 #define iso_dblkno(imp, loc) iso_lblktodaddr(imp, iso_lblkno(imp, loc))
215 
216 int cd9660_mount __P((struct mount *,
217 	    char *, caddr_t, struct nameidata *, struct proc *));
218 int cd9660_start __P((struct mount *, int, struct proc *));
219 int cd9660_unmount __P((struct mount *, int, struct proc *));
220 int cd9660_root __P((struct mount *, struct vnode **));
221 int cd9660_quotactl __P((struct mount *, int, uid_t, caddr_t, struct proc *));
222 int cd9660_statfs __P((struct mount *, struct statfs *, struct proc *));
223 int cd9660_sync __P((struct mount *, int, struct ucred *, struct proc *));
224 int cd9660_vget __P((struct mount *, ino_t, struct vnode **));
225 int cd9660_fhtovp __P((struct mount *, struct fid *, struct mbuf *,
226 	    struct vnode **, int *, struct ucred **));
227 int cd9660_vptofh __P((struct vnode *, struct fid *));
228 int cd9660_init __P(());
229 
230 struct iso_node;
231 int iso_blkatoff __P((struct iso_node *ip, long offset, struct buf **bpp));
232 int iso_iget __P((struct iso_node *xp, ino_t ino, int relocated,
233 		  struct iso_node **ipp, struct iso_directory_record *isodir));
234 int iso_iput __P((struct iso_node *ip));
235 int iso_ilock __P((struct iso_node *ip));
236 int iso_iunlock __P((struct iso_node *ip));
237 int cd9660_mountroot __P((void));
238 
239 extern int (**cd9660_vnodeop_p)();
240 
241 extern inline int
242 isonum_711(p)
243 	unsigned char *p;
244 {
245 	return *p;
246 }
247 
248 extern inline int
249 isonum_712(p)
250 	char *p;
251 {
252 	return *p;
253 }
254 
255 extern inline int
256 isonum_721(p)
257 	unsigned char *p;
258 {
259 	return *p|((char)p[1] << 8);
260 }
261 
262 extern inline int
263 isonum_722(p)
264 	unsigned char *p;
265 {
266 	return ((char)*p << 8)|p[1];
267 }
268 
269 extern inline int
270 isonum_723(p)
271 	unsigned char *p;
272 {
273 	return isonum_721(p);
274 }
275 
276 extern inline int
277 isonum_731(p)
278 	unsigned char *p;
279 {
280 	return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24);
281 }
282 
283 extern inline int
284 isonum_732(p)
285 	unsigned char *p;
286 {
287 	return (*p << 24)|(p[1] << 16)|(p[2] << 8)|p[3];
288 }
289 
290 extern inline int
291 isonum_733(p)
292 	unsigned char *p;
293 {
294 	return isonum_731(p);
295 }
296 
297 int isofncmp __P((unsigned char *, int, unsigned char *, int));
298 void isofntrans __P((unsigned char *, int, unsigned char *, unsigned short *,
299 		     int, int));
300 
301 /*
302  * Associated files have a leading '='.
303  */
304 #define	ASSOCCHAR	'='
305