Skip to main content

os/syscall/
fs.rs

1//! File and filesystem-related syscalls
2
3use crate::mm::translated_byte_buffer;
4use crate::task::current_user_token;
5
6const FD_STDOUT: usize = 1;
7
8/// write buf of length `len`  to a file with `fd`
9pub fn sys_write(fd: usize, buf: *const u8, len: usize) -> isize {
10    match fd {
11        FD_STDOUT => {
12            let buffers = translated_byte_buffer(current_user_token(), buf, len);
13            for buffer in buffers {
14                print!("{}", core::str::from_utf8(buffer).unwrap());
15            }
16            len as isize
17        }
18        _ => {
19            panic!("Unsupported fd in sys_write!");
20        }
21    }
22}