Kernel: Allow Ext2FSInode::write_bytes calls with a byte count of zero

write_bytes is called with a count of 0 bytes if a directory is being
deleted, because in that case even the . and .. pseudo directories are
getting removed. In this case write_bytes is now a no-op.

Before write_bytes would fail because it would check to see if there
were any blocks available to write in (even though it wasn't going to
write in them anyway).

This behaviour was uncovered because of a recent change where
directories are correctly reduced in size. Which in this case results in
all the blocks being removed from the inode, whereas previously there
would be some stale blocks around to pass the check.
This commit is contained in:
Mart G 2021-05-07 20:30:23 +02:00 committed by Andreas Kling
parent db06b106ae
commit cab6155254
Notes: sideshowbarker 2024-07-18 18:35:50 +09:00

View file

@ -971,6 +971,9 @@ KResultOr<ssize_t> Ext2FSInode::write_bytes(off_t offset, ssize_t count, const U
VERIFY(offset >= 0); VERIFY(offset >= 0);
VERIFY(count >= 0); VERIFY(count >= 0);
if (count == 0)
return 0;
Locker inode_locker(m_lock); Locker inode_locker(m_lock);
if (auto result = prepare_to_write_data(); result.is_error()) if (auto result = prepare_to_write_data(); result.is_error())