#define _PATH_DISKTAB "/etc/disktab"
#define DISKTAB "/etc/disktab"
#include <machine/disklabel.h>
#include <sys/uuid.h>
#define MAXPARTITIONSUNIT 64
#define MAXPARTITIONS16 16
#define DISKUNIT(dev) (minor(dev) / MAXPARTITIONSUNIT)
#define DISKPART(dev) (minor(dev) % MAXPARTITIONSUNIT)
#define RAW_PART 2
#define DISKMINOR(unit, part) \
(((unit) * MAXPARTITIONSUNIT) + (part))
#define MAKEDISKDEV(maj, unit, part) \
(makedev((maj), DISKMINOR((unit), (part))))
#define DISKLABELDEV(dev) \
(MAKEDISKDEV(major(dev), DISKUNIT(dev), RAW_PART))
#define DISKMAGIC 0x82564557U
#define MAXDISKSIZE 0x7fffffffffffLL
#ifndef _LOCORE
struct disklabel {
u_int32_t d_magic;
u_int16_t d_type;
u_int16_t d_subtype;
char d_typename[16];
char d_packname[16];
u_int32_t d_secsize;
u_int32_t d_nsectors;
u_int32_t d_ntracks;
u_int32_t d_ncylinders;
u_int32_t d_secpercyl;
u_int32_t d_secperunit;
u_char d_uid[8];
u_int32_t d_acylinders;
u_int16_t d_bstarth;
u_int16_t d_bendh;
u_int32_t d_bstart;
u_int32_t d_bend;
u_int32_t d_flags;
#define NDDATA 5
u_int32_t d_spare4[NDDATA];
u_int16_t d_secperunith;
u_int16_t d_version;
#define NSPARE 4
u_int32_t d_spare[NSPARE];
u_int32_t d_magic2;
u_int16_t d_checksum;
u_int16_t d_npartitions;
u_int32_t d_spare2;
u_int32_t d_spare3;
struct partition {
u_int32_t p_size;
u_int32_t p_offset;
u_int16_t p_offseth;
u_int16_t p_sizeh;
u_int8_t p_fstype;
u_int8_t p_fragblock;
u_int16_t p_cpg;
} d_partitions[MAXPARTITIONSUNIT];
};
#endif
#define DISKLABELV1_FFS_FRAGBLOCK(fsize, frag) \
((fsize) * (frag) == 0 ? 0 : \
(((ffs((fsize) * (frag)) - 13) << 3) | (ffs(frag))))
#define DISKLABELV1_FFS_BSIZE(i) ((i) == 0 ? 0 : (1 << (((i) >> 3) + 12)))
#define DISKLABELV1_FFS_FRAG(i) ((i) == 0 ? 0 : (1 << (((i) & 0x07) - 1)))
#define DISKLABELV1_FFS_FSIZE(i) (DISKLABELV1_FFS_FRAG(i) == 0 ? 0 : \
(DISKLABELV1_FFS_BSIZE(i) / DISKLABELV1_FFS_FRAG(i)))
#define DL_GETPSIZE(p) (((u_int64_t)(p)->p_sizeh << 32) + (p)->p_size)
#define DL_SETPSIZE(p, n) do { \
u_int64_t __x = (n); \
(p)->p_sizeh = __x >> 32; \
(p)->p_size = __x; \
} while (0)
#define DL_GETPOFFSET(p) (((u_int64_t)(p)->p_offseth << 32) + (p)->p_offset)
#define DL_SETPOFFSET(p, n) do { \
u_int64_t __x = (n); \
(p)->p_offseth = __x >> 32; \
(p)->p_offset = __x; \
} while (0)
#define DL_GETDSIZE(d) (((u_int64_t)(d)->d_secperunith << 32) + \
(d)->d_secperunit)
#define DL_SETDSIZE(d, n) do { \
u_int64_t __x = (n); \
(d)->d_secperunith = __x >> 32; \
(d)->d_secperunit = __x; \
} while (0)
#define DL_GETBSTART(d) (((u_int64_t)(d)->d_bstarth << 32) + \
(d)->d_bstart)
#define DL_SETBSTART(d, n) do { \
u_int64_t __x = (n); \
(d)->d_bstarth = __x >> 32; \
(d)->d_bstart = __x; \
} while (0)
#define DL_GETBEND(d) (((u_int64_t)(d)->d_bendh << 32) + \
(d)->d_bend)
#define DL_SETBEND(d, n) do { \
u_int64_t __x = (n); \
(d)->d_bendh = __x >> 32; \
(d)->d_bend = __x; \
} while (0)
#define DL_BLKSPERSEC(d) ((d)->d_secsize / DEV_BSIZE)
#define DL_SECTOBLK(d, n) ((n) * DL_BLKSPERSEC(d))
#define DL_BLKTOSEC(d, n) ((n) / DL_BLKSPERSEC(d))
#define DL_BLKOFFSET(d, n) (((n) % DL_BLKSPERSEC(d)) * DEV_BSIZE)
static __inline char
DL_PARTNUM2NAME(int partnum)
{
if (partnum >= MAXPARTITIONS)
return -1;
if (partnum <= 'z' - 'a')
return 'a' + partnum;
else if (partnum - 26 <= 'Z' - 'A')
return 'A' + partnum - 26;
return -1;
}
static __inline int
DL_PARTNAME2NUM(char partname)
{
int partnum = -1;
if (partname >= 'a' && partname <= 'z')
partnum = partname - 'a';
else if (partname >= 'A' && partname <= 'Z')
partnum = partname - 'A' + 26;
if (partnum >= MAXPARTITIONS)
partnum = -1;
return partnum;
}
#define DTYPE_SMD 1
#define DTYPE_MSCP 2
#define DTYPE_DEC 3
#define DTYPE_SCSI 4
#define DTYPE_ESDI 5
#define DTYPE_ST506 6
#define DTYPE_HPIB 7
#define DTYPE_HPFL 8
#define DTYPE_FLOPPY 10
#define DTYPE_CCD 11
#define DTYPE_VND 12
#define DTYPE_ATAPI 13
#define DTYPE_RAID 14
#define DTYPE_RDROOT 15
#ifdef DKTYPENAMES
static const char * const dktypenames[] = {
"unknown",
"SMD",
"MSCP",
"old DEC",
"SCSI",
"ESDI",
"ST506",
"HP-IB",
"HP-FL",
"type 9",
"floppy",
"ccd",
"vnd",
"ATAPI",
"RAID",
"rdroot",
NULL
};
#define DKMAXTYPES (sizeof(dktypenames) / sizeof(dktypenames[0]) - 1)
#endif
#define FS_UNUSED 0
#define FS_SWAP 1
#define FS_V6 2
#define FS_V7 3
#define FS_SYSV 4
#define FS_V71K 5
#define FS_V8 6
#define FS_BSDFFS 7
#define FS_MSDOS 8
#define FS_BSDLFS 9
#define FS_OTHER 10
#define FS_HPFS 11
#define FS_ISO9660 12
#define FS_BOOT 13
#define FS_ADOS 14
#define FS_HFS 15
#define FS_ADFS 16
#define FS_EXT2FS 17
#define FS_CCD 18
#define FS_RAID 19
#define FS_NTFS 20
#define FS_UDF 21
#ifdef DKTYPENAMES
static const char * const fstypenames[] = {
"unused",
"swap",
"Version6",
"Version7",
"SystemV",
"4.1BSD",
"Eighth-Edition",
"4.2BSD",
"MSDOS",
"4.4LFS",
"unknown",
"HPFS",
"ISO9660",
"boot",
"ADOS",
"HFS",
"ADFS",
"ext2fs",
"ccd",
"RAID",
"NTFS",
"UDF",
NULL
};
static char *fstypesnames[] = {
"",
"",
"",
"",
"",
"",
"",
"ffs",
"msdos",
"lfs",
"",
"",
"cd9660",
"",
"ados",
"",
"",
"ext2fs",
"",
"",
"ntfs",
"udf",
NULL
};
#define FSMAXTYPES (sizeof(fstypenames) / sizeof(fstypenames[0]) - 1)
#endif
#define D_VENDOR 0x08
#ifndef _LOCORE
struct partinfo {
struct disklabel *disklab;
struct partition *part;
};
#define GPTSECTOR 1
#define GPTSIGNATURE 0x5452415020494645LL
#define GPTREVISION 0x10000
#define NGPTPARTITIONS 128
#define GPTPARTATTR_REQUIRED (1ULL << 0)
#define GPTPARTATTR_IGNORE (1ULL << 1)
#define GPTPARTATTR_BOOTABLE (1ULL << 2)
#define GPTPARTATTR_MS_READONLY (1ULL << 60)
#define GPTPARTATTR_MS_SHADOW (1ULL << 61)
#define GPTPARTATTR_MS_HIDDEN (1ULL << 62)
#define GPTPARTATTR_MS_NOAUTOMOUNT (1ULL << 63)
#define GPTMINHDRSIZE 92
#define GPTMINPARTSIZE 128
#define GPTPARTNAMESIZE 36
struct gpt_header {
u_int64_t gh_sig;
u_int32_t gh_rev;
u_int32_t gh_size;
u_int32_t gh_csum;
u_int32_t gh_rsvd;
u_int64_t gh_lba_self;
u_int64_t gh_lba_alt;
u_int64_t gh_lba_start;
u_int64_t gh_lba_end;
struct uuid gh_guid;
u_int64_t gh_part_lba;
u_int32_t gh_part_num;
u_int32_t gh_part_size;
u_int32_t gh_part_csum;
};
struct gpt_partition {
struct uuid gp_type;
struct uuid gp_guid;
u_int64_t gp_lba_start;
u_int64_t gp_lba_end;
u_int64_t gp_attrs;
u_int16_t gp_name[GPTPARTNAMESIZE];
};
#define GPT_UUID_EFI_SYSTEM \
{ 0xc1, 0x2a, 0x73, 0x28, 0xf8, 0x1f, 0x11, 0xd2, \
0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b }
#define GPT_UUID_OPENBSD \
{ 0x82, 0x4c, 0xc7, 0xa0, 0x36, 0xa8, 0x11, 0xe3, \
0x89, 0x0a, 0x95, 0x25, 0x19, 0xad, 0x3f, 0x61 }
#define DOS_LABELSECTOR 1
#define DOSBBSECTOR 0
#define DOSPARTOFF 446
#define DOSDISKOFF 444
#define NDOSPART 4
#define DOSACTIVE 0x80
#define DOSMBR_SIGNATURE (0xaa55)
#define DOSMBR_SIGNATURE_OFF (0x1fe)
#define DOS_MAXEBR 256
struct dos_partition {
u_int8_t dp_flag;
u_int8_t dp_shd;
u_int8_t dp_ssect;
u_int8_t dp_scyl;
u_int8_t dp_typ;
u_int8_t dp_ehd;
u_int8_t dp_esect;
u_int8_t dp_ecyl;
u_int32_t dp_start;
u_int32_t dp_size;
};
#define DOSPTYP_UNUSED 0x00
#define DOSPTYP_FAT12 0x01
#define DOSPTYP_FAT16S 0x04
#define DOSPTYP_EXTEND 0x05
#define DOSPTYP_FAT16B 0x06
#define DOSPTYP_NTFS 0x07
#define DOSPTYP_FAT32 0x0b
#define DOSPTYP_FAT32L 0x0c
#define DOSPTYP_FAT16L 0x0e
#define DOSPTYP_EXTENDL 0x0f
#define DOSPTYP_ONTRACK 0x54
#define DOSPTYP_LINUX 0x83
#define DOSPTYP_FREEBSD 0xa5
#define DOSPTYP_OPENBSD 0xa6
#define DOSPTYP_NETBSD 0xa9
#define DOSPTYP_EFI 0xee
#define DOSPTYP_EFISYS 0xef
struct dos_mbr {
u_int8_t dmbr_boot[DOSPARTOFF];
struct dos_partition dmbr_parts[NDOSPART];
u_int16_t dmbr_sign;
} __packed;
#ifdef _KERNEL
void diskerr(struct buf *, char *, char *, int, int, struct disklabel *);
u_int dkcksum(struct disklabel *);
int initdisklabel(struct disklabel *);
int checkdisklabel(dev_t, void *, struct disklabel *, u_int64_t, u_int64_t);
int setdisklabel(struct disklabel *, struct disklabel *, u_int64_t);
int readdisklabel(dev_t, void (*)(struct buf *), struct disklabel *, int);
int writedisklabel(dev_t, void (*)(struct buf *), struct disklabel *);
int bounds_check_with_label(struct buf *, struct disklabel *);
int readdisksector(struct buf *, void (*)(struct buf *),
struct disklabel *, u_int64_t);
int readdoslabel(struct buf *, void (*)(struct buf *),
struct disklabel *, daddr_t *, int);
#ifdef CD9660
int iso_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp);
#endif
#ifdef UDF
int udf_disklabelspoof(dev_t dev, void (*strat)(struct buf *),
struct disklabel *lp);
#endif
#endif
#endif
#if !defined(_KERNEL) && !defined(_LOCORE)
#include <sys/cdefs.h>
__BEGIN_DECLS
struct disklabel *getdiskbyname(const char *);
__END_DECLS
#endif