Skip to content

Commit 6ec299d

Browse files
committed
node_monitor: Enable mount watching code
1 parent b3a2561 commit 6ec299d

File tree

3 files changed

+94
-2
lines changed

3 files changed

+94
-2
lines changed

src/system/libroot2/fs/disk_device.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2026, Dario Casalinuovo. All rights reserved.
2+
* Copyright 2019-2026, Dario Casalinuovo. All rights reserved.
33
* Distributed under the terms of the LGPL License.
44
*/
55

src/system/libroot2/fs/disk_monitor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019-2026, Dario Casalinuovo. All rights reserved.
2+
* Copyright 2026, Dario Casalinuovo. All rights reserved.
33
* Distributed under the terms of the LGPL License.
44
*/
55

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*
2+
* Copyright 2025-2026, Dario Casalinuovo. All rights reserved.
3+
* Distributed under the terms of the LGPL License.
4+
*/
5+
6+
#include <NodeMonitor.h>
7+
#include <OS.h>
8+
9+
#include <pthread.h>
10+
11+
#include "disk_monitor.h"
12+
#include "../kernel/nexus/nexus/nexus.h"
13+
#include "../kernel/nexus/nexus/node_monitor.h"
14+
#include "Team.h"
15+
16+
17+
extern "C" {
18+
19+
20+
status_t
21+
_kern_start_watching(dev_t device, ino_t node, uint32 flags,
22+
port_id port, uint32 token)
23+
{
24+
printf("_kern_start_watching\n");
25+
26+
if (flags & B_WATCH_MOUNT) {
27+
status_t err = BKernelPrivate::start_mount_watching(port, token);
28+
if (err != B_OK)
29+
return err;
30+
31+
if ((flags & ~B_WATCH_MOUNT) == 0)
32+
return B_OK;
33+
34+
flags &= ~B_WATCH_MOUNT;
35+
}
36+
37+
int nodeMonitor = BKernelPrivate::Team::GetNodeMonitorDescriptor();
38+
if (nodeMonitor < 0)
39+
return B_ENTRY_NOT_FOUND;
40+
41+
int nodeFD = -1;
42+
if (device == get_vref_dev())
43+
nodeFD = open_vref(node);
44+
45+
struct nexus_watch_fd req = {
46+
.fd = nodeFD,
47+
.flags = flags,
48+
.port = port,
49+
.token = token
50+
};
51+
52+
status_t ret = nexus_io(nodeMonitor, NEXUS_START_WATCHING, &req);
53+
close(nodeFD);
54+
return ret;
55+
}
56+
57+
58+
status_t
59+
_kern_stop_watching(dev_t device, ino_t node, port_id port, uint32 token)
60+
{
61+
BKernelPrivate::stop_mount_watching(port, token);
62+
63+
int nodeMonitor = BKernelPrivate::Team::GetNodeMonitorDescriptor();
64+
if (nodeMonitor < 0)
65+
return B_ENTRY_NOT_FOUND;
66+
67+
struct nexus_unwatch_fd req = {
68+
.device = (uint64_t)device,
69+
.node = (uint64_t)node,
70+
.port = port,
71+
.token = token
72+
};
73+
74+
return nexus_io(nodeMonitor, NEXUS_STOP_WATCHING, &req);
75+
}
76+
77+
78+
status_t
79+
_kern_stop_notifying(port_id port, uint32 token)
80+
{
81+
BKernelPrivate::stop_all_watching_for_target(port, token);
82+
83+
int nodeMonitor = BKernelPrivate::Team::GetNodeMonitorDescriptor();
84+
if (nodeMonitor < 0)
85+
return B_ENTRY_NOT_FOUND;
86+
87+
struct nexus_stop_notifying req = { .port = port, .token = token };
88+
return nexus_io(nodeMonitor, NEXUS_STOP_NOTIFYING, &req);
89+
}
90+
91+
92+
} // extern "C"

0 commit comments

Comments
 (0)