2 * Copyright 2003-2014 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
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
12 * headers/os/storage/NodeMonitor.h hrev47403
13 * src/kits/storage/NodeMonitor.cpp hrev47403
21 \brief Provides functions and constants for monitoring changes to a node.
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
34 //// Flags for the watch_node() call.
39 \brief Unsubscribe from watching a node.
41 Flag for watch_node().
43 \attention \c B_STOP_WATCHING does not apply to volume watching, you must
44 call stop_watching() instead.
52 \brief Subscribe to watching for change to the name of a node.
54 Flag for watch_volume() and watch_node().
62 \brief Subscribe to watching for changes to the stat information of a node.
64 Flag for watch_volume() and watch_node().
72 \brief Subscribe to watching for changes to the attributes of a node.
74 Flag for watch_volume() and watch_node().
81 \var B_WATCH_DIRECTORY
82 \brief Subscribe to watching for changes to the contents of a directory.
84 Flag for watch_node().
92 \brief Flag for watch_node().
94 Subscribe to watching for changes to all information of a node except
103 \brief Subscribe to watching for when a volume is mounted or unmounted.
105 You may prefer to use BVolumeRoster for volume watching instead.
107 Flag for watch_node().
114 \var B_WATCH_INTERIM_STAT
115 \brief To avoid a flood of messages for small and frequent write operations
116 on an open file the file system can limit the number of
117 notifications and mark them with the \c B_WATCH_INTERIM_STAT flag.
119 \internal Implementation detail, not in Be Book.
125 // The "opcode" field of the B_NODE_MONITOR notification message you get.
130 \brief \c B_NODE_MONITOR notification message "opcode" is set when entry is
139 \brief \c B_NODE_MONITOR notification message "opcode" is set when entry is
148 \brief \c B_NODE_MONITOR notification message "opcode" is set when entry is
157 \brief \c B_NODE_MONITOR notification message "opcode" set when stat info
160 More information can be found in the "fields" field.
168 \brief \c B_NODE_MONITOR notification message "opcode" set when attribute
171 More information can be found in the "cause" field.
178 \def B_DEVICE_MOUNTED
179 \brief \c B_NODE_MONITOR notification message "opcode" set when device is
187 \def B_DEVICE_UNMOUNTED
188 \brief \c B_NODE_MONITOR notification message "opcode" set when device is
195 // More specific info in the "cause" field of B_ATTR_CHANGED notification
201 \brief \c B_ATTR_CHANGED notification message "cause" set when attribute is
210 \brief \c B_ATTR_CHANGED notification message "cause" set when attribute is
217 // More specific info in the "fields" field of B_STAT_CHANGED notification
218 // messages, specifying what parts of the stat data have actually been
224 \brief Set when stat mode changes.
226 \c B_STAT_CHANGED notification messages "fields" flag.
234 \brief Set when UID changes.
236 \c B_STAT_CHANGED notification messages "fields" flag.
244 \brief Set when GID changes.
246 \c B_STAT_CHANGED notification messages "fields" flag.
254 \brief Set when stat size changes.
256 \c B_STAT_CHANGED notification messages "fields" flag.
263 \var B_STAT_ACCESS_TIME
264 \brief Set when access time changes.
266 \c B_STAT_CHANGED notification messages "fields" flag.
273 \var B_STAT_MODIFICATION_TIME
274 \brief Set when modification time changes.
276 \c B_STAT_CHANGED notification messages "fields" flag.
283 \var B_STAT_CREATION_TIME
284 \brief Set when creation time changes.
286 \c B_STAT_CHANGED notification messages "fields" flag.
293 \var B_STAT_CHANGE_TIME
294 \brief Set when access, modification or creation time changes.
296 \c B_STAT_CHANGED notification messages "fields" flag.
303 \var B_STAT_INTERIM_UPDATE
304 \brief Set when file is written to.
306 \internal Implementation detail, not in Be Book.
308 \c B_STAT_CHANGED notification messages "fields" flag.
315 \fn status_t watch_volume(dev_t volume, uint32 flags, BMessenger target)
316 \brief Subscribes \a target to watch node changes on \a volume.
318 Depending of \a flags the action performed by this function varies:
319 - \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
320 or <tt>B_WATCH_ATTR</tt>: The target is subscribed to watching the specified
321 aspects of any node on the volume.
323 \a flags may include:
328 \c B_WATCH_VOLUME flag is assumed.
330 \param volume dev_t referring to the volume to be watched.
331 \param flags Flags indicating the actions to be performed.
332 \param target Messenger referring to the target. Must be valid.
334 \return A status code.
335 \retval B_OK Everything went fine.
336 \retval B_BAD_VALUE \a flags did not include one of \c B_WATCH_NAME,
337 \c B_WATCH_STAT, or \c B_WATCH_ATTR.
344 \fn status_t watch_volume(dev_t volume, uint32 flags,
345 const BHandler* handler, const BLooper* looper)
346 \brief Subscribes \a handler or \a looper to watch node changes on
349 Depending of \a flags the action performed by this function varies:
350 - \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
351 or <tt>B_WATCH_ATTR</tt>: The target is subscribed to watching the specified
352 aspects of any node on the volume.
354 \a flags may include:
359 \c B_WATCH_VOLUME flag is assumed.
361 \param volume dev_t referring to the volume to be watched.
362 \param flags Flags indicating the actions to be performed.
363 \param handler The target \a handler. May be \c NULL, if \a looper is not
364 \c NULL. Then the preferred handler of the looper is targeted.
365 \param looper The target \a looper. May be \c NULL, if \a handler is not
366 \c NULL. Then the handler's looper is the target looper.
368 \return A status code.
369 \retval B_OK Everything went fine.
370 \retval B_BAD_VALUE \a flags did not include one of \c B_WATCH_NAME,
371 \c B_WATCH_STAT, or \c B_WATCH_ATTR.
378 \fn status_t watch_node(const node_ref* node, uint32 flags,
380 \brief Subscribes or unsubscribes \a target to node and/or mount watching.
382 Depending of \a flags the action performed by this function varies:
383 - \a flags is 0: The target is unsubscribed from watching the node.
384 \a node must not be \c NULL in this case.
385 - \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
387 - \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
388 \c B_WATCH_ATTR, or <tt>B_WATCH_DIRECTORY</tt>: The target is subscribed to
389 watching the specified aspects of the node. \a node must not be \c NULL
392 \a flags may include:
395 or one or more of the following:
399 - \c B_WATCH_DIRECTORY
403 Note that the latter two cases are not mutual exclusive, i.e. mount and
404 node watching can be requested with a single call.
406 \param node node_ref referring to the node to be watched. May be \c NULL,
407 if only mount watching is requested.
408 \param flags Flags indicating the actions to be performed.
409 \param target BMessenger object referring to the \a target.
411 \return \c B_OK if everything went fine, an error code otherwise.
418 \fn status_t watch_node(const node_ref* node, uint32 flags,
419 const BHandler* handler, const BLooper* looper)
420 \brief Subscribes or unsubscribes \a handler or \a looper to node and/or
423 Depending of \a flags the action performed by this function varies:
424 - \a flags is 0: The target is unsubscribed from watching the node.
425 \a node must not be \c NULL in this case.
426 - \a flags contains \c B_WATCH_MOUNT: The target is subscribed to mount
428 - \a flags contains at least one of \c B_WATCH_NAME, \c B_WATCH_STAT,
429 \c B_WATCH_ATTR, or <tt>B_WATCH_DIRECTORY</tt>: The target is subscribed to
430 watching the specified aspects of the node. \a node must not be \c NULL
433 \a flags may include:
436 or one or more of the following:
440 - \c B_WATCH_DIRECTORY
444 Note that the latter two cases are not mutual exclusive, i.e. mount and
445 node watching can be requested with a single call.
447 \param node node_ref referring to the node to be watched. May be \c NULL,
448 if only mount watching is requested.
449 \param flags Flags indicating the actions to be performed.
450 \param handler The target handler. May be \c NULL, if \a looper is not
451 \c NULL. Then the preferred handler of the looper is targeted.
452 \param looper The target looper. May be \c NULL, if \a handler is not
453 \c NULL. Then the handler's looper is the target looper.
455 \return \c B_OK if everything went fine, an error code otherwise.
462 \fn status_t stop_watching(BMessenger target)
463 \brief Unsubscribes \a target from node and mount monitoring.
465 You may still receive notification messages after calling stop_watching()
466 because while node monitoring is asynchronous and all changes are atomic,
467 message sending is not atomic so there is a lag time from when you
468 stop monitoring and when the message is received in your message receiving
469 thread. You can check the timestamp of the message to determine if
470 it was sent after stop_watching() was called.
472 \param target BMessenger object referring to the \a target.
474 \return A status code.
475 \retval B_OK Stopped sending notification messages to the \a target.
476 \retval B_BAD_VALUE \a target was invalid.
477 \retval B_ENTRY_NOT_FOUND Node not found.
484 \fn status_t stop_watching(const BHandler* handler, const BLooper* looper)
485 \brief Unsubscribes \a handler or \a looper target from node and mount
488 You may still receive notification messages after calling stop_watching()
489 because while node monitoring is asynchronous and all changes are atomic,
490 message sending is not atomic so there is a lag time from when you
491 stop monitoring and when the message is received in your message receiving
492 thread. You can check the timestamp of the message to determine if
493 it was sent after stop_watching() was called.
495 \param handler The target handler, may be \c NULL. If \a looper is not
496 \c NULL then the looper's preferred handler is targeted.
497 \param looper The target looper, may be \c NULL. If \a handler is not
498 \c NULL then the handler's looper is targeted.
500 \return A status code.
501 \retval B_OK Stopped sending notification messages to the target.
502 \retval B_BAD_VALUE Target from \a handler or \a looper was invalid.
503 \retval B_ENTRY_NOT_FOUND Node not found.