mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 01:43:22 +00:00
Implement ioctl() FIOCLEX command
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
4823b82e41
commit
89d04ecf7d
@ -311,6 +311,10 @@ impl FileTableEntry {
|
||||
self.flags.store(flags.bits(), Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn clear_flags(&self) {
|
||||
self.flags.store(0, Ordering::Relaxed);
|
||||
}
|
||||
|
||||
pub fn register_observer(&self, epoll: Weak<dyn Observer<FdEvents>>) {
|
||||
self.subject.register_observer(epoll, ());
|
||||
}
|
||||
|
@ -27,6 +27,10 @@ pub enum IoctlCmd {
|
||||
FIONBIO = 0x5421,
|
||||
/// the calling process gives up this controlling terminal
|
||||
TIOCNOTTY = 0x5422,
|
||||
/// Clear the close on exec flag on a file descriptor
|
||||
FIONCLEX = 0x5450,
|
||||
/// Set the close on exec flag on a file descriptor
|
||||
FIOCLEX = 0x5451,
|
||||
/// Enable or disable asynchronous I/O mode.
|
||||
FIOASYNC = 0x5452,
|
||||
/// Get Pty Number
|
||||
|
@ -3,7 +3,7 @@
|
||||
use super::SyscallReturn;
|
||||
use crate::{
|
||||
fs::{
|
||||
file_table::FileDesc,
|
||||
file_table::{FdFlags, FileDesc},
|
||||
utils::{IoctlCmd, StatusFlags},
|
||||
},
|
||||
prelude::*,
|
||||
@ -39,6 +39,23 @@ pub fn sys_ioctl(fd: FileDesc, cmd: u32, arg: Vaddr, ctx: &Context) -> Result<Sy
|
||||
file.set_status_flags(flags)?;
|
||||
0
|
||||
}
|
||||
IoctlCmd::FIOCLEX => {
|
||||
// Sets the close-on-exec flag of the file.
|
||||
// Follow the implementation of fcntl()
|
||||
|
||||
let flags = FdFlags::CLOEXEC;
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let entry = file_table.get_entry(fd)?;
|
||||
entry.set_flags(flags);
|
||||
0
|
||||
}
|
||||
IoctlCmd::FIONCLEX => {
|
||||
// Clears the close-on-exec flag of the file.
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let entry = file_table.get_entry(fd)?;
|
||||
entry.clear_flags();
|
||||
0
|
||||
}
|
||||
_ => file.ioctl(ioctl_cmd, arg)?,
|
||||
};
|
||||
Ok(SyscallReturn::Return(res as _))
|
||||
|
Reference in New Issue
Block a user