From d5c37d9122240fe95d308fbe15874e14dd786c5a Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Wed, 21 Oct 2026 14:38:16 -0300 Subject: Build with Zig 0.17 --- 9ns/src/bridge.zig | 18 +++++++++--------- 9ns/src/fuse.zig | 20 ++++++++++---------- 9ns/src/main.zig | 2 +- 9ns/src/nine.zig | 4 ++-- 9ns/src/ns.zig | 38 +++++++++++++++++++------------------- 5 files changed, 41 insertions(+), 41 deletions(-) (limited to '9ns/src') diff --git a/9ns/src/bridge.zig b/9ns/src/bridge.zig index b94ef78..c866238 100644 --- a/9ns/src/bridge.zig +++ b/9ns/src/bridge.zig @@ -1594,7 +1594,7 @@ const Mntgen = struct { /// Never blocks on the worker; allocation or a racing death reject the /// request with an errno reply instead. fn enqueue(mg: *Mntgen, m: *Mount, raw: []const u8) void { - const wants_reply = switch (@as(fuse.Opcode, @enumFromInt(std.mem.readInt(u32, raw[4..8], .little)))) { + const wants_reply = switch (@as(fuse.Opcode, @fromBackingInt(@intCast(std.mem.readInt(u32, raw[4..8], .little))))) { .forget, .batch_forget => false, else => true, }; @@ -1670,7 +1670,7 @@ const Mntgen = struct { var buf: [@sizeOf(fuse.InHeader) + @sizeOf(fuse.ForgetIn)]u8 = undefined; const hdr = fuse.InHeader{ .len = @sizeOf(fuse.InHeader) + @sizeOf(fuse.ForgetIn), - .opcode = @intFromEnum(fuse.Opcode.forget), + .opcode = @backingInt(fuse.Opcode.forget), .unique = unique, .nodeid = nodeid, .uid = 0, @@ -2155,7 +2155,7 @@ fn uniqueOf(raw: []const u8) u64 { /// Whether the kernel expects an answer to a raw request: everything but /// the forgets. fn wantsReply(raw: []const u8) bool { - return switch (@as(fuse.Opcode, @enumFromInt(std.mem.readInt(u32, raw[4..8], .little)))) { + return switch (@as(fuse.Opcode, @fromBackingInt(@intCast(std.mem.readInt(u32, raw[4..8], .little))))) { .forget, .batch_forget => false, else => true, }; @@ -2689,17 +2689,17 @@ test "attr mapping saturates hostile lengths instead of overflowing" { test "dirent names the kernel would reject are dropped from listings" { try testing.expect(validDirentName("a")); - try testing.expect(validDirentName("x" ** 1024)); + try testing.expect(validDirentName(&@as([1024]u8, @splat('x')))); try testing.expect(!validDirentName("")); try testing.expect(!validDirentName("a/b")); try testing.expect(!validDirentName("a\x00b")); try testing.expect(!validDirentName(".")); try testing.expect(!validDirentName("..")); - try testing.expect(!validDirentName("x" ** 1025)); + try testing.expect(!validDirentName(&@as([1025]u8, @splat('x')))); var buf: [4096]u8 = undefined; var n: usize = 0; - for ([_][]const u8{ ".", "..", "", "a/b", "keep", "x" ** 1025, "also" }) |name| { + for ([_][]const u8{ ".", "..", "", "a/b", "keep", &@as([1025]u8, @splat('x')), "also" }) |name| { n += (try cloud9.Stat.encode(testStat(name, 0o644, 1, 0x30), buf[n..])).len; } var list: DirList = .{}; @@ -2744,7 +2744,7 @@ test "interrupt source: INTERRUPT in flight → Tflush, other INTERRUPTs ignored // A FORGET arriving during a wait is copied into the stash, and the fd // stays watched: an INTERRUPT can still arrive behind it. var wire: [48]u8 = undefined; - const hdr = fuse.InHeader{ .len = 48, .opcode = @intFromEnum(fuse.Opcode.forget), .unique = 99, .nodeid = 5, .uid = 0, .gid = 0, .pid = 0, .total_extlen = 0, .padding = 0 }; + const hdr = fuse.InHeader{ .len = 48, .opcode = @backingInt(fuse.Opcode.forget), .unique = 99, .nodeid = 5, .uid = 0, .gid = 0, .pid = 0, .total_extlen = 0, .padding = 0 }; @memcpy(wire[0..40], std.mem.asBytes(&hdr)); @memcpy(wire[40..48], std.mem.asBytes(&fuse.ForgetIn{ .nlookup = 1 })); try testing.expectEqual(@as(usize, 48), linux.write(pi.write_end, &wire, wire.len)); @@ -2845,7 +2845,7 @@ const FakeKernel = struct { fn send(k: *FakeKernel, op: fuse.Opcode, unique: u64, nodeid: u64, parts: []const []const u8) !void { var len: usize = @sizeOf(fuse.InHeader); for (parts) |p| len += p.len; - const header = fuse.InHeader{ .len = @intCast(len), .opcode = @intFromEnum(op), .unique = unique, .nodeid = nodeid, .uid = 0, .gid = 0, .pid = 0, .total_extlen = 0, .padding = 0 }; + const header = fuse.InHeader{ .len = @intCast(len), .opcode = @backingInt(op), .unique = unique, .nodeid = nodeid, .uid = 0, .gid = 0, .pid = 0, .total_extlen = 0, .padding = 0 }; var wire: [512]u8 = undefined; @memcpy(wire[0..@sizeOf(fuse.InHeader)], std.mem.asBytes(&header)); var at: usize = @sizeOf(fuse.InHeader); @@ -2982,7 +2982,7 @@ test "serve: a parked READ holds up neither other READs nor metadata; its INTERR try k.send(.interrupt, 11, 0, &.{std.mem.asBytes(&fuse.InterruptIn{ .unique = 10 })}); var r = try k.recv(3000); try testing.expectEqual(@as(u64, 10), r.unique); - try testing.expectEqual(-@as(i32, @intFromEnum(linux.E.INTR)), r.err); + try testing.expectEqual(-@as(i32, @backingInt(linux.E.INTR)), r.err); try testing.expectEqual(@as(u32, 1), fs.flushes.load(.seq_cst)); try testing.expectEqual(hung_tag, fs.flush_oldtag.load(.seq_cst)); diff --git a/9ns/src/fuse.zig b/9ns/src/fuse.zig index 5f7b22a..b70365f 100644 --- a/9ns/src/fuse.zig +++ b/9ns/src/fuse.zig @@ -139,7 +139,7 @@ pub const InHeader = extern struct { padding: u16, pub fn op(h: InHeader) Opcode { - return @enumFromInt(h.opcode); + return @fromBackingInt(@intCast(h.opcode)); } }; @@ -254,7 +254,7 @@ pub const Kstatfs = extern struct { namelen: u32 = 0, frsize: u32 = 0, padding: u32 = 0, - spare: [6]u32 = [_]u32{0} ** 6, + spare: [6]u32 = @splat(0), }; pub const StatfsOut = extern struct { st: Kstatfs = .{} }; @@ -283,7 +283,7 @@ pub const InitOut = extern struct { flags2: u32 = 0, max_stack_depth: u32 = 0, request_timeout: u16 = 0, - unused: [11]u16 = [_]u16{0} ** 11, + unused: [11]u16 = @splat(0), }; /// Fixed 24-byte head of `fuse_dirent`; the name follows, padded to 8 bytes. @@ -395,7 +395,7 @@ pub fn reply(fd: i32, unique: u64, payloads: []const []const u8) Error!void { /// Error reply: an `OutHeader` carrying `-errno` and no payload. pub fn replyError(fd: i32, unique: u64, err: linux.E) Error!void { - const code: i32 = @intCast(@intFromEnum(err)); + const code: i32 = @intCast(@backingInt(err)); const header = OutHeader{ .len = @sizeOf(OutHeader), .@"error" = -code, .unique = unique }; var iov = [_]std.posix.iovec_const{.{ .base = @ptrCast(&header), .len = @sizeOf(OutHeader) }}; return writeAll(fd, &iov, 1, @sizeOf(OutHeader)); @@ -528,8 +528,8 @@ test "struct sizes match linux/fuse.h" { try testing.expectEqual(@as(usize, 40), @sizeOf(InHeader)); try testing.expectEqual(@as(usize, 64), @sizeOf(InitOut)); try testing.expectEqual(@as(usize, 24), @sizeOf(Dirent)); - try testing.expectEqual(@as(u32, 26), @intFromEnum(Opcode.init)); - try testing.expectEqual(Opcode.statx, @as(Opcode, @enumFromInt(52))); + try testing.expectEqual(@as(u32, 26), @backingInt(Opcode.init)); + try testing.expectEqual(Opcode.statx, @as(Opcode, @fromBackingInt(@intCast(52)))); } test "addDirent pads records to 8 bytes and refuses when full" { @@ -573,7 +573,7 @@ test "body/nameAfter/secondName on hand-built requests" { const name = "hello"; const hdr = InHeader{ .len = @intCast(@sizeOf(InHeader) + name.len + 1), - .opcode = @intFromEnum(Opcode.lookup), + .opcode = @backingInt(Opcode.lookup), .unique = 7, .nodeid = root_id, .uid = 1000, @@ -617,7 +617,7 @@ test "body/nameAfter/secondName on hand-built requests" { } test "initReply fields" { - var in = InitIn{ .major = 7, .minor = 45, .max_readahead = 131072, .flags = 0, .flags2 = 0, .unused = [_]u32{0} ** 11 }; + var in = InitIn{ .major = 7, .minor = 45, .max_readahead = 131072, .flags = 0, .flags2 = 0, .unused = @splat(0) }; const a = initReply(&in, 1 << 20); try testing.expectEqual(@as(u32, 7), a.major); try testing.expectEqual(@as(u32, 31), a.minor); @@ -696,7 +696,7 @@ test "replyError writes a negative errno" { try replyError(fds[1], 1, .NOSYS); try readExact(fds[0], &out); - try testing.expectEqual(-@as(i32, @intCast(@intFromEnum(linux.E.NOSYS))), std.mem.bytesToValue(OutHeader, &out).@"error"); + try testing.expectEqual(-@as(i32, @intCast(@backingInt(linux.E.NOSYS))), std.mem.bytesToValue(OutHeader, &out).@"error"); } test "readRequest parses one request from a pipe and rejects bad lengths" { @@ -705,7 +705,7 @@ test "readRequest parses one request from a pipe and rejects bad lengths" { defer _ = linux.close(fds[1]); var wire: [48]u8 align(8) = undefined; - const hdr = InHeader{ .len = 48, .opcode = @intFromEnum(Opcode.forget), .unique = 3, .nodeid = 2, .uid = 0, .gid = 0, .pid = 0, .total_extlen = 0, .padding = 0 }; + const hdr = InHeader{ .len = 48, .opcode = @backingInt(Opcode.forget), .unique = 3, .nodeid = 2, .uid = 0, .gid = 0, .pid = 0, .total_extlen = 0, .padding = 0 }; @memcpy(wire[0..40], std.mem.asBytes(&hdr)); @memcpy(wire[40..48], std.mem.asBytes(&ForgetIn{ .nlookup = 11 })); try testing.expectEqual(@as(usize, 48), linux.write(fds[1], &wire, wire.len)); diff --git a/9ns/src/main.zig b/9ns/src/main.zig index 86763a7..21c6bf4 100644 --- a/9ns/src/main.zig +++ b/9ns/src/main.zig @@ -464,7 +464,7 @@ pub fn main(init: std.process.Init) !u8 { var server: ?Server = null; var address: nine.Address = undefined; if (cfg.spawn_cmd) |cmd| { - const cmd_z = try arena.dupeZ(u8, cmd); + const cmd_z = try arena.dupeSentinel(u8, cmd, 0); server = spawnServer(cmd_z, envp) catch return own_failure; ns.watchServer(server.?.pid); address = .{ .fd = server.?.fd }; diff --git a/9ns/src/nine.zig b/9ns/src/nine.zig index 1eda9e2..6b48e7a 100644 --- a/9ns/src/nine.zig +++ b/9ns/src/nine.zig @@ -937,7 +937,7 @@ fn readSocket(fd: i32, buf: []u8) Session.Error!usize { /// Rerror text → errno, per docs/DESIGN.md (first match wins): cloud9's /// fs.enameErrno, which a server's own tests can ask too. pub fn enameToErrno(ename: []const u8) linux.E { - return @enumFromInt(cloud9.fs.enameErrno(ename)); + return @fromBackingInt(@intCast(cloud9.fs.enameErrno(ename))); } // -- transport ------------------------------------------------------------------ @@ -960,7 +960,7 @@ fn openTransport(address: Address) !i32 { .ip4 => |a| { const sa: linux.sockaddr.in = .{ .port = std.mem.nativeToBig(u16, t.port), - .addr = @bitCast(a.bytes), + .addr = std.mem.bytesToValue(u32, &a.bytes), }; const fd = try newSocket(linux.AF.INET, linux.IPPROTO.TCP); errdefer _ = linux.close(fd); diff --git a/9ns/src/ns.zig b/9ns/src/ns.zig index db41eda..f7549ef 100644 --- a/9ns/src/ns.zig +++ b/9ns/src/ns.zig @@ -135,7 +135,7 @@ pub fn pathCandidates(gpa: Allocator, envp: [*:null]const ?[*:0]const u8, name: list.deinit(gpa); } if (std.mem.indexOfScalar(u8, name, '/') != null) { - try list.append(gpa, try gpa.dupeZ(u8, name)); + try list.append(gpa, try gpa.dupeSentinel(u8, name, 0)); return list.toOwnedSlice(gpa); } const path = getenv(envp, "PATH") orelse default_path; @@ -162,7 +162,7 @@ pub fn findInPath(gpa: Allocator, envp: [*:null]const ?[*:0]const u8, name: []co if (linux.errno(rc) != .SUCCESS) continue; if (stx.mode & linux.S.IFMT != linux.S.IFREG) continue; if (stx.mode & 0o111 == 0) continue; - return gpa.dupeZ(u8, c); + return gpa.dupeSentinel(u8, c, 0); } return error.FileNotFound; } @@ -208,7 +208,7 @@ fn freeEnvp(gpa: Allocator, envp: [:null]?[*:0]const u8) void { fn buildArgv(gpa: Allocator, argv: []const []const u8) ![:null]?[*:0]const u8 { const out = try gpa.allocSentinel(?[*:0]const u8, argv.len, null); - for (argv, 0..) |a, i| out[i] = (try gpa.dupeZ(u8, a)).ptr; + for (argv, 0..) |a, i| out[i] = (try gpa.dupeSentinel(u8, a, 0)).ptr; return out; } @@ -246,7 +246,7 @@ pub fn ensureMountpoint(gpa: Allocator, path: [:0]const u8) !void { while (true) { base = std.fs.path.dirname(base) orelse "/"; var base_buf: [path_max]u8 = undefined; - const base_z = std.fmt.bufPrintZ(&base_buf, "{s}", .{base}) catch { + const base_z = std.fmt.bufPrintSentinel(&base_buf, "{s}", .{base}, 0) catch { std.debug.print("9ns: mountpoint {s}: path too long\n", .{path}); return error.Mountpoint; }; @@ -278,7 +278,7 @@ pub fn ensureMountpoint(gpa: Allocator, path: [:0]const u8) !void { std.debug.print("9ns: mkdir {s}: E{t}; refusing to shadow {s} (pass --mount an existing directory)\n", .{ path, mk, base }); return error.Mountpoint; } - const base_z = try gpa.dupeZ(u8, base); + const base_z = try gpa.dupeSentinel(u8, base, 0); defer gpa.free(base_z); try shadowDirectory(gpa, base_z); switch (mkdirComponents(path, base.len, missing)) { @@ -311,7 +311,7 @@ fn mkdirComponents(path: []const u8, base_len: usize, missing: []const u8) E { var it = std.mem.tokenizeScalar(u8, missing, '/'); while (it.next()) |comp| { end += 1 + comp.len; - const prefix = std.fmt.bufPrintZ(&buf, "{s}", .{path[0..end]}) catch return .NAMETOOLONG; + const prefix = std.fmt.bufPrintSentinel(&buf, "{s}", .{path[0..end]}, 0) catch return .NAMETOOLONG; switch (linux.errno(linux.mkdirat(linux.AT.FDCWD, prefix, 0o755))) { .SUCCESS, .EXIST => {}, else => |e| return e, @@ -326,7 +326,7 @@ const FileType = enum { dir, symlink, other }; /// such as /proc/self/root) to the same inode. fn isSameDirectory(a: []const u8, b: [*:0]const u8) bool { var a_buf: [path_max]u8 = undefined; - const a_z = std.fmt.bufPrintZ(&a_buf, "{s}", .{a}) catch return false; + const a_z = std.fmt.bufPrintSentinel(&a_buf, "{s}", .{a}, 0) catch return false; var sa: linux.Statx = undefined; var sb: linux.Statx = undefined; if (linux.errno(linux.statx(linux.AT.FDCWD, a_z, 0, .{ .INO = true }, &sa)) != .SUCCESS) return false; @@ -384,7 +384,7 @@ fn listDir(gpa: Allocator, fd: i32, dirpath: []const u8) ![]Entry { linux.DT.UNKNOWN => fileType(fd, name_ptr, true) orelse .other, else => .other, }; - try list.append(gpa, .{ .name = try gpa.dupeZ(u8, name), .kind = kind }); + try list.append(gpa, .{ .name = try gpa.dupeSentinel(u8, name, 0), .kind = kind }); } } return list.toOwnedSlice(gpa); @@ -423,11 +423,11 @@ fn shadowDirectory(gpa: Allocator, parent: [:0]const u8) !void { var dst_buf: [path_max]u8 = undefined; var link_buf: [path_max]u8 = undefined; for (entries) |e| { - const src = std.fmt.bufPrintZ(&src_buf, "/proc/self/fd/{d}/{s}", .{ pfd, e.name }) catch { + const src = std.fmt.bufPrintSentinel(&src_buf, "/proc/self/fd/{d}/{s}", .{ pfd, e.name }, 0) catch { std.debug.print("9ns: shadow {s}/{s}: name too long (skipped)\n", .{ parent, e.name }); continue; }; - const dst = std.fmt.bufPrintZ(&dst_buf, "{s}/{s}", .{ parent, e.name }) catch { + const dst = std.fmt.bufPrintSentinel(&dst_buf, "{s}/{s}", .{ parent, e.name }, 0) catch { std.debug.print("9ns: shadow {s}/{s}: name too long (skipped)\n", .{ parent, e.name }); continue; }; @@ -509,7 +509,7 @@ pub fn spawn(gpa: Allocator, s: Spawn) !Child { return error.EmptyProgramName; } - const mountpoint = try gpa.dupeZ(u8, s.mountpoint); + const mountpoint = try gpa.dupeSentinel(u8, s.mountpoint, 0); defer gpa.free(mountpoint); const fuse_opts_prefix = try std.fmt.allocPrintSentinel(gpa, "rootmode=40000,user_id={d},group_id={d},max_read={d}", .{ s.uid, s.gid, s.max_read }, 0); defer gpa.free(fuse_opts_prefix); @@ -742,7 +742,7 @@ fn childMain(c: *const ChildArgs) noreturn { } const fd: i32 = @intCast(rc_open); var opts_buf: [256]u8 = undefined; - const opts = std.fmt.bufPrintZ(&opts_buf, "fd={d},{s}", .{ fd, c.fuse_opts_prefix }) catch unreachable; + const opts = std.fmt.bufPrintSentinel(&opts_buf, "fd={d},{s}", .{ fd, c.fuse_opts_prefix }, 0) catch unreachable; const rc = linux.mount("9ns", c.mountpoint, "fuse", linux.MS.NOSUID | linux.MS.NODEV, @intFromPtr(opts.ptr)); if (linux.errno(rc) != .SUCCESS) childFail(c, setup_failure_status, "mount fuse", linux.errno(rc), true); fuse_fd = fd; @@ -860,7 +860,7 @@ fn armWatchdog() void { .it_interval = .{ .sec = 0, .nsec = 0 }, .it_value = .{ .sec = exit_grace_seconds, .nsec = 0 }, }; - _ = linux.setitimer(@intFromEnum(linux.ITIMER.REAL), &t, null); + _ = linux.setitimer(@backingInt(linux.ITIMER.REAL), &t, null); } fn onAlarm(_: linux.SIG) callconv(.c) void { @@ -888,14 +888,14 @@ fn onChld(_: linux.SIG) callconv(.c) void { const srv = server_pid.load(.seq_cst); if (srv > 0) { var sst: u32 = 0; - const src = linux.waitpid(srv, &sst, linux.W.NOHANG); + const src = linux.waitpid(srv, @ptrCast(&sst), linux.W.NOHANG); if (linux.errno(src) == .SUCCESS and src != 0) server_pid.store(0, .seq_cst); } const p = child_pid_ptr orelse return; const pid = @atomicLoad(i32, p, .seq_cst); if (pid <= 0) return; var st: u32 = 0; - const rc = linux.waitpid(pid, &st, linux.W.NOHANG); + const rc = linux.waitpid(pid, @ptrCast(&st), linux.W.NOHANG); if (linux.errno(rc) != .SUCCESS or rc == 0) return; reaped_status.store(st, .release); reaped.store(true, .release); @@ -960,7 +960,7 @@ fn takeReaped() ?u32 { /// waitpid status → exit code (`128+sig` when killed by a signal). pub fn decodeStatus(st: u32) u8 { if (linux.W.IFEXITED(st)) return linux.W.EXITSTATUS(st); - if (linux.W.IFSIGNALED(st)) return 128 +% @as(u8, @truncate(@intFromEnum(linux.W.TERMSIG(st)))); + if (linux.W.IFSIGNALED(st)) return 128 +% @as(u8, @truncate(@backingInt(linux.W.TERMSIG(st)))); return 1; } @@ -969,7 +969,7 @@ pub fn waitChild(pid: i32) !u8 { while (true) { if (takeReaped()) |st| return decodeStatus(st); var st: u32 = 0; - const rc = linux.waitpid(pid, &st, 0); + const rc = linux.waitpid(pid, @ptrCast(&st), 0); switch (linux.errno(rc)) { .SUCCESS => return decodeStatus(st), .INTR => continue, @@ -989,7 +989,7 @@ pub fn waitChild(pid: i32) !u8 { pub fn reapIfExited(pid: i32) ?u8 { if (takeReaped()) |st| return decodeStatus(st); var st: u32 = 0; - const rc = linux.waitpid(pid, &st, linux.W.NOHANG); + const rc = linux.waitpid(pid, @ptrCast(&st), linux.W.NOHANG); switch (linux.errno(rc)) { .SUCCESS => return if (rc == 0) null else decodeStatus(st), .CHILD => return if (takeReaped()) |s| decodeStatus(s) else null, @@ -1000,7 +1000,7 @@ pub fn reapIfExited(pid: i32) ?u8 { /// Reap any child (used for the `--spawn` server at exit). Non-blocking. pub fn reapAny(pid: i32) void { var st: u32 = 0; - _ = linux.waitpid(pid, &st, linux.W.NOHANG); + _ = linux.waitpid(pid, @ptrCast(&st), linux.W.NOHANG); } // --------------------------------------------------------------------------- -- cgit v1.3