disklabel.h revision 1.6
1/* $OpenBSD: disklabel.h,v 1.6 2006/06/26 23:11:31 krw 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 52struct dos_partition { 53 u_int8_t dp_flag; /* default boot flag */ 54 u_int8_t dp_shd; /* start head, IsN't Always Meaningful */ 55 u_int8_t dp_ssect; /* start sector, INAM */ 56 u_int8_t dp_scyl; /* start cylinder, INAM */ 57 u_int8_t dp_typ; /* partition type */ 58 u_int8_t dp_ehd; /* end head, INAM */ 59 u_int8_t dp_esect; /* end sector, INAM */ 60 u_int8_t dp_ecyl; /* end cylinder, INAM */ 61 u_int32_t dp_start; /* absolute start sector number */ 62 u_int32_t 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_FAT16L 0x0e /* 16-bit FAT, LBA-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 87static __inline u_int32_t get_le(void *); 88 89static __inline u_int32_t 90get_le(void *p) 91{ 92 u_int8_t *_p = (u_int8_t *)p; 93 u_int32_t x; 94 x = _p[0]; 95 x |= _p[1] << 8; 96 x |= _p[2] << 16; 97 x |= _p[3] << 24; 98 return x; 99} 100 101/* HFS/DPME */ 102 103/* partition map structure from Inside Macintosh: Devices, SCSI Manager 104 * pp. 13-14. The partition map always begins on physical block 1. 105 * 106 * With the exception of block 0, all blocks on the disk must belong to 107 * exactly one partition. The partition map itself belongs to a partition 108 * of type `APPLE_PARTITION_MAP', and is not limited in size by anything 109 * other than available disk space. The partition map is not necessarily 110 * the first partition listed. 111 */ 112struct part_map_entry { 113#define PART_ENTRY_MAGIC 0x504d 114 u_int16_t pmSig; /* partition signature */ 115 u_int16_t pmSigPad; /* (reserved) */ 116 u_int32_t pmMapBlkCnt; /* number of blocks in partition map */ 117 u_int32_t pmPyPartStart; /* first physical block of partition */ 118 u_int32_t pmPartBlkCnt; /* number of blocks in partition */ 119 char pmPartName[32]; /* partition name */ 120 char pmPartType[32]; /* partition type */ 121 u_int32_t pmLgDataStart; /* first logical block of data area */ 122 u_int32_t pmDataCnt; /* number of blocks in data area */ 123 u_int32_t pmPartStatus; /* partition status information */ 124 u_int32_t pmLgBootStart; /* first logical block of boot code */ 125 u_int32_t pmBootSize; /* size of boot code, in bytes */ 126 u_int32_t pmBootLoad; /* boot code load address */ 127 u_int32_t pmBootLoad2; /* (reserved) */ 128 u_int32_t pmBootEntry; /* boot code entry point */ 129 u_int32_t pmBootEntry2; /* (reserved) */ 130 u_int32_t pmBootCksum; /* boot code checksum */ 131 char pmProcessor[16]; /* processor type (e.g. "68020") */ 132 u_int8_t pmBootArgs[128]; /* A/UX boot arguments */ 133 /* we do not index the disk image as an array, 134 * leave out the on disk padding 135 */ 136#if 0 137 u_int8_t pad[248]; /* pad to end of block */ 138#endif 139}; 140 141#define PART_TYPE_DRIVER "APPLE_DRIVER" 142#define PART_TYPE_DRIVER43 "APPLE_DRIVER43" 143#define PART_TYPE_DRIVERATA "APPLE_DRIVER_ATA" 144#define PART_TYPE_DRIVERIOKIT "APPLE_DRIVER_IOKIT" 145#define PART_TYPE_FWDRIVER "APPLE_FWDRIVER" 146#define PART_TYPE_FWB_COMPONENT "FWB DRIVER COMPONENTS" 147#define PART_TYPE_FREE "APPLE_FREE" 148#define PART_TYPE_MAC "APPLE_HFS" 149#define PART_TYPE_OPENBSD "OPENBSD" 150 151 152struct cpu_disklabel { 153 struct dos_partition dosparts[NDOSPART]; 154 /* only store first entry and openbsd partition */ 155 struct part_map_entry macparts[2]; 156 struct dkbad bad; 157}; 158 159#define DKBAD(x) ((x)->bad) 160 161#endif /* _MACHINE_DISKLABEL_H_ */ 162