aboutsummaryrefslogtreecommitdiff
path: root/core/sys/linux
diff options
context:
space:
mode:
Diffstat (limited to 'core/sys/linux')
-rw-r--r--core/sys/linux/bits.odin22
-rw-r--r--core/sys/linux/constants.odin8
-rw-r--r--core/sys/linux/sys.odin26
-rw-r--r--core/sys/linux/types.odin19
4 files changed, 72 insertions, 3 deletions
diff --git a/core/sys/linux/bits.odin b/core/sys/linux/bits.odin
index 9f2c7a5d8..b22a021f6 100644
--- a/core/sys/linux/bits.odin
+++ b/core/sys/linux/bits.odin
@@ -519,6 +519,28 @@ Fd_Poll_Events_Bits :: enum {
RDHUP = 13,
}
+Inotify_Init_Bits :: enum {
+ IN_NONBLOCK = 11,
+ IN_CLOEXEC = 19,
+}
+
+Inotify_Events_Bits :: enum u32 {
+ IN_ACCESS = 0,
+ IN_MODIFY = 1,
+ IN_ATTRIB = 2,
+ IN_CLOSE_WRITE = 3,
+ IN_CLOSE_NOWRITE = 4,
+ IN_CLOSE = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE),
+ IN_OPEN = 5,
+ IN_MOVED_FROM = 6,
+ IN_MOVED_TO = 7,
+ IN_MOVE = (IN_MOVED_FROM | IN_MOVED_TO),
+ IN_CREATE = 8,
+ IN_DELETE = 9,
+ IN_DELETE_SELF = 10,
+ IN_MOVE_SELF = 11,
+}
+
/*
Bits for Mem_Protection bitfield
*/
diff --git a/core/sys/linux/constants.odin b/core/sys/linux/constants.odin
index 129444d0f..551a4fc40 100644
--- a/core/sys/linux/constants.odin
+++ b/core/sys/linux/constants.odin
@@ -135,6 +135,14 @@ STATX_BASIC_STATS :: Statx_Mask {
.BLOCKS,
}
+IN_ONLYDIR :: 0x01000000
+IN_DONT_FOLLOW :: 0x02000000
+IN_EXCL_UNLINK :: 0x04000000
+IN_MASK_CREATE :: 0x10000000
+IN_MASK_ADD :: 0x20000000
+IN_ISDIR :: 0x40000000
+IN_ONESHOT :: 0x80000000
+
/*
Tell `shmget` to create a new key
*/
diff --git a/core/sys/linux/sys.odin b/core/sys/linux/sys.odin
index c5894d78b..819edc4a5 100644
--- a/core/sys/linux/sys.odin
+++ b/core/sys/linux/sys.odin
@@ -2536,11 +2536,31 @@ waitid :: proc "contextless" (id_type: Id_Type, id: Id, sig_info: ^Sig_Info, opt
// TODO(flysand): ioprio_get
-// TODO(flysand): inotify_init
+inotify_init :: proc "contextless" () -> (Fd, Errno) {
+ ret := syscall(SYS_inotify_init)
+ return errno_unwrap(ret, Fd)
+}
+
+inotify_init1 :: proc "contextless" (flags: Inotify_Init_Flags) -> (Fd, Errno) {
+ ret := syscall(SYS_inotify_init1, transmute(i32)flags)
+ return errno_unwrap(ret, Fd)
+}
-// TODO(flysand): inotify_add_watch
+inotify_add_watch :: proc "contextless" (fd: Fd, pathname: cstring, mask: Inotify_Event_Mask) -> (Wd, Errno) {
+ ret := syscall(SYS_inotify_add_watch, fd, transmute(uintptr) pathname, transmute(u32) mask)
+ return errno_unwrap(ret, Wd)
+}
-// TODO(flysand): inotify_rm_watch
+inotify_rm_watch :: proc "contextless" (fd: Fd, wd: Wd) -> (Errno) {
+ ret := syscall(SYS_inotify_rm_watch, fd, wd)
+ return Errno(-ret)
+}
+
+// helper procedure to access the data within an `Inotify_Event`
+// since Odin doesn't have an alternative to `__flexarr`
+inotify_event_name :: proc "contextless" (event: ^Inotify_Event) -> cstring {
+ return transmute(cstring)&event.name
+}
// TODO(flysand): migrate_pages
diff --git a/core/sys/linux/types.odin b/core/sys/linux/types.odin
index 07c654749..88b8f3f3c 100644
--- a/core/sys/linux/types.odin
+++ b/core/sys/linux/types.odin
@@ -31,6 +31,11 @@ Id :: distinct uint
Fd :: distinct i32
/*
+ Represents a watch descriptor.
+*/
+Wd :: distinct i32
+
+/*
Type for PID file descriptors.
*/
Pid_FD :: distinct i32
@@ -343,6 +348,20 @@ Poll_Fd :: struct {
revents: Fd_Poll_Events,
}
+Inotify_Init_Flags :: bit_set[Inotify_Init_Bits; i32];
+
+Inotify_Event :: struct {
+ wd: Wd,
+ mask: Inotify_Event_Mask,
+ cookie: u32,
+ len: u32,
+ // used in place of __flexarr
+ // use inotify_event_name to read
+ name: [0]u8,
+}
+
+Inotify_Event_Mask :: bit_set[Inotify_Events_Bits; u32]
+
/*
Specifies protection for memory pages.
*/