1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 11:14:58 +00:00

Kernel/FileSystem: Make Inode::{write,read}_bytes methods non-virtual

We make these methods non-virtual because we want to ensure we properly
enforce locking of the m_inode_lock mutex. Also, for write operations,
we want to call prepare_to_write_data before the actual write. The
previous design required us to ensure the callers do that at various
places which lead to hard-to-find bugs. By moving everything to a place
where we call prepare_to_write_data only once, we eliminate a possibilty
of forgeting to call it on some code path in the kernel.
This commit is contained in:
Liav A 2022-08-06 04:22:20 +03:00 committed by Idan Horowitz
parent 4f4717e351
commit c88cc8557f
20 changed files with 87 additions and 72 deletions

View file

@ -42,12 +42,7 @@ ErrorOr<size_t> InodeFile::write(OpenFileDescription& description, u64 offset, U
if (Checked<off_t>::addition_would_overflow(offset, count))
return EOVERFLOW;
size_t nwritten = 0;
{
MutexLocker locker(m_inode->m_inode_lock);
TRY(m_inode->prepare_to_write_data());
nwritten = TRY(m_inode->write_bytes(offset, count, data, &description));
}
size_t nwritten = TRY(m_inode->write_bytes(offset, count, data, &description));
if (nwritten > 0) {
auto mtime_result = m_inode->update_timestamps({}, {}, kgettimeofday().to_truncated_seconds());
Thread::current()->did_file_write(nwritten);