Merge pull request #198 from arihant2math/more-fnctl

This commit is contained in:
Ashwin Naren
2026-02-09 13:59:40 -08:00
committed by GitHub
2 changed files with 26 additions and 4 deletions

View File

@@ -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<dyn FileOps>, FileCtx)> {
self.state.lock().await
}

View File

@@ -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<usize> {
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),
}
}