summaryrefslogtreecommitdiff
path: root/usr/src/man/man3ext/efi_alloc_and_init.3ext
blob: 79f9500688fbc768aaf094d993d2f98ebecec3bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
'\" te
.\" 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]
.TH EFI_ALLOC_AND_INIT 3EXT "May 16, 2020"
.SH NAME
efi_alloc_and_init, efi_alloc_and_read, efi_free, efi_write, efi_use_whole_disk,
efi_reserved_sectors \- manipulate a disk's EFI Partition Table
.SH SYNOPSIS
.nf
cc [ \fIflag \&.\|.\|.\fR ] \fIfile\fR\&.\|.\|. \fB-lefi\fR [ \fIlibrary \&.\|.\|.\fR ]
#include <sys/vtoc.h>
#include <sys/efi_partition.h>

\fBint\fR \fBefi_alloc_and_init\fR(\fBint\fR \fIfd\fR, \fBuint32_t\fR \fInparts\fR, \fBdk_gpt_t **\fR\fIvtoc\fR);
.fi

.LP
.nf
\fBint\fR \fBefi_alloc_and_read\fR(\fBint\fR \fIfd\fR, \fBdk_gpt_t **\fR\fIvtoc\fR);
.fi

.LP
.nf
\fBvoid\fR \fBefi_free\fR(\fBdk_gpt_t *\fR\fIvtoc\fR);
.fi

.LP
.nf
\fBint\fR \fBefi_write\fR(\fBint\fR \fIfd\fR, \fBdk_gpt_t *\fR\fIvtoc\fR);
.fi

.LP
.nf
\fBint\fR \fBefi_use_whole_disk\fR(\fBint\fR \fIfd\fR);
.fi

.LP
.nf
\fBuint_t\fR \fBefi_reserved_sectors\fR(\fBdk_gpt_t *\fR\fIvtoc\fR);
.fi

.SH DESCRIPTION
The \fBefi_alloc_and_init()\fR function initializes the \fBdk_gpt_t\fR
structure specified by \fIvtoc\fR in preparation for a call to
\fBefi_write()\fR. It calculates and initializes the \fBefi_version\fR,
\fBefi_lbasize\fR, \fBefi_nparts\fR, \fBefi_first_u_lba\fR, \fBefi_last_lba\fR,
and \fBefi_last_u_lba\fR members of this structure. The caller can then set the
\fBefi_nparts\fR member.
.sp
.LP
The \fBefi_alloc_and_read()\fR function allocates memory and returns the
partition table.
.sp
.LP
The \fBefi_free()\fR function frees the memory allocated by
\fBefi_alloc_and_init()\fR and \fBefi_alloc_and_read()\fR.
.sp
.LP
The \fBefi_write()\fR function writes the EFI partition table and creates a
Protective Master Boot Record (PMBR); see below.
.sp
.LP
The \fBefi_use_whole_disk()\fR 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).
.sp
.LP
The \fBefi_reserved_sectors()\fR function calculates number of sectors
needed to create the reserved partition. The reserved partition is used
by the operating system for internal purposes. The sector size used is
based on the device and is recorded in the \fBefi_lbasize\fR member of
the \fBdkgpt_t\fR structure indicated by the \fIvtoc\fR argument.
A full description of the \fBdk_gpt_t\fR structure appears later in the manual.
.sp
.LP
The \fIfd\fR argument refers to any slice on a raw disk, opened with
\fBO_NDELAY\fR. See \fBopen\fR(2).
.sp
.LP
The \fInparts\fR argument specifies the number of desired partitions.
.sp
.LP
The \fIvtoc\fR argument is a \fBdk_gpt_t\fR structure that describes an EFI
partition table and contains at least the following members:
.sp
.in +2
.nf
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 */
.fi
.in -2

.SS "Protective Master Boot Record"
When a disk receives an EFI label, a protective MBR (\fBPMBR\fR) is also
written containing a single partition of type \fBEEh\fR 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 \fB/usr/share/hwdata/efi.fixes\fR for more
information.

.SH RETURN VALUES
Upon successful completion, \fBefi_alloc_and_init()\fR returns 0. Otherwise it
returns \fBVT_EIO\fR if an I/O operation to the disk fails.
.sp
.LP
Upon successful completion, \fBefi_alloc_and_read()\fR 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:
.sp
.ne 2
.na
\fB\fBVT_EIO\fR\fR
.ad
.RS 13n
An I/O error occurred.
.RE

.sp
.ne 2
.na
\fB\fBVT_ERROR\fR\fR
.ad
.RS 13n
An unknown error occurred.
.RE

.sp
.ne 2
.na
\fB\fBVT_EINVAL\fR\fR
.ad
.RS 13n
An EFI label was not found.
.RE

.sp
.LP
The \fBefi_reserved_sectors()\fR function always returns the number of
reserved sectors required. It will always succeed.

.sp
.LP
Upon successful completion, \fBefi_write()\fR returns 0. Otherwise, it returns
a negative integer to indicate one of the following:
.sp
.ne 2
.na
\fB\fBVT_EIO\fR\fR
.ad
.RS 13n
An I/O error occurred.
.RE

.sp
.ne 2
.na
\fB\fBVT_ERROR\fR\fR
.ad
.RS 13n
An unknown error occurred.
.RE

.sp
.ne 2
.na
\fB\fBVT_EINVAL\fR\fR
.ad
.RS 13n
The label contains incorrect data.
.RE

.sp
.LP
Upon successfully completion, \fBefi_use_whole_disk()\fR returns 0. Otherwise,
it returns a negative integer to indicate one of the following:
.sp
.ne 2
.na
\fB\fBVT_EIO\fR\fR
.ad
.RS 13n
An I/O error occurred.
.RE

.sp
.ne 2
.na
\fB\fBVT_ERROR\fR\fR
.ad
.RS 13n
An unknown error occurred.
.RE

.sp
.ne 2
.na
\fB\fBVT_EINVAL\fR\fR
.ad
.RS 13n
The label contains incorrect data.
.RE

.sp
.ne 2
.na
\fB\fBVT_ENOSPC\fR\fR
.ad
.RS 13n
Space out of label was not found.
.RE

.SH USAGE
The EFI label is used on disks with more than 1^32-1 blocks. For compatibility
reasons, the \fBread_vtoc\fR(3EXT) and \fBwrite_vtoc()\fR functions should be
used on smaller disks. The application should attempt the \fBread_vtoc()\fR or
\fBwrite_vtoc()\fR call, check for an error of \fBVT_ENOTSUP\fR, then call the
analogous EFI function.
.SH ATTRIBUTES
See \fBattributes\fR(7) for descriptions of the following attributes:
.sp

.sp
.TS
box;
c | c
l | l .
ATTRIBUTE TYPE	ATTRIBUTE VALUE
_
Interface Stability	Committed
_
MT-Level	Unsafe
.TE

.SH SEE ALSO
.BR ioctl (2),
.BR open (2),
.BR read_vtoc (3EXT),
.BR libefi (3LIB),
.BR dkio (4I),
.BR attributes (7),
.BR fmthard (8),
.BR format (8),
.BR prtvtoc (8)