summaryrefslogtreecommitdiff
path: root/usr/src/lib/libefi
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src/lib/libefi')
-rw-r--r--usr/src/lib/libefi/Makefile49
-rw-r--r--usr/src/lib/libefi/Makefile.com55
-rw-r--r--usr/src/lib/libefi/amd64/Makefile36
-rw-r--r--usr/src/lib/libefi/common/crc32_efi.c47
-rw-r--r--usr/src/lib/libefi/common/llib-lefi42
-rw-r--r--usr/src/lib/libefi/common/rdwr_efi.c985
-rw-r--r--usr/src/lib/libefi/i386/Makefile31
-rw-r--r--usr/src/lib/libefi/sparc/Makefile31
-rw-r--r--usr/src/lib/libefi/sparcv9/Makefile36
-rw-r--r--usr/src/lib/libefi/spec/Makefile29
-rw-r--r--usr/src/lib/libefi/spec/Makefile.targ34
-rw-r--r--usr/src/lib/libefi/spec/amd64/Makefile42
-rw-r--r--usr/src/lib/libefi/spec/efi.spec79
-rw-r--r--usr/src/lib/libefi/spec/i386/Makefile42
-rw-r--r--usr/src/lib/libefi/spec/sparc/Makefile44
-rw-r--r--usr/src/lib/libefi/spec/sparcv9/Makefile43
-rw-r--r--usr/src/lib/libefi/spec/versions47
17 files changed, 1672 insertions, 0 deletions
diff --git a/usr/src/lib/libefi/Makefile b/usr/src/lib/libefi/Makefile
new file mode 100644
index 0000000000..6b817122f0
--- /dev/null
+++ b/usr/src/lib/libefi/Makefile
@@ -0,0 +1,49 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+include ../Makefile.lib
+
+SUBDIRS= $(MACH)
+$(BUILD64)SUBDIRS += $(MACH64)
+
+all := TARGET= all
+install := TARGET= install
+clean := TARGET= clean
+clobber := TARGET= clobber
+lint := TARGET= lint
+
+.KEEP_STATE:
+
+all install clean clobber: spec .WAIT $(SUBDIRS)
+
+lint: $(SUBDIRS)
+
+spec $(SUBDIRS): FRC
+ @cd $@; pwd; $(MAKE) $(TARGET)
+
+FRC:
diff --git a/usr/src/lib/libefi/Makefile.com b/usr/src/lib/libefi/Makefile.com
new file mode 100644
index 0000000000..32003df9b1
--- /dev/null
+++ b/usr/src/lib/libefi/Makefile.com
@@ -0,0 +1,55 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+LIBRARY = libefi.a
+VERS = .1
+OBJECTS = rdwr_efi.o crc32_efi.o
+
+include ../../Makefile.lib
+
+# install this library in the root filesystem
+include ../../Makefile.rootfs
+
+SRCDIR = ../common
+MAPDIR = ../spec/$(TRANSMACH)
+SPECMAPFILE = $(MAPDIR)/mapfile
+
+LIBS = $(DYNLIB) $(LINTLIB)
+LDLIBS += -luuid -lc
+$(LINTLIB) := SRCS = $(SRCDIR)/$(LINTSRC)
+CFLAGS += $(CCVERBOSE)
+
+LINTFLAGS64 += -errchk=longptr64
+
+.KEEP_STATE:
+
+all: $(LIBS)
+
+lint: lintcheck
+
+include ../../Makefile.targ
diff --git a/usr/src/lib/libefi/amd64/Makefile b/usr/src/lib/libefi/amd64/Makefile
new file mode 100644
index 0000000000..1064169930
--- /dev/null
+++ b/usr/src/lib/libefi/amd64/Makefile
@@ -0,0 +1,36 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+LIBS = $(DYNLIB) $(LINTLIB)
+
+all: $(LIBS)
+
+install: all $(ROOTLIBS64) $(ROOTLINKS64)
diff --git a/usr/src/lib/libefi/common/crc32_efi.c b/usr/src/lib/libefi/common/crc32_efi.c
new file mode 100644
index 0000000000..1dba28ad72
--- /dev/null
+++ b/usr/src/lib/libefi/common/crc32_efi.c
@@ -0,0 +1,47 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/crc32.h>
+
+static unsigned int crc32_tab[] = { CRC32_TABLE };
+
+/*
+ * Return a 32-bit CRC of the contents of the buffer.
+ *
+ * The seed is 0xffffffff and the result is XORed with 0xffffffff
+ * because this is what the Itanium firmware expects.
+ */
+unsigned int
+efi_crc32(const unsigned char *s, unsigned int len)
+{
+ unsigned int crc32val;
+
+ CRC32(crc32val, s, len, -1U, crc32_tab);
+
+ return (crc32val ^ -1U);
+}
diff --git a/usr/src/lib/libefi/common/llib-lefi b/usr/src/lib/libefi/common/llib-lefi
new file mode 100644
index 0000000000..974002e8b9
--- /dev/null
+++ b/usr/src/lib/libefi/common/llib-lefi
@@ -0,0 +1,42 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/* LINTLIBRARY */
+/* PROTOLIB1 */
+
+/*
+ * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <sys/efi_partition.h>
+#include <pkginfo.h>
+
+/*
+ * usr/src/lib/libefi
+ */
+/* rdwr_efi.c */
+int efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc);
+int efi_alloc_and_read(int fd, struct dk_gpt **vtoc);
+int efi_write(int fd, struct dk_gpt *vtoc);
+void efi_free(struct dk_gpt *);
+
diff --git a/usr/src/lib/libefi/common/rdwr_efi.c b/usr/src/lib/libefi/common/rdwr_efi.c
new file mode 100644
index 0000000000..a1540753b2
--- /dev/null
+++ b/usr/src/lib/libefi/common/rdwr_efi.c
@@ -0,0 +1,985 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License"). You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <strings.h>
+#include <unistd.h>
+#include <uuid/uuid.h>
+#include <libintl.h>
+#include <sys/types.h>
+#include <sys/dkio.h>
+#include <sys/vtoc.h>
+#include <sys/mhd.h>
+#include <sys/param.h>
+#include <sys/dktp/fdisk.h>
+#include <sys/efi_partition.h>
+#include <sys/byteorder.h>
+#include <sys/ddi.h>
+
+static struct uuid_to_ptag {
+ struct uuid uuid;
+} conversion_array[] = {
+ { EFI_UNUSED },
+ { EFI_BOOT },
+ { EFI_ROOT },
+ { EFI_SWAP },
+ { EFI_USR },
+ { EFI_BACKUP },
+ { 0 }, /* STAND is never used */
+ { EFI_VAR },
+ { EFI_HOME },
+ { EFI_ALTSCTR },
+ { 0 }, /* CACHE (cachefs) is never used */
+ { EFI_RESERVED },
+ { EFI_SYSTEM },
+ { EFI_LEGACY_MBR },
+ { EFI_RESV3 },
+ { EFI_RESV4 },
+ { EFI_MSFT_RESV },
+ { EFI_DELL_BASIC },
+ { EFI_DELL_RAID },
+ { EFI_DELL_SWAP },
+ { EFI_DELL_LVM },
+ { EFI_DELL_RESV }
+};
+
+/*
+ * Default vtoc information for non-SVr4 partitions
+ */
+struct dk_map2 default_vtoc_map[NDKMAP] = {
+ { V_ROOT, 0 }, /* a - 0 */
+ { V_SWAP, V_UNMNT }, /* b - 1 */
+ { V_BACKUP, V_UNMNT }, /* c - 2 */
+ { V_UNASSIGNED, 0 }, /* d - 3 */
+ { V_UNASSIGNED, 0 }, /* e - 4 */
+ { V_UNASSIGNED, 0 }, /* f - 5 */
+ { V_USR, 0 }, /* g - 6 */
+ { V_UNASSIGNED, 0 }, /* h - 7 */
+
+#if defined(_SUNOS_VTOC_16)
+
+#if defined(i386) || defined(__amd64)
+ { V_BOOT, V_UNMNT }, /* i - 8 */
+ { V_ALTSCTR, 0 }, /* j - 9 */
+
+#else
+#error No VTOC format defined.
+#endif /* defined(i386) */
+
+ { V_UNASSIGNED, 0 }, /* k - 10 */
+ { V_UNASSIGNED, 0 }, /* l - 11 */
+ { V_UNASSIGNED, 0 }, /* m - 12 */
+ { V_UNASSIGNED, 0 }, /* n - 13 */
+ { V_UNASSIGNED, 0 }, /* o - 14 */
+ { V_UNASSIGNED, 0 }, /* p - 15 */
+#endif /* defined(_SUNOS_VTOC_16) */
+};
+
+/*
+ * This is the size of the reserved partition.
+ * Valid in case of EFI labels.
+ */
+#define EFI_MIN_RESV_SIZE (16 * 1024)
+
+#ifdef DEBUG
+int efi_debug = 1;
+#else
+int efi_debug = 0;
+#endif
+
+extern unsigned int efi_crc32(const unsigned char *, unsigned int);
+static int efi_read(int, struct dk_gpt *);
+
+static int
+read_disk_info(int fd, diskaddr_t *capacity, uint_t *lbsize)
+{
+ struct dk_minfo disk_info;
+
+ if ((ioctl(fd, DKIOCGMEDIAINFO, (caddr_t)&disk_info)) == -1)
+ return (errno);
+ *capacity = disk_info.dki_capacity;
+ *lbsize = disk_info.dki_lbsize;
+ return (0);
+}
+
+/*
+ * the number of blocks the EFI label takes up (round up to nearest
+ * block)
+ */
+#define NBLOCKS(p, l) (1 + ((((p) * (int)sizeof (efi_gpe_t)) + \
+ ((l) - 1)) / (l)))
+/* number of partitions -- limited by what we can malloc */
+#define MAX_PARTS ((4294967295UL - sizeof (struct dk_gpt)) / \
+ sizeof (struct dk_part))
+
+int
+efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc)
+{
+ diskaddr_t capacity;
+ uint_t lbsize;
+ uint_t nblocks;
+ size_t length;
+ struct dk_gpt *vptr;
+ struct uuid uuid;
+
+ if (read_disk_info(fd, &capacity, &lbsize) != 0) {
+ if (efi_debug)
+ (void) fprintf(stderr,
+ "couldn't read disk information\n");
+ return (-1);
+ }
+
+ nblocks = NBLOCKS(nparts, lbsize);
+ if ((nblocks * lbsize) < EFI_MIN_ARRAY_SIZE + lbsize) {
+ /* 16K plus one block for the GPT */
+ nblocks = EFI_MIN_ARRAY_SIZE / lbsize + 1;
+ }
+
+ if (nparts > MAX_PARTS) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "the maximum number of partitions supported is %lu\n",
+ MAX_PARTS);
+ }
+ return (-1);
+ }
+
+ length = sizeof (struct dk_gpt) +
+ sizeof (struct dk_part) * (nparts - 1);
+
+ if ((*vtoc = calloc(length, 1)) == NULL)
+ return (-1);
+
+ vptr = *vtoc;
+
+ vptr->efi_version = EFI_VERSION_CURRENT;
+ vptr->efi_lbasize = lbsize;
+ vptr->efi_nparts = nparts;
+ /*
+ * add one block here for the PMBR; on disks with a 512 byte
+ * block size and 128 or fewer partitions, efi_first_u_lba
+ * should work out to "34"
+ */
+ vptr->efi_first_u_lba = nblocks + 1;
+ vptr->efi_last_lba = capacity - 1;
+ vptr->efi_last_u_lba = vptr->efi_last_lba - nblocks;
+ (void) uuid_generate((uchar_t *)&uuid);
+ UUID_LE_CONVERT(vptr->efi_disk_uguid, uuid);
+ return (0);
+}
+
+/*
+ * Read EFI - return partition number upon success.
+ */
+int
+efi_alloc_and_read(int fd, struct dk_gpt **vtoc)
+{
+ int rval;
+ uint32_t nparts;
+ int length;
+
+ /* figure out the number of entries that would fit into 16K */
+ nparts = EFI_MIN_ARRAY_SIZE / sizeof (efi_gpe_t);
+ length = (int) sizeof (struct dk_gpt) +
+ (int) sizeof (struct dk_part) * (nparts - 1);
+ if ((*vtoc = calloc(length, 1)) == NULL)
+ return (VT_ERROR);
+
+ (*vtoc)->efi_nparts = nparts;
+ rval = efi_read(fd, *vtoc);
+
+ if ((rval == VT_EINVAL) && (*vtoc)->efi_nparts > nparts) {
+ void *tmp;
+ length = (int) sizeof (struct dk_gpt) +
+ (int) sizeof (struct dk_part) *
+ ((*vtoc)->efi_nparts - 1);
+ nparts = (*vtoc)->efi_nparts;
+ if ((tmp = realloc(*vtoc, length)) == NULL) {
+ free (*vtoc);
+ *vtoc = NULL;
+ return (VT_ERROR);
+ } else {
+ *vtoc = tmp;
+ rval = efi_read(fd, *vtoc);
+ }
+ }
+
+ if (rval < 0) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "read of EFI table failed, rval=%d\n", rval);
+ }
+ free (*vtoc);
+ *vtoc = NULL;
+ }
+
+ return (rval);
+}
+
+static int
+efi_ioctl(int fd, int cmd, dk_efi_t *dk_ioc)
+{
+ void *data = dk_ioc->dki_data;
+ int error;
+
+ dk_ioc->dki_data_64 = (uint64_t)(uintptr_t)data;
+ error = ioctl(fd, cmd, (void *)dk_ioc);
+ dk_ioc->dki_data = data;
+
+ return (error);
+}
+
+static int
+check_label(int fd, dk_efi_t *dk_ioc)
+{
+ efi_gpt_t *efi;
+ uint_t crc;
+
+ if (efi_ioctl(fd, DKIOCGETEFI, dk_ioc) == -1) {
+ switch (errno) {
+ case EIO:
+ return (VT_EIO);
+ default:
+ return (VT_ERROR);
+ }
+ }
+ efi = dk_ioc->dki_data;
+ if (efi->efi_gpt_Signature != LE_64(EFI_SIGNATURE)) {
+ if (efi_debug)
+ (void) fprintf(stderr,
+ "Bad EFI signature: 0x%llx != 0x%llx\n",
+ (long long)efi->efi_gpt_Signature,
+ (long long)LE_64(EFI_SIGNATURE));
+ return (VT_EINVAL);
+ }
+
+ /*
+ * check CRC of the header; the size of the header should
+ * never be larger than one block
+ */
+ crc = efi->efi_gpt_HeaderCRC32;
+ efi->efi_gpt_HeaderCRC32 = 0;
+
+ if (((len_t)LE_32(efi->efi_gpt_HeaderSize) > dk_ioc->dki_length) ||
+ crc != LE_32(efi_crc32((unsigned char *)efi,
+ LE_32(efi->efi_gpt_HeaderSize)))) {
+ if (efi_debug)
+ (void) fprintf(stderr,
+ "Bad EFI CRC: 0x%x != 0x%x\n",
+ crc,
+ LE_32(efi_crc32((unsigned char *)efi,
+ sizeof (struct efi_gpt))));
+ return (VT_EINVAL);
+ }
+
+ return (0);
+}
+
+static int
+efi_read(int fd, struct dk_gpt *vtoc)
+{
+ int i, j;
+ int label_len;
+ int rval = 0;
+ int md_flag = 0;
+ struct dk_minfo disk_info;
+ dk_efi_t dk_ioc;
+ efi_gpt_t *efi;
+ efi_gpe_t *efi_parts;
+ struct dk_cinfo dki_info;
+ uint32_t user_length;
+
+ /*
+ * get the partition number for this file descriptor.
+ */
+ if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) {
+ if (efi_debug)
+ (void) fprintf(stderr, "DKIOCINFO errno 0x%x\n", errno);
+ switch (errno) {
+ case EIO:
+ return (VT_EIO);
+ case EINVAL:
+ return (VT_EINVAL);
+ default:
+ return (VT_ERROR);
+ }
+ }
+ if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) &&
+ (strncmp(dki_info.dki_dname, "md", 3) == 0)) {
+ md_flag++;
+ }
+ /* get the LBA size */
+ if (ioctl(fd, DKIOCGMEDIAINFO, (caddr_t)&disk_info) == -1) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "assuming LBA 512 bytes %d\n",
+ errno);
+ }
+ disk_info.dki_lbsize = DEV_BSIZE;
+ }
+ if (disk_info.dki_lbsize == 0) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "efi_read: assuming LBA 512 bytes\n");
+ }
+ disk_info.dki_lbsize = DEV_BSIZE;
+ }
+ /*
+ * Read the EFI GPT to figure out how many partitions we need
+ * to deal with.
+ */
+ dk_ioc.dki_lba = 1;
+ if (NBLOCKS(vtoc->efi_nparts, disk_info.dki_lbsize) < 34) {
+ label_len = EFI_MIN_ARRAY_SIZE + disk_info.dki_lbsize;
+ } else {
+ label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) +
+ disk_info.dki_lbsize;
+ if (label_len % disk_info.dki_lbsize) {
+ /* pad to physical sector size */
+ label_len += disk_info.dki_lbsize;
+ label_len &= ~(disk_info.dki_lbsize - 1);
+ }
+ }
+
+ if ((dk_ioc.dki_data = calloc(label_len, 1)) == NULL)
+ return (VT_ERROR);
+
+ dk_ioc.dki_length = label_len;
+ user_length = vtoc->efi_nparts;
+ efi = dk_ioc.dki_data;
+ if (md_flag) {
+ if (efi_ioctl(fd, DKIOCGETEFI, &dk_ioc) == -1) {
+ switch (errno) {
+ case EIO:
+ return (VT_EIO);
+ default:
+ return (VT_ERROR);
+ }
+ }
+ } else if ((rval = check_label(fd, &dk_ioc)) == VT_EINVAL) {
+ /* no valid label here; try the alternate */
+ dk_ioc.dki_lba = disk_info.dki_capacity - 1;
+ dk_ioc.dki_length = disk_info.dki_lbsize;
+ if (check_label(fd, &dk_ioc) == 0) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "efi_read: primary label corrupt; "
+ "using backup\n");
+ }
+ dk_ioc.dki_lba = LE_64(efi->efi_gpt_PartitionEntryLBA);
+ vtoc->efi_flags |= EFI_GPT_PRIMARY_CORRUPT;
+ vtoc->efi_nparts =
+ LE_32(efi->efi_gpt_NumberOfPartitionEntries);
+ /*
+ * partitions are between last usable LBA and
+ * backup partition header
+ */
+ dk_ioc.dki_data++;
+ dk_ioc.dki_length = disk_info.dki_capacity -
+ dk_ioc.dki_lba - 1;
+ dk_ioc.dki_length *= disk_info.dki_lbsize;
+ if (dk_ioc.dki_length > (len_t)label_len) {
+ rval = VT_EINVAL;
+ } else {
+ rval = efi_ioctl(fd, DKIOCGETEFI, &dk_ioc);
+ }
+ }
+ }
+ if (rval < 0) {
+ free(efi);
+ return (rval);
+ }
+
+ /* partitions start in the next block */
+ /* LINTED -- always longlong aligned */
+ efi_parts = (efi_gpe_t *)(((char *)efi) + disk_info.dki_lbsize);
+
+ /*
+ * Assemble this into a "dk_gpt" struct for easier
+ * digestibility by applications.
+ */
+ vtoc->efi_version = LE_32(efi->efi_gpt_Revision);
+ vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries);
+ vtoc->efi_part_size = LE_32(efi->efi_gpt_SizeOfPartitionEntry);
+ vtoc->efi_lbasize = disk_info.dki_lbsize;
+ vtoc->efi_last_lba = disk_info.dki_capacity - 1;
+ vtoc->efi_first_u_lba = LE_64(efi->efi_gpt_FirstUsableLBA);
+ vtoc->efi_last_u_lba = LE_64(efi->efi_gpt_LastUsableLBA);
+ UUID_LE_CONVERT(vtoc->efi_disk_uguid, efi->efi_gpt_DiskGUID);
+
+ /*
+ * If the array the user passed in is too small, set the length
+ * to what it needs to be and return
+ */
+ if (user_length < vtoc->efi_nparts) {
+ return (VT_EINVAL);
+ }
+
+ for (i = 0; i < vtoc->efi_nparts; i++) {
+
+ UUID_LE_CONVERT(vtoc->efi_parts[i].p_guid,
+ efi_parts[i].efi_gpe_PartitionTypeGUID);
+
+ for (j = 0;
+ j < sizeof (conversion_array) / sizeof (struct uuid_to_ptag);
+ j++) {
+
+ if (bcmp(&vtoc->efi_parts[i].p_guid,
+ &conversion_array[j].uuid,
+ sizeof (struct uuid)) == 0) {
+ vtoc->efi_parts[i].p_tag = j;
+ break;
+ }
+ }
+ if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED)
+ continue;
+ vtoc->efi_parts[i].p_flag =
+ LE_16(efi_parts[i].efi_gpe_Attributes.PartitionAttrs);
+ vtoc->efi_parts[i].p_start =
+ LE_64(efi_parts[i].efi_gpe_StartingLBA);
+ vtoc->efi_parts[i].p_size =
+ LE_64(efi_parts[i].efi_gpe_EndingLBA) -
+ vtoc->efi_parts[i].p_start + 1;
+ for (j = 0; j < EFI_PART_NAME_LEN; j++) {
+ vtoc->efi_parts[i].p_name[j] =
+ (uchar_t)LE_16(efi_parts[i].efi_gpe_PartitionName[j]);
+ }
+
+ UUID_LE_CONVERT(vtoc->efi_parts[i].p_uguid,
+ efi_parts[i].efi_gpe_UniquePartitionGUID);
+ }
+ free(efi);
+
+ return (dki_info.dki_partition);
+}
+
+/* writes a "protective" MBR */
+static int
+write_pmbr(int fd, struct dk_gpt *vtoc)
+{
+ dk_efi_t dk_ioc;
+ struct mboot mb;
+ uchar_t *cp;
+ diskaddr_t size_in_lba;
+
+ mb.signature = LE_16(MBB_MAGIC);
+ bzero(&mb.parts, sizeof (mb.parts));
+ cp = (uchar_t *)&mb.parts[0];
+ /* bootable or not */
+ *cp++ = 0;
+ /* beginning CHS; 0xffffff if not representable */
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ /* OS type */
+ *cp++ = EFI_PMBR;
+ /* ending CHS; 0xffffff if not representable */
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ /* starting LBA: 1 (little endian format) by EFI definition */
+ *cp++ = 0x01;
+ *cp++ = 0x00;
+ *cp++ = 0x00;
+ *cp++ = 0x00;
+ /* ending LBA: last block on the disk (little endian format) */
+ size_in_lba = vtoc->efi_last_lba;
+ if (size_in_lba < 0xffffffff) {
+ *cp++ = (size_in_lba & 0x000000ff);
+ *cp++ = (size_in_lba & 0x0000ff00) >> 8;
+ *cp++ = (size_in_lba & 0x00ff0000) >> 16;
+ *cp++ = (size_in_lba & 0xff000000) >> 24;
+ } else {
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ *cp++ = 0xff;
+ }
+ /* LINTED -- always longlong aligned */
+ dk_ioc.dki_data = (efi_gpt_t *)&mb;
+ dk_ioc.dki_lba = 0;
+ dk_ioc.dki_length = sizeof (mb);
+ if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) {
+ switch (errno) {
+ case EIO:
+ return (VT_EIO);
+ case EINVAL:
+ return (VT_EINVAL);
+ default:
+ return (VT_ERROR);
+ }
+ }
+ return (0);
+}
+
+/* make sure the user specified something reasonable */
+static int
+check_input(struct dk_gpt *vtoc)
+{
+ int resv_part = -1;
+ int i, j;
+ diskaddr_t istart, jstart, isize, jsize, endsect;
+
+ /*
+ * Sanity-check the input (make sure no partitions overlap)
+ */
+ for (i = 0; i < vtoc->efi_nparts; i++) {
+ /* It can't be unassigned and have an actual size */
+ if ((vtoc->efi_parts[i].p_tag == V_UNASSIGNED) &&
+ (vtoc->efi_parts[i].p_size != 0)) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+"partition %d is \"unassigned\" but has a size of %llu",
+ i,
+ vtoc->efi_parts[i].p_size);
+ }
+ return (VT_EINVAL);
+ }
+ if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) {
+ continue;
+ }
+ if (vtoc->efi_parts[i].p_tag == V_RESERVED) {
+ if (resv_part != -1) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+"found duplicate reserved partition at %d\n",
+ i);
+ }
+ return (VT_EINVAL);
+ }
+ resv_part = i;
+ }
+ if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) ||
+ (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "Partition %d starts at %llu. ",
+ i,
+ vtoc->efi_parts[i].p_start);
+ (void) fprintf(stderr,
+ "It must be between %llu and %llu.\n",
+ vtoc->efi_first_u_lba,
+ vtoc->efi_last_u_lba);
+ }
+ return (VT_EINVAL);
+ }
+ if ((vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size <
+ vtoc->efi_first_u_lba) ||
+ (vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size >
+ vtoc->efi_last_u_lba + 1)) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "Partition %d ends at %llu. ",
+ i,
+ vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size);
+ (void) fprintf(stderr,
+ "It must be between %llu and %llu.\n",
+ vtoc->efi_first_u_lba,
+ vtoc->efi_last_u_lba);
+ }
+ return (VT_EINVAL);
+ }
+
+ for (j = 0; j < vtoc->efi_nparts; j++) {
+ isize = vtoc->efi_parts[i].p_size;
+ jsize = vtoc->efi_parts[j].p_size;
+ istart = vtoc->efi_parts[i].p_start;
+ jstart = vtoc->efi_parts[j].p_start;
+ if ((i != j) && (isize != 0) && (jsize != 0)) {
+ endsect = jstart + jsize -1;
+ if ((jstart <= istart) &&
+ (istart <= endsect)) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+"Partition %d overlaps partition %d.",
+ i, j);
+ }
+ return (VT_EINVAL);
+ }
+ }
+ }
+ }
+ /* just a warning for now */
+ if ((resv_part == -1) && efi_debug) {
+ (void) fprintf(stderr,
+ "no reserved partition found\n");
+ }
+ return (0);
+}
+
+/*
+ * write EFI label and backup label
+ */
+int
+efi_write(int fd, struct dk_gpt *vtoc)
+{
+ dk_efi_t dk_ioc;
+ efi_gpt_t *efi;
+ efi_gpe_t *efi_parts;
+ int i, j;
+ struct dk_cinfo dki_info;
+ int md_flag = 0;
+
+ if (ioctl(fd, DKIOCINFO, (caddr_t)&dki_info) == -1) {
+ if (efi_debug)
+ (void) fprintf(stderr, "DKIOCINFO errno 0x%x\n", errno);
+ switch (errno) {
+ case EIO:
+ return (VT_EIO);
+ case EINVAL:
+ return (VT_EINVAL);
+ default:
+ return (VT_ERROR);
+ }
+ }
+
+ /* check if we are dealing wih a metadevice */
+ if ((strncmp(dki_info.dki_cname, "pseudo", 7) == 0) &&
+ (strncmp(dki_info.dki_dname, "md", 3) == 0)) {
+ md_flag = 1;
+ }
+
+ if (check_input(vtoc)) {
+ /*
+ * not valid; if it's a metadevice just pass it down
+ * because SVM will do its own checking
+ */
+ if (md_flag == 0) {
+ return (VT_EINVAL);
+ }
+ }
+
+ dk_ioc.dki_lba = 1;
+ if (NBLOCKS(vtoc->efi_nparts, vtoc->efi_lbasize) < 34) {
+ dk_ioc.dki_length = EFI_MIN_ARRAY_SIZE + vtoc->efi_lbasize;
+ } else {
+ dk_ioc.dki_length = NBLOCKS(vtoc->efi_nparts,
+ vtoc->efi_lbasize) *
+ vtoc->efi_lbasize;
+ }
+
+ if ((dk_ioc.dki_data = calloc(dk_ioc.dki_length, 1)) == NULL)
+ return (VT_ERROR);
+
+ efi = dk_ioc.dki_data;
+
+ /* stuff user's input into EFI struct */
+ efi->efi_gpt_Signature = LE_64(EFI_SIGNATURE);
+ efi->efi_gpt_Revision = LE_32(vtoc->efi_version); /* 0x02000100 */
+ efi->efi_gpt_HeaderSize = LE_32(sizeof (struct efi_gpt));
+ efi->efi_gpt_Reserved1 = 0;
+ efi->efi_gpt_MyLBA = LE_64(1ULL);
+ efi->efi_gpt_AlternateLBA = LE_64(vtoc->efi_last_lba);
+ efi->efi_gpt_FirstUsableLBA = LE_64(vtoc->efi_first_u_lba);
+ efi->efi_gpt_LastUsableLBA = LE_64(vtoc->efi_last_u_lba);
+ efi->efi_gpt_PartitionEntryLBA = LE_64(2ULL);
+ efi->efi_gpt_NumberOfPartitionEntries = LE_32(vtoc->efi_nparts);
+ efi->efi_gpt_SizeOfPartitionEntry = LE_32(sizeof (struct efi_gpe));
+ UUID_LE_CONVERT(efi->efi_gpt_DiskGUID, vtoc->efi_disk_uguid);
+
+ /* LINTED -- always longlong aligned */
+ efi_parts = (efi_gpe_t *)((char *)dk_ioc.dki_data + sizeof (efi_gpt_t));
+
+ for (i = 0; i < vtoc->efi_nparts; i++) {
+ for (j = 0;
+ j < sizeof (conversion_array) / sizeof (struct uuid_to_ptag);
+ j++) {
+
+ if (vtoc->efi_parts[i].p_tag == j) {
+ UUID_LE_CONVERT(
+ efi_parts[i].efi_gpe_PartitionTypeGUID,
+ conversion_array[j].uuid);
+ }
+ }
+ efi_parts[i].efi_gpe_StartingLBA =
+ LE_64(vtoc->efi_parts[i].p_start);
+ efi_parts[i].efi_gpe_EndingLBA =
+ LE_64(vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size - 1);
+ efi_parts[i].efi_gpe_Attributes.PartitionAttrs =
+ LE_16(vtoc->efi_parts[i].p_flag);
+ for (j = 0; j < EFI_PART_NAME_LEN; j++) {
+ efi_parts[i].efi_gpe_PartitionName[j] =
+ LE_16((ushort_t)vtoc->efi_parts[i].p_name[j]);
+ }
+ if ((vtoc->efi_parts[i].p_tag != V_UNASSIGNED) &&
+ uuid_is_null((uchar_t *)&vtoc->efi_parts[i].p_uguid)) {
+ (void) uuid_generate((uchar_t *)
+ &vtoc->efi_parts[i].p_uguid);
+ }
+ bcopy(&vtoc->efi_parts[i].p_uguid,
+ &efi_parts[i].efi_gpe_UniquePartitionGUID,
+ sizeof (uuid_t));
+ }
+ efi->efi_gpt_PartitionEntryArrayCRC32 =
+ LE_32(efi_crc32((unsigned char *)efi_parts,
+ vtoc->efi_nparts * (int)sizeof (struct efi_gpe)));
+ efi->efi_gpt_HeaderCRC32 =
+ LE_32(efi_crc32((unsigned char *)efi, sizeof (struct efi_gpt)));
+
+ if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) {
+ free(dk_ioc.dki_data);
+ switch (errno) {
+ case EIO:
+ return (VT_EIO);
+ case EINVAL:
+ return (VT_EINVAL);
+ default:
+ return (VT_ERROR);
+ }
+ }
+ /* if it's a metadevice we're done */
+ if (md_flag) {
+ free(dk_ioc.dki_data);
+ return (0);
+ }
+ /* write backup partition array */
+ dk_ioc.dki_lba = vtoc->efi_last_u_lba + 1;
+ dk_ioc.dki_length -= vtoc->efi_lbasize;
+ dk_ioc.dki_data++;
+ if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) {
+ /*
+ * we wrote the primary label okay, so don't fail
+ */
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "write of backup partitions to block %llu "
+ "failed, errno %d\n",
+ vtoc->efi_last_u_lba + 1,
+ errno);
+ }
+ }
+ /*
+ * now swap MyLBA and AlternateLBA fields and write backup
+ * partition table header
+ */
+ dk_ioc.dki_lba = vtoc->efi_last_lba;
+ dk_ioc.dki_length = vtoc->efi_lbasize;
+ dk_ioc.dki_data--;
+ efi->efi_gpt_AlternateLBA = LE_64(1ULL);
+ efi->efi_gpt_MyLBA = LE_64(vtoc->efi_last_lba);
+ efi->efi_gpt_PartitionEntryLBA = LE_64(vtoc->efi_last_u_lba + 1);
+ efi->efi_gpt_HeaderCRC32 = 0;
+ efi->efi_gpt_HeaderCRC32 =
+ LE_32(efi_crc32((unsigned char *)dk_ioc.dki_data,
+ sizeof (struct efi_gpt)));
+
+ if (efi_ioctl(fd, DKIOCSETEFI, &dk_ioc) == -1) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "write of backup header to block %llu failed, "
+ "errno %d\n",
+ vtoc->efi_last_lba,
+ errno);
+ }
+ }
+ /* write the PMBR */
+ (void) write_pmbr(fd, vtoc);
+ if (ioctl(fd, MHIOCREREGISTERDEVID) == -1) {
+ if (efi_debug) {
+ (void) fprintf(stderr,
+ "MHIOCREREGISTERDEVID failed %d\n",
+ errno);
+ }
+ }
+ free(dk_ioc.dki_data);
+ return (0);
+}
+
+void
+efi_free(struct dk_gpt *ptr)
+{
+ free(ptr);
+}
+
+/*
+ * Input: File descriptor
+ * Output: 1 if disk is >1TB OR has an EFI label, 0 otherwise.
+ */
+int
+efi_type(int fd)
+{
+ struct vtoc vtoc;
+
+ if (ioctl(fd, DKIOCGVTOC, &vtoc) == -1) {
+ if (errno == ENOTSUP) {
+ return (1);
+ }
+ }
+ return (0);
+}
+
+void
+efi_err_check(struct dk_gpt *vtoc)
+{
+ int resv_part = -1;
+ int i, j;
+ diskaddr_t istart, jstart, isize, jsize, endsect;
+ int overlap = 0;
+
+ /*
+ * make sure no partitions overlap
+ */
+ for (i = 0; i < vtoc->efi_nparts; i++) {
+ /* It can't be unassigned and have an actual size */
+ if ((vtoc->efi_parts[i].p_tag == V_UNASSIGNED) &&
+ (vtoc->efi_parts[i].p_size != 0)) {
+ (void) fprintf(stderr,
+ "partition %d is \"unassigned\" but has a size "
+ "of %llu\n", i, vtoc->efi_parts[i].p_size);
+ }
+ if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) {
+ continue;
+ }
+ if (vtoc->efi_parts[i].p_tag == V_RESERVED) {
+ if (resv_part != -1) {
+ (void) fprintf(stderr,
+ "found duplicate reserved partition at "
+ "%d\n", i);
+ }
+ resv_part = i;
+ if (vtoc->efi_parts[i].p_size != EFI_MIN_RESV_SIZE)
+ (void) fprintf(stderr,
+ "Warning: reserved partition size must "
+ "be %d sectors\n", EFI_MIN_RESV_SIZE);
+ }
+ if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) ||
+ (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) {
+ (void) fprintf(stderr,
+ "Partition %d starts at %llu\n",
+ i,
+ vtoc->efi_parts[i].p_start);
+ (void) fprintf(stderr,
+ "It must be between %llu and %llu.\n",
+ vtoc->efi_first_u_lba,
+ vtoc->efi_last_u_lba);
+ }
+ if ((vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size <
+ vtoc->efi_first_u_lba) ||
+ (vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size >
+ vtoc->efi_last_u_lba + 1)) {
+ (void) fprintf(stderr,
+ "Partition %d ends at %llu\n",
+ i,
+ vtoc->efi_parts[i].p_start +
+ vtoc->efi_parts[i].p_size);
+ (void) fprintf(stderr,
+ "It must be between %llu and %llu.\n",
+ vtoc->efi_first_u_lba,
+ vtoc->efi_last_u_lba);
+ }
+
+ for (j = 0; j < vtoc->efi_nparts; j++) {
+ isize = vtoc->efi_parts[i].p_size;
+ jsize = vtoc->efi_parts[j].p_size;
+ istart = vtoc->efi_parts[i].p_start;
+ jstart = vtoc->efi_parts[j].p_start;
+ if ((i != j) && (isize != 0) && (jsize != 0)) {
+ endsect = jstart + jsize -1;
+ if ((jstart <= istart) &&
+ (istart <= endsect)) {
+ if (!overlap) {
+ (void) fprintf(stderr,
+ "label error: EFI Labels do not "
+ "support overlapping partitions\n");
+ }
+ (void) fprintf(stderr,
+ "Partition %d overlaps partition "
+ "%d.\n", i, j);
+ overlap = 1;
+ }
+ }
+ }
+ }
+ /* make sure there is a reserved partition */
+ if (resv_part == -1) {
+ (void) fprintf(stderr,
+ "no reserved partition found\n");
+ }
+}
+
+/*
+ * We need to get information necessary to construct a *new* efi
+ * label type
+ */
+int
+efi_auto_sense(int fd, struct dk_gpt **vtoc)
+{
+
+ int i;
+
+ /*
+ * Now build the default partition table
+ */
+ if (efi_alloc_and_init(fd, EFI_NUMPAR, vtoc) != 0) {
+ if (efi_debug) {
+ (void) fprintf(stderr, "efi_alloc_and_init failed.\n");
+ }
+ return (-1);
+ }
+
+ for (i = 0; i < min((*vtoc)->efi_nparts, V_NUMPAR); i++) {
+ (*vtoc)->efi_parts[i].p_tag = default_vtoc_map[i].p_tag;
+ (*vtoc)->efi_parts[i].p_flag = default_vtoc_map[i].p_flag;
+ (*vtoc)->efi_parts[i].p_start = 0;
+ (*vtoc)->efi_parts[i].p_size = 0;
+ }
+ /*
+ * Make constants first
+ * and variable partitions later
+ */
+
+ /* root partition - s0 128 MB */
+ (*vtoc)->efi_parts[0].p_start = 34;
+ (*vtoc)->efi_parts[0].p_size = 262144;
+
+ /* partition - s1 128 MB */
+ (*vtoc)->efi_parts[1].p_start = 262178;
+ (*vtoc)->efi_parts[1].p_size = 262144;
+
+ /* partition -s2 is NOT the Backup disk */
+ (*vtoc)->efi_parts[2].p_tag = V_UNASSIGNED;
+
+ /* partition -s6 /usr partition - HOG */
+ (*vtoc)->efi_parts[6].p_start = 524322;
+ (*vtoc)->efi_parts[6].p_size = (*vtoc)->efi_last_u_lba - 524322
+ - (1024 * 16);
+
+ /* efi reserved partition - s9 16K */
+ (*vtoc)->efi_parts[8].p_start = (*vtoc)->efi_last_u_lba - (1024 * 16);
+ (*vtoc)->efi_parts[8].p_size = (1024 * 16);
+ (*vtoc)->efi_parts[8].p_tag = V_RESERVED;
+ return (0);
+}
diff --git a/usr/src/lib/libefi/i386/Makefile b/usr/src/lib/libefi/i386/Makefile
new file mode 100644
index 0000000000..0c05212571
--- /dev/null
+++ b/usr/src/lib/libefi/i386/Makefile
@@ -0,0 +1,31 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+include ../Makefile.com
+
+install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
diff --git a/usr/src/lib/libefi/sparc/Makefile b/usr/src/lib/libefi/sparc/Makefile
new file mode 100644
index 0000000000..0c05212571
--- /dev/null
+++ b/usr/src/lib/libefi/sparc/Makefile
@@ -0,0 +1,31 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+include ../Makefile.com
+
+install: all $(ROOTLIBS) $(ROOTLINKS) $(ROOTLINT)
diff --git a/usr/src/lib/libefi/sparcv9/Makefile b/usr/src/lib/libefi/sparcv9/Makefile
new file mode 100644
index 0000000000..c522671f45
--- /dev/null
+++ b/usr/src/lib/libefi/sparcv9/Makefile
@@ -0,0 +1,36 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+include ../Makefile.com
+include ../../Makefile.lib.64
+
+LIBS = $(DYNLIB) $(LINTLIB)
+
+all: $(LIBS)
+
+install: all $(ROOTLIBS64) $(ROOTLINKS64)
diff --git a/usr/src/lib/libefi/spec/Makefile b/usr/src/lib/libefi/spec/Makefile
new file mode 100644
index 0000000000..631c5dd98c
--- /dev/null
+++ b/usr/src/lib/libefi/spec/Makefile
@@ -0,0 +1,29 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# lib/libefi/spec/Makefile
+
+include $(SRC)/lib/Makefile.spec.arch
diff --git a/usr/src/lib/libefi/spec/Makefile.targ b/usr/src/lib/libefi/spec/Makefile.targ
new file mode 100644
index 0000000000..93620cea6d
--- /dev/null
+++ b/usr/src/lib/libefi/spec/Makefile.targ
@@ -0,0 +1,34 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# lib/libadm/spec/Makefile.targ
+
+LIBRARY = libefi.a
+VERS = .1
+
+OBJECTS = efi.o
+
+SPECCPP =
diff --git a/usr/src/lib/libefi/spec/amd64/Makefile b/usr/src/lib/libefi/spec/amd64/Makefile
new file mode 100644
index 0000000000..5dd1b7240f
--- /dev/null
+++ b/usr/src/lib/libefi/spec/amd64/Makefile
@@ -0,0 +1,42 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.lib.64
+
+# Uncomment the following if the linker complains
+#amd64_C_PICFLAGS = $(amd64_C_BIGPICFLAGS)
+
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB64)
diff --git a/usr/src/lib/libefi/spec/efi.spec b/usr/src/lib/libefi/spec/efi.spec
new file mode 100644
index 0000000000..9957cccbf4
--- /dev/null
+++ b/usr/src/lib/libefi/spec/efi.spec
@@ -0,0 +1,79 @@
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#pragma ident "%Z%%M% %I% %E% SMI"
+#
+# lib/libefi/spec/efi.spec
+
+# EFI reading/writing
+function efi_alloc_and_init
+include <sys/types.h>, <sys/vtoc.h>, <sys/efi_partition.h>
+declaration int efi_alloc_and_init(int, uint32_t, struct dk_gpt **)
+version SUNW_1.1
+exception $return < 0
+end
+
+# EFI reading/writing
+function efi_alloc_and_read
+include <sys/types.h>, <sys/vtoc.h>, <sys/efi_partition.h>
+declaration int efi_alloc_and_read(int, struct dk_gpt **)
+version SUNW_1.1
+exception $return < 0
+end
+
+# EFI reading/writing
+function efi_write
+include <sys/types.h>, <sys/vtoc.h>, <sys/efi_partition.h>
+declaration int efi_write(int , struct dk_gpt *)
+version SUNW_1.1
+exception $return < 0
+end
+
+# EFI reading/writing
+function efi_free
+include <stdlib.h>
+declaration void efi_free(struct dk_gpt *)
+version SUNW_1.1
+end
+
+# EFI type
+function efi_type
+include <sys/vtoc.h>, <errno.h>
+declaration int efi_type(int fd)
+version SUNWprivate_1.1
+end
+
+# EFI error check
+function efi_err_check
+include <sys/vtoc.h>, <sys/efi_partition.h>
+declaration void efi_err_check(struct dk_gpt *vtoc)
+version SUNWprivate_1.1
+end
+
+# EFI auto sense
+function efi_auto_sense
+include <sys/vtoc.h>, <sys/efi_partition.h>
+declaration int efi_auto_sense(int fd, struct dk_gpt **vtoc)
+version SUNWprivate_1.1
+end
diff --git a/usr/src/lib/libefi/spec/i386/Makefile b/usr/src/lib/libefi/spec/i386/Makefile
new file mode 100644
index 0000000000..e1550e7f62
--- /dev/null
+++ b/usr/src/lib/libefi/spec/i386/Makefile
@@ -0,0 +1,42 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# lib/libefi/spec/i386/Makefile
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+
+# Uncomment the following if the linker complains
+#i386_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB)
diff --git a/usr/src/lib/libefi/spec/sparc/Makefile b/usr/src/lib/libefi/spec/sparc/Makefile
new file mode 100644
index 0000000000..13c653d998
--- /dev/null
+++ b/usr/src/lib/libefi/spec/sparc/Makefile
@@ -0,0 +1,44 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# lib/libefi/spec/sparc/Makefile
+
+.KEEP_STATE:
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+
+# Uncomment the following if the linker complains
+#sparc_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB)
diff --git a/usr/src/lib/libefi/spec/sparcv9/Makefile b/usr/src/lib/libefi/spec/sparcv9/Makefile
new file mode 100644
index 0000000000..35aa251bbd
--- /dev/null
+++ b/usr/src/lib/libefi/spec/sparcv9/Makefile
@@ -0,0 +1,43 @@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+#
+#ident "%Z%%M% %I% %E% SMI"
+#
+# Copyright 2002 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# lib/libefi/spec/sparcv9/Makefile
+
+include ../Makefile.targ
+
+# Add arch specific objects here
+OBJECTS +=
+
+include $(SRC)/lib/Makefile.lib
+include $(SRC)/lib/Makefile.lib.64
+
+# Uncomment the following if the linker complains
+# sparcv9_C_PICFLAGS = -K PIC
+
+include $(SRC)/lib/Makefile.spec
+
+install: $(ROOTABILIB64)
diff --git a/usr/src/lib/libefi/spec/versions b/usr/src/lib/libefi/spec/versions
new file mode 100644
index 0000000000..dc2cad2ce6
--- /dev/null
+++ b/usr/src/lib/libefi/spec/versions
@@ -0,0 +1,47 @@
+#
+# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License, Version 1.0 only
+# (the "License"). You may not use this file except in compliance
+# with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+# ident "%Z%%M% %I% %E% SMI"
+#
+
+sparc {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}
+
+sparcv9 {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}
+
+
+i386 {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}
+
+amd64 {
+ SUNW_1.1;
+ SUNWprivate_1.1;
+}