1139825Simp/*- 21541Srgrimes * Copyright (c) 1987, 1988, 1993 31541Srgrimes * The Regents of the University of California. All rights reserved. 41541Srgrimes * 51541Srgrimes * Redistribution and use in source and binary forms, with or without 61541Srgrimes * modification, are permitted provided that the following conditions 71541Srgrimes * are met: 81541Srgrimes * 1. Redistributions of source code must retain the above copyright 91541Srgrimes * notice, this list of conditions and the following disclaimer. 101541Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111541Srgrimes * notice, this list of conditions and the following disclaimer in the 121541Srgrimes * documentation and/or other materials provided with the distribution. 131541Srgrimes * 4. Neither the name of the University nor the names of its contributors 141541Srgrimes * may be used to endorse or promote products derived from this software 151541Srgrimes * without specific prior written permission. 161541Srgrimes * 171541Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181541Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191541Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201541Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211541Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221541Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231541Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241541Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251541Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261541Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271541Srgrimes * SUCH DAMAGE. 281541Srgrimes * 2914478Shsu * @(#)disklabel.h 8.2 (Berkeley) 7/10/94 3050477Speter * $FreeBSD: stable/10/sys/sys/disklabel.h 322860 2017-08-24 21:44:23Z mckusick $ 311541Srgrimes */ 321541Srgrimes 3345260Sbde#ifndef _SYS_DISKLABEL_H_ 345052Sbde#define _SYS_DISKLABEL_H_ 352165Spaul 3655205Speter#ifndef _KERNEL 3718444Sbde#include <sys/types.h> 3818444Sbde#endif 3918429Sbde#include <sys/ioccom.h> 4018429Sbde 411541Srgrimes/* 421541Srgrimes * Disk description table, see disktab(5) 431541Srgrimes */ 441541Srgrimes#define _PATH_DISKTAB "/etc/disktab" 451541Srgrimes 461541Srgrimes/* 471541Srgrimes * Each disk has a label which includes information about the hardware 481541Srgrimes * disk geometry, filesystem partitions, and drive specific information. 491541Srgrimes * The label is in block 0 or 1, possibly offset from the beginning 501541Srgrimes * to leave room for a bootstrap, etc. 511541Srgrimes */ 521541Srgrimes 531541Srgrimes/* XXX these should be defined per controller (or drive) elsewhere, not here! */ 54144767Scognet#if defined(__i386__) || defined(__amd64__) || defined(__arm__) || \ 55213048Sjchandra defined(__ia64__) || defined(__powerpc__) || defined(__mips__) 561541Srgrimes#define LABELSECTOR 1 /* sector containing label */ 571541Srgrimes#define LABELOFFSET 0 /* offset of label in sector */ 581541Srgrimes#endif 591541Srgrimes 6014478Shsu#define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */ 611541Srgrimes#ifndef MAXPARTITIONS 621541Srgrimes#define MAXPARTITIONS 8 631541Srgrimes#endif 641541Srgrimes 6596473Sphk/* Size of bootblock area in sector-size neutral bytes */ 6696473Sphk#define BBSIZE 8192 6796473Sphk 685052Sbde#define LABEL_PART 2 /* partition containing label */ 695052Sbde#define RAW_PART 2 /* partition containing whole disk */ 705052Sbde#define SWAP_PART 1 /* partition normally containing swap */ 711541Srgrimes 721541Srgrimesstruct disklabel { 7314478Shsu u_int32_t d_magic; /* the magic number */ 7414478Shsu u_int16_t d_type; /* drive type */ 7514478Shsu u_int16_t d_subtype; /* controller/d_type specific */ 7614478Shsu char d_typename[16]; /* type name, e.g. "eagle" */ 7714478Shsu 7893810Sphk char d_packname[16]; /* pack identifier */ 7914478Shsu 801541Srgrimes /* disk geometry: */ 8114478Shsu u_int32_t d_secsize; /* # of bytes per sector */ 8214478Shsu u_int32_t d_nsectors; /* # of data sectors per track */ 8314478Shsu u_int32_t d_ntracks; /* # of tracks per cylinder */ 8414478Shsu u_int32_t d_ncylinders; /* # of data cylinders per unit */ 8514478Shsu u_int32_t d_secpercyl; /* # of data sectors per cylinder */ 8614478Shsu u_int32_t d_secperunit; /* # of data sectors per unit */ 8714478Shsu 881541Srgrimes /* 8914478Shsu * Spares (bad sector replacements) below are not counted in 9014478Shsu * d_nsectors or d_secpercyl. Spare sectors are assumed to 9114478Shsu * be physical sectors which occupy space at the end of each 9214478Shsu * track and/or cylinder. 931541Srgrimes */ 9414478Shsu u_int16_t d_sparespertrack; /* # of spare sectors per track */ 9514478Shsu u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */ 961541Srgrimes /* 9714478Shsu * Alternate cylinders include maintenance, replacement, configuration 9814478Shsu * description areas, etc. 991541Srgrimes */ 10014478Shsu u_int32_t d_acylinders; /* # of alt. cylinders per unit */ 1011541Srgrimes 1021541Srgrimes /* hardware characteristics: */ 1031541Srgrimes /* 1041541Srgrimes * d_interleave, d_trackskew and d_cylskew describe perturbations 1051541Srgrimes * in the media format used to compensate for a slow controller. 10614478Shsu * Interleave is physical sector interleave, set up by the 10714478Shsu * formatter or controller when formatting. When interleaving is 10814478Shsu * in use, logically adjacent sectors are not physically 10914478Shsu * contiguous, but instead are separated by some number of 11014478Shsu * sectors. It is specified as the ratio of physical sectors 11114478Shsu * traversed per logical sector. Thus an interleave of 1:1 11214478Shsu * implies contiguous layout, while 2:1 implies that logical 11314478Shsu * sector 0 is separated by one sector from logical sector 1. 11414478Shsu * d_trackskew is the offset of sector 0 on track N relative to 11514478Shsu * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew 11614478Shsu * is the offset of sector 0 on cylinder N relative to sector 0 11714478Shsu * on cylinder N-1. 1181541Srgrimes */ 11914478Shsu u_int16_t d_rpm; /* rotational speed */ 12014478Shsu u_int16_t d_interleave; /* hardware sector interleave */ 12114478Shsu u_int16_t d_trackskew; /* sector 0 skew, per track */ 12214478Shsu u_int16_t d_cylskew; /* sector 0 skew, per cylinder */ 12314478Shsu u_int32_t d_headswitch; /* head switch time, usec */ 12414478Shsu u_int32_t d_trkseek; /* track-to-track seek, usec */ 12514478Shsu u_int32_t d_flags; /* generic flags */ 1261541Srgrimes#define NDDATA 5 12714478Shsu u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */ 1281541Srgrimes#define NSPARE 5 12914478Shsu u_int32_t d_spare[NSPARE]; /* reserved for future use */ 13014478Shsu u_int32_t d_magic2; /* the magic number (again) */ 13114478Shsu u_int16_t d_checksum; /* xor of data incl. partitions */ 1321541Srgrimes 1331541Srgrimes /* filesystem and partition information: */ 13414478Shsu u_int16_t d_npartitions; /* number of partitions in following */ 13514478Shsu u_int32_t d_bbsize; /* size of boot area at sn0, bytes */ 13614478Shsu u_int32_t d_sbsize; /* max size of fs superblock, bytes */ 13783421Sobrien struct partition { /* the partition table */ 13814478Shsu u_int32_t p_size; /* number of sectors in partition */ 13914478Shsu u_int32_t p_offset; /* starting sector */ 14014478Shsu u_int32_t p_fsize; /* filesystem basic fragment size */ 14114478Shsu u_int8_t p_fstype; /* filesystem type, see below */ 14214478Shsu u_int8_t p_frag; /* filesystem fragments per block */ 14366066Sphk u_int16_t p_cpg; /* filesystem cylinders per group */ 1441541Srgrimes } d_partitions[MAXPARTITIONS]; /* actually may be more */ 1451541Srgrimes}; 14665921Sphk 14793810Sphk#ifdef CTASSERT 148105056SphkCTASSERT(sizeof(struct disklabel) == 148 + MAXPARTITIONS * 16); 14993810Sphk#endif 15093810Sphk 15192719Salfredstatic __inline u_int16_t dkcksum(struct disklabel *lp); 15265921Sphkstatic __inline u_int16_t 15394960Salfreddkcksum(struct disklabel *lp) 15465921Sphk{ 15565921Sphk u_int16_t *start, *end; 15665921Sphk u_int16_t sum = 0; 15765921Sphk 15865921Sphk start = (u_int16_t *)lp; 15965921Sphk end = (u_int16_t *)&lp->d_partitions[lp->d_npartitions]; 16065921Sphk while (start < end) 16165921Sphk sum ^= *start++; 16265921Sphk return (sum); 16365921Sphk} 16465921Sphk 1651541Srgrimes 1661541Srgrimes/* d_type values: */ 1671541Srgrimes#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ 1681541Srgrimes#define DTYPE_MSCP 2 /* MSCP */ 1691541Srgrimes#define DTYPE_DEC 3 /* other DEC (rk, rl) */ 1701541Srgrimes#define DTYPE_SCSI 4 /* SCSI */ 1711541Srgrimes#define DTYPE_ESDI 5 /* ESDI interface */ 1721541Srgrimes#define DTYPE_ST506 6 /* ST506 etc. */ 1731541Srgrimes#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ 1741541Srgrimes#define DTYPE_HPFL 8 /* HP Fiber-link */ 1751541Srgrimes#define DTYPE_FLOPPY 10 /* floppy */ 17615571Sasami#define DTYPE_CCD 11 /* concatenated disk */ 17745260Sbde#define DTYPE_VINUM 12 /* vinum volume */ 17849617Simp#define DTYPE_DOC2K 13 /* Msys DiskOnChip */ 179105503Sscottl#define DTYPE_RAID 14 /* CMU RAIDFrame */ 18093318Sgrog#define DTYPE_JFS2 16 /* IBM JFS 2 */ 1811541Srgrimes 1821541Srgrimes#ifdef DKTYPENAMES 18394048Sphkstatic const char *dktypenames[] = { 1841541Srgrimes "unknown", 1851541Srgrimes "SMD", 1861541Srgrimes "MSCP", 1871541Srgrimes "old DEC", 1881541Srgrimes "SCSI", 1891541Srgrimes "ESDI", 1901541Srgrimes "ST506", 1911541Srgrimes "HP-IB", 1921541Srgrimes "HP-FL", 1931541Srgrimes "type 9", 1941541Srgrimes "floppy", 19515571Sasami "CCD", 19633469Sjkh "Vinum", 19749617Simp "DOC2K", 198105503Sscottl "Raid", 19993318Sgrog "?", 20093318Sgrog "jfs", 20114478Shsu NULL 2021541Srgrimes}; 2031541Srgrimes#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) 2041541Srgrimes#endif 2051541Srgrimes 2061541Srgrimes/* 2071541Srgrimes * Filesystem type and version. 2081541Srgrimes * Used to interpret other filesystem-specific 2091541Srgrimes * per-partition information. 2101541Srgrimes */ 2111541Srgrimes#define FS_UNUSED 0 /* unused */ 2121541Srgrimes#define FS_SWAP 1 /* swap */ 2131541Srgrimes#define FS_V6 2 /* Sixth Edition */ 2141541Srgrimes#define FS_V7 3 /* Seventh Edition */ 2151541Srgrimes#define FS_SYSV 4 /* System V */ 2161541Srgrimes#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ 2171541Srgrimes#define FS_V8 6 /* Eighth Edition, 4K blocks */ 21896755Strhodes#define FS_BSDFFS 7 /* 4.2BSD fast filesystem */ 21996755Strhodes#define FS_MSDOS 8 /* MSDOS filesystem */ 22096755Strhodes#define FS_BSDLFS 9 /* 4.4BSD log-structured filesystem */ 2211541Srgrimes#define FS_OTHER 10 /* in use, but unknown/unsupported */ 22296755Strhodes#define FS_HPFS 11 /* OS/2 high-performance filesystem */ 2231541Srgrimes#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ 2241541Srgrimes#define FS_BOOT 13 /* partition contains bootstrap */ 22545260Sbde#define FS_VINUM 14 /* Vinum drive */ 226105503Sscottl#define FS_RAID 15 /* RAIDFrame drive */ 227174435Smarcel#define FS_FILECORE 16 /* Acorn Filecore Filing System */ 228174435Smarcel#define FS_EXT2FS 17 /* ext2fs */ 229174435Smarcel#define FS_NTFS 18 /* Windows/NT file system */ 230174435Smarcel#define FS_CCD 20 /* concatenated disk component */ 23193318Sgrog#define FS_JFS2 21 /* IBM JFS2 */ 232268091Sae#define FS_HAMMER 22 /* DragonFlyBSD Hammer FS */ 233268091Sae#define FS_HAMMER2 23 /* DragonFlyBSD Hammer2 FS */ 234174435Smarcel#define FS_UDF 24 /* UDF */ 235174435Smarcel#define FS_EFS 26 /* SGI's Extent File system */ 236174436Smarcel#define FS_ZFS 27 /* Sun's ZFS */ 237236023Smarcel#define FS_NANDFS 30 /* FreeBSD nandfs (NiLFS derived) */ 23845260Sbde 239101974Salfred#ifdef FSTYPENAMES 24094048Sphkstatic const char *fstypenames[] = { 2411541Srgrimes "unused", 2421541Srgrimes "swap", 2431541Srgrimes "Version 6", 2441541Srgrimes "Version 7", 2451541Srgrimes "System V", 2461541Srgrimes "4.1BSD", 2471541Srgrimes "Eighth Edition", 2481541Srgrimes "4.2BSD", 2491541Srgrimes "MSDOS", 2501541Srgrimes "4.4LFS", 2511541Srgrimes "unknown", 2521541Srgrimes "HPFS", 2531541Srgrimes "ISO9660", 2541541Srgrimes "boot", 25544948Sgrog "vinum", 256105503Sscottl "raid", 257174435Smarcel "Filecore", 258174435Smarcel "EXT2FS", 259174435Smarcel "NTFS", 26093318Sgrog "?", 261174435Smarcel "ccd", 262174435Smarcel "jfs", 263268091Sae "HAMMER", 264268091Sae "HAMMER2", 265174435Smarcel "UDF", 266177116Sremko "?", 267174435Smarcel "EFS", 268174436Smarcel "ZFS", 269236023Smarcel "?", 270236023Smarcel "?", 271236023Smarcel "nandfs", 27214478Shsu NULL 2731541Srgrimes}; 2741541Srgrimes#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) 2751541Srgrimes#endif 2761541Srgrimes 2771541Srgrimes/* 2781541Srgrimes * flags shared by various drives: 2791541Srgrimes */ 28093582Sphk#define D_REMOVABLE 0x01 /* removable media */ 28193582Sphk#define D_ECC 0x02 /* supports ECC */ 28293582Sphk#define D_BADSECT 0x04 /* supports bad sector forw. */ 28393582Sphk#define D_RAMDISK 0x08 /* disk emulator */ 28493582Sphk#define D_CHAIN 0x10 /* can do back-back transfers */ 2851541Srgrimes 2861541Srgrimes/* 28794182Sphk * NB: <sys/disk.h> defines ioctls from 'd'/128 and up. 2881541Srgrimes */ 2891541Srgrimes 290113591Sphk/* 291113591Sphk * Functions for proper encoding/decoding of struct disklabel into/from 292113591Sphk * bytestring. 293113591Sphk */ 294113591Sphkvoid bsd_partition_le_dec(u_char *ptr, struct partition *d); 295114556Sphkint bsd_disklabel_le_dec(u_char *ptr, struct disklabel *d, int maxpart); 296113591Sphkvoid bsd_partition_le_enc(u_char *ptr, struct partition *d); 297113591Sphkvoid bsd_disklabel_le_enc(u_char *ptr, struct disklabel *d); 298113591Sphk 29955205Speter#ifndef _KERNEL 3001541Srgrimes__BEGIN_DECLS 30192719Salfredstruct disklabel *getdiskbyname(const char *); 3021541Srgrimes__END_DECLS 3031541Srgrimes#endif 3042165Spaul 3055052Sbde#endif /* !_SYS_DISKLABEL_H_ */ 306