xref: /titanic_44/usr/src/uts/common/sys/vtoc.h (revision 4a634bb80136cc001d14ab96addd9915105e5223)
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  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 
31 #ifndef _SYS_VTOC_H
32 #define	_SYS_VTOC_H
33 
34 #pragma ident	"%Z%%M%	%I%	%E% SMI"
35 
36 #include <sys/dklabel.h>
37 
38 #ifdef	__cplusplus
39 extern "C" {
40 #endif
41 
42 /*
43  *	Note:  the VTOC is not implemented fully, nor in the manner
44  *	that AT&T implements it.  AT&T puts the vtoc structure
45  *	into a sector, usually the second sector (pdsector is first).
46  *
47  *	Sun incorporates the tag, flag, version, and volume vtoc fields into
48  *	its Disk Label, which already has some vtoc-equivalent fields.
49  *	Upon reading the vtoc with read_vtoc(), the following exceptions
50  *	occur:
51  *		v_bootinfo [all]	returned as zero
52  *		v_sanity		returned as VTOC_SANE
53  *						if Disk Label was sane
54  *		v_sectorsz		returned as 512
55  *		v_reserved [all]	retunred as zero
56  *		timestamp [all]		returned as zero
57  *
58  *	See  dklabel.h, read_vtoc(), and write_vtoc().
59  */
60 
61 #define	V_NUMPAR 	NDKMAP		/* The number of partitions */
62 					/* (from dkio.h) */
63 
64 #define	VTOC_SANE	0x600DDEEE	/* Indicates a sane VTOC */
65 #define	V_VERSION	0x01		/* 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 
98 struct partition	{
99 	ushort_t p_tag;			/* ID tag of partition */
100 	ushort_t p_flag;			/* permision flags */
101 	daddr_t	p_start;		/* start sector no of partition */
102 	long	p_size;			/* # of blocks in partition */
103 };
104 
105 struct vtoc {
106 	unsigned long	v_bootinfo[3];	/* info needed by mboot (unsupported) */
107 	unsigned long	v_sanity;	/* to verify vtoc sanity */
108 	unsigned long	v_version;	/* layout version */
109 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
110 	ushort_t	v_sectorsz;	/* sector size in bytes */
111 	ushort_t	v_nparts;	/* number of partitions */
112 	unsigned long	v_reserved[10];	/* free space */
113 	struct partition v_part[V_NUMPAR]; /* partition headers */
114 	time_t	timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
115 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
116 };
117 
118 #if defined(_SYSCALL32)
119 struct partition32	{
120 	uint16_t	p_tag;		/* ID tag of partition */
121 	uint16_t	p_flag;		/* permision flags */
122 	daddr32_t	p_start;	/* start sector no of partition */
123 	int32_t		p_size;		/* # of blocks in partition */
124 };
125 
126 struct vtoc32 {
127 	uint32_t	v_bootinfo[3];	/* info needed by mboot (unsupported) */
128 	uint32_t	v_sanity;	/* to verify vtoc sanity */
129 	uint32_t	v_version;	/* layout version */
130 	char	v_volume[LEN_DKL_VVOL];	/* volume name */
131 	uint16_t	v_sectorsz;	/* sector size in bytes */
132 	uint16_t	v_nparts;	/* number of partitions */
133 	uint32_t	v_reserved[10];	/* free space */
134 	struct partition32 v_part[V_NUMPAR]; /* partition headers */
135 	time32_t timestamp[V_NUMPAR];	/* partition timestamp (unsupported) */
136 	char	v_asciilabel[LEN_DKL_ASCII];	/* for compatibility */
137 };
138 
139 #define	vtoc32tovtoc(v32, v)				\
140 	{						\
141 	int i;						\
142 	v.v_bootinfo[0]		= v32.v_bootinfo[0];	\
143 	v.v_bootinfo[1]		= v32.v_bootinfo[1];	\
144 	v.v_bootinfo[2]		= v32.v_bootinfo[2];	\
145 	v.v_sanity		= v32.v_sanity;		\
146 	v.v_version		= v32.v_version;	\
147 	bcopy(v32.v_volume, v.v_volume, LEN_DKL_VVOL);	\
148 	v.v_sectorsz		= v32.v_sectorsz;	\
149 	v.v_nparts		= v32.v_nparts;		\
150 	v.v_version		= v32.v_version;	\
151 	for (i = 0; i < 10; i++)			\
152 		v.v_reserved[i] = v32.v_reserved[i];	\
153 	for (i = 0; i < V_NUMPAR; i++) {		\
154 		v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag;	\
155 		v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag;	\
156 		v.v_part[i].p_start = (daddr_t)v32.v_part[i].p_start;	\
157 		v.v_part[i].p_size = (long)v32.v_part[i].p_size;	\
158 	}						\
159 	for (i = 0; i < V_NUMPAR; i++)			\
160 		v.timestamp[i] = (time_t)v32.timestamp[i];		\
161 	bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII);		\
162 	}
163 
164 #define	vtoctovtoc32(v, v32)				\
165 	{						\
166 	int i;						\
167 	v32.v_bootinfo[0]	= v.v_bootinfo[0];	\
168 	v32.v_bootinfo[1]	= v.v_bootinfo[1];	\
169 	v32.v_bootinfo[2]	= v.v_bootinfo[2];	\
170 	v32.v_sanity		= v.v_sanity;		\
171 	v32.v_version		= v.v_version;		\
172 	bcopy(v.v_volume, v32.v_volume, LEN_DKL_VVOL);	\
173 	v32.v_sectorsz		= v.v_sectorsz;		\
174 	v32.v_nparts		= v.v_nparts;		\
175 	v32.v_version		= v.v_version;		\
176 	for (i = 0; i < 10; i++)			\
177 		v32.v_reserved[i] = v.v_reserved[i];	\
178 	for (i = 0; i < V_NUMPAR; i++) {		\
179 		v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag;	\
180 		v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag;	\
181 		v32.v_part[i].p_start = (daddr32_t)v.v_part[i].p_start;	\
182 		v32.v_part[i].p_size = (int32_t)v.v_part[i].p_size;	\
183 	}						\
184 	for (i = 0; i < V_NUMPAR; i++) {		\
185 		if (v.timestamp[i] > TIME32_MAX)	\
186 			v32.timestamp[i] = TIME32_MAX;	\
187 		else 					\
188 			v32.timestamp[i] = (time32_t)v.timestamp[i];	\
189 	}						\
190 	bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII);		\
191 	}
192 
193 #endif /* _SYSCALL32 */
194 
195 /*
196  * These defines are the mode parameter for the checksum routines.
197  */
198 #define	CK_CHECKSUM	0	/* check checksum */
199 #define	CK_MAKESUM	1	/* generate checksum */
200 
201 #if defined(__STDC__)
202 
203 extern	int	read_vtoc(int, struct vtoc *);
204 extern	int	write_vtoc(int, struct vtoc *);
205 
206 #else
207 
208 extern	int	read_vtoc();
209 extern	int	write_vtoc();
210 
211 #endif 	/* __STDC__ */
212 
213 #ifdef	__cplusplus
214 }
215 #endif
216 
217 #endif	/* _SYS_VTOC_H */
218