1*199767f8SToomas Soome /*- 2*199767f8SToomas Soome * Copyright (c) 2008 Marcel Moolenaar 3*199767f8SToomas Soome * All rights reserved. 4*199767f8SToomas Soome * 5*199767f8SToomas Soome * Redistribution and use in source and binary forms, with or without 6*199767f8SToomas Soome * modification, are permitted provided that the following conditions 7*199767f8SToomas Soome * are met: 8*199767f8SToomas Soome * 9*199767f8SToomas Soome * 1. Redistributions of source code must retain the above copyright 10*199767f8SToomas Soome * notice, this list of conditions and the following disclaimer. 11*199767f8SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 12*199767f8SToomas Soome * notice, this list of conditions and the following disclaimer in the 13*199767f8SToomas Soome * documentation and/or other materials provided with the distribution. 14*199767f8SToomas Soome * 15*199767f8SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16*199767f8SToomas Soome * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17*199767f8SToomas Soome * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18*199767f8SToomas Soome * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19*199767f8SToomas Soome * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20*199767f8SToomas Soome * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21*199767f8SToomas Soome * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22*199767f8SToomas Soome * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23*199767f8SToomas Soome * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24*199767f8SToomas Soome * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25*199767f8SToomas Soome * 26*199767f8SToomas Soome * $FreeBSD$ 27*199767f8SToomas Soome */ 28*199767f8SToomas Soome 29*199767f8SToomas Soome #ifndef _SYS_VTOC_H_ 30*199767f8SToomas Soome #define _SYS_VTOC_H_ 31*199767f8SToomas Soome 32*199767f8SToomas Soome #define VTOC_TAG_UNASSIGNED 0x00 33*199767f8SToomas Soome #define VTOC_TAG_BOOT 0x01 34*199767f8SToomas Soome #define VTOC_TAG_ROOT 0x02 35*199767f8SToomas Soome #define VTOC_TAG_SWAP 0x03 36*199767f8SToomas Soome #define VTOC_TAG_USR 0x04 37*199767f8SToomas Soome #define VTOC_TAG_BACKUP 0x05 /* "c" partition */ 38*199767f8SToomas Soome #define VTOC_TAG_STAND 0x06 39*199767f8SToomas Soome #define VTOC_TAG_VAR 0x07 40*199767f8SToomas Soome #define VTOC_TAG_HOME 0x08 41*199767f8SToomas Soome #define VTOC_TAG_ALTSCTR 0x09 /* alternate sector partition */ 42*199767f8SToomas Soome #define VTOC_TAG_CACHE 0x0a /* Solaris cachefs partition */ 43*199767f8SToomas Soome #define VTOC_TAG_VXVM_PUB 0x0e /* VxVM public region */ 44*199767f8SToomas Soome #define VTOC_TAG_VXVM_PRIV 0x0f /* VxVM private region */ 45*199767f8SToomas Soome 46*199767f8SToomas Soome /* NetBSD/mips defines this */ 47*199767f8SToomas Soome #define VTOC_TAG_NETBSD_FFS 0xff 48*199767f8SToomas Soome 49*199767f8SToomas Soome /* FreeBSD tags: the high byte equals ELFOSABI_FREEBSD */ 50*199767f8SToomas Soome #define VTOC_TAG_FREEBSD_SWAP 0x0901 51*199767f8SToomas Soome #define VTOC_TAG_FREEBSD_UFS 0x0902 52*199767f8SToomas Soome #define VTOC_TAG_FREEBSD_VINUM 0x0903 53*199767f8SToomas Soome #define VTOC_TAG_FREEBSD_ZFS 0x0904 54*199767f8SToomas Soome 55*199767f8SToomas Soome #define VTOC_FLAG_UNMNT 0x01 /* unmountable partition */ 56*199767f8SToomas Soome #define VTOC_FLAG_RDONLY 0x10 /* partition is read/only */ 57*199767f8SToomas Soome 58*199767f8SToomas Soome #define VTOC_ASCII_LEN 128 59*199767f8SToomas Soome #define VTOC_BOOTSIZE 8192 /* 16 sectors */ 60*199767f8SToomas Soome #define VTOC_MAGIC 0xdabe 61*199767f8SToomas Soome #define VTOC_RAW_PART 2 62*199767f8SToomas Soome #define VTOC_SANITY 0x600ddeee 63*199767f8SToomas Soome #define VTOC_VERSION 1 64*199767f8SToomas Soome #define VTOC_VOLUME_LEN 8 65*199767f8SToomas Soome 66*199767f8SToomas Soome #define VTOC8_NPARTS 8 67*199767f8SToomas Soome 68*199767f8SToomas Soome struct vtoc8 { 69*199767f8SToomas Soome char ascii[VTOC_ASCII_LEN]; 70*199767f8SToomas Soome uint32_t version; 71*199767f8SToomas Soome char volume[VTOC_VOLUME_LEN]; 72*199767f8SToomas Soome uint16_t nparts; 73*199767f8SToomas Soome struct { 74*199767f8SToomas Soome uint16_t tag; 75*199767f8SToomas Soome uint16_t flag; 76*199767f8SToomas Soome } part[VTOC8_NPARTS] __packed; 77*199767f8SToomas Soome uint16_t __alignment; 78*199767f8SToomas Soome uint32_t bootinfo[3]; 79*199767f8SToomas Soome uint32_t sanity; 80*199767f8SToomas Soome uint32_t reserved[10]; 81*199767f8SToomas Soome uint32_t timestamp[VTOC8_NPARTS]; 82*199767f8SToomas Soome uint16_t wskip; 83*199767f8SToomas Soome uint16_t rskip; 84*199767f8SToomas Soome char padding[152]; 85*199767f8SToomas Soome uint16_t rpm; 86*199767f8SToomas Soome uint16_t physcyls; 87*199767f8SToomas Soome uint16_t sparesecs; 88*199767f8SToomas Soome uint16_t spare1[2]; 89*199767f8SToomas Soome uint16_t interleave; 90*199767f8SToomas Soome uint16_t ncyls; 91*199767f8SToomas Soome uint16_t altcyls; 92*199767f8SToomas Soome uint16_t nheads; 93*199767f8SToomas Soome uint16_t nsecs; 94*199767f8SToomas Soome uint16_t spare2[2]; 95*199767f8SToomas Soome struct { 96*199767f8SToomas Soome uint32_t cyl; 97*199767f8SToomas Soome uint32_t nblks; 98*199767f8SToomas Soome } map[VTOC8_NPARTS]; 99*199767f8SToomas Soome uint16_t magic; 100*199767f8SToomas Soome uint16_t cksum; 101*199767f8SToomas Soome } __packed; 102*199767f8SToomas Soome 103*199767f8SToomas Soome #ifdef CTASSERT 104*199767f8SToomas Soome CTASSERT(sizeof(struct vtoc8) == 512); 105*199767f8SToomas Soome #endif 106*199767f8SToomas Soome 107*199767f8SToomas Soome #define NDKMAP 16 /* # of logical partitions */ 108*199767f8SToomas Soome #define DK_LABEL_LOC 1 /* location of disk label */ 109*199767f8SToomas Soome #define LEN_DKL_ASCII 128 /* length of dkl_asciilabel */ 110*199767f8SToomas Soome #define LEN_DKL_VVOL 8 /* length of v_volume */ 111*199767f8SToomas Soome #define DK_LABEL_SIZE 512 /* size of disk label */ 112*199767f8SToomas Soome #define DK_MAX_BLOCKS 0x7fffffff /* max # of blocks handled */ 113*199767f8SToomas Soome 114*199767f8SToomas Soome struct dk_vtoc { 115*199767f8SToomas Soome uint32_t v_bootinfo[3]; /* info needed by mboot (unsupported) */ 116*199767f8SToomas Soome uint32_t v_sanity; /* to verify vtoc sanity */ 117*199767f8SToomas Soome uint32_t v_version; /* layout version */ 118*199767f8SToomas Soome char v_volume[LEN_DKL_VVOL]; /* volume name */ 119*199767f8SToomas Soome uint16_t v_sectorsz; /* sector size in bytes */ 120*199767f8SToomas Soome uint16_t v_nparts; /* number of partitions */ 121*199767f8SToomas Soome uint32_t v_reserved[10]; /* free space */ 122*199767f8SToomas Soome struct { 123*199767f8SToomas Soome uint16_t p_tag; /* ID tag of partition */ 124*199767f8SToomas Soome uint16_t p_flag; /* permission flags */ 125*199767f8SToomas Soome uint32_t p_start;/* start sector no of partition */ 126*199767f8SToomas Soome int32_t p_size; /* # of blocks in partition */ 127*199767f8SToomas Soome } v_part[NDKMAP]; /* partition headers */ 128*199767f8SToomas Soome uint32_t timestamp[NDKMAP]; /* partition timestamp (unsupported) */ 129*199767f8SToomas Soome char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */ 130*199767f8SToomas Soome }; 131*199767f8SToomas Soome 132*199767f8SToomas Soome #define LEN_DKL_PAD (DK_LABEL_SIZE - \ 133*199767f8SToomas Soome ((sizeof (struct dk_vtoc) + \ 134*199767f8SToomas Soome (4 * sizeof (uint32_t)) + \ 135*199767f8SToomas Soome (12 * sizeof (uint16_t)) + \ 136*199767f8SToomas Soome (2 * (sizeof (uint16_t)))))) 137*199767f8SToomas Soome 138*199767f8SToomas Soome struct dk_label { 139*199767f8SToomas Soome struct dk_vtoc dkl_vtoc; /* vtoc inclusions from AT&T SVr4 */ 140*199767f8SToomas Soome uint32_t dkl_pcyl; /* # of physical cylinders */ 141*199767f8SToomas Soome uint32_t dkl_ncyl; /* # of data cylinders */ 142*199767f8SToomas Soome uint16_t dkl_acyl; /* # of alternate cylinders */ 143*199767f8SToomas Soome uint16_t dkl_bcyl; /* cyl offset (for fixed head area) */ 144*199767f8SToomas Soome uint32_t dkl_nhead; /* # of heads */ 145*199767f8SToomas Soome uint32_t dkl_nsect; /* # of data sectors per track */ 146*199767f8SToomas Soome uint16_t dkl_intrlv; /* interleave factor */ 147*199767f8SToomas Soome uint16_t dkl_skew; /* skew factor */ 148*199767f8SToomas Soome uint16_t dkl_apc; /* alternates per cyl (SCSI only) */ 149*199767f8SToomas Soome uint16_t dkl_rpm; /* revolutions per minute */ 150*199767f8SToomas Soome uint16_t dkl_write_reinstruct; /* # sectors to skip, writes */ 151*199767f8SToomas Soome uint16_t dkl_read_reinstruct; /* # sectors to skip, reads */ 152*199767f8SToomas Soome uint16_t dkl_extra[4]; /* for compatible expansion */ 153*199767f8SToomas Soome char dkl_pad[LEN_DKL_PAD]; /* unused part of 512 bytes */ 154*199767f8SToomas Soome uint16_t dkl_magic; /* identifies this label format */ 155*199767f8SToomas Soome uint16_t dkl_cksum; /* xor checksum of sector */ 156*199767f8SToomas Soome }; 157*199767f8SToomas Soome 158*199767f8SToomas Soome #ifdef CTASSERT 159*199767f8SToomas Soome CTASSERT(sizeof(struct dk_label) == 512); 160*199767f8SToomas Soome #endif 161*199767f8SToomas Soome 162*199767f8SToomas Soome #endif /* _SYS_VTOC_H_ */ 163