From 252f7fc253236053ec0f4d39f7c5e45c1d059b5a Mon Sep 17 00:00:00 2001 From: Yorhel Date: Thu, 8 Aug 2024 11:37:53 +0200 Subject: [PATCH] Use u64 for item counts in binary export They're still clamped to a u32 upon reading, but at least the file will have correct counts and can be read even when it exceeds 4.2 billion items. --- src/bin_export.zig | 4 ++-- src/bin_reader.zig | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin_export.zig b/src/bin_export.zig index 4130c83..b1d8f2b 100644 --- a/src/bin_export.zig +++ b/src/bin_export.zig @@ -39,7 +39,7 @@ pub const ItemKey = enum(u5) { cumdsize = 8, // u64 shrasize = 9, // u64 shrdsize = 10, // u64 - items = 11, // u32 + items = 11, // u64 sub = 12, // itemref only if dir is not empty // Only for .link ino = 13, // u64 @@ -217,7 +217,7 @@ pub const Dir = struct { lock: std.Thread.Mutex = .{}, last_sub: u64 = 0, stat: sink.Stat, - items: u32 = 0, + items: u64 = 0, size: u64 = 0, blocks: u64 = 0, err: bool = false, diff --git a/src/bin_reader.zig b/src/bin_reader.zig index b4637e3..4a06276 100644 --- a/src/bin_reader.zig +++ b/src/bin_reader.zig @@ -467,7 +467,7 @@ pub fn get(ref: u64, alloc: std.mem.Allocator) *model.Entry { .cumdsize => entry.pack.blocks = @intCast(kv.val.int(u64)/512), .shrasize => { if (entry.dir()) |d| d.shared_size = kv.val.int(u64); }, .shrdsize => { if (entry.dir()) |d| d.shared_blocks = kv.val.int(u64)/512; }, - .items => { if (entry.dir()) |d| d.items = kv.val.int(u32); }, + .items => { if (entry.dir()) |d| d.items = util.castClamp(u32, kv.val.int(u64)); }, .sub => { if (entry.dir()) |d| d.sub = .{ .ref = kv.val.itemref(ref) }; }, .ino => { if (entry.link()) |l| l.ino = kv.val.int(u64); },