10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*2212Sartem * Common Development and Distribution License (the "License"). 6*2212Sartem * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*2212Sartem * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 23*2212Sartem * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #ifndef _UD_LIB_H 270Sstevel@tonic-gate #define _UD_LIB_H 280Sstevel@tonic-gate 290Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 300Sstevel@tonic-gate 310Sstevel@tonic-gate #ifdef __cplusplus 320Sstevel@tonic-gate extern "C" { 330Sstevel@tonic-gate #endif 340Sstevel@tonic-gate 350Sstevel@tonic-gate #define UD_VOL_REC_START (32 * 1024) 360Sstevel@tonic-gate #define UD_VOL_REC_BSZ 2048 370Sstevel@tonic-gate #define UD_VOL_REC_END (256 * UD_VOL_REC_BSZ) 380Sstevel@tonic-gate 390Sstevel@tonic-gate #define UD_ECMA_VER2 0x00000002 400Sstevel@tonic-gate #define UD_ECMA_VER3 0x00000003 410Sstevel@tonic-gate #define UD_ECMA_UNKN 0xFFFFFFFF 420Sstevel@tonic-gate 430Sstevel@tonic-gate #define MAX_PARTS 10 440Sstevel@tonic-gate #define MAX_MAPS 10 450Sstevel@tonic-gate #define MAX_SPM 4 460Sstevel@tonic-gate 470Sstevel@tonic-gate #define lb_roundup(sz, lbsz) \ 480Sstevel@tonic-gate (((sz) + (lbsz - 1)) & (~(lbsz - 1))) 490Sstevel@tonic-gate 500Sstevel@tonic-gate struct vds { 510Sstevel@tonic-gate uint32_t pvd_loc; 520Sstevel@tonic-gate uint32_t pvd_len; 530Sstevel@tonic-gate uint32_t pvd_vdsn; 540Sstevel@tonic-gate 550Sstevel@tonic-gate uint32_t iud_loc; 560Sstevel@tonic-gate uint32_t iud_len; 570Sstevel@tonic-gate 580Sstevel@tonic-gate uint32_t part_loc[MAX_PARTS]; 590Sstevel@tonic-gate uint32_t part_len[MAX_PARTS]; 600Sstevel@tonic-gate 610Sstevel@tonic-gate uint32_t lvd_loc; 620Sstevel@tonic-gate uint32_t lvd_len; 630Sstevel@tonic-gate uint32_t lvd_vdsn; 640Sstevel@tonic-gate 650Sstevel@tonic-gate uint32_t usd_loc; 660Sstevel@tonic-gate uint32_t usd_len; 670Sstevel@tonic-gate }; 680Sstevel@tonic-gate 690Sstevel@tonic-gate /* 700Sstevel@tonic-gate * All addresses are the lbsize block numbers 710Sstevel@tonic-gate * offseted into the partition 720Sstevel@tonic-gate */ 730Sstevel@tonic-gate struct udf { 740Sstevel@tonic-gate uint32_t flags; 750Sstevel@tonic-gate #define INVALID_UDFS 0x0000 760Sstevel@tonic-gate #define VALID_UDFS 0x0001 770Sstevel@tonic-gate #define VALID_MVDS 0x0002 780Sstevel@tonic-gate #define VALID_RVDS 0x0004 790Sstevel@tonic-gate 800Sstevel@tonic-gate uint32_t ecma_version; 810Sstevel@tonic-gate uint8_t ecma_id[5]; 820Sstevel@tonic-gate 830Sstevel@tonic-gate uint16_t mi_read; 840Sstevel@tonic-gate uint16_t ma_read; 850Sstevel@tonic-gate uint16_t ma_write; 860Sstevel@tonic-gate 870Sstevel@tonic-gate uint32_t lbsize; 880Sstevel@tonic-gate 890Sstevel@tonic-gate uint32_t avdp_loc; /* First Readable avdp */ 900Sstevel@tonic-gate uint32_t avdp_len; 910Sstevel@tonic-gate 920Sstevel@tonic-gate uint32_t mvds_loc; 930Sstevel@tonic-gate uint32_t mvds_len; 940Sstevel@tonic-gate uint32_t rvds_len; 950Sstevel@tonic-gate uint32_t rvds_loc; 960Sstevel@tonic-gate 970Sstevel@tonic-gate struct vds mvds; 980Sstevel@tonic-gate struct vds rvds; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate /* 1010Sstevel@tonic-gate * location of the latest lvid 1020Sstevel@tonic-gate */ 1030Sstevel@tonic-gate uint32_t lvid_loc; 1040Sstevel@tonic-gate uint32_t lvid_len; 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate uint16_t fsds_prn; 1070Sstevel@tonic-gate uint32_t fsds_loc; 1080Sstevel@tonic-gate uint32_t fsds_len; 1090Sstevel@tonic-gate /* 1100Sstevel@tonic-gate * Location of the most usable fsd 1110Sstevel@tonic-gate * on WORM we have to follow till the 1120Sstevel@tonic-gate * end of the chain 1130Sstevel@tonic-gate * FSD location is absolute disk location 1140Sstevel@tonic-gate * after translating using maps and partitions 1150Sstevel@tonic-gate */ 1160Sstevel@tonic-gate uint32_t fsd_loc; 1170Sstevel@tonic-gate uint32_t fsd_len; 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate uint16_t ricb_prn; 1200Sstevel@tonic-gate uint32_t ricb_loc; 1210Sstevel@tonic-gate uint32_t ricb_len; 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate uint32_t vat_icb_loc; 1240Sstevel@tonic-gate uint32_t vat_icb_len; 1250Sstevel@tonic-gate }; 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate struct ud_part { 1280Sstevel@tonic-gate uint16_t udp_flags; /* See below */ 1290Sstevel@tonic-gate #define UDP_BITMAPS 0x00 1300Sstevel@tonic-gate #define UDP_SPACETBLS 0x01 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate uint16_t udp_number; /* partition Number */ 1330Sstevel@tonic-gate uint32_t udp_seqno; /* to find the prevailaing desc */ 1340Sstevel@tonic-gate uint32_t udp_access; /* access type */ 1350Sstevel@tonic-gate uint32_t udp_start; /* Starting block no of partition */ 1360Sstevel@tonic-gate uint32_t udp_length; /* Lenght of the partition */ 1370Sstevel@tonic-gate uint32_t udp_unall_loc; /* unall space tbl or bitmap loc */ 1380Sstevel@tonic-gate uint32_t udp_unall_len; /* unall space tbl or bitmap length */ 1390Sstevel@tonic-gate uint32_t udp_freed_loc; /* freed space tbl or bitmap loc */ 1400Sstevel@tonic-gate uint32_t udp_freed_len; /* freed space tbl or bitmap length */ 1410Sstevel@tonic-gate /* From part desc */ 1420Sstevel@tonic-gate 1430Sstevel@tonic-gate uint32_t udp_nfree; /* No of free blocks in the partition */ 1440Sstevel@tonic-gate uint32_t udp_nblocks; /* Total no of blks in the partition */ 1450Sstevel@tonic-gate /* From lvid */ 1460Sstevel@tonic-gate }; 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate 1490Sstevel@tonic-gate struct ud_map { 1500Sstevel@tonic-gate uint16_t udm_flags; 1510Sstevel@tonic-gate #define UDM_MAP_NORM 0x00 1520Sstevel@tonic-gate #define UDM_MAP_VPM 0x01 1530Sstevel@tonic-gate #define UDM_MAP_SPM 0x02 1540Sstevel@tonic-gate 1550Sstevel@tonic-gate uint16_t udm_vsn; 1560Sstevel@tonic-gate uint16_t udm_pn; 1570Sstevel@tonic-gate 1580Sstevel@tonic-gate uint32_t udm_vat_icb_loc; 1590Sstevel@tonic-gate uint32_t udm_nent; 1600Sstevel@tonic-gate uint32_t *udm_count; 1610Sstevel@tonic-gate struct buf **udm_bp; 1620Sstevel@tonic-gate uint32_t **udm_addr; 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate int32_t udm_plen; 1650Sstevel@tonic-gate int32_t udm_nspm; 1660Sstevel@tonic-gate uint32_t udm_spsz; 1670Sstevel@tonic-gate uint32_t udm_loc[MAX_SPM]; 1680Sstevel@tonic-gate struct buf *udm_sbp[MAX_SPM]; 1690Sstevel@tonic-gate caddr_t udm_spaddr[MAX_SPM]; 1700Sstevel@tonic-gate }; 1710Sstevel@tonic-gate 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate 1740Sstevel@tonic-gate #define REG_DOM_ID 0x1 1750Sstevel@tonic-gate #define REG_UDF_ID 0x2 1760Sstevel@tonic-gate #define REG_UDF_II 0x4 1770Sstevel@tonic-gate 1780Sstevel@tonic-gate #define EI_FLG_DIRTY 0x01 1790Sstevel@tonic-gate #define EI_FLG_PROT 0x02 1800Sstevel@tonic-gate 1810Sstevel@tonic-gate struct dom_id_suffix { 1820Sstevel@tonic-gate uint16_t dis_udf_revison; 1830Sstevel@tonic-gate uint8_t dis_domain_flags; 1840Sstevel@tonic-gate uint8_t dis_pad[5]; 1850Sstevel@tonic-gate }; 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate #define PROTECT_SOFT_WRITE 0x01 1880Sstevel@tonic-gate #define PROTECT_HARD_WRITE 0x02 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate struct udf_id_suffix { 1910Sstevel@tonic-gate uint16_t uis_udf_revision; 1920Sstevel@tonic-gate uint8_t uis_os_class; 1930Sstevel@tonic-gate uint8_t uis_os_identifier; 1940Sstevel@tonic-gate uint8_t uis_pad[4]; 1950Sstevel@tonic-gate }; 1960Sstevel@tonic-gate 1970Sstevel@tonic-gate struct impl_id_suffix { 1980Sstevel@tonic-gate uint8_t iis_os_class; 1990Sstevel@tonic-gate uint8_t iis_os_identifier; 2000Sstevel@tonic-gate uint8_t iis_pad[6]; 2010Sstevel@tonic-gate }; 2020Sstevel@tonic-gate 2030Sstevel@tonic-gate #define OS_CLASS_UNDEFINED 0x00 2040Sstevel@tonic-gate #define OS_CLASS_DOS_WIN3x 0x01 2050Sstevel@tonic-gate #define OS_CLASS_OS_2 0x02 2060Sstevel@tonic-gate #define OS_CLASS_MAC_OS_7 0x02 2070Sstevel@tonic-gate #define OS_CLASS_UNIX 0x04 2080Sstevel@tonic-gate #define OS_CLASS_WIN_95 0x05 2090Sstevel@tonic-gate #define OS_CLASS_WIN_NT 0x06 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate #define OS_IDENTIFIER_GENERIC 0x00 2120Sstevel@tonic-gate #define OS_IDENTIFIER_IBM_AIX 0x01 2130Sstevel@tonic-gate #define OS_IDENTIFIER_SOLARIS 0x02 2140Sstevel@tonic-gate #define OS_IDENTIFIER_HP_UX 0x03 2150Sstevel@tonic-gate #define OS_IDENTIFIER_SG_IRIX 0x04 2160Sstevel@tonic-gate #define OS_IDENTIFIER_LINUX 0x05 2170Sstevel@tonic-gate #define OS_IDENTIFIER_MK_LINUX 0x06 2180Sstevel@tonic-gate #define OS_IDENTIFIER_FREE_BSD 0x07 2190Sstevel@tonic-gate 220*2212Sartem struct ud_handle { 221*2212Sartem int fd; 222*2212Sartem struct udf udfs; 223*2212Sartem struct ud_part part[MAX_PARTS]; 224*2212Sartem int32_t n_parts; 225*2212Sartem struct ud_map maps[MAX_MAPS]; 226*2212Sartem int32_t n_maps; 227*2212Sartem }; 2280Sstevel@tonic-gate 229*2212Sartem typedef struct ud_handle *ud_handle_t; 2300Sstevel@tonic-gate 2310Sstevel@tonic-gate 232*2212Sartem int ud_init(int, ud_handle_t *); 233*2212Sartem void ud_fini(ud_handle_t); 234*2212Sartem int32_t ud_open_dev(ud_handle_t, char *, uint32_t); 235*2212Sartem void ud_close_dev(ud_handle_t); 236*2212Sartem int32_t ud_read_dev(ud_handle_t, uint64_t, uint8_t *, uint32_t); 237*2212Sartem int32_t ud_write_dev(ud_handle_t, uint64_t, uint8_t *, uint32_t); 238*2212Sartem 239*2212Sartem int32_t ud_fill_udfs_info(ud_handle_t); 240*2212Sartem int32_t ud_get_num_blks(ud_handle_t, uint32_t *); 241*2212Sartem 242*2212Sartem int32_t ud_verify_tag(ud_handle_t, struct tag *, 243*2212Sartem uint16_t, uint32_t, int32_t, int32_t); 244*2212Sartem void ud_make_tag(ud_handle_t, struct tag *, uint16_t, uint32_t, uint16_t); 245*2212Sartem uint32_t ud_xlate_to_daddr(ud_handle_t, uint16_t, uint32_t); 246*2212Sartem void ud_convert2local(int8_t *, int8_t *, int32_t); 247*2212Sartem 248*2212Sartem void print_charspec(FILE *, char *, struct charspec *); 249*2212Sartem void print_dstring(FILE *, char *, uint16_t, char *, uint8_t); 250*2212Sartem void set_dstring(dstring_t *, char *, int32_t); 251*2212Sartem void print_tstamp(FILE *, char *, tstamp_t *); 252*2212Sartem void print_regid(FILE *, char *, struct regid *, int32_t); 2530Sstevel@tonic-gate 254*2212Sartem void print_ext_ad(FILE *, char *, struct extent_ad *); 255*2212Sartem void print_tag(FILE *, struct tag *); 256*2212Sartem void print_pvd(FILE *, struct pri_vol_desc *); 257*2212Sartem void print_avd(FILE *, struct anch_vol_desc_ptr *); 258*2212Sartem void print_vdp(FILE *, struct vol_desc_ptr *); 259*2212Sartem void print_iuvd(FILE *, struct iuvd_desc *); 260*2212Sartem void print_part(FILE *, struct part_desc *); 261*2212Sartem void print_lvd(FILE *, struct log_vol_desc *); 262*2212Sartem void print_usd(FILE *, struct unall_spc_desc *); 263*2212Sartem void print_lvid(FILE *, struct log_vol_int_desc *); 264*2212Sartem void print_part(FILE *, struct part_desc *); 2650Sstevel@tonic-gate 266*2212Sartem void print_fsd(FILE *, ud_handle_t h, struct file_set_desc *); 267*2212Sartem void print_phdr(FILE *, struct phdr_desc *); 268*2212Sartem void print_fid(FILE *, struct file_id *); 269*2212Sartem void print_aed(FILE *, struct alloc_ext_desc *); 270*2212Sartem void print_icb_tag(FILE *, struct icb_tag *); 271*2212Sartem void print_ie(FILE *, struct indirect_entry *); 272*2212Sartem void print_td(FILE *, struct term_desc *); 273*2212Sartem void print_fe(FILE *, struct file_entry *); 274*2212Sartem void print_pmaps(FILE *, uint8_t *, int32_t); 275*2212Sartem void print_short_ad(FILE *, char *, struct short_ad *); 276*2212Sartem void print_long_ad(FILE *, char *, struct long_ad *); 2770Sstevel@tonic-gate 2780Sstevel@tonic-gate #ifdef __cplusplus 2790Sstevel@tonic-gate } 2800Sstevel@tonic-gate #endif 2810Sstevel@tonic-gate 2820Sstevel@tonic-gate #endif /* _UD_LIB_H */ 283