vfs: check userland buffers before reading them.
[haiku.git] / src / kits / storage / NodeMonitor.cpp
blob24d7657d3d44dba6dc3cbf8fa32522096c64acf4
1 /*
2 * Copyright 2001-2010 Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Ingo Weinhold, bonefish@@users.sf.net
7 * Axel Dörfler, axeld@pinc-software.de
8 * Clemens Zeidler <haiku@clemens-zeidler.de>
9 */
12 #include <Messenger.h>
13 #include <NodeMonitor.h>
15 #include <MessengerPrivate.h>
17 #include <syscalls.h>
19 #include "node_monitor_private.h"
22 // TODO: Tests!
25 // Subscribes a target to watch node changes on a volume.
26 status_t
27 watch_volume(dev_t volume, uint32 flags, BMessenger target)
29 if ((flags & (B_WATCH_NAME | B_WATCH_STAT | B_WATCH_ATTR)) == 0)
30 return B_BAD_VALUE;
32 flags |= B_WATCH_VOLUME;
34 BMessenger::Private messengerPrivate(target);
35 port_id port = messengerPrivate.Port();
36 int32 token = messengerPrivate.Token();
37 return _kern_start_watching(volume, (ino_t)-1, flags, port, token);
41 status_t
42 watch_volume(dev_t volume, uint32 flags, const BHandler* handler,
43 const BLooper* looper)
45 return watch_volume(volume, flags, BMessenger(handler, looper));
49 // Subscribes or unsubscribes a target to node and/or mount watching.
50 status_t
51 watch_node(const node_ref* node, uint32 flags, BMessenger target)
53 if (!target.IsValid())
54 return B_BAD_VALUE;
56 BMessenger::Private messengerPrivate(target);
57 port_id port = messengerPrivate.Port();
58 int32 token = messengerPrivate.Token();
60 if (flags == B_STOP_WATCHING) {
61 // unsubscribe from node node watching
62 if (node == NULL)
63 return B_BAD_VALUE;
65 return _kern_stop_watching(node->device, node->node, port, token);
68 // subscribe to...
69 // mount watching
70 if (flags & B_WATCH_MOUNT) {
71 status_t status = _kern_start_watching((dev_t)-1, (ino_t)-1,
72 B_WATCH_MOUNT, port, token);
73 if (status < B_OK)
74 return status;
76 flags &= ~B_WATCH_MOUNT;
79 // node watching
80 if (flags != 0) {
81 if (node == NULL)
82 return B_BAD_VALUE;
84 return _kern_start_watching(node->device, node->node, flags, port,
85 token);
88 return B_OK;
92 // Subscribes or unsubscribes a handler or looper to node and/or mount
93 // watching.
94 status_t
95 watch_node(const node_ref* node, uint32 flags, const BHandler* handler,
96 const BLooper* looper)
98 return watch_node(node, flags, BMessenger(handler, looper));
102 // Unsubscribes a target from node and mount monitoring.
103 status_t
104 stop_watching(BMessenger target)
106 if (!target.IsValid())
107 return B_BAD_VALUE;
109 BMessenger::Private messengerPrivate(target);
110 port_id port = messengerPrivate.Port();
111 int32 token = messengerPrivate.Token();
113 return _kern_stop_notifying(port, token);
117 // Unsubscribes a target from node and mount monitoring.
118 status_t
119 stop_watching(const BHandler* handler, const BLooper* looper)
121 return stop_watching(BMessenger(handler, looper));