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