Some cleanup to build zon.

Minor start on threaded extraction
This commit is contained in:
Caleb J. Gardner
2026-02-07 16:59:23 -06:00
committed by Caleb Gardner
parent 0e0222cd02
commit 053d64a954
5 changed files with 33 additions and 53 deletions
+1 -1
View File
@@ -20,7 +20,7 @@ pub fn build(b: *std.Build) !void {
mod.linkSystemLibrary("zstd", .{}); mod.linkSystemLibrary("zstd", .{});
const unsquashfs_options = b.addOptions(); const unsquashfs_options = b.addOptions();
unsquashfs_options.addOption(std.SemanticVersion, "version_string", try std.SemanticVersion.parse(version_string_option orelse "0.0.0-testing")); unsquashfs_options.addOption(std.SemanticVersion, "version", try std.SemanticVersion.parse(version_string_option orelse "0.0.0-testing"));
var exe_mod = b.createModule(.{ var exe_mod = b.createModule(.{
.root_source_file = b.path("src/bin/unsquashfs.zig"), .root_source_file = b.path("src/bin/unsquashfs.zig"),
+6 -37
View File
@@ -1,30 +1,7 @@
.{ .{
// This is the default name used by packages depending on this one. For .name = .squashfs,
// example, when a user runs `zig fetch --save <url>`, this field is used .version = "0.0.1",
// as the key in the `dependencies` table. Although the user can choose a .fingerprint = 0x37ba29474b87f145, // Changing this has security and trust implications.
// different name, most users will stick with this provided value.
//
// It is redundant to include "zig" in this name because it is already
// within the Zig package namespace.
.name = .zig_squashfs,
// This is a [Semantic Version](https://semver.org/).
// In a future version of Zig it will be used for package deduplication.
.version = "0.0.0",
// Together with name, this represents a globally unique package
// identifier. This field is generated by the Zig toolchain when the
// package is first created, and then *never changes*. This allows
// unambiguous detection of one package being an updated version of
// another.
//
// When forking a Zig project, this id should be regenerated (delete the
// field and run `zig build`) if the upstream project is still maintained.
// Otherwise, the fork is *hostile*, attempting to take control over the
// original project's identity. Thus it is recommended to leave the comment
// on the following line intact, so that it shows up in code reviews that
// modify the field.
.fingerprint = 0x527960c74dddb509, // Changing this has security and trust implications.
// Tracks the earliest Zig version that the package considers to be a
// supported use case.
.minimum_zig_version = "0.15.2", .minimum_zig_version = "0.15.2",
// This field is optional. // This field is optional.
// Each dependency must either provide a `url` and `hash`, or a `path`. // Each dependency must either provide a `url` and `hash`, or a `path`.
@@ -62,20 +39,12 @@
// .lazy = false, // .lazy = false,
//}, //},
}, },
// Specifies the set of files and directories that are included in this package.
// Only files and directories listed here are included in the `hash` that
// is computed for this package. Only files listed here will remain on disk
// when using the zig package manager. As a rule of thumb, one should list
// files required for compilation plus any license(s).
// Paths are relative to the build root. Use the empty string (`""`) to refer to
// the build root itself.
// A directory listed here means that all files within, recursively, are included.
.paths = .{ .paths = .{
"build.zig", "build.zig",
"build.zig.zon", "build.zig.zon",
"src", "src",
// For example...
//"LICENSE", "LICENSE",
//"README.md", "README.md",
}, },
} }
+4 -3
View File
@@ -1,5 +1,6 @@
const std = @import("std"); const std = @import("std");
const Writer = std.Io.Writer; const Writer = std.Io.Writer;
const builtin = @import("builtin");
const config = @import("config"); const config = @import("config");
const squashfs = @import("zig_squashfs"); const squashfs = @import("zig_squashfs");
@@ -64,9 +65,9 @@ fn handleArgs(alloc: std.mem.Allocator, out: *Writer) !void {
extLoc = nxt.?; extLoc = nxt.?;
continue; continue;
} else if (std.mem.eql(u8, arg, "--version")) { } else if (std.mem.eql(u8, arg, "--version")) {
_ = try out.write("v"); _ = try out.write("unsquashfs version");
try config.version_string.format(out); try config.version.format(out);
_ = try out.write("\n"); try out.print("\nBuilt using Zig {s} with {} backend in {} mode.\n", .{ builtin.zig_version_string, builtin.zig_backend, builtin.mode });
std.process.cleanExit(); std.process.cleanExit();
return; return;
} }
+1 -2
View File
@@ -198,8 +198,7 @@ pub fn extract(self: *SfsFile, path: []const u8, options: ExtractionOptions) !vo
} }
} }
defer if (ext_path.len > path.len) alloc.free(ext_path); defer if (ext_path.len > path.len) alloc.free(ext_path);
//TODO: switch to threaded version. return self.inode.extractToThreaded(self.archive, path, options, self.archive.thread_count);
return self.inode.extractTo(self.archive, path, options);
} }
/// Utility function. /// Utility function.
+21 -10
View File
@@ -133,6 +133,7 @@ fn entriesFromData(archive: *Archive, data: anytype) ![]DirEntry {
return DirEntry.readDir(alloc, &meta.interface, data.size); return DirEntry.readDir(alloc, &meta.interface, data.size);
} }
/// Extract the inode to the given path. Single threaded.
pub fn extractTo(self: Inode, archive: *Archive, path: []const u8, options: ExtractionOptions) !void { pub fn extractTo(self: Inode, archive: *Archive, path: []const u8, options: ExtractionOptions) !void {
switch (self.hdr.inode_type) { switch (self.hdr.inode_type) {
.dir, .ext_dir => { .dir, .ext_dir => {
@@ -175,20 +176,30 @@ const Perms = struct {
mod_time: u32, mod_time: u32,
}; };
pub fn extractToThreaded(inode: Inode, archive: *Archive, path: []const u8, options: ExtractionOptions, threads: usize) !void { /// Extract the inode to the given path. Multi-threaded.
_ = archive; /// Functions identically to extractTo on all but regular files and directories.
_ = path; ///
_ = options; /// If threads <= 1, then this just calls extractTo.
_ = threads; pub fn extractToThreaded(self: Inode, archive: *Archive, path: []const u8, options: ExtractionOptions, threads: usize) !void {
switch (inode.hdr.inode_type) {} if (threads <= 1) return self.extractTo(archive, path, options);
std.debug.print("{}\n", .{threads});
@constCast(&threads).* = try std.Thread.getCpuCount();
std.debug.print("{}\n", .{threads});
switch (self.hdr.inode_type) {
.dir, .ext_dir => {},
.file, .ext_file => {},
.symlink, .ext_symlink => try self.extractSymlink(path),
else => try self.extractDevice(archive, path, options),
}
return error.TODO;
} }
/// Extract threadedly the inode to the path. /// Extract threadedly the inode to the path.
fn extractThread(inode: Inode, archive: *Archive, path: []const u8, options: ExtractionOptions, wg: *WaitGroup, pool: *Pool, perms: ?*std.ArrayList(Perms)) !void { fn extractThread(self: Inode, archive: *Archive, path: []const u8, options: ExtractionOptions, wg: *WaitGroup, pool: *Pool, perms: ?*std.ArrayList(Perms)) !void {
_ = pool; _ = pool;
_ = perms; _ = perms;
_ = archive; _ = archive;
switch (inode.hdr.inode_type) { switch (self.hdr.inode_type) {
.dir, .ext_dir => { .dir, .ext_dir => {
//TOOD //TOOD
return error.TODO; return error.TODO;
@@ -199,11 +210,11 @@ fn extractThread(inode: Inode, archive: *Archive, path: []const u8, options: Ext
}, },
.symlink, .ext_symlink => { .symlink, .ext_symlink => {
defer wg.finish(); defer wg.finish();
try inode.extractSymlink(path); try self.extractSymlink(path);
}, },
else => { else => {
defer wg.finish(); defer wg.finish();
try inode.extractDevice(path, options.ignore_permissions); try self.extractDevice(path, options.ignore_permissions);
}, },
} }
} }