1 /* $NetBSD: disklabel.h,v 1.111 2011/11/13 22:19:09 christos 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_
38 * We need <machine/types.h> for __HAVE_OLD_DISKLABEL
41 #include <sys/types.h>
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.
51 #if HAVE_NBTOOL_CONFIG_H
52 #include <nbinclude/machine/disklabel.h>
54 #include <machine/disklabel.h>
55 #endif /* HAVE_NBTOOL_CONFIG_H */
58 * The absolute maximum number of disk partitions allowed.
59 * This is the maximum value of MAXPARTITIONS for which 'struct disklabel'
60 * is <= DEV_BSIZE bytes long. If MAXPARTITIONS is greater than this, beware.
62 #define MAXMAXPARTITIONS 22
63 #if MAXPARTITIONS > MAXMAXPARTITIONS
64 #warning beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
68 * Ports can switch their MAXPARTITIONS once, as follows:
70 * - define OLDMAXPARTITIONS in <machine/disklabel.h> as the old number
71 * - define MAXPARTITIONS as the new number
72 * - define DISKUNIT, DISKPART and DISKMINOR macros in <machine/disklabel.h>
73 * as appropriate for the port (see the i386 one for an example).
74 * - define __HAVE_OLD_DISKLABEL in <machine/types.h>
77 #if defined(_KERNEL) && defined(__HAVE_OLD_DISKLABEL) && \
78 (MAXPARTITIONS < OLDMAXPARTITIONS)
79 #error "can only grow disklabel size"
84 * Translate between device numbers and major/disk unit/disk partition.
86 #ifndef __HAVE_OLD_DISKLABEL
87 #if !HAVE_NBTOOL_CONFIG_H
88 #define DISKUNIT(dev) (minor(dev) / MAXPARTITIONS)
89 #define DISKPART(dev) (minor(dev) % MAXPARTITIONS)
90 #define DISKMINOR(unit, part) \
91 (((unit) * MAXPARTITIONS) + (part))
92 #endif /* !HAVE_NBTOOL_CONFIG_H */
94 #define MAKEDISKDEV(maj, unit, part) \
95 (makedev((maj), DISKMINOR((unit), (part))))
97 #define DISKMAGIC ((uint32_t)0x82564557) /* The disk magic number */
101 uint32_t d_magic
; /* the magic number */
102 uint16_t d_type
; /* drive type */
103 uint16_t d_subtype
; /* controller/d_type specific */
104 char d_typename
[16]; /* type name, e.g. "eagle" */
107 * d_packname contains the pack identifier and is returned when
108 * the disklabel is read off the disk or in-core copy.
109 * d_boot0 and d_boot1 are the (optional) names of the
110 * primary (block 0) and secondary (block 1-15) bootstraps
111 * as found in /usr/mdec. These are returned when using
112 * getdiskbyname(3) to retrieve the values from /etc/disktab.
115 char un_d_packname
[16]; /* pack identifier */
117 char *un_d_boot0
; /* primary bootstrap name */
118 char *un_d_boot1
; /* secondary bootstrap name */
120 uint64_t un_d_pad
; /* force 8 byte alignment */
122 #define d_packname d_un.un_d_packname
123 #define d_boot0 d_un.un_b.un_d_boot0
124 #define d_boot1 d_un.un_b.un_d_boot1
127 uint32_t d_secsize
; /* # of bytes per sector */
128 uint32_t d_nsectors
; /* # of data sectors per track */
129 uint32_t d_ntracks
; /* # of tracks per cylinder */
130 uint32_t d_ncylinders
; /* # of data cylinders per unit */
131 uint32_t d_secpercyl
; /* # of data sectors per cylinder */
132 uint32_t d_secperunit
; /* # of data sectors per unit */
135 * Spares (bad sector replacements) below are not counted in
136 * d_nsectors or d_secpercyl. Spare sectors are assumed to
137 * be physical sectors which occupy space at the end of each
138 * track and/or cylinder.
140 uint16_t d_sparespertrack
; /* # of spare sectors per track */
141 uint16_t d_sparespercyl
; /* # of spare sectors per cylinder */
143 * Alternative cylinders include maintenance, replacement,
144 * configuration description areas, etc.
146 uint32_t d_acylinders
; /* # of alt. cylinders per unit */
148 /* hardware characteristics: */
150 * d_interleave, d_trackskew and d_cylskew describe perturbations
151 * in the media format used to compensate for a slow controller.
152 * Interleave is physical sector interleave, set up by the
153 * formatter or controller when formatting. When interleaving is
154 * in use, logically adjacent sectors are not physically
155 * contiguous, but instead are separated by some number of
156 * sectors. It is specified as the ratio of physical sectors
157 * traversed per logical sector. Thus an interleave of 1:1
158 * implies contiguous layout, while 2:1 implies that logical
159 * sector 0 is separated by one sector from logical sector 1.
160 * d_trackskew is the offset of sector 0 on track N relative to
161 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew
162 * is the offset of sector 0 on cylinder N relative to sector 0
165 uint16_t d_rpm
; /* rotational speed */
166 uint16_t d_interleave
; /* hardware sector interleave */
167 uint16_t d_trackskew
; /* sector 0 skew, per track */
168 uint16_t d_cylskew
; /* sector 0 skew, per cylinder */
169 uint32_t d_headswitch
; /* head switch time, usec */
170 uint32_t d_trkseek
; /* track-to-track seek, usec */
171 uint32_t d_flags
; /* generic flags */
173 uint32_t d_drivedata
[NDDATA
]; /* drive-type specific information */
175 uint32_t d_spare
[NSPARE
]; /* reserved for future use */
176 uint32_t d_magic2
; /* the magic number (again) */
177 uint16_t d_checksum
; /* xor of data incl. partitions */
179 /* filesystem and partition information: */
180 uint16_t d_npartitions
; /* number of partitions in following */
181 uint32_t d_bbsize
; /* size of boot area at sn0, bytes */
182 uint32_t d_sbsize
; /* max size of fs superblock, bytes */
184 struct partition
{ /* the partition table */
185 uint32_t p_size
; /* number of sectors in partition */
186 uint32_t p_offset
; /* starting sector */
188 uint32_t fsize
; /* FFS, ADOS:
189 filesystem basic fragment size */
190 uint32_t cdsession
; /* ISO9660: session offset */
192 #define p_fsize __partition_u2.fsize
193 #define p_cdsession __partition_u2.cdsession
194 uint8_t p_fstype
; /* filesystem type, see below */
195 uint8_t p_frag
; /* filesystem fragments per block */
197 uint16_t cpg
; /* UFS: FS cylinders per group */
198 uint16_t sgs
; /* LFS: FS segment shift */
200 #define p_cpg __partition_u1.cpg
201 #define p_sgs __partition_u1.sgs
202 } d_partitions
[MAXPARTITIONS
]; /* actually may be more */
206 #if defined(__HAVE_OLD_DISKLABEL) && !HAVE_NBTOOL_CONFIG_H
208 * Same as above, but with OLDMAXPARTITIONS partitions. For use in
209 * the old DIOC* ioctl calls.
211 struct olddisklabel
{
217 char un_d_packname
[16];
226 uint32_t d_ncylinders
;
227 uint32_t d_secpercyl
;
228 uint32_t d_secperunit
;
229 uint16_t d_sparespertrack
;
230 uint16_t d_sparespercyl
;
231 uint32_t d_acylinders
;
233 uint16_t d_interleave
;
234 uint16_t d_trackskew
;
236 uint32_t d_headswitch
;
239 uint32_t d_drivedata
[NDDATA
];
240 uint32_t d_spare
[NSPARE
];
243 uint16_t d_npartitions
;
259 } d_partitions
[OLDMAXPARTITIONS
];
261 #endif /* __HAVE_OLD_DISKLABEL */
264 * offsets for asm boot files.
272 .set d_end_
,276 /* size of disk label */
276 * We normally use C99 initialisers (just in case the lists below are out
277 * of sequence, or have gaps), but lint doesn't grok them.
278 * Maybe some host compilers don't either, but many have for quite some time.
282 #define ARRAY_INIT(element,value) [element]=value
284 #define ARRAY_INIT(element,value) value
287 /* Use pre-processor magic to get all the parameters one one line... */
290 #define DKTYPE_DEFN(x) \
291 x(UNKNOWN, 0, "unknown") \
292 x(SMD, 1, "SMD") /* SMD, XSMD; VAX hp/up */ \
293 x(MSCP, 2, "MSCP") /* MSCP */ \
294 x(DEC, 3, "old DEC") /* other DEC (rk, rl) */ \
295 x(SCSI, 4, "SCSI") /* SCSI */ \
296 x(ESDI, 5, "ESDI") /* ESDI interface */ \
297 x(ST506, 6, "ST506") /* ST506 etc. */ \
298 x(HPIB, 7, "HP-IB") /* CS/80 on HP-IB */ \
299 x(HPFL, 8, "HP-FL") /* HP Fiber-link */ \
300 x(TYPE_9, 9, "type 9") \
301 x(FLOPPY, 10, "floppy") /* floppy */ \
302 x(CCD, 11, "ccd") /* concatenated disk device */ \
303 x(VND, 12, "vnd") /* uvnode pseudo-disk */ \
304 x(ATAPI, 13, "ATAPI") /* ATAPI */ \
305 x(RAID, 14, "RAID") /* RAIDframe */ \
306 x(LD, 15, "ld") /* logical disk */ \
307 x(JFS2, 16, "jfs") /* IBM JFS2 */ \
308 x(CGD, 17, "cgd") /* cryptographic pseudo-disk */ \
309 x(VINUM, 18, "vinum") /* vinum volume */ \
310 x(FLASH, 19, "flash") /* flash memory devices */ \
311 x(DM, 20, "dm") /* device-mapper pseudo-disk devices */\
312 x(RUMPD, 21, "rumpd") /* rump virtual disk */ \
315 #define DKTYPE_NUMS(tag, number, name) __CONCAT(DTYPE_,tag=number),
316 #ifndef DKTYPE_ENUMNAME
317 #define DKTYPE_ENUMNAME
319 enum DKTYPE_ENUMNAME
{ DKTYPE_DEFN(DKTYPE_NUMS
) DKMAXTYPES
};
324 #define DKTYPE_NAMES(tag, number, name) ARRAY_INIT(number,name),
325 static const char *const dktypenames
[] = { DKTYPE_DEFN(DKTYPE_NAMES
) NULL
};
330 * Partition type names, numbers, label-names, fsck prog, and mount prog
332 #define FSTYPE_DEFN(x) \
333 x(UNUSED, 0, "unused", NULL, NULL) /* unused */ \
334 x(SWAP, 1, "swap", NULL, NULL) /* swap */ \
335 x(V6, 2, "Version 6", NULL, NULL) /* Sixth Edition */ \
336 x(V7, 3, "Version 7", "v7fs", "v7fs") /* Seventh Edition */ \
337 x(SYSV, 4, "System V", NULL, NULL) /* System V */ \
338 x(V71K, 5, "4.1BSD", NULL, NULL) /* V7, 1K blocks (4.1, 2.9) */ \
339 x(V8, 6, "Eighth Edition",NULL, NULL) /* Eighth Edition, 4K blocks */ \
340 x(BSDFFS, 7, "4.2BSD", "ffs", "ffs") /* 4.2BSD fast file system */ \
341 x(MSDOS, 8, "MSDOS", "msdos", "msdos") /* MSDOS file system */ \
342 x(BSDLFS, 9, "4.4LFS", "lfs", "lfs") /* 4.4BSD log-structured FS */ \
343 x(OTHER, 10, "unknown", NULL, NULL) /* in use, unknown/unsupported */\
344 x(HPFS, 11, "HPFS", NULL, NULL) /* OS/2 high-performance FS */ \
345 x(ISO9660, 12, "ISO9660", NULL, "cd9660")/* ISO 9660, normally CD-ROM */ \
346 x(BOOT, 13, "boot", NULL, NULL) /* bootstrap code in partition */\
347 x(ADOS, 14, "ADOS", NULL, "ados") /* AmigaDOS fast file system */ \
348 x(HFS, 15, "HFS", NULL, NULL) /* Macintosh HFS */ \
349 x(FILECORE,16, "FILECORE", NULL, "filecore")/* Acorn Filecore FS */ \
350 x(EX2FS, 17, "Linux Ext2","ext2fs","ext2fs")/* Linux Extended 2 FS */ \
351 x(NTFS, 18, "NTFS", NULL, "ntfs") /* Windows/NT file system */ \
352 x(RAID, 19, "RAID", NULL, NULL) /* RAIDframe component */ \
353 x(CCD, 20, "ccd", NULL, NULL) /* concatenated disk component */\
354 x(JFS2, 21, "jfs", NULL, NULL) /* IBM JFS2 */ \
355 x(APPLEUFS,22, "Apple UFS", "ffs", "ffs") /* Apple UFS */ \
356 /* XXX this is not the same as FreeBSD. How to solve? */ \
357 x(VINUM, 23, "vinum", NULL, NULL) /* Vinum */ \
358 x(UDF, 24, "UDF", NULL, "udf") /* UDF */ \
359 x(SYSVBFS, 25, "SysVBFS", NULL, "sysvbfs")/* System V boot file system */ \
360 x(EFS, 26, "EFS", NULL, "efs") /* SGI's Extent Filesystem */ \
361 x(NILFS, 27, "NiLFS", NULL, "nilfs") /* NTT's NiLFS(2) */ \
362 x(CGD, 28, "cgd", NULL, NULL) /* Cryptographic disk */
366 #define FS_TYPENUMS(tag, number, name, fsck, mount) __CONCAT(FS_,tag=number),
367 #ifndef FSTYPE_ENUMNAME
368 #define FSTYPE_ENUMNAME
370 enum FSTYPE_ENUMNAME
{ FSTYPE_DEFN(FS_TYPENUMS
) FSMAXTYPES
};
375 #define FS_TYPENAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,name),
376 static const char *const fstypenames
[] = { FSTYPE_DEFN(FS_TYPENAMES
) NULL
};
381 /* These are the names MOUNT_XXX from <sys/mount.h> */
382 #define FS_FSCKNAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,fsck),
383 static const char *const fscknames
[] = { FSTYPE_DEFN(FS_FSCKNAMES
) NULL
};
385 #define FSMAXNAMES FSMAXTYPES
389 /* These are the names MOUNT_XXX from <sys/mount.h> */
390 #define FS_MOUNTNAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,mount),
391 static const char *const mountnames
[] = { FSTYPE_DEFN(FS_MOUNTNAMES
) NULL
};
393 #define FSMAXMOUNTNAMES FSMAXTYPES
397 * flags shared by various drives:
399 #define D_REMOVABLE 0x01 /* removable media */
400 #define D_ECC 0x02 /* supports ECC */
401 #define D_BADSECT 0x04 /* supports bad sector forw. */
402 #define D_RAMDISK 0x08 /* disk emulator */
403 #define D_CHAIN 0x10 /* can do back-back transfers */
404 #define D_SCSI_MMC 0x20 /* SCSI MMC sessioned media */
407 * Drive data for SMD.
409 #define d_smdflags d_drivedata[0]
410 #define D_SSE 0x1 /* supports skip sectoring */
411 #define d_mindist d_drivedata[1]
412 #define d_maxdist d_drivedata[2]
413 #define d_sdist d_drivedata[3]
416 * Drive data for ST506.
418 #define d_precompcyl d_drivedata[0]
419 #define d_gap3 d_drivedata[1] /* used only when formatting */
422 * Drive data for SCSI.
424 #define d_blind d_drivedata[0]
428 * Structure used to perform a format or other raw operation,
429 * returning data and/or register values. Register identification
430 * and format are device- and driver-dependent. Currently unused.
434 int df_count
; /* value-result */
436 int df_reg
[8]; /* result */
441 * Structure used internally to retrieve information about a partition
445 struct disklabel
*disklab
;
446 struct partition
*part
;
451 int disk_read_sectors(void (*)(struct buf
*), const struct disklabel
*,
452 struct buf
*, unsigned int, int);
453 void diskerr(const struct buf
*, const char *, const char *, int,
454 int, const struct disklabel
*);
455 u_int
dkcksum(struct disklabel
*);
456 u_int
dkcksum_sized(struct disklabel
*, size_t);
457 int setdisklabel(struct disklabel
*, struct disklabel
*, u_long
,
458 struct cpu_disklabel
*);
459 const char *readdisklabel(dev_t
, void (*)(struct buf
*),
460 struct disklabel
*, struct cpu_disklabel
*);
461 int writedisklabel(dev_t
, void (*)(struct buf
*), struct disklabel
*,
462 struct cpu_disklabel
*);
463 const char *convertdisklabel(struct disklabel
*, void (*)(struct buf
*),
464 struct buf
*, uint32_t);
465 int bounds_check_with_label(struct disk
*, struct buf
*, int);
466 int bounds_check_with_mediasize(struct buf
*, int, uint64_t);
467 const char *getfstypename(int);
471 #if !defined(_KERNEL) && !defined(_LOCORE)
473 #include <sys/cdefs.h>
477 #endif /* !_SYS_DISKLABEL_H_ */