xref: /illumos-gate/usr/src/uts/common/sys/dklabel.h (revision bbf21555)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_DKLABEL_H
28 #define	_SYS_DKLABEL_H
29 
30 #include <sys/isa_defs.h>
31 #include <sys/types32.h>
32 #include <sys/isa_defs.h>
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 /*
39  * Miscellaneous defines
40  */
41 #define	DKL_MAGIC	0xDABE		/* magic number */
42 #define	FKL_MAGIC	0xff		/* magic number for DOS floppies */
43 
44 #if defined(_SUNOS_VTOC_16)
45 #define	NDKMAP		16		/* # of logical partitions */
46 #define	DK_LABEL_LOC	1		/* location of disk label */
47 #elif defined(_SUNOS_VTOC_8)
48 #define	NDKMAP		8		/* # of logical partitions */
49 #define	DK_LABEL_LOC	0		/* location of disk label */
50 #else
51 #error "No VTOC format defined."
52 #endif
53 
54 #define	LEN_DKL_ASCII	128		/* length of dkl_asciilabel */
55 #define	LEN_DKL_VVOL	8		/* length of v_volume */
56 #define	DK_LABEL_SIZE	512		/* size of disk label */
57 #define	DK_MAX_BLOCKS	0x7fffffff	/* max # of blocks handled */
58 
59 /*
60  * Reserve two cylinders on SCSI disks.
61  * One is for the backup disk label and the other is for the deviceid.
62  *
63  * IPI disks only reserve one cylinder, but they will go away soon.
64  * CDROMs do not reserve any cylinders.
65  */
66 #define	DK_ACYL		2
67 
68 /*
69  * Format of a Sun disk label.
70  * Resides in cylinder 0, head 0, sector 0.
71  *
72  * sizeof (struct dk_label) should be 512 (the current sector size),
73  * but should the sector size increase, this structure should remain
74  * at the beginning of the sector.
75  */
76 
77 #if !defined(BLKADDR_TYPE)
78 #define	BLKADDR_TYPE
79 #if defined(_EXTVTOC)
80 typedef	unsigned long	blkaddr_t;
81 typedef	unsigned int	blkaddr32_t;
82 #else
83 typedef	daddr_t		blkaddr_t;
84 typedef	daddr32_t	blkaddr32_t;
85 #endif
86 #endif
87 
88 /*
89  * partition headers:  section 1
90  * Returned in struct dk_allmap by ioctl DKIOC[SG]APART (dkio(4I))
91  */
92 struct dk_map {
93 	blkaddr_t	dkl_cylno;	/* starting cylinder */
94 	blkaddr_t	dkl_nblk;	/* number of blocks;  if == 0, */
95 					/* partition is undefined */
96 };
97 
98 /*
99  * partition headers:  section 1
100  * Fixed size for on-disk dk_label
101  */
102 struct dk_map32 {
103 	blkaddr32_t	dkl_cylno;	/* starting cylinder */
104 	blkaddr32_t	dkl_nblk;	/* number of blocks;  if == 0, */
105 					/* partition is undefined */
106 };
107 
108 /*
109  * partition headers:  section 2,
110  * brought over from AT&T SVr4 vtoc structure.
111  */
112 struct dk_map2 {
113 	uint16_t	p_tag;		/* ID tag of partition */
114 	uint16_t	p_flag;		/* permission flag */
115 };
116 
117 struct dkl_partition    {
118 	uint16_t	p_tag;		/* ID tag of partition */
119 	uint16_t	p_flag;		/* permision flags */
120 	blkaddr32_t	p_start;	/* start sector no of partition */
121 	blkaddr32_t	p_size;		/* # of blocks in partition */
122 };
123 
124 
125 /*
126  * VTOC inclusions from AT&T SVr4
127  * Fixed sized types for on-disk VTOC
128  */
129 
130 struct dk_vtoc {
131 #if defined(_SUNOS_VTOC_16)
132 	uint32_t v_bootinfo[3];		/* info for mboot (unsupported) */
133 	uint32_t v_sanity;		/* to verify vtoc sanity */
134 	uint32_t v_version;		/* layout version */
135 	char    v_volume[LEN_DKL_VVOL];	/* volume name */
136 	uint16_t v_sectorsz;		/* sector size in bytes */
137 	uint16_t v_nparts;		/* number of partitions */
138 	uint32_t v_reserved[10];	/* free space */
139 	struct dkl_partition v_part[NDKMAP];	/* partition headers */
140 	time32_t timestamp[NDKMAP];	/* partition timestamp (unsupported) */
141 	char    v_asciilabel[LEN_DKL_ASCII];	/* for compatibility    */
142 #elif defined(_SUNOS_VTOC_8)
143 	uint32_t	v_version;		/* layout version */
144 	char		v_volume[LEN_DKL_VVOL];	/* volume name */
145 	uint16_t	v_nparts;		/* number of partitions  */
146 	struct dk_map2	v_part[NDKMAP];		/* partition hdrs, sec 2 */
147 	uint32_t	v_bootinfo[3];		/* info needed by mboot */
148 	uint32_t	v_sanity;		/* to verify vtoc sanity */
149 	uint32_t	v_reserved[10];		/* free space */
150 	time32_t	v_timestamp[NDKMAP];	/* partition timestamp */
151 #else
152 #error "No VTOC format defined."
153 #endif
154 };
155 
156 /*
157  * define the amount of disk label padding needed to make
158  * the entire structure occupy 512 bytes.
159  */
160 #if defined(_SUNOS_VTOC_16)
161 #define	LEN_DKL_PAD	(DK_LABEL_SIZE - \
162 			    ((sizeof (struct dk_vtoc) + \
163 			    (4 * sizeof (uint32_t)) + \
164 			    (12 * sizeof (uint16_t)) + \
165 			    (2 * (sizeof (uint16_t))))))
166 #elif defined(_SUNOS_VTOC_8)
167 #define	LEN_DKL_PAD	(DK_LABEL_SIZE \
168 			    - ((LEN_DKL_ASCII) + \
169 			    (sizeof (struct dk_vtoc)) + \
170 			    (sizeof (struct dk_map32)  * NDKMAP) + \
171 			    (14 * (sizeof (uint16_t))) + \
172 			    (2 * (sizeof (uint16_t)))))
173 #else
174 #error "No VTOC format defined."
175 #endif
176 
177 
178 struct dk_label {
179 #if defined(_SUNOS_VTOC_16)
180 	struct  dk_vtoc dkl_vtoc;	/* vtoc inclusions from AT&T SVr4 */
181 	uint32_t	dkl_pcyl;	/* # of physical cylinders */
182 	uint32_t	dkl_ncyl;	/* # of data cylinders */
183 	uint16_t	dkl_acyl;	/* # of alternate cylinders */
184 	uint16_t	dkl_bcyl;	/* cyl offset (for fixed head area) */
185 	uint32_t	dkl_nhead;	/* # of heads */
186 	uint32_t	dkl_nsect;	/* # of data sectors per track */
187 	uint16_t	dkl_intrlv;	/* interleave factor */
188 	uint16_t	dkl_skew;	/* skew factor */
189 	uint16_t	dkl_apc;	/* alternates per cyl (SCSI only)   */
190 	uint16_t	dkl_rpm;	/* revolutions per minute */
191 	uint16_t	dkl_write_reinstruct;	/* # sectors to skip, writes */
192 	uint16_t	dkl_read_reinstruct;	/* # sectors to skip, reads  */
193 	uint16_t	dkl_extra[4];	/* for compatible expansion */
194 	char		dkl_pad[LEN_DKL_PAD];	/* unused part of 512 bytes */
195 #elif defined(_SUNOS_VTOC_8)
196 	char		dkl_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
197 	struct dk_vtoc	dkl_vtoc;	/* vtoc inclusions from AT&T SVr4 */
198 	uint16_t	dkl_write_reinstruct;	/* # sectors to skip, writes */
199 	uint16_t	dkl_read_reinstruct;	/* # sectors to skip, reads */
200 	char		dkl_pad[LEN_DKL_PAD]; /* unused part of 512 bytes */
201 	uint16_t	dkl_rpm;	/* rotations per minute */
202 	uint16_t	dkl_pcyl;	/* # physical cylinders */
203 	uint16_t	dkl_apc;	/* alternates per cylinder */
204 	uint16_t	dkl_obs1;	/* obsolete */
205 	uint16_t	dkl_obs2;	/* obsolete */
206 	uint16_t	dkl_intrlv;	/* interleave factor */
207 	uint16_t	dkl_ncyl;	/* # of data cylinders */
208 	uint16_t	dkl_acyl;	/* # of alternate cylinders */
209 	uint16_t	dkl_nhead;	/* # of heads in this partition */
210 	uint16_t	dkl_nsect;	/* # of sectors per track */
211 	uint16_t	dkl_obs3;	/* obsolete */
212 	uint16_t	dkl_obs4;	/* obsolete */
213 	struct dk_map32	dkl_map[NDKMAP]; /* logical partition headers */
214 #else
215 #error "No VTOC format defined."
216 #endif
217 	uint16_t	dkl_magic;	/* identifies this label format */
218 	uint16_t	dkl_cksum;	/* xor checksum of sector */
219 };
220 
221 #if defined(_SUNOS_VTOC_16)
222 #define	dkl_asciilabel	dkl_vtoc.v_asciilabel
223 #define	v_timestamp	timestamp
224 
225 #elif defined(_SUNOS_VTOC_8)
226 
227 /*
228  * These defines are for historic compatibility with old drivers.
229  */
230 #define	dkl_gap1	dkl_obs1	/* used to be gap1 */
231 #define	dkl_gap2	dkl_obs2	/* used to be gap2 */
232 #define	dkl_bhead	dkl_obs3	/* used to be label head offset */
233 #define	dkl_ppart	dkl_obs4	/* used to by physical partition */
234 #else
235 #error "No VTOC format defined."
236 #endif
237 
238 struct fk_label {			/* DOS floppy label */
239 	uchar_t  fkl_type;
240 	uchar_t  fkl_magich;
241 	uchar_t  fkl_magicl;
242 	uchar_t  filler;
243 };
244 
245 /*
246  * Layout of stored fabricated device id  (on-disk)
247  */
248 #define	DK_DEVID_BLKSIZE	(512)
249 #define	DK_DEVID_SIZE		(DK_DEVID_BLKSIZE - ((sizeof (uchar_t) * 7)))
250 #define	DK_DEVID_REV_MSB	(0)
251 #define	DK_DEVID_REV_LSB	(1)
252 
253 struct dk_devid {
254 	uchar_t	dkd_rev_hi;			/* revision (MSB) */
255 	uchar_t	dkd_rev_lo;			/* revision (LSB) */
256 	uchar_t	dkd_flags;			/* flags (not used yet) */
257 	uchar_t	dkd_devid[DK_DEVID_SIZE];	/* devid stored here */
258 	uchar_t	dkd_checksum3;			/* checksum (MSB) */
259 	uchar_t	dkd_checksum2;
260 	uchar_t	dkd_checksum1;
261 	uchar_t	dkd_checksum0;			/* checksum (LSB) */
262 };
263 
264 #define	DKD_GETCHKSUM(dkd)	((dkd)->dkd_checksum3 << 24) + \
265 				((dkd)->dkd_checksum2 << 16) + \
266 				((dkd)->dkd_checksum1 << 8)  + \
267 				((dkd)->dkd_checksum0)
268 
269 #define	DKD_FORMCHKSUM(c, dkd)	(dkd)->dkd_checksum3 = hibyte(hiword((c))); \
270 				(dkd)->dkd_checksum2 = lobyte(hiword((c))); \
271 				(dkd)->dkd_checksum1 = hibyte(loword((c))); \
272 				(dkd)->dkd_checksum0 = lobyte(loword((c)));
273 #ifdef	__cplusplus
274 }
275 #endif
276 
277 #endif	/* _SYS_DKLABEL_H */
278