aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHimbeer <himbeer@disroot.org>2024-07-01 22:06:51 +0200
committerHimbeer <himbeer@disroot.org>2024-07-01 22:06:51 +0200
commit22ed2908af88d4f758788aefbb2ccf3928156906 (patch)
tree947cfe7ad4414aa80ed6310bd4c6d04776c3eabd
parenteef85056c996cf86e88c2589dc95429d59362c7b (diff)
vfs: Add resource descriptors
-rw-r--r--src/lib/vfs.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/lib/vfs.zig b/src/lib/vfs.zig
index 798813f..0eb57a6 100644
--- a/src/lib/vfs.zig
+++ b/src/lib/vfs.zig
@@ -15,6 +15,7 @@ pub const Error = error{
RelativePathNotAllowed,
NotADirectory,
NoAbsoluteContainingDirectory,
+ TooManyReferences,
};
// A stream is a resource that provides a shared data stream with a driver.
@@ -73,6 +74,7 @@ pub const Resource = union(enum) {
pub const Inode = struct {
name: []const u8,
resource: Resource,
+ refs: usize = 0,
};
pub const Node = std.DoublyLinkedList(Inode).Node;
@@ -112,6 +114,22 @@ pub const Tree = struct {
}
};
+pub const ResourceDescriptor = struct {
+ inode: *Inode,
+ pos: usize = 0,
+
+ pub fn init(inode: *Inode) !ResourceDescriptor {
+ inode.refs = std.math.add(usize, inode.refs, 1) catch return Error.TooManyReferences;
+ return .{
+ .inode = inode,
+ };
+ }
+
+ pub fn deinit(self: ResourceDescriptor) void {
+ self.inode.refs -|= 1;
+ }
+};
+
pub fn init(allocator: mem.Allocator) void {
root = Tree.init(allocator);
}