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 (c) 1996, 1998, 1999 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #ifndef _MKFS_PCFS_H 28*7c478bd9Sstevel@tonic-gate #define _MKFS_PCFS_H 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gate #ifdef __cplusplus 33*7c478bd9Sstevel@tonic-gate extern "C" { 34*7c478bd9Sstevel@tonic-gate #endif 35*7c478bd9Sstevel@tonic-gate 36*7c478bd9Sstevel@tonic-gate #define BPSEC 512 /* Assumed # of bytes per sector */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #define OPCODE1 0xE9 39*7c478bd9Sstevel@tonic-gate #define OPCODE2 0xEB 40*7c478bd9Sstevel@tonic-gate #define BOOTSECSIG 0xAA55 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate /* 43*7c478bd9Sstevel@tonic-gate * Offset (in bytes) from address of boot sector to where we put 44*7c478bd9Sstevel@tonic-gate * the backup copy of that sector. (FAT32 only) 45*7c478bd9Sstevel@tonic-gate */ 46*7c478bd9Sstevel@tonic-gate #define BKUP_BOOTSECT_OFFSET 0xC00 47*7c478bd9Sstevel@tonic-gate 48*7c478bd9Sstevel@tonic-gate #define uppercase(c) ((c) >= 'a' && (c) <= 'z' ? (c) - 'a' + 'A' : (c)) 49*7c478bd9Sstevel@tonic-gate 50*7c478bd9Sstevel@tonic-gate #define FAT12_TYPE_STRING "FAT12 " 51*7c478bd9Sstevel@tonic-gate #define FAT16_TYPE_STRING "FAT16 " 52*7c478bd9Sstevel@tonic-gate #define FAT32_TYPE_STRING "FAT32 " 53*7c478bd9Sstevel@tonic-gate 54*7c478bd9Sstevel@tonic-gate #define FAT12_ENTSPERSECT 341 55*7c478bd9Sstevel@tonic-gate #define FAT16_ENTSPERSECT 256 56*7c478bd9Sstevel@tonic-gate #define FAT32_ENTSPERSECT 128 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate #ifndef SUNIXOSBOOT 59*7c478bd9Sstevel@tonic-gate #define SUNIXOSBOOT 190 /* Solaris UNIX boot partition */ 60*7c478bd9Sstevel@tonic-gate #endif 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate /* 63*7c478bd9Sstevel@tonic-gate * A macro implementing a ceiling function for integer divides. 64*7c478bd9Sstevel@tonic-gate */ 65*7c478bd9Sstevel@tonic-gate #define idivceil(dvend, dvsor) \ 66*7c478bd9Sstevel@tonic-gate ((dvend)/(dvsor) + (((dvend)%(dvsor) == 0) ? 0 : 1)) 67*7c478bd9Sstevel@tonic-gate 68*7c478bd9Sstevel@tonic-gate /* 69*7c478bd9Sstevel@tonic-gate * Return values for the seek_XXX functions 70*7c478bd9Sstevel@tonic-gate */ 71*7c478bd9Sstevel@tonic-gate #define PART_NOT_FOUND 0 72*7c478bd9Sstevel@tonic-gate #define PART_FOUND 1 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate /* 75*7c478bd9Sstevel@tonic-gate * MS-DOS Disk layout: 76*7c478bd9Sstevel@tonic-gate * 77*7c478bd9Sstevel@tonic-gate * --------------------- 78*7c478bd9Sstevel@tonic-gate * | Boot sector | 79*7c478bd9Sstevel@tonic-gate * |-------------------| 80*7c478bd9Sstevel@tonic-gate * | Reserved area | 81*7c478bd9Sstevel@tonic-gate * |-------------------| 82*7c478bd9Sstevel@tonic-gate * | FAT #1 | 83*7c478bd9Sstevel@tonic-gate * |-------------------| 84*7c478bd9Sstevel@tonic-gate * | FAT #2 | 85*7c478bd9Sstevel@tonic-gate * |-------------------| 86*7c478bd9Sstevel@tonic-gate * | Root directory | 87*7c478bd9Sstevel@tonic-gate * |-------------------| 88*7c478bd9Sstevel@tonic-gate * | | 89*7c478bd9Sstevel@tonic-gate * | File area | 90*7c478bd9Sstevel@tonic-gate * |___________________| 91*7c478bd9Sstevel@tonic-gate */ 92*7c478bd9Sstevel@tonic-gate 93*7c478bd9Sstevel@tonic-gate #ifdef i386 94*7c478bd9Sstevel@tonic-gate #pragma pack(1) 95*7c478bd9Sstevel@tonic-gate #endif 96*7c478bd9Sstevel@tonic-gate struct _orig_bios_param_blk { 97*7c478bd9Sstevel@tonic-gate uint16_t bytes_sector; 98*7c478bd9Sstevel@tonic-gate uchar_t sectors_per_cluster; 99*7c478bd9Sstevel@tonic-gate uint16_t resv_sectors; 100*7c478bd9Sstevel@tonic-gate uchar_t num_fats; 101*7c478bd9Sstevel@tonic-gate uint16_t num_root_entries; 102*7c478bd9Sstevel@tonic-gate uint16_t sectors_in_volume; 103*7c478bd9Sstevel@tonic-gate uchar_t media; 104*7c478bd9Sstevel@tonic-gate uint16_t sectors_per_fat; 105*7c478bd9Sstevel@tonic-gate uint16_t sectors_per_track; 106*7c478bd9Sstevel@tonic-gate uint16_t heads; 107*7c478bd9Sstevel@tonic-gate uint32_t hidden_sectors; 108*7c478bd9Sstevel@tonic-gate uint32_t sectors_in_logical_volume; 109*7c478bd9Sstevel@tonic-gate }; 110*7c478bd9Sstevel@tonic-gate #ifdef i386 111*7c478bd9Sstevel@tonic-gate #pragma pack() 112*7c478bd9Sstevel@tonic-gate #endif 113*7c478bd9Sstevel@tonic-gate 114*7c478bd9Sstevel@tonic-gate #ifdef i386 115*7c478bd9Sstevel@tonic-gate #pragma pack(1) 116*7c478bd9Sstevel@tonic-gate #endif 117*7c478bd9Sstevel@tonic-gate struct _bpb32_extensions { 118*7c478bd9Sstevel@tonic-gate uint32_t big_sectors_per_fat; 119*7c478bd9Sstevel@tonic-gate uint16_t ext_flags; 120*7c478bd9Sstevel@tonic-gate uchar_t fs_vers_lo; 121*7c478bd9Sstevel@tonic-gate uchar_t fs_vers_hi; 122*7c478bd9Sstevel@tonic-gate uint32_t root_dir_clust; 123*7c478bd9Sstevel@tonic-gate uint16_t fsinfosec; 124*7c478bd9Sstevel@tonic-gate uint16_t backupboot; 125*7c478bd9Sstevel@tonic-gate uint16_t reserved[6]; 126*7c478bd9Sstevel@tonic-gate }; 127*7c478bd9Sstevel@tonic-gate #ifdef i386 128*7c478bd9Sstevel@tonic-gate #pragma pack() 129*7c478bd9Sstevel@tonic-gate #endif 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate #ifdef i386 132*7c478bd9Sstevel@tonic-gate #pragma pack(1) 133*7c478bd9Sstevel@tonic-gate #endif 134*7c478bd9Sstevel@tonic-gate struct _bpb_extensions { 135*7c478bd9Sstevel@tonic-gate uchar_t phys_drive_num; 136*7c478bd9Sstevel@tonic-gate uchar_t reserved; 137*7c478bd9Sstevel@tonic-gate uchar_t ext_signature; 138*7c478bd9Sstevel@tonic-gate uint32_t volume_id; 139*7c478bd9Sstevel@tonic-gate uchar_t volume_label[11]; 140*7c478bd9Sstevel@tonic-gate uchar_t type[8]; 141*7c478bd9Sstevel@tonic-gate }; 142*7c478bd9Sstevel@tonic-gate #ifdef i386 143*7c478bd9Sstevel@tonic-gate #pragma pack() 144*7c478bd9Sstevel@tonic-gate #endif 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate #ifdef i386 147*7c478bd9Sstevel@tonic-gate #pragma pack(1) 148*7c478bd9Sstevel@tonic-gate #endif 149*7c478bd9Sstevel@tonic-gate struct _sun_bpb_extensions { 150*7c478bd9Sstevel@tonic-gate uint16_t bs_offset_high; 151*7c478bd9Sstevel@tonic-gate uint16_t bs_offset_low; 152*7c478bd9Sstevel@tonic-gate }; 153*7c478bd9Sstevel@tonic-gate #ifdef i386 154*7c478bd9Sstevel@tonic-gate #pragma pack() 155*7c478bd9Sstevel@tonic-gate #endif 156*7c478bd9Sstevel@tonic-gate 157*7c478bd9Sstevel@tonic-gate /* 158*7c478bd9Sstevel@tonic-gate * bpb_t is a conglomeration of all the fields a bpb can have. Every 159*7c478bd9Sstevel@tonic-gate * bpb will have the orig_bios struct, but only FAT32's will have bpb32, 160*7c478bd9Sstevel@tonic-gate * and only Solaris boot diskettes will have the sunbpb structure. 161*7c478bd9Sstevel@tonic-gate */ 162*7c478bd9Sstevel@tonic-gate typedef struct _bios_param_blk { 163*7c478bd9Sstevel@tonic-gate struct _orig_bios_param_blk bpb; 164*7c478bd9Sstevel@tonic-gate struct _bpb32_extensions bpb32; 165*7c478bd9Sstevel@tonic-gate struct _bpb_extensions ebpb; 166*7c478bd9Sstevel@tonic-gate struct _sun_bpb_extensions sunbpb; 167*7c478bd9Sstevel@tonic-gate } bpb_t; 168*7c478bd9Sstevel@tonic-gate 169*7c478bd9Sstevel@tonic-gate #ifdef i386 170*7c478bd9Sstevel@tonic-gate #pragma pack(1) 171*7c478bd9Sstevel@tonic-gate struct _bpb_head { 172*7c478bd9Sstevel@tonic-gate uchar_t bs_jump_code[3]; 173*7c478bd9Sstevel@tonic-gate uchar_t bs_oem_name[8]; 174*7c478bd9Sstevel@tonic-gate struct _orig_bios_param_blk bs_bpb; 175*7c478bd9Sstevel@tonic-gate }; 176*7c478bd9Sstevel@tonic-gate #pragma pack() 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate #pragma pack(1) 179*7c478bd9Sstevel@tonic-gate struct _boot_sector { 180*7c478bd9Sstevel@tonic-gate struct _bpb_head bs_front; 181*7c478bd9Sstevel@tonic-gate struct _bpb_extensions bs_ebpb; 182*7c478bd9Sstevel@tonic-gate struct _sun_bpb_extensions bs_sebpb; 183*7c478bd9Sstevel@tonic-gate uchar_t bs_bootstrap[444]; 184*7c478bd9Sstevel@tonic-gate uchar_t bs_signature[2]; 185*7c478bd9Sstevel@tonic-gate }; 186*7c478bd9Sstevel@tonic-gate #pragma pack() 187*7c478bd9Sstevel@tonic-gate 188*7c478bd9Sstevel@tonic-gate #pragma pack(1) 189*7c478bd9Sstevel@tonic-gate struct _boot_sector32 { 190*7c478bd9Sstevel@tonic-gate struct _bpb_head bs_front; 191*7c478bd9Sstevel@tonic-gate struct _bpb32_extensions bs_bpb32; 192*7c478bd9Sstevel@tonic-gate struct _bpb_extensions bs_ebpb; 193*7c478bd9Sstevel@tonic-gate uchar_t bs_bootstrap[420]; 194*7c478bd9Sstevel@tonic-gate uchar_t bs_signature[2]; 195*7c478bd9Sstevel@tonic-gate }; 196*7c478bd9Sstevel@tonic-gate #pragma pack() 197*7c478bd9Sstevel@tonic-gate #else 198*7c478bd9Sstevel@tonic-gate #define ORIG_BPB_START_INDEX 8 /* index into filler field */ 199*7c478bd9Sstevel@tonic-gate #define EXT_BPB_START_INDEX 33 /* index into filler field */ 200*7c478bd9Sstevel@tonic-gate #define BPB_32_START_INDEX 33 /* index into filler field */ 201*7c478bd9Sstevel@tonic-gate #define EXT_BPB_32_START_INDEX 61 /* index into filler field */ 202*7c478bd9Sstevel@tonic-gate struct _boot_sector { 203*7c478bd9Sstevel@tonic-gate uchar_t bs_jump_code[3]; 204*7c478bd9Sstevel@tonic-gate uchar_t bs_filler[59]; 205*7c478bd9Sstevel@tonic-gate uchar_t bs_sun_bpb[4]; 206*7c478bd9Sstevel@tonic-gate uchar_t bs_bootstrap[444]; 207*7c478bd9Sstevel@tonic-gate uchar_t bs_signature[2]; 208*7c478bd9Sstevel@tonic-gate }; 209*7c478bd9Sstevel@tonic-gate 210*7c478bd9Sstevel@tonic-gate struct _boot_sector32 { 211*7c478bd9Sstevel@tonic-gate uchar_t bs_jump_code[3]; 212*7c478bd9Sstevel@tonic-gate uchar_t bs_filler[87]; 213*7c478bd9Sstevel@tonic-gate uchar_t bs_bootstrap[420]; 214*7c478bd9Sstevel@tonic-gate uchar_t bs_signature[2]; 215*7c478bd9Sstevel@tonic-gate }; 216*7c478bd9Sstevel@tonic-gate #endif 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate typedef union _ubso { 219*7c478bd9Sstevel@tonic-gate struct _boot_sector bs; 220*7c478bd9Sstevel@tonic-gate struct _boot_sector32 bs32; 221*7c478bd9Sstevel@tonic-gate struct mboot mb; 222*7c478bd9Sstevel@tonic-gate uchar_t buf[BPSEC]; 223*7c478bd9Sstevel@tonic-gate } boot_sector_t; 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 /* _MKFS_PCFS_H */ 230