1 /* $OpenBSD: disklabel.h,v 1.4 2002/09/15 09:01:58 deraadt Exp $ */ 2 3 /* 4 * Copyright (c) 1994 Christopher G. Demetriou 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 3. All advertising materials mentioning features or use of this software 16 * must display the following acknowledgement: 17 * This product includes software developed by Christopher G. Demetriou. 18 * 4. The name of the author may not be used to endorse or promote products 19 * derived from this software without specific prior written permission 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 #ifndef _MACHINE_DISKLABEL_H_ 34 #define _MACHINE_DISKLABEL_H_ 35 36 #define LABELSECTOR 1 /* sector containing label */ 37 #define LABELOFFSET 0 /* offset of label in sector */ 38 #define MAXPARTITIONS 16 /* number of partitions */ 39 #define RAW_PART 2 /* raw partition: ie. rsd0c */ 40 41 /* MBR partition table */ 42 #define DOSBBSECTOR 0 /* MBR sector number */ 43 #define DOSPARTOFF 446 /* Offset of MBR partition table */ 44 #define NDOSPART 4 /* # of partitions in MBR */ 45 #define DOSMAGICOFF 510 /* Offset of magic number */ 46 #define DOSMAGIC 0xaa55 /* Actual magic number */ 47 #define MBRMAGIC DOSMAGIC 48 #define DOSMBR_SIGNATURE MBRMAGIC 49 #define DOSMBR_SIGNATURE_OFF DOSMAGICOFF 50 #define DOSACTIVE 0x80 51 52 struct dos_partition { 53 unsigned char dp_flag; /* default boot flag */ 54 unsigned char dp_shd; /* start head, IsN't Always Meaningful */ 55 unsigned char dp_ssect; /* start sector, INAM */ 56 unsigned char dp_scyl; /* start cylinder, INAM */ 57 unsigned char dp_typ; /* partition type */ 58 unsigned char dp_ehd; /* end head, INAM */ 59 unsigned char dp_esect; /* end sector, INAM */ 60 unsigned char dp_ecyl; /* end cylinder, INAM */ 61 unsigned long dp_start; /* absolute start sector number */ 62 unsigned long dp_size; /* partition size in sectors */ 63 }; 64 65 /* Known DOS partition types. */ 66 #define DOSPTYP_UNUSED 0x00 /* Unused partition */ 67 #define DOSPTYP_FAT12 0x01 /* 12-bit FAT */ 68 #define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */ 69 #define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */ 70 #define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */ 71 #define DOSPTYP_FAT32 0x0b /* 32-bit FAT */ 72 #define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */ 73 #define DOSPTYP_FAT16C 0x0e /* 16-bit FAT, CHS-mapped */ 74 #define DOSPTYP_EXTENDL 0x0f /* Extended, LBA-mapped; contains sub-partitions */ 75 #define DOSPTYP_ONTRACK 0x54 76 #define DOSPTYP_LINUX 0x83 /* That other thing */ 77 #define DOSPTYP_FREEBSD 0xa5 /* FreeBSD partition type */ 78 #define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */ 79 #define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */ 80 81 #include <sys/dkbad.h> 82 83 /* Isolate the relevant bits to get sector and cylinder. */ 84 #define DPSECT(s) ((s) & 0x3f) 85 #define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2)) 86 87 static __inline u_int32_t get_le(void *p); 88 89 static __inline u_int32_t 90 #ifdef __cplusplus 91 get_le(void *p) 92 #else 93 get_le(p) 94 void *p; 95 #endif 96 { 97 u_int8_t *_p = (u_int8_t *)p; 98 int x; 99 x = _p[0]; 100 x |= _p[1] << 8; 101 x |= _p[2] << 16; 102 x |= _p[3] << 24; 103 return x; 104 } 105 106 /* HFS/DPME */ 107 108 /* partition map structure from Inside Macintosh: Devices, SCSI Manager 109 * pp. 13-14. The partition map always begins on physical block 1. 110 * 111 * With the exception of block 0, all blocks on the disk must belong to 112 * exactly one partition. The partition map itself belongs to a partition 113 * of type `APPLE_PARTITION_MAP', and is not limited in size by anything 114 * other than available disk space. The partition map is not necessarily 115 * the first partition listed. 116 */ 117 struct part_map_entry { 118 #define PART_ENTRY_MAGIC 0x504d 119 u_int16_t pmSig; /* partition signature */ 120 u_int16_t pmSigPad; /* (reserved) */ 121 u_int32_t pmMapBlkCnt; /* number of blocks in partition map */ 122 u_int32_t pmPyPartStart; /* first physical block of partition */ 123 u_int32_t pmPartBlkCnt; /* number of blocks in partition */ 124 char pmPartName[32]; /* partition name */ 125 char pmPartType[32]; /* partition type */ 126 u_int32_t pmLgDataStart; /* first logical block of data area */ 127 u_int32_t pmDataCnt; /* number of blocks in data area */ 128 u_int32_t pmPartStatus; /* partition status information */ 129 u_int32_t pmLgBootStart; /* first logical block of boot code */ 130 u_int32_t pmBootSize; /* size of boot code, in bytes */ 131 u_int32_t pmBootLoad; /* boot code load address */ 132 u_int32_t pmBootLoad2; /* (reserved) */ 133 u_int32_t pmBootEntry; /* boot code entry point */ 134 u_int32_t pmBootEntry2; /* (reserved) */ 135 u_int32_t pmBootCksum; /* boot code checksum */ 136 char pmProcessor[16]; /* processor type (e.g. "68020") */ 137 u_int8_t pmBootArgs[128]; /* A/UX boot arguments */ 138 /* we do not index the disk image as an array, 139 * leave out the on disk padding 140 */ 141 #if 0 142 u_int8_t pad[248]; /* pad to end of block */ 143 #endif 144 }; 145 146 #define PART_TYPE_DRIVER "APPLE_DRIVER" 147 #define PART_TYPE_DRIVER43 "APPLE_DRIVER43" 148 #define PART_TYPE_DRIVERATA "APPLE_DRIVER_ATA" 149 #define PART_TYPE_DRIVERIOKIT "APPLE_DRIVER_IOKIT" 150 #define PART_TYPE_FWDRIVER "APPLE_FWDRIVER" 151 #define PART_TYPE_FWB_COMPONENT "FWB DRIVER COMPONENTS" 152 #define PART_TYPE_FREE "APPLE_FREE" 153 #define PART_TYPE_MAC "APPLE_HFS" 154 #define PART_TYPE_OPENBSD "OPENBSD" 155 156 157 struct cpu_disklabel { 158 struct dos_partition dosparts[NDOSPART]; 159 /* only store first entry and openbsd partition */ 160 struct part_map_entry macparts[2]; 161 struct dkbad bad; 162 }; 163 164 #define DKBAD(x) ((x)->bad) 165 166 #endif /* _MACHINE_DISKLABEL_H_ */ 167