| ... | ... | @@ -3,6 +3,7 @@ const builtin = @import("builtin"); |
| 3 | 3 | const sys_libc = @import("sys-libc"); |
| 4 | 4 | const nio = @import("nio"); |
| 5 | 5 | const errno = @import("errno"); |
| 6 | const time = @import("time"); |
| 6 | 7 | |
| 7 | 8 | const nfs = @import("./nfs.zig"); |
| 8 | 9 | const Dir = nfs.Dir; |
| ... | ... | @@ -37,3 +38,45 @@ pub fn anyReadable(self: File) nio.AnyReadable { |
| 37 | 38 | .state = @ptrFromInt(@as(usize, @bitCast(@as(isize, @intCast(@intFromEnum(self.fd)))))), |
| 38 | 39 | }; |
| 39 | 40 | } |
| 41 | |
| 42 | pub fn stat(self: File) !Stat { |
| 43 | const st = try sys_libc.fstat(@intFromEnum(self.fd)); |
| 44 | return .{ |
| 45 | .inode = st.ino, |
| 46 | .size = @bitCast(st.size), |
| 47 | .mode = st.mode, |
| 48 | .kind = {}, |
| 49 | .atime = @as(i128, st.atim.sec) * time.ns_per_s + st.atim.nsec, |
| 50 | .mtime = @as(i128, st.mtim.sec) * time.ns_per_s + st.mtim.nsec, |
| 51 | .ctime = @as(i128, st.ctim.sec) * time.ns_per_s + st.ctim.nsec, |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | pub const Stat = struct { |
| 56 | inode: INode, |
| 57 | size: u64, |
| 58 | mode: Mode, |
| 59 | kind: void, //Kind, |
| 60 | /// Last access time in nanoseconds, relative to UTC 1970-01-01. |
| 61 | atime: i128, |
| 62 | /// Last modification time in nanoseconds, relative to UTC 1970-01-01. |
| 63 | mtime: i128, |
| 64 | /// Last status/metadata change time in nanoseconds, relative to UTC 1970-01-01. |
| 65 | ctime: i128, |
| 66 | }; |
| 67 | |
| 68 | pub const INode = switch (builtin.target.os.tag) { |
| 69 | .linux, |
| 70 | => sys_libc.ino_t, |
| 71 | else => |v| @compileError("TODO: " ++ @tagName(v)), |
| 72 | }; |
| 73 | |
| 74 | pub const Mode = switch (builtin.target.os.tag) { |
| 75 | .linux, |
| 76 | => sys_libc.mode_t, |
| 77 | else => |v| @compileError("TODO: " ++ @tagName(v)), |
| 78 | }; |
| 79 | |
| 80 | pub const Kind = enum { |
| 81 | // |
| 82 | }; |