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 tosys_open. Must be opened with at leastO_WRONLYorO_RDWRaccess.data- Byte slice containing the data to write. The kernel writes at mostdata.len()bytes. Must be non-empty.
§Returns
Ok(bytes_written)- The number of bytes actually written, which may be less thandata.len()(partial write). The caller should retry with the remaining data if a partial write occurs.
§Errors
SyscallError::BadDescriptor-fdis not a valid open file descriptor.SyscallError::PermissionDenied- The file descriptor was not opened for writing.SyscallError::InvalidArgument-datahas zero length.SyscallError::IoError- An I/O error occurred writing to the underlying storage or device.SyscallError::OutOfMemory- The filesystem has no remaining free space.
§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");