start with real sections

This commit is contained in:
Motiejus Jakštys 2022-03-02 06:50:15 +02:00 committed by Motiejus Jakštys
parent a526379fd8
commit 9721e1be7f
2 changed files with 51 additions and 6 deletions

View File

@ -370,12 +370,15 @@ STATUS SECTION SIZE DESCRIPTION
Section creation order:
1. Groupmembers, UserGids. No dependencies.
2. ShellIndex, ShellBlob. No dependencies.
3. `bdz_*`. No depdendencies.
4. Groups. Requires Groupmembers.
5. Users. Requires Groupmembers and ShellIndex.
6. `idx_*`. Requires offsets to Groups and Users.
1. `bdz_*`. No depdendencies.
1. ShellIndex, ShellBlob. No dependencies.
1. UserGids. No dependencies.
1. Users, but without `additional_gids_offset`. No dependencies.
1. Groupmembers. Depends on Users, ex. `additional_gids_offset`.
1. Groups. Requires Groupmembers.
1. Mutate `Users.additional_gids_offset`. Requires Groupmembers and ShellIndex.
1. `idx_*`. Requires offsets to Groups and Users.
1. Header.
[git-subtrac]: https://apenwarr.ca/log/20191109
[cmph]: http://cmph.sourceforge.net/

View File

@ -3,11 +3,13 @@ const unicode = std.unicode;
const sort = std.sort;
const Allocator = std.mem.Allocator;
const ArrayListUnmanaged = std.ArrayListUnmanaged;
const ArrayList = std.ArrayList;
const StringHashMap = std.StringHashMap;
const AutoHashMap = std.AutoHashMap;
const BufSet = std.BufSet;
const pad = @import("padding.zig");
const compress = @import("compress.zig");
const userImport = @import("user.zig");
const groupImport = @import("group.zig");
const User = userImport.User;
@ -139,6 +141,46 @@ const Corpus = struct {
}
};
pub const Sections = struct {
allocator: Allocator,
corpus: *const Corpus,
pub fn init(allocator: Allocator, corpus: *const Corpus) Sections {
return Sections{
.allocator = allocator,
.corpus = corpus,
};
}
pub const GroupMembers = struct {
offsets: []const usize,
bytes: []const u8,
};
const groupMembersErr = error{Overflow} || Allocator.Error;
pub fn groupMembers(self: *const Sections) groupMembersErr!GroupMembers {
var buf: [compress.maxVarintLen64]u8 = undefined;
var offsets = ArrayListUnmanaged(usize).initCapacity(
self.allocator,
self.corpus.groups.len,
);
var bytes = ArrayList(u8).init(self.allocator);
var offset: usize = 0;
for (self.corpus.groups) |group, i| {
offsets[i] = offset;
const users = self.corpus.groupname2users.get(group.name).?;
const len = try compress.putVarint(&buf, users.len);
offset += len;
try bytes.appendSlice(buf[0..len]);
for (users) |user| {
// TODO: offset into the User's record
_ = user;
}
}
}
};
// cmpUser compares two users for sorting. By username's utf8 codepoints, ascending.
fn cmpUser(_: void, a: User, b: User) bool {
var utf8_a = (unicode.Utf8View.init(a.name) catch unreachable).iterator();