1 /* $NetBSD: disklabel.h,v 1.1 2002/03/06 02:13:41 simonb Exp $ */ 2 3 /* 4 * Copyright 2000, 2001 5 * Broadcom Corporation. All rights reserved. 6 * 7 * This software is furnished under license and may be used and copied only 8 * in accordance with the following terms and conditions. Subject to these 9 * conditions, you may download, copy, install, use, modify and distribute 10 * modified or unmodified copies of this software in source and/or binary 11 * form. No title or ownership is transferred hereby. 12 * 13 * 1) Any source code used, modified or distributed must reproduce and 14 * retain this copyright notice and list of conditions as they appear in 15 * the source file. 16 * 17 * 2) No right is granted to use any trade name, trademark, or logo of 18 * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any 19 * trademark or logo of Broadcom Corporation may be used to endorse or 20 * promote products derived from this software without the prior written 21 * permission of Broadcom Corporation. 22 * 23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED 24 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 26 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE 27 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE 28 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36 /* from: $NetBSD: disklabel.h,v 1.4 2000/05/05 03:27:22 soren Exp */ 37 38 /* 39 * Copyright (c) 1994 Christopher G. Demetriou 40 * All rights reserved. 41 * 42 * Redistribution and use in source and binary forms, with or without 43 * modification, are permitted provided that the following conditions 44 * are met: 45 * 1. Redistributions of source code must retain the above copyright 46 * notice, this list of conditions and the following disclaimer. 47 * 2. Redistributions in binary form must reproduce the above copyright 48 * notice, this list of conditions and the following disclaimer in the 49 * documentation and/or other materials provided with the distribution. 50 * 3. All advertising materials mentioning features or use of this software 51 * must display the following acknowledgement: 52 * This product includes software developed by Christopher G. Demetriou. 53 * 4. The name of the author may not be used to endorse or promote products 54 * derived from this software without specific prior written permission 55 * 56 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 57 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 58 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 59 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 60 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 61 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 62 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 63 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 64 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 65 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 66 */ 67 68 #ifndef _MACHINE_DISKLABEL_H_ 69 #define _MACHINE_DISKLABEL_H_ 70 71 #define LABELSECTOR 1 /* sector containing label */ 72 #define LABELOFFSET 0 /* offset of label in sector */ 73 #define MAXPARTITIONS 16 74 #define RAW_PART 3 75 76 #ifdef __NetBSD__ 77 /* Pull in MBR partition definitions. */ 78 #include <sys/disklabel_mbr.h> 79 80 #ifndef __ASSEMBLER__ 81 #include <sys/dkbad.h> 82 struct cpu_disklabel { 83 struct mbr_partition dosparts[NMBRPART]; 84 struct dkbad bad; 85 }; 86 #endif 87 #endif 88 89 /* 90 * CFE boot block, modeled loosely on Alpha. 91 * 92 * It consists of: 93 * 94 * BSD disk label 95 * <blank space> 96 * Boot block info (5 uint_64s) 97 * 98 * The boot block portion looks like: 99 * 100 * 101 * +-------+-------+-------+-------+-------+-------+-------+-------+ 102 * | BOOT_MAGIC_NUMBER | 103 * +-------+-------+-------+-------+-------+-------+-------+-------+ 104 * | Flags | Reserved | Vers | Header Checksum | 105 * +-------+-------+-------+-------+-------+-------+-------+-------+ 106 * | Secondary Loader Location (bytes) | 107 * +-------+-------+-------+-------+-------+-------+-------+-------+ 108 * | Loader Checksum | Size of loader (bytes) | 109 * +-------+-------+-------+-------+-------+-------+-------+-------+ 110 * | Reserved | Architecture Information | 111 * +-------+-------+-------+-------+-------+-------+-------+-------+ 112 * 113 * Boot block fields should always be read as 64-bit numbers. 114 * 115 */ 116 117 118 struct boot_block { 119 uint64_t bb_data[64]; /* data (disklabel, also as below) */ 120 }; 121 #define bb_magic bb_data[59] /* magic number */ 122 #define bb_hdrinfo bb_data[60] /* header checksum, ver, flags */ 123 #define bb_secstart bb_data[61] /* secondary start (bytes) */ 124 #define bb_secsize bb_data[62] /* secondary size (bytes) */ 125 #define bb_archinfo bb_data[63] /* architecture info */ 126 127 #define BOOT_BLOCK_OFFSET 0 /* offset of boot block. */ 128 #define BOOT_BLOCK_BLOCKSIZE 512 /* block size for sec. size/start, 129 * and for boot block itself 130 */ 131 #define BOOT_BLOCK_SIZE 40 /* 5 64-bit words */ 132 133 #define BOOT_MAGIC_NUMBER 0x43465631424f4f54 134 #define BOOT_HDR_CHECKSUM_MASK 0x00000000FFFFFFFF 135 #define BOOT_HDR_VER_MASK 0x000000FF00000000 136 #define BOOT_HDR_VER_SHIFT 32 137 #define BOOT_HDR_FLAGS_MASK 0xFF00000000000000 138 #define BOOT_SECSIZE_MASK 0x00000000FFFFFFFF 139 #define BOOT_DATA_CHECKSUM_MASK 0xFFFFFFFF00000000 140 #define BOOT_DATA_CHECKSUM_SHIFT 32 141 #define BOOT_ARCHINFO_MASK 0x00000000FFFFFFFF 142 143 #define BOOT_HDR_VERSION 1 144 145 #define CHECKSUM_BOOT_BLOCK(bb,cksum) \ 146 do { \ 147 uint32_t *_ptr = (uint32_t *) (bb); \ 148 uint32_t _cksum; \ 149 int _i; \ 150 \ 151 _cksum = 0; \ 152 for (_i = 0; \ 153 _i < (BOOT_BLOCK_SIZE / sizeof (uint32_t)); \ 154 _i++) \ 155 _cksum += _ptr[_i]; \ 156 *(cksum) = _cksum; \ 157 } while (0) 158 159 160 #define CHECKSUM_BOOT_DATA(data,len,cksum) \ 161 do { \ 162 uint32_t *_ptr = (uint32_t *) (data); \ 163 uint32_t _cksum; \ 164 int _i; \ 165 \ 166 _cksum = 0; \ 167 for (_i = 0; \ 168 _i < ((len) / sizeof (uint32_t)); \ 169 _i++) \ 170 _cksum += _ptr[_i]; \ 171 *(cksum) = _cksum; \ 172 } while (0) 173 174 175 #endif /* _MACHINE_DISKLABEL_H_ */ 176