aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-06-30 13:39:18 +0200
committerHimbeer <himbeer@disroot.org>2024-06-30 13:39:18 +0200
commit741349424774d6128f4da0f9bff85203200415c3 (patch)
treefa603aa7b7c4983f1a8f746d5f2f77b207f7482c /src
parent0141799541d286e205aa5aa1ae0552aeca6c672a (diff)
vfs: Add initial VFS provider
Diffstat (limited to 'src')
-rw-r--r--src/lib/vfs.zig59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/lib/vfs.zig b/src/lib/vfs.zig
new file mode 100644
index 0000000..8cebb1b
--- /dev/null
+++ b/src/lib/vfs.zig
@@ -0,0 +1,59 @@
+// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
+//
+// SPDX-License-Identifier: AGPL-3.0-or-later
+
+const std = @import("std");
+
+pub var default = undefined;
+
+pub const Error = error{
+ NotFound,
+};
+
+// A stream is a resource that provides a shared data stream with a driver.
+pub const StreamMeta = struct {};
+
+// A file is a resource that creates a unique data stream with a driver.
+pub const FileMeta = struct {};
+
+// A hook is a resource that invokes raw driver callbacks when interacted with.
+pub const HookMeta = struct {};
+
+pub const Meta = union(enum) {
+ stream: StreamMeta,
+ file: FileMeta,
+ hook: HookMeta,
+};
+
+pub const Inode = struct {
+ name: []u8,
+ meta: Meta,
+};
+
+pub const Tree = struct {
+ allocator: std.mem.Allocator,
+ nodes: std.DoublyLinkedList(Inode),
+
+ pub fn init(allocator: std.mem.Allocator) Tree {
+ return .{
+ .allocator = allocator,
+ .nodes = std.DoublyLinkedList(Inode){},
+ };
+ }
+
+ pub fn provideResource(self: *Tree, inode: Inode) !void {
+ var node = try self.allocator.create(std.DoublyLinkedList(Inode).Node);
+ node.data = inode;
+ self.nodes.append(node);
+ }
+
+ pub fn remove(self: *Tree, name: []const u8) !void {
+ if (self.findByNameExact(name)) |node| {
+ self.nodes.remove(node);
+ } else return NotFound;
+ }
+};
+
+pub fn init(allocator: std.mem.Allocator) void {
+ default = Tree.init(allocator);
+}