FreeBSD/Linux Kernel Cross Reference
sys/sys/disklabel.h
1 /* $NetBSD: disklabel.h,v 1.88 2003/11/14 12:07:42 lukem Exp $ */
2
3 /*
4 * Copyright (c) 1987, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
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. Neither the name of the University nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
32 */
33
34 #ifndef _SYS_DISKLABEL_H_
35 #define _SYS_DISKLABEL_H_
36
37 /*
38 * We need <machine/types.h> for __HAVE_OLD_DISKLABEL
39 */
40 #ifndef _LOCORE
41 #include <sys/types.h>
42 #endif
43
44 /*
45 * Each disk has a label which includes information about the hardware
46 * disk geometry, filesystem partitions, and drive specific information.
47 * The location of the label, as well as the number of partitions the
48 * label can describe and the number of the "whole disk" (raw)
49 * paritition are machine dependent.
50 */
51 #include <machine/disklabel.h>
52
53 /*
54 * The absolute maximum number of disk partitions allowed.
55 * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
56 * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
57 */
58 #define MAXMAXPARTITIONS 22
59 #if MAXPARTITIONS > MAXMAXPARTITIONS
60 #warning beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
61 #endif
62
63 /*
64 * Ports can switch their MAXPARTITIONS once, as follows:
65 *
66 * - define OLDMAXPARTITIONS in <machine/disklabel.h> as the old number
67 * - define MAXPARTITIONS as the new number
68 * - define DISKUNIT, DISKPART and DISKMINOR macros in <machine/disklabel.h>
69 * as appropriate for the port (see the i386 one for an example).
70 * - define __HAVE_OLD_DISKLABEL in <machine/types.h>
71 */
72
73 #if defined(_KERNEL) && defined(__HAVE_OLD_DISKLABEL) && \
74 (MAXPARTITIONS < OLDMAXPARTITIONS)
75 #error "can only grow disklabel size"
76 #endif
77
78
79 /*
80 * Translate between device numbers and major/disk unit/disk partition.
81 */
82 #ifndef __HAVE_OLD_DISKLABEL
83 #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
84 #define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
85 #define DISKMINOR(unit, part) \
86 (((unit) * MAXPARTITIONS) + (part))
87 #endif
88 #define MAKEDISKDEV(maj, unit, part) \
89 (makedev((maj), DISKMINOR((unit), (part))))
90
91 #define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */
92
93 #ifndef _LOCORE
94 struct disklabel {
95 u_int32_t d_magic; /* the magic number */
96 u_int16_t d_type; /* drive type */
97 u_int16_t d_subtype; /* controller/d_type specific */
98 char d_typename[16]; /* type name, e.g. "eagle" */
99
100 /*
101 * d_packname contains the pack identifier and is returned when
102 * the disklabel is read off the disk or in-core copy.
103 * d_boot0 and d_boot1 are the (optional) names of the
104 * primary (block 0) and secondary (block 1-15) bootstraps
105 * as found in /usr/mdec. These are returned when using
106 * getdiskbyname(3) to retrieve the values from /etc/disktab.
107 */
108 union {
109 char un_d_packname[16]; /* pack identifier */
110 struct {
111 char *un_d_boot0; /* primary bootstrap name */
112 char *un_d_boot1; /* secondary bootstrap name */
113 } un_b;
114 } d_un;
115 #define d_packname d_un.un_d_packname
116 #define d_boot0 d_un.un_b.un_d_boot0
117 #define d_boot1 d_un.un_b.un_d_boot1
118
119 /* disk geometry: */
120 u_int32_t d_secsize; /* # of bytes per sector */
121 u_int32_t d_nsectors; /* # of data sectors per track */
122 u_int32_t d_ntracks; /* # of tracks per cylinder */
123 u_int32_t d_ncylinders; /* # of data cylinders per unit */
124 u_int32_t d_secpercyl; /* # of data sectors per cylinder */
125 u_int32_t d_secperunit; /* # of data sectors per unit */
126
127 /*
128 * Spares (bad sector replacements) below are not counted in
129 * d_nsectors or d_secpercyl. Spare sectors are assumed to
130 * be physical sectors which occupy space at the end of each
131 * track and/or cylinder.
132 */
133 u_int16_t d_sparespertrack; /* # of spare sectors per track */
134 u_int16_t d_sparespercyl; /* # of spare sectors per cylinder */
135 /*
136 * Alternative cylinders include maintenance, replacement,
137 * configuration description areas, etc.
138 */
139 u_int32_t d_acylinders; /* # of alt. cylinders per unit */
140
141 /* hardware characteristics: */
142 /*
143 * d_interleave, d_trackskew and d_cylskew describe perturbations
144 * in the media format used to compensate for a slow controller.
145 * Interleave is physical sector interleave, set up by the
146 * formatter or controller when formatting. When interleaving is
147 * in use, logically adjacent sectors are not physically
148 * contiguous, but instead are separated by some number of
149 * sectors. It is specified as the ratio of physical sectors
150 * traversed per logical sector. Thus an interleave of 1:1
151 * implies contiguous layout, while 2:1 implies that logical
152 * sector 0 is separated by one sector from logical sector 1.
153 * d_trackskew is the offset of sector 0 on track N relative to
154 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew
155 * is the offset of sector 0 on cylinder N relative to sector 0
156 * on cylinder N-1.
157 */
158 u_int16_t d_rpm; /* rotational speed */
159 u_int16_t d_interleave; /* hardware sector interleave */
160 u_int16_t d_trackskew; /* sector 0 skew, per track */
161 u_int16_t d_cylskew; /* sector 0 skew, per cylinder */
162 u_int32_t d_headswitch; /* head switch time, usec */
163 u_int32_t d_trkseek; /* track-to-track seek, usec */
164 u_int32_t d_flags; /* generic flags */
165 #define NDDATA 5
166 u_int32_t d_drivedata[NDDATA]; /* drive-type specific information */
167 #define NSPARE 5
168 u_int32_t d_spare[NSPARE]; /* reserved for future use */
169 u_int32_t d_magic2; /* the magic number (again) */
170 u_int16_t d_checksum; /* xor of data incl. partitions */
171
172 /* filesystem and partition information: */
173 u_int16_t d_npartitions; /* number of partitions in following */
174 u_int32_t d_bbsize; /* size of boot area at sn0, bytes */
175 u_int32_t d_sbsize; /* max size of fs superblock, bytes */
176 struct partition { /* the partition table */
177 u_int32_t p_size; /* number of sectors in partition */
178 u_int32_t p_offset; /* starting sector */
179 union {
180 u_int32_t fsize; /* FFS, ADOS:
181 filesystem basic fragment size */
182 u_int32_t cdsession; /* ISO9660: session offset */
183 } __partition_u2;
184 #define p_fsize __partition_u2.fsize
185 #define p_cdsession __partition_u2.cdsession
186 u_int8_t p_fstype; /* filesystem type, see below */
187 u_int8_t p_frag; /* filesystem fragments per block */
188 union {
189 u_int16_t cpg; /* UFS: FS cylinders per group */
190 u_int16_t sgs; /* LFS: FS segment shift */
191 } __partition_u1;
192 #define p_cpg __partition_u1.cpg
193 #define p_sgs __partition_u1.sgs
194 } d_partitions[MAXPARTITIONS]; /* actually may be more */
195 };
196
197 #ifdef __HAVE_OLD_DISKLABEL
198 /*
199 * Same as above, but with OLDMAXPARTITIONS partitions. For use in
200 * the old DIOC* ioctl calls.
201 */
202 struct olddisklabel {
203 u_int32_t d_magic;
204 u_int16_t d_type;
205 u_int16_t d_subtype;
206 char d_typename[16];
207 union {
208 char un_d_packname[16];
209 struct {
210 char *un_d_boot0;
211 char *un_d_boot1;
212 } un_b;
213 } d_un;
214 u_int32_t d_secsize;
215 u_int32_t d_nsectors;
216 u_int32_t d_ntracks;
217 u_int32_t d_ncylinders;
218 u_int32_t d_secpercyl;
219 u_int32_t d_secperunit;
220 u_int16_t d_sparespertrack;
221 u_int16_t d_sparespercyl;
222 u_int32_t d_acylinders;
223 u_int16_t d_rpm;
224 u_int16_t d_interleave;
225 u_int16_t d_trackskew;
226 u_int16_t d_cylskew;
227 u_int32_t d_headswitch;
228 u_int32_t d_trkseek;
229 u_int32_t d_flags;
230 u_int32_t d_drivedata[NDDATA];
231 u_int32_t d_spare[NSPARE];
232 u_int32_t d_magic2;
233 u_int16_t d_checksum;
234 u_int16_t d_npartitions;
235 u_int32_t d_bbsize;
236 u_int32_t d_sbsize;
237 struct opartition {
238 u_int32_t p_size;
239 u_int32_t p_offset;
240 union {
241 u_int32_t fsize;
242 u_int32_t cdsession;
243 } __partition_u2;
244 u_int8_t p_fstype;
245 u_int8_t p_frag;
246 union {
247 u_int16_t cpg;
248 u_int16_t sgs;
249 } __partition_u1;
250 } d_partitions[OLDMAXPARTITIONS];
251 };
252 #endif /* __HAVE_OLD_DISKLABEL */
253 #else /* _LOCORE */
254 /*
255 * offsets for asm boot files.
256 */
257 .set d_secsize,40
258 .set d_nsectors,44
259 .set d_ntracks,48
260 .set d_ncylinders,52
261 .set d_secpercyl,56
262 .set d_secperunit,60
263 .set d_end_,276 /* size of disk label */
264 #endif /* _LOCORE */
265
266 /* d_type values: */
267 #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
268 #define DTYPE_MSCP 2 /* MSCP */
269 #define DTYPE_DEC 3 /* other DEC (rk, rl) */
270 #define DTYPE_SCSI 4 /* SCSI */
271 #define DTYPE_ESDI 5 /* ESDI interface */
272 #define DTYPE_ST506 6 /* ST506 etc. */
273 #define DTYPE_HPIB 7 /* CS/80 on HP-IB */
274 #define DTYPE_HPFL 8 /* HP Fiber-link */
275 #define DTYPE_FLOPPY 10 /* floppy */
276 #define DTYPE_CCD 11 /* concatenated disk device */
277 #define DTYPE_VND 12 /* vnode pseudo-disk */
278 #define DTYPE_ATAPI 13 /* ATAPI */
279 #define DTYPE_RAID 14 /* RAIDframe */
280 #define DTYPE_LD 15 /* logical disk */
281 #define DTYPE_JFS2 16 /* IBM JFS2 */
282 #define DTYPE_CGD 17 /* cryptographic pseudo-disk */
283 #define DTYPE_VINUM 18 /* vinum volume */
284
285 #ifdef DKTYPENAMES
286 static const char *const dktypenames[] = {
287 "unknown",
288 "SMD",
289 "MSCP",
290 "old DEC",
291 "SCSI",
292 "ESDI",
293 "ST506",
294 "HP-IB",
295 "HP-FL",
296 "type 9",
297 "floppy",
298 "ccd",
299 "vnd",
300 "ATAPI",
301 "RAID",
302 "ld",
303 "jfs",
304 "cgd",
305 "vinum",
306 NULL
307 };
308 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
309 #endif
310
311 /*
312 * Filesystem type and version.
313 * Used to interpret other filesystem-specific
314 * per-partition information.
315 *
316 * These are used only for COMPAT_09 support.
317 */
318 #define FS_UNUSED 0 /* unused */
319 #define FS_SWAP 1 /* swap */
320 #define FS_V6 2 /* Sixth Edition */
321 #define FS_V7 3 /* Seventh Edition */
322 #define FS_SYSV 4 /* System V */
323 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
324 #define FS_V8 6 /* Eighth Edition, 4K blocks */
325 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
326 #define FS_MSDOS 8 /* MSDOS file system */
327 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
328 #define FS_OTHER 10 /* in use, but unknown/unsupported */
329 #define FS_HPFS 11 /* OS/2 high-performance file system */
330 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
331 #define FS_BOOT 13 /* partition contains bootstrap */
332 #define FS_ADOS 14 /* AmigaDOS fast file system */
333 #define FS_HFS 15 /* Macintosh HFS */
334 #define FS_FILECORE 16 /* Acorn Filecore Filing System */
335 #define FS_EX2FS 17 /* Linux Extended 2 file system */
336 #define FS_NTFS 18 /* Windows/NT file system */
337 #define FS_RAID 19 /* RAIDframe component */
338 #define FS_CCD 20 /* concatenated disk component */
339 #define FS_JFS2 21 /* IBM JFS2 */
340 #define FS_APPLEUFS 22 /* Apple UFS */
341 /* XXX this is not the same as FreeBSD. How to solve? */
342 #define FS_VINUM 23 /* Vinum */
343
344 /* Adjust the FSMAXTYPES def below if you add something after APPLEUFS */
345
346 #ifdef FSTYPENAMES
347 static const char *const fstypenames[] = {
348 "unused",
349 "swap",
350 "Version 6",
351 "Version 7",
352 "System V",
353 "4.1BSD",
354 "Eighth Edition",
355 "4.2BSD",
356 "MSDOS",
357 "4.4LFS",
358 "unknown",
359 "HPFS",
360 "ISO9660",
361 "boot",
362 "ADOS",
363 "HFS",
364 "FILECORE",
365 "Linux Ext2",
366 "NTFS",
367 "RAID",
368 "ccd",
369 "jfs",
370 "Apple UFS",
371 "vinum",
372 NULL
373 };
374 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
375 #else
376 #define FSMAXTYPES (FS_VINUM + 1)
377 #endif
378
379 #ifdef FSCKNAMES
380 /* These are the names MOUNT_XXX from <sys/mount.h> */
381 static const char *const fscknames[] = {
382 NULL, /* unused */
383 NULL, /* swap */
384 NULL, /* Version 6 */
385 NULL, /* Version 7 */
386 NULL, /* System V */
387 NULL, /* 4.1BSD */
388 NULL, /* Eighth edition */
389 "ffs", /* 4.2BSD */
390 "msdos", /* MSDOS */
391 "lfs", /* 4.4LFS */
392 NULL, /* unknown */
393 NULL, /* HPFS */
394 NULL, /* ISO9660 */
395 NULL, /* boot */
396 NULL, /* ADOS */
397 NULL, /* HFS */
398 NULL, /* FILECORE */
399 "ext2fs", /* Linux Ext2 */
400 NULL, /* Windows/NT */
401 NULL, /* RAID Component */
402 NULL, /* concatenated disk component */
403 NULL, /* IBM JFS2 */
404 "ffs", /* Apple UFS */
405 NULL /* NULL */
406 };
407 #define FSMAXNAMES (sizeof(fscknames) / sizeof(fscknames[0]) - 1)
408
409 #endif
410
411 #ifdef MOUNTNAMES
412 /* These are the names MOUNT_XXX from <sys/mount.h> */
413 static const char *const mountnames[] = {
414 NULL, /* unused */
415 NULL, /* swap */
416 NULL, /* Version 6 */
417 NULL, /* Version 7 */
418 NULL, /* System V */
419 NULL, /* 4.1BSD */
420 NULL, /* Eighth edition */
421 "ffs", /* 4.2BSD */
422 "msdos", /* MSDOS */
423 "lfs", /* 4.4LFS */
424 NULL, /* unknown */
425 NULL, /* HPFS */
426 "cd9660", /* ISO9660 */
427 NULL, /* boot */
428 "ados", /* ADOS */
429 NULL, /* HFS */
430 "filecore", /* FILECORE */
431 "ext2fs", /* Linux Ext2 */
432 "ntfs", /* Windows/NT */
433 NULL, /* RAID Component */
434 NULL, /* concatenated disk component */
435 NULL, /* IBM JFS2 */
436 "ffs", /* Apple UFS */
437 NULL /* NULL */
438 };
439 #define FSMAXMOUNTNAMES (sizeof(mountnames) / sizeof(mountnames[0]) - 1)
440
441 #endif
442
443 /*
444 * flags shared by various drives:
445 */
446 #define D_REMOVABLE 0x01 /* removable media */
447 #define D_ECC 0x02 /* supports ECC */
448 #define D_BADSECT 0x04 /* supports bad sector forw. */
449 #define D_RAMDISK 0x08 /* disk emulator */
450 #define D_CHAIN 0x10 /* can do back-back transfers */
451
452 /*
453 * Drive data for SMD.
454 */
455 #define d_smdflags d_drivedata[0]
456 #define D_SSE 0x1 /* supports skip sectoring */
457 #define d_mindist d_drivedata[1]
458 #define d_maxdist d_drivedata[2]
459 #define d_sdist d_drivedata[3]
460
461 /*
462 * Drive data for ST506.
463 */
464 #define d_precompcyl d_drivedata[0]
465 #define d_gap3 d_drivedata[1] /* used only when formatting */
466
467 /*
468 * Drive data for SCSI.
469 */
470 #define d_blind d_drivedata[0]
471
472 #ifndef _LOCORE
473 /*
474 * Structure used to perform a format or other raw operation,
475 * returning data and/or register values. Register identification
476 * and format are device- and driver-dependent. Currently unused.
477 */
478 struct format_op {
479 char *df_buf;
480 int df_count; /* value-result */
481 daddr_t df_startblk;
482 int df_reg[8]; /* result */
483 };
484
485 /*
486 * Structure used internally to retrieve information about a partition
487 * on a disk.
488 */
489 struct partinfo {
490 struct disklabel *disklab;
491 struct partition *part;
492 };
493
494 #ifdef _KERNEL
495
496 struct disk;
497
498 void diskerr __P((const struct buf *, const char *, const char *, int,
499 int, const struct disklabel *));
500 u_int dkcksum __P((struct disklabel *));
501 int setdisklabel __P((struct disklabel *, struct disklabel *, u_long,
502 struct cpu_disklabel *));
503 const char *readdisklabel __P((dev_t, void (*)(struct buf *),
504 struct disklabel *, struct cpu_disklabel *));
505 int writedisklabel __P((dev_t, void (*)(struct buf *), struct disklabel *,
506 struct cpu_disklabel *));
507 int bounds_check_with_label __P((struct disk *, struct buf *, int));
508 int bounds_check_with_mediasize __P((struct buf *, int, u_int64_t));
509 #endif
510 #endif /* _LOCORE */
511
512 #if !defined(_KERNEL) && !defined(_LOCORE)
513
514 #include <sys/cdefs.h>
515
516 #endif
517
518 #endif /* !_SYS_DISKLABEL_H_ */
Cache object: 85f4b3a8b13ce2364698c3856782c1cf
|