Files
zig-squashfs/src/inode/sym.zig
T
Caleb Gardner bbf3539dcf Messing around with thing.
Things not working.
2025-05-16 15:16:46 -05:00

49 lines
1.5 KiB
Zig

const std = @import("std");
const io = std.io;
pub const SymInode = struct {
hard_links: u32,
size: u32,
target: []const u8,
pub fn init(alloc: std.mem.Allocator, rdr: io.AnyReader) !SymInode {
var fixed_buf = [_]u8{0} ** 8;
_ = try rdr.readAll(@ptrCast(&fixed_buf));
const size = std.mem.bytesToValue(u32, fixed_buf[4..]);
const target = try alloc.alloc(u8, size);
_ = try rdr.readAll(target);
return .{
.hard_links = std.mem.bytesToValue(u32, fixed_buf[0..4]),
.size = size,
.target = target,
};
}
pub fn deinit(self: SymInode, alloc: std.mem.Allocator) void {
alloc.free(self.target);
}
};
pub const ExtSymInode = struct {
hard_links: u32,
size: u32,
target: []const u8,
xattr_idx: u32,
pub fn init(alloc: std.mem.Allocator, rdr: io.AnyReader) !ExtSymInode {
var fixed_buf = [_]u8{0} ** 8;
_ = try rdr.readAll(&fixed_buf);
const size = std.mem.bytesToValue(u32, fixed_buf[4..]);
const target = try alloc.alloc(u8, size);
_ = try rdr.readAll(target);
return .{
.hard_links = std.mem.bytesToValue(u32, fixed_buf[0..4]),
.size = size,
.target = target,
.xattr_idx = try rdr.readInt(u32, std.builtin.Endian.little),
};
}
pub fn deinit(self: ExtSymInode, alloc: std.mem.Allocator) void {
alloc.free(self.target);
}
};