Commit | Line | Data |
---|---|---|
57a981eb KB |
1 | .\" Copyright (c) 1987 Regents of the University of California. |
2 | .\" All rights reserved. | |
37adbef5 | 3 | .\" |
57a981eb KB |
4 | .\" This code is derived from software contributed to Berkeley by |
5 | .\" Symmetric Computer Systems. | |
6 | .\" | |
91cff1e1 | 7 | .\" %sccs.include.redist.man% |
57a981eb | 8 | .\" |
91cff1e1 | 9 | .\" @(#)disklabel.5.5 6.5 (Berkeley) %G% |
37adbef5 MK |
10 | .\" |
11 | .TH DISKLABEL 5 "" | |
12 | .UC 7 | |
13 | .SH NAME | |
14 | disklabel \- disk pack label | |
15 | .SH SYNOPSIS | |
16 | .B #include <sys/disklabel.h> | |
17 | .SH DESCRIPTION | |
18 | Each disk or disk pack on a system may contain a disk label | |
19 | which provides detailed information | |
20 | about the geometry of the disk and the partitions into which the disk | |
21 | is divided. | |
22 | It should be initialized when the disk is formatted, | |
23 | and may be changed later with the | |
24 | .IR disklabel (8) | |
25 | program. | |
26 | This information is used by the system disk driver and by the bootstrap | |
27 | program to determine how to program the drive | |
28 | and where to find the filesystems on the disk partitions. | |
29 | Additional information is used by the filesystem in order | |
30 | to use the disk most efficiently and to locate important filesystem information. | |
afbc24d7 MK |
31 | The description of each partition contains an identifier for the partition |
32 | type (standard filesystem, swap area, etc.). | |
33 | The filesystem updates the in-core copy of the label if it contains | |
34 | incomplete information about the filesystem. | |
35 | .PP | |
37adbef5 MK |
36 | The label is located in sector number |
37 | .I LABELSECTOR | |
38 | of the drive, usually sector 0 where it may be found | |
39 | without any information about the disk geometry. | |
40 | It is at an offset | |
41 | .I LABELOFFSET | |
42 | from the beginning of the sector, to allow room for the initial bootstrap. | |
afbc24d7 MK |
43 | The disk sector containing the label is normally made read-only |
44 | so that it is not accidentally overwritten by pack-to-pack copies | |
45 | or swap operations; | |
46 | the DIOCWLABEL | |
47 | .IR ioctl , | |
48 | which is done as needed by the | |
49 | .IR disklabel (8) | |
50 | program. | |
51 | .PP | |
52 | A copy of the in-core label for a disk can be obtained with the DIOCGDINFO | |
53 | .IR ioctl ; | |
54 | this works with a file descriptor for a block or character (``raw'') device | |
55 | for any partition of the disk. | |
56 | The in-core copy of the label is set by the DIOCSDINFO | |
57 | .IR ioctl . | |
58 | The offset of a partition cannot generally be changed while it is open, | |
59 | nor can it be made smaller while it is open. | |
60 | One exception is that any change is allowed if no label was found | |
61 | on the disk, and the driver was able to construct only a skeletal label | |
62 | without partition information. | |
63 | Finally, the DIOCWDINFO | |
64 | .I ioctl | |
65 | operation sets the in-core label and then updates the on-disk label; | |
66 | there must be an existing label on the disk for this operation to succeed. | |
67 | Thus, the initial label for a disk or disk pack must be installed | |
68 | by writing to the raw disk. | |
69 | All of these operations are normally done using | |
70 | .IR disklabel (8). | |
71 | .PP | |
37adbef5 MK |
72 | The format of the disk label, as specified in |
73 | .RI < sys/disklabel.h >, | |
74 | is | |
75 | .nf | |
76 | .DT | |
7f6b9dcb KM |
77 | /* |
78 | * Disk description table, see disktab(5) | |
79 | */ | |
80 | #define DISKTAB "/etc/disktab" | |
81 | ||
82 | /* | |
83 | * Each disk has a label which includes information about the hardware | |
84 | * disk geometry, filesystem partitions, and drive specific information. | |
85 | * The label is in block 0 or 1, possibly offset from the beginning | |
86 | * to leave room for a bootstrap, etc. | |
87 | */ | |
88 | .ta \w'#define 'u +\w'MAXPARTITIONS 'u +\w'((u_long) 0x82564557) 'u | |
89 | #define LABELSECTOR 0 /* sector containing label */ | |
90 | #define LABELOFFSET 64 /* offset of label in sector */ | |
91 | #define DISKMAGIC ((u_long) 0x82564557) /* The disk magic number */ | |
92 | #ifndef MAXPARTITIONS | |
93 | #define MAXPARTITIONS 8 | |
94 | #endif | |
95 | ||
96 | ||
97 | .ta \w'struct 'u +\w'u_long 'u +\w'd_packname[16] 'u | |
98 | #ifndef LOCORE | |
99 | struct disklabel { | |
100 | u_long d_magic; /* the magic number */ | |
101 | short d_type; /* drive type */ | |
102 | short d_subtype; /* controller/d_type specific */ | |
103 | char d_typename[16]; /* type name, e.g. "eagle" */ | |
104 | /* | |
105 | * d_packname contains the pack identifier and is returned when | |
106 | * the disklabel is read off the disk or in-core copy. | |
107 | * d_boot0 and d_boot1 are the (optional) names of the | |
108 | * primary (block 0) and secondary (block 1-15) bootstraps | |
109 | * as found in /usr/mdec. These are returned when using | |
110 | * getdiskbyname(3) to retrieve the values from /etc/disktab. | |
111 | */ | |
112 | #if defined(KERNEL) || defined(STANDALONE) | |
113 | char d_packname[16]; /* pack identifier */ | |
114 | #else | |
115 | .ta \w'struct 'u +\w'struct 'u +\w'struct { 'u +\w'un_d_packname[16] 'u | |
116 | union { | |
117 | char un_d_packname[16]; /* pack identifier */ | |
118 | struct { | |
119 | char *un_d_boot0; /* primary bootstrap name */ | |
120 | char *un_d_boot1; /* secondary bootstrap name */ | |
121 | } un_b; | |
122 | } d_un; | |
123 | .ta \w'#define 'u +\w'd_packname 'u | |
124 | #define d_packname d_un.un_d_packname | |
125 | #define d_boot0 d_un.un_b.un_d_boot0 | |
126 | #define d_boot1 d_un.un_b.un_d_boot1 | |
127 | #endif /* ! KERNEL or STANDALONE */ | |
128 | .ta \w'struct 'u +\w'u_short 'u +\w'd_d_drivedata[NDDATA] 'u | |
129 | /* disk geometry: */ | |
130 | u_long d_secsize; /* # of bytes per sector */ | |
131 | u_long d_nsectors; /* # of data sectors per track */ | |
132 | u_long d_ntracks; /* # of tracks per cylinder */ | |
133 | u_long d_ncylinders; /* # of data cylinders per unit */ | |
134 | u_long d_secpercyl; /* # of data sectors per cylinder */ | |
135 | u_long d_secperunit; /* # of data sectors per unit */ | |
136 | /* | |
137 | * Spares (bad sector replacements) below | |
138 | * are not counted in d_nsectors or d_secpercyl. | |
139 | * Spare sectors are assumed to be physical sectors | |
140 | * which occupy space at the end of each track and/or cylinder. | |
141 | */ | |
142 | u_short d_sparespertrack; /* # of spare sectors per track */ | |
143 | u_short d_sparespercyl; /* # of spare sectors per cylinder */ | |
144 | /* | |
145 | * Alternate cylinders include maintenance, replacement, | |
146 | * configuration description areas, etc. | |
147 | */ | |
148 | u_long d_acylinders; /* # of alt. cylinders per unit */ | |
149 | ||
150 | /* hardware characteristics: */ | |
151 | /* | |
152 | * d_interleave, d_trackskew and d_cylskew describe perturbations | |
153 | * in the media format used to compensate for a slow controller. | |
154 | * Interleave is physical sector interleave, set up by the formatter | |
155 | * or controller when formatting. When interleaving is in use, | |
156 | * logically adjacent sectors are not physically contiguous, | |
157 | * but instead are separated by some number of sectors. | |
158 | * It is specified as the ratio of physical sectors traversed | |
159 | * per logical sector. Thus an interleave of 1:1 implies contiguous | |
160 | * layout, while 2:1 implies that logical sector 0 is separated | |
161 | * by one sector from logical sector 1. | |
162 | * d_trackskew is the offset of sector 0 on track N | |
163 | * relative to sector 0 on track N-1 on the same cylinder. | |
164 | * Finally, d_cylskew is the offset of sector 0 on cylinder N | |
165 | * relative to sector 0 on cylinder N-1. | |
166 | */ | |
167 | u_short d_rpm; /* rotational speed */ | |
168 | u_short d_interleave; /* hardware sector interleave */ | |
169 | u_short d_trackskew; /* sector 0 skew, per track */ | |
170 | u_short d_cylskew; /* sector 0 skew, per cylinder */ | |
171 | u_long d_headswitch; /* head switch time, usec */ | |
172 | u_long d_trkseek; /* track-to-track seek, usec */ | |
173 | u_long d_flags; /* generic flags */ | |
174 | #define NDDATA 5 | |
175 | u_long d_drivedata[NDDATA]; /* drive-type specific information */ | |
176 | #define NSPARE 5 | |
177 | u_long d_spare[NSPARE]; /* reserved for future use */ | |
178 | u_long d_magic2; /* the magic number (again) */ | |
179 | u_short d_checksum; /* xor of data incl. partitions */ | |
180 | ||
181 | /* filesystem and partition information: */ | |
182 | u_short d_npartitions; /* number of partitions in following */ | |
183 | u_long d_bbsize; /* size of boot area at sn0, bytes */ | |
184 | u_long d_sbsize; /* max size of fs superblock, bytes */ | |
185 | struct partition { /* the partition table */ | |
186 | .ta \w'struct 'u +\w'struct 'u +\w'u_short 'u +\w'd_d_drivedata[NDDATA] 'u | |
187 | u_long p_size; /* number of sectors in partition */ | |
188 | u_long p_offset; /* starting sector */ | |
189 | u_long p_fsize; /* filesystem basic fragment size */ | |
190 | u_char p_fstype; /* filesystem type, see below */ | |
191 | u_char p_frag; /* filesystem fragments per block */ | |
192 | u_short p_cpg; /* filesystem cylinders per group */ | |
193 | .ta \w'struct 'u +\w'u_short 'u +\w'd_d_drivedata[NDDATA] 'u | |
194 | } d_partitions[MAXPARTITIONS]; /* actually may be more */ | |
195 | }; | |
196 | ||
197 | /* d_type values: */ | |
198 | .ta \w'#define 'u +\w'DTYPE_FLOPPY 'u +\w'0x10 'u | |
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 | |
208 | static 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 | /* | |
226 | * Filesystem type and version. | |
227 | * Used to interpret other filesystem-specific | |
228 | * per-partition information. | |
229 | */ | |
230 | #define FS_UNUSED 0 /* unused */ | |
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 */ | |
237 | #define FS_BSDFFS 7 /* 4.2BSD fast file system */ | |
238 | ||
239 | #ifdef DKTYPENAMES | |
240 | static 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 | /* | |
255 | * flags shared by various drives: | |
256 | */ | |
257 | #define D_REMOVABLE 0x01 /* removable media */ | |
258 | #define D_ECC 0x02 /* supports ECC */ | |
259 | #define D_BADSECT 0x04 /* supports bad sector forw. */ | |
260 | #define D_RAMDISK 0x08 /* disk emulator */ | |
261 | #define D_CHAIN 0x10 /* can do back-back transfers */ | |
262 | ||
263 | /* | |
264 | * Drive data for SMD. | |
265 | */ | |
266 | .ta \w'#define 'u +\w'DTYPE_FLOPPY 'u +\w'd_drivedata[1] 'u | |
267 | #define d_smdflags d_drivedata[0] | |
268 | #define D_SSE 0x1 /* supports skip sectoring */ | |
269 | #define d_mindist d_drivedata[1] | |
270 | #define d_maxdist d_drivedata[2] | |
271 | #define d_sdist d_drivedata[3] | |
272 | ||
273 | /* | |
274 | * Drive data for ST506. | |
275 | */ | |
276 | #define d_precompcyl d_drivedata[0] | |
277 | #define d_gap3 d_drivedata[1] /* used only when formatting */ | |
278 | ||
279 | #ifndef LOCORE | |
280 | /* | |
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 | */ | |
287 | .ta \w'struct 'u +\w'daddr_t 'u +\w'df_startblk 'u | |
288 | struct format_op { | |
289 | char *df_buf; | |
290 | int df_count; /* value-result */ | |
291 | daddr_t df_startblk; | |
292 | int df_reg[8]; /* result */ | |
293 | }; | |
294 | ||
295 | /* | |
296 | * Structure used internally to retrieve | |
297 | * information about a partition on a disk. | |
298 | */ | |
299 | struct partinfo { | |
300 | struct disklabel *disklab; | |
301 | struct partition *part; | |
302 | }; | |
303 | ||
304 | /* | |
305 | * Disk-specific ioctls. | |
306 | */ | |
307 | /* get and set disklabel; DIOCGPART used internally */ | |
308 | .ta \w'#define 'u +\w'DIOCSRETRIES 'u +\w'_IOW( d , 103, struct disklabel) 'u | |
309 | #define DIOCGDINFO _IOR('d', 101, struct disklabel) /* get */ | |
310 | #define DIOCSDINFO _IOW('d', 102, struct disklabel) /* set */ | |
311 | #define DIOCWDINFO _IOW('d', 103, struct disklabel) /* set, update disk */ | |
312 | #define DIOCGPART _IOW('d', 104, struct partinfo) /* get partition */ | |
313 | ||
314 | /* do format operation, read or write */ | |
315 | #define DIOCRFORMAT _IOWR('d', 105, struct format_op) | |
316 | #define DIOCWFORMAT _IOWR('d', 106, struct format_op) | |
317 | ||
318 | #define DIOCSSTEP _IOW('d', 107, int) /* set step rate */ | |
319 | #define DIOCSRETRIES _IOW('d', 108, int) /* set # of retries */ | |
320 | #define DIOCWLABEL _IOW('d', 109, int) /* write en/disable label */ | |
321 | ||
322 | #define DIOCSBAD _IOW('d', 110, struct dkbad) /* set kernel dkbad */ | |
323 | ||
324 | #endif LOCORE | |
37adbef5 MK |
325 | .SH "SEE ALSO" |
326 | disktab(5), disklabel(8) |