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