From 7f2ba8be02a43f8adf0b724c6b3c921fe25f2302 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sun, 5 Sep 2004 14:57:54 +0000 Subject: [PATCH] Now clears out any remainders of the pages in the iovecs if the request couldn't be satisfied completely (ie. because the file size is not a multiple of the page size). It's no longer necessary to implement this functionality in the file systems. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@8858 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kernel/core/cache/vnode_store.cpp | 33 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/kernel/core/cache/vnode_store.cpp b/src/kernel/core/cache/vnode_store.cpp index 24f8c8bab7..7af2dfefc4 100644 --- a/src/kernel/core/cache/vnode_store.cpp +++ b/src/kernel/core/cache/vnode_store.cpp @@ -8,9 +8,9 @@ #include #include -#include #include +#include static void @@ -24,12 +24,7 @@ static off_t store_commit(struct vm_store *_store, off_t size) { vnode_store *store = (vnode_store *)_store; - // ToDo: enable this again when "size" is maintained correctly -#if 0 - // we don't like committing more memory than we have - if (size > store->size) - size = store->size; -#endif + store->vm.committed_size = size; return size; } @@ -49,8 +44,28 @@ static status_t store_read(struct vm_store *_store, off_t offset, const iovec *vecs, size_t count, size_t *_numBytes) { vnode_store *store = (vnode_store *)_store; - return vfs_read_pages(store->vnode, offset, vecs, count, _numBytes); - // ToDo: the file system must currently clear out the remainder of the last page... + size_t bytesUntouched = *_numBytes; + + status_t status = vfs_read_pages(store->vnode, offset, vecs, count, _numBytes); + + bytesUntouched -= *_numBytes; + + // if the request could be filled completely, or an error occured, we're done here + if (status < B_OK || bytesUntouched == 0) + return status; + + // Clear out any leftovers that were not touched by the above read - we're + // doing this here so that not every file system/device has to implement + // this + for (int32 i = count; i-- > 0 && bytesUntouched != 0;) { + size_t length = min_c(bytesUntouched, vecs[i].iov_len); + + // ToDo: will have to map the pages in later (when we switch to physical pages) + memset((void *)((addr_t)vecs[i].iov_base + vecs[i].iov_len - length), 0, length); + bytesUntouched -= length; + } + + return B_OK; }