xref: /haiku/docs/user/storage/NodeMonitor.dox (revision 14b32de1d5efe99b4c6d4ef8c25df47eb009cf0f)
1/*
2 * Copyright 2003-2013 Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
4 *
5 * Authors:
6 *		Axel Dörfler, axeld@pinc-software.de
7 *		John Scipione, jscipione@gmail.com
8 *		Ingo Weinhold, bonefish@users.sf.net
9 *		Clemens Zeidler, haiku@clemens-zeidler.de
10 *
11 * Corresponds to:
12 *		headers/os/storage/NodeMonitor.h	hrev45253
13 *		src/kits/storage/NodeMonitor.cpp	hrev45253
14 */
15
16
17/*!
18	\file NodeMonitor.h
19	\ingroup storage
20	\ingroup libbe
21	\brief Provides functions and constants for monitoring changes to a node.
22
23	The are three main node monitoring functions are watch_volume(),
24	watch_node() and stop_watching().
25	- watch_volume() starts watching a volume and sends a message
26	  when a requested event occurs.
27	- watch_node() starts or stops watching a node, or watches for volumes
28	  to be mounted and unmounted, and sends a message when an event occurs.
29	- stop_watching() stops monitoring a node or volume and no longer sends
30	  messages.
31*/
32
33
34/*!
35	\var B_STOP_WATCHING
36
37	Flag for watch_node(). Unsubscribe from watching a node.
38
39	\attention \c B_STOP_WATCHING does not apply to volume watching, you must
40	           call stop_watching() instead.
41*/
42
43
44/*!
45	\var B_WATCH_NAME
46
47	Flag for watch_volume() and watch_node(). Subscribe to watching for
48	change to the name of a node.
49*/
50
51
52/*!
53	\var B_WATCH_STAT
54
55	Flag for watch_volume() and watch_node(). Subscribe to watching for
56	changes to the stat information of a node.
57*/
58
59
60/*!
61	\var B_WATCH_ATTR
62
63	Flag for watch_volume() and watch_node(). Subscribe to watching for
64	changes to the attributes of a node.
65*/
66
67
68/*!
69	\var B_WATCH_DIRECTORY
70
71	Flag for watch_node(). Subscribe to watching for changes to the contents
72	of a directory.
73*/
74
75
76/*!
77	\var B_WATCH_ALL
78
79	Flag for watch_node(). Subscribe to watching for changes to all
80	information of a node except \c B_WATCH_MOUNT.
81*/
82
83
84/*!
85	\var B_WATCH_MOUNT
86
87	Flag for watch_node(). Subscribe to watching for when a volume is mounted
88	or unmounted. You may prefer to use BVolumeRoster for volume watching
89	instead.
90*/
91
92
93/*!
94	\var B_WATCH_INTERIM_STAT
95
96	\internal Implementation detail. Not in Be Book.
97
98	To avoid a flood of messages for small and frequent write operations on an
99	open file the file system can limit the number of notifications and mark
100	them with the \c B_WATCH_INTERIM_STAT flag.
101*/
102
103
104/*!
105	\def B_ENTRY_CREATED
106
107	\c B_NODE_MONITOR notification message "opcode" is set when entry is
108	created.
109*/
110
111
112/*!
113	\def B_ENTRY_REMOVED
114
115	\c B_NODE_MONITOR notification message "opcode" is set when entry is
116	removed.
117*/
118
119
120/*!
121	\def B_ENTRY_MOVED
122
123	\c B_NODE_MONITOR notification message "opcode" is set when entry is
124	moved.
125*/
126
127
128/*!
129	\def B_STAT_CHANGED
130
131	\c B_NODE_MONITOR notification message "opcode" set when stat info
132	changes. More information can be found in the "fields" field.
133*/
134
135
136/*!
137	\def B_ATTR_CHANGED
138
139	\c B_NODE_MONITOR notification message "opcode" set when attribute
140	changes. More information can be found in the "cause" field.
141*/
142
143
144/*!
145	\def B_DEVICE_MOUNTED
146
147	\c B_NODE_MONITOR notification message "opcode" set when device is
148	mounted.
149*/
150
151
152/*!
153	\def B_DEVICE_UNMOUNTED
154
155	\c B_NODE_MONITOR notification message "opcode" set when device is
156	unmounted.
157*/
158
159
160/*!
161	\def B_ATTR_CREATED
162
163	\c B_ATTR_CHANGED notification message "cause" set when attribute is
164	created. (Haiku only)
165*/
166
167
168/*!
169	\def B_ATTR_REMOVED
170
171	\c B_ATTR_CHANGED notification message "cause" set when attribute is
172	removed. (Haiku only)
173*/
174
175
176/*!
177	\var B_STAT_MODE
178
179	\c B_STAT_CHANGED notification messages "fields" flag set when stat mode
180	changes.
181*/
182
183
184/*!
185	\var B_STAT_UID
186
187	\c B_STAT_CHANGED notification messages "fields" flag set when UID
188	changes.
189*/
190
191
192/*!
193	\var B_STAT_GID
194
195	\c B_STAT_CHANGED notification messages "fields" flag set when GID
196	changes.
197*/
198
199
200/*!
201	\var B_STAT_SIZE
202
203	\c B_STAT_CHANGED notification messages "fields" flag set when stat size
204	changes.
205*/
206
207
208/*!
209	\var B_STAT_ACCESS_TIME
210
211	\c B_STAT_CHANGED notification messages "fields" flag set when access time
212	changes.
213*/
214
215
216/*!
217	\var B_STAT_MODIFICATION_TIME
218
219	\c B_STAT_CHANGED notification messages "fields" flag set when
220	modification time changes.
221*/
222
223
224/*!
225	\var B_STAT_CREATION_TIME
226
227	\c B_STAT_CHANGED notification messages "fields" flag set when creation
228	time changes.
229*/
230
231
232/*!
233	\var B_STAT_CHANGE_TIME
234
235	\c B_STAT_CHANGED notification messages "fields" flag set when access,
236	modification or creation time changes.
237*/
238
239
240/*!
241	\var B_STAT_INTERIM_UPDATE
242
243	\internal Implementation detail. Not in Be Book.
244
245	\c B_STAT_CHANGED notification messages "fields" flag set when file is
246	written to.
247*/
248
249
250/*!
251	\fn status_t watch_volume(dev_t volume, uint32 flags, BMessenger target)
252	\brief Subscribes \a target to watch node changes on \a volume.
253
254	Depending of \a flags the action performed by this function varies:
255	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
256	  or <tt>B_WATCH_ATTR</tt>: The target is subscribed to watching the specified
257	  aspects of any node on the volume.
258
259	\a flags may include:
260	- \c B_WATCH_NAME
261	- \c B_WATCH_STAT
262	- \c B_WATCH_ATTR
263
264	\c B_WATCH_VOLUME flag is assumed.
265
266	\param volume dev_t referring to the volume to be watched.
267	\param flags Flags indicating the actions to be performed.
268	\param target Messenger referring to the target. Must be valid.
269
270	\return A status code.
271	\retval B_OK Everything went fine.
272	\retval B_BAD_VALUE \a flags did not include one of \c B_WATCH_NAME,
273	        \c B_WATCH_STAT, or \c B_WATCH_ATTR.
274*/
275
276
277/*!
278	\fn status_t watch_volume(dev_t volume, uint32 flags,
279		const BHandler *handler, const BLooper *looper)
280	\brief Subscribes \a handler or \a looper to watch node changes on
281	       \a volume.
282
283	Depending of \a flags the action performed by this function varies:
284	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
285	  or <tt>B_WATCH_ATTR</tt>: The target is subscribed to watching the specified
286	  aspects of any node on the volume.
287
288	\a flags may include:
289	- \c B_WATCH_NAME
290	- \c B_WATCH_STAT
291	- \c B_WATCH_ATTR
292
293	\c B_WATCH_VOLUME flag is assumed.
294
295	\param volume dev_t referring to the volume to be watched.
296	\param flags Flags indicating the actions to be performed.
297	\param handler The target \a handler. May be \c NULL, if \a looper is not
298	       \c NULL. Then the preferred handler of the looper is targeted.
299	\param looper The target \a looper. May be \c NULL, if \a handler is not
300	       \c NULL. Then the handler's looper is the target looper.
301
302	\return A status code.
303	\retval B_OK Everything went fine.
304	\retval B_BAD_VALUE \a flags did not include one of \c B_WATCH_NAME,
305	        \c B_WATCH_STAT, or \c B_WATCH_ATTR.
306*/
307
308
309/*!
310	\fn status_t watch_node(const node_ref *node, uint32 flags,
311		BMessenger target)
312	\brief Subscribes or unsubscribes \a target to node and/or mount watching.
313
314	Depending of \a flags the action performed by this function varies:
315	- \a flags is 0: The target is unsubscribed from watching the node.
316	  \a node must not be \c NULL in this case.
317	- \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
318	  watching.
319	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
320	  \c B_WATCH_ATTR, or <tt>B_WATCH_DIRECTORY</tt>: The target is subscribed to
321	  watching the specified aspects of the node. \a node must not be \c NULL
322	  in this case.
323
324	\a flags may include:
325	- \c B_STOP_WATCHING
326
327	or one or more of the following:
328	- \c B_WATCH_NAME
329	- \c B_WATCH_STAT
330	- \c B_WATCH_ATTR
331	- \c B_WATCH_DIRECTORY
332	- \c B_WATCH_ALL
333	- \c B_WATCH_MOUNT
334
335	Note that the latter two cases are not mutual exclusive, i.e. mount and
336	node watching can be requested with a single call.
337
338	\param node node_ref referring to the node to be watched. May be \c NULL,
339	       if only mount watching is requested.
340	\param flags Flags indicating the actions to be performed.
341	\param target BMessenger object referring to the \a target.
342
343	\return \c B_OK if everything went fine, an error code otherwise.
344*/
345
346
347/*!
348	\fn status_t watch_node(const node_ref *node, uint32 flags,
349		const BHandler *handler, const BLooper *looper)
350	\brief Subscribes or unsubscribes \a handler or \a looper to node and/or
351	       mount watching.
352
353	Depending of \a flags the action performed by this function varies:
354	- \a flags is 0: The target is unsubscribed from watching the node.
355	  \a node must not be \c NULL in this case.
356	- \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
357	  watching.
358	- \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
359	  \c B_WATCH_ATTR, or <tt>B_WATCH_DIRECTORY</tt>: The target is subscribed to
360	  watching the specified aspects of the node. \a node must not be \c NULL
361	  in this case.
362
363	\a flags may include:
364	- \c B_STOP_WATCHING
365
366	or one or more of the following:
367	- \c B_WATCH_NAME
368	- \c B_WATCH_STAT
369	- \c B_WATCH_ATTR
370	- \c B_WATCH_DIRECTORY
371	- \c B_WATCH_ALL
372	- \c B_WATCH_MOUNT
373
374	Note that the latter two cases are not mutual exclusive, i.e. mount and
375	node watching can be requested with a single call.
376
377	\param node node_ref referring to the node to be watched. May be \c NULL,
378	       if only mount watching is requested.
379	\param flags Flags indicating the actions to be performed.
380	\param handler The target handler. May be \c NULL, if \a looper is not
381	       \c NULL. Then the preferred handler of the looper is targeted.
382	\param looper The target looper. May be \c NULL, if \a handler is not
383	       \c NULL. Then the handler's looper is the target looper.
384
385	\return \c B_OK if everything went fine, an error code otherwise.
386*/
387
388
389/*!
390	\fn status_t stop_watching(BMessenger target)
391	\brief Unsubscribes \a target from node and mount monitoring.
392
393	You may still receive notification messages after calling stop_watching()
394	because while node monitoring is asynchronous and all changes are atomic,
395	message sending is not atomic so there is a lag time from when you
396	stop monitoring and when the message is received in your message receiving
397	thread. You can check the timestamp of the message to determine if
398	it was sent after stop_watching() was called.
399
400	\param target BMessenger object referring to the \a target.
401
402	\return A status code.
403	\retval B_OK Stopped sending notification messages to the \a target.
404	\retval B_BAD_VALUE \a target was invalid.
405	\retval B_ENTRY_NOT_FOUND Node not found.
406*/
407
408
409/*!
410	\fn status_t stop_watching(const BHandler *handler, const BLooper *looper)
411	\brief Unsubscribes \a handler or \a looper target from node and mount
412	       monitoring.
413
414	You may still receive notification messages after calling stop_watching()
415	because while node monitoring is asynchronous and all changes are atomic,
416	message sending is not atomic so there is a lag time from when you
417	stop monitoring and when the message is received in your message receiving
418	thread. You can check the timestamp of the message to determine if
419	it was sent after stop_watching() was called.
420
421	\param handler The target handler, may be \c NULL. If \a looper is not
422	       \c NULL then the looper's preferred handler is targeted.
423	\param looper The target looper, may be \c NULL. If \a handler is not
424	       \c NULL then the handler's looper is targeted.
425
426	\return A status code.
427	\retval B_OK Stopped sending notification messages to the target.
428	\retval B_BAD_VALUE Target from \a handler or \a looper was invalid.
429	\retval B_ENTRY_NOT_FOUND Node not found.
430*/
431