summaryrefslogtreecommitdiff
path: root/sys/arch/amd64/stand/efiboot
diff options
context:
space:
mode:
authorYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2016-12-23 05:57:27 +0000
committerYASUOKA Masahiko <yasuoka@cvs.openbsd.org>2016-12-23 05:57:27 +0000
commitc3f2f058208a96dc3f0ba30b64c16c901978da0e (patch)
tree483d24f7eac0eafc385fd36a59a4e23678e6f5d6 /sys/arch/amd64/stand/efiboot
parent6b2099d24088de831885761e74e27784bc0551ce (diff)
The efi disk i/o to read sectors properly when the sector size is not
512. The problem actually had happened on macbookair7,1. reported and tested by gonzalo@.
Diffstat (limited to 'sys/arch/amd64/stand/efiboot')
-rw-r--r--sys/arch/amd64/stand/efiboot/efidev.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/sys/arch/amd64/stand/efiboot/efidev.c b/sys/arch/amd64/stand/efiboot/efidev.c
index 371da089c33..2f3ec14ebac 100644
--- a/sys/arch/amd64/stand/efiboot/efidev.c
+++ b/sys/arch/amd64/stand/efiboot/efidev.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: efidev.c,v 1.21 2016/09/11 17:51:21 jsing Exp $ */
+/* $OpenBSD: efidev.c,v 1.22 2016/12/23 05:57:26 yasuoka Exp $ */
/*
* Copyright (c) 1996 Michael Shalayeff
@@ -94,14 +94,15 @@ efid_io(int rw, efi_diskinfo_t ed, u_int off, int nsect, void *buf)
if (blks == 0)
/* block size < 512. HP Stream 13 actually has such a disk. */
return (EFI_UNSUPPORTED);
- lba = off / blks;
/* leading and trailing unaligned blocks in intrisic block */
i_lblks = ((off % blks) == 0)? 0 : blks - (off % blks);
- i_tblks = (off + nsect) % blks;
+ i_tblks = (nsect > i_lblks)? (off + nsect) % blks : 0;
/* aligned blocks in intrisic block */
- i_nblks = nsect - (i_lblks + i_tblks);
+ i_nblks = (nsect > i_lblks + i_tblks)? nsect - (i_lblks + i_tblks) : 0;
+
+ lba = (off + i_lblks) / blks;
switch (rw) {
case F_READ:
@@ -122,8 +123,8 @@ efid_io(int rw, efi_diskinfo_t ed, u_int off, int nsect, void *buf)
ed->blkio->Media->BlockSize, iblk);
if (EFI_ERROR(status))
goto on_eio;
- memcpy(buf, iblk + (blks - i_lblks),
- i_lblks * DEV_BSIZE);
+ memcpy(buf, iblk + (blks - i_lblks) * DEV_BSIZE,
+ min(nsect, i_lblks) * DEV_BSIZE);
}
if (i_nblks > 0) {
status = EFI_CALL(ed->blkio->ReadBlocks,