Module sys/statx
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
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
| Name | Type | Description |
|---|---|---|
_buf_ptr | *(u8) | |
_buf_size | usize |
impl(Statx, ...)
is_file : (Statx) fn(self : Statx) -> boolWhether this is a regular file — S_ISREG, i.e. mode & S_IFMT == S_IFREG. Sockets, FIFOs and devices are all false.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: bool
is_directory : (Statx) fn(self : Statx) -> boolis_symlink : (Statx) fn(self : Statx) -> boolWhether this is a symbolic link — S_ISLNK.
This can only ever be true if the stat did NOT follow the link, i.e.
the call was made with AT_SYMLINK_NOFOLLOW. A plain statx resolves
the link and reports its target, so it answers false for a symlink.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: bool
size : (Statx) fn(self : Statx) -> i64Size 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: i64
mode : (Statx) fn(self : Statx) -> u32The 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u32
uid : (Statx) fn(self : Statx) -> u32Owning user id. 0 on Windows, which has no numeric uid — the CRT's
_stat64 zeroes the field rather than mapping a SID.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u32
gid : (Statx) fn(self : Statx) -> u32Owning group id. 0 on Windows, for the same reason as uid.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u32
ino : (Statx) fn(self : Statx) -> u64Inode 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u64
nlink : (Statx) fn(self : Statx) -> u64Number of hard links. A directory counts 2 plus its subdirectories on most POSIX filesystems; a file with no other names counts 1, and 0 means the file has been unlinked while this descriptor kept it alive.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u64
mtime_sec : (Statx) fn(self : Statx) -> i64Modification 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: i64
mtime_nsec : (Statx) fn(self : Statx) -> u32Nanoseconds 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u32
atime_sec : (Statx) fn(self : Statx) -> i64Access 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: i64
atime_nsec : (Statx) fn(self : Statx) -> u32Nanoseconds part of the access time, 0..999_999_999.
Parameters
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u32
ctime_sec : (Statx) fn(self : Statx) -> i64Inode 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: i64
ctime_nsec : (Statx) fn(self : Statx) -> u32Nanoseconds 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
| Name | Type | Notes |
|---|---|---|
self | Statx |
Returns: u32