1 /*
2 * This file and its contents are supplied under the terms of the
3 * Common Development and Distribution License ("CDDL"), version 1.0.
4 * You may only use this file in accordance with the terms of version
5 * 1.0 of the CDDL.
6 *
7 * A full copy of the text of the CDDL should have accompanied this
8 * source. A copy of the CDDL is also available via the Internet at
9 * http://www.illumos.org/license/CDDL.
10 */
11
12 /*
13 * Copyright (c) 2014 Joyent, Inc. All rights reserved.
14 */
15
16 /*
17 * Header file to support for the inotify facility. Note that this facility
18 * is designed to be binary compatible with the Linux inotify facility; values
19 * for constants here should therefore exactly match those found in Linux, and
20 * this facility shouldn't be extended independently of Linux.
21 */
22
23 #ifndef _SYS_INOTIFY_H
24 #define _SYS_INOTIFY_H
25
26 #include <sys/types.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32 /*
33 * Events that can be explicitly requested on any inotify watch.
34 */
35 #define IN_ACCESS 0x00000001
36 #define IN_MODIFY 0x00000002
37 #define IN_ATTRIB 0x00000004
38 #define IN_CLOSE_WRITE 0x00000008
39 #define IN_CLOSE_NOWRITE 0x00000010
40 #define IN_OPEN 0x00000020
41 #define IN_MOVED_FROM 0x00000040
42 #define IN_MOVED_TO 0x00000080
43 #define IN_CREATE 0x00000100
44 #define IN_DELETE 0x00000200
45 #define IN_DELETE_SELF 0x00000400
46 #define IN_MOVE_SELF 0x00000800
47
48 /*
49 * Events that can be sent to an inotify watch -- requested or not.
50 */
51 #define IN_UNMOUNT 0x00002000
52 #define IN_Q_OVERFLOW 0x00004000
53 #define IN_IGNORED 0x00008000
54
55 /*
56 * Flags that can modify an inotify event.
57 */
58 #define IN_ONLYDIR 0x01000000
59 #define IN_DONT_FOLLOW 0x02000000
60 #define IN_EXCL_UNLINK 0x04000000
61 #define IN_MASK_ADD 0x20000000
62 #define IN_ISDIR 0x40000000
63 #define IN_ONESHOT 0x80000000
64
65 /*
66 * Helpful constants.
67 */
68 #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE)
69 #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO)
70 #define IN_ALL_EVENTS \
71 (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
72 IN_CLOSE_NOWRITE | IN_OPEN | IN_MOVED_FROM | IN_MOVED_TO | \
73 IN_DELETE | IN_CREATE | IN_DELETE_SELF | IN_MOVE_SELF)
74
75 #define IN_CHILD_EVENTS \
76 (IN_ACCESS | IN_MODIFY | IN_ATTRIB | IN_CLOSE_WRITE | \
77 IN_CLOSE_NOWRITE | IN_MODIFY | IN_OPEN)
78
79 /*
80 * To assure binary compatibility with Linux, these values are fixed at their
81 * Linux equivalents, not their native ones.
82 */
83 #define IN_CLOEXEC 02000000 /* LX_O_CLOEXEC */
84 #define IN_NONBLOCK 04000 /* LX_O_NONBLOCK */
85
86 struct inotify_event {
87 int32_t wd; /* watch descriptor */
88 uint32_t mask; /* mask of events */
89 uint32_t cookie; /* event association cookie, if any */
90 uint32_t len; /* size of name field */
91 char name[]; /* optional NUL-terminated name */
92 };
93
94 /*
95 * These ioctl values are specific to the native implementation; applications
96 * shouldn't be using them directly, and they should therefore be safe to
97 * change without breaking apps.
98 */
99 #define INOTIFYIOC (('i' << 24) | ('n' << 16) | ('y' << 8))
100 #define INOTIFYIOC_ADD_WATCH (INOTIFYIOC | 1) /* add watch */
101 #define INOTIFYIOC_RM_WATCH (INOTIFYIOC | 2) /* remove watch */
102 #define INOTIFYIOC_ADD_CHILD (INOTIFYIOC | 3) /* add child watch */
103 #define INOTIFYIOC_ACTIVATE (INOTIFYIOC | 4) /* activate watch */
104
105 #ifndef _LP64
106 #ifndef _LITTLE_ENDIAN
107 #define INOTIFY_PTR(type, name) uint32_t name##pad; type *name
108 #else
109 #define INOTIFY_PTR(type, name) type *name; uint32_t name##pad
110 #endif
111 #else
112 #define INOTIFY_PTR(type, name) type *name
113 #endif
114
115 typedef struct inotify_addwatch {
116 int inaw_fd; /* open fd for object */
117 uint32_t inaw_mask; /* desired mask */
118 } inotify_addwatch_t;
119
120 typedef struct inotify_addchild {
121 INOTIFY_PTR(char, inac_name); /* pointer to name */
122 int inac_fd; /* open fd for parent */
123 } inotify_addchild_t;
124
125 #ifndef _KERNEL
126
127 extern int inotify_init(void);
128 extern int inotify_init1(int);
129 extern int inotify_add_watch(int, const char *, uint32_t);
130 extern int inotify_rm_watch(int, int);
131
132 #else
133
134 #define IN_UNMASKABLE \
135 (IN_UNMOUNT | IN_Q_OVERFLOW | IN_IGNORED | IN_ISDIR)
136
137 #define IN_MODIFIERS \
138 (IN_EXCL_UNLINK | IN_ONESHOT)
139
140 #define IN_FLAGS \
141 (IN_ONLYDIR | IN_DONT_FOLLOW | IN_MASK_ADD)
142
143 #define IN_REMOVAL (1ULL << 32)
144 #define INOTIFYMNRN_INOTIFY 0
145 #define INOTIFYMNRN_CLONE 1
146
147 #endif /* _KERNEL */
148
149 #ifdef __cplusplus
150 }
151 #endif
152
153 #endif /* _SYS_INOTIFY_H */