diff --git a/README.md b/README.md index 3f34872..56f2601 100644 --- a/README.md +++ b/README.md @@ -180,10 +180,10 @@ referred by their byte offset in the `Users` and `Groups` section relative to the beginning of the section. ``` -const PackedGroup = struct { +const PackedGroup = packed struct { gid: u32, // index to a separate structure with a list of members. The memberlist is - // always 2^5-byte aligned (32b), this is an index there. + // 2^5-byte aligned (32b), this is an index there. members_offset: u27, groupname_len: u5, // a groupname_len-sized string @@ -347,10 +347,10 @@ Each section is padded to 64 bytes. ``` STATUS SECTION SIZE DESCRIPTION ✅ Header 48 see "Turbonss header" section - bdz_gid ? bdz(gid) - bdz_groupname ? bdz(groupname) - bdz_uid ? bdz(uid) - bdz_name ? bdz(username) +✅ bdz_gid ? bdz(gid) +✅ bdz_groupname ? bdz(groupname) +✅ bdz_uid ? bdz(uid) +✅ bdz_name ? bdz(username) idx_gid2group len(group)*29/8 bdz->offset Groups idx_groupname2group len(group)*29/8 bdz->offset Groups idx_uid2user len(user)*29/8 bdz->offset Users diff --git a/src/bdz.zig b/src/bdz.zig index 018f8ad..628d9d2 100644 --- a/src/bdz.zig +++ b/src/bdz.zig @@ -5,7 +5,7 @@ const c = @cImport({ @cInclude("bdz.h"); }); -pub fn search_packed(packed_mphf: []const u8, key: []const u8) error{Overflow}!u32 { +pub fn search(packed_mphf: []const u8, key: []const u8) error{Overflow}!u32 { const bdz_start = @intToPtr(?*anyopaque, @ptrToInt(&packed_mphf[0])); const len = try std.math.cast(c_uint, key.len); return @as(u32, c.bdz_search_packed(bdz_start, key.ptr, len)); diff --git a/src/cmph.zig b/src/cmph.zig index 3380155..af3be3b 100644 --- a/src/cmph.zig +++ b/src/cmph.zig @@ -59,7 +59,7 @@ test "basic pack/unpack" { var used: [items_len]bool = undefined; inline for (items) |elem| { - const hashed = try bdz.search_packed(buf, elem); + const hashed = try bdz.search(buf, elem); used[hashed] = true; } diff --git a/src/group.zig b/src/group.zig index 4e11855..b1e2087 100644 --- a/src/group.zig +++ b/src/group.zig @@ -1,7 +1,19 @@ const std = @import("std"); +const PackedGroup = packed struct { + gid: u32, + members_offset: u27, + groupname_len: u5, +}; + const Group = struct { gid: u32, name: []const u8, members: std.BufSet, }; + +const testing = std.testing; + +test "PackedGroup alignment" { + try testing.expectEqual(@sizeOf(PackedGroup) * 8, @bitSizeOf(PackedGroup)); +} diff --git a/src/user.zig b/src/user.zig index 1e556ea..fcdb04c 100644 --- a/src/user.zig +++ b/src/user.zig @@ -248,7 +248,7 @@ test "PackedUser internal and external alignment" { // cannot be converted from/to [@bitSizeOf(PackedUser)/8]u8; // asBytes/bytesAsValue use @sizeOf, which is larger. Now we are putting no // more than 1, but it probably could be higher. - try testing.expect(@bitSizeOf(PackedUser) - @sizeOf(PackedUser) * 8 <= 8); + try testing.expect(@sizeOf(PackedUser) * 8 - @bitSizeOf(PackedUser) <= 8); } fn testShellIndex(shell: []const u8) ?u6 {