Further work on inode decoding
This commit is contained in:
+8
-8
@@ -20,17 +20,15 @@ pub const DirIndex = struct {
|
||||
name: []const u8,
|
||||
};
|
||||
|
||||
fn readDirIndex(rdr: io.AnyReader) !DirIndex {
|
||||
fn readDirIndex(rdr: io.AnyReader, alloc: std.heap.Allocator) !DirIndex {
|
||||
const out = DirIndex{
|
||||
.dir_header_offset = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.dir_table_offset = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.name_size = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.name = undefined,
|
||||
};
|
||||
const buf = try std.heap.page_allocator.alloc(u8, out.name_size);
|
||||
defer std.heap.page_allocator.free(buf);
|
||||
try rdr.read(buf);
|
||||
out.name = buf[0..];
|
||||
out.name = try alloc.alloc(u8, out.name_size);
|
||||
try rdr.read(out.name);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -45,7 +43,7 @@ pub const ExtDirInode = struct {
|
||||
indexes: []const DirIndex,
|
||||
};
|
||||
|
||||
pub fn readExtDirInode(rdr: io.AnyReader) !ExtDirInode {
|
||||
pub fn readExtDirInode(rdr: io.AnyReader, alloc: std.heap.Allocator) !ExtDirInode {
|
||||
const out = ExtDirInode{
|
||||
.hard_links = rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.dir_table_size = rdr.readInt(u32, std.builtin.Endian.little),
|
||||
@@ -56,10 +54,12 @@ pub fn readExtDirInode(rdr: io.AnyReader) !ExtDirInode {
|
||||
.xattr_index = rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.indexes = undefined,
|
||||
};
|
||||
out.indexes = []const DirIndex{undefined} ** out.dir_index_count;
|
||||
const tmp = std.ArrayList(DirIndex).init(alloc);
|
||||
try tmp.resize(out.dir_index_count);
|
||||
const i: u16 = 0;
|
||||
while (i < out.dir_index_count) : (i += 1) {
|
||||
out.indexes[i] = try readDirIndex(rdr);
|
||||
tmp.items[i] = try readDirIndex(rdr, alloc);
|
||||
}
|
||||
out.indexes = tmp.items;
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ pub const FileInode = struct {
|
||||
block_sizes: []const u32,
|
||||
};
|
||||
|
||||
pub fn readFileInode(rdr: std.io.AnyReader, block_size: u32) !FileInode {
|
||||
pub fn readFileInode(rdr: std.io.AnyReader, block_size: u32, alloc: std.heap.Allocator) !FileInode {
|
||||
const out = FileInode{
|
||||
.start = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.frag_index = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
@@ -17,9 +17,11 @@ pub fn readFileInode(rdr: std.io.AnyReader, block_size: u32) !FileInode {
|
||||
.block_sizes = undefined,
|
||||
};
|
||||
var block_num = out.size / block_size;
|
||||
if (out.frag_index != 0xFFFFFFFF and out.size % block_size != 0) {
|
||||
if (out.frag_index != 0xFFFFFFFF) {
|
||||
block_num += 1;
|
||||
}
|
||||
out.block_sizes = try alloc.alloc(u32, block_num);
|
||||
try rdr.read(std.mem.asBytes(&out.block_sizes));
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -34,7 +36,7 @@ pub const ExtFileInode = struct {
|
||||
block_sizes: []const u32,
|
||||
};
|
||||
|
||||
pub fn readExtFileInode(rdr: std.io.AnyReader, block_size: u32) !ExtFileInode {
|
||||
pub fn readExtFileInode(rdr: std.io.AnyReader, block_size: u32, alloc: std.heap.Allocator) !ExtFileInode {
|
||||
const out = ExtFileInode{
|
||||
.start = try rdr.readInt(u64, std.builtin.Endian.little),
|
||||
.size = try rdr.readInt(u64, std.builtin.Endian.little),
|
||||
@@ -49,6 +51,7 @@ pub fn readExtFileInode(rdr: std.io.AnyReader, block_size: u32) !ExtFileInode {
|
||||
if (out.frag_index != 0xFFFFFFFF and out.size % block_size != 0) {
|
||||
block_num += 1;
|
||||
}
|
||||
//TODO: stuff
|
||||
out.block_sizes = try alloc.alloc(u32, block_num);
|
||||
try rdr.read(std.mem.asBytes(&out.block_sizes));
|
||||
return out;
|
||||
}
|
||||
|
||||
+6
-4
@@ -7,13 +7,14 @@ pub const SymlinkInode = struct {
|
||||
path: []const u8,
|
||||
};
|
||||
|
||||
pub fn readSymlinkInode(rdr: io.AnyReader) !SymlinkInode {
|
||||
pub fn readSymlinkInode(rdr: io.AnyReader, alloc: std.heap.Allocator) !SymlinkInode {
|
||||
const out = SymlinkInode{
|
||||
.hard_links = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.target_size = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.path = undefined,
|
||||
};
|
||||
out.path = (try rdr.readBoundedBytes(out.target_size + 1)).constSlice();
|
||||
out.path = try alloc.alloc(u8, out.target_size + 1);
|
||||
try rdr.read(out.path);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -24,14 +25,15 @@ pub const ExtSymlinkInode = struct {
|
||||
xattr_index: u32,
|
||||
};
|
||||
|
||||
pub fn readExtSymlinkInode(rdr: io.AnyReader) !SymlinkInode {
|
||||
pub fn readExtSymlinkInode(rdr: io.AnyReader, alloc: std.heap.Allocator) !SymlinkInode {
|
||||
const out = ExtSymlinkInode{
|
||||
.hard_links = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.target_size = try rdr.readInt(u32, std.builtin.Endian.little),
|
||||
.path = undefined,
|
||||
.xattr_index = undefined,
|
||||
};
|
||||
out.path = (try rdr.readBoundedBytes(out.target_size + 1)).constSlice();
|
||||
out.path = try alloc.alloc(u8, out.target_size + 1);
|
||||
try rdr.read(out.path);
|
||||
out.xattr_index = try rdr.readInt(u32, std.builtin.Endian.little);
|
||||
return out;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user