xref: /illumos-gate/usr/src/uts/common/sys/vtoc.h (revision dd51520e127b452179a2ce4ea3bd8dee949f9afe)
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 
28 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
29 /*	  All Rights Reserved  	*/
30 
31 
32 #ifndef _SYS_VTOC_H
33 #define	_SYS_VTOC_H
34 
35 #include <sys/dklabel.h>
36 
37 #ifdef	__cplusplus
38 extern "C" {
39 #endif
40 
41 /*
42  *	Note:  the VTOC is not implemented fully, nor in the manner
43  *	that AT&T implements it.  AT&T puts the vtoc structure
44  *	into a sector, usually the second sector (pdsector is first).
45  *
46  *	Sun incorporates the tag, flag, version, and volume vtoc fields into
47  *	its Disk Label, which already has some vtoc-equivalent fields.
48  *	Upon reading the vtoc with read_vtoc(), the following exceptions
49  *	occur:
50  *		v_bootinfo [all]	returned as zero
51  *		v_sanity		returned as VTOC_SANE
52  *						if Disk Label was sane
53  *		v_sectorsz		returned as 512
54  *		v_reserved [all]	retunred as zero
55  *		timestamp [all]		returned as zero
56  *
57  *	See  dklabel.h, read_vtoc(), and write_vtoc().
58  */
59 
60 #define	V_NUMPAR 	NDKMAP		/* The number of partitions */
61 					/* (from dkio.h) */
62 
63 #define	VTOC_SANE	0x600DDEEE	/* Indicates a sane VTOC */
64 #define	V_VERSION	0x01		/* layout version number */
65 #define	V_EXTVERSION	V_VERSION	/* extvtoc layout version number */
66 
67 /*
68  * Partition identification tags
69  */
70 #define	V_UNASSIGNED	0x00		/* unassigned partition */
71 #define	V_BOOT		0x01		/* Boot partition */
72 #define	V_ROOT		0x02		/* Root filesystem */
73 #define	V_SWAP		0x03		/* Swap filesystem */
74 #define	V_USR		0x04		/* Usr filesystem */
75 #define	V_BACKUP	0x05		/* full disk */
76 #define	V_STAND		0x06		/* Stand partition */
77 #define	V_VAR		0x07		/* Var partition */
78 #define	V_HOME		0x08		/* Home partition */
79 #define	V_ALTSCTR	0x09		/* Alternate sector partition */
80 #define	V_CACHE		0x0a		/* Cache (cachefs) partition */
81 #define	V_RESERVED	0x0b		/* SMI reserved data */
82 
83 /*
84  * Partition permission flags
85  */
86 #define	V_UNMNT		0x01		/* Unmountable partition */
87 #define	V_RONLY		0x10		/* Read only */
88 
89 /*
90  * error codes for reading & writing vtoc
91  */
92 #define	VT_ERROR	(-2)		/* errno supplies specific error */
93 #define	VT_EIO		(-3)		/* I/O error accessing vtoc */
94 #define	VT_EINVAL	(-4)		/* illegal value in vtoc or request */
95 #define	VT_ENOTSUP	(-5)		/* VTOC op. not supported */
96 #define	VT_ENOSPC	(-6)		/* requested space not found */
97 #define	VT_EOVERFLOW	(-7)		/* VTOC op. data struct limited */
98 
99 struct partition	{
100 	ushort_t p_tag;			/* ID tag of partition */
101 	ushort_t p_flag;		/* permission flags */
102 	daddr_t	p_start;		/* start sector no of partition */
103 	long	p_size;			/* # of blocks in partition */
104 };
105 
106 struct vtoc {
107 	unsigned long	v_bootinfo[3];	/* info needed by mboot (unsupported) */
108 	unsigned long	v_sanity;	/* to verify vtoc sanity */
109 	unsigned long	v_version;	/* layout version */
110 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
111 	ushort_t	v_sectorsz;	/* sector size in bytes */
112 	ushort_t	v_nparts;	/* number of partitions */
113 	unsigned long	v_reserved[10];	/* free space */
114 	struct partition v_part[V_NUMPAR]; /* partition headers */
115 	time_t	timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
116 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
117 };
118 
119 struct extpartition {
120 	ushort_t p_tag;			/* ID tag of partition */
121 	ushort_t p_flag;		/* permission flags */
122 	ushort_t p_pad[2];
123 	diskaddr_t p_start;		/* start sector no of partition */
124 	diskaddr_t p_size;			/* # of blocks in partition */
125 };
126 
127 
128 struct extvtoc {
129 	uint64_t	v_bootinfo[3];	/* info needed by mboot (unsupported) */
130 	uint64_t	v_sanity;	/* to verify vtoc sanity */
131 	uint64_t	v_version;	/* layout version */
132 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
133 	ushort_t	v_sectorsz;	/* sector size in bytes */
134 	ushort_t	v_nparts;	/* number of partitions */
135 	ushort_t	pad[2];
136 	uint64_t	v_reserved[10];
137 	struct extpartition v_part[V_NUMPAR]; /* partition headers */
138 	uint64_t timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
139 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
140 };
141 
142 #ifdef _KERNEL
143 #define	extvtoctovtoc(extv, v)						\
144 	{								\
145 	int i;								\
146 	v.v_bootinfo[0]		= (unsigned long)extv.v_bootinfo[0];	\
147 	v.v_bootinfo[1]		= (unsigned long)extv.v_bootinfo[1];	\
148 	v.v_bootinfo[2]		= (unsigned long)extv.v_bootinfo[2];	\
149 	v.v_sanity		= (unsigned long)extv.v_sanity;		\
150 	v.v_version		= (unsigned long)extv.v_version;	\
151 	bcopy(extv.v_volume, v.v_volume, LEN_DKL_VVOL);			\
152 	v.v_sectorsz		= extv.v_sectorsz;			\
153 	v.v_nparts		= extv.v_nparts;			\
154 	for (i = 0; i < 10; i++)					\
155 		v.v_reserved[i] = (unsigned long)extv.v_reserved[i];	\
156 	for (i = 0; i < V_NUMPAR; i++) {				\
157 		v.v_part[i].p_tag = extv.v_part[i].p_tag;		\
158 		v.v_part[i].p_flag = extv.v_part[i].p_flag;		\
159 		v.v_part[i].p_start = (daddr_t)extv.v_part[i].p_start;	\
160 		v.v_part[i].p_size = (long)extv.v_part[i].p_size;	\
161 		v.timestamp[i] = (time_t)extv.timestamp[i];		\
162 	}								\
163 	bcopy(extv.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII);	\
164 	}
165 
166 #define	vtoctoextvtoc(v, extv)						\
167 	{								\
168 	int i;								\
169 	extv.v_bootinfo[0]	= (uint64_t)v.v_bootinfo[0];		\
170 	extv.v_bootinfo[1]	= (uint64_t)v.v_bootinfo[1];		\
171 	extv.v_bootinfo[2]	= (uint64_t)v.v_bootinfo[2];		\
172 	extv.v_sanity		= (uint64_t)v.v_sanity;			\
173 	extv.v_version		= (uint64_t)v.v_version;		\
174 	bcopy(v.v_volume, extv.v_volume, LEN_DKL_VVOL);			\
175 	extv.v_sectorsz		= v.v_sectorsz;				\
176 	extv.v_nparts		= v.v_nparts;				\
177 	for (i = 0; i < 10; i++)					\
178 		extv.v_reserved[i] = (uint64_t)v.v_reserved[i];		\
179 	for (i = 0; i < V_NUMPAR; i++) {				\
180 		extv.v_part[i].p_tag = v.v_part[i].p_tag;		\
181 		extv.v_part[i].p_flag = v.v_part[i].p_flag;		\
182 		extv.v_part[i].p_start =				\
183 		    (diskaddr_t)(unsigned long)v.v_part[i].p_start;	\
184 		extv.v_part[i].p_size =					\
185 		    (diskaddr_t)(unsigned long)v.v_part[i].p_size;	\
186 		extv.timestamp[i] = (uint64_t)v.timestamp[i];		\
187 	}								\
188 	bcopy(v.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII);	\
189 	}
190 #endif /* _KERNEL */
191 
192 #if defined(_SYSCALL32)
193 struct partition32	{
194 	uint16_t	p_tag;		/* ID tag of partition */
195 	uint16_t	p_flag;		/* permission flags */
196 	daddr32_t	p_start;	/* start sector no of partition */
197 	int32_t		p_size;		/* # of blocks in partition */
198 };
199 
200 struct vtoc32 {
201 	uint32_t	v_bootinfo[3];	/* info needed by mboot (unsupported) */
202 	uint32_t	v_sanity;	/* to verify vtoc sanity */
203 	uint32_t	v_version;	/* layout version */
204 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
205 	uint16_t	v_sectorsz;	/* sector size in bytes */
206 	uint16_t	v_nparts;	/* number of partitions */
207 	uint32_t	v_reserved[10];	/* free space */
208 	struct partition32 v_part[V_NUMPAR]; /* partition headers */
209 	time32_t timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
210 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
211 };
212 
213 #define	vtoc32tovtoc(v32, v)				\
214 	{						\
215 	int i;						\
216 	v.v_bootinfo[0]		= v32.v_bootinfo[0];	\
217 	v.v_bootinfo[1]		= v32.v_bootinfo[1];	\
218 	v.v_bootinfo[2]		= v32.v_bootinfo[2];	\
219 	v.v_sanity		= v32.v_sanity;		\
220 	v.v_version		= v32.v_version;	\
221 	bcopy(v32.v_volume, v.v_volume, LEN_DKL_VVOL);	\
222 	v.v_sectorsz		= v32.v_sectorsz;	\
223 	v.v_nparts		= v32.v_nparts;		\
224 	v.v_version		= v32.v_version;	\
225 	for (i = 0; i < 10; i++)			\
226 		v.v_reserved[i] = v32.v_reserved[i];	\
227 	for (i = 0; i < V_NUMPAR; i++) {		\
228 		v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag;	\
229 		v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag;	\
230 		v.v_part[i].p_start = (unsigned)v32.v_part[i].p_start;	\
231 		v.v_part[i].p_size = (unsigned)v32.v_part[i].p_size;	\
232 	}						\
233 	for (i = 0; i < V_NUMPAR; i++)			\
234 		v.timestamp[i] = (time_t)v32.timestamp[i];		\
235 	bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII);		\
236 	}
237 
238 #define	vtoc32toextvtoc(v32, extv)					\
239 	{								\
240 	int i;								\
241 	extv.v_bootinfo[0]		= v32.v_bootinfo[0];		\
242 	extv.v_bootinfo[1]		= v32.v_bootinfo[1];		\
243 	extv.v_bootinfo[2]		= v32.v_bootinfo[2];		\
244 	extv.v_sanity		= v32.v_sanity;				\
245 	extv.v_version		= v32.v_version;			\
246 	bcopy(v32.v_volume, extv.v_volume, LEN_DKL_VVOL);		\
247 	extv.v_sectorsz		= v32.v_sectorsz;			\
248 	extv.v_nparts		= v32.v_nparts;				\
249 	extv.v_version		= v32.v_version;			\
250 	for (i = 0; i < 10; i++)					\
251 		extv.v_reserved[i] = v32.v_reserved[i];			\
252 	for (i = 0; i < V_NUMPAR; i++) {				\
253 		extv.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag;	\
254 		extv.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag;	\
255 		extv.v_part[i].p_start = (diskaddr_t)v32.v_part[i].p_start; \
256 		extv.v_part[i].p_size = (diskaddr_t)v32.v_part[i].p_size; \
257 		extv.timestamp[i] = (time_t)v32.timestamp[i];		\
258 	}								\
259 	bcopy(v32.v_asciilabel, extv.v_asciilabel, LEN_DKL_ASCII);	\
260 	}
261 
262 
263 #define	vtoctovtoc32(v, v32)				\
264 	{						\
265 	int i;						\
266 	v32.v_bootinfo[0]	= v.v_bootinfo[0];	\
267 	v32.v_bootinfo[1]	= v.v_bootinfo[1];	\
268 	v32.v_bootinfo[2]	= v.v_bootinfo[2];	\
269 	v32.v_sanity		= v.v_sanity;		\
270 	v32.v_version		= v.v_version;		\
271 	bcopy(v.v_volume, v32.v_volume, LEN_DKL_VVOL);	\
272 	v32.v_sectorsz		= v.v_sectorsz;		\
273 	v32.v_nparts		= v.v_nparts;		\
274 	v32.v_version		= v.v_version;		\
275 	for (i = 0; i < 10; i++)			\
276 		v32.v_reserved[i] = v.v_reserved[i];	\
277 	for (i = 0; i < V_NUMPAR; i++) {		\
278 		v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag;	\
279 		v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag;	\
280 		v32.v_part[i].p_start = (unsigned)v.v_part[i].p_start;	\
281 		v32.v_part[i].p_size = (unsigned)v.v_part[i].p_size;	\
282 	}						\
283 	for (i = 0; i < V_NUMPAR; i++) {		\
284 		if (v.timestamp[i] > TIME32_MAX)	\
285 			v32.timestamp[i] = TIME32_MAX;	\
286 		else 					\
287 			v32.timestamp[i] = (time32_t)v.timestamp[i];	\
288 	}						\
289 	bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII);		\
290 	}
291 
292 #define	extvtoctovtoc32(extv, v32)				\
293 	{						\
294 	int i;						\
295 	v32.v_bootinfo[0]	= extv.v_bootinfo[0];	\
296 	v32.v_bootinfo[1]	= extv.v_bootinfo[1];	\
297 	v32.v_bootinfo[2]	= extv.v_bootinfo[2];	\
298 	v32.v_sanity		= extv.v_sanity;		\
299 	v32.v_version		= extv.v_version;		\
300 	bcopy(extv.v_volume, v32.v_volume, LEN_DKL_VVOL);	\
301 	v32.v_sectorsz		= extv.v_sectorsz;		\
302 	v32.v_nparts		= extv.v_nparts;		\
303 	v32.v_version		= extv.v_version;		\
304 	for (i = 0; i < 10; i++)			\
305 		v32.v_reserved[i] = extv.v_reserved[i];	\
306 	for (i = 0; i < V_NUMPAR; i++) {		\
307 		v32.v_part[i].p_tag = (ushort_t)extv.v_part[i].p_tag;	\
308 		v32.v_part[i].p_flag = (ushort_t)extv.v_part[i].p_flag;	\
309 		v32.v_part[i].p_start = (unsigned)extv.v_part[i].p_start; \
310 		v32.v_part[i].p_size = (unsigned)extv.v_part[i].p_size;	\
311 	}						\
312 	for (i = 0; i < V_NUMPAR; i++) {		\
313 		if (extv.timestamp[i] > TIME32_MAX)	\
314 			v32.timestamp[i] = TIME32_MAX;	\
315 		else 					\
316 			v32.timestamp[i] = (time32_t)extv.timestamp[i];	\
317 	}						\
318 	bcopy(extv.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII);	\
319 	}
320 
321 
322 #endif /* _SYSCALL32 */
323 
324 /*
325  * These defines are the mode parameter for the checksum routines.
326  */
327 #define	CK_CHECKSUM	0	/* check checksum */
328 #define	CK_MAKESUM	1	/* generate checksum */
329 
330 #if defined(__STDC__)
331 
332 extern	int	read_vtoc(int, struct vtoc *);
333 extern	int	write_vtoc(int, struct vtoc *);
334 extern	int	read_extvtoc(int, struct extvtoc *);
335 extern	int	write_extvtoc(int, struct extvtoc *);
336 
337 #else
338 
339 extern	int	read_vtoc();
340 extern	int	write_vtoc();
341 extern	int	read_extvtoc();
342 extern	int	write_extvtoc();
343 
344 #endif 	/* __STDC__ */
345 
346 #ifdef	__cplusplus
347 }
348 #endif
349 
350 #endif	/* _SYS_VTOC_H */
351