1 /*        $NetBSD: ukfs_int_disklabel.h,v 1.3 2011/02/22 15:42:15 pooka Exp $   */
2 
3 /*
4  * Modified copy of disklabel.h so that ukfs doesn't have to depend
5  * on NetBSD headers.  Contains just about only "struct disklabel".
6  * The on-disk disklabel doesn't really change format, so no need
7  * to track this against NetBSD changes.
8  */
9 
10 /*
11  * Copyright (c) 1987, 1988, 1993
12  *        The Regents of the University of California.  All rights reserved.
13  *
14  * Redistribution and use in source and binary forms, with or without
15  * modification, are permitted provided that the following conditions
16  * are met:
17  * 1. Redistributions of source code must retain the above copyright
18  *    notice, this list of conditions and the following disclaimer.
19  * 2. Redistributions in binary form must reproduce the above copyright
20  *    notice, this list of conditions and the following disclaimer in the
21  *    documentation and/or other materials provided with the distribution.
22  * 3. Neither the name of the University nor the names of its contributors
23  *    may be used to endorse or promote products derived from this software
24  *    without specific prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36  * SUCH DAMAGE.
37  *
38  *        @(#)disklabel.h     8.2 (Berkeley) 7/10/94
39  */
40 
41 #ifndef LIB_UKFS_DISKLABEL_H_
42 #define   LIB_UKFS_DISKLABEL_H_
43 
44 #include <sys/types.h>
45 
46 #include <stdint.h>
47 
48 #define   UKFS_MAXPARTITIONS  22
49 #define   UKFS_DISKMAGIC      ((uint32_t)0x82564557)        /* The disk magic number */
50 
51 struct ukfs__disklabel {
52           uint32_t d_magic;             /* the magic number */
53           uint16_t d_type;              /* drive type */
54           uint16_t d_subtype;           /* controller/d_type specific */
55           char        d_typename[16];   /* type name, e.g. "eagle" */
56 
57           /*
58            * d_packname contains the pack identifier and is returned when
59            * the disklabel is read off the disk or in-core copy.
60            * d_boot0 and d_boot1 are the (optional) names of the
61            * primary (block 0) and secondary (block 1-15) bootstraps
62            * as found in /usr/mdec.  These are returned when using
63            * getdiskbyname(3) to retrieve the values from /etc/disktab.
64            */
65           union {
66                     char      un_d_packname[16];  /* pack identifier */
67                     struct {
68                               char *un_d_boot0;   /* primary bootstrap name */
69                               char *un_d_boot1;   /* secondary bootstrap name */
70                     } un_b;
71           } d_un;
72 #define   d_packname          d_un.un_d_packname
73 #define   d_boot0             d_un.un_b.un_d_boot0
74 #define   d_boot1             d_un.un_b.un_d_boot1
75 
76                               /* disk geometry: */
77           uint32_t d_secsize;           /* # of bytes per sector */
78           uint32_t d_nsectors;                    /* # of data sectors per track */
79           uint32_t d_ntracks;           /* # of tracks per cylinder */
80           uint32_t d_ncylinders;                  /* # of data cylinders per unit */
81           uint32_t d_secpercyl;                   /* # of data sectors per cylinder */
82           uint32_t d_secperunit;                  /* # of data sectors per unit */
83 
84           /*
85            * Spares (bad sector replacements) below are not counted in
86            * d_nsectors or d_secpercyl.  Spare sectors are assumed to
87            * be physical sectors which occupy space at the end of each
88            * track and/or cylinder.
89            */
90           uint16_t d_sparespertrack;    /* # of spare sectors per track */
91           uint16_t d_sparespercyl;      /* # of spare sectors per cylinder */
92           /*
93            * Alternative cylinders include maintenance, replacement,
94            * configuration description areas, etc.
95            */
96           uint32_t d_acylinders;                  /* # of alt. cylinders per unit */
97 
98                               /* hardware characteristics: */
99           /*
100            * d_interleave, d_trackskew and d_cylskew describe perturbations
101            * in the media format used to compensate for a slow controller.
102            * Interleave is physical sector interleave, set up by the
103            * formatter or controller when formatting.  When interleaving is
104            * in use, logically adjacent sectors are not physically
105            * contiguous, but instead are separated by some number of
106            * sectors.  It is specified as the ratio of physical sectors
107            * traversed per logical sector.  Thus an interleave of 1:1
108            * implies contiguous layout, while 2:1 implies that logical
109            * sector 0 is separated by one sector from logical sector 1.
110            * d_trackskew is the offset of sector 0 on track N relative to
111            * sector 0 on track N-1 on the same cylinder.  Finally, d_cylskew
112            * is the offset of sector 0 on cylinder N relative to sector 0
113            * on cylinder N-1.
114            */
115           uint16_t d_rpm;               /* rotational speed */
116           uint16_t d_interleave;                  /* hardware sector interleave */
117           uint16_t d_trackskew;                   /* sector 0 skew, per track */
118           uint16_t d_cylskew;           /* sector 0 skew, per cylinder */
119           uint32_t d_headswitch;                  /* head switch time, usec */
120           uint32_t d_trkseek;           /* track-to-track seek, usec */
121           uint32_t d_flags;             /* generic flags */
122 #define   NDDATA 5
123           uint32_t d_drivedata[NDDATA]; /* drive-type specific information */
124 #define   NSPARE 5
125           uint32_t d_spare[NSPARE];     /* reserved for future use */
126           uint32_t d_magic2;            /* the magic number (again) */
127           uint16_t d_checksum;                    /* xor of data incl. partitions */
128 
129                               /* filesystem and partition information: */
130           uint16_t d_npartitions;       /* number of partitions in following */
131           uint32_t d_bbsize;            /* size of boot area at sn0, bytes */
132           uint32_t d_sbsize;            /* max size of fs superblock, bytes */
133           struct    ukfs__partition {   /* the partition table */
134                     uint32_t p_size;    /* number of sectors in partition */
135                     uint32_t p_offset;  /* starting sector */
136                     union {
137                               uint32_t fsize; /* FFS, ADOS:
138                                                       filesystem basic fragment size */
139                               uint32_t cdsession; /* ISO9660: session offset */
140                     } __partition_u2;
141 #define   p_fsize             __partition_u2.fsize
142 #define   p_cdsession         __partition_u2.cdsession
143                     uint8_t p_fstype;   /* filesystem type, see below */
144                     uint8_t p_frag;     /* filesystem fragments per block */
145                     union {
146                               uint16_t cpg;       /* UFS: FS cylinders per group */
147                               uint16_t sgs;       /* LFS: FS segment shift */
148                     } __partition_u1;
149 #define   p_cpg     __partition_u1.cpg
150 #define   p_sgs     __partition_u1.sgs
151           } d_partitions[UKFS_MAXPARTITIONS];     /* actually may be more */
152 };
153 
154 uint16_t        ukfs__disklabel_dkcksum(struct ukfs__disklabel *, int);
155 int             ukfs__disklabel_scan(struct ukfs__disklabel *, int *,
156                                              char *, size_t);
157 
158 #endif /* !LIB_UKFS_DISKLABEL_H_ */
159