From 00866cc1495afea8118b01483580eb41f7e04f6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Wed, 2 Dec 2020 23:49:49 +0100 Subject: [PATCH] IOCache: adjust the last iovec when the capacity isn't multiple of B_PAGE_SIZE Patch by mark_mcs, edited by me this fixes #16030 Change-Id: I9255fe960f73cdfc3fd2668cdaf7db19fedd70f1 Reviewed-on: https://review.haiku-os.org/c/haiku/+/3451 Reviewed-by: Rene Gollent --- src/system/kernel/device_manager/IOCache.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/system/kernel/device_manager/IOCache.cpp b/src/system/kernel/device_manager/IOCache.cpp index 7cd834b8a5..050cf2bc7f 100644 --- a/src/system/kernel/device_manager/IOCache.cpp +++ b/src/system/kernel/device_manager/IOCache.cpp @@ -545,6 +545,12 @@ IOCache::_TransferPages(size_t firstPage, size_t pageCount, bool isWrite, } } + // Don't try to read past the end of the device just to fill a page; + // this makes sure that sum(fVecs[].length) == requestLength + generic_size_t padLength = B_PAGE_SIZE - requestLength % B_PAGE_SIZE; + if (vecCount > 0 && padLength != B_PAGE_SIZE) + fVecs[vecCount - 1].length -= padLength; + // create a request for the transfer IORequest request; status_t error = request.Init(firstPageOffset, fVecs, vecCount,