std::fs::sys::unix
Unix Filesystem Syscall Layer
Thin 1:1 wrappers around POSIX filesystem syscalls, returning
Result<T, Io::IoError> instead of raw errno-based error codes.
All public API lives under the Fs::Sys namespace.
Functions
| Function | Wraps | Returns |
|---|---|---|
open |
open(2) 3-arg |
Result<i32, IoError> |
close |
close(2) |
Result<void, IoError> |
read |
read(2) |
Result<i64, IoError> |
write |
write(2) |
Result<i64, IoError> |
lseek |
lseek(2) |
Result<i64, IoError> |
stat |
stat(2) |
Result<Stat, IoError> |
fstat |
fstat(2) |
Result<Stat, IoError> |
lstat |
lstat(2) |
Result<Stat, IoError> |
realpath |
realpath(3) |
Result<String, IoError> |
tempDirPath |
env/stat fallback | Result<String, IoError> |
mkdir |
mkdir(2) |
Result<void, IoError> |
unlink |
unlink(2) |
Result<void, IoError> |
rmdir |
rmdir(2) |
Result<void, IoError> |
removeDirAll |
runtime helper | Result<void, IoError> |
rename |
rename(2) |
Result<void, IoError> |
opendir |
opendir(3) |
Result<DirPtr, IoError> |
readdir |
readdir(3) |
Result<Option<SysDirEntry>, IoError> |
readdirEntry |
runtime helper | Result<boolean, IoError> |
closedir |
closedir(3) |
void |
Types
| Type | Description |
|---|---|
Stat |
File metadata: dev, ino, mode, nlink, uid, gid, size, times |
SysDirEntry |
Directory entry: name (borrowed str), ino, fileType |
Constants
| Group | Constants |
|---|---|
| Open flags | O_RDONLY, O_WRONLY, O_RDWR, O_CREAT, O_TRUNC, … |
| Seek modes | SEEK_SET, SEEK_CUR, SEEK_END |
| File type mask | S_IFMT, S_IFREG, S_IFDIR, S_IFLNK |
| Permission bits | S_IRWXU, S_IRUSR, S_IWUSR, … (user/group/other) |
| Dirent types | DT_UNKNOWN, DT_REG, DT_DIR, DT_LNK |
Design Notes
Functions that succeed without a meaningful value (close, mkdir, etc.)
return Result<void, Io::IoError> with Result::OK(()).
C Runtime Dependency
Six functions live in C (std/runtime/internal/rt_fs.c) because they
cannot be expressed in pure Ignis today:
| C function | Why C is needed |
|---|---|
ignis_stat_call |
struct stat layout is platform-dependent |
ignis_fstat_call |
same |
ignis_lstat_call |
same |
ignis_open3 |
open(2) is variadic; Ignis has no variadic calls |
ignis_readdir_call |
struct dirent layout is platform-dependent |
ignis_remove_dir_all_call |
symlink-safe recursion uses libc structs |
Everything else (read, write, close, lseek, unlink, rmdir,
rename, mkdir, opendir, closedir, readdir, realpath) calls libc
directly through Ignis extern blocks.
When @platform / @target / @feature attributes land, the C
helpers can be replaced with platform-conditional Ignis code.
Example
import Fs from "std::fs";
import Io from "std::io";
function main(): i32 {
let fd: Result<i32, Io::IoError> = Fs::Sys::open(
"/tmp/test.txt",
Fs::Sys::O_WRONLY | Fs::Sys::O_CREAT | Fs::Sys::O_TRUNC,
438, // 0o666
);
if fd.isError() { return 1; }
let rawFd: i32 = fd.unwrap();
let msg: *u8 = "hello from Ignis\n";
let n: Result<i64, Io::IoError> = Fs::Sys::write(rawFd, msg as *mut void, 17);
Fs::Sys::close(rawFd);
return 0;
}
namespace __fs_dirFunctions
function closedir(dirp: *mut void): i32POSIX closedir; closes a directory stream.
function opendir(name: *u8): *mut voidPOSIX opendir; opens a directory stream.
function readdir(dirp: *mut void): *mut voidPOSIX readdir; returns a host-owned dirent pointer or null.
namespace __fs_errnoFunctions
function strerror(errnum: i32): *u8Returns a host-owned message for an errno value.
Constants
const EACCES: i32const EAGAIN: i32const EEXIST: i32const EINTR: i32const EINVAL: i32const ENOENT: i32const ETIMEDOUT: i32namespace __fs_errno_fnFunctions
function errno_location(): *mut i32Returns the thread-local errno pointer on Linux.
namespace __fs_ioFunctions
function close(fd: i32): i32POSIX close; closes a file descriptor.
function lseek(fd: i32, offset: i64, whence: i32): i64POSIX lseek; repositions a file descriptor offset.
function mkdir(pathname: *u8, mode: u32): i32POSIX mkdir; creates one directory with mode.
function read(fd: i32, buf: *mut void, count: u64): i64POSIX read; returns bytes read, 0 on EOF, or -1.
function rename(oldpath: *u8, newpath: *u8): i32POSIX rename; renames a filesystem path.
function rmdir(pathname: *u8): i32POSIX rmdir; removes an empty directory path.
function unlink(pathname: *u8): i32POSIX unlink; removes a file path.
function write(fd: i32, buf: *mut void, count: u64): i64POSIX write; returns bytes written or -1.
Constants
const O_APPEND: i32const O_CREAT: i32const O_EXCL: i32const O_RDONLY: i32const O_RDWR: i32const O_TRUNC: i32const O_WRONLY: i32const S_IFDIR: u32const S_IFLNK: u32const S_IFMT: u32const S_IFREG: u32const S_IRGRP: u32const S_IROTH: u32const S_IRUSR: u32const S_IRWXG: u32const S_IRWXO: u32const S_IRWXU: u32const S_IWGRP: u32const S_IWOTH: u32const S_IWUSR: u32const S_IXGRP: u32const S_IXOTH: u32const S_IXUSR: u32const SEEK_CUR: i32const SEEK_END: i32const SEEK_SET: i32namespace __fs_pathFunctions
function realpath(pathname: *u8, resolvedPath: *u8): *mut u8POSIX realpath; resolves an absolute canonical path.
namespace __fs_rtFunctions
function ignis_dirent_ino(entry: *mut void): u64Returns the inode from a host dirent.
function ignis_dirent_name(entry: *mut void): *u8Returns the d_name pointer from a host dirent.
function ignis_dirent_type(entry: *mut void): u8Returns the file-type byte from a host dirent.
function ignis_fstat_call(fd: i32, outDev: &mut u64, outIno: &mut u64, outMode: &mut u32, outNlink: &mut u64, outUid: &mut u32, outGid: &mut u32, outSize: &mut i64, outAtime: &mut i64, outMtime: &mut i64, outCtime: &mut i64, outBlksize: &mut i64, outBlocks: &mut i64): i32Runtime bridge for fstat(2) with layout-independent out parameters.
function ignis_lstat_call(path: *u8, outDev: &mut u64, outIno: &mut u64, outMode: &mut u32, outNlink: &mut u64, outUid: &mut u32, outGid: &mut u32, outSize: &mut i64, outAtime: &mut i64, outMtime: &mut i64, outCtime: &mut i64, outBlksize: &mut i64, outBlocks: &mut i64): i32Runtime bridge for lstat(2) that does not follow symlinks.
function ignis_open3(pathname: *u8, flags: i32, mode: u32): i32Runtime bridge for variadic open(path, flags, mode).
function ignis_readdir_call(dirp: *mut void, outName: &mut u64, outIno: &mut u64, outType: &mut u8): i32Runtime bridge for readdir with extracted out parameters.
function ignis_remove_dir_all_call(path: *u8): i32Runtime recursive directory removal helper.
function ignis_stat_call(path: *u8, outDev: &mut u64, outIno: &mut u64, outMode: &mut u32, outNlink: &mut u64, outUid: &mut u32, outGid: &mut u32, outSize: &mut i64, outAtime: &mut i64, outMtime: &mut i64, outCtime: &mut i64, outBlksize: &mut i64, outBlocks: &mut i64): i32Runtime bridge for stat(2) with layout-independent out parameters.
namespace SysPOSIX filesystem backend used by supported Unix-like targets.
Records
record StatFile metadata returned by stat and fstat.
Fields correspond to POSIX struct stat members. Times are
seconds since the Unix epoch (tv_sec only; sub-second precision
is not exposed).
dev: u64ino: u64mode: u32nlink: u64uid: u32gid: u32size: i64atime: i64mtime: i64ctime: i64blksize: i64blocks: i64record SysDirEntrySingle entry read from a directory stream via readdir.
The name field is borrowed from the internal C dirent buffer —
valid only until the next readdir call or closedir.
name: strFile name (borrowed — valid until next readdir/closedir).
ino: u64Inode number.
fileType: u8File type hint (DT_REG, DT_DIR, etc.). 0 if unknown.
Functions
function close(fd: i32): Result<void, IoError>Closes file descriptor fd.
function closedir(dirp: *mut void): voidCloses a directory stream opened with opendir.
function fstat(fd: i32): Result<Stat, IoError>Returns file metadata for open file descriptor fd.
function lastError(): IoErrorConverts current errno into the portable Io::IoError representation.
function lseek(fd: i32, offset: i64, whence: i32): Result<i64, IoError>Repositions the file offset of fd.
whence is SEEK_SET, SEEK_CUR, or SEEK_END.
function lstat(path: str): Result<Stat, IoError>Returns file metadata for path without following symlinks.
function mkdir(path: str, mode: u32): Result<void, IoError>Creates a directory at path with the given permission mode.
function open(path: str, flags: i32, mode: u32): Result<i32, IoError>Opens path with flags and mode. Returns the fd on success.
Uses the 3-argument open(2) so mode is always available for
O_CREAT. Pass 0 for mode when not creating.
function opendir(path: str): Result<*mut void, IoError>Opens a directory stream for reading entries.
The returned DirPtr must be closed with closedir when done.
function read(fd: i32, buf: *mut void, count: u64): Result<i64, IoError>Reads up to count bytes from fd into buf.
Returns the number of bytes actually read (0 means EOF).
function readdir(dirp: *mut void): Result<Option<SysDirEntry>, IoError>Reads the next entry from a directory stream.
Returns Result::OK(Option::NONE) when the end of the directory is reached.
The returned SysDirEntry borrows its name from the internal
dirent buffer — valid only until the next readdir or closedir.
function readdirEntry(dirp: *mut void, outName: &mut u64, outIno: &mut u64, outType: &mut u8): Result<boolean, IoError>Reads the next entry from a directory stream.
function realpath(path: str): Result<String, IoError>Resolves path to an existing canonical absolute path.
function removeDirAll(path: str): Result<void, IoError>Recursively removes a directory tree without following symlink directories.
function rename(oldPath: str, newPath: str): Result<void, IoError>Renames oldPath to newPath.
function rmdir(path: str): Result<void, IoError>Removes the empty directory at path.
function stat(path: str): Result<Stat, IoError>Returns file metadata for path.
function tempDirCandidate(value: *mut u8): Option<String>Returns a temp-dir candidate only when the raw path is non-empty and a directory.
function tempDirPath(): Result<String, IoError>Returns the host temporary-directory root.
function unlink(path: str): Result<void, IoError>Removes the file at path.
function write(fd: i32, buf: *mut void, count: u64): Result<i64, IoError>Writes up to count bytes from buf to fd.
Returns the number of bytes actually written.
Constants
const DT_DIR: u8const DT_LNK: u8const DT_REG: u8const DT_UNKNOWN: u8const O_APPEND: i32const O_CREAT: i32const O_EXCL: i32const O_RDONLY: i32const O_RDWR: i32const O_TRUNC: i32const O_WRONLY: i32const S_IFDIR: u32const S_IFLNK: u32const S_IFMT: u32const S_IFREG: u32const S_IRGRP: u32const S_IROTH: u32const S_IRUSR: u32const S_IRWXG: u32const S_IRWXO: u32const S_IRWXU: u32const S_IWGRP: u32const S_IWOTH: u32const S_IWUSR: u32const S_IXGRP: u32const S_IXOTH: u32const S_IXUSR: u32const SEEK_CUR: i32const SEEK_END: i32const SEEK_SET: i32