1 '\" te
   2 .\" Copyright (c) 2008, Sun Microsystems, Inc. All Rights Reserved.
   3 .\" Copyright 2018 OmniOS Community Edition (OmniOSce) Association.
   4 .\" 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.
   5 .\" 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.
   6 .\" 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]
   7 .TH EFI_ALLOC_AND_INIT 3EXT "November 20, 2019"
   8 .SH NAME
   9 efi_alloc_and_init, efi_alloc_and_read, efi_free, efi_write, efi_use_whole_disk,
  10 efi_reserved_sectors \- manipulate a disk's EFI Partition Table
  11 .SH SYNOPSIS
  12 .nf
  13 cc [ \fIflag \&.\|.\|.\fR ] \fIfile\fR\&.\|.\|. \fB-lefi\fR [ \fIlibrary \&.\|.\|.\fR ]
  14 #include <sys/vtoc.h>
  15 #include <sys/efi_partition.h>
  16 
  17 \fBint\fR \fBefi_alloc_and_init\fR(\fBint\fR \fIfd\fR, \fBuint32_t\fR \fInparts\fR, \fBdk_gpt_t **\fR\fIvtoc\fR);
  18 .fi
  19 
  20 .LP
  21 .nf
  22 \fBint\fR \fBefi_alloc_and_read\fR(\fBint\fR \fIfd\fR, \fBdk_gpt_t **\fR\fIvtoc\fR);
  23 .fi
  24 
  25 .LP
  26 .nf
  27 \fBvoid\fR \fBefi_free\fR(\fBdk_gpt_t *\fR\fIvtoc\fR);
  28 .fi
  29 
  30 .LP
  31 .nf
  32 \fBint\fR \fBefi_write\fR(\fBint\fR \fIfd\fR, \fBdk_gpt_t *\fR\fIvtoc\fR);
  33 .fi
  34 
  35 .LP
  36 .nf
  37 \fBint\fR \fBefi_use_whole_disk\fR(\fBint\fR \fIfd\fR);
  38 .fi
  39 
  40 .LP
  41 .nf
  42 \fBuint_t\fR \fBefi_reserved_sectors\fR(\fBdk_gpt_t *\fR\fIvtoc\fR);
  43 .fi
  44 
  45 .SH DESCRIPTION
  46 The \fBefi_alloc_and_init()\fR function initializes the \fBdk_gpt_t\fR
  47 structure specified by \fIvtoc\fR in preparation for a call to
  48 \fBefi_write()\fR. It calculates and initializes the \fBefi_version\fR,
  49 \fBefi_lbasize\fR, \fBefi_nparts\fR, \fBefi_first_u_lba\fR, \fBefi_last_lba\fR,
  50 and \fBefi_last_u_lba\fR members of this structure. The caller can then set the
  51 \fBefi_nparts\fR member.
  52 .sp
  53 .LP
  54 The \fBefi_alloc_and_read()\fR function allocates memory and returns the
  55 partition table.
  56 .sp
  57 .LP
  58 The \fBefi_free()\fR function frees the memory allocated by
  59 \fBefi_alloc_and_init()\fR and \fBefi_alloc_and_read()\fR.
  60 .sp
  61 .LP
  62 The \fBefi_write()\fR function writes the EFI partition table and creates a
  63 Protective Master Boot Record (PMBR); see below.
  64 .sp
  65 .LP
  66 The \fBefi_use_whole_disk()\fR function takes any space that is not contained
  67 in the disk label and adds it to the last physically non-zero area before the
  68 reserved slice (from slice 0 to slice 6 or unallocated space).
  69 .sp
  70 .LP
  71 The \fBefi_reserved_sectors()\fR function calculates number of sectors
  72 needed to create the reserved partition. The reserved partition is used
  73 by the operating system for internal purposes. The sector size used is
  74 based on the device and is recorded in the \fBefi_lbasize\fR member of
  75 the \fBdkgpt_t\fR structure indicated by the \fIvtoc\fR argument.
  76 A full description of the \fBdk_gpt_t\fR structure appears later in the manual.
  77 .sp
  78 .LP
  79 The \fIfd\fR argument refers to any slice on a raw disk, opened with
  80 \fBO_NDELAY\fR. See \fBopen\fR(2).
  81 .sp
  82 .LP
  83 The \fInparts\fR argument specifies the number of desired partitions.
  84 .sp
  85 .LP
  86 The \fIvtoc\fR argument is a \fBdk_gpt_t\fR structure that describes an EFI
  87 partition table and contains at least the following members:
  88 .sp
  89 .in +2
  90 .nf
  91 uint_t          efi_version;     /* set to EFI_VERSION_CURRENT */
  92 uint_t          efi_nparts;      /* no. of partitions in efi_parts */
  93 uint_t          efi_lbasize;     /* size of block in bytes */
  94 diskaddr_t      efi_last_lba;    /* last block on the disk */
  95 diskaddr_t      efi_first_u_lba; /* first block after labels */
  96 diskaddr_t      efi_last_u_lba;  /* last block before backup labels */
  97 struct dk_part  efi_parts[];     /* array of partitions */
  98 .fi
  99 .in -2
 100 
 101 .SS "Protective Master Boot Record"
 102 When a disk receives an EFI label, a protective MBR (\fBPMBR\fR) is also
 103 written containing a single partiton of type \fBEEh\fR and spanning the
 104 entire disk (up to the limit of what can be represented in an MBR). By
 105 default that partition is placed in slot 0 of the PMBR and not marked as
 106 active. Some BIOS implementations contain bugs that require the entry to be
 107 placed into a different slot or to be made active in order for the system
 108 to boot successfully. The default behaviour is modified for systems with known
 109 firmware bugs, refer to \fB/usr/share/hwdata/efi.fixes\fR for more
 110 information.
 111 
 112 .SH RETURN VALUES
 113 Upon successful completion, \fBefi_alloc_and_init()\fR returns 0. Otherwise it
 114 returns \fBVT_EIO\fR if an I/O operation to the disk fails.
 115 .sp
 116 .LP
 117 Upon successful completion, \fBefi_alloc_and_read()\fR returns a positive
 118 integer indicating the slice index associated with the open file descriptor.
 119 Otherwise, it returns a negative integer to indicate one of the following:
 120 .sp
 121 .ne 2
 122 .na
 123 \fB\fBVT_EIO\fR\fR
 124 .ad
 125 .RS 13n
 126 An I/O error occurred.
 127 .RE
 128 
 129 .sp
 130 .ne 2
 131 .na
 132 \fB\fBVT_ERROR\fR\fR
 133 .ad
 134 .RS 13n
 135 An unknown error occurred.
 136 .RE
 137 
 138 .sp
 139 .ne 2
 140 .na
 141 \fB\fBVT_EINVAL\fR\fR
 142 .ad
 143 .RS 13n
 144 An EFI label was not found.
 145 .RE
 146 
 147 .sp
 148 .LP
 149 The \fBefi_reserved_sectors()\fR function always returns the number of
 150 reserved sectors required. It will always succeed.
 151 
 152 .sp
 153 .LP
 154 Upon successful completion, \fBefi_write()\fR returns 0. Otherwise, it returns
 155 a negative integer to indicate one of the following:
 156 .sp
 157 .ne 2
 158 .na
 159 \fB\fBVT_EIO\fR\fR
 160 .ad
 161 .RS 13n
 162 An I/O error occurred.
 163 .RE
 164 
 165 .sp
 166 .ne 2
 167 .na
 168 \fB\fBVT_ERROR\fR\fR
 169 .ad
 170 .RS 13n
 171 An unknown error occurred.
 172 .RE
 173 
 174 .sp
 175 .ne 2
 176 .na
 177 \fB\fBVT_EINVAL\fR\fR
 178 .ad
 179 .RS 13n
 180 The label contains incorrect data.
 181 .RE
 182 
 183 .sp
 184 .LP
 185 Upon successfully completion, \fBefi_use_whole_disk()\fR returns 0. Otherwise,
 186 it returns a negative integer to indicate one of the following:
 187 .sp
 188 .ne 2
 189 .na
 190 \fB\fBVT_EIO\fR\fR
 191 .ad
 192 .RS 13n
 193 An I/O error occurred.
 194 .RE
 195 
 196 .sp
 197 .ne 2
 198 .na
 199 \fB\fBVT_ERROR\fR\fR
 200 .ad
 201 .RS 13n
 202 An unknown error occurred.
 203 .RE
 204 
 205 .sp
 206 .ne 2
 207 .na
 208 \fB\fBVT_EINVAL\fR\fR
 209 .ad
 210 .RS 13n
 211 The label contains incorrect data.
 212 .RE
 213 
 214 .sp
 215 .ne 2
 216 .na
 217 \fB\fBVT_ENOSPC\fR\fR
 218 .ad
 219 .RS 13n
 220 Space out of label was not found.
 221 .RE
 222 
 223 .SH USAGE
 224 The EFI label is used on disks with more than 1^32-1 blocks. For compatibility
 225 reasons, the \fBread_vtoc\fR(3EXT) and \fBwrite_vtoc()\fR functions should be
 226 used on smaller disks. The application should attempt the \fBread_vtoc()\fR or
 227 \fBwrite_vtoc()\fR call, check for an error of \fBVT_ENOTSUP\fR, then call the
 228 analogous EFI function.
 229 .SH ATTRIBUTES
 230 See \fBattributes\fR(5) for descriptions of the following attributes:
 231 .sp
 232 
 233 .sp
 234 .TS
 235 box;
 236 c | c
 237 l | l .
 238 ATTRIBUTE TYPE  ATTRIBUTE VALUE
 239 _
 240 Interface Stability     Committed
 241 _
 242 MT-Level        Unsafe
 243 .TE
 244 
 245 .SH SEE ALSO
 246 \fBfmthard\fR(1M), \fBformat\fR(1M), \fBprtvtoc\fR(1M), \fBioctl\fR(2),
 247 \fBopen\fR(2), \fBlibefi\fR(3LIB), \fBread_vtoc\fR(3EXT), \fBattributes\fR(5),
 248 \fBdkio\fR(7I)