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