From ed3e5ec0311062fa5661aa1dead48533cc6477e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 27 Feb 2009 22:31:15 +0000 Subject: [PATCH] * zero_pages() did not fill in the _bytes parameter correctly - it returned how many unclear bytes remained instead of how many were cleared. This caused sparse files to show garbage instead of empty space. This fixes bug #2889. * common_file_io_vec_pages() set "size" (size_t) from file_io_vecs::length which is off_t without taking into account that important information could be lost. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29339 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/system/kernel/fs/vfs.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/system/kernel/fs/vfs.cpp b/src/system/kernel/fs/vfs.cpp index 06b06405bc..258fecf34c 100644 --- a/src/system/kernel/fs/vfs.cpp +++ b/src/system/kernel/fs/vfs.cpp @@ -3308,7 +3308,9 @@ dump_vnode_usage(int argc, char **argv) #endif // ADD_DEBUGGER_COMMANDS -//! Clears an iovec array of physical pages. +/*! Clears an iovec array of physical pages. + Returns in \a _bytes the number of bytes successfully cleared. +*/ static status_t zero_pages(const iovec* vecs, size_t vecCount, size_t* _bytes) { @@ -3321,14 +3323,13 @@ zero_pages(const iovec* vecs, size_t vecCount, size_t* _bytes) status_t status = vm_memset_physical((addr_t)vecs[index].iov_base, 0, length); if (status != B_OK) { - *_bytes = bytes; + *_bytes -= bytes; return status; } bytes -= length; } - *_bytes = bytes; return B_OK; } @@ -3359,8 +3360,9 @@ common_file_io_vec_pages(struct vnode *vnode, void *cookie, // now directly read the data from the device // the first file_io_vec can be read directly - size = fileVecs[0].length; - if (size > numBytes) + if (fileVecs[0].length < numBytes) + size = fileVecs[0].length; + else size = numBytes; if (fileVecs[0].offset >= 0) { @@ -8548,7 +8550,7 @@ _user_flock(int fd, int operation) case LOCK_SH: case LOCK_EX: break; - + default: return B_BAD_VALUE; }