From 7df07b24d3eb55209493a990af86055a58625a2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Wed, 23 Nov 2005 18:52:17 +0000 Subject: [PATCH] Nice if an experienced problem matches a bug in the implementation that closely: Inode::WriteAt() didn't call Inode::WriteBack() in case the file size was enlarged - it was only written in case the file was closed which a) could have not happened because of a crash, and b) would move the change into the wrong transaction, and could therefore result in an incorrect update, as seen. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@15094 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/add-ons/kernel/file_systems/bfs/Inode.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/Inode.cpp b/src/add-ons/kernel/file_systems/bfs/Inode.cpp index 2c15ca2eed..d9232d394b 100644 --- a/src/add-ons/kernel/file_systems/bfs/Inode.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Inode.cpp @@ -1190,8 +1190,6 @@ Inode::ReadAt(off_t pos, uint8 *buffer, size_t *_length) status_t Inode::WriteAt(Transaction &transaction, off_t pos, const uint8 *buffer, size_t *_length) { - // call the right WriteAt() method, depending on the inode flags - // update the last modification time in memory, it will be written // back to the inode, and the index when the file is closed // ToDo: should update the internal last modified time only at this point! @@ -1229,6 +1227,13 @@ Inode::WriteAt(Transaction &transaction, off_t pos, const uint8 *buffer, size_t // have to fill the gap between that position and the old file // size with zeros. FillGapWithZeros(oldSize, pos); + + // we need to write back the inode here because it has to + // go into this transaction (we cannot wait until the file + // is closed) + status = WriteBack(transaction); + if (status < B_OK) + return status; } // If we don't want to write anything, we can now return (we may @@ -1837,8 +1842,7 @@ Inode::SetFileSize(Transaction &transaction, off_t size) // fails, so we should shrink the stream to its former size ShrinkStream(transaction, oldSize); } - } - else + } else status = ShrinkStream(transaction, size); if (status < B_OK)