aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/sysexchange.zig3
-rw-r--r--src/lib/vfs.zig15
2 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/sysexchange.zig b/src/lib/sysexchange.zig
index c3d7fa4..d509e7a 100644
--- a/src/lib/sysexchange.zig
+++ b/src/lib/sysexchange.zig
@@ -65,6 +65,7 @@ pub const Status = enum(usize) {
in_use,
detached,
orphaned,
+ already_exists,
unknown = std.math.maxInt(usize),
pub fn fromError(err: anyerror) Status {
@@ -126,6 +127,7 @@ pub const Status = enum(usize) {
error.InUse => .in_use,
error.Detached => .detached,
error.Orphaned => .orphaned,
+ error.AlreadyExists => .already_exists,
else => .unknown,
};
}
@@ -192,6 +194,7 @@ pub const Status = enum(usize) {
.in_use => error.InUse,
.detached => error.Detached,
.orphaned => error.Orphaned,
+ .already_exists => error.AlreadyExists,
.unknown => error.Unknown,
};
}
diff --git a/src/lib/vfs.zig b/src/lib/vfs.zig
index c8cc552..71dda98 100644
--- a/src/lib/vfs.zig
+++ b/src/lib/vfs.zig
@@ -42,6 +42,7 @@ pub const Error = error{
InUse,
Detached,
Orphaned,
+ AlreadyExists,
};
// A stream is a resource that provides a shared data stream with a driver.
@@ -307,6 +308,18 @@ pub fn provideResource(path: []const u8, resource: Resource, pid: u16, options:
.dir => blk: {
const dir = inode.resource.data.dir;
+ if (dir.find(basename)) |node| {
+ if (node.data.inode.flags.detached and node.data.inode.options.reclaimable) {
+ node.data.inode = .{
+ .resource = resource,
+ .pid = pid,
+ .options = options,
+ .flags = .{},
+ };
+ break :blk;
+ } else break :blk Error.AlreadyExists;
+ }
+
break :blk dir.provideResource(.{
.name = basename,
.inode = .{
@@ -320,6 +333,8 @@ pub fn provideResource(path: []const u8, resource: Resource, pid: u16, options:
.dir_hook => blk: {
const dir_hook = inode.resource.data.dir_hook;
+ // fixme: Check for duplicate resources with the same path
+
break :blk dir_hook.provideFn(basename.ptr, basename.len, .{
.resource = resource,
.pid = pid,