⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

sys_open

Function sys_open 

Source
pub fn sys_open(_path: &str, _flags: u32) -> SyscallResult<u64>
Expand description

Open a file or directory, returning a file descriptor.

Resolves the given path through the VeridianOS VFS (Virtual File System) and returns a new file descriptor for the opened file. The file descriptor is an index into the per-process file descriptor table and is valid until closed with sys_close.

The caller must hold a capability granting access to the target file or its parent directory. The required capability rights depend on the open flags: READ for O_RDONLY, WRITE for O_WRONLY or O_RDWR, and both for O_RDWR.

§Arguments

  • path - Path to the file or directory to open. Can be absolute (starting with /) or relative to the process’s current working directory. The path is resolved through the VFS layer (RamFS, DevFS, ProcFS, or BlockFS depending on the mount point).
  • flags - Bitwise OR of open mode flags:
    • O_RDONLY (0x000) - Open for reading only.
    • O_WRONLY (0x001) - Open for writing only.
    • O_RDWR (0x002) - Open for reading and writing.
    • O_CREAT (0x100) - Create the file if it does not exist.
    • O_TRUNC (0x200) - Truncate the file to zero length if it exists.
    • O_APPEND (0x400) - Writes always append to end of file.
    • O_EXCL (0x800) - With O_CREAT, fail if the file already exists.

§Returns

  • Ok(fd) - A file descriptor (unsigned 64-bit integer) for the opened file. The descriptor is the lowest available unused fd in the process’s table.

§Errors

§Examples

use veridian_kernel::pkg::sdk::syscall_api::{sys_close, sys_open};

// Open an existing file for reading
let fd = sys_open("/etc/config.toml", 0x000).expect("open failed");

// Create a new file for writing (O_WRONLY | O_CREAT | O_TRUNC)
let fd_new = sys_open("/tmp/output.txt", 0x001 | 0x100 | 0x200).expect("create failed");

sys_close(fd).expect("close failed");
sys_close(fd_new).expect("close failed");