efipart.c (313355) | efipart.c (328889) |
---|---|
1/*- 2 * Copyright (c) 2010 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2010 Marcel Moolenaar 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 11 unchanged lines hidden (view full) --- 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27#include <sys/cdefs.h> |
28__FBSDID("$FreeBSD: stable/11/sys/boot/efi/libefi/efipart.c 313355 2017-02-06 22:03:07Z tsoome $"); | 28__FBSDID("$FreeBSD: stable/11/sys/boot/efi/libefi/efipart.c 328889 2018-02-05 17:01:18Z kevans $"); |
29 30#include <sys/param.h> 31#include <sys/time.h> 32#include <stddef.h> 33#include <stdarg.h> 34 35#include <bootstrap.h> 36 37#include <efi.h> 38#include <efilib.h> 39#include <efiprot.h> 40 41static EFI_GUID blkio_guid = BLOCK_IO_PROTOCOL; 42 43static int efipart_init(void); 44static int efipart_strategy(void *, int, daddr_t, size_t, char *, size_t *); 45static int efipart_realstrategy(void *, int, daddr_t, size_t, char *, size_t *); 46static int efipart_open(struct open_file *, ...); 47static int efipart_close(struct open_file *); | 29 30#include <sys/param.h> 31#include <sys/time.h> 32#include <stddef.h> 33#include <stdarg.h> 34 35#include <bootstrap.h> 36 37#include <efi.h> 38#include <efilib.h> 39#include <efiprot.h> 40 41static EFI_GUID blkio_guid = BLOCK_IO_PROTOCOL; 42 43static int efipart_init(void); 44static int efipart_strategy(void *, int, daddr_t, size_t, char *, size_t *); 45static int efipart_realstrategy(void *, int, daddr_t, size_t, char *, size_t *); 46static int efipart_open(struct open_file *, ...); 47static int efipart_close(struct open_file *); |
48static void efipart_print(int); | 48static int efipart_print(int); |
49 50struct devsw efipart_dev = { 51 .dv_name = "part", 52 .dv_type = DEVT_DISK, 53 .dv_init = efipart_init, 54 .dv_strategy = efipart_strategy, 55 .dv_open = efipart_open, 56 .dv_close = efipart_close, --- 98 unchanged lines hidden (view full) --- 155 err = efi_register_handles(&efipart_dev, hout, aliases, nout); 156 free(hin); 157 158 if (nout == 0 && nrdisk > 0) 159 printf("Found %d disk(s) but no logical partition\n", nrdisk); 160 return (err); 161} 162 | 49 50struct devsw efipart_dev = { 51 .dv_name = "part", 52 .dv_type = DEVT_DISK, 53 .dv_init = efipart_init, 54 .dv_strategy = efipart_strategy, 55 .dv_open = efipart_open, 56 .dv_close = efipart_close, --- 98 unchanged lines hidden (view full) --- 155 err = efi_register_handles(&efipart_dev, hout, aliases, nout); 156 free(hin); 157 158 if (nout == 0 && nrdisk > 0) 159 printf("Found %d disk(s) but no logical partition\n", nrdisk); 160 return (err); 161} 162 |
163static void | 163static int |
164efipart_print(int verbose) 165{ 166 char line[80]; 167 EFI_BLOCK_IO *blkio; 168 EFI_HANDLE h; 169 EFI_STATUS status; 170 u_int unit; | 164efipart_print(int verbose) 165{ 166 char line[80]; 167 EFI_BLOCK_IO *blkio; 168 EFI_HANDLE h; 169 EFI_STATUS status; 170 u_int unit; |
171 int ret = 0; |
|
171 | 172 |
172 pager_open(); | 173 printf("%s devices:", efipart_dev.dv_name); 174 if ((ret = pager_output("\n")) != 0) 175 return (ret); 176 |
173 for (unit = 0, h = efi_find_handle(&efipart_dev, 0); 174 h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) { | 177 for (unit = 0, h = efi_find_handle(&efipart_dev, 0); 178 h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) { |
175 sprintf(line, " %s%d:", efipart_dev.dv_name, unit); 176 if (pager_output(line)) | 179 snprintf(line, sizeof(line), " %s%d:", 180 efipart_dev.dv_name, unit); 181 if ((ret = pager_output(line)) != 0) |
177 break; 178 179 status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio); 180 if (!EFI_ERROR(status)) { | 182 break; 183 184 status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio); 185 if (!EFI_ERROR(status)) { |
181 sprintf(line, " %llu blocks", | 186 snprintf(line, sizeof(line), " %llu blocks", |
182 (unsigned long long)(blkio->Media->LastBlock + 1)); | 187 (unsigned long long)(blkio->Media->LastBlock + 1)); |
183 if (pager_output(line)) | 188 if ((ret = pager_output(line)) != 0) |
184 break; 185 if (blkio->Media->RemovableMedia) | 189 break; 190 if (blkio->Media->RemovableMedia) |
186 if (pager_output(" (removable)")) | 191 if ((ret = pager_output(" (removable)")) != 0) |
187 break; 188 } | 192 break; 193 } |
189 if (pager_output("\n")) | 194 if ((ret = pager_output("\n")) != 0) |
190 break; 191 } | 195 break; 196 } |
192 pager_close(); | 197 return (ret); |
193} 194 195static int 196efipart_open(struct open_file *f, ...) 197{ 198 va_list args; 199 struct devdesc *dev; 200 EFI_BLOCK_IO *blkio; --- 164 unchanged lines hidden --- | 198} 199 200static int 201efipart_open(struct open_file *f, ...) 202{ 203 va_list args; 204 struct devdesc *dev; 205 EFI_BLOCK_IO *blkio; --- 164 unchanged lines hidden --- |