xref: /freebsd/usr.sbin/makefs/cd9660/iso9660_rrip.h (revision ec965063070e5753c166cf592c9336444b74720a)
1 /*	$NetBSD: iso9660_rrip.h,v 1.5 2009/01/10 22:06:29 bjh21 Exp $	*/
2 
3 /*-
4  * SPDX-License-Identifier: BSD-2-Clause-NetBSD
5  *
6  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
7  * Perez-Rathke and Ram Vedam.  All rights reserved.
8  *
9  * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
10  * Alan Perez-Rathke and Ram Vedam.
11  *
12  * Redistribution and use in source and binary forms, with or
13  * without modification, are permitted provided that the following
14  * conditions are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above
18  *    copyright notice, this list of conditions and the following
19  *    disclaimer in the documentation and/or other materials provided
20  *    with the distribution.
21  *
22  * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
23  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26  * DISCLAIMED.  IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
27  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
30  * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34  * OF SUCH DAMAGE.
35  *
36  * $FreeBSD$
37  */
38 #ifndef __ISO9660_RRIP_H__
39 #define __ISO9660_RRIP_H__
40 
41 /*
42  * This will hold all the functions needed to
43  * write an ISO 9660 image with Rock Ridge Extensions
44  */
45 
46 /* For writing must use ISO_RRIP_EXTREF structure */
47 
48 #include "makefs.h"
49 #include <cd9660_rrip.h>
50 #include "cd9660.h"
51 #include <sys/queue.h>
52 
53 #define	 PX_LENGTH	   0x2C
54 #define	 PN_LENGTH	   0x14
55 #define	 TF_CREATION	   0x00
56 #define	 TF_MODIFY	   0x01
57 #define	 TF_ACCESS	   0x02
58 #define	 TF_ATTRIBUTES	   0x04
59 #define	 TF_BACKUP	   0x08
60 #define	 TF_EXPIRATION	   0x10
61 #define	 TF_EFFECTIVE	   0x20
62 #define	 TF_LONGFORM	   0x40
63 #define  NM_CONTINUE	   0x80
64 #define	 NM_CURRENT	   0x100
65 #define	 NM_PARENT	   0x200
66 
67 
68 #define	 SUSP_LOC_ENTRY	   0x01
69 #define	 SUSP_LOC_DOT	   0x02
70 #define	 SUSP_LOC_DOTDOT   0x04
71 
72 #define SUSP_TYPE_SUSP		1
73 #define SUSP_TYPE_RRIP		2
74 
75 #define SUSP_ENTRY_SUSP_CE	1
76 #define SUSP_ENTRY_SUSP_PD	2
77 #define SUSP_ENTRY_SUSP_SP	3
78 #define SUSP_ENTRY_SUSP_ST	4
79 #define SUSP_ENTRY_SUSP_ER	5
80 #define SUSP_ENTRY_SUSP_ES	6
81 
82 #define SUSP_ENTRY_RRIP_PX	1
83 #define SUSP_ENTRY_RRIP_PN	2
84 #define SUSP_ENTRY_RRIP_SL	3
85 #define SUSP_ENTRY_RRIP_NM	4
86 #define SUSP_ENTRY_RRIP_CL	5
87 #define SUSP_ENTRY_RRIP_PL	6
88 #define SUSP_ENTRY_RRIP_RE	7
89 #define SUSP_ENTRY_RRIP_TF	8
90 #define SUSP_ENTRY_RRIP_SF	9
91 
92 #define SUSP_RRIP_ER_EXT_ID "IEEE_P1282"
93 #define SUSP_RRIP_ER_EXT_DES "THE IEEE P1282 PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS."
94 #define SUSP_RRIP_ER_EXT_SRC "PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, PISCATAWAY, NJ, USA FOR THE P1282 SPECIFICATION."
95 
96 #define SL_FLAGS_NONE	        0
97 #define SL_FLAGS_CONTINUE       1
98 #define SL_FLAGS_CURRENT        2
99 #define SL_FLAGS_PARENT	        4
100 #define SL_FLAGS_ROOT	        8
101 
102 typedef struct {
103 	ISO_SUSP_HEADER		 h;
104 	u_char mode		[ISODCL(5,12)];
105 	u_char links		[ISODCL(13,20)];
106 	u_char uid		[ISODCL(21,28)];
107 	u_char gid		[ISODCL(29,36)];
108 	u_char serial		[ISODCL(37,44)];
109 } ISO_RRIP_PX;
110 
111 typedef struct {
112 	ISO_SUSP_HEADER		 h;
113 	u_char high		[ISODCL(5,12)];
114 	u_char low		[ISODCL(13,20)];
115 } ISO_RRIP_PN;
116 
117 typedef struct {
118 	ISO_SUSP_HEADER		 h;
119 	u_char flags		 [ISODCL ( 4, 4)];
120 	u_char component	 [ISODCL ( 4, 256)];
121 	u_int  nBytes;
122 } ISO_RRIP_SL;
123 
124 typedef struct {
125 	ISO_SUSP_HEADER		 h;
126 	u_char flags		 [ISODCL ( 4, 4)];
127 	u_char timestamp	 [ISODCL ( 5, 256)];
128 } ISO_RRIP_TF;
129 
130 #define RRIP_NM_FLAGS_NONE 0x00
131 #define RRIP_NM_FLAGS_CONTINUE 0x01
132 #define RRIP_NM_FLAGS_CURRENT 0x02
133 #define RRIP_NM_FLAGS_PARENT 0x04
134 
135 typedef struct {
136 	ISO_SUSP_HEADER		 h;
137 	u_char flags		 [ISODCL ( 4, 4)];
138 	u_char altname		 [ISODCL ( 4, 256)];
139 } ISO_RRIP_NM;
140 
141 /* Note that this is the same structure as cd9660_rrip.h : ISO_RRIP_CONT */
142 typedef struct {
143 	ISO_SUSP_HEADER		 h;
144 	u_char ca_sector	 [ISODCL ( 5, 12)];
145 	u_char offset		 [ISODCL ( 13, 20)];
146 	u_char length		 [ISODCL ( 21, 28)];
147 } ISO_SUSP_CE;
148 
149 typedef struct {
150 	ISO_SUSP_HEADER		 h;
151 	u_char padding_area	 [ISODCL ( 4, 256)];
152 } ISO_SUSP_PD;
153 
154 typedef struct {
155 	ISO_SUSP_HEADER		 h;
156 	u_char check		 [ISODCL ( 4, 5)];
157 	u_char len_skp		 [ISODCL ( 6, 6)];
158 } ISO_SUSP_SP;
159 
160 typedef struct {
161 	ISO_SUSP_HEADER		 h;
162 } ISO_SUSP_ST;
163 
164 typedef struct {
165 	ISO_SUSP_HEADER		 h;
166 	u_char len_id		 [ISODCL ( 4, 4)];
167 	u_char len_des		 [ISODCL ( 5, 5)];
168 	u_char len_src		 [ISODCL ( 6, 6)];
169 	u_char ext_ver		 [ISODCL ( 7, 7)];
170 	u_char ext_data		 [ISODCL (8,256)];
171 /*	u_char ext_id		 [ISODCL ( 8, 256)];
172 	u_char ext_des		 [ISODCL ( 257, 513)];
173 	u_char ext_src		 [ISODCL ( 514, 770)];*/
174 } ISO_SUSP_ER;
175 
176 typedef struct {
177 	ISO_SUSP_HEADER		 h;
178 	u_char ext_seq		 [ISODCL ( 4, 4)];
179 } ISO_SUSP_ES;
180 
181 typedef union {
182 	ISO_RRIP_PX			PX;
183 	ISO_RRIP_PN			PN;
184 	ISO_RRIP_SL			SL;
185 	ISO_RRIP_NM			NM;
186 	ISO_RRIP_CLINK			CL;
187 	ISO_RRIP_PLINK			PL;
188 	ISO_RRIP_RELDIR			RE;
189 	ISO_RRIP_TF			TF;
190 } rrip_entry;
191 
192 typedef union {
193 	ISO_SUSP_CE			CE;
194 	ISO_SUSP_PD			PD;
195 	ISO_SUSP_SP			SP;
196 	ISO_SUSP_ST			ST;
197 	ISO_SUSP_ER			ER;
198 	ISO_SUSP_ES			ES;
199 } susp_entry;
200 
201 typedef union {
202 	susp_entry		  su_entry;
203 	rrip_entry		  rr_entry;
204 } SUSP_ENTRIES;
205 
206 struct ISO_SUSP_ATTRIBUTES {
207 	SUSP_ENTRIES attr;
208 	int type;
209 	char type_of[2];
210 	char last_in_suf;	/* last entry in the System Use Field? */
211 	/* Dan's addons - will merge later. This allows use of a switch */
212 	char susp_type;		/* SUSP or RRIP */
213 	char entry_type;	/* Record type */
214 	char write_location;
215 	TAILQ_ENTRY(ISO_SUSP_ATTRIBUTES) rr_ll;
216 };
217 
218 #define CD9660_SUSP_ENTRY_SIZE(entry)\
219 	((int) ((entry)->attr.su_entry.SP.h.length[0]))
220 
221 /* Recursive function - move later to func pointer code*/
222 int cd9660_susp_finalize(iso9660_disk *, cd9660node *);
223 
224 /* These two operate on single nodes */
225 int cd9660_susp_finalize_node(iso9660_disk *, cd9660node *);
226 int cd9660_rrip_finalize_node(cd9660node *);
227 
228 /* POSIX File attribute */
229 int cd9660node_rrip_px(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
230 
231 /* Device number */
232 int cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
233 
234 /* Symbolic link */
235 int cd9660node_rrip_SL(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
236 
237 /* Alternate Name function */
238 void cd9660_rrip_NM(cd9660node *);
239 void cd9660_rrip_add_NM(cd9660node *,const char *);
240 
241 /* Parent and child link function */
242 int cd9660_rrip_PL(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
243 int cd9660_rrip_CL(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
244 int cd9660_rrip_RE(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
245 
246 int cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
247 
248 
249 
250 /*
251  * Relocation directory function. I'm not quite sure what
252  * sort of parameters are needed, but personally I don't think
253  * any parameters are needed except for the memory address where
254  * the information needs to be put in
255  */
256 int cd9660node_rrip_re(void *, fsnode *);
257 
258 /*
259  * Don't know if this function is needed because it apparently is an
260  * optional feature that does not really need to be implemented but I
261  * thought I should add it anyway.
262  */
263 int cd9660_susp_ce (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
264 int cd9660_susp_pd (struct ISO_SUSP_ATTRIBUTES *, int);
265 int cd9660_susp_sp (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
266 int cd9660_susp_st (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
267 
268 struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ER(cd9660node *, u_char, const char *,
269     const char *, const char *);
270 struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ES(struct ISO_SUSP_ATTRIBUTES*,
271     cd9660node *);
272 
273 
274 /* Helper functions */
275 
276 /* Common SUSP/RRIP functions */
277 int cd9660_susp_initialize(iso9660_disk *, cd9660node *, cd9660node *,
278     cd9660node *);
279 int cd9660_susp_initialize_node(iso9660_disk *, cd9660node *);
280 struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_create_node(int, int, const char *,
281     int);
282 struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_add_entry(cd9660node *,
283     struct ISO_SUSP_ATTRIBUTES *, struct ISO_SUSP_ATTRIBUTES *, int);
284 
285 /* RRIP specific functions */
286 int cd9660_rrip_initialize_node(iso9660_disk *, cd9660node *, cd9660node *,
287     cd9660node *);
288 void cd9660_createSL(cd9660node *);
289 
290 /* Functions that probably can be removed */
291 /* int cd9660node_initialize_node(int, char *); */
292 
293 
294 #endif
295