efiblock.c revision 1.2.2.2       1  1.2.2.2  pgoyette /* $NetBSD: efiblock.c,v 1.2.2.2 2018/09/06 06:56:47 pgoyette Exp $ */
      2  1.2.2.2  pgoyette 
      3  1.2.2.2  pgoyette /*-
      4  1.2.2.2  pgoyette  * Copyright (c) 2016 Kimihiro Nonaka <nonaka (at) netbsd.org>
      5  1.2.2.2  pgoyette  * Copyright (c) 2018 Jared McNeill <jmcneill (at) invisible.ca>
      6  1.2.2.2  pgoyette  * All rights reserved.
      7  1.2.2.2  pgoyette  *
      8  1.2.2.2  pgoyette  * Redistribution and use in source and binary forms, with or without
      9  1.2.2.2  pgoyette  * modification, are permitted provided that the following conditions
     10  1.2.2.2  pgoyette  * are met:
     11  1.2.2.2  pgoyette  * 1. Redistributions of source code must retain the above copyright
     12  1.2.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer.
     13  1.2.2.2  pgoyette  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.2.2.2  pgoyette  *    notice, this list of conditions and the following disclaimer in the
     15  1.2.2.2  pgoyette  *    documentation and/or other materials provided with the distribution.
     16  1.2.2.2  pgoyette  *
     17  1.2.2.2  pgoyette  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     18  1.2.2.2  pgoyette  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     19  1.2.2.2  pgoyette  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     20  1.2.2.2  pgoyette  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     21  1.2.2.2  pgoyette  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     22  1.2.2.2  pgoyette  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     23  1.2.2.2  pgoyette  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     24  1.2.2.2  pgoyette  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     25  1.2.2.2  pgoyette  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     26  1.2.2.2  pgoyette  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     27  1.2.2.2  pgoyette  * SUCH DAMAGE.
     28  1.2.2.2  pgoyette  */
     29  1.2.2.2  pgoyette 
     30  1.2.2.2  pgoyette #define FSTYPENAMES
     31  1.2.2.2  pgoyette 
     32  1.2.2.2  pgoyette #include <sys/param.h>
     33  1.2.2.2  pgoyette #include <sys/md5.h>
     34  1.2.2.2  pgoyette 
     35  1.2.2.2  pgoyette #include "efiboot.h"
     36  1.2.2.2  pgoyette #include "efiblock.h"
     37  1.2.2.2  pgoyette 
     38  1.2.2.2  pgoyette static EFI_HANDLE *efi_block;
     39  1.2.2.2  pgoyette static UINTN efi_nblock;
     40  1.2.2.2  pgoyette static struct efi_block_part *efi_block_booted = NULL;
     41  1.2.2.2  pgoyette 
     42  1.2.2.2  pgoyette static TAILQ_HEAD(, efi_block_dev) efi_block_devs = TAILQ_HEAD_INITIALIZER(efi_block_devs);
     43  1.2.2.2  pgoyette 
     44  1.2.2.2  pgoyette static int
     45  1.2.2.2  pgoyette efi_block_parse(const char *fname, struct efi_block_part **pbpart, char **pfile)
     46  1.2.2.2  pgoyette {
     47  1.2.2.2  pgoyette 	struct efi_block_dev *bdev;
     48  1.2.2.2  pgoyette 	struct efi_block_part *bpart;
     49  1.2.2.2  pgoyette 	char pathbuf[PATH_MAX], *default_device, *ep = NULL;
     50  1.2.2.2  pgoyette 	const char *full_path;
     51  1.2.2.2  pgoyette 	intmax_t dev;
     52  1.2.2.2  pgoyette 	int part;
     53  1.2.2.2  pgoyette 
     54  1.2.2.2  pgoyette 	default_device = get_default_device();
     55  1.2.2.2  pgoyette 	if (strchr(fname, ':') == NULL) {
     56  1.2.2.2  pgoyette 		if (strlen(default_device) > 0) {
     57  1.2.2.2  pgoyette 			snprintf(pathbuf, sizeof(pathbuf), "%s:%s", default_device, fname);
     58  1.2.2.2  pgoyette 			full_path = pathbuf;
     59  1.2.2.2  pgoyette 			*pfile = __UNCONST(fname);
     60  1.2.2.2  pgoyette 		} else {
     61  1.2.2.2  pgoyette 			return EINVAL;
     62  1.2.2.2  pgoyette 		}
     63  1.2.2.2  pgoyette 	} else {
     64  1.2.2.2  pgoyette 		full_path = fname;
     65  1.2.2.2  pgoyette 		*pfile = strchr(fname, ':') + 1;
     66  1.2.2.2  pgoyette 	}
     67  1.2.2.2  pgoyette 
     68  1.2.2.2  pgoyette 	if (strncasecmp(full_path, "hd", 2) != 0)
     69  1.2.2.2  pgoyette 		return EINVAL;
     70  1.2.2.2  pgoyette 	dev = strtoimax(full_path + 2, &ep, 10);
     71  1.2.2.2  pgoyette 	if (dev < 0 || dev >= efi_nblock)
     72  1.2.2.2  pgoyette 		return ENXIO;
     73  1.2.2.2  pgoyette 	if (ep[0] < 'a' || ep[0] >= 'a' + MAXPARTITIONS || ep[1] != ':')
     74  1.2.2.2  pgoyette 		return EINVAL;
     75  1.2.2.2  pgoyette 	part = ep[0] - 'a';
     76  1.2.2.2  pgoyette 	TAILQ_FOREACH(bdev, &efi_block_devs, entries) {
     77  1.2.2.2  pgoyette 		if (bdev->index == dev) {
     78  1.2.2.2  pgoyette 			TAILQ_FOREACH(bpart, &bdev->partitions, entries) {
     79  1.2.2.2  pgoyette 				if (bpart->index == part) {
     80  1.2.2.2  pgoyette 					*pbpart = bpart;
     81  1.2.2.2  pgoyette 					return 0;
     82  1.2.2.2  pgoyette 				}
     83  1.2.2.2  pgoyette 			}
     84  1.2.2.2  pgoyette 		}
     85  1.2.2.2  pgoyette 	}
     86  1.2.2.2  pgoyette 
     87  1.2.2.2  pgoyette 	return ENOENT;
     88  1.2.2.2  pgoyette }
     89  1.2.2.2  pgoyette 
     90  1.2.2.2  pgoyette static void
     91  1.2.2.2  pgoyette efi_block_generate_hash_mbr(struct efi_block_part *bpart, struct mbr_sector *mbr)
     92  1.2.2.2  pgoyette {
     93  1.2.2.2  pgoyette 	MD5_CTX md5ctx;
     94  1.2.2.2  pgoyette 
     95  1.2.2.2  pgoyette 	MD5Init(&md5ctx);
     96  1.2.2.2  pgoyette 	MD5Update(&md5ctx, (void *)mbr, sizeof(*mbr));
     97  1.2.2.2  pgoyette 	MD5Final(bpart->hash, &md5ctx);
     98  1.2.2.2  pgoyette }
     99  1.2.2.2  pgoyette 
    100  1.2.2.2  pgoyette static int
    101  1.2.2.2  pgoyette efi_block_find_partitions_disklabel(struct efi_block_dev *bdev, struct mbr_sector *mbr, uint32_t start, uint32_t size)
    102  1.2.2.2  pgoyette {
    103  1.2.2.2  pgoyette 	struct efi_block_part *bpart;
    104  1.2.2.2  pgoyette 	struct disklabel d;
    105  1.2.2.2  pgoyette 	struct partition *p;
    106  1.2.2.2  pgoyette 	EFI_STATUS status;
    107  1.2.2.2  pgoyette 	EFI_LBA lba;
    108  1.2.2.2  pgoyette 	uint8_t *buf;
    109  1.2.2.2  pgoyette 	UINT32 sz;
    110  1.2.2.2  pgoyette 	int n;
    111  1.2.2.2  pgoyette 
    112  1.2.2.2  pgoyette 	sz = __MAX(sizeof(d), bdev->bio->Media->BlockSize);
    113  1.2.2.2  pgoyette 	sz = roundup(sz, bdev->bio->Media->BlockSize);
    114  1.2.2.2  pgoyette 	buf = AllocatePool(sz);
    115  1.2.2.2  pgoyette 	if (!buf)
    116  1.2.2.2  pgoyette 		return ENOMEM;
    117  1.2.2.2  pgoyette 
    118  1.2.2.2  pgoyette 	lba = ((start + LABELSECTOR) * DEV_BSIZE) / bdev->bio->Media->BlockSize;
    119  1.2.2.2  pgoyette 	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id, lba, sz, buf);
    120  1.2.2.2  pgoyette 	if (EFI_ERROR(status) || getdisklabel(buf, &d) != NULL) {
    121  1.2.2.2  pgoyette 		FreePool(buf);
    122  1.2.2.2  pgoyette 		return EIO;
    123  1.2.2.2  pgoyette 	}
    124  1.2.2.2  pgoyette 	FreePool(buf);
    125  1.2.2.2  pgoyette 
    126  1.2.2.2  pgoyette 	if (le32toh(d.d_magic) != DISKMAGIC || le32toh(d.d_magic2) != DISKMAGIC)
    127  1.2.2.2  pgoyette 		return EINVAL;
    128  1.2.2.2  pgoyette 	if (le16toh(d.d_npartitions) > MAXPARTITIONS)
    129  1.2.2.2  pgoyette 		return EINVAL;
    130  1.2.2.2  pgoyette 
    131  1.2.2.2  pgoyette 	for (n = 0; n < le16toh(d.d_npartitions); n++) {
    132  1.2.2.2  pgoyette 		p = &d.d_partitions[n];
    133  1.2.2.2  pgoyette 		switch (p->p_fstype) {
    134  1.2.2.2  pgoyette 		case FS_BSDFFS:
    135  1.2.2.2  pgoyette 		case FS_MSDOS:
    136  1.2.2.2  pgoyette 		case FS_BSDLFS:
    137  1.2.2.2  pgoyette 			break;
    138  1.2.2.2  pgoyette 		default:
    139  1.2.2.2  pgoyette 			continue;
    140  1.2.2.2  pgoyette 		}
    141  1.2.2.2  pgoyette 
    142  1.2.2.2  pgoyette 		bpart = alloc(sizeof(*bpart));
    143  1.2.2.2  pgoyette 		bpart->index = n;
    144  1.2.2.2  pgoyette 		bpart->bdev = bdev;
    145  1.2.2.2  pgoyette 		bpart->type = EFI_BLOCK_PART_DISKLABEL;
    146  1.2.2.2  pgoyette 		bpart->disklabel.secsize = le32toh(d.d_secsize);
    147  1.2.2.2  pgoyette 		bpart->disklabel.part = *p;
    148  1.2.2.2  pgoyette 		efi_block_generate_hash_mbr(bpart, mbr);
    149  1.2.2.2  pgoyette 		TAILQ_INSERT_TAIL(&bdev->partitions, bpart, entries);
    150  1.2.2.2  pgoyette 	}
    151  1.2.2.2  pgoyette 
    152  1.2.2.2  pgoyette 	return 0;
    153  1.2.2.2  pgoyette }
    154  1.2.2.2  pgoyette 
    155  1.2.2.2  pgoyette static int
    156  1.2.2.2  pgoyette efi_block_find_partitions_mbr(struct efi_block_dev *bdev)
    157  1.2.2.2  pgoyette {
    158  1.2.2.2  pgoyette 	struct mbr_sector mbr;
    159  1.2.2.2  pgoyette 	struct mbr_partition *mbr_part;
    160  1.2.2.2  pgoyette 	EFI_STATUS status;
    161  1.2.2.2  pgoyette 	uint8_t *buf;
    162  1.2.2.2  pgoyette 	UINT32 sz;
    163  1.2.2.2  pgoyette 	int n;
    164  1.2.2.2  pgoyette 
    165  1.2.2.2  pgoyette 	sz = __MAX(sizeof(mbr), bdev->bio->Media->BlockSize);
    166  1.2.2.2  pgoyette 	sz = roundup(sz, bdev->bio->Media->BlockSize);
    167  1.2.2.2  pgoyette 	buf = AllocatePool(sz);
    168  1.2.2.2  pgoyette 	if (!buf)
    169  1.2.2.2  pgoyette 		return ENOMEM;
    170  1.2.2.2  pgoyette 
    171  1.2.2.2  pgoyette 	status = uefi_call_wrapper(bdev->bio->ReadBlocks, 5, bdev->bio, bdev->media_id, 0, sz, buf);
    172  1.2.2.2  pgoyette 	if (EFI_ERROR(status)) {
    173  1.2.2.2  pgoyette 		FreePool(buf);
    174  1.2.2.2  pgoyette 		return EIO;
    175  1.2.2.2  pgoyette 	}
    176  1.2.2.2  pgoyette 	memcpy(&mbr, buf, sizeof(mbr));
    177  1.2.2.2  pgoyette 	FreePool(buf);
    178  1.2.2.2  pgoyette 
    179  1.2.2.2  pgoyette 	if (le32toh(mbr.mbr_magic) != MBR_MAGIC)
    180  1.2.2.2  pgoyette 		return ENOENT;
    181  1.2.2.2  pgoyette 
    182  1.2.2.2  pgoyette 	for (n = 0; n < MBR_PART_COUNT; n++) {
    183  1.2.2.2  pgoyette 		mbr_part = &mbr.mbr_parts[n];
    184  1.2.2.2  pgoyette 		if (le32toh(mbr_part->mbrp_size) == 0)
    185  1.2.2.2  pgoyette 			continue;
    186  1.2.2.2  pgoyette 		if (mbr_part->mbrp_type == MBR_PTYPE_NETBSD) {
    187  1.2.2.2  pgoyette 			efi_block_find_partitions_disklabel(bdev, &mbr, le32toh(mbr_part->mbrp_start), le32toh(mbr_part->mbrp_size));
    188  1.2.2.2  pgoyette 			break;
    189  1.2.2.2  pgoyette 		}
    190  1.2.2.2  pgoyette 	}
    191  1.2.2.2  pgoyette 
    192  1.2.2.2  pgoyette 	return 0;
    193  1.2.2.2  pgoyette }
    194  1.2.2.2  pgoyette 
    195  1.2.2.2  pgoyette static int
    196  1.2.2.2  pgoyette efi_block_find_partitions(struct efi_block_dev *bdev)
    197  1.2.2.2  pgoyette {
    198  1.2.2.2  pgoyette 	return efi_block_find_partitions_mbr(bdev);
    199  1.2.2.2  pgoyette }
    200  1.2.2.2  pgoyette 
    201  1.2.2.2  pgoyette void
    202  1.2.2.2  pgoyette efi_block_probe(void)
    203  1.2.2.2  pgoyette {
    204  1.2.2.2  pgoyette 	struct efi_block_dev *bdev;
    205  1.2.2.2  pgoyette 	EFI_BLOCK_IO *bio;
    206  1.2.2.2  pgoyette 	EFI_STATUS status;
    207  1.2.2.2  pgoyette 	uint16_t devindex = 0;
    208  1.2.2.2  pgoyette 	int depth = -1;
    209  1.2.2.2  pgoyette 	int n;
    210  1.2.2.2  pgoyette 
    211  1.2.2.2  pgoyette 	status = LibLocateHandle(ByProtocol, &BlockIoProtocol, NULL, &efi_nblock, &efi_block);
    212  1.2.2.2  pgoyette 	if (EFI_ERROR(status))
    213  1.2.2.2  pgoyette 		return;
    214  1.2.2.2  pgoyette 
    215  1.2.2.2  pgoyette 	if (efi_bootdp) {
    216  1.2.2.2  pgoyette 		depth = efi_device_path_depth(efi_bootdp, MEDIA_DEVICE_PATH);
    217  1.2.2.2  pgoyette 		if (depth == 0)
    218  1.2.2.2  pgoyette 			depth = 1;
    219  1.2.2.2  pgoyette 	}
    220  1.2.2.2  pgoyette 
    221  1.2.2.2  pgoyette 	for (n = 0; n < efi_nblock; n++) {
    222  1.2.2.2  pgoyette 		status = uefi_call_wrapper(BS->HandleProtocol, 3, efi_block[n], &BlockIoProtocol, (void **)&bio);
    223  1.2.2.2  pgoyette 		if (EFI_ERROR(status) || !bio->Media->MediaPresent)
    224  1.2.2.2  pgoyette 			continue;
    225  1.2.2.2  pgoyette 
    226  1.2.2.2  pgoyette 		if (bio->Media->LogicalPartition)
    227  1.2.2.2  pgoyette 			continue;
    228  1.2.2.2  pgoyette 
    229  1.2.2.2  pgoyette 		bdev = alloc(sizeof(*bdev));
    230  1.2.2.2  pgoyette 		bdev->index = devindex++;
    231  1.2.2.2  pgoyette 		bdev->bio = bio;
    232  1.2.2.2  pgoyette 		bdev->media_id = bio->Media->MediaId;
    233  1.2.2.2  pgoyette 		bdev->path = DevicePathFromHandle(efi_block[n]);
    234  1.2.2.2  pgoyette 		TAILQ_INIT(&bdev->partitions);
    235  1.2.2.2  pgoyette 		TAILQ_INSERT_TAIL(&efi_block_devs, bdev, entries);
    236  1.2.2.2  pgoyette 
    237  1.2.2.2  pgoyette 		if (depth > 0 && efi_device_path_ncmp(efi_bootdp, DevicePathFromHandle(efi_block[n]), depth) == 0) {
    238  1.2.2.2  pgoyette 			char devname[9];
    239  1.2.2.2  pgoyette 			snprintf(devname, sizeof(devname), "hd%ua", bdev->index);
    240  1.2.2.2  pgoyette 			set_default_device(devname);
    241  1.2.2.2  pgoyette 		}
    242  1.2.2.2  pgoyette 
    243  1.2.2.2  pgoyette 		efi_block_find_partitions(bdev);
    244  1.2.2.2  pgoyette 	}
    245  1.2.2.2  pgoyette }
    246  1.2.2.2  pgoyette 
    247  1.2.2.2  pgoyette void
    248  1.2.2.2  pgoyette efi_block_show(void)
    249  1.2.2.2  pgoyette {
    250  1.2.2.2  pgoyette 	struct efi_block_dev *bdev;
    251  1.2.2.2  pgoyette 	struct efi_block_part *bpart;
    252  1.2.2.2  pgoyette 	uint64_t size;
    253  1.2.2.2  pgoyette 	CHAR16 *path;
    254  1.2.2.2  pgoyette 
    255  1.2.2.2  pgoyette 	TAILQ_FOREACH(bdev, &efi_block_devs, entries) {
    256  1.2.2.2  pgoyette 		printf("hd%u (", bdev->index);
    257  1.2.2.2  pgoyette 
    258  1.2.2.2  pgoyette 		/* Size in MB */
    259  1.2.2.2  pgoyette 		size = ((bdev->bio->Media->LastBlock + 1) * bdev->bio->Media->BlockSize) / (1024 * 1024);
    260  1.2.2.2  pgoyette 		if (size >= 10000)
    261  1.2.2.2  pgoyette 			printf("%"PRIu64" GB", size / 1024);
    262  1.2.2.2  pgoyette 		else
    263  1.2.2.2  pgoyette 			printf("%"PRIu64" MB", size);
    264  1.2.2.2  pgoyette 		printf("): ");
    265  1.2.2.2  pgoyette 
    266  1.2.2.2  pgoyette 		path = DevicePathToStr(bdev->path);
    267  1.2.2.2  pgoyette 		Print(L"%s", path);
    268  1.2.2.2  pgoyette 		FreePool(path);
    269  1.2.2.2  pgoyette 
    270  1.2.2.2  pgoyette 		printf("\n");
    271  1.2.2.2  pgoyette 
    272  1.2.2.2  pgoyette 		TAILQ_FOREACH(bpart, &bdev->partitions, entries) {
    273  1.2.2.2  pgoyette 			switch (bpart->type) {
    274  1.2.2.2  pgoyette 			case EFI_BLOCK_PART_DISKLABEL:
    275  1.2.2.2  pgoyette 				printf("  hd%u%c (", bdev->index, bpart->index + 'a');
    276  1.2.2.2  pgoyette 
    277  1.2.2.2  pgoyette 				/* Size in MB */
    278  1.2.2.2  pgoyette 				size = ((uint64_t)bpart->disklabel.secsize * bpart->disklabel.part.p_size) / (1024 * 1024);
    279  1.2.2.2  pgoyette 				if (size >= 10000)
    280  1.2.2.2  pgoyette 					printf("%"PRIu64" GB", size / 1024);
    281  1.2.2.2  pgoyette 				else
    282  1.2.2.2  pgoyette 					printf("%"PRIu64" MB", size);
    283  1.2.2.2  pgoyette 				printf("): ");
    284  1.2.2.2  pgoyette 
    285  1.2.2.2  pgoyette 				printf("%s\n", fstypenames[bpart->disklabel.part.p_fstype]);
    286  1.2.2.2  pgoyette 				break;
    287  1.2.2.2  pgoyette 			default:
    288  1.2.2.2  pgoyette 				break;
    289  1.2.2.2  pgoyette 			}
    290  1.2.2.2  pgoyette 		}
    291  1.2.2.2  pgoyette 	}
    292  1.2.2.2  pgoyette }
    293  1.2.2.2  pgoyette 
    294  1.2.2.2  pgoyette struct efi_block_part *
    295  1.2.2.2  pgoyette efi_block_boot_part(void)
    296  1.2.2.2  pgoyette {
    297  1.2.2.2  pgoyette 	return efi_block_booted;
    298  1.2.2.2  pgoyette }
    299  1.2.2.2  pgoyette 
    300  1.2.2.2  pgoyette int
    301  1.2.2.2  pgoyette efi_block_open(struct open_file *f, ...)
    302  1.2.2.2  pgoyette {
    303  1.2.2.2  pgoyette 	struct efi_block_part *bpart;
    304  1.2.2.2  pgoyette 	const char *fname;
    305  1.2.2.2  pgoyette 	char **file;
    306  1.2.2.2  pgoyette 	char *path;
    307  1.2.2.2  pgoyette 	va_list ap;
    308  1.2.2.2  pgoyette 	int rv, n;
    309  1.2.2.2  pgoyette 
    310  1.2.2.2  pgoyette 	va_start(ap, f);
    311  1.2.2.2  pgoyette 	fname = va_arg(ap, const char *);
    312  1.2.2.2  pgoyette 	file = va_arg(ap, char **);
    313  1.2.2.2  pgoyette 	va_end(ap);
    314  1.2.2.2  pgoyette 
    315  1.2.2.2  pgoyette 	rv = efi_block_parse(fname, &bpart, &path);
    316  1.2.2.2  pgoyette 	if (rv != 0)
    317  1.2.2.2  pgoyette 		return rv;
    318  1.2.2.2  pgoyette 
    319  1.2.2.2  pgoyette 	for (n = 0; n < ndevs; n++)
    320  1.2.2.2  pgoyette 		if (strcmp(DEV_NAME(&devsw[n]), "efiblock") == 0) {
    321  1.2.2.2  pgoyette 			f->f_dev = &devsw[n];
    322  1.2.2.2  pgoyette 			break;
    323  1.2.2.2  pgoyette 		}
    324  1.2.2.2  pgoyette 	if (n == ndevs)
    325  1.2.2.2  pgoyette 		return ENXIO;
    326  1.2.2.2  pgoyette 
    327  1.2.2.2  pgoyette 	f->f_devdata = bpart;
    328  1.2.2.2  pgoyette 
    329  1.2.2.2  pgoyette 	*file = path;
    330  1.2.2.2  pgoyette 
    331  1.2.2.2  pgoyette 	efi_block_booted = bpart;
    332  1.2.2.2  pgoyette 
    333  1.2.2.2  pgoyette 	return 0;
    334  1.2.2.2  pgoyette }
    335  1.2.2.2  pgoyette 
    336  1.2.2.2  pgoyette int
    337  1.2.2.2  pgoyette efi_block_close(struct open_file *f)
    338  1.2.2.2  pgoyette {
    339  1.2.2.2  pgoyette 	return 0;
    340  1.2.2.2  pgoyette }
    341  1.2.2.2  pgoyette 
    342  1.2.2.2  pgoyette int
    343  1.2.2.2  pgoyette efi_block_strategy(void *devdata, int rw, daddr_t dblk, size_t size, void *buf, size_t *rsize)
    344  1.2.2.2  pgoyette {
    345  1.2.2.2  pgoyette 	struct efi_block_part *bpart = devdata;
    346  1.2.2.2  pgoyette 	EFI_STATUS status;
    347  1.2.2.2  pgoyette 
    348  1.2.2.2  pgoyette 	if (rw != F_READ)
    349  1.2.2.2  pgoyette 		return EROFS;
    350  1.2.2.2  pgoyette 
    351  1.2.2.2  pgoyette 	switch (bpart->type) {
    352  1.2.2.2  pgoyette 	case EFI_BLOCK_PART_DISKLABEL:
    353  1.2.2.2  pgoyette 		if (bpart->bdev->bio->Media->BlockSize != bpart->disklabel.secsize) {
    354  1.2.2.2  pgoyette 			printf("%s: unsupported block size %d (expected %d)\n", __func__,
    355  1.2.2.2  pgoyette 			    bpart->bdev->bio->Media->BlockSize, bpart->disklabel.secsize);
    356  1.2.2.2  pgoyette 			return EIO;
    357  1.2.2.2  pgoyette 		}
    358  1.2.2.2  pgoyette 		dblk += bpart->disklabel.part.p_offset;
    359  1.2.2.2  pgoyette 		break;
    360  1.2.2.2  pgoyette 	default:
    361  1.2.2.2  pgoyette 		return EINVAL;
    362  1.2.2.2  pgoyette 	}
    363  1.2.2.2  pgoyette 
    364  1.2.2.2  pgoyette 	status = uefi_call_wrapper(bpart->bdev->bio->ReadBlocks, 5, bpart->bdev->bio, bpart->bdev->media_id, dblk, size, buf);
    365  1.2.2.2  pgoyette 	if (EFI_ERROR(status))
    366  1.2.2.2  pgoyette 		return EIO;
    367  1.2.2.2  pgoyette 
    368  1.2.2.2  pgoyette 	*rsize = size;
    369  1.2.2.2  pgoyette 
    370  1.2.2.2  pgoyette 	return 0;
    371  1.2.2.2  pgoyette }
    372