Module sys/statx

sys/statx
Stability: unstable — it is a BORROWED view with no lifetime to enforce that. A `Statx` holds a bare pointer to a buffer someone else allocated and owns, so it dangles the moment that buffer is freed, and nothing in the type system says so. The field set is also the intersection of what three different platform structs happen to carry, with per-platform meanings that differ (see `ctime_sec`, `uid` and `ino` below), and it omits fields the runtime already extracts — Linux's `btime` (creation time), `blksize` and `blocks`. Freezing needs an owning type, and a decision on whether creation time joins the set. `std/fs/metadata` is the stable surface. — stable modules only change additively; this one may still change.

Statx — a typed view over the platform's stat buffer.

std/sys/file's statx (by path) and fstat (by descriptor) fill a raw buffer whose LAYOUT differs per platform: a struct statx on Linux, a struct stat on macOS and wasm, and a private struct on Windows that carries a _stat64 plus the sub-second times and NTFS file index that _stat64 cannot supply. Statx wraps that buffer so the field readers live behind one Yo type instead of at every call site — which is the whole reason this is a struct with methods rather than a set of free functions.

std/fs/metadata.yo (Metadata) is the public surface; std/fs/file.yo and std/fs/dir.yo also read it directly.

Stability

unstable — it is a BORROWED view with no lifetime to enforce that. A Statx holds a bare pointer to a buffer someone else allocated and owns, so it dangles the moment that buffer is freed, and nothing in the type system says so. The field set is also the intersection of what three different platform structs happen to carry, with per-platform meanings that differ (see ctime_sec, uid and ino below), and it omits fields the runtime already extracts — Linux's btime (creation time), blksize and blocks. Freezing needs an owning type, and a decision on whether creation time joins the set. std/fs/metadata is the stable surface.

Types

Statx struct
Statx

A read-only view of the metadata that a statx or fstat call wrote into a caller-owned buffer.

It stores only the pointer and the size — it allocates nothing, frees nothing, and is only valid while the underlying buffer lives. Construct it over a buffer of __yo_statx_buf_size() bytes that one of std/sys/file's statx/fstat has filled; reading it before a successful fill returns whatever was in the memory.

Fields

NameTypeDescription
_buf_ptr*(u8)
_buf_sizeusize
impl(Statx, ...)
is_file : (Statx) fn(self : Statx) -> bool

Whether this is a regular file — S_ISREG, i.e. mode & S_IFMT == S_IFREG. Sockets, FIFOs and devices are all false.

Parameters

NameTypeNotes
selfStatx

Returns: bool

is_directory : (Statx) fn(self : Statx) -> bool

Whether this is a directory — S_ISDIR.

Parameters

NameTypeNotes
selfStatx

Returns: bool

size : (Statx) fn(self : Statx) -> i64

Size in bytes. For a regular file the file length; for a SYMLINK stat'ed without following, the length of the target path — which is how you size a readlink buffer exactly. For a directory an unspecified filesystem-internal number, not an entry count.

Parameters

NameTypeNotes
selfStatx

Returns: i64

mode : (Statx) fn(self : Statx) -> u32

The raw st_mode word: file-type bits AND permission bits together. Mask with S_IFMT for the type (the is_* predicates above do it for you) or with 0o7777 for the permissions before passing it to std/sys/perm's fchmod. On Windows the CRT synthesizes this from the file attributes, so the group and other bits mirror the owner's rather than describing an ACL.

Parameters

NameTypeNotes
selfStatx

Returns: u32

uid : (Statx) fn(self : Statx) -> u32

Owning user id. 0 on Windows, which has no numeric uid — the CRT's _stat64 zeroes the field rather than mapping a SID.

Parameters

NameTypeNotes
selfStatx

Returns: u32

gid : (Statx) fn(self : Statx) -> u32

Owning group id. 0 on Windows, for the same reason as uid.

Parameters

NameTypeNotes
selfStatx

Returns: u32

ino : (Statx) fn(self : Statx) -> u64

Inode number — unique per filesystem, so the pair (device, inode) identifies a file and is how you detect two paths that are hard links to the same thing. On Windows the runtime supplies the NTFS file index from GetFileInformationByHandle, which plays the same role.

Parameters

NameTypeNotes
selfStatx

Returns: u64

mtime_sec : (Statx) fn(self : Statx) -> i64

Modification time, whole seconds since the Unix epoch — when the CONTENTS last changed. This is the timestamp to compare for "is my build output stale".

Parameters

NameTypeNotes
selfStatx

Returns: i64

mtime_nsec : (Statx) fn(self : Statx) -> u32

Nanoseconds part of the modification time, 0..999_999_999. Filesystem resolution varies — HFS+ and many older filesystems store whole seconds, so a 0 here does not mean the write landed exactly on a second boundary.

Parameters

NameTypeNotes
selfStatx

Returns: u32

atime_sec : (Statx) fn(self : Statx) -> i64

Access time, whole seconds since the Unix epoch. Often stale on purpose: most systems mount with relatime or noatime, so this may not have been updated by the last read.

Parameters

NameTypeNotes
selfStatx

Returns: i64

atime_nsec : (Statx) fn(self : Statx) -> u32

Nanoseconds part of the access time, 0..999_999_999.

Parameters

NameTypeNotes
selfStatx

Returns: u32

ctime_sec : (Statx) fn(self : Statx) -> i64

Inode CHANGE time in whole seconds — when the metadata last changed (a chmod, a rename, a link count change), not when the file was created. POSIX has no creation time in struct stat, which is why there is no btime accessor here.

Windows differs: the CRT's st_ctime is the file's CREATION time, so this reads as a birth time there. Do not use it to detect a metadata change portably.

Parameters

NameTypeNotes
selfStatx

Returns: i64

ctime_nsec : (Statx) fn(self : Statx) -> u32

Nanoseconds part of the change time, 0..999_999_999. On Windows the runtime copies the modification time's sub-second part here, since the creation time's own is tracked separately — so it does not belong to the seconds value ctime_sec returns.

Parameters

NameTypeNotes
selfStatx

Returns: u32