mirror of
https://github.com/hexagonal-sun/moss-kernel.git
synced 2026-04-20 07:08:37 -04:00
Merge pull request #198 from arihant2math/more-fnctl
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user