syntax cosmetics
This commit is contained in:
parent
65914ddcd6
commit
d6150734f1
@ -132,10 +132,11 @@ caller does not receive `ENOMEM`.
|
|||||||
Primitive types
|
Primitive types
|
||||||
---------------
|
---------------
|
||||||
|
|
||||||
`User` and `Group` entries are sorted by the order they were received in the input
|
`User` and `Group` entries are sorted by the order they were received in the
|
||||||
file. All entries are aligned to 8 bytes. All `User` and `Group` entries are
|
input file. All entries are aligned to 8 bytes. All `User` and `Group` entries
|
||||||
referred by their byte offset in the `Users` and `Groups` section relative to
|
are referred by their byte offset (shifted by 3 bits due to the 8-byte
|
||||||
the beginning of the section.
|
alignment) in the `Users` and `Groups` section relative to the beginning of the
|
||||||
|
section.
|
||||||
|
|
||||||
```
|
```
|
||||||
const PackedGroup = packed struct {
|
const PackedGroup = packed struct {
|
||||||
@ -146,7 +147,8 @@ const PackedGroup = packed struct {
|
|||||||
```
|
```
|
||||||
|
|
||||||
PackedGroup is followed by the group name (of length `groupname_len`), followed
|
PackedGroup is followed by the group name (of length `groupname_len`), followed
|
||||||
by a varint-compressed offset to the groupmembers section, followed by 8b padding.
|
by a varint-compressed offset to the groupmembers section, followed by padding
|
||||||
|
upto 8 bytes.
|
||||||
|
|
||||||
PackedUser is a bit more involved:
|
PackedUser is a bit more involved:
|
||||||
|
|
||||||
@ -177,9 +179,9 @@ them.
|
|||||||
|
|
||||||
PackedUser employs two data-oriented compression techniques:
|
PackedUser employs two data-oriented compression techniques:
|
||||||
- shells are often shared across different users, see the "Shells" section.
|
- shells are often shared across different users, see the "Shells" section.
|
||||||
- `name` is frequently a suffix of `home`. For example, `/home/vidmantas` and
|
- `name` is frequently a suffix of `home`. For example, `home=/home/vidmantas`
|
||||||
`vidmantas`. In this case storing both name and home is wasteful. Therefore
|
and `name=vidmantas`. In this case storing both name and home is wasteful.
|
||||||
name has two options:
|
Therefore name has two options:
|
||||||
1. `name_is_a_suffix=true`: name is a suffix of the home dir. Then `name`
|
1. `name_is_a_suffix=true`: name is a suffix of the home dir. Then `name`
|
||||||
starts at the `home_len - name_len`'th byte of `home`, and ends at the same
|
starts at the `home_len - name_len`'th byte of `home`, and ends at the same
|
||||||
place as `home`.
|
place as `home`.
|
||||||
|
@ -702,10 +702,10 @@ fn bdzIdx(
|
|||||||
keys: []const T,
|
keys: []const T,
|
||||||
idx2offset: []const u32,
|
idx2offset: []const u32,
|
||||||
) error{OutOfMemory}![]align(8) const u32 {
|
) error{OutOfMemory}![]align(8) const u32 {
|
||||||
const search_fn = switch (T) {
|
const search_fn = comptime switch (T) {
|
||||||
u32 => bdz.search_u32,
|
u32 => bdz.search_u32,
|
||||||
[]const u8 => bdz.search,
|
[]const u8 => bdz.search,
|
||||||
else => unreachable,
|
else => @compileError("unexpected type " ++ @typeName(T)),
|
||||||
};
|
};
|
||||||
assert(keys.len <= math.maxInt(u32));
|
assert(keys.len <= math.maxInt(u32));
|
||||||
var result = try allocator.alignedAlloc(u32, 8, keys.len);
|
var result = try allocator.alignedAlloc(u32, 8, keys.len);
|
||||||
|
@ -74,7 +74,6 @@ pub fn fromReader(allocator: Allocator, reader: anytype) FromReaderError![]Group
|
|||||||
|
|
||||||
var i: usize = 0;
|
var i: usize = 0;
|
||||||
while (true) : (i += 1) {
|
while (true) : (i += 1) {
|
||||||
// TODO: catch and interpret different errors
|
|
||||||
const max = std.math.maxInt(u32);
|
const max = std.math.maxInt(u32);
|
||||||
reader.readUntilDelimiterArrayList(&line, '\n', max) catch |err| switch (err) {
|
reader.readUntilDelimiterArrayList(&line, '\n', max) catch |err| switch (err) {
|
||||||
error.EndOfStream => break,
|
error.EndOfStream => break,
|
||||||
|
@ -220,7 +220,7 @@ fn getgrgid_r(
|
|||||||
const omit_members = state.omit_members;
|
const omit_members = state.omit_members;
|
||||||
|
|
||||||
var buf = buffer[0..buflen];
|
var buf = buffer[0..buflen];
|
||||||
var cgroup = db.getgrgid(gid, buf, omit_members) catch |err| switch (err) {
|
const cgroup = db.getgrgid(gid, buf, omit_members) catch |err| switch (err) {
|
||||||
error.BufferTooSmall => {
|
error.BufferTooSmall => {
|
||||||
errnop.* = @enumToInt(os.E.RANGE);
|
errnop.* = @enumToInt(os.E.RANGE);
|
||||||
return c.NSS_STATUS_TRYAGAIN;
|
return c.NSS_STATUS_TRYAGAIN;
|
||||||
@ -262,17 +262,16 @@ fn getgrnam_r(
|
|||||||
const omit_members = state.omit_members;
|
const omit_members = state.omit_members;
|
||||||
const nameSlice = mem.sliceTo(name, 0);
|
const nameSlice = mem.sliceTo(name, 0);
|
||||||
var buf = buffer[0..buflen];
|
var buf = buffer[0..buflen];
|
||||||
var cgroup = db.getgrnam(nameSlice, buf, omit_members) catch |err| switch (err) {
|
const cgroup = db.getgrnam(nameSlice, buf, omit_members) catch |err| switch (err) {
|
||||||
error.BufferTooSmall => {
|
error.BufferTooSmall => {
|
||||||
errnop.* = @enumToInt(os.E.RANGE);
|
errnop.* = @enumToInt(os.E.RANGE);
|
||||||
return c.NSS_STATUS_TRYAGAIN;
|
return c.NSS_STATUS_TRYAGAIN;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const got_cgroup = cgroup orelse {
|
group.* = cgroup orelse {
|
||||||
errnop.* = @enumToInt(os.E.NOENT);
|
errnop.* = @enumToInt(os.E.NOENT);
|
||||||
return c.NSS_STATUS_NOTFOUND;
|
return c.NSS_STATUS_NOTFOUND;
|
||||||
};
|
};
|
||||||
group.* = got_cgroup;
|
|
||||||
return c.NSS_STATUS_SUCCESS;
|
return c.NSS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -286,11 +285,10 @@ fn setpwent(state: *State) c.enum_nss_status {
|
|||||||
state.getpwent_iterator_mu.lock();
|
state.getpwent_iterator_mu.lock();
|
||||||
defer state.getpwent_iterator_mu.unlock();
|
defer state.getpwent_iterator_mu.unlock();
|
||||||
|
|
||||||
const db = state.file.db;
|
|
||||||
state.getpwent_iterator = PackedUser.iterator(
|
state.getpwent_iterator = PackedUser.iterator(
|
||||||
db.users,
|
state.file.db.users,
|
||||||
db.header.num_users,
|
state.file.db.header.num_users,
|
||||||
db.shellReader(),
|
state.file.db.shellReader(),
|
||||||
);
|
);
|
||||||
return c.NSS_STATUS_SUCCESS;
|
return c.NSS_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user