xref: /illumos-gate/usr/src/cmd/fs.d/udfs/common/ud_lib.h (revision eee96f107560ac00d5cc32e4aa8a02376aaf19d4)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_UD_LIB_H
27 #define	_UD_LIB_H
28 
29 #ifdef	__cplusplus
30 extern "C" {
31 #endif
32 
33 #define	UD_VOL_REC_START	(32 * 1024)
34 #define	UD_VOL_REC_BSZ		2048
35 #define	UD_VOL_REC_END		(256 * UD_VOL_REC_BSZ)
36 
37 #define	UD_ECMA_VER2		0x00000002
38 #define	UD_ECMA_VER3		0x00000003
39 #define	UD_ECMA_UNKN		0xFFFFFFFF
40 
41 #define	MAX_PARTS	10
42 #define	MAX_MAPS	10
43 #define	MAX_SPM		4
44 
45 #define	lb_roundup(sz, lbsz)	\
46 	(((sz) + (lbsz - 1)) & (~(lbsz - 1)))
47 
48 struct vds {
49 	uint32_t	pvd_loc;
50 	uint32_t	pvd_len;
51 	uint32_t	pvd_vdsn;
52 
53 	uint32_t	iud_loc;
54 	uint32_t	iud_len;
55 
56 	uint32_t	part_loc[MAX_PARTS];
57 	uint32_t	part_len[MAX_PARTS];
58 
59 	uint32_t	lvd_loc;
60 	uint32_t	lvd_len;
61 	uint32_t	lvd_vdsn;
62 
63 	uint32_t	usd_loc;
64 	uint32_t	usd_len;
65 };
66 
67 /*
68  * All addresses are the lbsize block numbers
69  * offseted into the partition
70  */
71 struct udf {
72 	uint32_t	flags;
73 #define	INVALID_UDFS	0x0000
74 #define	VALID_UDFS	0x0001
75 #define	VALID_MVDS	0x0002
76 #define	VALID_RVDS	0x0004
77 
78 	uint32_t	ecma_version;
79 	uint8_t		ecma_id[5];
80 
81 	uint16_t	mi_read;
82 	uint16_t	ma_read;
83 	uint16_t	ma_write;
84 
85 	uint32_t	lbsize;
86 
87 	uint32_t	avdp_loc;	/* First Readable avdp */
88 	uint32_t	avdp_len;
89 
90 	uint32_t	mvds_loc;
91 	uint32_t	mvds_len;
92 	uint32_t	rvds_len;
93 	uint32_t	rvds_loc;
94 
95 	struct	vds	mvds;
96 	struct	vds	rvds;
97 
98 	/*
99 	 * location of the latest lvid
100 	 */
101 	uint32_t	lvid_loc;
102 	uint32_t	lvid_len;
103 
104 	uint16_t	fsds_prn;
105 	uint32_t	fsds_loc;
106 	uint32_t	fsds_len;
107 	/*
108 	 * Location of the most usable fsd
109 	 * on WORM we have to follow till the
110 	 * end of the chain
111 	 * FSD location is absolute disk location
112 	 * after translating using maps and partitions
113 	 */
114 	uint32_t	fsd_loc;
115 	uint32_t	fsd_len;
116 
117 	uint16_t	ricb_prn;
118 	uint32_t	ricb_loc;
119 	uint32_t	ricb_len;
120 
121 	uint32_t	vat_icb_loc;
122 	uint32_t	vat_icb_len;
123 };
124 
125 struct ud_part {
126 	uint16_t	udp_flags;	/* See below */
127 #define	UDP_BITMAPS	0x00
128 #define	UDP_SPACETBLS	0x01
129 
130 	uint16_t	udp_number;	/* partition Number */
131 	uint32_t	udp_seqno;	/* to find the prevailaing desc */
132 	uint32_t	udp_access;	/* access type */
133 	uint32_t	udp_start;	/* Starting block no of partition */
134 	uint32_t	udp_length;	/* Lenght of the partition */
135 	uint32_t	udp_unall_loc;	/* unall space tbl or bitmap loc */
136 	uint32_t	udp_unall_len;	/* unall space tbl or bitmap length */
137 	uint32_t	udp_freed_loc;	/* freed space tbl or bitmap loc */
138 	uint32_t	udp_freed_len;	/* freed space tbl or bitmap length */
139 					/* From part desc */
140 
141 	uint32_t	udp_nfree;	/* No of free blocks in the partition */
142 	uint32_t	udp_nblocks;	/* Total no of blks in the partition */
143 					/* From lvid */
144 };
145 
146 
147 struct ud_map {
148 	uint16_t	udm_flags;
149 #define	UDM_MAP_NORM	0x00
150 #define	UDM_MAP_VPM	0x01
151 #define	UDM_MAP_SPM	0x02
152 
153 	uint16_t	udm_vsn;
154 	uint16_t	udm_pn;
155 
156 	uint32_t	udm_vat_icb_loc;
157 	uint32_t	udm_nent;
158 	uint32_t	*udm_count;
159 	struct buf	**udm_bp;
160 	uint32_t	**udm_addr;
161 
162 	int32_t		udm_plen;
163 	int32_t		udm_nspm;
164 	uint32_t	udm_spsz;
165 	uint32_t	udm_loc[MAX_SPM];
166 	struct buf	*udm_sbp[MAX_SPM];
167 	caddr_t		udm_spaddr[MAX_SPM];
168 };
169 
170 
171 
172 #define	REG_DOM_ID	0x1
173 #define	REG_UDF_ID	0x2
174 #define	REG_UDF_II	0x4
175 
176 #define	EI_FLG_DIRTY	0x01
177 #define	EI_FLG_PROT	0x02
178 
179 struct dom_id_suffix {
180 	uint16_t	dis_udf_revison;
181 	uint8_t		dis_domain_flags;
182 	uint8_t		dis_pad[5];
183 };
184 
185 #define	PROTECT_SOFT_WRITE	0x01
186 #define	PROTECT_HARD_WRITE	0x02
187 
188 struct udf_id_suffix {
189 	uint16_t	uis_udf_revision;
190 	uint8_t		uis_os_class;
191 	uint8_t		uis_os_identifier;
192 	uint8_t		uis_pad[4];
193 };
194 
195 struct impl_id_suffix {
196 	uint8_t		iis_os_class;
197 	uint8_t		iis_os_identifier;
198 	uint8_t		iis_pad[6];
199 };
200 
201 #define	OS_CLASS_UNDEFINED	0x00
202 #define	OS_CLASS_DOS_WIN3x	0x01
203 #define	OS_CLASS_OS_2		0x02
204 #define	OS_CLASS_MAC_OS_7	0x02
205 #define	OS_CLASS_UNIX		0x04
206 #define	OS_CLASS_WIN_95		0x05
207 #define	OS_CLASS_WIN_NT		0x06
208 
209 #define	OS_IDENTIFIER_GENERIC	0x00
210 #define	OS_IDENTIFIER_IBM_AIX	0x01
211 #define	OS_IDENTIFIER_SOLARIS	0x02
212 #define	OS_IDENTIFIER_HP_UX	0x03
213 #define	OS_IDENTIFIER_SG_IRIX	0x04
214 #define	OS_IDENTIFIER_LINUX	0x05
215 #define	OS_IDENTIFIER_MK_LINUX	0x06
216 #define	OS_IDENTIFIER_FREE_BSD	0x07
217 
218 struct ud_handle {
219 	int		fd;
220 	struct udf	udfs;
221 	struct ud_part	part[MAX_PARTS];
222 	int32_t		n_parts;
223 	struct ud_map	maps[MAX_MAPS];
224 	int32_t		n_maps;
225 };
226 
227 typedef struct ud_handle *ud_handle_t;
228 
229 
230 int	ud_init(int, ud_handle_t *);
231 void	ud_fini(ud_handle_t);
232 int32_t	ud_open_dev(ud_handle_t, char *, uint32_t);
233 void	ud_close_dev(ud_handle_t);
234 int32_t	ud_read_dev(ud_handle_t, uint64_t, uint8_t *, uint32_t);
235 int32_t	ud_write_dev(ud_handle_t, uint64_t, uint8_t *, uint32_t);
236 
237 int32_t	ud_fill_udfs_info(ud_handle_t);
238 int32_t ud_get_num_blks(ud_handle_t, uint32_t *);
239 
240 int32_t ud_verify_tag(ud_handle_t, struct tag *,
241 	uint16_t, uint32_t, int32_t, int32_t);
242 void	ud_make_tag(ud_handle_t, struct tag *, uint16_t, uint32_t, uint16_t);
243 uint32_t ud_xlate_to_daddr(ud_handle_t, uint16_t, uint32_t);
244 void	ud_convert2local(int8_t *, int8_t *, int32_t);
245 
246 void	print_charspec(FILE *, char *, struct charspec *);
247 void	print_dstring(FILE *, char *, uint16_t, char *, uint8_t);
248 void	set_dstring(dstring_t *, char *, int32_t);
249 void	print_tstamp(FILE *, char *, tstamp_t *);
250 void	print_regid(FILE *, char *, struct regid *, int32_t);
251 
252 void	print_ext_ad(FILE *, char *, struct extent_ad *);
253 void	print_tag(FILE *, struct tag *);
254 void	print_pvd(FILE *, struct pri_vol_desc *);
255 void	print_avd(FILE *, struct anch_vol_desc_ptr *);
256 void	print_vdp(FILE *, struct vol_desc_ptr *);
257 void	print_iuvd(FILE *, struct iuvd_desc *);
258 void	print_part(FILE *, struct part_desc *);
259 void	print_lvd(FILE *, struct log_vol_desc *);
260 void	print_usd(FILE *, struct unall_spc_desc *);
261 void	print_lvid(FILE *, struct log_vol_int_desc *);
262 void	print_part(FILE *, struct part_desc *);
263 
264 void	print_fsd(FILE *, ud_handle_t h, struct file_set_desc *);
265 void	print_phdr(FILE *, struct phdr_desc *);
266 void	print_fid(FILE *, struct file_id *);
267 void	print_aed(FILE *, struct alloc_ext_desc *);
268 void	print_icb_tag(FILE *, struct icb_tag *);
269 void	print_ie(FILE *, struct indirect_entry *);
270 void	print_td(FILE *, struct term_desc *);
271 void	print_fe(FILE *, struct file_entry *);
272 void	print_pmaps(FILE *, uint8_t *, int32_t);
273 void	print_short_ad(FILE *, char *, struct short_ad *);
274 void	print_long_ad(FILE *, char *, struct long_ad *);
275 
276 #ifdef	__cplusplus
277 }
278 #endif
279 
280 #endif	/* _UD_LIB_H */
281