diff --git a/src/fs/open_file.rs b/src/fs/open_file.rs index ce005dc..c4d8560 100644 --- a/src/fs/open_file.rs +++ b/src/fs/open_file.rs @@ -53,6 +53,10 @@ impl OpenFile { self.state.lock().await.1.flags } + pub async fn set_flags(&self, flags: OpenFlags) { + self.state.lock().await.1.flags = flags; + } + pub async fn lock(&self) -> AsyncMutexGuard<'_, (Box, FileCtx)> { self.state.lock().await } diff --git a/src/process/fd_table/fcntl.rs b/src/process/fd_table/fcntl.rs index f3d08b0..8353034 100644 --- a/src/process/fd_table/fcntl.rs +++ b/src/process/fd_table/fcntl.rs @@ -1,9 +1,9 @@ -use bitflags::Flags; -use libkernel::error::{KernelError, Result}; - use super::Fd; use crate::process::fd_table::dup::dup_fd; use crate::{process::fd_table::FdFlags, sched::current::current_task_shared}; +use bitflags::Flags; +use libkernel::error::{KernelError, Result}; +use libkernel::fs::OpenFlags; const F_DUPFD: u32 = 0; // Duplicate file descriptor. const F_GETFD: u32 = 1; // Get file descriptor flags. @@ -54,7 +54,25 @@ pub async fn sys_fcntl(fd: Fd, op: u32, arg: usize) -> Result { Ok(open_fd.flags().await.bits() as _) } - F_SETFL => todo!(), + F_SETFL => { + let fl = OpenFlags::from_bits_retain(arg as _); + if fl.contains_unknown_bits() { + return Err(KernelError::InvalidValue); + } + let open_fd = { + let mut fds = task.fd_table.lock_save_irq(); + let fd = fds + .entries + .get_mut(fd.as_raw() as usize) + .and_then(|entry| entry.as_mut()) + .ok_or(KernelError::BadFd)?; + + fd.file.clone() + }; + // TODO: Ignore sync/dsync when implemented + open_fd.set_flags(fl).await; + Ok(0) + } _ => Err(KernelError::InvalidValue), } }