diff options
-rw-r--r-- | src/lib/syscall.zig | 8 | ||||
-rw-r--r-- | src/lib/sysexchange.zig | 6 | ||||
-rw-r--r-- | src/lib/vfs.zig | 25 |
3 files changed, 27 insertions, 12 deletions
diff --git a/src/lib/syscall.zig b/src/lib/syscall.zig index d2aaca3..21934b6 100644 --- a/src/lib/syscall.zig +++ b/src/lib/syscall.zig @@ -221,8 +221,12 @@ fn remove(trap_frame: *trap.Frame) void { .dir_hook => { const dir_hook = inode.resource.data.dir_hook; - const result = dir_hook.removeFn(basename.ptr, basename.len); - sysexchange.frameReturnResult(void, trap_frame, result); + if (dir_hook.removeFn) |removeFn| { + const result = removeFn(basename.ptr, basename.len); + sysexchange.frameReturnResult(void, trap_frame, result); + } else { + sysexchange.frameReturn(void, trap_frame, vfs.Error.RemoveNotSupported); + } }, else => sysexchange.frameReturn(void, trap_frame, vfs.Error.NotADirectory), } diff --git a/src/lib/sysexchange.zig b/src/lib/sysexchange.zig index 56a0fe7..d6405b9 100644 --- a/src/lib/sysexchange.zig +++ b/src/lib/sysexchange.zig @@ -68,6 +68,8 @@ pub const Status = enum(usize) { already_exists, is_a_hook, is_a_container, + provide_not_supported, + remove_not_supported, unknown = std.math.maxInt(usize), pub fn fromError(err: anyerror) Status { @@ -132,6 +134,8 @@ pub const Status = enum(usize) { error.AlreadyExists => .already_exists, error.IsAHook => .is_a_hook, error.IsAContainer => .is_a_container, + error.ProvideNotSupported => .provide_not_supported, + error.RemoveNotSupported => .remove_not_supported, else => .unknown, }; } @@ -201,6 +205,8 @@ pub const Status = enum(usize) { .already_exists => error.AlreadyExists, .is_a_hook => error.IsAHook, .is_a_container => error.IsAContainer, + .provide_not_supported => error.ProvideNotSupported, + .remove_not_supported => error.RemoveNotSupported, .unknown => error.Unknown, }; } diff --git a/src/lib/vfs.zig b/src/lib/vfs.zig index 16a793c..bf1ac85 100644 --- a/src/lib/vfs.zig +++ b/src/lib/vfs.zig @@ -48,6 +48,8 @@ pub const Error = error{ AlreadyExists, IsAHook, IsAContainer, + ProvideNotSupported, + RemoveNotSupported, }; // A stream is a resource that provides a shared data stream with a driver. @@ -80,15 +82,15 @@ pub const Hook = extern struct { // A directory hook is a resource that provides other resources via driver callbacks. pub const DirHook = extern struct { - provideFn: ProvideFn, + provideFn: ?ProvideFn, findFn: FindFn, listFn: ListFn, - removeFn: RemoveFn, + removeFn: ?RemoveFn, - pub const ProvideFn = *allowzero const fn (name_ptr: [*]const u8, name_len: usize, inode: Inode) callconv(.C) sysexchange.Result(void); + pub const ProvideFn = *const fn (name_ptr: [*]const u8, name_len: usize, inode: Inode) callconv(.C) sysexchange.Result(void); pub const FindFn = *allowzero const fn (name_ptr: [*]const u8, name_len: usize) callconv(.C) ?*Inode; pub const ListFn = *allowzero const fn (inodes_ptr: [*]Inode, inodes_len: usize) callconv(.C) sysexchange.Result(usize); - pub const RemoveFn = *allowzero const fn (name_ptr: [*]const u8, name_len: usize) callconv(.C) sysexchange.Result(void); + pub const RemoveFn = *const fn (name_ptr: [*]const u8, name_len: usize) callconv(.C) sysexchange.Result(void); }; pub const FileContext = extern struct { @@ -414,12 +416,15 @@ pub fn provideResource(path: []const u8, resource: Resource, pid: u16, options: // fixme: Check for duplicate resources with the same path - break :blk dir_hook.provideFn(basename.ptr, basename.len, .{ - .resource = resource, - .pid = pid, - .options = options, - .flags = .{}, - }).toErrorUnion(); + break :blk if (dir_hook.provideFn) |provideFn| + provideFn(basename.ptr, basename.len, .{ + .resource = resource, + .pid = pid, + .options = options, + .flags = .{}, + }).toErrorUnion() + else + Error.ProvideNotSupported; }, else => Error.NotADirectory, }; |