man pages section 3: Extended Library Functions, Volume 1

Exit Print View

Updated: July 2014
 
 

efi_alloc_and_init(3EXT)

Name

efi_alloc_and_init, efi_alloc_and_read, efi_free, efi_write, efi_use_whole_disk - manipulate a disk's EFI Partition Table

Synopsis

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);

Description

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 sturcture. 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.

The efi_use_whole_disk() function takes any space that is not contained in the disk label and adds it into the EFI label. If the reserved partition is right before the backup label, add the space to the last physically non-zero area before the reserved partition. Otherwise, add the space to the last physically non-zero area before the backup label.

The fd argument refers to any partition 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;      /* index of last user-defined  */
                                /* (non-zero) partition in efi_parts */
                                /* plus one */
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 */
uint_t         efi_num_of_partition_entries /* number of partitions */
                                /* in efi_parts, representing actual */
                                /* GUID partition entries allocated */
                                /* on disk */
struct dk_part efi_parts[];     /* array of partitions */

Return Values

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 partition 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.

VT_ERROR

An unknown error occurred.

VT_EINVAL

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.

VT_ERROR

An unknown error occurred.

VT_EINVAL

The label contains incorrect data.

Upon successful 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.

VT_ERROR

An unknown error occurred.

VT_EINVAL

The label contains incorrect data.

VT_ENOSPC

Space out of label was not found.

Attributes

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE
ATTRIBUTE VALUE
Interface Stability
Committed
MT-Level
Unsafe

See Also

fmthard(1M), format(1M), prtvtoc(1M), ioctl(2), open(2), libefi(3LIB), read_vtoc(3EXT), attributes(5), dkio(7I)