From 01752b3cb4573b1f3f777e2b3cc88f67c902b2d3 Mon Sep 17 00:00:00 2001 From: Vincent Dagonneau Date: Sat, 26 Jan 2019 10:29:53 +0100 Subject: [PATCH 1/4] Added inotify bindings. --- src/unix/notbsd/linux/mod.rs | 53 ++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 8669a06ca5954..fac779afd5cfd 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -655,6 +655,13 @@ s! { pub updated: ::c_ulong, pub ha: [::c_uchar; ::MAX_ADDR_LEN], } + + pub struct inotify_event { + pub wd: ::c_int, + pub mask: ::uint32_t, + pub cookie: ::uint32_t, + pub len: ::uint32_t + } } pub const ABDAY_1: ::nl_item = 0x20000; @@ -1677,6 +1684,46 @@ pub const ARPD_LOOKUP: ::c_ushort = 0x02; pub const ARPD_FLUSH: ::c_ushort = 0x03; pub const ATF_MAGIC: ::c_int = 0x80; +// uapi/linux/inotify.h +pub const IN_ACCESS: ::uint32_t = 0x0000_0001; +pub const IN_MODIFY: ::uint32_t = 0x0000_0002; +pub const IN_ATTRIB: ::uint32_t = 0x0000_0004; +pub const IN_CLOSE_WRITE: ::uint32_t = 0x0000_0008; +pub const IN_CLOSE_NOWRITE: ::uint32_t = 0x0000_0010; +pub const IN_OPEN: ::uint32_t = 0x0000_0020; +pub const IN_MOVED_FROM: ::uint32_t = 0x0000_0040; +pub const IN_MOVED_TO: ::uint32_t = 0x0000_0080; +pub const IN_CREATE: ::uint32_t = 0x0000_0100; +pub const IN_DELETE: ::uint32_t = 0x0000_0200; +pub const IN_DELETE_SELF: ::uint32_t = 0x0000_0400; +pub const IN_MOVE_SELF: ::uint32_t = 0x0000_0800; + +pub const IN_UNMOUNT: ::uint32_t = 0x0000_2000; +pub const IN_Q_OVERFLOW: ::uint32_t = 0x0000_4000; +pub const IN_IGNORED: ::uint32_t = 0x0000_8000; + +pub const IN_CLOSE: ::uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); +pub const IN_MOVE: ::uint32_t = (IN_MOVED_FROM | IN_MOVED_TO); + +pub const IN_ONLYDIR: ::uint32_t = 0x0100_0000; +pub const IN_DONT_FOLLOW: ::uint32_t = 0x0200_0000; +pub const IN_EXCL_UNLINK: ::uint32_t = 0x0400_0000; + +pub const IN_MASK_CREATE: ::uint32_t = 0x1000_0000; +pub const IN_MASK_ADD: ::uint32_t = 0x2000_0000; +pub const IN_ISDIR: ::uint32_t = 0x4000_0000; +pub const IN_ONESHOT: ::uint32_t = 0x8000_0000; + +pub const IN_ALL_EVENTS: ::uint32_t = ( + IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | + IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | + IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF | + IN_MOVE_SELF +); + +pub const IN_CLOEXEC: ::c_int = O_CLOEXEC; +pub const IN_NONBLOCK: ::c_int = O_NONBLOCK; + #[cfg(not(target_arch = "sparc64"))] pub const SO_TIMESTAMPING: ::c_int = 37; #[cfg(target_arch = "sparc64")] @@ -2259,6 +2306,12 @@ extern { nobj: ::size_t, stream: *mut ::FILE ) -> ::size_t; + pub fn inotify_init() -> ::c_int; + pub fn inotify_init1(flags: ::c_int) -> ::c_int; + pub fn inotify_add_watch(fd: ::c_int, + path: *const ::c_char, + mask: ::uint32_t) -> ::c_int; + pub fn inotify_rm_watch(fd: ::c_int, wd: ::c_int) -> ::c_int; } cfg_if! { From eb3e48c62ffe21f928d7bff50bfa10fcf4dbd439 Mon Sep 17 00:00:00 2001 From: Vincent Dagonneau Date: Mon, 28 Jan 2019 19:41:29 +0100 Subject: [PATCH 2/4] Added inotify headers to the libc-test. --- libc-test/build.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 5edbdf5b73893..ae9dabbe93577 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -288,6 +288,8 @@ fn main() { cfg.header("linux/if_ether.h"); cfg.header("linux/if_tun.h"); cfg.header("linux/net_tstamp.h"); + cfg.header("uapi/linux/inotify.h"); + // DCCP support if !uclibc && !musl && !emscripten { cfg.header("linux/dccp.h"); From da27966859d92798d4cf1f5a1809a988edcbafcd Mon Sep 17 00:00:00 2001 From: Vincent Dagonneau Date: Mon, 28 Jan 2019 20:56:15 +0100 Subject: [PATCH 3/4] Fixed typo; Added inotify headers to the libc-test. --- libc-test/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index ae9dabbe93577..1853a1fcb787b 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -288,7 +288,7 @@ fn main() { cfg.header("linux/if_ether.h"); cfg.header("linux/if_tun.h"); cfg.header("linux/net_tstamp.h"); - cfg.header("uapi/linux/inotify.h"); + cfg.header("linux/inotify.h"); // DCCP support if !uclibc && !musl && !emscripten { From dfb7c0caba40c15dc627d20a0a92fb0c3fba2ae4 Mon Sep 17 00:00:00 2001 From: Vincent Dagonneau Date: Mon, 4 Feb 2019 09:11:21 +0100 Subject: [PATCH 4/4] Added the proper libc header to libc-test; Removed some defines as they seem to be too new. --- libc-test/build.rs | 2 +- src/unix/notbsd/linux/mod.rs | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 1853a1fcb787b..d81a54d716224 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -288,7 +288,7 @@ fn main() { cfg.header("linux/if_ether.h"); cfg.header("linux/if_tun.h"); cfg.header("linux/net_tstamp.h"); - cfg.header("linux/inotify.h"); + cfg.header("sys/inotify.h"); // DCCP support if !uclibc && !musl && !emscripten { diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index fac779afd5cfd..ea26933f19434 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -1690,9 +1690,11 @@ pub const IN_MODIFY: ::uint32_t = 0x0000_0002; pub const IN_ATTRIB: ::uint32_t = 0x0000_0004; pub const IN_CLOSE_WRITE: ::uint32_t = 0x0000_0008; pub const IN_CLOSE_NOWRITE: ::uint32_t = 0x0000_0010; +pub const IN_CLOSE: ::uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); pub const IN_OPEN: ::uint32_t = 0x0000_0020; pub const IN_MOVED_FROM: ::uint32_t = 0x0000_0040; pub const IN_MOVED_TO: ::uint32_t = 0x0000_0080; +pub const IN_MOVE: ::uint32_t = (IN_MOVED_FROM | IN_MOVED_TO); pub const IN_CREATE: ::uint32_t = 0x0000_0100; pub const IN_DELETE: ::uint32_t = 0x0000_0200; pub const IN_DELETE_SELF: ::uint32_t = 0x0000_0400; @@ -1702,15 +1704,12 @@ pub const IN_UNMOUNT: ::uint32_t = 0x0000_2000; pub const IN_Q_OVERFLOW: ::uint32_t = 0x0000_4000; pub const IN_IGNORED: ::uint32_t = 0x0000_8000; -pub const IN_CLOSE: ::uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE); -pub const IN_MOVE: ::uint32_t = (IN_MOVED_FROM | IN_MOVED_TO); - pub const IN_ONLYDIR: ::uint32_t = 0x0100_0000; pub const IN_DONT_FOLLOW: ::uint32_t = 0x0200_0000; -pub const IN_EXCL_UNLINK: ::uint32_t = 0x0400_0000; +// pub const IN_EXCL_UNLINK: ::uint32_t = 0x0400_0000; -pub const IN_MASK_CREATE: ::uint32_t = 0x1000_0000; -pub const IN_MASK_ADD: ::uint32_t = 0x2000_0000; +// pub const IN_MASK_CREATE: ::uint32_t = 0x1000_0000; +// pub const IN_MASK_ADD: ::uint32_t = 0x2000_0000; pub const IN_ISDIR: ::uint32_t = 0x4000_0000; pub const IN_ONESHOT: ::uint32_t = 0x8000_0000;