FreeBSD/Linux Kernel Cross Reference
sys/sys/disklabel.h
1 /* $NetBSD: disklabel.h,v 1.90 2005/01/07 18:29:15 matt 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 #define DTYPE_FLASH 19 /* flash memory devices */
285
286 #ifdef DKTYPENAMES
287 static const char *const dktypenames[] = {
288 "unknown",
289 "SMD",
290 "MSCP",
291 "old DEC",
292 "SCSI",
293 "ESDI",
294 "ST506",
295 "HP-IB",
296 "HP-FL",
297 "type 9",
298 "floppy",
299 "ccd",
300 "vnd",
301 "ATAPI",
302 "RAID",
303 "ld",
304 "jfs",
305 "cgd",
306 "vinum",
307 "flash",
308 NULL
309 };
310 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
311 #endif
312
313 /*
314 * Filesystem type and version.
315 * Used to interpret other filesystem-specific
316 * per-partition information.
317 *
318 * These are used only for COMPAT_09 support.
319 */
320 #define FS_UNUSED 0 /* unused */
321 #define FS_SWAP 1 /* swap */
322 #define FS_V6 2 /* Sixth Edition */
323 #define FS_V7 3 /* Seventh Edition */
324 #define FS_SYSV 4 /* System V */
325 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
326 #define FS_V8 6 /* Eighth Edition, 4K blocks */
327 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
328 #define FS_MSDOS 8 /* MSDOS file system */
329 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
330 #define FS_OTHER 10 /* in use, but unknown/unsupported */
331 #define FS_HPFS 11 /* OS/2 high-performance file system */
332 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
333 #define FS_BOOT 13 /* partition contains bootstrap */
334 #define FS_ADOS 14 /* AmigaDOS fast file system */
335 #define FS_HFS 15 /* Macintosh HFS */
336 #define FS_FILECORE 16 /* Acorn Filecore Filing System */
337 #define FS_EX2FS 17 /* Linux Extended 2 file system */
338 #define FS_NTFS 18 /* Windows/NT file system */
339 #define FS_RAID 19 /* RAIDframe component */
340 #define FS_CCD 20 /* concatenated disk component */
341 #define FS_JFS2 21 /* IBM JFS2 */
342 #define FS_APPLEUFS 22 /* Apple UFS */
343 /* XXX this is not the same as FreeBSD. How to solve? */
344 #define FS_VINUM 23 /* Vinum */
345
346 /* Adjust the FSMAXTYPES def below if you add something after APPLEUFS */
347
348 #ifdef FSTYPENAMES
349 static const char *const fstypenames[] = {
350 "unused",
351 "swap",
352 "Version 6",
353 "Version 7",
354 "System V",
355 "4.1BSD",
356 "Eighth Edition",
357 "4.2BSD",
358 "MSDOS",
359 "4.4LFS",
360 "unknown",
361 "HPFS",
362 "ISO9660",
363 "boot",
364 "ADOS",
365 "HFS",
366 "FILECORE",
367 "Linux Ext2",
368 "NTFS",
369 "RAID",
370 "ccd",
371 "jfs",
372 "Apple UFS",
373 "vinum",
374 NULL
375 };
376 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
377 #else
378 #define FSMAXTYPES (FS_VINUM + 1)
379 #endif
380
381 #ifdef FSCKNAMES
382 /* These are the names MOUNT_XXX from <sys/mount.h> */
383 static const char *const fscknames[] = {
384 NULL, /* unused */
385 NULL, /* swap */
386 NULL, /* Version 6 */
387 NULL, /* Version 7 */
388 NULL, /* System V */
389 NULL, /* 4.1BSD */
390 NULL, /* Eighth edition */
391 "ffs", /* 4.2BSD */
392 "msdos", /* MSDOS */
393 "lfs", /* 4.4LFS */
394 NULL, /* unknown */
395 NULL, /* HPFS */
396 NULL, /* ISO9660 */
397 NULL, /* boot */
398 NULL, /* ADOS */
399 NULL, /* HFS */
400 NULL, /* FILECORE */
401 "ext2fs", /* Linux Ext2 */
402 NULL, /* Windows/NT */
403 NULL, /* RAID Component */
404 NULL, /* concatenated disk component */
405 NULL, /* IBM JFS2 */
406 "ffs", /* Apple UFS */
407 NULL /* NULL */
408 };
409 #define FSMAXNAMES (sizeof(fscknames) / sizeof(fscknames[0]) - 1)
410
411 #endif
412
413 #ifdef MOUNTNAMES
414 /* These are the names MOUNT_XXX from <sys/mount.h> */
415 static const char *const mountnames[] = {
416 NULL, /* unused */
417 NULL, /* swap */
418 NULL, /* Version 6 */
419 NULL, /* Version 7 */
420 NULL, /* System V */
421 NULL, /* 4.1BSD */
422 NULL, /* Eighth edition */
423 "ffs", /* 4.2BSD */
424 "msdos", /* MSDOS */
425 "lfs", /* 4.4LFS */
426 NULL, /* unknown */
427 NULL, /* HPFS */
428 "cd9660", /* ISO9660 */
429 NULL, /* boot */
430 "ados", /* ADOS */
431 NULL, /* HFS */
432 "filecore", /* FILECORE */
433 "ext2fs", /* Linux Ext2 */
434 "ntfs", /* Windows/NT */
435 NULL, /* RAID Component */
436 NULL, /* concatenated disk component */
437 NULL, /* IBM JFS2 */
438 "ffs", /* Apple UFS */
439 NULL /* NULL */
440 };
441 #define FSMAXMOUNTNAMES (sizeof(mountnames) / sizeof(mountnames[0]) - 1)
442
443 #endif
444
445 /*
446 * flags shared by various drives:
447 */
448 #define D_REMOVABLE 0x01 /* removable media */
449 #define D_ECC 0x02 /* supports ECC */
450 #define D_BADSECT 0x04 /* supports bad sector forw. */
451 #define D_RAMDISK 0x08 /* disk emulator */
452 #define D_CHAIN 0x10 /* can do back-back transfers */
453
454 /*
455 * Drive data for SMD.
456 */
457 #define d_smdflags d_drivedata[0]
458 #define D_SSE 0x1 /* supports skip sectoring */
459 #define d_mindist d_drivedata[1]
460 #define d_maxdist d_drivedata[2]
461 #define d_sdist d_drivedata[3]
462
463 /*
464 * Drive data for ST506.
465 */
466 #define d_precompcyl d_drivedata[0]
467 #define d_gap3 d_drivedata[1] /* used only when formatting */
468
469 /*
470 * Drive data for SCSI.
471 */
472 #define d_blind d_drivedata[0]
473
474 #ifndef _LOCORE
475 /*
476 * Structure used to perform a format or other raw operation,
477 * returning data and/or register values. Register identification
478 * and format are device- and driver-dependent. Currently unused.
479 */
480 struct format_op {
481 char *df_buf;
482 int df_count; /* value-result */
483 daddr_t df_startblk;
484 int df_reg[8]; /* result */
485 };
486
487 /*
488 * Structure used internally to retrieve information about a partition
489 * on a disk.
490 */
491 struct partinfo {
492 struct disklabel *disklab;
493 struct partition *part;
494 };
495
496 #ifdef _KERNEL
497
498 struct disk;
499
500 void diskerr(const struct buf *, const char *, const char *, int,
501 int, const struct disklabel *);
502 u_int dkcksum(struct disklabel *);
503 int setdisklabel(struct disklabel *, struct disklabel *, u_long,
504 struct cpu_disklabel *);
505 const char *readdisklabel(dev_t, void (*)(struct buf *),
506 struct disklabel *, struct cpu_disklabel *);
507 int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *,
508 struct cpu_disklabel *);
509 int bounds_check_with_label(struct disk *, struct buf *, int);
510 int bounds_check_with_mediasize(struct buf *, int, u_int64_t);
511 #endif
512 #endif /* _LOCORE */
513
514 #if !defined(_KERNEL) && !defined(_LOCORE)
515
516 #include <sys/cdefs.h>
517
518 #endif
519
520 #endif /* !_SYS_DISKLABEL_H_ */
Cache object: f682566cecbbd4c4cfbc7ba9c465500e
|