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

sys_write

Function sys_write 

Source
pub fn sys_write(_fd: u64, _data: &[u8]) -> SyscallResult<usize>
Expand description

Write data to an open file descriptor.

Writes up to data.len() bytes from the provided buffer to the file descriptor, starting at the file’s current offset (or at the end of file if O_APPEND was set). The file offset is advanced by the number of bytes written. Partial writes are possible: the kernel may write fewer bytes than requested if storage is full or for device files.

For special file descriptors: fd 1 (stdout) and fd 2 (stderr) write to the process’s standard output, which is typically the serial console in VeridianOS.

§Arguments

  • fd - File descriptor returned by a prior call to sys_open. Must be opened with at least O_WRONLY or O_RDWR access.
  • data - Byte slice containing the data to write. The kernel writes at most data.len() bytes. Must be non-empty.

§Returns

  • Ok(bytes_written) - The number of bytes actually written, which may be less than data.len() (partial write). The caller should retry with the remaining data if a partial write occurs.

§Errors

§Examples

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

// Write to a file
let fd = sys_open("/tmp/log.txt", 0x001 | 0x100).expect("open failed");
let data = b"VeridianOS kernel log entry\n";
let written = sys_write(fd, data).expect("write failed");
sys_close(fd).expect("close failed");

// Write to stdout (serial console)
let stdout_fd = 1;
sys_write(stdout_fd, b"Hello, VeridianOS!\n").expect("write to stdout failed");