|
| 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