do not require valid disk when -T is specified
[unix-history] / usr / src / sbin / disklabel / disklabel.5.5
CommitLineData
eadcc84a 1.\" Copyright (c) 1987, 1991 Regents of the University of California.
57a981eb 2.\" All rights reserved.
37adbef5 3.\"
57a981eb
KB
4.\" This code is derived from software contributed to Berkeley by
5.\" Symmetric Computer Systems.
6.\"
eadcc84a 7.\" %sccs.include.redist.roff%
57a981eb 8.\"
eadcc84a 9.\" @(#)disklabel.5.5 6.6 (Berkeley) %G%
37adbef5 10.\"
eadcc84a
CL
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
37adbef5
MK
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
eadcc84a 26.Xr disklabel 8
37adbef5
MK
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.
afbc24d7
MK
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.
eadcc84a 37.Pp
37adbef5 38The label is located in sector number
eadcc84a 39.Dv LABELSECTOR
37adbef5
MK
40of the drive, usually sector 0 where it may be found
41without any information about the disk geometry.
42It is at an offset
eadcc84a 43.Dv LABELOFFSET
37adbef5 44from the beginning of the sector, to allow room for the initial bootstrap.
afbc24d7
MK
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;
eadcc84a
CL
48the
49.Dv DIOCWLABEL
50.Xr ioctl 2 ,
afbc24d7 51which is done as needed by the
eadcc84a 52.Xr disklabel
afbc24d7 53program.
eadcc84a
CL
54.Pp
55A copy of the in-core label for a disk can be obtained with the
56.Dv DIOCGDINFO
57.Xr ioctl ;
afbc24d7
MK
58this works with a file descriptor for a block or character (``raw'') device
59for any partition of the disk.
eadcc84a
CL
60The in-core copy of the label is set by the
61.Dv DIOCSDINFO
62.Xr ioctl .
afbc24d7
MK
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.
eadcc84a
CL
68Finally, the
69.Dv DIOCWDINFO
70.Xr ioctl
afbc24d7
MK
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
eadcc84a
CL
76.Xr disklabel .
77.Pp
37adbef5 78The format of the disk label, as specified in
eadcc84a 79.Aw Pa sys/disklabel.h ,
37adbef5 80is
eadcc84a 81.Bd -literal
7f6b9dcb 82/*
eadcc84a
CL
83* Disk description table, see disktab(5)
84*/
7f6b9dcb
KM
85#define DISKTAB "/etc/disktab"
86
87/*
eadcc84a
CL
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
7f6b9dcb
KM
94#define LABELSECTOR 0 /* sector containing label */
95#define LABELOFFSET 64 /* offset of label in sector */
96#define DISKMAGIC ((u_long) 0x82564557) /* The disk magic number */
97#ifndef MAXPARTITIONS
98#define MAXPARTITIONS 8
99#endif
100
7f6b9dcb
KM
101#ifndef LOCORE
102struct disklabel {
103 u_long d_magic; /* the magic number */
104 short d_type; /* drive type */
105 short d_subtype; /* controller/d_type specific */
106 char d_typename[16]; /* type name, e.g. "eagle" */
107 /*
eadcc84a
CL
108 * d_packname contains the pack identifier and is returned when
109 * the disklabel is read off the disk or in-core copy.
110 * d_boot0 and d_boot1 are the (optional) names of the
111 * primary (block 0) and secondary (block 1-15) bootstraps
112 * as found in /usr/mdec. These are returned when using
113 * getdiskbyname(3)
114 to retrieve the values from /etc/disktab.
115 */
7f6b9dcb
KM
116#if defined(KERNEL) || defined(STANDALONE)
117 char d_packname[16]; /* pack identifier */
118#else
7f6b9dcb
KM
119 union {
120 char un_d_packname[16]; /* pack identifier */
121 struct {
122 char *un_d_boot0; /* primary bootstrap name */
123 char *un_d_boot1; /* secondary bootstrap name */
124 } un_b;
125 } d_un;
eadcc84a 126
7f6b9dcb
KM
127#define d_packname d_un.un_d_packname
128#define d_boot0 d_un.un_b.un_d_boot0
129#define d_boot1 d_un.un_b.un_d_boot1
130#endif /* ! KERNEL or STANDALONE */
eadcc84a
CL
131
132 /* disk geometry: */
7f6b9dcb
KM
133 u_long d_secsize; /* # of bytes per sector */
134 u_long d_nsectors; /* # of data sectors per track */
135 u_long d_ntracks; /* # of tracks per cylinder */
136 u_long d_ncylinders; /* # of data cylinders per unit */
137 u_long d_secpercyl; /* # of data sectors per cylinder */
138 u_long d_secperunit; /* # of data sectors per unit */
139 /*
eadcc84a
CL
140 * Spares (bad sector replacements) below
141 * are not counted in d_nsectors or d_secpercyl.
142 * Spare sectors are assumed to be physical sectors
143 * which occupy space at the end of each track and/or cylinder.
144 */
7f6b9dcb
KM
145 u_short d_sparespertrack; /* # of spare sectors per track */
146 u_short d_sparespercyl; /* # of spare sectors per cylinder */
147 /*
eadcc84a
CL
148 * Alternate cylinders include maintenance, replacement,
149 * configuration description areas, etc.
150 */
7f6b9dcb
KM
151 u_long d_acylinders; /* # of alt. cylinders per unit */
152
153 /* hardware characteristics: */
154 /*
eadcc84a
CL
155 * d_interleave, d_trackskew and d_cylskew describe perturbations
156 * in the media format used to compensate for a slow controller.
157 * Interleave is physical sector interleave, set up by the formatter
158 * or controller when formatting. When interleaving is in use,
159 * logically adjacent sectors are not physically contiguous,
160 * but instead are separated by some number of sectors.
161 * It is specified as the ratio of physical sectors traversed
162 * per logical sector. Thus an interleave of 1:1 implies contiguous
163 * layout, while 2:1 implies that logical sector 0 is separated
164 * by one sector from logical sector 1.
165 * d_trackskew is the offset of sector 0 on track N
166 * relative to sector 0 on track N-1 on the same cylinder.
167 * Finally, d_cylskew is the offset of sector 0 on cylinder N
168 * relative to sector 0 on cylinder N-1.
169 */
7f6b9dcb
KM
170 u_short d_rpm; /* rotational speed */
171 u_short d_interleave; /* hardware sector interleave */
172 u_short d_trackskew; /* sector 0 skew, per track */
173 u_short d_cylskew; /* sector 0 skew, per cylinder */
174 u_long d_headswitch; /* head switch time, usec */
175 u_long d_trkseek; /* track-to-track seek, usec */
176 u_long d_flags; /* generic flags */
177#define NDDATA 5
178 u_long d_drivedata[NDDATA]; /* drive-type specific information */
179#define NSPARE 5
180 u_long d_spare[NSPARE]; /* reserved for future use */
181 u_long d_magic2; /* the magic number (again) */
182 u_short d_checksum; /* xor of data incl. partitions */
183
eadcc84a 184 /* filesystem and partition information: */
7f6b9dcb
KM
185 u_short d_npartitions; /* number of partitions in following */
186 u_long d_bbsize; /* size of boot area at sn0, bytes */
187 u_long d_sbsize; /* max size of fs superblock, bytes */
188 struct partition { /* the partition table */
7f6b9dcb
KM
189 u_long p_size; /* number of sectors in partition */
190 u_long p_offset; /* starting sector */
191 u_long p_fsize; /* filesystem basic fragment size */
192 u_char p_fstype; /* filesystem type, see below */
193 u_char p_frag; /* filesystem fragments per block */
194 u_short p_cpg; /* filesystem cylinders per group */
7f6b9dcb
KM
195 } d_partitions[MAXPARTITIONS]; /* actually may be more */
196};
197
198/* d_type values: */
7f6b9dcb
KM
199#define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
200#define DTYPE_MSCP 2 /* MSCP */
201#define DTYPE_DEC 3 /* other DEC (rk, rl) */
202#define DTYPE_SCSI 4 /* SCSI */
203#define DTYPE_ESDI 5 /* ESDI interface */
204#define DTYPE_ST506 6 /* ST506 etc. */
205#define DTYPE_FLOPPY 10 /* floppy */
206
207#ifdef DKTYPENAMES
208static char *dktypenames[] = {
209 "unknown",
210 "SMD",
211 "MSCP",
212 "old DEC",
213 "SCSI",
214 "ESDI",
215 "type 6",
216 "type 7",
217 "type 8",
218 "type 9",
219 "floppy",
220 0
221};
222#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
223#endif
224
225/*
eadcc84a
CL
226* Filesystem type and version.
227* Used to interpret other filesystem-specific
228* per-partition information.
229*/
7f6b9dcb 230#define FS_UNUSED 0 /* unused */
eadcc84a
CL
231#define FS_SWAP 1 /* swap */
232#define FS_V6 2 /* Sixth Edition */
233#define FS_V7 3 /* Seventh Edition */
234#define FS_SYSV 4 /* System V */
235#define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
236#define FS_V8 6 /* Eighth Edition, 4K blocks */
7f6b9dcb
KM
237#define FS_BSDFFS 7 /* 4.2BSD fast file system */
238
239#ifdef DKTYPENAMES
240static char *fstypenames[] = {
241 "unused",
242 "swap",
243 "Version 6",
244 "Version 7",
245 "System V",
246 "4.1BSD",
247 "Eighth Edition",
248 "4.2BSD",
249 0
250};
251#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
252#endif
253
254/*
eadcc84a
CL
255* flags shared by various drives:
256*/
7f6b9dcb 257#define D_REMOVABLE 0x01 /* removable media */
eadcc84a 258#define D_ECC 0x02 /* supports ECC */
7f6b9dcb
KM
259#define D_BADSECT 0x04 /* supports bad sector forw. */
260#define D_RAMDISK 0x08 /* disk emulator */
eadcc84a 261#define D_CHAIN 0x10 /* can do back-back transfers */
7f6b9dcb
KM
262
263/*
eadcc84a
CL
264* Drive data for SMD.
265*/
266
7f6b9dcb 267#define d_smdflags d_drivedata[0]
eadcc84a 268#define D_SSE 0x1 /* supports skip sectoring */
7f6b9dcb
KM
269#define d_mindist d_drivedata[1]
270#define d_maxdist d_drivedata[2]
eadcc84a 271#define d_sdist d_drivedata[3]
7f6b9dcb
KM
272
273/*
eadcc84a
CL
274* Drive data for ST506.
275*/
7f6b9dcb 276#define d_precompcyl d_drivedata[0]
eadcc84a 277#define d_gap3 d_drivedata[1] /* used only when formatting */
7f6b9dcb
KM
278
279#ifndef LOCORE
280/*
eadcc84a
CL
281* Structure used to perform a format
282* or other raw operation, returning data
283* and/or register values.
284* Register identification and format
285* are device- and driver-dependent.
286*/
7f6b9dcb
KM
287struct format_op {
288 char *df_buf;
289 int df_count; /* value-result */
290 daddr_t df_startblk;
291 int df_reg[8]; /* result */
292};
293
294/*
eadcc84a
CL
295* Structure used internally to retrieve
296* information about a partition on a disk.
297*/
7f6b9dcb
KM
298struct partinfo {
299 struct disklabel *disklab;
300 struct partition *part;
301};
302
303/*
eadcc84a
CL
304* Disk-specific ioctls.
305*/
306 /* get and set disklabel; DIOCGPART used internally */
307#define DIOCGDINFO _IOR('d', 101, struct disklabel) /* get */
308#define DIOCSDINFO _IOW('d', 102, struct disklabel) /* set */
309#define DIOCWDINFO _IOW('d', 103, struct disklabel) /* set, update disk */
310#define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */
7f6b9dcb
KM
311
312/* do format operation, read or write */
313#define DIOCRFORMAT _IOWR('d', 105, struct format_op)
314#define DIOCWFORMAT _IOWR('d', 106, struct format_op)
315
eadcc84a
CL
316#define DIOCSSTEP _IOW('d', 107, int) /* set step rate */
317#define DIOCSRETRIES _IOW('d', 108, int) /* set # of retries */
318#define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */
7f6b9dcb 319
eadcc84a 320#define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */
7f6b9dcb
KM
321
322#endif LOCORE
eadcc84a
CL
323.Ed
324.Sh SEE ALSO
325.Xr disktab 5 ,
326.Xr disklabel 8
327.Sh HISTORY