efipart.c (256281) | efipart.c (271135) |
---|---|
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/10/sys/boot/efi/libefi/efipart.c 219683 2011-03-16 00:08:10Z marcel $"); | 28__FBSDID("$FreeBSD: stable/10/sys/boot/efi/libefi/efipart.c 271135 2014-09-04 21:01:10Z emaste $"); |
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; | 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; |
42static EFI_GUID devpath_guid = DEVICE_PATH_PROTOCOL; |
|
42 43static int efipart_init(void); 44static int efipart_strategy(void *, int, daddr_t, size_t, char *, size_t *); 45static int efipart_open(struct open_file *, ...); 46static int efipart_close(struct open_file *); 47static void efipart_print(int); 48 49struct devsw efipart_dev = { --- 7 unchanged lines hidden (view full) --- 57 .dv_print = efipart_print, 58 .dv_cleanup = NULL 59}; 60 61static int 62efipart_init(void) 63{ 64 EFI_BLOCK_IO *blkio; | 43 44static int efipart_init(void); 45static int efipart_strategy(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); 49 50struct devsw efipart_dev = { --- 7 unchanged lines hidden (view full) --- 58 .dv_print = efipart_print, 59 .dv_cleanup = NULL 60}; 61 62static int 63efipart_init(void) 64{ 65 EFI_BLOCK_IO *blkio; |
65 EFI_HANDLE *hin, *hout; | 66 EFI_DEVICE_PATH *devpath, *node; 67 EFI_HANDLE *hin, *hout, *aliases, handle; |
66 EFI_STATUS status; 67 UINTN sz; | 68 EFI_STATUS status; 69 UINTN sz; |
70 CHAR16 *path; |
|
68 u_int n, nin, nout; 69 int err; 70 71 sz = 0; 72 hin = NULL; 73 status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0); 74 if (status == EFI_BUFFER_TOO_SMALL) { | 71 u_int n, nin, nout; 72 int err; 73 74 sz = 0; 75 hin = NULL; 76 status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 0); 77 if (status == EFI_BUFFER_TOO_SMALL) { |
75 hin = (EFI_HANDLE *)malloc(sz * 2); | 78 hin = (EFI_HANDLE *)malloc(sz * 3); |
76 status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 77 hin); 78 if (EFI_ERROR(status)) 79 free(hin); 80 } 81 if (EFI_ERROR(status)) 82 return (efi_status_to_errno(status)); 83 84 /* Filter handles to only include FreeBSD partitions. */ 85 nin = sz / sizeof(EFI_HANDLE); 86 hout = hin + nin; | 79 status = BS->LocateHandle(ByProtocol, &blkio_guid, 0, &sz, 80 hin); 81 if (EFI_ERROR(status)) 82 free(hin); 83 } 84 if (EFI_ERROR(status)) 85 return (efi_status_to_errno(status)); 86 87 /* Filter handles to only include FreeBSD partitions. */ 88 nin = sz / sizeof(EFI_HANDLE); 89 hout = hin + nin; |
90 aliases = hout + nin; |
|
87 nout = 0; 88 | 91 nout = 0; 92 |
93 bzero(aliases, nin * sizeof(EFI_HANDLE)); 94 |
|
89 for (n = 0; n < nin; n++) { | 95 for (n = 0; n < nin; n++) { |
90 status = BS->HandleProtocol(hin[n], &blkio_guid, &blkio); | 96 status = BS->HandleProtocol(hin[n], &devpath_guid, 97 (void **)&devpath); 98 if (EFI_ERROR(status)) { 99 continue; 100 } 101 node = devpath; 102 while (!IsDevicePathEnd(NextDevicePathNode(node))) 103 node = NextDevicePathNode(node); 104 status = BS->HandleProtocol(hin[n], &blkio_guid, 105 (void**)&blkio); |
91 if (EFI_ERROR(status)) 92 continue; 93 if (!blkio->Media->LogicalPartition) 94 continue; | 106 if (EFI_ERROR(status)) 107 continue; 108 if (!blkio->Media->LogicalPartition) 109 continue; |
95 hout[nout] = hin[n]; | 110 111 /* 112 * If we come across a logical partition of subtype CDROM 113 * it doesn't refer to the CD filesystem itself, but rather 114 * to any usable El Torito boot image on it. In this case 115 * we try to find the parent device and add that instead as 116 * that will be the CD filesystem. 117 */ 118 if (DevicePathType(node) == MEDIA_DEVICE_PATH && 119 DevicePathSubType(node) == MEDIA_CDROM_DP) { 120 node->Type = END_DEVICE_PATH_TYPE; 121 node->SubType = END_ENTIRE_DEVICE_PATH_SUBTYPE; 122 status = BS->LocateDevicePath(&blkio_guid, &devpath, 123 &handle); 124 if (EFI_ERROR(status)) 125 continue; 126 hout[nout] = handle; 127 aliases[nout] = hin[n]; 128 } else 129 hout[nout] = hin[n]; |
96 nout++; 97 } 98 | 130 nout++; 131 } 132 |
99 err = efi_register_handles(&efipart_dev, hout, nout); | 133 err = efi_register_handles(&efipart_dev, hout, aliases, nout); |
100 free(hin); 101 return (err); 102} 103 104static void 105efipart_print(int verbose) 106{ 107 char line[80]; 108 EFI_BLOCK_IO *blkio; 109 EFI_HANDLE h; 110 EFI_STATUS status; 111 u_int unit; 112 113 for (unit = 0, h = efi_find_handle(&efipart_dev, 0); 114 h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) { 115 sprintf(line, " %s%d:", efipart_dev.dv_name, unit); 116 pager_output(line); 117 | 134 free(hin); 135 return (err); 136} 137 138static void 139efipart_print(int verbose) 140{ 141 char line[80]; 142 EFI_BLOCK_IO *blkio; 143 EFI_HANDLE h; 144 EFI_STATUS status; 145 u_int unit; 146 147 for (unit = 0, h = efi_find_handle(&efipart_dev, 0); 148 h != NULL; h = efi_find_handle(&efipart_dev, ++unit)) { 149 sprintf(line, " %s%d:", efipart_dev.dv_name, unit); 150 pager_output(line); 151 |
118 status = BS->HandleProtocol(h, &blkio_guid, &blkio); | 152 status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio); |
119 if (!EFI_ERROR(status)) { 120 sprintf(line, " %llu blocks", 121 (unsigned long long)(blkio->Media->LastBlock + 1)); 122 pager_output(line); 123 if (blkio->Media->RemovableMedia) 124 pager_output(" (removable)"); 125 } 126 pager_output("\n"); --- 12 unchanged lines hidden (view full) --- 139 va_start(args, f); 140 dev = va_arg(args, struct devdesc*); 141 va_end(args); 142 143 h = efi_find_handle(&efipart_dev, dev->d_unit); 144 if (h == NULL) 145 return (EINVAL); 146 | 153 if (!EFI_ERROR(status)) { 154 sprintf(line, " %llu blocks", 155 (unsigned long long)(blkio->Media->LastBlock + 1)); 156 pager_output(line); 157 if (blkio->Media->RemovableMedia) 158 pager_output(" (removable)"); 159 } 160 pager_output("\n"); --- 12 unchanged lines hidden (view full) --- 173 va_start(args, f); 174 dev = va_arg(args, struct devdesc*); 175 va_end(args); 176 177 h = efi_find_handle(&efipart_dev, dev->d_unit); 178 if (h == NULL) 179 return (EINVAL); 180 |
147 status = BS->HandleProtocol(h, &blkio_guid, &blkio); | 181 status = BS->HandleProtocol(h, &blkio_guid, (void **)&blkio); |
148 if (EFI_ERROR(status)) 149 return (efi_status_to_errno(status)); 150 151 if (!blkio->Media->MediaPresent) 152 return (EAGAIN); 153 154 dev->d_opendata = blkio; 155 return (0); --- 111 unchanged lines hidden --- | 182 if (EFI_ERROR(status)) 183 return (efi_status_to_errno(status)); 184 185 if (!blkio->Media->MediaPresent) 186 return (EAGAIN); 187 188 dev->d_opendata = blkio; 189 return (0); --- 111 unchanged lines hidden --- |