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; }