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