diff options
Diffstat (limited to 'src/fs.zig')
| -rw-r--r-- | src/fs.zig | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -171,8 +171,8 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply { const path = osPath(p, req.node) orelse return Reply.fail(req.tag, E.NOENT); if (req.op == .release) return .{ .tag = req.tag }; const io = std.Io.Threaded.global_single_threaded.io(); - const stat = pardes.tape.site(.os_stat, null, statPath, .{ io, path, std.Io.Dir.StatFileOptions{} }) catch return Reply.fail(req.tag, E.NOENT); - const attr: Reply.Attr = .{ .name = if (req.node == os_root) "os" else std.fs.path.basename(path), .node = req.node, .dir = stat.kind == .directory, .size = stat.size, .mode = if (stat.kind == .directory) 0o755 else 0o644, .mtime = std.math.cast(u32, stat.mtime.toSeconds()) orelse 0 }; + const stat = pardes.tape.site(.os_stat, null, osStat, .{ io, path }) catch return Reply.fail(req.tag, E.NOENT); + const attr: Reply.Attr = .{ .name = if (req.node == os_root) "os" else std.fs.path.basename(path), .node = req.node, .dir = stat.kind == .directory, .size = stat.size, .mode = if (stat.kind == .directory) 0o755 else 0o644, .mtime = stat.mtime }; switch (req.op) { .getattr => return .{ .tag = req.tag, .attr = attr }, .open => { @@ -223,6 +223,16 @@ pub fn osHandle(p: *pardes.Pardes, req: Req) Reply { } } +/// What /os keeps of a stat, as the tape carries it to a replica: the same +/// bytes on every OS, which std.Io.File.Stat is not (a FreeBSD one's +/// `nlink` and `permissions` are another width than a Linux one's). +pub const OsStat = struct { kind: std.Io.File.Kind, size: u64, mtime: u32 }; + +fn osStat(io: std.Io, path: []const u8) !OsStat { + const stat = try statPath(io, path, .{}); + return .{ .kind = stat.kind, .size = stat.size, .mtime = std.math.cast(u32, stat.mtime.toSeconds()) orelse 0 }; +} + /// A directory's listing under /os, the entries from `off` until `size` /// bytes of them are staged, into `listing`: the syscalls of a readdir. fn osListing(io: std.Io, path: []const u8, off: u64, size: u32, listing: *[16 * 1024]u8) error{ NotDir, Io }![]const u8 { @@ -249,7 +259,7 @@ fn osListing(io: std.Io, path: []const u8, off: u64, size: u32, listing: *[16 * return listed.items; } -const OsReadWrite = union(enum) { reply: Reply, read: []const u8 }; +pub const OsReadWrite = union(enum) { reply: Reply, read: []const u8 }; /// The syscalls of an /os read, write or truncate: the reply, or the bytes /// read into `buf`. |
