Reworked Inode to have a dirty bit and subclass-implemented flush_metadata().

This way we can defer disk writes as long as we like. There's no automatic
flushing happening just yet.
This commit is contained in:
Andreas Kling 2018-12-19 21:56:45 +01:00
parent d506c857ab
commit 1f44cd9dd9
Notes: sideshowbarker 2024-07-19 16:08:01 +09:00
11 changed files with 82 additions and 58 deletions

View file

@ -1,5 +1,6 @@
#include <AK/Assertions.h>
#include <AK/HashMap.h>
#include <LibC/errno_numbers.h>
#include "FileSystem.h"
static dword s_lastFileSystemID;
@ -60,7 +61,7 @@ ByteBuffer Inode::read_entire(FileDescriptor* descriptor)
ASSERT(offset <= (ssize_t)initial_size); // FIXME: Support dynamically growing the buffer.
}
if (nread < 0) {
kprintf("CoreInode::read_entire: ERROR: %d\n", nread);
kprintf("Inode::read_entire: ERROR: %d\n", nread);
return nullptr;
}
@ -128,7 +129,35 @@ Inode::~Inode()
{
}
int Inode::set_atime_and_mtime(Unix::time_t atime, Unix::time_t mtime)
int Inode::set_atime(Unix::time_t ts)
{
return fs().set_atime_and_mtime(identifier(), atime, mtime);
if (fs().is_readonly())
return -EROFS;
if (m_metadata.atime == ts)
return 0;
m_metadata.atime = ts;
m_dirty = true;
return 0;
}
int Inode::set_ctime(Unix::time_t ts)
{
if (fs().is_readonly())
return -EROFS;
if (m_metadata.ctime == ts)
return 0;
m_metadata.ctime = ts;
m_dirty = true;
return 0;
}
int Inode::set_mtime(Unix::time_t ts)
{
if (fs().is_readonly())
return -EROFS;
if (m_metadata.mtime == ts)
return 0;
m_metadata.mtime = ts;
m_dirty = true;
return 0;
}