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)- WithO_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
SyscallError::NotFound- The file does not exist andO_CREATwas not specified, or a path component does not exist.SyscallError::PermissionDenied- The caller lacks the required capability for the requested access mode.SyscallError::AlreadyExists-O_CREAT | O_EXCLwas specified and the file already exists.SyscallError::InvalidArgument- The path is empty, contains null bytes, orflagscontains an invalid combination.SyscallError::IoError- An I/O error occurred accessing the underlying storage.
§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");