aboutsummaryrefslogtreecommitdiff
path: root/Inotify.dcl
blob: 0fa983dc00c1673b67e5e2595ea4ccb418c61898 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
definition module Inotify

/**
 * Links with Linux's inotify
 */

from Data.Either import ::Either
from Data.Maybe import ::Maybe

/**
 * An inotify file descriptor
 *
 * @var A state that is used for callbacks
 */
:: *Inotify st

/**
 * An inotify watch descriptor
 */
:: INWatch

/**
 * An inotify event mask
 */
:: INMask :== Int

/**
 * An inotify event
 */
:: INEvent :== Int

/**
 * An inotify callback: event, maybe filename, state, world -> state, world
 *
 * @var A state that is passed on.
 */
:: INCallback st :== INEvent (Maybe String) st *World -> *(st, *World)

/**
 * Bitwise OR for event masks
 */
(|-) infixl 6 :: (INMask INMask -> INMask)

/**
 * Initialise an inotify file descriptor with some state.
 *
 * @param The initial state
 * @result A file descriptor or Nothing if the C initialisation failed
 */
inotify_init :: st -> Maybe *(Inotify st)

/**
 * Close an inotify file descriptor and get back the state
 *
 * @param The file descriptor
 * @result The final state
 */
inotify_close :: *(Inotify st) -> st

/**
 * Add a watch on some file
 *
 * @param The callback for events
 * @param A mask of events to watch for
 * @param The filename
 * @param The inotify file descriptor
 * @result Either an error code or a watch descriptor, and the inotify file descriptor
 */
inotify_add_watch :: (INCallback st) !INMask !String !*(Inotify st)
	-> *(!Either Int INWatch, !*Inotify st)

/**
 * Remove a watch
 *
 * @param The watch to remove
 * @param The inotify file descriptor
 * @result A boolean indicating success and the inotify file descriptor
 */
inotify_rm_watch :: !INWatch !*(Inotify st) -> *(!Bool, !*Inotify st)

/**
 * Poll an inotify file descriptor; i.e. wait for new events
 *
 * @param Timeout in milliseconds (Nothing for no timeout)
 * @param The inotify file descriptor
 * @result The number of events, and the inotify file descriptor
 */
inotify_poll :: !(Maybe Int) !*(Inotify st) -> *(!Int, !*Inotify st)

/**
 * Check for new events and call callbacks
 */
inotify_check :: !*(Inotify st) !*World -> *(!*Inotify st, !*World)

/**
 * Check if an event matches a mask
 *
 * @param The mask
 * @param The event
 * @result True iff the event matches the mask
 */
inotify_is_event :: INMask INEvent -> Bool

/**
 * Combination of inotify_poll and inotify_check that will return only if no
 * events were given when a timeout occurred.
 *
 * @param Timeout in milliseconds (Nothing for no timeout)
 * @param The inotify file descriptor
 * @param The World
 * @result The inotify file descriptor and the World. However, the function
 *   only returns if no events were given when the timeout occurred. Otherwise,
 *   it will loop.
 */
inotify_loop_with_timeout :: !(Maybe Int) !*(Inotify st) !*World
	-> *(!*Inotify st, !*World)

/**
 * inotify_loop_with_timeout with Nothing as timeout (will never return)
 *
 * @param The inotify file descriptor
 * @param The World
 * @result The parameters back, however, this function will never return.
 */
inotify_loop_forever :: !*(Inotify st) !*World -> *(!*Inotify st, !*World)

/*** Begin inotify.h ***/

/**
 * Inotify event mask: file was accessed
 */
IN_ACCESS        :== 0x00000001

/**
 * Inotify event mask: file was modified
 */
IN_MODIFY        :== 0x00000002

/**
 * Inotify event mask: metadata changed
 */
IN_ATTRIB        :== 0x00000004

/**
 * Inotify event mask: file opened for writing was closed
 */
IN_CLOSE_WRITE   :== 0x00000008

/**
 * Inotify event mask: file not opened for writing was closed
 */
IN_CLOSE_NOWRITE :== 0x00000010

/**
 * Inotify event mask: file was opened
 */
IN_OPEN          :== 0x00000020

/**
 * Inotify event mask: file was moved from watched directory
 */
IN_MOVED_FROM    :== 0x00000040

/**
 * Inotify event mask: file was moved to watched directory
 */
IN_MOVED_TO      :== 0x00000080

/**
 * Inotify event mask: file was created in watched directory
 */
IN_CREATE        :== 0x00000100

/**
 * Inotify event mask: file in watched directory was deleted
 */
IN_DELETE        :== 0x00000200

/**
 * Inotify event mask: watched file was deleted
 */
IN_DELETE_SELF   :== 0x00000400

/**
 * Inotify event mask: watched file was moved
 */
IN_MOVE_SELF     :== 0x00000800

/**
 * Inotify event mask: backing fs of watched file was unmounted
 */
IN_UNMOUNT       :== 0x00002000

/**
 * Inotify event mask: the inotify event queue overflowed
 */
IN_Q_OVERFLOW    :== 0x00004000

/**
 * Inotify event mask: the watch has been removed, either through
 * inotify_rm_watch or because it was deleted, the fs was unmounted, etc.
 */
IN_IGNORED       :== 0x00008000

/**
 * Inotify event mask: watched file was closed
 */
IN_CLOSE         :== (IN_CLOSE_WRITE |- IN_CLOSE_NOWRITE)

/**
 * Inotify event mask: a file was moved from or to a watched directory
 */
IN_MOVE          :== (IN_MOVED_FROM |- IN_MOVED_TO)

/**
 * Inotify event mask: only watch the path if it is a directory
 */
IN_ONLYDIR       :== 0x01000000

/**
 * Inotify event mask: don't follow symlinks
 */
IN_DONT_FOLLOW   :== 0x02000000

/**
 * Inotify event mask: stop watching files when they get unlinked
 */
IN_EXCL_UNLINK   :== 0x04000000

/**
 * Inotify event mask: when adding a watch on a path for which a watch already
 * exists, OR the new event mask with the old one instead of replacing it.
 */
IN_MASK_ADD      :== 0x20000000

/**
 * Inotify event mask: the event occurred against a directory
 */
IN_ISDIR         :== 0x40000000

/**
 * Inotify event mask: monitor a watch only for one event, then remove it
 */
IN_ONESHOT       :== 0x80000000

/**
 * Inotify event mask: OR of all events
 */
IN_ALL_EVENTS    :==
	(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)

/*** End inotify.h ***/