mirror of
https://github.com/rcore-os/rCore.git
synced 2025-01-19 01:07:05 +04:00
Refactor ioctl numbers and add FIOCLEX
This commit is contained in:
parent
6883127d5a
commit
28aaae53b9
@ -5,6 +5,7 @@ use crate::net::Socket;
|
||||
use crate::syscall::{SysError, SysResult};
|
||||
use alloc::boxed::Box;
|
||||
use rcore_fs::vfs::PollStatus;
|
||||
use super::ioctl::*;
|
||||
|
||||
// TODO: merge FileLike to FileHandle ?
|
||||
// TODO: fix dup and remove Clone
|
||||
@ -30,13 +31,19 @@ impl FileLike {
|
||||
Ok(len)
|
||||
}
|
||||
pub fn ioctl(&mut self, request: usize, arg1: usize, arg2: usize, arg3: usize) -> SysResult {
|
||||
match self {
|
||||
FileLike::File(file) => file.io_control(request as u32, arg1)?,
|
||||
FileLike::Socket(socket) => {
|
||||
socket.ioctl(request, arg1, arg2, arg3)?;
|
||||
match request {
|
||||
// TODO: place flags & path in FileLike in stead of FileHandle/Socket
|
||||
FIOCLEX => Ok(0),
|
||||
_ => {
|
||||
match self {
|
||||
FileLike::File(file) => file.io_control(request as u32, arg1)?,
|
||||
FileLike::Socket(socket) => {
|
||||
socket.ioctl(request, arg1, arg2, arg3)?;
|
||||
}
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
}
|
||||
Ok(0)
|
||||
}
|
||||
pub fn poll(&self) -> Result<PollStatus, SysError> {
|
||||
let status = match self {
|
||||
|
36
kernel/src/fs/ioctl.rs
Normal file
36
kernel/src/fs/ioctl.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// for IOR and IOW:
|
||||
// 32bits total, command in lower 16bits, size of the parameter structure in the lower 14 bits of the upper 16 bits
|
||||
// higher 2 bits: 01 = write, 10 = read
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
pub const TCGETS: usize = 0x5401;
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub const TCGETS: usize = 0x540D;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
pub const TIOCGPGRP: usize = 0x540F;
|
||||
// _IOR('t', 119, int)
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub const TIOCGPGRP: usize = 0x4_004_74_77;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
pub const TIOCSPGRP: usize = 0x5410;
|
||||
// _IOW('t', 118, int)
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub const TIOCSPGRP: usize = 0x8_004_74_76;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
pub const TIOCGWINSZ: usize = 0x5413;
|
||||
// _IOR('t', 104, struct winsize)
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub const TIOCGWINSZ: usize = 0x4_008_74_68;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
pub const FIONCLEX: usize = 0x5450;
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub const FIOCLEX: usize = 0x6602;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
pub const FIOCLEX: usize = 0x5451;
|
||||
#[cfg(target_arch = "mips")]
|
||||
pub const FIOCLEX: usize = 0x6601;
|
@ -18,6 +18,7 @@ mod file_like;
|
||||
mod pipe;
|
||||
mod pseudo;
|
||||
mod stdio;
|
||||
mod ioctl;
|
||||
|
||||
/// Hard link user programs
|
||||
#[cfg(feature = "link_user")]
|
||||
@ -48,8 +49,8 @@ lazy_static! {
|
||||
.clone()
|
||||
);
|
||||
// enable block cache
|
||||
// Arc::new(BlockCache::new(driver, 0x100))
|
||||
Arc::new(driver)
|
||||
Arc::new(BlockCache::new(driver, 0x100))
|
||||
// Arc::new(driver)
|
||||
}
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
{
|
||||
|
@ -7,6 +7,7 @@ use rcore_fs::vfs::*;
|
||||
|
||||
use crate::sync::Condvar;
|
||||
use crate::sync::SpinNoIrqLock as Mutex;
|
||||
use super::ioctl::*;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Stdin {
|
||||
@ -52,32 +53,6 @@ lazy_static! {
|
||||
pub static ref STDOUT: Arc<Stdout> = Arc::new(Stdout::default());
|
||||
}
|
||||
|
||||
// 32bits total, command in lower 16bits, size of the parameter structure in the lower 14 bits of the upper 16 bits
|
||||
// higher 2 bits: 01 = write, 10 = read
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
const TCGETS: u32 = 0x5401;
|
||||
#[cfg(target_arch = "mips")]
|
||||
const TCGETS: u32 = 0x540D;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
const TIOCGPGRP: u32 = 0x540F;
|
||||
// _IOR('t', 119, int)
|
||||
#[cfg(target_arch = "mips")]
|
||||
const TIOCGPGRP: u32 = 0x4_004_74_77;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
const TIOCSPGRP: u32 = 0x5410;
|
||||
// _IOW('t', 118, int)
|
||||
#[cfg(target_arch = "mips")]
|
||||
const TIOCSPGRP: u32 = 0x8_004_74_76;
|
||||
|
||||
#[cfg(not(target_arch = "mips"))]
|
||||
const TIOCGWINSZ: u32 = 0x5413;
|
||||
// _IOR('t', 104, struct winsize)
|
||||
#[cfg(target_arch = "mips")]
|
||||
const TIOCGWINSZ: u32 = 0x4_008_74_68;
|
||||
|
||||
// TODO: better way to provide default impl?
|
||||
macro_rules! impl_inode {
|
||||
() => {
|
||||
@ -93,7 +68,7 @@ macro_rules! impl_inode {
|
||||
fn find(&self, _name: &str) -> Result<Arc<INode>> { Err(FsError::NotDir) }
|
||||
fn get_entry(&self, _id: usize) -> Result<String> { Err(FsError::NotDir) }
|
||||
fn io_control(&self, cmd: u32, data: usize) -> Result<()> {
|
||||
match cmd {
|
||||
match cmd as usize {
|
||||
TCGETS | TIOCGWINSZ | TIOCSPGRP => {
|
||||
// pretend to be tty
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user