Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/odin-lang/Odin
Browse files Browse the repository at this point in the history
  • Loading branch information
gingerBill committed Nov 14, 2024
2 parents b5a9b8b + 537ff3b commit f57d531
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
30 changes: 30 additions & 0 deletions core/sys/linux/bits.odin
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,36 @@ Fd_Poll_Events_Bits :: enum {
RDHUP = 13,
}

Inotify_Init_Bits :: enum {
NONBLOCK = 11,
CLOEXEC = 19,
}

Inotify_Event_Bits :: enum u32 {
ACCESS = 0,
MODIFY = 1,
ATTRIB = 2,
CLOSE_WRITE = 3,
CLOSE_NOWRITE = 4,
OPEN = 5,
MOVED_FROM = 6,
MOVED_TO = 7,
CREATE = 8,
DELETE = 9,
DELETE_SELF = 10,
MOVE_SELF = 11,
UNMOUNT = 13,
Q_OVERFLOW = 14,
IGNORED = 15,
ONLYDIR = 24,
DONT_FOLLOW = 25,
EXCL_UNLINK = 26,
MASK_CREATE = 28,
MASK_ADD = 29,
ISDIR = 30,
ONESHOT = 31,
}

/*
Bits for Mem_Protection bitfield
*/
Expand Down
25 changes: 25 additions & 0 deletions core/sys/linux/constants.odin
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,31 @@ STATX_BASIC_STATS :: Statx_Mask {
.BLOCKS,
}

IN_ALL_EVENTS :: Inotify_Event_Mask {
.ACCESS,
.MODIFY,
.ATTRIB,
.CLOSE_WRITE,
.CLOSE_NOWRITE,
.OPEN,
.MOVED_FROM,
.MOVED_TO,
.CREATE,
.DELETE,
.DELETE_SELF,
.MOVE_SELF,
}

IN_CLOSE :: Inotify_Event_Mask {
.CLOSE_WRITE,
.CLOSE_NOWRITE,
}

IN_MOVE :: Inotify_Event_Mask {
.MOVED_FROM,
.MOVED_TO,
}

/*
Tell `shmget` to create a new key
*/
Expand Down
25 changes: 22 additions & 3 deletions core/sys/linux/sys.odin
Original file line number Diff line number Diff line change
Expand Up @@ -2536,11 +2536,30 @@ 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) {
when ODIN_ARCH == .arm64 || ODIN_ARCH == .riscv64 {
ret := syscall(SYS_inotify_init1, 0)
return errno_unwrap(ret, Fd)
} else {
ret := syscall(SYS_inotify_init)
return errno_unwrap(ret, Fd)
}
}

// TODO(flysand): inotify_add_watch
inotify_init1 :: proc "contextless" (flags: Inotify_Init_Flags) -> (Fd, Errno) {
ret := syscall(SYS_inotify_init1, transmute(i32)flags)
return errno_unwrap(ret, Fd)
}

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)
}

// TODO(flysand): migrate_pages

Expand Down
17 changes: 17 additions & 0 deletions core/sys/linux/types.odin
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Id :: distinct uint
*/
Fd :: distinct i32

/*
Represents a watch descriptor.
*/
Wd :: distinct i32

/*
Type for PID file descriptors.
*/
Expand Down Expand Up @@ -343,6 +348,18 @@ 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,
name: [0]u8,
}

Inotify_Event_Mask :: bit_set[Inotify_Event_Bits; u32]

/*
Specifies protection for memory pages.
*/
Expand Down

0 comments on commit f57d531

Please sign in to comment.