Skip to content

Commit 1f63b26

Browse files
committed
Auto merge of #1230 - vdagonneau:master, r=gnzlbg
Added inotify bindings. Hi, I'd like to add inotify bindings. This is a first throw at it. Can you guide me through the process of merging it ?
2 parents f8a2c53 + dfb7c0c commit 1f63b26

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

libc-test/build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,8 @@ fn main() {
288288
cfg.header("linux/if_ether.h");
289289
cfg.header("linux/if_tun.h");
290290
cfg.header("linux/net_tstamp.h");
291+
cfg.header("sys/inotify.h");
292+
291293
// DCCP support
292294
if !uclibc && !musl && !emscripten {
293295
cfg.header("linux/dccp.h");

src/unix/notbsd/linux/mod.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,13 @@ s! {
655655
pub updated: ::c_ulong,
656656
pub ha: [::c_uchar; ::MAX_ADDR_LEN],
657657
}
658+
659+
pub struct inotify_event {
660+
pub wd: ::c_int,
661+
pub mask: ::uint32_t,
662+
pub cookie: ::uint32_t,
663+
pub len: ::uint32_t
664+
}
658665
}
659666

660667
pub const ABDAY_1: ::nl_item = 0x20000;
@@ -1677,6 +1684,45 @@ pub const ARPD_LOOKUP: ::c_ushort = 0x02;
16771684
pub const ARPD_FLUSH: ::c_ushort = 0x03;
16781685
pub const ATF_MAGIC: ::c_int = 0x80;
16791686

1687+
// uapi/linux/inotify.h
1688+
pub const IN_ACCESS: ::uint32_t = 0x0000_0001;
1689+
pub const IN_MODIFY: ::uint32_t = 0x0000_0002;
1690+
pub const IN_ATTRIB: ::uint32_t = 0x0000_0004;
1691+
pub const IN_CLOSE_WRITE: ::uint32_t = 0x0000_0008;
1692+
pub const IN_CLOSE_NOWRITE: ::uint32_t = 0x0000_0010;
1693+
pub const IN_CLOSE: ::uint32_t = (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE);
1694+
pub const IN_OPEN: ::uint32_t = 0x0000_0020;
1695+
pub const IN_MOVED_FROM: ::uint32_t = 0x0000_0040;
1696+
pub const IN_MOVED_TO: ::uint32_t = 0x0000_0080;
1697+
pub const IN_MOVE: ::uint32_t = (IN_MOVED_FROM | IN_MOVED_TO);
1698+
pub const IN_CREATE: ::uint32_t = 0x0000_0100;
1699+
pub const IN_DELETE: ::uint32_t = 0x0000_0200;
1700+
pub const IN_DELETE_SELF: ::uint32_t = 0x0000_0400;
1701+
pub const IN_MOVE_SELF: ::uint32_t = 0x0000_0800;
1702+
1703+
pub const IN_UNMOUNT: ::uint32_t = 0x0000_2000;
1704+
pub const IN_Q_OVERFLOW: ::uint32_t = 0x0000_4000;
1705+
pub const IN_IGNORED: ::uint32_t = 0x0000_8000;
1706+
1707+
pub const IN_ONLYDIR: ::uint32_t = 0x0100_0000;
1708+
pub const IN_DONT_FOLLOW: ::uint32_t = 0x0200_0000;
1709+
// pub const IN_EXCL_UNLINK: ::uint32_t = 0x0400_0000;
1710+
1711+
// pub const IN_MASK_CREATE: ::uint32_t = 0x1000_0000;
1712+
// pub const IN_MASK_ADD: ::uint32_t = 0x2000_0000;
1713+
pub const IN_ISDIR: ::uint32_t = 0x4000_0000;
1714+
pub const IN_ONESHOT: ::uint32_t = 0x8000_0000;
1715+
1716+
pub const IN_ALL_EVENTS: ::uint32_t = (
1717+
IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE |
1718+
IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM |
1719+
IN_MOVED_TO | IN_DELETE | IN_CREATE | IN_DELETE_SELF |
1720+
IN_MOVE_SELF
1721+
);
1722+
1723+
pub const IN_CLOEXEC: ::c_int = O_CLOEXEC;
1724+
pub const IN_NONBLOCK: ::c_int = O_NONBLOCK;
1725+
16801726
#[cfg(not(target_arch = "sparc64"))]
16811727
pub const SO_TIMESTAMPING: ::c_int = 37;
16821728
#[cfg(target_arch = "sparc64")]
@@ -2259,6 +2305,12 @@ extern {
22592305
nobj: ::size_t,
22602306
stream: *mut ::FILE
22612307
) -> ::size_t;
2308+
pub fn inotify_init() -> ::c_int;
2309+
pub fn inotify_init1(flags: ::c_int) -> ::c_int;
2310+
pub fn inotify_add_watch(fd: ::c_int,
2311+
path: *const ::c_char,
2312+
mask: ::uint32_t) -> ::c_int;
2313+
pub fn inotify_rm_watch(fd: ::c_int, wd: ::c_int) -> ::c_int;
22622314
}
22632315

22642316
cfg_if! {

0 commit comments

Comments
 (0)