1 /** $MirOS: src/sys/sys/disklabel.h,v 1.4 2007/09/18 20:12:10 tg Exp $ */ 2 /* $OpenBSD: disklabel.h,v 1.26 2005/03/29 16:30:21 deraadt Exp $ */ 3 /* $NetBSD: disklabel.h,v 1.41 1996/05/10 23:07:37 mark Exp $ */ 4 5 /* 6 * Copyright (c) 1987, 1988, 1993 7 * The Regents of the University of California. All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the University nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31 * SUCH DAMAGE. 32 * 33 * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 34 */ 35 36 /* 37 * Disk description table, see disktab(5) 38 */ 39 #define _PATH_DISKTAB "/etc/disktab" 40 #define DISKTAB "/etc/disktab" /* deprecated */ 41 42 /* 43 * Each disk has a label which includes information about the hardware 44 * disk geometry, filesystem partitions, and drive specific information. 45 * The location of the label, as well as the number of partitions the 46 * label can describe and the number of the "whole disk" (raw) 47 * paritition are machine dependent. 48 */ 49 #include <machine/disklabel.h> 50 51 /* 52 * The absolute maximum number of disk partitions allowed. 53 * This is the maximum value of MAXPARTITIONS for which 'struct disklabel' 54 * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware. 55 */ 56 #define MAXMAXPARTITIONS 22 57 #if MAXPARTITIONS > MAXMAXPARTITIONS 58 #warn beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS 59 #endif 60 61 /* 62 * Translate between device numbers and major/disk unit/disk partition. 63 */ 64 #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS) 65 #define DISKPART(dev) (minor(dev) % MAXPARTITIONS) 66 #define DISKMINOR(unit, part) \ 67 (((unit) * MAXPARTITIONS) + (part)) 68 #define MAKEDISKDEV(maj, unit, part) \ 69 (makedev((maj), DISKMINOR((unit), (part)))) 70 #define DISKLABELDEV(dev) \ 71 (MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART)) 72 73 #define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */ 74 75 #ifndef _LOCORE 76 struct disklabel { 77 u_int32_t d_magic; /* the magic number */ 78 u_int16_t d_type; /* drive type */ 79 u_int16_t d_subtype; /* controller/d_type specific */ 80 char d_typename[16]; /* type name, e.g. "eagle" */ 81 82 /* 83 * d_packname contains the pack identifier and is returned when 84 * the disklabel is read off the disk or in-core copy. 85 * d_boot0 and d_boot1 are the (optional) names of the 86 * primary (block 0) and secondary (block 1-15) bootstraps 87 * as found in /usr/mdec. These are returned when using 88 * getdiskbyname(3) to retrieve the values from /etc/disktab. 89 */ 90 union { 91 char un_d_packname[16]; /* pack identifier */ 92 struct { 93 char *un_d_boot0; /* primary bootstrap name */ 94 char *un_d_boot1; /* secondary bootstrap name */ 95 } un_b; 96 } d_un; 97 #define d_packname d_un.un_d_packname 98 #define d_boot0 d_un.un_b.un_d_boot0 99 #define d_boot1 d_un.un_b.un_d_boot1 100 101 /* disk geometry: */ 102 u_int32_t d_secsize; /* # of bytes per sector */ 103 u_int32_t d_nsectors; /* # of data sectors per track */ 104 u_int32_t d_ntracks; /* # of tracks per cylinder */ 105 u_int32_t d_ncylinders; /* # of data cylinders per unit */ 106 u_int32_t d_secpercyl; /* # of data sectors per cylinder */ 107 u_int32_t d_secperunit; /* # of data sectors per unit */ 108 109 /* 110 * Spares (bad sector replacements) below are not counted in 111 * d_nsectors or d_secpercyl. Spare sectors are assumed to 112 * be physical sectors which occupy space at the end of each 113 * track and/or cylinder. 114 */ 115 u_int16_t d_sparespertrack; /* # of spare sectors per track */ 116 u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */ 117 /* 118 * Alternate cylinders include maintenance, replacement, configuration 119 * description areas, etc. 120 */ 121 u_int32_t d_acylinders; /* # of alt. cylinders per unit */ 122 123 /* hardware characteristics: */ 124 /* 125 * d_interleave, d_trackskew and d_cylskew describe perturbations 126 * in the media format used to compensate for a slow controller. 127 * Interleave is physical sector interleave, set up by the 128 * formatter or controller when formatting. When interleaving is 129 * in use, logically adjacent sectors are not physically 130 * contiguous, but instead are separated by some number of 131 * sectors. It is specified as the ratio of physical sectors 132 * traversed per logical sector. Thus an interleave of 1:1 133 * implies contiguous layout, while 2:1 implies that logical 134 * sector 0 is separated by one sector from logical sector 1. 135 * d_trackskew is the offset of sector 0 on track N relative to 136 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew 137 * is the offset of sector 0 on cylinder N relative to sector 0 138 * on cylinder N-1. 139 */ 140 u_int16_t d_rpm; /* rotational speed */ 141 u_int16_t d_interleave; /* hardware sector interleave */ 142 u_int16_t d_trackskew; /* sector 0 skew, per track */ 143 u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ 144 u_int32_t d_headswitch; /* head switch time, usec */ 145 u_int32_t d_trkseek; /* track-to-track seek, usec */ 146 u_int32_t d_flags; /* generic flags */ 147 #define NDDATA 5 148 u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ 149 #define NSPARE 5 150 u_int32_t d_spare[NSPARE]; /* reserved for future use */ 151 u_int32_t d_magic2; /* the magic number (again) */ 152 u_int16_t d_checksum; /* xor of data incl. partitions */ 153 154 /* filesystem and partition information: */ 155 u_int16_t d_npartitions; /* number of partitions in following */ 156 u_int32_t d_bbsize; /* size of boot area at sn0, bytes */ 157 u_int32_t d_sbsize; /* max size of fs superblock, bytes */ 158 struct partition { /* the partition table */ 159 u_int32_t p_size; /* number of sectors in partition */ 160 u_int32_t p_offset; /* starting sector */ 161 u_int32_t p_fsize; /* filesystem basic fragment size */ 162 u_int8_t p_fstype; /* filesystem type, see below */ 163 u_int8_t p_frag; /* filesystem fragments per block */ 164 union { 165 u_int16_t cpg; /* UFS: FS cylinders per group */ 166 u_int16_t sgs; /* LFS: FS segment shift */ 167 } __partition_u1; 168 #define p_cpg __partition_u1.cpg 169 #define p_sgs __partition_u1.sgs 170 } d_partitions[MAXPARTITIONS]; /* actually may be more */ 171 }; 172 #else /* _LOCORE */ 173 /* 174 * offsets for asm boot files. 175 */ 176 .set d_secsize,40 177 .set d_nsectors,44 178 .set d_ntracks,48 179 .set d_ncylinders,52 180 .set d_secpercyl,56 181 .set d_secperunit,60 182 .set d_end_,404 /* size of disk label */ 183 #endif /* _LOCORE */ 184 185 /* d_type values: */ 186 #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ 187 #define DTYPE_MSCP 2 /* MSCP */ 188 #define DTYPE_DEC 3 /* other DEC (rk, rl) */ 189 #define DTYPE_SCSI 4 /* SCSI */ 190 #define DTYPE_ESDI 5 /* ESDI interface */ 191 #define DTYPE_ST506 6 /* ST506 etc. */ 192 #define DTYPE_HPIB 7 /* CS/80 on HP-IB */ 193 #define DTYPE_HPFL 8 /* HP Fiber-link */ 194 #define DTYPE_FLOPPY 10 /* floppy */ 195 #define DTYPE_CCD 11 /* concatenated disk device */ 196 #define DTYPE_VND 12 /* vnode pseudo-disk */ 197 #define DTYPE_ATAPI 13 /* ATAPI */ 198 #define DTYPE_RAID 14 /* RAIDframe */ 199 200 #ifdef DKTYPENAMES 201 static char *dktypenames[] = { 202 "unknown", 203 "SMD", 204 "MSCP", 205 "old DEC", 206 "SCSI", 207 "ESDI", 208 "ST506", 209 "HP-IB", 210 "HP-FL", 211 "type 9", 212 "floppy", 213 "ccd", 214 "vnd", 215 "ATAPI", 216 "RAID", 217 NULL 218 }; 219 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) 220 #endif 221 222 /* 223 * Filesystem type and version. 224 * Used to interpret other filesystem-specific 225 * per-partition information. 226 */ 227 #define FS_UNUSED 0 /* unused */ 228 #define FS_SWAP 1 /* swap */ 229 #define FS_V6 2 /* Sixth Edition */ 230 #define FS_V7 3 /* Seventh Edition */ 231 #define FS_SYSV 4 /* System V */ 232 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ 233 #define FS_V8 6 /* Eighth Edition, 4K blocks */ 234 #define FS_BSDFFS 7 /* 4.2BSD fast file system */ 235 #define FS_MSDOS 8 /* MSDOS file system */ 236 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ 237 #define FS_OTHER 10 /* in use, but unknown/unsupported */ 238 #define FS_HPFS 11 /* OS/2 high-performance file system */ 239 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ 240 #define FS_BOOT 13 /* partition contains bootstrap */ 241 #define FS_ADOS 14 /* AmigaDOS fast file system */ 242 #define FS_HFS 15 /* Macintosh HFS */ 243 #define FS_ADFS 16 /* Acorn Disk Filing System */ 244 #define FS_EXT2FS 17 /* ext2fs */ 245 #define FS_CCD 18 /* ccd component */ 246 #define FS_RAID 19 /* RAIDframe */ 247 #define FS_NTFS 20 /* NT OS/2 file system */ 248 #define FS_UDF 21 /* UDF (DVD) filesystem */ 249 #define FS_APPLEUFS 22 /* Apple UFS */ 250 #define FS_MANUAL 23 /* manual / reserved, e.g. vnd(4) */ 251 252 #ifdef DKTYPENAMES 253 static char *fstypenames[] = { 254 "unused", 255 "swap", 256 "Version6", 257 "Version7", 258 "SystemV", 259 "4.1BSD", 260 "Eighth-Edition", 261 "4.2BSD", 262 "MSDOS", 263 "4.4LFS", 264 "unknown", 265 "HPFS", 266 "ISO9660", 267 "boot", 268 "ADOS", 269 "HFS", 270 "ADFS", 271 "ext2fs", 272 "ccd", 273 "RAID", 274 "NTFS", 275 "UDF", 276 "Apple UFS", 277 "manual", 278 NULL 279 }; 280 281 /* Similar to the above, but used for things like the mount command. */ 282 static char *fstypesnames[] = { 283 "", /* 0 */ 284 "", /* 1 */ 285 "", /* 2 */ 286 "", /* 3 */ 287 "", /* 4 */ 288 "", /* 5 */ 289 "", /* 6 */ 290 "ffs", /* 7 */ 291 "msdos", /* 8 */ 292 "lfs", /* 9 */ 293 "", /* 10 */ 294 "", /* 11 */ 295 "cd9660", /* 12 */ 296 "", /* 13 */ 297 "ados", /* 14 */ 298 "", /* 15 */ 299 "", /* 16 */ 300 "ext2fs", /* 17 */ 301 "", /* 18 */ 302 "", /* 19 */ 303 "ntfs", /* 20 */ 304 "udf", /* 21 */ 305 "", /* 22 */ 306 "", /* 23 */ 307 NULL 308 }; 309 310 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) 311 #endif 312 313 /* 314 * flags shared by various drives: 315 */ 316 #define D_REMOVABLE 0x01 /* removable media */ 317 #define D_ECC 0x02 /* supports ECC */ 318 #define D_BADSECT 0x04 /* supports bad sector forw. */ 319 #define D_RAMDISK 0x08 /* disk emulator */ 320 #define D_CHAIN 0x10 /* can do back-back transfers */ 321 322 /* 323 * Drive data for SMD. 324 */ 325 #define d_smdflags d_drivedata[0] 326 #define D_SSE 0x1 /* supports skip sectoring */ 327 #define d_mindist d_drivedata[1] 328 #define d_maxdist d_drivedata[2] 329 #define d_sdist d_drivedata[3] 330 331 /* 332 * Drive data for ST506. 333 */ 334 #define d_precompcyl d_drivedata[0] 335 #define d_gap3 d_drivedata[1] /* used only when formatting */ 336 337 /* 338 * Drive data for SCSI. 339 */ 340 #define d_blind d_drivedata[0] 341 342 #ifndef _LOCORE 343 /* 344 * Structure used to perform a format or other raw operation, returning 345 * data and/or register values. Register identification and format 346 * are device- and driver-dependent. 347 */ 348 struct format_op { 349 char *df_buf; 350 int df_count; /* value-result */ 351 daddr_t df_startblk; 352 int df_reg[8]; /* result */ 353 }; 354 355 /* 356 * Structure used internally to retrieve information about a partition 357 * on a disk. 358 */ 359 struct partinfo { 360 struct disklabel *disklab; 361 struct partition *part; 362 }; 363 364 #ifdef _KERNEL 365 void diskerr(struct buf *, char *, char *, int, int, struct disklabel *); 366 void disksort(struct buf *, struct buf *); 367 u_int dkcksum(struct disklabel *); 368 int setdisklabel(struct disklabel *, struct disklabel *, u_long, 369 struct cpu_disklabel *); 370 char *readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, 371 struct cpu_disklabel *, int); 372 int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *, 373 struct cpu_disklabel *); 374 int bounds_check_with_label(struct buf *, struct disklabel *, 375 struct cpu_disklabel *, int); 376 #ifdef CD9660 377 int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *), 378 struct disklabel *lp); 379 #endif 380 #ifdef UDF 381 int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *), 382 struct disklabel *lp); 383 #endif 384 #endif 385 #endif /* _LOCORE */ 386 387 #if !defined(_KERNEL) && !defined(_LOCORE) 388 389 #include <sys/cdefs.h> 390 391 __BEGIN_DECLS 392 struct disklabel *getdiskbyname(const char *); 393 __END_DECLS 394 395 #endif 396