1 /* $OpenBSD: disklabel.h,v 1.6 2003/01/14 22:38:36 mickey Exp $ */ 2 /* $NetBSD: disklabel.h,v 1.1 1995/02/13 23:07:34 cgd Exp $ */ 3 4 /* 5 * Copyright (c) 1994 Christopher G. Demetriou 6 * All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by Christopher G. Demetriou. 19 * 4. The name of the author may not be used to endorse or promote products 20 * derived from this software without specific prior written permission 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 #ifndef _MACHINE_DISKLABEL_H_ 35 #define _MACHINE_DISKLABEL_H_ 36 37 enum disklabel_tag { DLT_ALPHA, DLT_I386, DLT_AMIGA, DLT_HPPA }; 38 39 /* 40 * What disklabels are we probing for, and in which order? 41 */ 42 #ifndef LABELPROBES 43 #define LABELPROBES DLT_ALPHA, DLT_I386, DLT_AMIGA, DLT_HPPA 44 #endif 45 46 #define ALPHA_LABELSECTOR 0 /* sector containing label */ 47 #define ALPHA_LABELOFFSET 64 /* offset of label in sector */ 48 #define I386_LABELSECTOR 1 /* sector containing label */ 49 #define I386_LABELOFFSET 0 /* offset of label in sector */ 50 #define AMIGA_LABELSECTOR 0 /* sector containing label */ 51 #define AMIGA_LABELOFFSET 64 /* offset of label in sector */ 52 #define HPPA_LABELSECTOR 1 /* sector containing label */ 53 #define HPPA_LABELOFFSET 0 /* offset of label in sector */ 54 55 #define LABELSECTOR HPPA_LABELSECTOR 56 #define LABELOFFSET HPPA_LABELOFFSET 57 58 #define MAXPARTITIONS 16 /* number of partitions */ 59 #define RAW_PART 2 /* raw partition: xx?c */ 60 61 /* DOS partition table -- located in boot block */ 62 #define DOSBBSECTOR 0 /* DOS boot block relative sector # */ 63 #define DOSPARTOFF 446 64 #define DOSACTIVE 0x80 65 #define NDOSPART 4 66 #define DOSMBR_SIGNATURE 0xaa55 67 #define DOSMBR_SIGNATURE_OFF 0x1fe 68 69 struct dos_partition { 70 u_int8_t dp_flag; /* bootstrap flags */ 71 u_int8_t dp_shd; /* starting head */ 72 u_int8_t dp_ssect; /* starting sector */ 73 u_int8_t dp_scyl; /* starting cylinder */ 74 u_int8_t dp_typ; /* partition type (see below) */ 75 u_int8_t dp_ehd; /* end head */ 76 u_int8_t dp_esect; /* end sector */ 77 u_int8_t dp_ecyl; /* end cylinder */ 78 u_int32_t dp_start; /* absolute starting sector number */ 79 u_int32_t dp_size; /* partition size in sectors */ 80 }; 81 82 /* Known DOS partition types. */ 83 #define DOSPTYP_UNUSED 0x00 /* Unused partition */ 84 #define DOSPTYP_FAT12 0x01 /* 12-bit FAT */ 85 #define DOSPTYP_FAT16S 0x04 /* 16-bit FAT, less than 32M */ 86 #define DOSPTYP_EXTEND 0x05 /* Extended; contains sub-partitions */ 87 #define DOSPTYP_FAT16B 0x06 /* 16-bit FAT, more than 32M */ 88 #define DOSPTYP_FAT32 0x0b /* 32-bit FAT */ 89 #define DOSPTYP_FAT32L 0x0c /* 32-bit FAT, LBA-mapped */ 90 #define DOSPTYP_FAT16L 0x0e /* 16-bit FAT, LBA-mapped */ 91 #define DOSPTYP_ONTRACK 0x54 92 #define DOSPTYP_LINUX 0x83 /* That other thing */ 93 #define DOSPTYP_FREEBSD 0xa5 /* FreeBSD partition type */ 94 #define DOSPTYP_OPENBSD 0xa6 /* OpenBSD partition type */ 95 #define DOSPTYP_NETBSD 0xa9 /* NetBSD partition type */ 96 97 /* Isolate the relevant bits to get sector and cylinder. */ 98 #define DPSECT(s) ((s) & 0x3f) 99 #define DPCYL(c, s) ((c) + (((s) & 0xc0) << 2)) 100 101 /* 102 * describes ados Rigid Disk Blocks 103 * which are used to partition a drive 104 */ 105 #define RDBNULL ((u_int32_t)0xffffffff) 106 107 /* 108 * you will find rdblock somewhere in [0, RDBMAXBLOCKS) 109 */ 110 #define RDB_MAXBLOCKS 16 111 112 struct rdblock { 113 u_int32_t id; /* 'RDSK' */ 114 u_int32_t nsumlong; /* number of longs in check sum */ 115 u_int32_t chksum; /* simple additive with wrap checksum */ 116 u_int32_t hostid; /* scsi target of host */ 117 u_int32_t nbytes; /* size of disk blocks */ 118 u_int32_t flags; 119 u_int32_t badbhead; /* linked list of badblocks */ 120 u_int32_t partbhead; /* linked list of partblocks */ 121 u_int32_t fsbhead; /* " " of fsblocks */ 122 u_int32_t driveinit; 123 u_int32_t resv1[6]; /* RDBNULL */ 124 u_int32_t ncylinders; /* number of cylinders on drive */ 125 u_int32_t nsectors; /* number of sectors per track */ 126 u_int32_t nheads; /* number of tracks per cylinder */ 127 u_int32_t interleave; 128 u_int32_t park; /* only used with st506 i.e. not */ 129 u_int32_t resv2[3]; 130 u_int32_t wprecomp; /* start cyl for write precomp */ 131 u_int32_t reducedwrite; /* start cyl for reduced write current */ 132 u_int32_t steprate; /* driver step rate in ?s */ 133 u_int32_t resv3[5]; 134 u_int32_t rdblowb; /* lowblock of range for rdb's */ 135 u_int32_t rdbhighb; /* high block of range for rdb's */ 136 u_int32_t lowcyl; /* low cylinder of partition area */ 137 u_int32_t highcyl; /* upper cylinder of partition area */ 138 u_int32_t secpercyl; /* number of sectors per cylinder */ 139 u_int32_t parkseconds; /* zero if no park needed */ 140 u_int32_t resv4[2]; 141 char diskvendor[8]; /* inquiry stuff */ 142 char diskproduct[16]; /* inquiry stuff */ 143 char diskrevision[4]; /* inquiry stuff */ 144 char contvendor[8]; /* inquiry stuff */ 145 char contproduct[16]; /* inquiry stuff */ 146 char contrevision[4]; /* inquiry stuff */ 147 #if never_use_secsize 148 u_int32_t resv5[0]; 149 #endif 150 }; 151 152 153 #define RDBF_LAST 0x1 /* last drive available */ 154 #define RDBF_LASTLUN 0x2 /* last LUN available */ 155 #define RDBF_LASTUNIT 0x4 /* last target available */ 156 #define RDBF_NORESELECT 0x8 /* do not use reselect */ 157 #define RDBF_DISKID 0x10 /* disk id is valid ?? */ 158 #define RDBF_CTRLID 0x20 /* ctrl id is valid ?? */ 159 #define RDBF_SYNC 0x40 /* drive supports SCSI synchronous mode */ 160 161 struct ados_environ { 162 u_int32_t tabsize; /* 0: environ table size */ 163 u_int32_t sizeblock; /* 1: n long words in a block */ 164 u_int32_t secorg; /* 2: not used must be zero */ 165 u_int32_t numheads; /* 3: number of surfaces */ 166 u_int32_t secperblk; /* 4: must be 1 */ 167 u_int32_t secpertrk; /* 5: blocks per track */ 168 u_int32_t resvblocks; /* 6: reserved blocks at start */ 169 u_int32_t prefac; /* 7: must be 0 */ 170 u_int32_t interleave; /* 8: normally 1 */ 171 u_int32_t lowcyl; /* 9: low cylinder of partition */ 172 u_int32_t highcyl; /* 10: upper cylinder of partition */ 173 u_int32_t numbufs; /* 11: ados: number of buffers */ 174 u_int32_t membuftype; /* 12: ados: type of bufmem */ 175 u_int32_t maxtrans; /* 13: maxtrans the ctrlr supports */ 176 u_int32_t mask; /* 14: mask for valid address */ 177 u_int32_t bootpri; /* 15: boot priority for autoboot */ 178 u_int32_t dostype; /* 16: filesystem type */ 179 u_int32_t baud; /* 17: serial handler baud rate */ 180 u_int32_t control; /* 18: control word for fs */ 181 u_int32_t bootblocks; /* 19: blocks containing boot code */ 182 u_int32_t fsize; /* 20: file system block size */ 183 u_int32_t frag; /* 21: allowable frags per block */ 184 u_int32_t cpg; /* 22: cylinders per group */ 185 }; 186 187 struct partblock { 188 u_int32_t id; /* 'PART' */ 189 u_int32_t nsumlong; /* number of longs in check sum */ 190 u_int32_t chksum; /* simple additive with wrap checksum */ 191 u_int32_t hostid; /* scsi target of host */ 192 u_int32_t next; /* next in chain */ 193 u_int32_t flags; /* see below */ 194 u_int32_t resv1[3]; 195 u_char partname[32]; /* (BCPL) part name (may not be unique) */ 196 u_int32_t resv2[15]; 197 struct ados_environ e; 198 #if never_use_secsize 199 u_int32_t extra[9]; /* 8 for extra added to environ */ 200 #endif 201 }; 202 203 #define PBF_BOOTABLE 0x1 /* partition is bootable */ 204 #define PBF_NOMOUNT 0x2 /* partition should be mounted */ 205 206 struct badblock { 207 u_int32_t id; /* 'BADB' */ 208 u_int32_t nsumlong; /* number of longs in check sum */ 209 u_int32_t chksum; /* simple additive with wrap checksum */ 210 u_int32_t hostid; /* scsi target of host */ 211 u_int32_t next; /* next in chain */ 212 u_int32_t resv; 213 struct badblockent { 214 u_int32_t badblock; 215 u_int32_t goodblock; 216 } badtab[0]; /* 61 for secsize == 512 */ 217 }; 218 219 struct fsblock { 220 u_int32_t id; /* 'FSHD' */ 221 u_int32_t nsumlong; /* number of longs in check sum */ 222 u_int32_t chksum; /* simple additive with wrap checksum */ 223 u_int32_t hostid; /* scsi target of host */ 224 u_int32_t next; /* next in chain */ 225 u_int32_t flags; 226 u_int32_t resv1[2]; 227 u_int32_t dostype; /* this is a file system for this type */ 228 u_int32_t version; /* version of this fs */ 229 u_int32_t patchflags; /* describes which functions to replace */ 230 u_int32_t type; /* zero */ 231 u_int32_t task; /* zero */ 232 u_int32_t lock; /* zero */ 233 u_int32_t handler; /* zero */ 234 u_int32_t stacksize; /* to use when loading handler */ 235 u_int32_t priority; /* to run the fs at. */ 236 u_int32_t startup; /* zero */ 237 u_int32_t lsegblocks; /* linked list of lsegblocks of fs code */ 238 u_int32_t globalvec; /* bcpl vector not used mostly */ 239 #if never_use_secsize 240 u_int32_t resv2[44]; 241 #endif 242 }; 243 244 struct lsegblock { 245 u_int32_t id; /* 'LSEG' */ 246 u_int32_t nsumlong; /* number of longs in check sum */ 247 u_int32_t chksum; /* simple additive with wrap checksum */ 248 u_int32_t hostid; /* scsi target of host */ 249 u_int32_t next; /* next in chain */ 250 u_int32_t loaddata[0]; /* load segment data, 123 for secsize == 512 */ 251 }; 252 253 #define RDBLOCK_ID 0x5244534b /* 'RDSK' */ 254 #define PARTBLOCK_ID 0x50415254 /* 'PART' */ 255 #define BADBLOCK_ID 0x42414442 /* 'BADB' */ 256 #define FSBLOCK_ID 0x46534844 /* 'FSHD' */ 257 #define LSEGBLOCK_ID 0x4c534547 /* 'LSEG' */ 258 259 /* 260 * volume header for "LIF" format volumes 261 */ 262 struct lifvol { 263 short vol_id; 264 char vol_label[6]; 265 u_int vol_addr; 266 short vol_oct; 267 short vol_dummy; 268 u_int vol_dirsize; 269 short vol_version; 270 short vol_zero; 271 u_int vol_number; 272 u_int vol_lastvol; 273 u_int vol_length; 274 char vol_toc[6]; 275 char vol_dummy1[198]; 276 277 u_int ipl_addr; 278 u_int ipl_size; 279 u_int ipl_entry; 280 281 u_int vol_dummy2; 282 }; 283 284 struct lifdir { 285 char dir_name[10]; 286 u_short dir_type; 287 u_int dir_addr; 288 u_int dir_length; 289 char dir_toc[6]; 290 short dir_flag; 291 u_int dir_implement; 292 }; 293 294 struct lif_load { 295 int address; 296 int count; 297 }; 298 299 #define LIF_VOL_ID -32768 300 #define LIF_VOL_OCT 4096 301 #define LIF_DIR_SWAP 0x5243 302 #define LIF_DIR_FS 0xcd38 303 #define LIF_DIR_IOMAP 0xcd60 304 #define LIF_DIR_HPUX 0xcd80 305 #define LIF_DIR_ISL 0xce00 306 #define LIF_DIR_PAD 0xcffe 307 #define LIF_DIR_AUTO 0xcfff 308 #define LIF_DIR_EST 0xd001 309 #define LIF_DIR_TYPE 0xe942 310 311 #define LIF_DIR_FLAG 0x8001 /* dont ask me! */ 312 #define LIF_SECTSIZE 256 313 314 #define LIF_NUMDIR 8 315 316 #define LIF_VOLSTART 0 317 #define LIF_VOLSIZE sizeof(struct lifvol) 318 #define LIF_DIRSTART 2048 319 #define LIF_DIRSIZE (LIF_NUMDIR * sizeof(struct lifdir)) 320 #define LIF_FILESTART 8192 321 322 #define btolifs(b) (((b) + (LIF_SECTSIZE - 1)) / LIF_SECTSIZE) 323 #define lifstob(s) ((s) * LIF_SECTSIZE) 324 #define lifstodb(s) ((s) * LIF_SECTSIZE / DEV_BSIZE) 325 326 #include <sys/dkbad.h> 327 struct cpu_disklabel { 328 enum disklabel_tag labeltag; 329 int labelsector; 330 union { 331 struct { 332 } _alpha; 333 struct { 334 struct dos_partition dosparts[NDOSPART]; 335 struct dkbad bad; 336 } _i386; 337 struct { 338 u_int32_t rdblock; /* RDBNULL -> inval. */ 339 u_int32_t pblist[MAXPARTITIONS];/* pblock number */ 340 int pbindex[MAXPARTITIONS]; /* index of pblock */ 341 int valid; /* valid? */ 342 } _amiga; 343 struct { 344 struct lifvol lifvol; 345 struct lifdir lifdir[LIF_NUMDIR]; 346 } _hppa; 347 } u; 348 }; 349 350 #define DKBAD(x) ((x)->u._i386.bad) 351 352 #endif /* _MACHINE_DISKLABEL_H_ */ 353