1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-23 18:35:07 +00:00

Kernel: Add a mechanism for listening for changes to an inode.

The syscall is quite simple:

    int watch_file(const char* path, int path_length);

It returns a file descriptor referring to a "InodeWatcher" object in the
kernel. It becomes readable whenever something changes about the inode.

Currently this is implemented by hooking the "metadata dirty bit" in
Inode which isn't perfect, but it's a start. :^)
This commit is contained in:
Andreas Kling 2019-07-22 20:01:11 +02:00
parent a9adf4c95b
commit c8e2bb5605
12 changed files with 200 additions and 3 deletions

View file

@ -1,6 +1,7 @@
#include <AK/NonnullRefPtrVector.h>
#include <AK/StringBuilder.h>
#include <Kernel/FileSystem/Inode.h>
#include <Kernel/FileSystem/InodeWatcher.h>
#include <Kernel/Net/LocalSocket.h>
#include <Kernel/VM/VMObject.h>
@ -131,3 +132,33 @@ bool Inode::unbind_socket()
m_socket = nullptr;
return true;
}
void Inode::register_watcher(Badge<InodeWatcher>, InodeWatcher& watcher)
{
LOCKER(m_lock);
ASSERT(!m_watchers.contains(&watcher));
m_watchers.set(&watcher);
}
void Inode::unregister_watcher(Badge<InodeWatcher>, InodeWatcher& watcher)
{
LOCKER(m_lock);
ASSERT(m_watchers.contains(&watcher));
m_watchers.remove(&watcher);
}
void Inode::set_metadata_dirty(bool metadata_dirty)
{
if (m_metadata_dirty == metadata_dirty)
return;
m_metadata_dirty = metadata_dirty;
if (m_metadata_dirty) {
// FIXME: Maybe we should hook into modification events somewhere else, I'm not sure where.
// We don't always end up on this particular code path, for instance when writing to an ext2fs file.
LOCKER(m_lock);
for (auto& watcher : m_watchers) {
watcher->notify_inode_event({}, InodeWatcher::Event::Type::Modified);
}
}
}