1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 3*7c478bd9Sstevel@tonic-gate * 4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*7c478bd9Sstevel@tonic-gate * with the License. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 12*7c478bd9Sstevel@tonic-gate * and limitations under the License. 13*7c478bd9Sstevel@tonic-gate * 14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*7c478bd9Sstevel@tonic-gate * 20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 21*7c478bd9Sstevel@tonic-gate */ 22*7c478bd9Sstevel@tonic-gate /* 23*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _PCFILEP_H 28*7c478bd9Sstevel@tonic-gate #define _PCFILEP_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 31*7c478bd9Sstevel@tonic-gate extern "C" { 32*7c478bd9Sstevel@tonic-gate #endif 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #define MAX_DOSMOUNT_RETRIES 3 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #define TICKS_PER_SEC 18 /* It's really 18.2! */ 37*7c478bd9Sstevel@tonic-gate #define SECSIZ 512 38*7c478bd9Sstevel@tonic-gate #define fat_bpc(i) (pi[(i)]->f_bpb.bs_spc * SECSIZ) 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate /* 41*7c478bd9Sstevel@tonic-gate * Access permissions for dosAccess(), dosOpen() 42*7c478bd9Sstevel@tonic-gate * NOTE: These permission need to match those for the DOS compiler. 43*7c478bd9Sstevel@tonic-gate */ 44*7c478bd9Sstevel@tonic-gate #define FILE_EXISTS 1 45*7c478bd9Sstevel@tonic-gate #define FILE_READ 0x0000 46*7c478bd9Sstevel@tonic-gate #define FILE_WRITE 0x0001 47*7c478bd9Sstevel@tonic-gate #define FILE_RDWR 0x0002 48*7c478bd9Sstevel@tonic-gate #define FILE_APPEND 0x0008 49*7c478bd9Sstevel@tonic-gate #define FILE_CREATE 0x0100 50*7c478bd9Sstevel@tonic-gate #define FILE_TRUNC 0x0200 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate #define TYPE_EMPTY 0x00 /* undefined partition */ 53*7c478bd9Sstevel@tonic-gate #define TYPE_DOS 0x13 /* causes fatInit() to search for */ 54*7c478bd9Sstevel@tonic-gate /* active partition */ 55*7c478bd9Sstevel@tonic-gate #define TYPE_DOS_12 0x01 /* partition with FAT12 filesys */ 56*7c478bd9Sstevel@tonic-gate #define TYPE_DOS_16 0x04 /* partition with FAT16 filesys */ 57*7c478bd9Sstevel@tonic-gate #define TYPE_DOS_EXT 0x05 /* not bootable, ignore */ 58*7c478bd9Sstevel@tonic-gate #define TYPE_HUGH 0x06 /* HUGH partition */ 59*7c478bd9Sstevel@tonic-gate #define TYPE_COMPAQ 0x12 /* Compaq's diag partition */ 60*7c478bd9Sstevel@tonic-gate #define TYPE_SOLARIS 0x82 61*7c478bd9Sstevel@tonic-gate #define TYPE_SOLARIS_BOOT 0xBE /* For "boot hill" project */ 62*7c478bd9Sstevel@tonic-gate 63*7c478bd9Sstevel@tonic-gate #define FDISK_START 0x1be /* location in first sector where */ 64*7c478bd9Sstevel@tonic-gate /* the fdisk starts. */ 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate #define FDISK_PARTS 4 /* Number of partitions in a fdisk */ 67*7c478bd9Sstevel@tonic-gate #define FDISK_ACTIVE 0x80 /* indicates partition is active */ 68*7c478bd9Sstevel@tonic-gate #define FDISK_INACTIVE 0x00 /* " partition inactive */ 69*7c478bd9Sstevel@tonic-gate 70*7c478bd9Sstevel@tonic-gate #pragma pack(1) 71*7c478bd9Sstevel@tonic-gate struct _fdisk_partition_ { 72*7c478bd9Sstevel@tonic-gate uchar_t fd_active; 73*7c478bd9Sstevel@tonic-gate uchar_t fd_b_head; 74*7c478bd9Sstevel@tonic-gate uchar_t fd_b_sec; 75*7c478bd9Sstevel@tonic-gate uchar_t fd_b_cyl; 76*7c478bd9Sstevel@tonic-gate uchar_t fd_type; 77*7c478bd9Sstevel@tonic-gate uchar_t fd_e_head; 78*7c478bd9Sstevel@tonic-gate uchar_t fd_e_sec; 79*7c478bd9Sstevel@tonic-gate uchar_t fd_e_cyl; 80*7c478bd9Sstevel@tonic-gate union { 81*7c478bd9Sstevel@tonic-gate long fd_start_sec_long; 82*7c478bd9Sstevel@tonic-gate struct { 83*7c478bd9Sstevel@tonic-gate ushort_t low; 84*7c478bd9Sstevel@tonic-gate ushort_t high; 85*7c478bd9Sstevel@tonic-gate } s; 86*7c478bd9Sstevel@tonic-gate } u; 87*7c478bd9Sstevel@tonic-gate long fd_part_len; 88*7c478bd9Sstevel@tonic-gate }; 89*7c478bd9Sstevel@tonic-gate #define fd_start_sec u.fd_start_sec_long 90*7c478bd9Sstevel@tonic-gate #define fd_partition fd_type 91*7c478bd9Sstevel@tonic-gate typedef struct _fdisk_partition_ _fdisk_t, *_fdisk_p; 92*7c478bd9Sstevel@tonic-gate #pragma pack() 93*7c478bd9Sstevel@tonic-gate 94*7c478bd9Sstevel@tonic-gate #pragma pack(1) 95*7c478bd9Sstevel@tonic-gate struct _boot_sector_ { 96*7c478bd9Sstevel@tonic-gate uchar_t bs_jump_code[3]; 97*7c478bd9Sstevel@tonic-gate uchar_t bs_oem_name[8]; 98*7c478bd9Sstevel@tonic-gate uchar_t bs_bytes_sector[2]; 99*7c478bd9Sstevel@tonic-gate uchar_t bs_spc; /* ... sectors per cluster */ 100*7c478bd9Sstevel@tonic-gate uchar_t bs_resv_sectors[2]; 101*7c478bd9Sstevel@tonic-gate uchar_t bs_num_fats; 102*7c478bd9Sstevel@tonic-gate uchar_t bs_num_root_entries[2]; 103*7c478bd9Sstevel@tonic-gate uchar_t bs_siv[2]; /* ... sectors in volume */ 104*7c478bd9Sstevel@tonic-gate uchar_t bs_media; 105*7c478bd9Sstevel@tonic-gate uchar_t bs_spf[2]; /* ... sectors per fat */ 106*7c478bd9Sstevel@tonic-gate uchar_t bs_sectors_per_track[2]; 107*7c478bd9Sstevel@tonic-gate uchar_t bs_heads[2]; 108*7c478bd9Sstevel@tonic-gate /* 109*7c478bd9Sstevel@tonic-gate * Byte offset at this point is 28 so we can declare the next 110*7c478bd9Sstevel@tonic-gate * variable with the correct type and not worry about alignment. 111*7c478bd9Sstevel@tonic-gate */ 112*7c478bd9Sstevel@tonic-gate long bs_hidden_sectors; 113*7c478bd9Sstevel@tonic-gate long bs_lsiv; /* ... logical sectors in volume */ 114*7c478bd9Sstevel@tonic-gate uchar_t bs_phys_drive_num; 115*7c478bd9Sstevel@tonic-gate uchar_t bs_reserved; 116*7c478bd9Sstevel@tonic-gate uchar_t bs_ext_signature; 117*7c478bd9Sstevel@tonic-gate char bs_volume_id[4]; 118*7c478bd9Sstevel@tonic-gate char bs_volume_label[11]; 119*7c478bd9Sstevel@tonic-gate char bs_type[8]; 120*7c478bd9Sstevel@tonic-gate 121*7c478bd9Sstevel@tonic-gate /* ---- ADDED BY SUNSOFT FOR MDBOOT ---- */ 122*7c478bd9Sstevel@tonic-gate ushort_t bs_offset_high; 123*7c478bd9Sstevel@tonic-gate ushort_t bs_offset_low; 124*7c478bd9Sstevel@tonic-gate }; 125*7c478bd9Sstevel@tonic-gate #pragma pack() 126*7c478bd9Sstevel@tonic-gate typedef struct _boot_sector_ _boot_sector_t, *_boot_sector_p; 127*7c478bd9Sstevel@tonic-gate 128*7c478bd9Sstevel@tonic-gate /* 129*7c478bd9Sstevel@tonic-gate * Cluster types 130*7c478bd9Sstevel@tonic-gate */ 131*7c478bd9Sstevel@tonic-gate #define CLUSTER_AVAIL 0x00 132*7c478bd9Sstevel@tonic-gate #define CLUSTER_RES_12_0 0x0ff0 /* 12bit fat, first reserved */ 133*7c478bd9Sstevel@tonic-gate #define CLUSTER_RES_12_6 0x0ff6 /* 12bit fat, last reserved */ 134*7c478bd9Sstevel@tonic-gate #define CLUSTER_RES_16_0 0xfff0 /* 16bit fat, first reserved */ 135*7c478bd9Sstevel@tonic-gate #define CLUSTER_RES_16_6 0xfff6 /* 16bit fat, last reserved */ 136*7c478bd9Sstevel@tonic-gate #define CLUSTER_BAD_12 0x0ff7 /* 12bit fat, bad entry */ 137*7c478bd9Sstevel@tonic-gate #define CLUSTER_BAD_16 0xfff7 /* 16bit fat, bad entry */ 138*7c478bd9Sstevel@tonic-gate #define CLUSTER_EOF CLUSTER_EOF_16_0 139*7c478bd9Sstevel@tonic-gate #define CLUSTER_MAX_12 0x0ff7 /* max clusters for 12bit fat */ 140*7c478bd9Sstevel@tonic-gate #define CLUSTER_EOF_12_0 0x0ff8 /* 12bit fat, EOF first entry */ 141*7c478bd9Sstevel@tonic-gate #define CLUSTER_EOF_12_8 0x0fff /* 12bit fat, EOF last entry */ 142*7c478bd9Sstevel@tonic-gate #define CLUSTER_EOF_16_0 0xfff8 /* 16bit fat, EOF first entry */ 143*7c478bd9Sstevel@tonic-gate #define CLUSTER_EOF_16_8 0xffff /* 16bit fat, EOF last entry */ 144*7c478bd9Sstevel@tonic-gate 145*7c478bd9Sstevel@tonic-gate /* 146*7c478bd9Sstevel@tonic-gate * Cluster operations for allocation 147*7c478bd9Sstevel@tonic-gate */ 148*7c478bd9Sstevel@tonic-gate #define CLUSTER_NOOP 0x0001 /* ... just allocate cluster */ 149*7c478bd9Sstevel@tonic-gate #define CLUSTER_ZEROFILL 0x0002 /* ... zero fill the alloc'd cluster */ 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate #define CLUSTER_FIRST 0x0002 /* ... first cluster number to search */ 152*7c478bd9Sstevel@tonic-gate #define CLUSTER_ROOTDIR 0x0000 /* ... root dir's cluster number */ 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate /* 155*7c478bd9Sstevel@tonic-gate * This structure is filled in by initFAT() 156*7c478bd9Sstevel@tonic-gate */ 157*7c478bd9Sstevel@tonic-gate struct _fat_controller_ { 158*7c478bd9Sstevel@tonic-gate union { 159*7c478bd9Sstevel@tonic-gate _boot_sector_t fu_bpb; /* boot parameter block */ 160*7c478bd9Sstevel@tonic-gate uchar_t fu_sector[SECSIZ]; 161*7c478bd9Sstevel@tonic-gate } fu; 162*7c478bd9Sstevel@tonic-gate long f_adjust; /* starting sec for part. */ 163*7c478bd9Sstevel@tonic-gate long f_rootsec; /* root dir starting sec. */ 164*7c478bd9Sstevel@tonic-gate long f_rootlen; /* length of root in sectors */ 165*7c478bd9Sstevel@tonic-gate long f_filesec; /* adjustment for clusters */ 166*7c478bd9Sstevel@tonic-gate long f_dclust; /* cur dir cluster */ 167*7c478bd9Sstevel@tonic-gate int f_nxtfree; /* next free cluster */ 168*7c478bd9Sstevel@tonic-gate int f_ncluster; /* number of cluster in part */ 169*7c478bd9Sstevel@tonic-gate char f_16bit:1, /* 1 if 16bit fat entries */ 170*7c478bd9Sstevel@tonic-gate f_flush:1; /* flush the fat */ 171*7c478bd9Sstevel@tonic-gate }; 172*7c478bd9Sstevel@tonic-gate typedef struct _fat_controller_ _fat_controller_t, *_fat_controller_p; 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate #define f_bpb fu.fu_bpb 175*7c478bd9Sstevel@tonic-gate #define f_sector fu.fu_sector 176*7c478bd9Sstevel@tonic-gate 177*7c478bd9Sstevel@tonic-gate #define NAMESIZ 8 178*7c478bd9Sstevel@tonic-gate #define EXTSIZ 3 179*7c478bd9Sstevel@tonic-gate #pragma pack(1) 180*7c478bd9Sstevel@tonic-gate struct _dir_entry_ { 181*7c478bd9Sstevel@tonic-gate char d_name[NAMESIZ]; 182*7c478bd9Sstevel@tonic-gate char d_ext[EXTSIZ]; 183*7c478bd9Sstevel@tonic-gate uchar_t d_attr; 184*7c478bd9Sstevel@tonic-gate char d_res[10]; 185*7c478bd9Sstevel@tonic-gate short d_time; 186*7c478bd9Sstevel@tonic-gate short d_date; 187*7c478bd9Sstevel@tonic-gate ushort_t d_cluster; 188*7c478bd9Sstevel@tonic-gate long d_size; 189*7c478bd9Sstevel@tonic-gate }; 190*7c478bd9Sstevel@tonic-gate #pragma pack() 191*7c478bd9Sstevel@tonic-gate typedef struct _dir_entry_ _dir_entry_t, *_dir_entry_p; 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate /* 194*7c478bd9Sstevel@tonic-gate * Number of entries in one sector 195*7c478bd9Sstevel@tonic-gate */ 196*7c478bd9Sstevel@tonic-gate #define DIRENTS (SECSIZ / sizeof (_dir_entry_t)) 197*7c478bd9Sstevel@tonic-gate 198*7c478bd9Sstevel@tonic-gate /* 199*7c478bd9Sstevel@tonic-gate * Directory entry attributes 200*7c478bd9Sstevel@tonic-gate */ 201*7c478bd9Sstevel@tonic-gate #define DE_READONLY 0x01 202*7c478bd9Sstevel@tonic-gate #define DE_HIDDEN 0x02 203*7c478bd9Sstevel@tonic-gate #define DE_SYSTEM 0x04 204*7c478bd9Sstevel@tonic-gate #define DE_LABEL 0x08 205*7c478bd9Sstevel@tonic-gate #define DE_DIRECTORY 0x10 206*7c478bd9Sstevel@tonic-gate #define DE_ARCHIVE 0x20 207*7c478bd9Sstevel@tonic-gate #define DE_RESERVED1 0x40 208*7c478bd9Sstevel@tonic-gate #define DE_RESERVED2 0x80 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate #define DE_IS_LFN (DE_READONLY | DE_HIDDEN | DE_SYSTEM | DE_LABEL) 211*7c478bd9Sstevel@tonic-gate 212*7c478bd9Sstevel@tonic-gate struct _file_descriptor_ { 213*7c478bd9Sstevel@tonic-gate struct _file_descriptor_ *f_forw; /* link to next file descriptor */ 214*7c478bd9Sstevel@tonic-gate int f_desc; /* descriptor number */ 215*7c478bd9Sstevel@tonic-gate long f_startclust; /* starting cluster number */ 216*7c478bd9Sstevel@tonic-gate long f_off; /* current offset */ 217*7c478bd9Sstevel@tonic-gate long f_len; /* size of file */ 218*7c478bd9Sstevel@tonic-gate long f_index; /* index into directory block */ 219*7c478bd9Sstevel@tonic-gate uchar_t f_attr; /* attributes */ 220*7c478bd9Sstevel@tonic-gate int f_volidx; /* Volume device index */ 221*7c478bd9Sstevel@tonic-gate char *f_volname; /* Name of volume */ 222*7c478bd9Sstevel@tonic-gate }; 223*7c478bd9Sstevel@tonic-gate typedef struct _file_descriptor_ _file_desc_t, *_file_desc_p; 224*7c478bd9Sstevel@tonic-gate 225*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 226*7c478bd9Sstevel@tonic-gate } 227*7c478bd9Sstevel@tonic-gate #endif 228*7c478bd9Sstevel@tonic-gate 229*7c478bd9Sstevel@tonic-gate #endif /* _PCFILEP_H */ 230