mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:17:35 +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:
parent
a9adf4c95b
commit
c8e2bb5605
12 changed files with 200 additions and 3 deletions
38
Kernel/FileSystem/InodeWatcher.h
Normal file
38
Kernel/FileSystem/InodeWatcher.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/Badge.h>
|
||||
#include <AK/CircularQueue.h>
|
||||
#include <AK/WeakPtr.h>
|
||||
#include <Kernel/FileSystem/File.h>
|
||||
|
||||
class Inode;
|
||||
|
||||
class InodeWatcher final : public File {
|
||||
public:
|
||||
static NonnullRefPtr<InodeWatcher> create(Inode&);
|
||||
virtual ~InodeWatcher() override;
|
||||
|
||||
struct Event {
|
||||
enum class Type {
|
||||
Invalid = 0,
|
||||
Modified,
|
||||
};
|
||||
|
||||
Type type { Type::Invalid };
|
||||
};
|
||||
|
||||
virtual bool can_read(FileDescription&) const override;
|
||||
virtual bool can_write(FileDescription&) const override;
|
||||
virtual ssize_t read(FileDescription&, u8*, ssize_t) override;
|
||||
virtual ssize_t write(FileDescription&, const u8*, ssize_t) override;
|
||||
virtual String absolute_path(const FileDescription&) const override;
|
||||
virtual const char* class_name() const override { return "InodeWatcher"; };
|
||||
|
||||
void notify_inode_event(Badge<Inode>, Event::Type);
|
||||
|
||||
private:
|
||||
explicit InodeWatcher(Inode&);
|
||||
|
||||
WeakPtr<Inode> m_inode;
|
||||
CircularQueue<Event, 32> m_queue;
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue