161480Sbostic.\" Copyright (c) 1987, 1991, 1993
261480Sbostic.\"	The Regents of the University of California.  All rights reserved.
331568Skarels.\"
435031Sbostic.\" This code is derived from software contributed to Berkeley by
535031Sbostic.\" Symmetric Computer Systems.
631568Skarels.\"
749638Scael.\" %sccs.include.redist.roff%
835031Sbostic.\"
9*67104Smckusick.\"     @(#)disklabel.5.5	8.2 (Berkeley) 05/06/94
1035031Sbostic.\"
1149638Scael.Dd
1249638Scael.Dt DISKLABEL 5
1349638Scael.Os
1449638Scael.Sh NAME
1549638Scael.Nm disklabel
1649638Scael.Nd disk pack label
1749638Scael.Sh SYNOPSIS
1849638Scael.Fd #include <sys/disklabel.h>
1949638Scael.Sh DESCRIPTION
2031568SkarelsEach disk or disk pack on a system may contain a disk label
2131568Skarelswhich provides detailed information
2231568Skarelsabout the geometry of the disk and the partitions into which the disk
2331568Skarelsis divided.
2431568SkarelsIt should be initialized when the disk is formatted,
2531568Skarelsand may be changed later with the
2649638Scael.Xr disklabel 8
2731568Skarelsprogram.
2831568SkarelsThis information is used by the system disk driver and by the bootstrap
2931568Skarelsprogram to determine how to program the drive
3031568Skarelsand where to find the filesystems on the disk partitions.
3131568SkarelsAdditional information is used by the filesystem in order
3231568Skarelsto use the disk most efficiently and to locate important filesystem information.
3334728SkarelsThe description of each partition contains an identifier for the partition
3434728Skarelstype (standard filesystem, swap area, etc.).
3534728SkarelsThe filesystem updates the in-core copy of the label if it contains
3634728Skarelsincomplete information about the filesystem.
3749638Scael.Pp
3831568SkarelsThe label is located in sector number
3949638Scael.Dv LABELSECTOR
4031568Skarelsof the drive, usually sector 0 where it may be found
4131568Skarelswithout any information about the disk geometry.
4231568SkarelsIt is at an offset
4349638Scael.Dv LABELOFFSET
4431568Skarelsfrom the beginning of the sector, to allow room for the initial bootstrap.
4534728SkarelsThe disk sector containing the label is normally made read-only
4634728Skarelsso that it is not accidentally overwritten by pack-to-pack copies
4734728Skarelsor swap operations;
4849638Scaelthe
4949638Scael.Dv DIOCWLABEL
5049638Scael.Xr ioctl 2 ,
5134728Skarelswhich is done as needed by the
5249638Scael.Xr disklabel
5334728Skarelsprogram.
5449638Scael.Pp
5549638ScaelA copy of the in-core label for a disk can be obtained with the
5649638Scael.Dv DIOCGDINFO
5749638Scael.Xr ioctl ;
5834728Skarelsthis works with a file descriptor for a block or character (``raw'') device
5934728Skarelsfor any partition of the disk.
6049638ScaelThe in-core copy of the label is set by the
6149638Scael.Dv DIOCSDINFO
6249638Scael.Xr ioctl .
6334728SkarelsThe offset of a partition cannot generally be changed while it is open,
6434728Skarelsnor can it be made smaller while it is open.
6534728SkarelsOne exception is that any change is allowed if no label was found
6634728Skarelson the disk, and the driver was able to construct only a skeletal label
6734728Skarelswithout partition information.
6849638ScaelFinally, the
6949638Scael.Dv DIOCWDINFO
7049638Scael.Xr ioctl
7134728Skarelsoperation sets the in-core label and then updates the on-disk label;
7234728Skarelsthere must be an existing label on the disk for this operation to succeed.
7334728SkarelsThus, the initial label for a disk or disk pack must be installed
7434728Skarelsby writing to the raw disk.
7534728SkarelsAll of these operations are normally done using
7649638Scael.Xr disklabel .
7749638Scael.Pp
7831568SkarelsThe format of the disk label, as specified in
7949638Scael.Aw Pa sys/disklabel.h ,
8031568Skarelsis
8149638Scael.Bd -literal
8234948Smckusick/*
8349638Scael* Disk description table, see disktab(5)
8449638Scael*/
8534948Smckusick#define	DISKTAB		"/etc/disktab"
8634948Smckusick
8734948Smckusick/*
8849638Scael* Each disk has a label which includes information about the hardware
8949638Scael* disk geometry, filesystem partitions, and drive specific information.
9049638Scael* The label is in block 0 or 1, possibly offset from the beginning
9149638Scael* to leave room for a bootstrap, etc.
9249638Scael*/
9349638Scael
9458604Smckusick#ifndef	LABELSECTOR
9558604Smckusick#define LABELSECTOR	0			/* sector containing label */
9658604Smckusick#endif
9758604Smckusick
9858604Smckusick#ifndef	LABELOFFSET
9958604Smckusick#define LABELOFFSET	64			/* offset of label in sector */
10058604Smckusick#endif
10158604Smckusick
10234948Smckusick#define DISKMAGIC	((u_long) 0x82564557)	/* The disk magic number */
10334948Smckusick#ifndef MAXPARTITIONS
10434948Smckusick#define	MAXPARTITIONS	8
10534948Smckusick#endif
10634948Smckusick
10734948Smckusick#ifndef LOCORE
10834948Smckusickstruct disklabel {
10934948Smckusick	u_long	d_magic;	/* the magic number */
11034948Smckusick	short	d_type;		/* drive type */
11134948Smckusick	short	d_subtype;	/* controller/d_type specific */
11234948Smckusick	char	d_typename[16];	/* type name, e.g. "eagle" */
11334948Smckusick	/*
11449638Scael	* d_packname contains the pack identifier and is returned when
11549638Scael	* the disklabel is read off the disk or in-core copy.
11649638Scael	* d_boot0 and d_boot1 are the (optional) names of the
11749638Scael	* primary (block 0) and secondary (block 1-15) bootstraps
11849638Scael	* as found in /usr/mdec.  These are returned when using
11949638Scael	* getdiskbyname(3)
12049638Scael	to retrieve the values from /etc/disktab.
12149638Scael	*/
12234948Smckusick#if defined(KERNEL) || defined(STANDALONE)
12334948Smckusick	char	d_packname[16];		/* pack identifier */
12434948Smckusick#else
12534948Smckusick	union {
12634948Smckusick		char	un_d_packname[16];	/* pack identifier */
12734948Smckusick		struct {
12834948Smckusick			char *un_d_boot0;	/* primary bootstrap name */
12934948Smckusick			char *un_d_boot1;	/* secondary bootstrap name */
13034948Smckusick		} un_b;
13134948Smckusick	} d_un;
13249638Scael
13334948Smckusick#define d_packname	d_un.un_d_packname
13434948Smckusick#define d_boot0		d_un.un_b.un_d_boot0
13534948Smckusick#define d_boot1		d_un.un_b.un_d_boot1
13634948Smckusick#endif	/* ! KERNEL or STANDALONE */
13749638Scael
13849638Scael	/* disk geometry: */
13934948Smckusick	u_long	d_secsize;	/* # of bytes per sector */
14034948Smckusick	u_long	d_nsectors;	/* # of data sectors per track */
14134948Smckusick	u_long	d_ntracks;	/* # of tracks per cylinder */
14234948Smckusick	u_long	d_ncylinders;	/* # of data cylinders per unit */
14334948Smckusick	u_long	d_secpercyl;	/* # of data sectors per cylinder */
14434948Smckusick	u_long	d_secperunit;	/* # of data sectors per unit */
14534948Smckusick	/*
14649638Scael	* Spares (bad sector replacements) below
14749638Scael	* are not counted in d_nsectors or d_secpercyl.
14849638Scael	* Spare sectors are assumed to be physical sectors
14949638Scael	* which occupy space at the end of each track and/or cylinder.
15049638Scael	*/
15134948Smckusick	u_short	d_sparespertrack;	/* # of spare sectors per track */
15234948Smckusick	u_short	d_sparespercyl;	/* # of spare sectors per cylinder */
15334948Smckusick	/*
15449638Scael	* Alternate cylinders include maintenance, replacement,
15549638Scael	* configuration description areas, etc.
15649638Scael	*/
15734948Smckusick	u_long	d_acylinders;	/* # of alt. cylinders per unit */
15834948Smckusick
15934948Smckusick		/* hardware characteristics: */
16034948Smckusick	/*
16149638Scael	* d_interleave, d_trackskew and d_cylskew describe perturbations
16249638Scael	* in the media format used to compensate for a slow controller.
16349638Scael	* Interleave is physical sector interleave, set up by the formatter
16449638Scael	* or controller when formatting.  When interleaving is in use,
16549638Scael	* logically adjacent sectors are not physically contiguous,
16649638Scael	* but instead are separated by some number of sectors.
16749638Scael	* It is specified as the ratio of physical sectors traversed
16849638Scael	* per logical sector.  Thus an interleave of 1:1 implies contiguous
16949638Scael	* layout, while 2:1 implies that logical sector 0 is separated
17049638Scael	* by one sector from logical sector 1.
17149638Scael	* d_trackskew is the offset of sector 0 on track N
17249638Scael	* relative to sector 0 on track N-1 on the same cylinder.
17349638Scael	* Finally, d_cylskew is the offset of sector 0 on cylinder N
17449638Scael	* relative to sector 0 on cylinder N-1.
17549638Scael	*/
17634948Smckusick	u_short	d_rpm;	/* rotational speed */
17734948Smckusick	u_short	d_interleave;	/* hardware sector interleave */
17834948Smckusick	u_short	d_trackskew;	/* sector 0 skew, per track */
17934948Smckusick	u_short	d_cylskew;	/* sector 0 skew, per cylinder */
18034948Smckusick	u_long	d_headswitch;	/* head switch time, usec */
18134948Smckusick	u_long	d_trkseek;	/* track-to-track seek, usec */
18234948Smckusick	u_long	d_flags;	/* generic flags */
18334948Smckusick#define NDDATA 5
18434948Smckusick	u_long	d_drivedata[NDDATA];	/* drive-type specific information */
18534948Smckusick#define NSPARE 5
18634948Smckusick	u_long	d_spare[NSPARE];	/* reserved for future use */
18734948Smckusick	u_long	d_magic2;	/* the magic number (again) */
18834948Smckusick	u_short	d_checksum;	/* xor of data incl. partitions */
18934948Smckusick
19049638Scael	/* filesystem and partition information: */
19134948Smckusick	u_short	d_npartitions;	/* number of partitions in following */
19234948Smckusick	u_long	d_bbsize;	/* size of boot area at sn0, bytes */
19334948Smckusick	u_long	d_sbsize;	/* max size of fs superblock, bytes */
19434948Smckusick	struct	partition {	/* the partition table */
19534948Smckusick		u_long	p_size;	/* number of sectors in partition */
19634948Smckusick		u_long	p_offset;	/* starting sector */
19734948Smckusick		u_long	p_fsize;	/* filesystem basic fragment size */
19834948Smckusick		u_char	p_fstype;	/* filesystem type, see below */
19934948Smckusick		u_char	p_frag;	/* filesystem fragments per block */
20058604Smckusick		union {
20158604Smckusick			u_short	cpg;	/* UFS: FS cylinders per group */
20258604Smckusick			u_short	sgs;	/* LFS: FS segment shift */
20358604Smckusick		} __partition_u1;
20458604Smckusick#define	p_cpg	__partition_u1.cpg
20558604Smckusick#define	p_sgs	__partition_u1.sgs
20634948Smckusick		u_short	p_cpg;	/* filesystem cylinders per group */
20734948Smckusick	} d_partitions[MAXPARTITIONS];	/* actually may be more */
20834948Smckusick};
20934948Smckusick
21034948Smckusick/* d_type values: */
21134948Smckusick#define	DTYPE_SMD	1	/* SMD, XSMD; VAX hp/up */
21234948Smckusick#define	DTYPE_MSCP	2	/* MSCP */
21334948Smckusick#define	DTYPE_DEC	3	/* other DEC (rk, rl) */
21434948Smckusick#define	DTYPE_SCSI	4	/* SCSI */
21534948Smckusick#define	DTYPE_ESDI	5	/* ESDI interface */
21634948Smckusick#define	DTYPE_ST506	6	/* ST506 etc. */
21758604Smckusick#define	DTYPE_HPIB	7	/* CS/80 on HP-IB */
21858604Smckusick#define	DTYPE_HPFL	8	/* HP Fiber-link */
21934948Smckusick#define	DTYPE_FLOPPY	10	/* floppy */
22034948Smckusick
22134948Smckusick#ifdef DKTYPENAMES
22234948Smckusickstatic char *dktypenames[] = {
22334948Smckusick	"unknown",
22434948Smckusick	"SMD",
22534948Smckusick	"MSCP",
22634948Smckusick	"old DEC",
22734948Smckusick	"SCSI",
22834948Smckusick	"ESDI",
22958604Smckusick	"ST506",
23058604Smckusick	"HP-IB",
23158604Smckusick	"HP-FL",
23234948Smckusick	"type 9",
23334948Smckusick	"floppy",
23434948Smckusick	0
23534948Smckusick};
23634948Smckusick#define DKMAXTYPES	(sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
23734948Smckusick#endif
23834948Smckusick
23934948Smckusick/*
24049638Scael* Filesystem type and version.
24149638Scael* Used to interpret other filesystem-specific
24249638Scael* per-partition information.
24349638Scael*/
24434948Smckusick#define	FS_UNUSED	0	/* unused */
24549638Scael#define	FS_SWAP		1	/* swap */
24649638Scael#define	FS_V6		2	/* Sixth Edition */
24749638Scael#define	FS_V7		3	/* Seventh Edition */
24849638Scael#define	FS_SYSV		4	/* System V */
24949638Scael#define	FS_V71K		5	/* V7 with 1K blocks (4.1, 2.9) */
25049638Scael#define	FS_V8		6	/* Eighth Edition, 4K blocks */
25134948Smckusick#define	FS_BSDFFS	7	/* 4.2BSD fast file system */
25258604Smckusick#define	FS_MSDOS	8	/* MSDOS file system */
25358604Smckusick#define	FS_BSDLFS	9	/* 4.4BSD log-structured file system */
25458604Smckusick#define	FS_OTHER	10	/* in use, but unknown/unsupported */
25558604Smckusick#define	FS_HPFS		11	/* OS/2 high-performance file system */
25658604Smckusick#define	FS_ISO9660	12	/* ISO 9660, normally CD-ROM */
25758604Smckusick#define	FS_BOOT		13	/* partition contains bootstrap */
25834948Smckusick
25934948Smckusick#ifdef	DKTYPENAMES
26034948Smckusickstatic char *fstypenames[] = {
26134948Smckusick	"unused",
26234948Smckusick	"swap",
26334948Smckusick	"Version 6",
26434948Smckusick	"Version 7",
26534948Smckusick	"System V",
26634948Smckusick	"4.1BSD",
26734948Smckusick	"Eighth Edition",
26834948Smckusick	"4.2BSD",
26958604Smckusick	"MSDOS",
27058604Smckusick	"4.4LFS",
27158604Smckusick	"unknown",
27258604Smckusick	"HPFS",
27358604Smckusick	"ISO9660",
27458604Smckusick	"boot",
27534948Smckusick	0
27634948Smckusick};
27734948Smckusick#define FSMAXTYPES	(sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
27834948Smckusick#endif
27934948Smckusick
28034948Smckusick/*
28149638Scael* flags shared by various drives:
28249638Scael*/
28334948Smckusick#define	D_REMOVABLE	0x01	/* removable media */
28449638Scael#define	D_ECC		0x02	/* supports ECC */
28534948Smckusick#define	D_BADSECT	0x04	/* supports bad sector forw. */
28634948Smckusick#define	D_RAMDISK	0x08	/* disk emulator */
28749638Scael#define	D_CHAIN		0x10	/* can do back-back transfers */
28834948Smckusick
28934948Smckusick/*
29049638Scael* Drive data for SMD.
29149638Scael*/
29249638Scael
29334948Smckusick#define	d_smdflags	d_drivedata[0]
29449638Scael#define	D_SSE		0x1	/* supports skip sectoring */
29534948Smckusick#define	d_mindist	d_drivedata[1]
29634948Smckusick#define	d_maxdist	d_drivedata[2]
29749638Scael#define	d_sdist		d_drivedata[3]
29834948Smckusick
29934948Smckusick/*
30049638Scael* Drive data for ST506.
30149638Scael*/
30234948Smckusick#define d_precompcyl	d_drivedata[0]
30349638Scael#define d_gap3		d_drivedata[1]	/* used only when formatting */
30434948Smckusick
30558604Smckusick/*
30658604Smckusick * Drive data for SCSI.
30758604Smckusick */
30858604Smckusick#define	d_blind		d_drivedata[0]
30958604Smckusick
31034948Smckusick#ifndef LOCORE
31134948Smckusick/*
31249638Scael* Structure used to perform a format
31349638Scael* or other raw operation, returning data
31449638Scael* and/or register values.
31549638Scael* Register identification and format
31649638Scael* are device- and driver-dependent.
31749638Scael*/
31834948Smckusickstruct format_op {
31934948Smckusick	char	*df_buf;
32034948Smckusick	int	df_count;	/* value-result */
32134948Smckusick	daddr_t	df_startblk;
32234948Smckusick	int	df_reg[8];	/* result */
32334948Smckusick};
32434948Smckusick
32534948Smckusick/*
32649638Scael* Structure used internally to retrieve
32749638Scael* information about a partition on a disk.
32849638Scael*/
32934948Smckusickstruct partinfo {
33034948Smckusick	struct	disklabel *disklab;
33134948Smckusick	struct	partition *part;
33234948Smckusick};
33334948Smckusick
33434948Smckusick/*
33549638Scael* Disk-specific ioctls.
33649638Scael*/
33749638Scael	/* get and set disklabel; DIOCGPART used internally */
33849638Scael#define DIOCGDINFO   _IOR('d', 101, struct disklabel) /* get */
33949638Scael#define DIOCSDINFO   _IOW('d', 102, struct disklabel) /* set */
34049638Scael#define DIOCWDINFO   _IOW('d', 103, struct disklabel) /* set, update disk */
34149638Scael#define DIOCGPART    _IOW('d', 104, struct partinfo)  /* get partition */
34234948Smckusick
34334948Smckusick/* do format operation, read or write */
34434948Smckusick#define DIOCRFORMAT	_IOWR('d', 105, struct format_op)
34534948Smckusick#define DIOCWFORMAT	_IOWR('d', 106, struct format_op)
34634948Smckusick
34749638Scael#define DIOCSSTEP	_IOW('d', 107, int) /* set step rate */
34849638Scael#define DIOCSRETRIES	_IOW('d', 108, int) /* set # of retries */
34949638Scael#define DIOCWLABEL	_IOW('d', 109, int) /* write en/disable label */
35034948Smckusick
35149638Scael#define DIOCSBAD	_IOW('d', 110, struct dkbad) /* set kernel dkbad */
35234948Smckusick
35334948Smckusick#endif LOCORE
35449638Scael.Ed
35549638Scael.Sh SEE ALSO
35649638Scael.Xr disktab 5 ,
35749638Scael.Xr disklabel 8
35849638Scael.Sh HISTORY
359*67104SmckusickThe
360*67104Smckusick.Nm disklabel
361*67104Smckusickfunction was introduced in
362*67104Smckusick.Bx 4.3 Tahoe .
363