struct MetadataLinux [src]

MetadataUnix, but using Linux's statx syscall.

Fields

statx: std.os.linux.Statx

Members

Source

pub const MetadataLinux = struct { statx: std.os.linux.Statx, const Self = @This(); /// Returns the size of the file pub fn size(self: Self) u64 { return self.statx.size; } /// Returns a `Permissions` struct, representing the permissions on the file pub fn permissions(self: Self) Permissions { return Permissions{ .inner = PermissionsUnix{ .mode = self.statx.mode } }; } /// Returns the `Kind` of the file pub fn kind(self: Self) Kind { const m = self.statx.mode & posix.S.IFMT; switch (m) { posix.S.IFBLK => return .block_device, posix.S.IFCHR => return .character_device, posix.S.IFDIR => return .directory, posix.S.IFIFO => return .named_pipe, posix.S.IFLNK => return .sym_link, posix.S.IFREG => return .file, posix.S.IFSOCK => return .unix_domain_socket, else => {}, } return .unknown; } /// Returns the last time the file was accessed in nanoseconds since UTC 1970-01-01 pub fn accessed(self: Self) i128 { return @as(i128, self.statx.atime.sec) * std.time.ns_per_s + self.statx.atime.nsec; } /// Returns the last time the file was modified in nanoseconds since UTC 1970-01-01 pub fn modified(self: Self) i128 { return @as(i128, self.statx.mtime.sec) * std.time.ns_per_s + self.statx.mtime.nsec; } /// Returns the time the file was created in nanoseconds since UTC 1970-01-01. /// Returns null if this is not supported by the filesystem, or on kernels before than version 4.11 pub fn created(self: Self) ?i128 { if (self.statx.mask & std.os.linux.STATX_BTIME == 0) return null; return @as(i128, self.statx.btime.sec) * std.time.ns_per_s + self.statx.btime.nsec; } }