xref: /openbsd-src/sbin/disklabel/disklabel.5 (revision b2ea75c1b17e1a9a339660e7ed45cd24946b230e)
1.\"	$OpenBSD: disklabel.5,v 1.11 2001/08/12 12:03:01 heko Exp $
2.\"	$NetBSD: disklabel.5,v 1.3 1995/03/18 14:54:36 cgd Exp $
3.\"
4.\" Copyright (c) 1987, 1991, 1993
5.\"	The Regents of the University of California.  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" Symmetric Computer Systems.
9.\"
10.\" Redistribution and use in source and binary forms, with or without
11.\" modification, are permitted provided that the following conditions
12.\" are met:
13.\" 1. Redistributions of source code must retain the above copyright
14.\"    notice, this list of conditions and the following disclaimer.
15.\" 2. Redistributions in binary form must reproduce the above copyright
16.\"    notice, this list of conditions and the following disclaimer in the
17.\"    documentation and/or other materials provided with the distribution.
18.\" 3. All advertising materials mentioning features or use of this software
19.\"    must display the following acknowledgement:
20.\"	This product includes software developed by the University of
21.\"	California, Berkeley and its contributors.
22.\" 4. Neither the name of the University nor the names of its contributors
23.\"    may be used to endorse or promote products derived from this software
24.\"    without specific prior written permission.
25.\"
26.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36.\" SUCH DAMAGE.
37.\"
38.\"     @(#)disklabel.5.5	8.1 (Berkeley) 6/5/93
39.\"
40.Dd August 6, 2001
41.Dt DISKLABEL 5
42.Os
43.Sh NAME
44.Nm disklabel
45.Nd disk pack label
46.Sh SYNOPSIS
47.Fd #include <sys/disklabel.h>
48.Sh DESCRIPTION
49Each disk or disk pack on a system may contain a disk label
50which provides detailed information
51about the geometry of the disk and the partitions into which the disk
52is divided.
53It should be initialized when the disk is formatted,
54and may be changed later with the
55.Xr disklabel 8
56program.
57This information is used by the system disk driver and by the bootstrap
58program to determine how to program the drive
59and where to find the filesystems on the disk partitions.
60Additional information is used by the filesystem in order
61to use the disk most efficiently and to locate important filesystem information.
62The description of each partition contains an identifier for the partition
63type (standard filesystem, swap area, etc.).
64The filesystem updates the in-core copy of the label if it contains
65incomplete information about the filesystem.
66.Pp
67The label is located in sector number
68.Dv LABELSECTOR
69of the drive, usually sector 0 where it may be found
70without any information about the disk geometry.
71It is at an offset
72.Dv LABELOFFSET
73from the beginning of the sector, to allow room for the initial bootstrap.
74The disk sector containing the label is normally made read-only
75so that it is not accidentally overwritten by pack-to-pack copies
76or swap operations;
77the
78.Dv DIOCWLABEL
79.Xr ioctl 2 ,
80which is done as needed by the
81.Xr disklabel
82program, allows modification of the label sector.
83.Pp
84A copy of the in-core label for a disk can be obtained with the
85.Dv DIOCGDINFO
86.Xr ioctl ;
87this works with a file descriptor for a block or character
88.Pq Dq raw
89device for any partition of the disk.
90The in-core copy of the label is set by the
91.Dv DIOCSDINFO
92.Xr ioctl .
93The offset of a partition cannot generally be changed while it is open,
94nor can it be made smaller while it is open.
95One exception is that any change is allowed if no label was found
96on the disk, and the driver was able to construct only a skeletal label
97without partition information.
98The
99.Dv DIOCWDINFO
100.Xr ioctl
101operation sets the in-core label and then updates the on-disk label;
102there must be an existing label on the disk for this operation to succeed.
103Thus, the initial label for a disk or disk pack must be installed
104by writing to the raw disk.
105The
106.Dv DIOCGPDINFO
107.Xr ioctl
108operation gets the default label for a disk.  This simulates the case
109where there is no physical label on the disk itself and can be used to
110see the label the kernel would construct in that case.
111The
112.Dv DIOCRLDINFO
113.Xr ioctl
114operation causes the kernel to update its copy of label based on the
115physical label on the disk.  It can be used when the on-disk version
116of the label was changed directly or, if there is no physical label,
117to update the kernel's skeletal label if some variable affecting label
118generation has changed (e.g. the fdisk partition table).
119All of these operations are normally done using
120.Xr disklabel .
121.Pp
122The format of the disk label, as specified in
123.Pa sys/disklabel.h ,
124is
125.Bd -literal
126/*
127 * Disk description table, see disktab(5)
128 */
129#define	DISKTAB		"/etc/disktab"
130
131/*
132 * Each disk has a label which includes information about the hardware
133 * disk geometry, filesystem partitions, and drive specific information.
134 * The label is in block 0 or 1, possibly offset from the beginning
135 * to leave room for a bootstrap, etc.
136 */
137
138#ifndef	LABELSECTOR
139#define LABELSECTOR	0		/* sector containing label */
140#endif
141
142#ifndef	LABELOFFSET
143#define LABELOFFSET	64		/* offset of label in sector */
144#endif
145
146#define DISKMAGIC	((u_int32_t)0x82564557)	/* disk magic number */
147
148#ifndef LOCORE
149struct disklabel {
150	u_int32_t	d_magic;	/* the magic number */
151	u_int16_t	d_type;		/* drive type */
152	u_int16_t	d_subtype;	/* controller/d_type specific */
153	char	d_typename[16];	/* type name, e.g., "eagle" */
154	/*
155	 * d_packname contains the pack identifier and is returned when
156	 * the disklabel is read off the disk or in-core copy.
157	 * d_boot0 and d_boot1 are the (optional) names of the
158	 * primary (block 0) and secondary (block 1-15) bootstraps
159	 * as found in /usr/mdec.  These are returned when using
160	 * getdiskbyname(3) to retrieve the values from /etc/disktab.
161	 */
162	union {
163		char	un_d_packname[16];    /* pack identifier */
164		struct {
165			char *un_d_boot0;     /* primary bootstrap name */
166			char *un_d_boot1;     /* secondary bootstrap name */
167		} un_b;
168	} d_un;
169#define d_packname	d_un.un_d_packname
170#define d_boot0		d_un.un_b.un_d_boot0
171#define d_boot1		d_un.un_b.un_d_boot1
172
173	/* disk geometry: */
174	u_int32_t	d_secsize;	/* # of bytes per sector */
175	u_int32_t	d_nsectors;	/* # of data sectors per track */
176	u_int32_t	d_ntracks;	/* # of tracks per cylinder */
177	u_int32_t	d_ncylinders;	/* # of data cylinders per unit */
178	u_int32_t	d_secpercyl;	/* # of data sectors per cylinder */
179	u_int32_t	d_secperunit;	/* # of data sectors per unit */
180	/*
181	 * Spares (bad sector replacements) below
182	 * are not counted in d_nsectors or d_secpercyl.
183	 * Spare sectors are assumed to be physical sectors
184	 * which occupy space at the end of each track and/or cylinder.
185	 */
186	u_int16_t	d_sparespertrack;  /* # of spare sects per track */
187	u_int16_t	d_sparespercyl; /* # of spare sects per cylinder */
188	/*
189	 * Alternate cylinders include maintenance, replacement,
190	 * configuration description areas, etc.
191	 */
192	u_int32_t	d_acylinders;	/* # of alt. cylinders per unit */
193
194	/* hardware characteristics: */
195	/*
196	 * d_interleave, d_trackskew and d_cylskew describe perturbations
197	 * in the media format used to compensate for a slow controller.
198	 * Interleave is physical sector interleave, set up by the
199	 * formatter or controller when formatting.  When interleaving is
200	 * in use, logically adjacent sectors are not physically
201	 * contiguous, but instead are separated by some number of sectors.
202	 * It is specified as the ratio of physical sectors traversed
203	 * per logical sector.  Thus an interleave of 1:1 implies
204	 * contiguous layout, while 2:1 implies that logical sector 0 is
205	 * separated by one sector from logical sector 1.
206	 * d_trackskew is the offset of sector 0 on track N
207	 * relative to sector 0 on track N-1 on the same cylinder.
208	 * Finally, d_cylskew is the offset of sector 0 on cylinder N
209	 * relative to sector 0 on cylinder N-1.
210	 */
211	u_int16_t	d_rpm;	/* rotational speed */
212	u_int16_t	d_interleave;	/* hardware sector interleave */
213	u_int16_t	d_trackskew;	/* sector 0 skew, per track */
214	u_int16_t	d_cylskew;	/* sector 0 skew, per cylinder */
215	u_int32_t	d_headswitch;	/* head switch time, usec */
216	u_int32_t	d_trkseek;	/* track-to-track seek, usec */
217	u_int32_t	d_flags;	/* generic flags */
218#define NDDATA 5
219	u_int32_t	d_drivedata[NDDATA]; /* drive-type specific info */
220#define NSPARE 5
221	u_int32_t	d_spare[NSPARE];/* reserved for future use */
222	u_int32_t	d_magic2;	/* the magic number (again) */
223	u_int16_t	d_checksum;	/* xor of data incl. partitions */
224
225	/* filesystem and partition information: */
226	u_int16_t	d_npartitions;	/* # of partitions in following */
227	u_int32_t	d_bbsize;	/* size of boot area at sn0, bytes */
228	u_int32_t	d_sbsize;	/* max size of fs superblock, bytes */
229	struct	partition {	/* the partition table */
230		u_int32_t	p_size;	/* number of sectors in partition */
231		u_int32_t	p_offset;	/* starting sector */
232		u_int32_t	p_fsize;	/* filesystem basic frag size */
233		u_int8_t	p_fstype;	/* filesystem type, see below */
234		u_int8_t	p_frag;		/* filesystem frags per block */
235		union {
236			u_int16_t	cpg;	/* UFS: FS cyls per group */
237			u_int16_t	sgs;	/* LFS: FS segment shift */
238		} __partition_u1;
239#define	p_cpg	__partition_u1.cpg
240#define	p_sgs	__partition_u1.sgs
241	} d_partitions[MAXPARTITIONS];	/* actually may be more,
242					 * MAXPARTITIONS depends on the
243					 * architecture, and typically
244					 * varies between 8 and 16.
245					 */
246};
247
248/* d_type values: */
249#define	DTYPE_SMD	1	/* SMD, XSMD; VAX hp/up */
250#define	DTYPE_MSCP	2	/* MSCP */
251#define	DTYPE_DEC	3	/* other DEC (rk, rl) */
252#define	DTYPE_SCSI	4	/* SCSI */
253#define	DTYPE_ESDI	5	/* ESDI interface */
254#define	DTYPE_ST506	6	/* ST506 etc. */
255#define	DTYPE_HPIB	7	/* CS/80 on HP-IB */
256#define	DTYPE_HPFL	8	/* HP Fiber-link */
257#define	DTYPE_FLOPPY	10	/* floppy */
258#define	DTYPE_CCD	11	/* concatenated disk device */
259#define	DTYPE_VND	12	/* vnode pseudo-disk */
260#define	DTYPE_ATAPI	13	/* ATAPI */
261#define	DTYPE_RAID	14	/* RAIDframe */
262
263#ifdef DKTYPENAMES
264static char *dktypenames[] = {
265	"unknown",
266	"SMD",
267	"MSCP",
268	"old DEC",
269	"SCSI",
270	"ESDI",
271	"ST506",
272	"HP-IB",
273	"HP-FL",
274	"type 9",
275	"floppy",
276	"ccd",
277	"vnd",
278	"ATAPI",
279	"RAID",
280	NULL
281};
282#define DKMAXTYPES	(sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
283#endif
284
285/*
286 * Filesystem type and version.
287 * Used to interpret other filesystem-specific
288 * per-partition information.
289 */
290#define	FS_UNUSED	0	/* unused */
291#define	FS_SWAP		1	/* swap */
292#define	FS_V6		2	/* Sixth Edition */
293#define	FS_V7		3	/* Seventh Edition */
294#define	FS_SYSV		4	/* System V */
295#define	FS_V71K		5	/* V7 with 1K blocks (4.1, 2.9) */
296#define	FS_V8		6	/* Eighth Edition, 4K blocks */
297#define	FS_BSDFFS	7	/* 4.2BSD fast file system */
298#define	FS_MSDOS	8	/* MSDOS file system */
299#define	FS_BSDLFS	9	/* 4.4BSD log-structured file system */
300#define	FS_OTHER	10	/* in use, but unknown/unsupported */
301#define	FS_HPFS		11	/* OS/2 high-performance file system */
302#define	FS_ISO9660	12	/* ISO 9660, normally CD-ROM */
303#define	FS_BOOT		13	/* partition contains bootstrap */
304#define FS_ADOS		14	/* AmigaDOS fast file system */
305#define FS_HFS		15	/* Macintosh HFS */
306#define FS_ADFS		16	/* Acorn Disk Filing System */
307#define FS_EXT2FS	17	/* ext2fs */
308#define FS_CCD		18	/* ccd component */
309#define FS_RAID		19	/* RAIDframe */
310
311#ifdef	DKTYPENAMES
312static char *fstypenames[] = {
313	"unused",
314	"swap",
315	"Version6",
316	"Version7",
317	"SystemV",
318	"4.1BSD",
319	"Eighth-Edition",
320	"4.2BSD",
321	"MSDOS",
322	"4.4LFS",
323	"unknown",
324	"HPFS",
325	"ISO9660",
326	"boot",
327	"ADOS",
328	"HFS",
329	"ADFS",
330	"ext2fs",
331	"ccd",
332	"RAID",
333	NULL
334};
335#define FSMAXTYPES	(sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
336#endif
337
338/*
339 * flags shared by various drives:
340 */
341#define	D_REMOVABLE	0x01	/* removable media */
342#define	D_ECC		0x02	/* supports ECC */
343#define	D_BADSECT	0x04	/* supports bad sector forw. */
344#define	D_RAMDISK	0x08	/* disk emulator */
345#define	D_CHAIN		0x10	/* can do back-back transfers */
346
347/*
348 * Drive data for SMD.
349 */
350
351#define	d_smdflags	d_drivedata[0]
352#define	D_SSE		0x1	/* supports skip sectoring */
353#define	d_mindist	d_drivedata[1]
354#define	d_maxdist	d_drivedata[2]
355#define	d_sdist		d_drivedata[3]
356
357/*
358 * Drive data for ST506.
359 */
360#define d_precompcyl	d_drivedata[0]
361#define d_gap3		d_drivedata[1]	/* used only when formatting */
362
363/*
364 * Drive data for SCSI.
365 */
366#define	d_blind		d_drivedata[0]
367
368#ifndef LOCORE
369/*
370 * Structure used to perform a format
371 * or other raw operation, returning data
372 * and/or register values.
373 * Register identification and format
374 * are device- and driver-dependent.
375 */
376struct format_op {
377	char	*df_buf;
378	int	df_count;	/* value-result */
379	daddr_t	df_startblk;
380	int	df_reg[8];	/* result */
381};
382
383/*
384 * Structure used internally to retrieve
385 * information about a partition on a disk.
386 */
387struct partinfo {
388	struct	disklabel *disklab;
389	struct	partition *part;
390};
391
392/*
393 * Disk-specific ioctls.
394 */
395/* get and set disklabel; DIOCGPART used internally */
396#define DIOCGDINFO   _IOR('d', 101, struct disklabel) /* get */
397#define DIOCSDINFO   _IOW('d', 102, struct disklabel) /* set */
398#define DIOCWDINFO   _IOW('d', 103, struct disklabel) /* set, update disk */
399#define DIOCGPART    _IOW('d', 104, struct partinfo)  /* get partition */
400
401/* do format operation, read or write */
402#define DIOCRFORMAT	_IOWR('d', 105, struct format_op)
403#define DIOCWFORMAT	_IOWR('d', 106, struct format_op)
404
405#define DIOCSSTEP	_IOW('d', 107, int) /* set step rate */
406#define DIOCSRETRIES	_IOW('d', 108, int) /* set # of retries */
407#define DIOCWLABEL	_IOW('d', 109, int) /* write en/disable label */
408
409#define DIOCSBAD	_IOW('d', 110, struct dkbad) /* set kernel dkbad */
410#define DIOCEJECT	_IO('d', 112)                /* eject disk */
411#define DIOCLOCK	_IOW('d', 113, int)          /* lock/unlock pack */
412
413#define DIOCGPDINFO	_IOR('d', 114, struct disklabel)/* get physical */
414#define DIOCRLDINFO	_IO('d', 115)                   /* reload disklabel */
415
416#endif /* LOCORE */
417.Ed
418.Sh SEE ALSO
419.Xr disktab 5 ,
420.Xr disklabel 8
421