199767f8919635c4928607450d9e0abb932109ceToomas Soome/*-
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Copyright (c) 2008 Marcel Moolenaar
199767f8919635c4928607450d9e0abb932109ceToomas Soome * All rights reserved.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * Redistribution and use in source and binary forms, with or without
199767f8919635c4928607450d9e0abb932109ceToomas Soome * modification, are permitted provided that the following conditions
199767f8919635c4928607450d9e0abb932109ceToomas Soome * are met:
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 1. Redistributions of source code must retain the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
199767f8919635c4928607450d9e0abb932109ceToomas Soome * notice, this list of conditions and the following disclaimer in the
199767f8919635c4928607450d9e0abb932109ceToomas Soome * documentation and/or other materials provided with the distribution.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
199767f8919635c4928607450d9e0abb932109ceToomas Soome * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
199767f8919635c4928607450d9e0abb932109ceToomas Soome * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
199767f8919635c4928607450d9e0abb932109ceToomas Soome * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
199767f8919635c4928607450d9e0abb932109ceToomas Soome * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
199767f8919635c4928607450d9e0abb932109ceToomas Soome * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
199767f8919635c4928607450d9e0abb932109ceToomas Soome *
199767f8919635c4928607450d9e0abb932109ceToomas Soome * $FreeBSD$
199767f8919635c4928607450d9e0abb932109ceToomas Soome */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifndef _SYS_VTOC_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define _SYS_VTOC_H_
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_UNASSIGNED 0x00
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_BOOT 0x01
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_ROOT 0x02
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_SWAP 0x03
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_USR 0x04
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_BACKUP 0x05 /* "c" partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_STAND 0x06
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_VAR 0x07
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_HOME 0x08
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_ALTSCTR 0x09 /* alternate sector partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_CACHE 0x0a /* Solaris cachefs partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_VXVM_PUB 0x0e /* VxVM public region */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_VXVM_PRIV 0x0f /* VxVM private region */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* NetBSD/mips defines this */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_NETBSD_FFS 0xff
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome/* FreeBSD tags: the high byte equals ELFOSABI_FREEBSD */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_FREEBSD_SWAP 0x0901
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_FREEBSD_UFS 0x0902
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_FREEBSD_VINUM 0x0903
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_FREEBSD_ZFS 0x0904
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_TAG_FREEBSD_NANDFS 0x0905
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_FLAG_UNMNT 0x01 /* unmountable partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_FLAG_RDONLY 0x10 /* partition is read/only */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_ASCII_LEN 128
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_BOOTSIZE 8192 /* 16 sectors */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_MAGIC 0xdabe
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_RAW_PART 2
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_SANITY 0x600ddeee
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_VERSION 1
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC_VOLUME_LEN 8
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define VTOC8_NPARTS 8
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct vtoc8 {
199767f8919635c4928607450d9e0abb932109ceToomas Soome char ascii[VTOC_ASCII_LEN];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t version;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char volume[VTOC_VOLUME_LEN];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t nparts;
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t tag;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t flag;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } part[VTOC8_NPARTS] __packed;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t __alignment;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t bootinfo[3];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t sanity;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t reserved[10];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t timestamp[VTOC8_NPARTS];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t wskip;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t rskip;
199767f8919635c4928607450d9e0abb932109ceToomas Soome char padding[152];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t rpm;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t physcyls;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t sparesecs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t spare1[2];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t interleave;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t ncyls;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t altcyls;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t nheads;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t nsecs;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t spare2[2];
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t cyl;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t nblks;
199767f8919635c4928607450d9e0abb932109ceToomas Soome } map[VTOC8_NPARTS];
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t magic;
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t cksum;
199767f8919635c4928607450d9e0abb932109ceToomas Soome} __packed;
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef CTASSERT
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCTASSERT(sizeof(struct vtoc8) == 512);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define NDKMAP 16 /* # of logical partitions */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DK_LABEL_LOC 1 /* location of disk label */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LEN_DKL_ASCII 128 /* length of dkl_asciilabel */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LEN_DKL_VVOL 8 /* length of v_volume */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DK_LABEL_SIZE 512 /* size of disk label */
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define DK_MAX_BLOCKS 0x7fffffff /* max # of blocks handled */
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct dk_vtoc {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t v_bootinfo[3]; /* info needed by mboot (unsupported) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t v_sanity; /* to verify vtoc sanity */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t v_version; /* layout version */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char v_volume[LEN_DKL_VVOL]; /* volume name */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t v_sectorsz; /* sector size in bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t v_nparts; /* number of partitions */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t v_reserved[10]; /* free space */
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct {
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t p_tag; /* ID tag of partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t p_flag; /* permission flags */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t p_start;/* start sector no of partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome int32_t p_size; /* # of blocks in partition */
199767f8919635c4928607450d9e0abb932109ceToomas Soome } v_part[NDKMAP]; /* partition headers */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t timestamp[NDKMAP]; /* partition timestamp (unsupported) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char v_asciilabel[LEN_DKL_ASCII]; /* for compatibility */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#define LEN_DKL_PAD (DK_LABEL_SIZE - \
199767f8919635c4928607450d9e0abb932109ceToomas Soome ((sizeof (struct dk_vtoc) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (4 * sizeof (uint32_t)) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (12 * sizeof (uint16_t)) + \
199767f8919635c4928607450d9e0abb932109ceToomas Soome (2 * (sizeof (uint16_t))))))
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soomestruct dk_label {
199767f8919635c4928607450d9e0abb932109ceToomas Soome struct dk_vtoc dkl_vtoc; /* vtoc inclusions from AT&T SVr4 */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t dkl_pcyl; /* # of physical cylinders */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t dkl_ncyl; /* # of data cylinders */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_acyl; /* # of alternate cylinders */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_bcyl; /* cyl offset (for fixed head area) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t dkl_nhead; /* # of heads */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint32_t dkl_nsect; /* # of data sectors per track */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_intrlv; /* interleave factor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_skew; /* skew factor */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_apc; /* alternates per cyl (SCSI only) */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_rpm; /* revolutions per minute */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_write_reinstruct; /* # sectors to skip, writes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_read_reinstruct; /* # sectors to skip, reads */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_extra[4]; /* for compatible expansion */
199767f8919635c4928607450d9e0abb932109ceToomas Soome char dkl_pad[LEN_DKL_PAD]; /* unused part of 512 bytes */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_magic; /* identifies this label format */
199767f8919635c4928607450d9e0abb932109ceToomas Soome uint16_t dkl_cksum; /* xor checksum of sector */
199767f8919635c4928607450d9e0abb932109ceToomas Soome};
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#ifdef CTASSERT
199767f8919635c4928607450d9e0abb932109ceToomas SoomeCTASSERT(sizeof(struct dk_label) == 512);
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif
199767f8919635c4928607450d9e0abb932109ceToomas Soome
199767f8919635c4928607450d9e0abb932109ceToomas Soome#endif /* _SYS_VTOC_H_ */