From beca6a2ae67123d5eff5b223844a4f15521add69 Mon Sep 17 00:00:00 2001 From: "Caleb J. Gardner" Date: Sun, 1 Mar 2026 02:27:54 -0600 Subject: [PATCH] Small tweaks --- .github/workflows/release-build.yml | 4 +-- build.zig.zon | 39 ++------------------------- src/util/meta_cache.zig | 41 +++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 39 deletions(-) create mode 100644 src/util/meta_cache.zig diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index b53f4e5..f7776a7 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -17,7 +17,7 @@ jobs: - name: Build normal version run: zig build --release=fast -Dversion=${{ github.ref_name }} - name: Move normal build out - run: mv zig-out/bin/unsquashfs ./unsquashfs-x86_64 + run: mv zig-out/bin/unsquashfs ./unsquashfs-x86_64-zig-libs - name: Rebuild with C libraries run: zig build --release=fast -Duse_c_libs=true -Dversion="${{ github.ref_name }}" - name: Move C build out @@ -27,5 +27,5 @@ jobs: with: prerelease: true files: | - unsquashfs-x86_64 + unsquashfs-x86_64-zig-libs unsquashfs-x86_64-c-libs diff --git a/build.zig.zon b/build.zig.zon index 00d1bdd..fb60d72 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,44 +1,9 @@ .{ .name = .squashfs, - .version = "0.0.1", + .version = "0.0.6", .fingerprint = 0x37ba29474b87f145, // Changing this has security and trust implications. .minimum_zig_version = "0.15.2", - // This field is optional. - // Each dependency must either provide a `url` and `hash`, or a `path`. - // `zig build --fetch` can be used to fetch all dependencies of a package, recursively. - // Once all dependencies are fetched, `zig build` no longer requires - // internet connectivity. - .dependencies = .{ - // See `zig fetch --save ` for a command-line interface for adding dependencies. - //.example = .{ - // // When updating this field to a new URL, be sure to delete the corresponding - // // `hash`, otherwise you are communicating that you expect to find the old hash at - // // the new URL. If the contents of a URL change this will result in a hash mismatch - // // which will prevent zig from using it. - // .url = "https://example.com/foo.tar.gz", - // - // // This is computed from the file contents of the directory of files that is - // // obtained after fetching `url` and applying the inclusion rules given by - // // `paths`. - // // - // // This field is the source of truth; packages do not come from a `url`; they - // // come from a `hash`. `url` is just one of many possible mirrors for how to - // // obtain a package matching this `hash`. - // // - // // Uses the [multihash](https://multiformats.io/multihash/) format. - // .hash = "...", - // - // // When this is provided, the package is found in a directory relative to the - // // build root. In this case the package's hash is irrelevant and therefore not - // // computed. This field and `url` are mutually exclusive. - // .path = "foo", - // - // // When this is set to `true`, a package is declared to be lazily - // // fetched. This makes the dependency only get fetched if it is - // // actually used. - // .lazy = false, - //}, - }, + .dependencies = .{}, .paths = .{ "build.zig", "build.zig.zon", diff --git a/src/util/meta_cache.zig b/src/util/meta_cache.zig new file mode 100644 index 0000000..e60288a --- /dev/null +++ b/src/util/meta_cache.zig @@ -0,0 +1,41 @@ +const std = @import("std"); + +const OffsetFile = @import("offset_file.zig"); + +const MetadataCache = @This(); + +alloc: std.mem.Allocator, + +buf: []u8, +fixed_alloc: std.heap.FixedBufferAllocator, + +cache: std.AutoArrayHashMap(u64, [8192]u8), + +mut: std.Thread.Mutex = .{}, +cache_mut: std.AutoArrayHashMap(u64, std.Thread.Mutex), + +fil: OffsetFile, + +pub fn init(alloc: std.mem.Allocator, cache_size: u64) !MetadataCache {} +pub fn deinit(self: *MetadataCache) void { + self.mut.lock(); + defer self.mut.unlock(); + self.cache.deinit(); + self.cache_mut.deinit(); + self.alloc.free(self.buf); +} + +pub fn getChunk(self: *MetadataCache, offset: u64) ![8192]u8 { + var res = self.cache.get(offset); + if (res != null) return res.?; + var offset_mut = blk: { + self.mut.lock(); + defer self.mut.unlock(); + const mut = try self.cache_mut.getOrPut(offset); + if (!mut.found_existing) + mut.value_ptr.* = .{}; + break :blk mut.value_ptr; + }; + offset_mut.lock(); + defer offset_mut.unlock(); +}