fstat (nr 5)
Linux Signature
int fstat(int fd, struct stat *statbuf);
Description
Returns information about a file referred to by the file descriptor fd, writing it into the stat structure at statbuf.
Current Implementation
- Zero-fills the 144-byte
struct statbuffer. - Sets
st_modeat offset 24 toS_IFCHR | 0666(character device, read/write for all), regardless of which fd is queried. - Always returns 0 (success).
This is sufficient for musl’s stdio initialisation, which calls fstat on stdout to determine whether it is a terminal.
Source: osl/src/syscalls/fs.rs — sys_fstat
Future Work
- Return different
st_modevalues depending on the fd (e.g., regular file vs. character device). - Populate other stat fields (
st_size,st_ino,st_dev, timestamps, etc.). - Return
-EBADFfor invalid file descriptors. - Validate that
statbufis a writable user-space address.