From b09a63b4f730583f0467ede10acde5d2c07159fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Tue, 26 Oct 2004 23:51:18 +0000 Subject: [PATCH] Now has a special case if the length read or written is 0 - because in this case, the read/write must not fail, even if there is no block_run at the specified position. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@9520 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Stream.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Stream.h b/src/add-ons/kernel/file_systems/bfs/Stream.h index 31d20b53bc..beff1cc30d 100644 --- a/src/add-ons/kernel/file_systems/bfs/Stream.h +++ b/src/add-ons/kernel/file_systems/bfs/Stream.h @@ -362,17 +362,16 @@ template status_t Stream::ReadAt(off_t pos, uint8 *buffer, size_t *_length) { - // set/check boundaries for pos/length + size_t length = *_length; + // set/check boundaries for pos/length if (pos < 0) return B_BAD_VALUE; - if (pos >= Node()->data.Size()) { + if (pos >= Node()->data.Size() || length == 0) { *_length = 0; return B_NO_ERROR; } - size_t length = *_length; - if (pos + length > Node()->data.Size()) length = Node()->data.Size() - pos; @@ -477,7 +476,7 @@ Stream::ReadAt(off_t pos, uint8 *buffer, size_t *_length) } *_length = bytesRead; - return B_NO_ERROR; + return B_OK; } @@ -490,6 +489,7 @@ Stream::WriteAt(Transaction *transaction, off_t pos, const uint8 *buffer, // set/check boundaries for pos/length if (pos < 0) return B_BAD_VALUE; + if (pos + length > Size()) { off_t oldSize = Size(); @@ -517,6 +517,11 @@ Stream::WriteAt(Transaction *transaction, off_t pos, const uint8 *buffer, FillGapWithZeros(oldSize, pos); } + // If we don't want to write anything, we can now return (we may + // just have changed the file size using the position parameter) + if (length == 0) + return B_OK; + block_run run; off_t offset; if (FindBlockRun(pos, run, offset) < B_OK) { @@ -626,6 +631,6 @@ Stream::WriteAt(Transaction *transaction, off_t pos, const uint8 *buffer, *_length = bytesWritten; - return B_NO_ERROR; + return B_OK; }