Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
The contents of this file are subject to the terms of the Common Development and Distribution License (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]
cc [ flag .\|.\|. ] file.\|.\|. -lefi [ library .\|.\|. ] #include <sys/vtoc.h> #include <sys/efi_partition.h> int efi_alloc_and_init(int fd, uint32_t nparts, dk_gpt_t **vtoc);
int efi_alloc_and_read(int fd, dk_gpt_t **vtoc);
void efi_free(dk_gpt_t *vtoc);
int efi_write(int fd, dk_gpt_t *vtoc);
int efi_use_whole_disk(int fd);
The efi_alloc_and_init() function initializes the dk_gpt_t structure specified by vtoc in preparation for a call to efi_write(). It calculates and initializes the efi_version, efi_lbasize, efi_nparts, efi_first_u_lba, efi_last_lba, and efi_last_u_lba members of this structure. The caller can then set the efi_nparts member.
The efi_alloc_and_read() function allocates memory and returns the partition table.
The efi_free() function frees the memory allocated by efi_alloc_and_init() and efi_alloc_and_read().
The efi_write() function writes the EFI partition table and creates a Protective Master Boot Record (PMBR); see below.
The efi_use_whole_disk() function takes any space that is not contained in the disk label and adds it to the last physically non-zero area before the reserved slice (from slice 0 to slice 6 or unallocated space).
The fd argument refers to any slice on a raw disk, opened with O_NDELAY. See open(2).
The nparts argument specifies the number of desired partitions.
The vtoc argument is a dk_gpt_t structure that describes an EFI partition table and contains at least the following members:
uint_t efi_version; /* set to EFI_VERSION_CURRENT */ uint_t efi_nparts; /* no. of partitions in efi_parts */ uint_t efi_lbasize; /* size of block in bytes */ diskaddr_t efi_last_lba; /* last block on the disk */ diskaddr_t efi_first_u_lba; /* first block after labels */ diskaddr_t efi_last_u_lba; /* last block before backup labels */ struct dk_part efi_parts[]; /* array of partitions */
When a disk receives an EFI label, a protective MBR (PMBR) is also written containing a single partiton of type EEh and spanning the entire disk (up to the limit of what can be represented in an MBR). By default that partition is placed in slot 0 of the PMBR and not marked as active. Some BIOS implementations contain bugs that require the entry to be placed into a different slot or to be made active in order for the system to boot successfully. The default behaviour is modified for systems with known firmware bugs, refer to /usr/share/hwdata/efi.fixes for more information.
Upon successful completion, efi_alloc_and_init() returns 0. Otherwise it returns VT_EIO if an I/O operation to the disk fails.
Upon successful completion, efi_alloc_and_read() returns a positive integer indicating the slice index associated with the open file descriptor. Otherwise, it returns a negative integer to indicate one of the following: VT_EIO
An I/O error occurred.
An unknown error occurred.
An EFI label was not found.
Upon successful completion, efi_write() returns 0. Otherwise, it returns a negative integer to indicate one of the following: VT_EIO
An I/O error occurred.
An unknown error occurred.
The label contains incorrect data.
Upon successfully completion, efi_use_whole_disk() returns 0. Otherwise, it returns a negative integer to indicate one of the following: VT_EIO
An I/O error occurred.
An unknown error occurred.
The label contains incorrect data.
Space out of label was not found.
The EFI label is used on disks with more than 1^32-1 blocks. For compatibility reasons, the read_vtoc(3EXT) and write_vtoc() functions should be used on smaller disks. The application should attempt the read_vtoc() or write_vtoc() call, check for an error of VT_ENOTSUP, then call the analogous EFI function.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE ATTRIBUTE VALUE |
Interface Stability Committed |
MT-Level Unsafe |
fmthard(1M), format(1M), prtvtoc(1M), ioctl(2), open(2), libefi(3LIB), read_vtoc(3EXT), attributes(5), dkio(7I)