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

sys_close

Function sys_close 

Source
pub fn sys_close(_fd: u64) -> SyscallResult<()>
Expand description

Close an open file descriptor, releasing associated resources.

Releases the file descriptor so it can be reused by subsequent calls to sys_open or other fd-allocating syscalls. If this is the last file descriptor referring to the underlying file description, the file description is also released and any pending writes are flushed.

Closing a file descriptor that has already been closed is an error. Closing an fd does not guarantee data has been persisted to disk; use a sync operation for durability guarantees.

§Arguments

  • fd - File descriptor to close. Must be a valid, currently open descriptor in the process’s file descriptor table.

§Returns

  • Ok(()) on successful close.

§Errors

§Examples

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

let fd = sys_open("/etc/motd", 0x000).expect("open failed");
// ... use the file descriptor ...
sys_close(fd).expect("close failed");

// Attempting to close again would return BadDescriptor
let result = sys_close(fd);
assert!(result.is_err());