1 /* $NetBSD: disklabel.h,v 1.88 2003/11/14 12:07:42 lukem Exp $ */
4 * Copyright (c) 1987, 1988, 1993
5 * The Regents of the University of California. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
31 * @(#)disklabel.h 8.2 (Berkeley) 7/10/94
34 #ifndef _SYS_DISKLABEL_H_
35 #define _SYS_DISKLABEL_H_
40 * We need <machine/types.h> for __HAVE_OLD_DISKLABEL
42 #if 0 /* XXX ffsdrv */
44 #include <sys/types.h>
48 /* sys/arch/i386/include/type.h XXX ffsdrv */
49 #define __HAVE_OLD_DISKLABEL
52 * Each disk has a label which includes information about the hardware
53 * disk geometry, filesystem partitions, and drive specific information.
54 * The location of the label, as well as the number of partitions the
55 * label can describe and the number of the "whole disk" (raw)
56 * paritition are machine dependent.
58 #if 0 /* XXX ffsdrv */
59 #include <machine/disklabel.h>
62 /* arch/i386/include/disklabel.h */
63 #define LABELSECTOR 1 /* sector containing label */
64 #define LABELOFFSET 0 /* offset of label in sector */
65 #define MAXPARTITIONS 16 /* number of partitions */
66 #define OLDMAXPARTITIONS 8 /* number of partitions before 1.6 */
67 #define RAW_PART 3 /* raw partition: XX?d (XXX) */
70 * We use the highest bit of the minor number for the partition number.
71 * This maintains backward compatibility with device nodes created before
72 * MAXPARTITIONS was increased.
74 #define __I386_MAXDISKS ((1 << 20) / MAXPARTITIONS)
75 #define DISKUNIT(dev) ((minor(dev) / OLDMAXPARTITIONS) % __I386_MAXDISKS)
76 #define DISKPART(dev) ((minor(dev) % OLDMAXPARTITIONS) + \
77 ((minor(dev) / (__I386_MAXDISKS * OLDMAXPARTITIONS)) * OLDMAXPARTITIONS))
78 #define DISKMINOR(unit, part) \
79 (((unit) * OLDMAXPARTITIONS) + ((part) % OLDMAXPARTITIONS) + \
80 ((part) / OLDMAXPARTITIONS) * (__I386_MAXDISKS * OLDMAXPARTITIONS))
82 /* Pull in MBR partition definitions. */
83 #include "bootblock.h"
85 /* end of arch/i386/include/disklabel.h */
89 * The absolute maximum number of disk partitions allowed.
90 * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
91 * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
93 #define MAXMAXPARTITIONS 22
94 #if MAXPARTITIONS > MAXMAXPARTITIONS
95 #warning beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
99 * Ports can switch their MAXPARTITIONS once, as follows:
101 * - define OLDMAXPARTITIONS in <machine/disklabel.h> as the old number
102 * - define MAXPARTITIONS as the new number
103 * - define DISKUNIT, DISKPART and DISKMINOR macros in <machine/disklabel.h>
104 * as appropriate for the port (see the i386 one for an example).
105 * - define __HAVE_OLD_DISKLABEL in <machine/types.h>
108 #if defined(_KERNEL) && defined(__HAVE_OLD_DISKLABEL) && \
109 (MAXPARTITIONS < OLDMAXPARTITIONS)
110 #error "can only grow disklabel size"
115 * Translate between device numbers and major/disk unit/disk partition.
117 #ifndef __HAVE_OLD_DISKLABEL
118 #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
119 #define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
120 #define DISKMINOR(unit, part) \
121 (((unit) * MAXPARTITIONS) + (part))
123 #define MAKEDISKDEV(maj, unit, part) \
124 (makedev((maj), DISKMINOR((unit), (part))))
126 #define DISKMAGIC ((u_int32_t)0x82564557) /* The disk magic number */
130 u_int32_t d_magic
; /* the magic number */
131 u_int16_t d_type
; /* drive type */
132 u_int16_t d_subtype
; /* controller/d_type specific */
133 char d_typename
[16]; /* type name, e.g. "eagle" */
136 * d_packname contains the pack identifier and is returned when
137 * the disklabel is read off the disk or in-core copy.
138 * d_boot0 and d_boot1 are the (optional) names of the
139 * primary (block 0) and secondary (block 1-15) bootstraps
140 * as found in /usr/mdec. These are returned when using
141 * getdiskbyname(3) to retrieve the values from /etc/disktab.
144 char un_d_packname
[16]; /* pack identifier */
146 char *un_d_boot0
; /* primary bootstrap name */
147 char *un_d_boot1
; /* secondary bootstrap name */
150 #define d_packname d_un.un_d_packname
151 #define d_boot0 d_un.un_b.un_d_boot0
152 #define d_boot1 d_un.un_b.un_d_boot1
155 u_int32_t d_secsize
; /* # of bytes per sector */
156 u_int32_t d_nsectors
; /* # of data sectors per track */
157 u_int32_t d_ntracks
; /* # of tracks per cylinder */
158 u_int32_t d_ncylinders
; /* # of data cylinders per unit */
159 u_int32_t d_secpercyl
; /* # of data sectors per cylinder */
160 u_int32_t d_secperunit
; /* # of data sectors per unit */
163 * Spares (bad sector replacements) below are not counted in
164 * d_nsectors or d_secpercyl. Spare sectors are assumed to
165 * be physical sectors which occupy space at the end of each
166 * track and/or cylinder.
168 u_int16_t d_sparespertrack
; /* # of spare sectors per track */
169 u_int16_t d_sparespercyl
; /* # of spare sectors per cylinder */
171 * Alternative cylinders include maintenance, replacement,
172 * configuration description areas, etc.
174 u_int32_t d_acylinders
; /* # of alt. cylinders per unit */
176 /* hardware characteristics: */
178 * d_interleave, d_trackskew and d_cylskew describe perturbations
179 * in the media format used to compensate for a slow controller.
180 * Interleave is physical sector interleave, set up by the
181 * formatter or controller when formatting. When interleaving is
182 * in use, logically adjacent sectors are not physically
183 * contiguous, but instead are separated by some number of
184 * sectors. It is specified as the ratio of physical sectors
185 * traversed per logical sector. Thus an interleave of 1:1
186 * implies contiguous layout, while 2:1 implies that logical
187 * sector 0 is separated by one sector from logical sector 1.
188 * d_trackskew is the offset of sector 0 on track N relative to
189 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew
190 * is the offset of sector 0 on cylinder N relative to sector 0
193 u_int16_t d_rpm
; /* rotational speed */
194 u_int16_t d_interleave
; /* hardware sector interleave */
195 u_int16_t d_trackskew
; /* sector 0 skew, per track */
196 u_int16_t d_cylskew
; /* sector 0 skew, per cylinder */
197 u_int32_t d_headswitch
; /* head switch time, usec */
198 u_int32_t d_trkseek
; /* track-to-track seek, usec */
199 u_int32_t d_flags
; /* generic flags */
201 u_int32_t d_drivedata
[NDDATA
]; /* drive-type specific information */
203 u_int32_t d_spare
[NSPARE
]; /* reserved for future use */
204 u_int32_t d_magic2
; /* the magic number (again) */
205 u_int16_t d_checksum
; /* xor of data incl. partitions */
207 /* filesystem and partition information: */
208 u_int16_t d_npartitions
; /* number of partitions in following */
209 u_int32_t d_bbsize
; /* size of boot area at sn0, bytes */
210 u_int32_t d_sbsize
; /* max size of fs superblock, bytes */
211 struct partition
{ /* the partition table */
212 u_int32_t p_size
; /* number of sectors in partition */
213 u_int32_t p_offset
; /* starting sector */
215 u_int32_t fsize
; /* FFS, ADOS:
216 filesystem basic fragment size */
217 u_int32_t cdsession
; /* ISO9660: session offset */
219 #define p_fsize __partition_u2.fsize
220 #define p_cdsession __partition_u2.cdsession
221 u_int8_t p_fstype
; /* filesystem type, see below */
222 u_int8_t p_frag
; /* filesystem fragments per block */
224 u_int16_t cpg
; /* UFS: FS cylinders per group */
225 u_int16_t sgs
; /* LFS: FS segment shift */
227 #define p_cpg __partition_u1.cpg
228 #define p_sgs __partition_u1.sgs
229 } d_partitions
[MAXPARTITIONS
]; /* actually may be more */
232 #ifdef __HAVE_OLD_DISKLABEL
234 * Same as above, but with OLDMAXPARTITIONS partitions. For use in
235 * the old DIOC* ioctl calls.
237 struct olddisklabel
{
243 char un_d_packname
[16];
250 u_int32_t d_nsectors
;
252 u_int32_t d_ncylinders
;
253 u_int32_t d_secpercyl
;
254 u_int32_t d_secperunit
;
255 u_int16_t d_sparespertrack
;
256 u_int16_t d_sparespercyl
;
257 u_int32_t d_acylinders
;
259 u_int16_t d_interleave
;
260 u_int16_t d_trackskew
;
262 u_int32_t d_headswitch
;
265 u_int32_t d_drivedata
[NDDATA
];
266 u_int32_t d_spare
[NSPARE
];
268 u_int16_t d_checksum
;
269 u_int16_t d_npartitions
;
285 } d_partitions
[OLDMAXPARTITIONS
];
287 #endif /* __HAVE_OLD_DISKLABEL */
290 * offsets for asm boot files.
298 .set d_end_
,276 /* size of disk label */
302 #define DTYPE_SMD 1 /* SMD, XSMD; VAX hp/up */
303 #define DTYPE_MSCP 2 /* MSCP */
304 #define DTYPE_DEC 3 /* other DEC (rk, rl) */
305 #define DTYPE_SCSI 4 /* SCSI */
306 #define DTYPE_ESDI 5 /* ESDI interface */
307 #define DTYPE_ST506 6 /* ST506 etc. */
308 #define DTYPE_HPIB 7 /* CS/80 on HP-IB */
309 #define DTYPE_HPFL 8 /* HP Fiber-link */
310 #define DTYPE_FLOPPY 10 /* floppy */
311 #define DTYPE_CCD 11 /* concatenated disk device */
312 #define DTYPE_VND 12 /* vnode pseudo-disk */
313 #define DTYPE_ATAPI 13 /* ATAPI */
314 #define DTYPE_RAID 14 /* RAIDframe */
315 #define DTYPE_LD 15 /* logical disk */
316 #define DTYPE_JFS2 16 /* IBM JFS2 */
317 #define DTYPE_CGD 17 /* cryptographic pseudo-disk */
318 #define DTYPE_VINUM 18 /* vinum volume */
321 static const char *const dktypenames
[] = {
343 #define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
347 * Filesystem type and version.
348 * Used to interpret other filesystem-specific
349 * per-partition information.
351 * These are used only for COMPAT_09 support.
353 #define FS_UNUSED 0 /* unused */
354 #define FS_SWAP 1 /* swap */
355 #define FS_V6 2 /* Sixth Edition */
356 #define FS_V7 3 /* Seventh Edition */
357 #define FS_SYSV 4 /* System V */
358 #define FS_V71K 5 /* V7 with 1K blocks (4.1, 2.9) */
359 #define FS_V8 6 /* Eighth Edition, 4K blocks */
360 #define FS_BSDFFS 7 /* 4.2BSD fast file system */
361 #define FS_MSDOS 8 /* MSDOS file system */
362 #define FS_BSDLFS 9 /* 4.4BSD log-structured file system */
363 #define FS_OTHER 10 /* in use, but unknown/unsupported */
364 #define FS_HPFS 11 /* OS/2 high-performance file system */
365 #define FS_ISO9660 12 /* ISO 9660, normally CD-ROM */
366 #define FS_BOOT 13 /* partition contains bootstrap */
367 #define FS_ADOS 14 /* AmigaDOS fast file system */
368 #define FS_HFS 15 /* Macintosh HFS */
369 #define FS_FILECORE 16 /* Acorn Filecore Filing System */
370 #define FS_EX2FS 17 /* Linux Extended 2 file system */
371 #define FS_NTFS 18 /* Windows/NT file system */
372 #define FS_RAID 19 /* RAIDframe component */
373 #define FS_CCD 20 /* concatenated disk component */
374 #define FS_JFS2 21 /* IBM JFS2 */
375 #define FS_APPLEUFS 22 /* Apple UFS */
376 /* XXX this is not the same as FreeBSD. How to solve? */
377 #define FS_VINUM 23 /* Vinum */
379 /* Adjust the FSMAXTYPES def below if you add something after APPLEUFS */
382 static const char *const fstypenames
[] = {
409 #define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
411 #define FSMAXTYPES (FS_VINUM + 1)
415 /* These are the names MOUNT_XXX from <sys/mount.h> */
416 static const char *const fscknames
[] = {
419 NULL
, /* Version 6 */
420 NULL
, /* Version 7 */
423 NULL
, /* Eighth edition */
434 "ext2fs", /* Linux Ext2 */
435 NULL
, /* Windows/NT */
436 NULL
, /* RAID Component */
437 NULL
, /* concatenated disk component */
439 "ffs", /* Apple UFS */
442 #define FSMAXNAMES (sizeof(fscknames) / sizeof(fscknames[0]) - 1)
447 /* These are the names MOUNT_XXX from <sys/mount.h> */
448 static const char *const mountnames
[] = {
451 NULL
, /* Version 6 */
452 NULL
, /* Version 7 */
455 NULL
, /* Eighth edition */
461 "cd9660", /* ISO9660 */
465 "filecore", /* FILECORE */
466 "ext2fs", /* Linux Ext2 */
467 "ntfs", /* Windows/NT */
468 NULL
, /* RAID Component */
469 NULL
, /* concatenated disk component */
471 "ffs", /* Apple UFS */
474 #define FSMAXMOUNTNAMES (sizeof(mountnames) / sizeof(mountnames[0]) - 1)
479 * flags shared by various drives:
481 #define D_REMOVABLE 0x01 /* removable media */
482 #define D_ECC 0x02 /* supports ECC */
483 #define D_BADSECT 0x04 /* supports bad sector forw. */
484 #define D_RAMDISK 0x08 /* disk emulator */
485 #define D_CHAIN 0x10 /* can do back-back transfers */
488 * Drive data for SMD.
490 #define d_smdflags d_drivedata[0]
491 #define D_SSE 0x1 /* supports skip sectoring */
492 #define d_mindist d_drivedata[1]
493 #define d_maxdist d_drivedata[2]
494 #define d_sdist d_drivedata[3]
497 * Drive data for ST506.
499 #define d_precompcyl d_drivedata[0]
500 #define d_gap3 d_drivedata[1] /* used only when formatting */
503 * Drive data for SCSI.
505 #define d_blind d_drivedata[0]
509 * Structure used to perform a format or other raw operation,
510 * returning data and/or register values. Register identification
511 * and format are device- and driver-dependent. Currently unused.
515 int df_count
; /* value-result */
517 int df_reg
[8]; /* result */
521 * Structure used internally to retrieve information about a partition
525 struct disklabel
*disklab
;
526 struct partition
*part
;
533 void diskerr
__P((const struct buf
*, const char *, const char *, int,
534 int, const struct disklabel
*));
535 u_int dkcksum
__P((struct disklabel
*));
536 int setdisklabel
__P((struct disklabel
*, struct disklabel
*, u_long
,
537 struct cpu_disklabel
*));
538 const char *readdisklabel
__P((dev_t
, void (*)(struct buf
*),
539 struct disklabel
*, struct cpu_disklabel
*));
540 int writedisklabel
__P((dev_t
, void (*)(struct buf
*), struct disklabel
*,
541 struct cpu_disklabel
*));
542 int bounds_check_with_label
__P((struct disk
*, struct buf
*, int));
543 int bounds_check_with_mediasize
__P((struct buf
*, int, u_int64_t
));
547 #if !defined(_KERNEL) && !defined(_LOCORE)
549 #if 0 /* XXX ffsdrv */
550 #include <sys/cdefs.h>
555 #endif /* !_SYS_DISKLABEL_H_ */