commit 56678fefc4220f859def6ba37fcd5d51fd822907
parent 37e7f3e666a32c82836915be63dce0699481ab3a
Author: Stacy Harper <contact@stacyharper.net>
Date: Mon, 16 Jan 2023 15:08:36 +0100
Add inotify syscalls wrappers
Only x86_64 got SYS_inotify_init so we prefer to always calls
SYS_inotify_init1 with 0 as operation.
Signed-off-by: Stacy Harper <contact@stacyharper.net>
Diffstat:
2 files changed, 57 insertions(+), 0 deletions(-)
diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha
@@ -877,3 +877,30 @@ export fn flock(fd: int, op: int) (int | errno) = {
return wrap_return(syscall2(SYS_flock,
fd: u64, op: u64))?: int;
};
+
+export fn inotify_init() (int | errno) = {
+ return wrap_return(syscall1(SYS_inotify_init1, 0))?: int;
+};
+
+export fn inotify_init1(flags: int) (int | errno) = {
+ return wrap_return(syscall1(SYS_inotify_init1, flags: u64))?: int;
+};
+
+export fn inotify_add_watch(fd: int, path: path, mask: u32) (int | errno) = {
+ let path = kpath(path)?;
+ return wrap_return(syscall3(SYS_inotify_add_watch,
+ fd: u64, path: uintptr: u64, mask))?: int;
+};
+
+export fn inotify_rm_watch(fd: int, wd: int) (int | errno) = {
+ return wrap_return(syscall2(SYS_inotify_rm_watch,
+ fd: u64, wd: u64))?: int;
+};
+
+export type inotify_event = struct {
+ wd: int,
+ mask: u32,
+ cookie: u32,
+ length: u32,
+ name: *const char
+};
diff --git a/rt/+linux/types.ha b/rt/+linux/types.ha
@@ -842,3 +842,33 @@ export def SEEK_END: int = 2;
export def LOCK_SH: int = 1;
export def LOCK_EX: int = 2;
export def LOCK_UN: int = 4;
+
+// Inotify init1 flags
+export def IN_NONBLOCK: int = O_NONBLOCK;
+export def IN_CLOEXEC: int = O_CLOEXEC;
+
+// Inotify event masks
+export def INACCESS: u32 = 0x00000001;
+export def INMODIFY: u32 = 0x00000002;
+export def INATTRIB: u32 = 0x00000004;
+export def INCLOSEWRITE: u32 = 0x00000008;
+export def INCLOSENOWRITE: u32 = 0x00000010;
+export def INOPEN: u32 = 0x00000020;
+export def INMOVEDFROM: u32 = 0x00000040;
+export def INMOVEDTO: u32 = 0x00000080;
+export def INCREATE: u32 = 0x00000100;
+export def INDELETE: u32 = 0x00000200;
+export def INDELETESELF: u32 = 0x00000400;
+export def INMOVESELF: u32 = 0x00000800;
+export def INONLYDIR: u32 = 0x01000000;
+export def INDONTFOLLOW: u32 = 0x02000000;
+export def INEXCLUNLINK: u32 = 0x04000000;
+export def INMASKCREATE: u32 = 0x10000000;
+export def INMASKADD: u32 = 0x20000000;
+export def INISDIR: u32 = 0x40000000;
+export def INONESHOT: u32 = 0x80000000;
+export def INUNMOUNT: u32 = 0x00002000;
+export def INQOVERFLOW: u32 = 0x00004000;
+export def INIGNORED: u32 = 0x00008000;
+export def INMOVE: u32 = INMOVEDFROM | INMOVEDTO;
+export def INCLOSE: u32 = INCLOSEWRITE | INCLOSENOWRITE;