1.\" Copyright (c) 1987, 1991, 1993 2.\" The Regents of the University of California. All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Symmetric Computer Systems. 6.\" 7.\" %sccs.include.redist.roff% 8.\" 9.\" @(#)disklabel.5.5 8.2 (Berkeley) 05/06/94 10.\" 11.Dd 12.Dt DISKLABEL 5 13.Os 14.Sh NAME 15.Nm disklabel 16.Nd disk pack label 17.Sh SYNOPSIS 18.Fd #include <sys/disklabel.h> 19.Sh DESCRIPTION 20Each disk or disk pack on a system may contain a disk label 21which provides detailed information 22about the geometry of the disk and the partitions into which the disk 23is divided. 24It should be initialized when the disk is formatted, 25and may be changed later with the 26.Xr disklabel 8 27program. 28This information is used by the system disk driver and by the bootstrap 29program to determine how to program the drive 30and where to find the filesystems on the disk partitions. 31Additional information is used by the filesystem in order 32to use the disk most efficiently and to locate important filesystem information. 33The description of each partition contains an identifier for the partition 34type (standard filesystem, swap area, etc.). 35The filesystem updates the in-core copy of the label if it contains 36incomplete information about the filesystem. 37.Pp 38The label is located in sector number 39.Dv LABELSECTOR 40of the drive, usually sector 0 where it may be found 41without any information about the disk geometry. 42It is at an offset 43.Dv LABELOFFSET 44from the beginning of the sector, to allow room for the initial bootstrap. 45The disk sector containing the label is normally made read-only 46so that it is not accidentally overwritten by pack-to-pack copies 47or swap operations; 48the 49.Dv DIOCWLABEL 50.Xr ioctl 2 , 51which is done as needed by the 52.Xr disklabel 53program. 54.Pp 55A copy of the in-core label for a disk can be obtained with the 56.Dv DIOCGDINFO 57.Xr ioctl ; 58this works with a file descriptor for a block or character (``raw'') device 59for any partition of the disk. 60The in-core copy of the label is set by the 61.Dv DIOCSDINFO 62.Xr ioctl . 63The offset of a partition cannot generally be changed while it is open, 64nor can it be made smaller while it is open. 65One exception is that any change is allowed if no label was found 66on the disk, and the driver was able to construct only a skeletal label 67without partition information. 68Finally, the 69.Dv DIOCWDINFO 70.Xr ioctl 71operation sets the in-core label and then updates the on-disk label; 72there must be an existing label on the disk for this operation to succeed. 73Thus, the initial label for a disk or disk pack must be installed 74by writing to the raw disk. 75All of these operations are normally done using 76.Xr disklabel . 77.Pp 78The format of the disk label, as specified in 79.Aw Pa sys/disklabel.h , 80is 81.Bd -literal 82/* 83* Disk description table, see disktab(5) 84*/ 85#define DISKTAB "/etc/disktab" 86 87/* 88* Each disk has a label which includes information about the hardware 89* disk geometry, filesystem partitions, and drive specific information. 90* The label is in block 0 or 1, possibly offset from the beginning 91* to leave room for a bootstrap, etc. 92*/ 93 94#ifndef LABELSECTOR 95#define LABELSECTOR 0 /* sector containing label */ 96#endif 97 98#ifndef LABELOFFSET 99#define LABELOFFSET 64 /* offset of label in sector */ 100#endif 101 102#define DISKMAGIC ((u_long) 0x82564557) /* The disk magic number */ 103#ifndef MAXPARTITIONS 104#define MAXPARTITIONS 8 105#endif 106 107#ifndef LOCORE 108struct disklabel { 109 u_long d_magic; /* the magic number */ 110 short d_type; /* drive type */ 111 short d_subtype; /* controller/d_type specific */ 112 char d_typename[16]; /* type name, e.g. "eagle" */ 113 /* 114 * d_packname contains the pack identifier and is returned when 115 * the disklabel is read off the disk or in-core copy. 116 * d_boot0 and d_boot1 are the (optional) names of the 117 * primary (block 0) and secondary (block 1-15) bootstraps 118 * as found in /usr/mdec. These are returned when using 119 * getdiskbyname(3) 120 to retrieve the values from /etc/disktab. 121 */ 122#if defined(KERNEL) || defined(STANDALONE) 123 char d_packname[16]; /* pack identifier */ 124#else 125 union { 126 char un_d_packname[16]; /* pack identifier */ 127 struct { 128 char *un_d_boot0; /* primary bootstrap name */ 129 char *un_d_boot1; /* secondary bootstrap name */ 130 } un_b; 131 } d_un; 132 133#define d_packname d_un.un_d_packname 134#define d_boot0 d_un.un_b.un_d_boot0 135#define d_boot1 d_un.un_b.un_d_boot1 136#endif /* ! KERNEL or STANDALONE */ 137 138 /* disk geometry: */ 139 u_long d_secsize; /* # of bytes per sector */ 140 u_long d_nsectors; /* # of data sectors per track */ 141 u_long d_ntracks; /* # of tracks per cylinder */ 142 u_long d_ncylinders; /* # of data cylinders per unit */ 143 u_long d_secpercyl; /* # of data sectors per cylinder */ 144 u_long d_secperunit; /* # of data sectors per unit */ 145 /* 146 * Spares (bad sector replacements) below 147 * are not counted in d_nsectors or d_secpercyl. 148 * Spare sectors are assumed to be physical sectors 149 * which occupy space at the end of each track and/or cylinder. 150 */ 151 u_short d_sparespertrack; /* # of spare sectors per track */ 152 u_short d_sparespercyl; /* # of spare sectors per cylinder */ 153 /* 154 * Alternate cylinders include maintenance, replacement, 155 * configuration description areas, etc. 156 */ 157 u_long d_acylinders; /* # of alt. cylinders per unit */ 158 159 /* hardware characteristics: */ 160 /* 161 * d_interleave, d_trackskew and d_cylskew describe perturbations 162 * in the media format used to compensate for a slow controller. 163 * Interleave is physical sector interleave, set up by the formatter 164 * or controller when formatting. When interleaving is in use, 165 * logically adjacent sectors are not physically contiguous, 166 * but instead are separated by some number of sectors. 167 * It is specified as the ratio of physical sectors traversed 168 * per logical sector. Thus an interleave of 1:1 implies contiguous 169 * layout, while 2:1 implies that logical sector 0 is separated 170 * by one sector from logical sector 1. 171 * d_trackskew is the offset of sector 0 on track N 172 * relative to sector 0 on track N-1 on the same cylinder. 173 * Finally, d_cylskew is the offset of sector 0 on cylinder N 174 * relative to sector 0 on cylinder N-1. 175 */ 176 u_short d_rpm; /* rotational speed */ 177 u_short d_interleave; /* hardware sector interleave */ 178 u_short d_trackskew; /* sector 0 skew, per track */ 179 u_short d_cylskew; /* sector 0 skew, per cylinder */ 180 u_long d_headswitch; /* head switch time, usec */ 181 u_long d_trkseek; /* track-to-track seek, usec */ 182 u_long d_flags; /* generic flags */ 183#define NDDATA 5 184 u_long d_drivedata[NDDATA]; /* drive-type specific information */ 185#define NSPARE 5 186 u_long d_spare[NSPARE]; /* reserved for future use */ 187 u_long d_magic2; /* the magic number (again) */ 188 u_short d_checksum; /* xor of data incl. partitions */ 189 190 /* filesystem and partition information: */ 191 u_short d_npartitions; /* number of partitions in following */ 192 u_long d_bbsize; /* size of boot area at sn0, bytes */ 193 u_long d_sbsize; /* max size of fs superblock, bytes */ 194 struct partition { /* the partition table */ 195 u_long p_size; /* number of sectors in partition */ 196 u_long p_offset; /* starting sector */ 197 u_long p_fsize; /* filesystem basic fragment size */ 198 u_char p_fstype; /* filesystem type, see below */ 199 u_char p_frag; /* filesystem fragments per block */ 200 union { 201 u_short cpg; /* UFS: FS cylinders per group */ 202 u_short sgs; /* LFS: FS segment shift */ 203 } __partition_u1; 204#define p_cpg __partition_u1.cpg 205#define p_sgs __partition_u1.sgs 206 u_short p_cpg; /* filesystem cylinders per group */ 207 } d_partitions[MAXPARTITIONS]; /* actually may be more */ 208}; 209 210/* d_type values: */ 211#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */ 212#define DTYPE_MSCP 2 /* MSCP */ 213#define DTYPE_DEC 3 /* other DEC (rk, rl) */ 214#define DTYPE_SCSI 4 /* SCSI */ 215#define DTYPE_ESDI 5 /* ESDI interface */ 216#define DTYPE_ST506 6 /* ST506 etc. */ 217#define DTYPE_HPIB 7 /* CS/80 on HP-IB */ 218#define DTYPE_HPFL 8 /* HP Fiber-link */ 219#define DTYPE_FLOPPY 10 /* floppy */ 220 221#ifdef DKTYPENAMES 222static char *dktypenames[] = { 223 "unknown", 224 "SMD", 225 "MSCP", 226 "old DEC", 227 "SCSI", 228 "ESDI", 229 "ST506", 230 "HP-IB", 231 "HP-FL", 232 "type 9", 233 "floppy", 234 0 235}; 236#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1) 237#endif 238 239/* 240* Filesystem type and version. 241* Used to interpret other filesystem-specific 242* per-partition information. 243*/ 244#define FS_UNUSED 0 /* unused */ 245#define FS_SWAP 1 /* swap */ 246#define FS_V6 2 /* Sixth Edition */ 247#define FS_V7 3 /* Seventh Edition */ 248#define FS_SYSV 4 /* System V */ 249#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */ 250#define FS_V8 6 /* Eighth Edition, 4K blocks */ 251#define FS_BSDFFS 7 /* 4.2BSD fast file system */ 252#define FS_MSDOS 8 /* MSDOS file system */ 253#define FS_BSDLFS 9 /* 4.4BSD log-structured file system */ 254#define FS_OTHER 10 /* in use, but unknown/unsupported */ 255#define FS_HPFS 11 /* OS/2 high-performance file system */ 256#define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */ 257#define FS_BOOT 13 /* partition contains bootstrap */ 258 259#ifdef DKTYPENAMES 260static char *fstypenames[] = { 261 "unused", 262 "swap", 263 "Version 6", 264 "Version 7", 265 "System V", 266 "4.1BSD", 267 "Eighth Edition", 268 "4.2BSD", 269 "MSDOS", 270 "4.4LFS", 271 "unknown", 272 "HPFS", 273 "ISO9660", 274 "boot", 275 0 276}; 277#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1) 278#endif 279 280/* 281* flags shared by various drives: 282*/ 283#define D_REMOVABLE 0x01 /* removable media */ 284#define D_ECC 0x02 /* supports ECC */ 285#define D_BADSECT 0x04 /* supports bad sector forw. */ 286#define D_RAMDISK 0x08 /* disk emulator */ 287#define D_CHAIN 0x10 /* can do back-back transfers */ 288 289/* 290* Drive data for SMD. 291*/ 292 293#define d_smdflags d_drivedata[0] 294#define D_SSE 0x1 /* supports skip sectoring */ 295#define d_mindist d_drivedata[1] 296#define d_maxdist d_drivedata[2] 297#define d_sdist d_drivedata[3] 298 299/* 300* Drive data for ST506. 301*/ 302#define d_precompcyl d_drivedata[0] 303#define d_gap3 d_drivedata[1] /* used only when formatting */ 304 305/* 306 * Drive data for SCSI. 307 */ 308#define d_blind d_drivedata[0] 309 310#ifndef LOCORE 311/* 312* Structure used to perform a format 313* or other raw operation, returning data 314* and/or register values. 315* Register identification and format 316* are device- and driver-dependent. 317*/ 318struct format_op { 319 char *df_buf; 320 int df_count; /* value-result */ 321 daddr_t df_startblk; 322 int df_reg[8]; /* result */ 323}; 324 325/* 326* Structure used internally to retrieve 327* information about a partition on a disk. 328*/ 329struct partinfo { 330 struct disklabel *disklab; 331 struct partition *part; 332}; 333 334/* 335* Disk-specific ioctls. 336*/ 337 /* get and set disklabel; DIOCGPART used internally */ 338#define DIOCGDINFO _IOR('d', 101, struct disklabel) /* get */ 339#define DIOCSDINFO _IOW('d', 102, struct disklabel) /* set */ 340#define DIOCWDINFO _IOW('d', 103, struct disklabel) /* set, update disk */ 341#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ 342 343/* do format operation, read or write */ 344#define DIOCRFORMAT _IOWR('d', 105, struct format_op) 345#define DIOCWFORMAT _IOWR('d', 106, struct format_op) 346 347#define DIOCSSTEP _IOW('d', 107, int) /* set step rate */ 348#define DIOCSRETRIES _IOW('d', 108, int) /* set # of retries */ 349#define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ 350 351#define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */ 352 353#endif LOCORE 354.Ed 355.Sh SEE ALSO 356.Xr disktab 5 , 357.Xr disklabel 8 358.Sh HISTORY 359The 360.Nm disklabel 361function was introduced in 362.Bx 4.3 Tahoe . 363