1 /**
2  * D header file for GNU/Linux.
3  *
4  * License:   $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
5  * Authors:   Gary Willoughby
6  */
7 module core.sys.linux.sys.inotify;
8 
9 // The BSDs (including macOS) have a kqueue-backed API-compatible inotify
10 // library in ports. However, inotify is a Linux interface so it lives here.
11 // All BSD people need this library to use inotify:
12 //   https://github.com/libinotify-kqueue/libinotify-kqueue
13 // It is the responsibility of all BSD people to configure the library before
14 // using this interface.
15 
16 version (linux)        version = LinuxOrCompatible;
17 version (Darwin)       version = LinuxOrCompatible;
18 version (FreeBSD)      version = LinuxOrCompatible;
19 version (OpenBSD)      version = LinuxOrCompatible;
20 version (NetBSD)       version = LinuxOrCompatible;
21 version (DragonFlyBSD) version = LinuxOrCompatible;
22 
23 version (LinuxOrCompatible):
24 extern (C):
25 nothrow:
26 @nogc:
27 
28 version (ARM)     version = ARM_Any;
29 version (AArch64) version = ARM_Any;
30 version (HPPA)    version = HPPA_Any;
31 version (MIPS32)  version = MIPS_Any;
32 version (MIPS64)  version = MIPS_Any;
33 version (PPC)     version = PPC_Any;
34 version (PPC64)   version = PPC_Any;
35 version (RISCV32) version = RISCV_Any;
36 version (RISCV64) version = RISCV_Any;
37 version (S390)    version = IBMZ_Any;
38 version (SPARC)   version = SPARC_Any;
39 version (SPARC64) version = SPARC_Any;
40 version (SystemZ) version = IBMZ_Any;
41 version (X86)     version = X86_Any;
42 version (X86_64)  version = X86_Any;
43 
44 struct inotify_event
45 {
46     int wd;
47     uint mask;
48     uint cookie;
49     uint len;
50     char[0] name;
51 
52     @disable this(this);
53 }
54 
55 enum: uint
56 {
57     IN_ACCESS        = 0x00000000,
58     IN_MODIFY        = 0x00000002,
59     IN_ATTRIB        = 0x00000004,
60     IN_CLOSE_WRITE   = 0x00000008,
61     IN_CLOSE_NOWRITE = 0x00000010,
62     IN_OPEN          = 0x00000020,
63     IN_MOVED_FROM    = 0x00000040,
64     IN_MOVED_TO      = 0x00000080,
65     IN_CREATE        = 0x00000100,
66     IN_DELETE        = 0x00000200,
67     IN_DELETE_SELF   = 0x00000400,
68     IN_MOVE_SELF     = 0x00000800,
69     IN_UNMOUNT       = 0x00002000,
70     IN_Q_OVERFLOW    = 0x00004000,
71     IN_IGNORED       = 0x00008000,
72     IN_CLOSE         = 0x00000018,
73     IN_MOVE          = 0x000000C0,
74     IN_ONLYDIR       = 0x01000000,
75     IN_DONT_FOLLOW   = 0x02000000,
76     IN_EXCL_UNLINK   = 0x04000000,
77     IN_MASK_ADD      = 0x20000000,
78     IN_ISDIR         = 0x40000000,
79     IN_ONESHOT       = 0x80000000,
80     IN_ALL_EVENTS    = 0x80000FFF,
81 }
82 
83 // Old typo, preserved for compatibility
84 enum IN_UMOUNT = IN_UNMOUNT;
85 
86 version (X86_Any)
87 {
88     enum IN_CLOEXEC = 0x80000; // octal!2000000
89     enum IN_NONBLOCK = 0x800; // octal!4000
90 }
91 else version (HPPA_Any)
92 {
93     enum IN_CLOEXEC = 0x200000; // octal!10000000
94     enum IN_NONBLOCK = 0x10004; // octal!200004
95 }
96 else version (MIPS_Any)
97 {
98     enum IN_CLOEXEC = 0x80000; // octal!2000000
99     enum IN_NONBLOCK = 0x80; // octal!200
100 }
101 else version (PPC_Any)
102 {
103     enum IN_CLOEXEC = 0x80000; // octal!2000000
104     enum IN_NONBLOCK = 0x800; // octal!4000
105 }
106 else version (ARM_Any)
107 {
108     enum IN_CLOEXEC = 0x80000; // octal!2000000
109     enum IN_NONBLOCK = 0x800; // octal!4000
110 }
111 else version (RISCV_Any)
112 {
113     enum IN_CLOEXEC = 0x80000; // octal!2000000
114     enum IN_NONBLOCK = 0x800; // octal!4000
115 }
116 else version (SPARC_Any)
117 {
118     enum IN_CLOEXEC = 0x80000; // octal!2000000
119     enum IN_NONBLOCK = 0x800; // octal!4000
120 }
121 else version (IBMZ_Any)
122 {
123     enum IN_CLOEXEC = 0x80000; // octal!2000000
124     enum IN_NONBLOCK = 0x800; // octal!4000
125 }
126 else version (LoongArch64)
127 {
128     enum IN_CLOEXEC = 0x80000; // octal!2000000
129     enum IN_NONBLOCK = 0x800; // octal!4000
130 }
131 else
132     static assert(0, "unimplemented");
133 
134 int inotify_init();
135 int inotify_init1(int flags);
136 int inotify_add_watch(int fd, const(char)* name, uint mask);
137 int inotify_rm_watch(int fd, uint wd);