1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 14:48:14 +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

@ -11,10 +11,11 @@
#include <Kernel/Lock.h>
class FileDescription;
class InodeWatcher;
class LocalSocket;
class VMObject;
class Inode : public RefCounted<Inode> {
class Inode : public RefCounted<Inode>, public Weakable<Inode> {
friend class VFS;
friend class FS;
@ -73,9 +74,12 @@ public:
static void sync();
void register_watcher(Badge<InodeWatcher>, InodeWatcher&);
void unregister_watcher(Badge<InodeWatcher>, InodeWatcher&);
protected:
Inode(FS& fs, unsigned index);
void set_metadata_dirty(bool b) { m_metadata_dirty = b; }
void set_metadata_dirty(bool);
void inode_contents_changed(off_t, ssize_t, const u8*);
void inode_size_changed(size_t old_size, size_t new_size);
@ -86,5 +90,6 @@ private:
unsigned m_index { 0 };
WeakPtr<VMObject> m_vmo;
RefPtr<LocalSocket> m_socket;
HashTable<InodeWatcher*> m_watchers;
bool m_metadata_dirty { false };
};