From fa84c61a81a1bb13d8a7c62617694c1b9a4bd85a Mon Sep 17 00:00:00 2001 From: Augustin Cavalier Date: Sun, 14 Apr 2019 21:21:26 -0400 Subject: [PATCH] nvme_disk: Round the length to the proper offset for partial reads. Following this commit, Haiku boots successfully in VMware from a NVMe device! --- src/add-ons/kernel/drivers/disk/nvme/nvme_disk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/drivers/disk/nvme/nvme_disk.cpp b/src/add-ons/kernel/drivers/disk/nvme/nvme_disk.cpp index 402c894b28..db4e386a29 100644 --- a/src/add-ons/kernel/drivers/disk/nvme/nvme_disk.cpp +++ b/src/add-ons/kernel/drivers/disk/nvme/nvme_disk.cpp @@ -288,8 +288,8 @@ nvme_disk_read(void* cookie, off_t pos, void* buffer, size_t* length) // libnvme does transfers in units of device sectors, so if we have to // round either the position or the length, we will need a bounce buffer. - off_t rounded_pos = ROUNDDOWN(pos, block_size); - size_t rounded_len = ROUNDUP(*length, block_size); + const off_t rounded_pos = ROUNDDOWN(pos, block_size); + size_t rounded_len = ROUNDUP((*length) + (pos - rounded_pos), block_size); if (rounded_pos != pos || rounded_len != *length || IS_USER_ADDRESS(buffer)) { void* bounceBuffer = malloc(rounded_len);