mirror of
https://github.com/RGBCube/serenity
synced 2025-07-03 05:32:13 +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
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue