# HG changeset patch # User Toomas Soome # Date 1574241468 -7200 # Node ID 6ede5d6cae835a3f17b2c28404be3dae9294bc4b # Parent 2ea982aef0acc1d527b994023414425bf1947ebd 12003 libefi: add efi_reserved_sectors() Reviewed by: John Levon Reviewed by: Robert Mustacchi Approved by: Dan McDonald diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/lib/libefi/common/mapfile-vers --- a/usr/src/lib/libefi/common/mapfile-vers Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/lib/libefi/common/mapfile-vers Wed Nov 20 11:17:48 2019 +0200 @@ -38,6 +38,11 @@ $mapfile_version 2 +SYMBOL_VERSION ILLUMOS_0.1 { + global: + efi_reserved_sectors; +} SUNW_1.2; + SYMBOL_VERSION SUNW_1.2 { global: efi_use_whole_disk; diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/lib/libefi/common/rdwr_efi.c --- a/usr/src/lib/libefi/common/rdwr_efi.c Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/lib/libefi/common/rdwr_efi.c Wed Nov 20 11:17:48 2019 +0200 @@ -154,6 +154,19 @@ #define MAX_PARTS ((4294967295UL - sizeof (struct dk_gpt)) / \ sizeof (struct dk_part)) +/* + * The EFI reserved partition size is 8 MiB. This calculates the number of + * sectors required to store 8 MiB, taking into account the device's sector + * size. + */ +uint_t +efi_reserved_sectors(dk_gpt_t *efi) +{ + /* roundup to sector size */ + return ((EFI_MIN_RESV_SIZE * DEV_BSIZE + efi->efi_lbasize - 1) / + efi->efi_lbasize); +} + int efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc) { @@ -939,7 +952,7 @@ * physically non-zero partition. */ if (pl_start + pl_size - 1 == efi_label->efi_last_u_lba - - EFI_MIN_RESV_SIZE) { + efi_reserved_sectors(efi_label)) { efi_label->efi_parts[phy_last_slice].p_size += efi_label->efi_last_lba - efi_label->efi_altern_lba; } @@ -1194,10 +1207,12 @@ int i, j; diskaddr_t istart, jstart, isize, jsize, endsect; int overlap = 0; + uint_t reserved; /* * make sure no partitions overlap */ + reserved = efi_reserved_sectors(vtoc); 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) && @@ -1216,10 +1231,10 @@ "%d\n", i); } resv_part = i; - if (vtoc->efi_parts[i].p_size != EFI_MIN_RESV_SIZE) + if (vtoc->efi_parts[i].p_size != reserved) (void) fprintf(stderr, "Warning: reserved partition size must " - "be %d sectors\n", EFI_MIN_RESV_SIZE); + "be %u sectors\n", reserved); } if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) || (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) { diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/man/man3ext/Makefile --- a/usr/src/man/man3ext/Makefile Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/man/man3ext/Makefile Wed Nov 20 11:17:48 2019 +0200 @@ -16,28 +16,28 @@ include $(SRC)/Makefile.master -MANSECT= 3ext +MANSECT= 3ext -MANFILES= NOTE.3ext \ - SUNW_C_GetMechSession.3ext \ - auto_ef.3ext \ - crypt.3ext \ - demangle.3ext \ - ecb_crypt.3ext \ - efi_alloc_and_init.3ext \ - ld_support.3ext \ - md4.3ext \ - md5.3ext \ - read_vtoc.3ext \ - rtld_audit.3ext \ - rtld_db.3ext \ - sendfile.3ext \ - sendfilev.3ext \ - sha1.3ext \ - sha2.3ext \ - stdarg.3ext \ - tsalarm_get.3ext \ - varargs.3ext +MANFILES= NOTE.3ext \ + SUNW_C_GetMechSession.3ext \ + auto_ef.3ext \ + crypt.3ext \ + demangle.3ext \ + ecb_crypt.3ext \ + efi_alloc_and_init.3ext \ + ld_support.3ext \ + md4.3ext \ + md5.3ext \ + read_vtoc.3ext \ + rtld_audit.3ext \ + rtld_db.3ext \ + sendfile.3ext \ + sendfilev.3ext \ + sha1.3ext \ + sha2.3ext \ + stdarg.3ext \ + tsalarm_get.3ext \ + varargs.3ext MANLINKS= DES_FAILED.3ext \ MD4Final.3ext \ @@ -77,6 +77,7 @@ des_setparity.3ext \ efi_alloc_and_read.3ext \ efi_free.3ext \ + efi_reserved_sectors.3ext \ efi_use_whole_disk.3ext \ efi_write.3ext \ encrypt.3ext \ @@ -154,6 +155,7 @@ efi_alloc_and_read.3ext := LINKSRC = efi_alloc_and_init.3ext efi_free.3ext := LINKSRC = efi_alloc_and_init.3ext +efi_reserved_sectors.3ext := LINKSRC = efi_alloc_and_init.3ext efi_use_whole_disk.3ext := LINKSRC = efi_alloc_and_init.3ext efi_write.3ext := LINKSRC = efi_alloc_and_init.3ext diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/man/man3ext/efi_alloc_and_init.3ext --- a/usr/src/man/man3ext/efi_alloc_and_init.3ext Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/man/man3ext/efi_alloc_and_init.3ext Wed Nov 20 11:17:48 2019 +0200 @@ -4,12 +4,11 @@ .\" 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 "February 6, 2018" +.TH EFI_ALLOC_AND_INIT 3EXT "November 20, 2019" .SH NAME -efi_alloc_and_init, efi_alloc_and_read, efi_free, efi_write, efi_use_whole_disk -\- manipulate a disk's EFI Partition Table +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 -.LP .nf cc [ \fIflag \&.\|.\|.\fR ] \fIfile\fR\&.\|.\|. \fB-lefi\fR [ \fIlibrary \&.\|.\|.\fR ] #include @@ -38,8 +37,12 @@ \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 -.LP 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, @@ -65,6 +68,14 @@ 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 @@ -88,7 +99,6 @@ .in -2 .SS "Protective Master Boot Record" -.LP When a disk receives an EFI label, a protective MBR (\fBPMBR\fR) is also written containing a single partiton of type \fBEEh\fR and spanning the entire disk (up to the limit of what can be represented in an MBR). By @@ -100,7 +110,6 @@ information. .SH RETURN VALUES -.LP 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 @@ -137,6 +146,11 @@ .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 @@ -207,14 +221,12 @@ .RE .SH USAGE -.LP 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 -.LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -231,7 +243,6 @@ .TE .SH SEE ALSO -.LP \fBfmthard\fR(1M), \fBformat\fR(1M), \fBprtvtoc\fR(1M), \fBioctl\fR(2), \fBopen\fR(2), \fBlibefi\fR(3LIB), \fBread_vtoc\fR(3EXT), \fBattributes\fR(5), \fBdkio\fR(7I) diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/man/man3lib/libefi.3lib --- a/usr/src/man/man3lib/libefi.3lib Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/man/man3lib/libefi.3lib Wed Nov 20 11:17:48 2019 +0200 @@ -3,22 +3,17 @@ .\" 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 LIBEFI 3LIB "May 8, 2008" +.TH LIBEFI 3LIB "November 20, 2019" .SH NAME libefi \- EFI partition table library .SH SYNOPSIS -.LP .nf cc [ \fIflag\fR... ] \fIfile\fR... \fB-lefi\fR [ \fIlibrary\fR... ] .fi .SH DESCRIPTION -.sp -.LP The functions in this library manipulate a disk's EFI partition table. .SH INTERFACES -.sp -.LP The shared object \fBlibefi.so.1\fR provides the public interfaces defined below. See \fBIntro\fR(3) for additional information on shared object interfaces. @@ -29,12 +24,11 @@ l l l l . \fBefi_alloc_and_init\fR \fBefi_alloc_and_read\fR -\fBefi_free\fR \fBefi_use_whole_disk\fR -\fBefi_write\fR +\fBefi_free\fR \fBefi_reserved_sectors\fR +\fBefi_use_whole_disk\fR \fBefi_write\fR .TE .SH FILES -.sp .ne 2 .na \fB\fB/lib/libefi.so.1\fR\fR @@ -53,8 +47,6 @@ .RE .SH ATTRIBUTES -.sp -.LP See \fBattributes\fR(5) for descriptions of the following attributes: .sp @@ -71,6 +63,4 @@ .TE .SH SEE ALSO -.sp -.LP \fBIntro\fR(3), \fBefi_alloc_and_init\fR(3EXT), \fBattributes\fR(5) diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/pkg/manifests/system-library.man3ext.inc --- a/usr/src/pkg/manifests/system-library.man3ext.inc Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/pkg/manifests/system-library.man3ext.inc Wed Nov 20 11:17:48 2019 +0200 @@ -74,6 +74,8 @@ link path=usr/share/man/man3ext/efi_alloc_and_read.3ext \ target=efi_alloc_and_init.3ext link path=usr/share/man/man3ext/efi_free.3ext target=efi_alloc_and_init.3ext +link path=usr/share/man/man3ext/efi_reserved_sectors.3ext \ + target=efi_alloc_and_init.3ext link path=usr/share/man/man3ext/efi_use_whole_disk.3ext \ target=efi_alloc_and_init.3ext link path=usr/share/man/man3ext/efi_write.3ext target=efi_alloc_and_init.3ext diff -r 2ea982aef0ac -r 6ede5d6cae83 usr/src/uts/common/sys/efi_partition.h --- a/usr/src/uts/common/sys/efi_partition.h Thu Nov 22 12:18:39 2018 +0200 +++ b/usr/src/uts/common/sys/efi_partition.h Wed Nov 20 11:17:48 2019 +0200 @@ -255,6 +255,7 @@ #define EFI_NUMPAR 9 #ifndef _KERNEL +extern uint_t efi_reserved_sectors(struct dk_gpt *); extern int efi_alloc_and_init(int, uint32_t, struct dk_gpt **); extern int efi_alloc_and_read(int, struct dk_gpt **); extern int efi_write(int, struct dk_gpt *);