From ad05e5dff1eb840bfaace12cc4ca75a501dfa750 Mon Sep 17 00:00:00 2001 From: "Caleb J. Gardner" Date: Sun, 10 May 2026 14:34:05 -0500 Subject: [PATCH] Added xattr function to inode --- src/inode.zig | 20 ++++++++++++++++++-- src/xattr_table.zig | 2 ++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/inode.zig b/src/inode.zig index 61a4c11..6a22167 100644 --- a/src/inode.zig +++ b/src/inode.zig @@ -17,6 +17,7 @@ const Decompressor = @import("util/decompressor.zig"); const MetadataReader = @import("util/metadata.zig"); const OffsetFile = @import("util/offset_file.zig"); const SharedCache = @import("util/shared_cache.zig"); +const XattrTable = @import("xattr_table.zig"); const Inode = @This(); @@ -121,8 +122,21 @@ pub fn gid(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, decom pub fn uid(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, decomp: *const Decompressor, id_table_start: u64) !u16 { return LookupTable.lookupValue(u16, alloc, io, decomp, fil, id_table_start, self.hdr.uid_idx); } -// Get an extended inode's xattr values. -pub fn xattrValues(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, decomp: *const Decompressor, xattr_table_start: u64) !Xattr {} +// Get an inode's xattr values. If the inode does not have xattr values (including if the inode is not an extended type), an empty slice is returned. +pub fn xattrValues(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, decomp: *const Decompressor, xattr_table_start: u64) ![]XattrTable.XattrOwned { + const idx = switch (self.data) { + .ext_dir => |e| e.xattr_idx, + .ext_file => |e| e.xattr_idx, + .ext_symlink => |e| e.xattr_idx, + .ext_block_dev => |e| e.xattr_idx, + .ext_char_dev => |e| e.xattr_idx, + .ext_fifo => |e| e.xattr_idx, + .ext_socket => |e| e.xattr_idx, + else => return &[0]XattrTable.XattrOwned{}, + }; + if (idx == 0xFFFFFFFF) return &[0]XattrTable.XattrOwned{}; + return XattrTable.statelessLookup(alloc, io, decomp, fil, xattr_table_start, idx); +} // Types @@ -188,3 +202,5 @@ pub fn extract(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, s pub fn extractDir(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, super: Archive.Superblock, path: []const u8, options: ExtractionOptions) !void {} pub fn extractRegFile(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, super: Archive.Superblock, path: []const u8, options: ExtractionOptions) !void {} pub fn extractSymlink(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, super: Archive.Superblock, path: []const u8, options: ExtractionOptions) !void {} +pub fn extractDevice(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, super: Archive.Superblock, path: []const u8, options: ExtractionOptions) !void {} +pub fn extractIPC(self: Inode, alloc: std.mem.Allocator, io: Io, fil: OffsetFile, super: Archive.Superblock, path: []const u8, options: ExtractionOptions) !void {} diff --git a/src/xattr_table.zig b/src/xattr_table.zig index 0164726..f72f4d7 100644 --- a/src/xattr_table.zig +++ b/src/xattr_table.zig @@ -111,6 +111,7 @@ pub fn get(self: *XattrCachedTable, alloc: std.mem.Allocator, io: Io, idx: u32) try meta.interface.readSliceEndian(val_size, @ptrCast(&val_size), .little); const val = try self.alloc.alloc(u8, val_size); + errdefer alloc.free(val); try meta.interface.readSliceEndian(u8, val, .little); try self.value_cache.put(val_ref, val); @@ -271,6 +272,7 @@ pub fn statelessLookup(alloc: std.mem.Allocator, io: Io, decomp: *const Decompre try meta.interface.readSliceEndian(val_size, @ptrCast(&val_size), .little); const val = try alloc.alloc(u8, val_size); + errdefer alloc.free(val); try meta.interface.readSliceEndian(u8, val, .little); out[i] = .{