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