xref: /freebsd/sys/fs/cd9660/iso.h (revision afe61c15161c324a7af299a9b8457aba5afc92db)
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  */
40 
41 #define ISODCL(from, to) (to - from + 1)
42 
43 struct iso_volume_descriptor {
44 	char type[ISODCL(1,1)]; /* 711 */
45 	char id[ISODCL(2,6)];
46 	char version[ISODCL(7,7)];
47 	char data[ISODCL(8,2048)];
48 };
49 
50 /* volume descriptor types */
51 #define ISO_VD_PRIMARY 1
52 #define ISO_VD_END 255
53 
54 #define ISO_STANDARD_ID "CD001"
55 #define ISO_ECMA_ID     "CDW01"
56 
57 struct iso_primary_descriptor {
58 	char type			[ISODCL (  1,   1)]; /* 711 */
59 	char id				[ISODCL (  2,   6)];
60 	char version			[ISODCL (  7,   7)]; /* 711 */
61 	char unused1			[ISODCL (  8,   8)];
62 	char system_id			[ISODCL (  9,  40)]; /* achars */
63 	char volume_id			[ISODCL ( 41,  72)]; /* dchars */
64 	char unused2			[ISODCL ( 73,  80)];
65 	char volume_space_size		[ISODCL ( 81,  88)]; /* 733 */
66 	char unused3			[ISODCL ( 89, 120)];
67 	char volume_set_size		[ISODCL (121, 124)]; /* 723 */
68 	char volume_sequence_number	[ISODCL (125, 128)]; /* 723 */
69 	char logical_block_size		[ISODCL (129, 132)]; /* 723 */
70 	char path_table_size		[ISODCL (133, 140)]; /* 733 */
71 	char type_l_path_table		[ISODCL (141, 144)]; /* 731 */
72 	char opt_type_l_path_table	[ISODCL (145, 148)]; /* 731 */
73 	char type_m_path_table		[ISODCL (149, 152)]; /* 732 */
74 	char opt_type_m_path_table	[ISODCL (153, 156)]; /* 732 */
75 	char root_directory_record	[ISODCL (157, 190)]; /* 9.1 */
76 	char volume_set_id		[ISODCL (191, 318)]; /* dchars */
77 	char publisher_id		[ISODCL (319, 446)]; /* achars */
78 	char preparer_id		[ISODCL (447, 574)]; /* achars */
79 	char application_id		[ISODCL (575, 702)]; /* achars */
80 	char copyright_file_id		[ISODCL (703, 739)]; /* 7.5 dchars */
81 	char abstract_file_id		[ISODCL (740, 776)]; /* 7.5 dchars */
82 	char bibliographic_file_id	[ISODCL (777, 813)]; /* 7.5 dchars */
83 	char creation_date		[ISODCL (814, 830)]; /* 8.4.26.1 */
84 	char modification_date		[ISODCL (831, 847)]; /* 8.4.26.1 */
85 	char expiration_date		[ISODCL (848, 864)]; /* 8.4.26.1 */
86 	char effective_date		[ISODCL (865, 881)]; /* 8.4.26.1 */
87 	char file_structure_version	[ISODCL (882, 882)]; /* 711 */
88 	char unused4			[ISODCL (883, 883)];
89 	char application_data		[ISODCL (884, 1395)];
90 	char unused5			[ISODCL (1396, 2048)];
91 };
92 #define ISO_DEFAULT_BLOCK_SIZE		2048
93 
94 struct iso_directory_record {
95 	char length			[ISODCL (1, 1)]; /* 711 */
96 	char ext_attr_length		[ISODCL (2, 2)]; /* 711 */
97 	unsigned char extent		[ISODCL (3, 10)]; /* 733 */
98 	unsigned char size		[ISODCL (11, 18)]; /* 733 */
99 	char date			[ISODCL (19, 25)]; /* 7 by 711 */
100 	char flags			[ISODCL (26, 26)];
101 	char file_unit_size		[ISODCL (27, 27)]; /* 711 */
102 	char interleave			[ISODCL (28, 28)]; /* 711 */
103 	char volume_sequence_number	[ISODCL (29, 32)]; /* 723 */
104 	char name_len			[ISODCL (33, 33)]; /* 711 */
105 	char name			[0];
106 };
107 /* can't take sizeof(iso_directory_record), because of possible alignment
108    of the last entry (34 instead of 33) */
109 #define ISO_DIRECTORY_RECORD_SIZE	33
110 
111 struct iso_extended_attributes {
112 	unsigned char owner		[ISODCL (1, 4)]; /* 723 */
113 	unsigned char group		[ISODCL (5, 8)]; /* 723 */
114 	unsigned char perm		[ISODCL (9, 10)]; /* 9.5.3 */
115 	char ctime			[ISODCL (11, 27)]; /* 8.4.26.1 */
116 	char mtime			[ISODCL (28, 44)]; /* 8.4.26.1 */
117 	char xtime			[ISODCL (45, 61)]; /* 8.4.26.1 */
118 	char ftime			[ISODCL (62, 78)]; /* 8.4.26.1 */
119 	char recfmt			[ISODCL (79, 79)]; /* 711 */
120 	char recattr			[ISODCL (80, 80)]; /* 711 */
121 	unsigned char reclen		[ISODCL (81, 84)]; /* 723 */
122 	char system_id			[ISODCL (85, 116)]; /* achars */
123 	char system_use			[ISODCL (117, 180)];
124 	char version			[ISODCL (181, 181)]; /* 711 */
125 	char len_esc			[ISODCL (182, 182)]; /* 711 */
126 	char reserved			[ISODCL (183, 246)];
127 	unsigned char len_au		[ISODCL (247, 250)]; /* 723 */
128 };
129 
130 /* CD-ROM Format type */
131 enum ISO_FTYPE  { ISO_FTYPE_DEFAULT, ISO_FTYPE_9660, ISO_FTYPE_RRIP, ISO_FTYPE_ECMA };
132 
133 #ifndef	ISOFSMNT_ROOT
134 #define	ISOFSMNT_ROOT	0
135 #endif
136 
137 struct iso_mnt {
138 	int im_flags;
139 
140 	struct mount *im_mountp;
141 	dev_t im_dev;
142 	struct vnode *im_devvp;
143 
144 	int logical_block_size;
145 	int im_bshift;
146 	int im_bmask;
147 
148 	int volume_space_size;
149 	char im_fsmnt[50];
150 	struct netexport im_export;
151 
152 	char root[ISODCL (157, 190)];
153 	int root_extent;
154 	int root_size;
155 	enum ISO_FTYPE  iso_ftype;
156 
157 	int rr_skip;
158 	int rr_skip0;
159 };
160 
161 #define VFSTOISOFS(mp)	((struct iso_mnt *)((mp)->mnt_data))
162 
163 #define iso_blkoff(imp, loc) ((loc) & (imp)->im_bmask)
164 #define iso_lblkno(imp, loc) ((loc) >> (imp)->im_bshift)
165 #define iso_blksize(imp, ip, lbn) ((imp)->logical_block_size)
166 #define iso_lblktosize(imp, blk) ((blk) << (imp)->im_bshift)
167 
168 int cd9660_mount __P((struct mount *,
169 	    char *, caddr_t, struct nameidata *, struct proc *));
170 int cd9660_start __P((struct mount *, int, struct proc *));
171 int cd9660_unmount __P((struct mount *, int, struct proc *));
172 int cd9660_root __P((struct mount *, struct vnode **));
173 int cd9660_quotactl __P((struct mount *, int, uid_t, caddr_t, struct proc *));
174 int cd9660_statfs __P((struct mount *, struct statfs *, struct proc *));
175 int cd9660_sync __P((struct mount *, int, struct ucred *, struct proc *));
176 int cd9660_vget __P((struct mount *, ino_t, struct vnode **));
177 int cd9660_fhtovp __P((struct mount *, struct fid *, struct mbuf *,
178 	    struct vnode **, int *, struct ucred **));
179 int cd9660_vptofh __P((struct vnode *, struct fid *));
180 int cd9660_init __P(());
181 
182 struct iso_node;
183 int iso_blkatoff __P((struct iso_node *ip, long offset, struct buf **bpp));
184 int iso_iget __P((struct iso_node *xp, ino_t ino, int relocated,
185 		  struct iso_node **ipp, struct iso_directory_record *isodir));
186 int iso_iput __P((struct iso_node *ip));
187 int iso_ilock __P((struct iso_node *ip));
188 int iso_iunlock __P((struct iso_node *ip));
189 int cd9660_mountroot __P((void));
190 
191 extern int (**cd9660_vnodeop_p)();
192 
193 extern inline int
194 isonum_711(p)
195 	unsigned char *p;
196 {
197 	return *p;
198 }
199 
200 extern inline int
201 isonum_712(p)
202 	char *p;
203 {
204 	return *p;
205 }
206 
207 extern inline int
208 isonum_721(p)
209 	unsigned char *p;
210 {
211 	return *p|((char)p[1] << 8);
212 }
213 
214 extern inline int
215 isonum_722(p)
216 	unsigned char *p;
217 {
218 	return ((char)*p << 8)|p[1];
219 }
220 
221 extern inline int
222 isonum_723(p)
223 	unsigned char *p;
224 {
225 	return isonum_721(p);
226 }
227 
228 extern inline int
229 isonum_731(p)
230 	unsigned char *p;
231 {
232 	return *p|(p[1] << 8)|(p[2] << 16)|(p[3] << 24);
233 }
234 
235 extern inline int
236 isonum_732(p)
237 	unsigned char *p;
238 {
239 	return (*p << 24)|(p[1] << 16)|(p[2] << 8)|p[3];
240 }
241 
242 extern inline int
243 isonum_733(p)
244 	unsigned char *p;
245 {
246 	return isonum_731(p);
247 }
248 
249 int isofncmp __P((unsigned char *, int, unsigned char *, int));
250 void isofntrans __P((unsigned char *, int, unsigned char *, unsigned short *,
251 		     int, int));
252 
253 /*
254  * Associated files have a leading '='.
255  */
256 #define	ASSOCCHAR	'='
257