diff options
-rw-r--r-- | src/lib/vfs.zig | 18 |
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); } |