17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*af007057Syl194034 * Common Development and Distribution License (the "License"). 6*af007057Syl194034 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*af007057Syl194034 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 287c478bd9Sstevel@tonic-gate /* All Rights Reserved */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate 317c478bd9Sstevel@tonic-gate #ifndef _SYS_VTOC_H 327c478bd9Sstevel@tonic-gate #define _SYS_VTOC_H 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #include <sys/dklabel.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #ifdef __cplusplus 397c478bd9Sstevel@tonic-gate extern "C" { 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * Note: the VTOC is not implemented fully, nor in the manner 447c478bd9Sstevel@tonic-gate * that AT&T implements it. AT&T puts the vtoc structure 457c478bd9Sstevel@tonic-gate * into a sector, usually the second sector (pdsector is first). 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * Sun incorporates the tag, flag, version, and volume vtoc fields into 487c478bd9Sstevel@tonic-gate * its Disk Label, which already has some vtoc-equivalent fields. 497c478bd9Sstevel@tonic-gate * Upon reading the vtoc with read_vtoc(), the following exceptions 507c478bd9Sstevel@tonic-gate * occur: 517c478bd9Sstevel@tonic-gate * v_bootinfo [all] returned as zero 527c478bd9Sstevel@tonic-gate * v_sanity returned as VTOC_SANE 537c478bd9Sstevel@tonic-gate * if Disk Label was sane 547c478bd9Sstevel@tonic-gate * v_sectorsz returned as 512 557c478bd9Sstevel@tonic-gate * v_reserved [all] retunred as zero 567c478bd9Sstevel@tonic-gate * timestamp [all] returned as zero 577c478bd9Sstevel@tonic-gate * 587c478bd9Sstevel@tonic-gate * See dklabel.h, read_vtoc(), and write_vtoc(). 597c478bd9Sstevel@tonic-gate */ 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate #define V_NUMPAR NDKMAP /* The number of partitions */ 627c478bd9Sstevel@tonic-gate /* (from dkio.h) */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #define VTOC_SANE 0x600DDEEE /* Indicates a sane VTOC */ 657c478bd9Sstevel@tonic-gate #define V_VERSION 0x01 /* layout version number */ 667c478bd9Sstevel@tonic-gate 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * Partition identification tags 697c478bd9Sstevel@tonic-gate */ 707c478bd9Sstevel@tonic-gate #define V_UNASSIGNED 0x00 /* unassigned partition */ 717c478bd9Sstevel@tonic-gate #define V_BOOT 0x01 /* Boot partition */ 727c478bd9Sstevel@tonic-gate #define V_ROOT 0x02 /* Root filesystem */ 737c478bd9Sstevel@tonic-gate #define V_SWAP 0x03 /* Swap filesystem */ 747c478bd9Sstevel@tonic-gate #define V_USR 0x04 /* Usr filesystem */ 757c478bd9Sstevel@tonic-gate #define V_BACKUP 0x05 /* full disk */ 767c478bd9Sstevel@tonic-gate #define V_STAND 0x06 /* Stand partition */ 777c478bd9Sstevel@tonic-gate #define V_VAR 0x07 /* Var partition */ 787c478bd9Sstevel@tonic-gate #define V_HOME 0x08 /* Home partition */ 797c478bd9Sstevel@tonic-gate #define V_ALTSCTR 0x09 /* Alternate sector partition */ 807c478bd9Sstevel@tonic-gate #define V_CACHE 0x0a /* Cache (cachefs) partition */ 817c478bd9Sstevel@tonic-gate #define V_RESERVED 0x0b /* SMI reserved data */ 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * Partition permission flags 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate #define V_UNMNT 0x01 /* Unmountable partition */ 877c478bd9Sstevel@tonic-gate #define V_RONLY 0x10 /* Read only */ 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * error codes for reading & writing vtoc 917c478bd9Sstevel@tonic-gate */ 927c478bd9Sstevel@tonic-gate #define VT_ERROR (-2) /* errno supplies specific error */ 937c478bd9Sstevel@tonic-gate #define VT_EIO (-3) /* I/O error accessing vtoc */ 947c478bd9Sstevel@tonic-gate #define VT_EINVAL (-4) /* illegal value in vtoc or request */ 957c478bd9Sstevel@tonic-gate #define VT_ENOTSUP (-5) /* VTOC op. not supported */ 96*af007057Syl194034 #define VT_ENOSPC (-6) /* requested space not found */ 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate struct partition { 997c478bd9Sstevel@tonic-gate ushort_t p_tag; /* ID tag of partition */ 1007c478bd9Sstevel@tonic-gate ushort_t p_flag; /* permision flags */ 1017c478bd9Sstevel@tonic-gate daddr_t p_start; /* start sector no of partition */ 1027c478bd9Sstevel@tonic-gate long p_size; /* # of blocks in partition */ 1037c478bd9Sstevel@tonic-gate }; 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate struct vtoc { 1067c478bd9Sstevel@tonic-gate unsigned long v_bootinfo[3]; /* info needed by mboot (unsupported) */ 1077c478bd9Sstevel@tonic-gate unsigned long v_sanity; /* to verify vtoc sanity */ 1087c478bd9Sstevel@tonic-gate unsigned long v_version; /* layout version */ 1097c478bd9Sstevel@tonic-gate char v_volume[LEN_DKL_VVOL]; /* volume name */ 1107c478bd9Sstevel@tonic-gate ushort_t v_sectorsz; /* sector size in bytes */ 1117c478bd9Sstevel@tonic-gate ushort_t v_nparts; /* number of partitions */ 1127c478bd9Sstevel@tonic-gate unsigned long v_reserved[10]; /* free space */ 1137c478bd9Sstevel@tonic-gate struct partition v_part[V_NUMPAR]; /* partition headers */ 1147c478bd9Sstevel@tonic-gate time_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */ 1157c478bd9Sstevel@tonic-gate char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */ 1167c478bd9Sstevel@tonic-gate }; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate #if defined(_SYSCALL32) 1197c478bd9Sstevel@tonic-gate struct partition32 { 1207c478bd9Sstevel@tonic-gate uint16_t p_tag; /* ID tag of partition */ 1217c478bd9Sstevel@tonic-gate uint16_t p_flag; /* permision flags */ 1227c478bd9Sstevel@tonic-gate daddr32_t p_start; /* start sector no of partition */ 1237c478bd9Sstevel@tonic-gate int32_t p_size; /* # of blocks in partition */ 1247c478bd9Sstevel@tonic-gate }; 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate struct vtoc32 { 1277c478bd9Sstevel@tonic-gate uint32_t v_bootinfo[3]; /* info needed by mboot (unsupported) */ 1287c478bd9Sstevel@tonic-gate uint32_t v_sanity; /* to verify vtoc sanity */ 1297c478bd9Sstevel@tonic-gate uint32_t v_version; /* layout version */ 1307c478bd9Sstevel@tonic-gate char v_volume[LEN_DKL_VVOL]; /* volume name */ 1317c478bd9Sstevel@tonic-gate uint16_t v_sectorsz; /* sector size in bytes */ 1327c478bd9Sstevel@tonic-gate uint16_t v_nparts; /* number of partitions */ 1337c478bd9Sstevel@tonic-gate uint32_t v_reserved[10]; /* free space */ 1347c478bd9Sstevel@tonic-gate struct partition32 v_part[V_NUMPAR]; /* partition headers */ 1357c478bd9Sstevel@tonic-gate time32_t timestamp[V_NUMPAR]; /* partition timestamp (unsupported) */ 1367c478bd9Sstevel@tonic-gate char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */ 1377c478bd9Sstevel@tonic-gate }; 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate #define vtoc32tovtoc(v32, v) \ 1407c478bd9Sstevel@tonic-gate { \ 1417c478bd9Sstevel@tonic-gate int i; \ 1427c478bd9Sstevel@tonic-gate v.v_bootinfo[0] = v32.v_bootinfo[0]; \ 1437c478bd9Sstevel@tonic-gate v.v_bootinfo[1] = v32.v_bootinfo[1]; \ 1447c478bd9Sstevel@tonic-gate v.v_bootinfo[2] = v32.v_bootinfo[2]; \ 1457c478bd9Sstevel@tonic-gate v.v_sanity = v32.v_sanity; \ 1467c478bd9Sstevel@tonic-gate v.v_version = v32.v_version; \ 1477c478bd9Sstevel@tonic-gate bcopy(v32.v_volume, v.v_volume, LEN_DKL_VVOL); \ 1487c478bd9Sstevel@tonic-gate v.v_sectorsz = v32.v_sectorsz; \ 1497c478bd9Sstevel@tonic-gate v.v_nparts = v32.v_nparts; \ 1507c478bd9Sstevel@tonic-gate v.v_version = v32.v_version; \ 1517c478bd9Sstevel@tonic-gate for (i = 0; i < 10; i++) \ 1527c478bd9Sstevel@tonic-gate v.v_reserved[i] = v32.v_reserved[i]; \ 1537c478bd9Sstevel@tonic-gate for (i = 0; i < V_NUMPAR; i++) { \ 1547c478bd9Sstevel@tonic-gate v.v_part[i].p_tag = (ushort_t)v32.v_part[i].p_tag; \ 1557c478bd9Sstevel@tonic-gate v.v_part[i].p_flag = (ushort_t)v32.v_part[i].p_flag; \ 1567c478bd9Sstevel@tonic-gate v.v_part[i].p_start = (daddr_t)v32.v_part[i].p_start; \ 1577c478bd9Sstevel@tonic-gate v.v_part[i].p_size = (long)v32.v_part[i].p_size; \ 1587c478bd9Sstevel@tonic-gate } \ 1597c478bd9Sstevel@tonic-gate for (i = 0; i < V_NUMPAR; i++) \ 1607c478bd9Sstevel@tonic-gate v.timestamp[i] = (time_t)v32.timestamp[i]; \ 1617c478bd9Sstevel@tonic-gate bcopy(v32.v_asciilabel, v.v_asciilabel, LEN_DKL_ASCII); \ 1627c478bd9Sstevel@tonic-gate } 1637c478bd9Sstevel@tonic-gate 1647c478bd9Sstevel@tonic-gate #define vtoctovtoc32(v, v32) \ 1657c478bd9Sstevel@tonic-gate { \ 1667c478bd9Sstevel@tonic-gate int i; \ 1677c478bd9Sstevel@tonic-gate v32.v_bootinfo[0] = v.v_bootinfo[0]; \ 1687c478bd9Sstevel@tonic-gate v32.v_bootinfo[1] = v.v_bootinfo[1]; \ 1697c478bd9Sstevel@tonic-gate v32.v_bootinfo[2] = v.v_bootinfo[2]; \ 1707c478bd9Sstevel@tonic-gate v32.v_sanity = v.v_sanity; \ 1717c478bd9Sstevel@tonic-gate v32.v_version = v.v_version; \ 1727c478bd9Sstevel@tonic-gate bcopy(v.v_volume, v32.v_volume, LEN_DKL_VVOL); \ 1737c478bd9Sstevel@tonic-gate v32.v_sectorsz = v.v_sectorsz; \ 1747c478bd9Sstevel@tonic-gate v32.v_nparts = v.v_nparts; \ 1757c478bd9Sstevel@tonic-gate v32.v_version = v.v_version; \ 1767c478bd9Sstevel@tonic-gate for (i = 0; i < 10; i++) \ 1777c478bd9Sstevel@tonic-gate v32.v_reserved[i] = v.v_reserved[i]; \ 1787c478bd9Sstevel@tonic-gate for (i = 0; i < V_NUMPAR; i++) { \ 1797c478bd9Sstevel@tonic-gate v32.v_part[i].p_tag = (ushort_t)v.v_part[i].p_tag; \ 1807c478bd9Sstevel@tonic-gate v32.v_part[i].p_flag = (ushort_t)v.v_part[i].p_flag; \ 1817c478bd9Sstevel@tonic-gate v32.v_part[i].p_start = (daddr32_t)v.v_part[i].p_start; \ 1827c478bd9Sstevel@tonic-gate v32.v_part[i].p_size = (int32_t)v.v_part[i].p_size; \ 1837c478bd9Sstevel@tonic-gate } \ 1847c478bd9Sstevel@tonic-gate for (i = 0; i < V_NUMPAR; i++) { \ 1857c478bd9Sstevel@tonic-gate if (v.timestamp[i] > TIME32_MAX) \ 1867c478bd9Sstevel@tonic-gate v32.timestamp[i] = TIME32_MAX; \ 1877c478bd9Sstevel@tonic-gate else \ 1887c478bd9Sstevel@tonic-gate v32.timestamp[i] = (time32_t)v.timestamp[i]; \ 1897c478bd9Sstevel@tonic-gate } \ 1907c478bd9Sstevel@tonic-gate bcopy(v.v_asciilabel, v32.v_asciilabel, LEN_DKL_ASCII); \ 1917c478bd9Sstevel@tonic-gate } 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate #endif /* _SYSCALL32 */ 1947c478bd9Sstevel@tonic-gate 1957c478bd9Sstevel@tonic-gate /* 1967c478bd9Sstevel@tonic-gate * These defines are the mode parameter for the checksum routines. 1977c478bd9Sstevel@tonic-gate */ 1987c478bd9Sstevel@tonic-gate #define CK_CHECKSUM 0 /* check checksum */ 1997c478bd9Sstevel@tonic-gate #define CK_MAKESUM 1 /* generate checksum */ 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #if defined(__STDC__) 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate extern int read_vtoc(int, struct vtoc *); 2047c478bd9Sstevel@tonic-gate extern int write_vtoc(int, struct vtoc *); 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate #else 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate extern int read_vtoc(); 2097c478bd9Sstevel@tonic-gate extern int write_vtoc(); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate #endif /* __STDC__ */ 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate #endif 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate #endif /* _SYS_VTOC_H */ 218