FreeBSD/Linux Kernel Cross Reference
sys/sys/disklabel.h
1 /* $NetBSD: disklabel.h,v 1.97 2005/12/29 14:53:47 tsutsui 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 #if HAVE_NBTOOL_CONFIG_H
52 #include <nbinclude/machine/disklabel.h>
53 #else
54 #include <machine/disklabel.h>
55 #endif /* HAVE_NBTOOL_CONFIG_H */
56
57 /*
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.
61 */
62 #define MAXMAXPARTITIONS 22
63 #if MAXPARTITIONS > MAXMAXPARTITIONS
64 #warning beware: MAXPARTITIONS bigger than MAXMAXPARTITIONS
65 #endif
66
67 /*
68 * Ports can switch their MAXPARTITIONS once, as follows:
69 *
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>
75 */
76
77 #if defined(_KERNEL) && defined(__HAVE_OLD_DISKLABEL) && \
78 (MAXPARTITIONS < OLDMAXPARTITIONS)
79 #error "can only grow disklabel size"
80 #endif
81
82
83 /*
84 * Translate between device numbers and major/disk unit/disk partition.
85 */
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 */
93 #endif
94 #define MAKEDISKDEV(maj, unit, part) \
95 (makedev((maj), DISKMINOR((unit), (part))))
96
97 #define DISKMAGIC ((uint32_t)0x82564557) /* The disk magic number */
98
99 #ifndef _LOCORE
100 struct disklabel {
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" */
105
106 /*
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.
113 */
114 union {
115 char un_d_packname[16]; /* pack identifier */
116 struct {
117 char *un_d_boot0; /* primary bootstrap name */
118 char *un_d_boot1; /* secondary bootstrap name */
119 } un_b;
120 } d_un;
121 #define d_packname d_un.un_d_packname
122 #define d_boot0 d_un.un_b.un_d_boot0
123 #define d_boot1 d_un.un_b.un_d_boot1
124
125 /* disk geometry: */
126 uint32_t d_secsize; /* # of bytes per sector */
127 uint32_t d_nsectors; /* # of data sectors per track */
128 uint32_t d_ntracks; /* # of tracks per cylinder */
129 uint32_t d_ncylinders; /* # of data cylinders per unit */
130 uint32_t d_secpercyl; /* # of data sectors per cylinder */
131 uint32_t d_secperunit; /* # of data sectors per unit */
132
133 /*
134 * Spares (bad sector replacements) below are not counted in
135 * d_nsectors or d_secpercyl. Spare sectors are assumed to
136 * be physical sectors which occupy space at the end of each
137 * track and/or cylinder.
138 */
139 uint16_t d_sparespertrack; /* # of spare sectors per track */
140 uint16_t d_sparespercyl; /* # of spare sectors per cylinder */
141 /*
142 * Alternative cylinders include maintenance, replacement,
143 * configuration description areas, etc.
144 */
145 uint32_t d_acylinders; /* # of alt. cylinders per unit */
146
147 /* hardware characteristics: */
148 /*
149 * d_interleave, d_trackskew and d_cylskew describe perturbations
150 * in the media format used to compensate for a slow controller.
151 * Interleave is physical sector interleave, set up by the
152 * formatter or controller when formatting. When interleaving is
153 * in use, logically adjacent sectors are not physically
154 * contiguous, but instead are separated by some number of
155 * sectors. It is specified as the ratio of physical sectors
156 * traversed per logical sector. Thus an interleave of 1:1
157 * implies contiguous layout, while 2:1 implies that logical
158 * sector 0 is separated by one sector from logical sector 1.
159 * d_trackskew is the offset of sector 0 on track N relative to
160 * sector 0 on track N-1 on the same cylinder. Finally, d_cylskew
161 * is the offset of sector 0 on cylinder N relative to sector 0
162 * on cylinder N-1.
163 */
164 uint16_t d_rpm; /* rotational speed */
165 uint16_t d_interleave; /* hardware sector interleave */
166 uint16_t d_trackskew; /* sector 0 skew, per track */
167 uint16_t d_cylskew; /* sector 0 skew, per cylinder */
168 uint32_t d_headswitch; /* head switch time, usec */
169 uint32_t d_trkseek; /* track-to-track seek, usec */
170 uint32_t d_flags; /* generic flags */
171 #define NDDATA 5
172 uint32_t d_drivedata[NDDATA]; /* drive-type specific information */
173 #define NSPARE 5
174 uint32_t d_spare[NSPARE]; /* reserved for future use */
175 uint32_t d_magic2; /* the magic number (again) */
176 uint16_t d_checksum; /* xor of data incl. partitions */
177
178 /* filesystem and partition information: */
179 uint16_t d_npartitions; /* number of partitions in following */
180 uint32_t d_bbsize; /* size of boot area at sn0, bytes */
181 uint32_t d_sbsize; /* max size of fs superblock, bytes */
182 struct partition { /* the partition table */
183 uint32_t p_size; /* number of sectors in partition */
184 uint32_t p_offset; /* starting sector */
185 union {
186 uint32_t fsize; /* FFS, ADOS:
187 filesystem basic fragment size */
188 uint32_t cdsession; /* ISO9660: session offset */
189 } __partition_u2;
190 #define p_fsize __partition_u2.fsize
191 #define p_cdsession __partition_u2.cdsession
192 uint8_t p_fstype; /* filesystem type, see below */
193 uint8_t p_frag; /* filesystem fragments per block */
194 union {
195 uint16_t cpg; /* UFS: FS cylinders per group */
196 uint16_t sgs; /* LFS: FS segment shift */
197 } __partition_u1;
198 #define p_cpg __partition_u1.cpg
199 #define p_sgs __partition_u1.sgs
200 } d_partitions[MAXPARTITIONS]; /* actually may be more */
201 };
202
203 #if defined(__HAVE_OLD_DISKLABEL) && !HAVE_NBTOOL_CONFIG_H
204 /*
205 * Same as above, but with OLDMAXPARTITIONS partitions. For use in
206 * the old DIOC* ioctl calls.
207 */
208 struct olddisklabel {
209 uint32_t d_magic;
210 uint16_t d_type;
211 uint16_t d_subtype;
212 char d_typename[16];
213 union {
214 char un_d_packname[16];
215 struct {
216 char *un_d_boot0;
217 char *un_d_boot1;
218 } un_b;
219 } d_un;
220 uint32_t d_secsize;
221 uint32_t d_nsectors;
222 uint32_t d_ntracks;
223 uint32_t d_ncylinders;
224 uint32_t d_secpercyl;
225 uint32_t d_secperunit;
226 uint16_t d_sparespertrack;
227 uint16_t d_sparespercyl;
228 uint32_t d_acylinders;
229 uint16_t d_rpm;
230 uint16_t d_interleave;
231 uint16_t d_trackskew;
232 uint16_t d_cylskew;
233 uint32_t d_headswitch;
234 uint32_t d_trkseek;
235 uint32_t d_flags;
236 uint32_t d_drivedata[NDDATA];
237 uint32_t d_spare[NSPARE];
238 uint32_t d_magic2;
239 uint16_t d_checksum;
240 uint16_t d_npartitions;
241 uint32_t d_bbsize;
242 uint32_t d_sbsize;
243 struct opartition {
244 uint32_t p_size;
245 uint32_t p_offset;
246 union {
247 uint32_t fsize;
248 uint32_t cdsession;
249 } __partition_u2;
250 uint8_t p_fstype;
251 uint8_t p_frag;
252 union {
253 uint16_t cpg;
254 uint16_t sgs;
255 } __partition_u1;
256 } d_partitions[OLDMAXPARTITIONS];
257 };
258 #endif /* __HAVE_OLD_DISKLABEL */
259 #else /* _LOCORE */
260 /*
261 * offsets for asm boot files.
262 */
263 .set d_secsize,40
264 .set d_nsectors,44
265 .set d_ntracks,48
266 .set d_ncylinders,52
267 .set d_secpercyl,56
268 .set d_secperunit,60
269 .set d_end_,276 /* size of disk label */
270 #endif /* _LOCORE */
271
272 /*
273 * We normally use C99 initialisers (just in case the lists below are out
274 * of sequence, or have gaps), but lint doesn't grok them.
275 * Maybe some host compilers don't either, but many have for quite some time.
276 */
277
278 #ifndef lint
279 #define ARRAY_INIT(element,value) [element]=value
280 #else
281 #define ARRAY_INIT(element,value) value
282 #endif
283
284 /* Use pre-processor magic to get all the parameters one one line... */
285
286 /* d_type values: */
287 #define DKTYPE_DEFN(x) \
288 x(UNKNOWN, 0, "unknown") \
289 x(SMD, 1, "SMD") /* SMD, XSMD; VAX hp/up */ \
290 x(MSCP, 2, "MSCP") /* MSCP */ \
291 x(DEC, 3, "old DEC") /* other DEC (rk, rl) */ \
292 x(SCSI, 4, "SCSI") /* SCSI */ \
293 x(ESDI, 5, "ESDI") /* ESDI interface */ \
294 x(ST506, 6, "ST506") /* ST506 etc. */ \
295 x(HPIB, 7, "HP-IB") /* CS/80 on HP-IB */ \
296 x(HPFL, 8, "HP-FL") /* HP Fiber-link */ \
297 x(TYPE_9, 9, "type 9") \
298 x(FLOPPY, 10, "floppy") /* floppy */ \
299 x(CCD, 11, "ccd") /* concatenated disk device */ \
300 x(VND, 12, "vnd") /* uvnode pseudo-disk */ \
301 x(ATAPI, 13, "ATAPI") /* ATAPI */ \
302 x(RAID, 14, "RAID") /* RAIDframe */ \
303 x(LD, 15, "ld") /* logical disk */ \
304 x(JFS2, 16, "jfs") /* IBM JFS2 */ \
305 x(CGD, 17, "cgd") /* cryptographic pseudo-disk */ \
306 x(VINUM, 18, "vinum") /* vinum volume */ \
307 x(FLASH, 19, "flash") /* flash memory devices */ \
308
309 #ifndef OMIT_DKTYPENUMS
310 #define DKTYPE_NUMS(tag, number, name) __CONCAT(DTYPE_,tag=number),
311 enum { DKTYPE_DEFN(DKTYPE_NUMS) DKMAXTYPES };
312 #undef DKTYPE_NUMS
313 #endif /* OMIT_DKTYPENUMS */
314
315 #ifdef DKTYPENAMES
316 #define DKTYPE_NAMES(tag, number, name) ARRAY_INIT(number,name),
317 static const char *const dktypenames[] = { DKTYPE_DEFN(DKTYPE_NAMES) NULL };
318 #undef DKTYPE_NAMES
319 #endif
320
321 /*
322 * Partition type names, numbers, label-names, fsck prog, and mount prog
323 */
324 #define FSTYPE_DEFN(x) \
325 x(UNUSED, 0, "unused", NULL, NULL) /* unused */ \
326 x(SWAP, 1, "swap", NULL, NULL) /* swap */ \
327 x(V6, 2, "Version 6", NULL, NULL) /* Sixth Edition */ \
328 x(V7, 3, "Version 7", NULL, NULL) /* Seventh Edition */ \
329 x(SYSV, 4, "System V", NULL, NULL) /* System V */ \
330 x(V71K, 5, "4.1BSD", NULL, NULL) /* V7, 1K blocks (4.1, 2.9) */ \
331 x(V8, 6, "Eighth Edition",NULL, NULL) /* Eighth Edition, 4K blocks */ \
332 x(BSDFFS, 7, "4.2BSD", "ffs", "ffs") /* 4.2BSD fast file system */ \
333 x(MSDOS, 8, "MSDOS", "msdos", "msdos") /* MSDOS file system */ \
334 x(BSDLFS, 9, "4.4LFS", "lfs", "lfs") /* 4.4BSD log-structured FS */ \
335 x(OTHER, 10, "unknown", NULL, NULL) /* in use, unknown/unsupported */\
336 x(HPFS, 11, "HPFS", NULL, NULL) /* OS/2 high-performance FS */ \
337 x(ISO9660, 12, "ISO9660", NULL, "cd9660")/* ISO 9660, normally CD-ROM */ \
338 x(BOOT, 13, "boot", NULL, NULL) /* bootstrap code in partition */\
339 x(ADOS, 14, "ADOS", NULL, "ados") /* AmigaDOS fast file system */ \
340 x(HFS, 15, "HFS", NULL, NULL) /* Macintosh HFS */ \
341 x(FILECORE,16, "FILECORE", NULL, "filecore")/* Acorn Filecore FS */ \
342 x(EX2FS, 17, "Linux Ext2","ext2fs","ext2fs")/* Linux Extended 2 FS */ \
343 x(NTFS, 18, "NTFS", NULL, "ntfs") /* Windows/NT file system */ \
344 x(RAID, 19, "RAID", NULL, NULL) /* RAIDframe component */ \
345 x(CCD, 20, "ccd", NULL, NULL) /* concatenated disk component */\
346 x(JFS2, 21, "jfs", NULL, NULL) /* IBM JFS2 */ \
347 x(APPLEUFS,22, "Apple UFS", "ffs", "ffs") /* Apple UFS */ \
348 /* XXX this is not the same as FreeBSD. How to solve? */ \
349 x(VINUM, 23, "vinum", NULL, NULL) /* Vinum */ \
350 x(UDF, 24, "UDF", NULL, "udf") /* UDF */ \
351 x(SYSVBFS, 25, "SysVBFS", NULL, "sysvbfs")/* System V boot file system */ \
352
353 #ifndef OMIT_FSTYPENUMS
354 #define FS_TYPENUMS(tag, number, name, fsck, mount) __CONCAT(FS_,tag=number),
355 enum { FSTYPE_DEFN(FS_TYPENUMS) FSMAXTYPES };
356 #undef FS_TYPENUMS
357 #endif /* OMIT_FSTYPENUMS */
358
359 #ifdef FSTYPENAMES
360 #define FS_TYPENAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,name),
361 static const char *const fstypenames[] = { FSTYPE_DEFN(FS_TYPENAMES) NULL };
362 #undef FS_TYPENAMES
363 #endif
364
365 #ifdef FSCKNAMES
366 /* These are the names MOUNT_XXX from <sys/mount.h> */
367 #define FS_FSCKNAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,fsck),
368 static const char *const fscknames[] = { FSTYPE_DEFN(FS_FSCKNAMES) NULL };
369 #undef FS_FSCKNAMES
370 #define FSMAXNAMES FSMAXTYPES
371 #endif
372
373 #ifdef MOUNTNAMES
374 /* These are the names MOUNT_XXX from <sys/mount.h> */
375 #define FS_MOUNTNAMES(tag, number, name, fsck, mount) ARRAY_INIT(number,mount),
376 static const char *const mountnames[] = { FSTYPE_DEFN(FS_MOUNTNAMES) NULL };
377 #undef FS_MOUNTNAMES
378 #define FSMAXMOUNTNAMES FSMAXTYPES
379 #endif
380
381 /*
382 * flags shared by various drives:
383 */
384 #define D_REMOVABLE 0x01 /* removable media */
385 #define D_ECC 0x02 /* supports ECC */
386 #define D_BADSECT 0x04 /* supports bad sector forw. */
387 #define D_RAMDISK 0x08 /* disk emulator */
388 #define D_CHAIN 0x10 /* can do back-back transfers */
389
390 /*
391 * Drive data for SMD.
392 */
393 #define d_smdflags d_drivedata[0]
394 #define D_SSE 0x1 /* supports skip sectoring */
395 #define d_mindist d_drivedata[1]
396 #define d_maxdist d_drivedata[2]
397 #define d_sdist d_drivedata[3]
398
399 /*
400 * Drive data for ST506.
401 */
402 #define d_precompcyl d_drivedata[0]
403 #define d_gap3 d_drivedata[1] /* used only when formatting */
404
405 /*
406 * Drive data for SCSI.
407 */
408 #define d_blind d_drivedata[0]
409
410 #ifndef _LOCORE
411 /*
412 * Structure used to perform a format or other raw operation,
413 * returning data and/or register values. Register identification
414 * and format are device- and driver-dependent. Currently unused.
415 */
416 struct format_op {
417 char *df_buf;
418 int df_count; /* value-result */
419 daddr_t df_startblk;
420 int df_reg[8]; /* result */
421 };
422
423 /*
424 * Structure used internally to retrieve information about a partition
425 * on a disk.
426 */
427 struct partinfo {
428 struct disklabel *disklab;
429 struct partition *part;
430 };
431
432 #ifdef _KERNEL
433
434 struct disk;
435
436 void diskerr(const struct buf *, const char *, const char *, int,
437 int, const struct disklabel *);
438 u_int dkcksum(struct disklabel *);
439 int setdisklabel(struct disklabel *, struct disklabel *, u_long,
440 struct cpu_disklabel *);
441 const char *readdisklabel(dev_t, void (*)(struct buf *),
442 struct disklabel *, struct cpu_disklabel *);
443 int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *,
444 struct cpu_disklabel *);
445 int bounds_check_with_label(struct disk *, struct buf *, int);
446 int bounds_check_with_mediasize(struct buf *, int, uint64_t);
447 #endif
448 #endif /* _LOCORE */
449
450 #if !defined(_KERNEL) && !defined(_LOCORE)
451
452 #include <sys/cdefs.h>
453
454 #endif
455
456 #endif /* !_SYS_DISKLABEL_H_ */
Cache object: eed2de3b24e66d937eb9532ea190d628
|