mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-07 09:04:30 +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:
@@ -10,6 +10,7 @@
|
||||
#include <Kernel/FileSystem/Custody.h>
|
||||
#include <Kernel/FileSystem/FIFO.h>
|
||||
#include <Kernel/FileSystem/FileDescription.h>
|
||||
#include <Kernel/FileSystem/InodeWatcher.h>
|
||||
#include <Kernel/FileSystem/SharedMemory.h>
|
||||
#include <Kernel/FileSystem/VirtualFileSystem.h>
|
||||
#include <Kernel/IO.h>
|
||||
@@ -2638,6 +2639,26 @@ int Process::sys$ftruncate(int fd, off_t length)
|
||||
return description->truncate(length);
|
||||
}
|
||||
|
||||
int Process::sys$watch_file(const char* path, int path_length)
|
||||
{
|
||||
if (!validate_read(path, path_length))
|
||||
return -EFAULT;
|
||||
|
||||
auto custody_or_error = VFS::the().resolve_path({ path, path_length }, current_directory());
|
||||
if (custody_or_error.is_error())
|
||||
return custody_or_error.error();
|
||||
|
||||
auto& custody = custody_or_error.value();
|
||||
auto& inode = custody->inode();
|
||||
|
||||
int fd = alloc_fd();
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
m_fds[fd].set(FileDescription::create(*InodeWatcher::create(inode)));
|
||||
return fd;
|
||||
}
|
||||
|
||||
int Process::sys$systrace(pid_t pid)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
|
||||
Reference in New Issue
Block a user