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