xref: /freebsd/usr.sbin/makefs/cd9660/iso9660_rrip.h (revision 518cdd344ec51584478f39b9a9cac77fc0766ce1)
101a0f853SOlivier Houchard /*	$NetBSD: iso9660_rrip.h,v 1.5 2009/01/10 22:06:29 bjh21 Exp $	*/
201a0f853SOlivier Houchard 
31de7b4b8SPedro F. Giffuni /*-
4b61a5730SWarner Losh  * SPDX-License-Identifier: BSD-2-Clause
51de7b4b8SPedro F. Giffuni  *
601a0f853SOlivier Houchard  * Copyright (c) 2005 Daniel Watt, Walter Deignan, Ryan Gabrys, Alan
701a0f853SOlivier Houchard  * Perez-Rathke and Ram Vedam.  All rights reserved.
801a0f853SOlivier Houchard  *
901a0f853SOlivier Houchard  * This code was written by Daniel Watt, Walter Deignan, Ryan Gabrys,
1001a0f853SOlivier Houchard  * Alan Perez-Rathke and Ram Vedam.
1101a0f853SOlivier Houchard  *
1201a0f853SOlivier Houchard  * Redistribution and use in source and binary forms, with or
1301a0f853SOlivier Houchard  * without modification, are permitted provided that the following
1401a0f853SOlivier Houchard  * conditions are met:
1501a0f853SOlivier Houchard  * 1. Redistributions of source code must retain the above copyright
1601a0f853SOlivier Houchard  *    notice, this list of conditions and the following disclaimer.
1701a0f853SOlivier Houchard  * 2. Redistributions in binary form must reproduce the above
1801a0f853SOlivier Houchard  *    copyright notice, this list of conditions and the following
1901a0f853SOlivier Houchard  *    disclaimer in the documentation and/or other materials provided
2001a0f853SOlivier Houchard  *    with the distribution.
2101a0f853SOlivier Houchard  *
2201a0f853SOlivier Houchard  * THIS SOFTWARE IS PROVIDED BY DANIEL WATT, WALTER DEIGNAN, RYAN
2301a0f853SOlivier Houchard  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM ``AS IS'' AND ANY EXPRESS OR
2401a0f853SOlivier Houchard  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2501a0f853SOlivier Houchard  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2601a0f853SOlivier Houchard  * DISCLAIMED.  IN NO EVENT SHALL DANIEL WATT, WALTER DEIGNAN, RYAN
2701a0f853SOlivier Houchard  * GABRYS, ALAN PEREZ-RATHKE AND RAM VEDAM BE LIABLE FOR ANY DIRECT, INDIRECT,
2801a0f853SOlivier Houchard  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2901a0f853SOlivier Houchard  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3001a0f853SOlivier Houchard  * USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3101a0f853SOlivier Houchard  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3201a0f853SOlivier Houchard  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3301a0f853SOlivier Houchard  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
3401a0f853SOlivier Houchard  * OF SUCH DAMAGE.
3501a0f853SOlivier Houchard  */
3601a0f853SOlivier Houchard #ifndef __ISO9660_RRIP_H__
3701a0f853SOlivier Houchard #define __ISO9660_RRIP_H__
3801a0f853SOlivier Houchard 
3901a0f853SOlivier Houchard /*
4001a0f853SOlivier Houchard  * This will hold all the functions needed to
4101a0f853SOlivier Houchard  * write an ISO 9660 image with Rock Ridge Extensions
4201a0f853SOlivier Houchard  */
4301a0f853SOlivier Houchard 
4401a0f853SOlivier Houchard /* For writing must use ISO_RRIP_EXTREF structure */
4501a0f853SOlivier Houchard 
4601a0f853SOlivier Houchard #include "makefs.h"
4701a0f853SOlivier Houchard #include <cd9660_rrip.h>
4801a0f853SOlivier Houchard #include "cd9660.h"
4901a0f853SOlivier Houchard #include <sys/queue.h>
5001a0f853SOlivier Houchard 
5101a0f853SOlivier Houchard #define	 PX_LENGTH	   0x2C
5201a0f853SOlivier Houchard #define	 PN_LENGTH	   0x14
53c65c969bSEd Maste #define	 TF_CREATION	   0x01
54c65c969bSEd Maste #define	 TF_MODIFY	   0x02
55c65c969bSEd Maste #define	 TF_ACCESS	   0x04
56c65c969bSEd Maste #define	 TF_ATTRIBUTES	   0x08
57c65c969bSEd Maste #define	 TF_BACKUP	   0x10
58c65c969bSEd Maste #define	 TF_EXPIRATION	   0x20
59c65c969bSEd Maste #define	 TF_EFFECTIVE	   0x40
60c65c969bSEd Maste #define	 TF_LONG_FORM	   0x80
61c3ec1935SEd Maste #define	 NM_CONTINUE	   0x01
62c3ec1935SEd Maste #define	 NM_CURRENT	   0x02
63c3ec1935SEd Maste #define	 NM_PARENT	   0x04
6401a0f853SOlivier Houchard 
6501a0f853SOlivier Houchard 
6601a0f853SOlivier Houchard #define	 SUSP_LOC_ENTRY	   0x01
6701a0f853SOlivier Houchard #define	 SUSP_LOC_DOT	   0x02
6801a0f853SOlivier Houchard #define	 SUSP_LOC_DOTDOT   0x04
6901a0f853SOlivier Houchard 
7001a0f853SOlivier Houchard #define SUSP_TYPE_SUSP		1
7101a0f853SOlivier Houchard #define SUSP_TYPE_RRIP		2
7201a0f853SOlivier Houchard 
7301a0f853SOlivier Houchard #define SUSP_ENTRY_SUSP_CE	1
7401a0f853SOlivier Houchard #define SUSP_ENTRY_SUSP_PD	2
7501a0f853SOlivier Houchard #define SUSP_ENTRY_SUSP_SP	3
7601a0f853SOlivier Houchard #define SUSP_ENTRY_SUSP_ST	4
7701a0f853SOlivier Houchard #define SUSP_ENTRY_SUSP_ER	5
7801a0f853SOlivier Houchard #define SUSP_ENTRY_SUSP_ES	6
7901a0f853SOlivier Houchard 
8001a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_PX	1
8101a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_PN	2
8201a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_SL	3
8301a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_NM	4
8401a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_CL	5
8501a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_PL	6
8601a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_RE	7
8701a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_TF	8
8801a0f853SOlivier Houchard #define SUSP_ENTRY_RRIP_SF	9
8901a0f853SOlivier Houchard 
9001a0f853SOlivier Houchard #define SUSP_RRIP_ER_EXT_ID "IEEE_P1282"
9101a0f853SOlivier Houchard #define SUSP_RRIP_ER_EXT_DES "THE IEEE P1282 PROTOCOL PROVIDES SUPPORT FOR POSIX FILE SYSTEM SEMANTICS."
9201a0f853SOlivier Houchard #define SUSP_RRIP_ER_EXT_SRC "PLEASE CONTACT THE IEEE STANDARDS DEPARTMENT, PISCATAWAY, NJ, USA FOR THE P1282 SPECIFICATION."
9301a0f853SOlivier Houchard 
9401a0f853SOlivier Houchard #define SL_FLAGS_NONE	        0
9501a0f853SOlivier Houchard #define SL_FLAGS_CONTINUE       1
9601a0f853SOlivier Houchard #define SL_FLAGS_CURRENT        2
9701a0f853SOlivier Houchard #define SL_FLAGS_PARENT	        4
9801a0f853SOlivier Houchard #define SL_FLAGS_ROOT	        8
9901a0f853SOlivier Houchard 
10001a0f853SOlivier Houchard typedef struct {
10101a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
10201a0f853SOlivier Houchard 	u_char mode		[ISODCL(5,12)];
10301a0f853SOlivier Houchard 	u_char links		[ISODCL(13,20)];
10401a0f853SOlivier Houchard 	u_char uid		[ISODCL(21,28)];
10501a0f853SOlivier Houchard 	u_char gid		[ISODCL(29,36)];
106516e0168SMarius Strobl 	u_char serial		[ISODCL(37,44)];
10701a0f853SOlivier Houchard } ISO_RRIP_PX;
10801a0f853SOlivier Houchard 
10901a0f853SOlivier Houchard typedef struct {
11001a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
11101a0f853SOlivier Houchard 	u_char high		[ISODCL(5,12)];
11201a0f853SOlivier Houchard 	u_char low		[ISODCL(13,20)];
11301a0f853SOlivier Houchard } ISO_RRIP_PN;
11401a0f853SOlivier Houchard 
11501a0f853SOlivier Houchard typedef struct {
11601a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
11701a0f853SOlivier Houchard 	u_char flags		 [ISODCL ( 4, 4)];
11801a0f853SOlivier Houchard 	u_char component	 [ISODCL ( 4, 256)];
11901a0f853SOlivier Houchard 	u_int  nBytes;
12001a0f853SOlivier Houchard } ISO_RRIP_SL;
12101a0f853SOlivier Houchard 
12201a0f853SOlivier Houchard typedef struct {
12301a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
12401a0f853SOlivier Houchard 	u_char flags		 [ISODCL ( 4, 4)];
12501a0f853SOlivier Houchard 	u_char timestamp	 [ISODCL ( 5, 256)];
12601a0f853SOlivier Houchard } ISO_RRIP_TF;
12701a0f853SOlivier Houchard 
12801a0f853SOlivier Houchard #define RRIP_NM_FLAGS_NONE 0x00
12901a0f853SOlivier Houchard #define RRIP_NM_FLAGS_CONTINUE 0x01
13001a0f853SOlivier Houchard #define RRIP_NM_FLAGS_CURRENT 0x02
13101a0f853SOlivier Houchard #define RRIP_NM_FLAGS_PARENT 0x04
13201a0f853SOlivier Houchard 
13301a0f853SOlivier Houchard typedef struct {
13401a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
13501a0f853SOlivier Houchard 	u_char flags		 [ISODCL ( 4, 4)];
13601a0f853SOlivier Houchard 	u_char altname		 [ISODCL ( 4, 256)];
13701a0f853SOlivier Houchard } ISO_RRIP_NM;
13801a0f853SOlivier Houchard 
13901a0f853SOlivier Houchard /* Note that this is the same structure as cd9660_rrip.h : ISO_RRIP_CONT */
14001a0f853SOlivier Houchard typedef struct {
14101a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
14201a0f853SOlivier Houchard 	u_char ca_sector	 [ISODCL ( 5, 12)];
14301a0f853SOlivier Houchard 	u_char offset		 [ISODCL ( 13, 20)];
14401a0f853SOlivier Houchard 	u_char length		 [ISODCL ( 21, 28)];
14501a0f853SOlivier Houchard } ISO_SUSP_CE;
14601a0f853SOlivier Houchard 
14701a0f853SOlivier Houchard typedef struct {
14801a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
14901a0f853SOlivier Houchard 	u_char padding_area	 [ISODCL ( 4, 256)];
15001a0f853SOlivier Houchard } ISO_SUSP_PD;
15101a0f853SOlivier Houchard 
15201a0f853SOlivier Houchard typedef struct {
15301a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
15401a0f853SOlivier Houchard 	u_char check		 [ISODCL ( 4, 5)];
15501a0f853SOlivier Houchard 	u_char len_skp		 [ISODCL ( 6, 6)];
15601a0f853SOlivier Houchard } ISO_SUSP_SP;
15701a0f853SOlivier Houchard 
15801a0f853SOlivier Houchard typedef struct {
15901a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
16001a0f853SOlivier Houchard } ISO_SUSP_ST;
16101a0f853SOlivier Houchard 
16201a0f853SOlivier Houchard typedef struct {
16301a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
16401a0f853SOlivier Houchard 	u_char len_id		 [ISODCL ( 4, 4)];
16501a0f853SOlivier Houchard 	u_char len_des		 [ISODCL ( 5, 5)];
16601a0f853SOlivier Houchard 	u_char len_src		 [ISODCL ( 6, 6)];
16701a0f853SOlivier Houchard 	u_char ext_ver		 [ISODCL ( 7, 7)];
16801a0f853SOlivier Houchard 	u_char ext_data		 [ISODCL (8,256)];
16901a0f853SOlivier Houchard /*	u_char ext_id		 [ISODCL ( 8, 256)];
17001a0f853SOlivier Houchard 	u_char ext_des		 [ISODCL ( 257, 513)];
17101a0f853SOlivier Houchard 	u_char ext_src		 [ISODCL ( 514, 770)];*/
17201a0f853SOlivier Houchard } ISO_SUSP_ER;
17301a0f853SOlivier Houchard 
17401a0f853SOlivier Houchard typedef struct {
17501a0f853SOlivier Houchard 	ISO_SUSP_HEADER		 h;
17601a0f853SOlivier Houchard 	u_char ext_seq		 [ISODCL ( 4, 4)];
17701a0f853SOlivier Houchard } ISO_SUSP_ES;
17801a0f853SOlivier Houchard 
17901a0f853SOlivier Houchard typedef union {
18001a0f853SOlivier Houchard 	ISO_RRIP_PX			PX;
18101a0f853SOlivier Houchard 	ISO_RRIP_PN			PN;
18201a0f853SOlivier Houchard 	ISO_RRIP_SL			SL;
18301a0f853SOlivier Houchard 	ISO_RRIP_NM			NM;
18401a0f853SOlivier Houchard 	ISO_RRIP_CLINK			CL;
18501a0f853SOlivier Houchard 	ISO_RRIP_PLINK			PL;
18601a0f853SOlivier Houchard 	ISO_RRIP_RELDIR			RE;
18701a0f853SOlivier Houchard 	ISO_RRIP_TF			TF;
18801a0f853SOlivier Houchard } rrip_entry;
18901a0f853SOlivier Houchard 
19001a0f853SOlivier Houchard typedef union {
19101a0f853SOlivier Houchard 	ISO_SUSP_CE			CE;
19201a0f853SOlivier Houchard 	ISO_SUSP_PD			PD;
19301a0f853SOlivier Houchard 	ISO_SUSP_SP			SP;
19401a0f853SOlivier Houchard 	ISO_SUSP_ST			ST;
19501a0f853SOlivier Houchard 	ISO_SUSP_ER			ER;
19601a0f853SOlivier Houchard 	ISO_SUSP_ES			ES;
19701a0f853SOlivier Houchard } susp_entry;
19801a0f853SOlivier Houchard 
19901a0f853SOlivier Houchard typedef union {
20001a0f853SOlivier Houchard 	susp_entry		  su_entry;
20101a0f853SOlivier Houchard 	rrip_entry		  rr_entry;
20201a0f853SOlivier Houchard } SUSP_ENTRIES;
20301a0f853SOlivier Houchard 
20401a0f853SOlivier Houchard struct ISO_SUSP_ATTRIBUTES {
20501a0f853SOlivier Houchard 	SUSP_ENTRIES attr;
20601a0f853SOlivier Houchard 	int type;
20701a0f853SOlivier Houchard 	char type_of[2];
20801a0f853SOlivier Houchard 	char last_in_suf;	/* last entry in the System Use Field? */
20901a0f853SOlivier Houchard 	/* Dan's addons - will merge later. This allows use of a switch */
21001a0f853SOlivier Houchard 	char susp_type;		/* SUSP or RRIP */
21101a0f853SOlivier Houchard 	char entry_type;	/* Record type */
21201a0f853SOlivier Houchard 	char write_location;
21301a0f853SOlivier Houchard 	TAILQ_ENTRY(ISO_SUSP_ATTRIBUTES) rr_ll;
21401a0f853SOlivier Houchard };
21501a0f853SOlivier Houchard 
21601a0f853SOlivier Houchard #define CD9660_SUSP_ENTRY_SIZE(entry)\
21701a0f853SOlivier Houchard 	((int) ((entry)->attr.su_entry.SP.h.length[0]))
21801a0f853SOlivier Houchard 
21901a0f853SOlivier Houchard /* Recursive function - move later to func pointer code*/
2201631d42aSEd Maste int cd9660_susp_finalize(iso9660_disk *, cd9660node *);
22101a0f853SOlivier Houchard 
22201a0f853SOlivier Houchard /* These two operate on single nodes */
2231631d42aSEd Maste int cd9660_susp_finalize_node(iso9660_disk *, cd9660node *);
22401a0f853SOlivier Houchard int cd9660_rrip_finalize_node(cd9660node *);
22501a0f853SOlivier Houchard 
22601a0f853SOlivier Houchard /* POSIX File attribute */
227*518cdd34SEd Maste int cd9660node_rrip_px(iso9660_disk *, struct ISO_SUSP_ATTRIBUTES *, fsnode *);
22801a0f853SOlivier Houchard 
22901a0f853SOlivier Houchard /* Device number */
23001a0f853SOlivier Houchard int cd9660node_rrip_pn(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
23101a0f853SOlivier Houchard 
23201a0f853SOlivier Houchard /* Symbolic link */
23301a0f853SOlivier Houchard int cd9660node_rrip_SL(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
23401a0f853SOlivier Houchard 
23501a0f853SOlivier Houchard /* Alternate Name function */
23601a0f853SOlivier Houchard void cd9660_rrip_NM(cd9660node *);
23701a0f853SOlivier Houchard void cd9660_rrip_add_NM(cd9660node *,const char *);
23801a0f853SOlivier Houchard 
23901a0f853SOlivier Houchard /* Parent and child link function */
24001a0f853SOlivier Houchard int cd9660_rrip_PL(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
24101a0f853SOlivier Houchard int cd9660_rrip_CL(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
24201a0f853SOlivier Houchard int cd9660_rrip_RE(struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
24301a0f853SOlivier Houchard 
24401a0f853SOlivier Houchard int cd9660node_rrip_tf(struct ISO_SUSP_ATTRIBUTES *, fsnode *);
24501a0f853SOlivier Houchard 
24601a0f853SOlivier Houchard 
24701a0f853SOlivier Houchard 
24801a0f853SOlivier Houchard /*
24901a0f853SOlivier Houchard  * Relocation directory function. I'm not quite sure what
25001a0f853SOlivier Houchard  * sort of parameters are needed, but personally I don't think
25101a0f853SOlivier Houchard  * any parameters are needed except for the memory address where
25201a0f853SOlivier Houchard  * the information needs to be put in
25301a0f853SOlivier Houchard  */
25401a0f853SOlivier Houchard int cd9660node_rrip_re(void *, fsnode *);
25501a0f853SOlivier Houchard 
25601a0f853SOlivier Houchard /*
25701a0f853SOlivier Houchard  * Don't know if this function is needed because it apparently is an
25801a0f853SOlivier Houchard  * optional feature that does not really need to be implemented but I
25901a0f853SOlivier Houchard  * thought I should add it anyway.
26001a0f853SOlivier Houchard  */
26101a0f853SOlivier Houchard int cd9660_susp_ce (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
26201a0f853SOlivier Houchard int cd9660_susp_pd (struct ISO_SUSP_ATTRIBUTES *, int);
26301a0f853SOlivier Houchard int cd9660_susp_sp (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
26401a0f853SOlivier Houchard int cd9660_susp_st (struct ISO_SUSP_ATTRIBUTES *, cd9660node *);
26501a0f853SOlivier Houchard 
26601a0f853SOlivier Houchard struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ER(cd9660node *, u_char, const char *,
26701a0f853SOlivier Houchard     const char *, const char *);
26801a0f853SOlivier Houchard struct ISO_SUSP_ATTRIBUTES *cd9660_susp_ES(struct ISO_SUSP_ATTRIBUTES*,
26901a0f853SOlivier Houchard     cd9660node *);
27001a0f853SOlivier Houchard 
27101a0f853SOlivier Houchard 
27201a0f853SOlivier Houchard /* Helper functions */
27301a0f853SOlivier Houchard 
27401a0f853SOlivier Houchard /* Common SUSP/RRIP functions */
2751631d42aSEd Maste int cd9660_susp_initialize(iso9660_disk *, cd9660node *, cd9660node *,
2761631d42aSEd Maste     cd9660node *);
2771631d42aSEd Maste int cd9660_susp_initialize_node(iso9660_disk *, cd9660node *);
27801a0f853SOlivier Houchard struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_create_node(int, int, const char *,
27901a0f853SOlivier Houchard     int);
28001a0f853SOlivier Houchard struct ISO_SUSP_ATTRIBUTES *cd9660node_susp_add_entry(cd9660node *,
28101a0f853SOlivier Houchard     struct ISO_SUSP_ATTRIBUTES *, struct ISO_SUSP_ATTRIBUTES *, int);
28201a0f853SOlivier Houchard 
28301a0f853SOlivier Houchard /* RRIP specific functions */
2841631d42aSEd Maste int cd9660_rrip_initialize_node(iso9660_disk *, cd9660node *, cd9660node *,
2851631d42aSEd Maste     cd9660node *);
28601a0f853SOlivier Houchard void cd9660_createSL(cd9660node *);
28701a0f853SOlivier Houchard 
28801a0f853SOlivier Houchard /* Functions that probably can be removed */
28901a0f853SOlivier Houchard /* int cd9660node_initialize_node(int, char *); */
29001a0f853SOlivier Houchard 
29101a0f853SOlivier Houchard 
29201a0f853SOlivier Houchard #endif
293