Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

实现pty,附带测试程序 #685

Merged
merged 5 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions kernel/src/driver/base/device/device_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ impl Major {
/// /dev/fb* framebuffers
pub const FB_MAJOR: Self = Self::new(29);

/// Pty
pub const UNIX98_PTY_MASTER_MAJOR: Self = Self::new(128);
pub const UNIX98_PTY_MAJOR_COUNT: Self = Self::new(8);
pub const UNIX98_PTY_SLAVE_MAJOR: Self =
Self::new(Self::UNIX98_PTY_MASTER_MAJOR.0 + Self::UNIX98_PTY_MAJOR_COUNT.0);

pub const fn new(x: u32) -> Self {
Major(x)
}
Expand Down
17 changes: 11 additions & 6 deletions kernel/src/driver/disk/ahci/ahci_inode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::filesystem::vfs::syscall::ModeType;
use crate::filesystem::vfs::{
core::generate_inode_id, FilePrivateData, FileSystem, FileType, IndexNode, Metadata,
};
use crate::libs::spinlock::SpinLockGuard;
use crate::{libs::spinlock::SpinLock, time::TimeSpec};
use alloc::{
string::String,
Expand Down Expand Up @@ -76,11 +77,15 @@ impl IndexNode for LockedAhciInode {
self
}

fn open(&self, _data: &mut FilePrivateData, _mode: &FileMode) -> Result<(), SystemError> {
fn open(
&self,
_data: SpinLockGuard<FilePrivateData>,
_mode: &FileMode,
) -> Result<(), SystemError> {
Err(SystemError::EOPNOTSUPP_OR_ENOTSUP)
}

fn close(&self, _data: &mut FilePrivateData) -> Result<(), SystemError> {
fn close(&self, _data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
Err(SystemError::EOPNOTSUPP_OR_ENOTSUP)
}

Expand Down Expand Up @@ -114,13 +119,13 @@ impl IndexNode for LockedAhciInode {
offset: usize, // lba地址
len: usize,
buf: &mut [u8],
data: &mut FilePrivateData,
data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
if buf.len() < len {
return Err(SystemError::EINVAL);
}

if let FilePrivateData::Unused = data {
if let FilePrivateData::Unused = *data {
return self.0.lock().disk.read_at_bytes(offset, len, buf);
}

Expand All @@ -133,13 +138,13 @@ impl IndexNode for LockedAhciInode {
offset: usize, // lba地址
len: usize,
buf: &[u8],
data: &mut FilePrivateData,
data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
if buf.len() < len {
return Err(SystemError::EINVAL);
}

if let FilePrivateData::Unused = data {
if let FilePrivateData::Unused = *data {
return self.0.lock().disk.write_at_bytes(offset, len, buf);
}

Expand Down
10 changes: 5 additions & 5 deletions kernel/src/driver/input/ps2_mouse/ps_mouse_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use crate::{
},
libs::{
rwlock::{RwLockReadGuard, RwLockWriteGuard},
spinlock::SpinLock,
spinlock::{SpinLock, SpinLockGuard},
},
time::TimeSpec,
};
Expand Down Expand Up @@ -587,15 +587,15 @@ impl DeviceINode for Ps2MouseDevice {
impl IndexNode for Ps2MouseDevice {
fn open(
&self,
_data: &mut FilePrivateData,
_data: SpinLockGuard<FilePrivateData>,
_mode: &crate::filesystem::vfs::file::FileMode,
) -> Result<(), SystemError> {
let mut guard = self.inner.lock_irqsave();
guard.buf.clear();
Ok(())
}

fn close(&self, _data: &mut FilePrivateData) -> Result<(), SystemError> {
fn close(&self, _data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
let mut guard = self.inner.lock_irqsave();
guard.buf.clear();
Ok(())
Expand All @@ -606,7 +606,7 @@ impl IndexNode for Ps2MouseDevice {
_offset: usize,
_len: usize,
buf: &mut [u8],
_data: &mut FilePrivateData,
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
let mut guard = self.inner.lock_irqsave();

Expand All @@ -625,7 +625,7 @@ impl IndexNode for Ps2MouseDevice {
_offset: usize,
_len: usize,
_buf: &[u8],
_data: &mut FilePrivateData,
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
return Err(SystemError::EOPNOTSUPP_OR_ENOTSUP);
}
Expand Down
18 changes: 13 additions & 5 deletions kernel/src/driver/keyboard/ps2_keyboard.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ use crate::{
},
},
init::initcall::INITCALL_DEVICE,
libs::{keyboard_parser::TypeOneFSM, rwlock::RwLock, spinlock::SpinLock},
libs::{
keyboard_parser::TypeOneFSM,
rwlock::RwLock,
spinlock::{SpinLock, SpinLockGuard},
},
time::TimeSpec,
};
use system_error::SystemError;
Expand Down Expand Up @@ -115,7 +119,7 @@ impl IndexNode for LockedPS2KeyBoardInode {
_offset: usize,
_len: usize,
_buf: &mut [u8],
_data: &mut FilePrivateData,
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
return Err(SystemError::ENOSYS);
}
Expand All @@ -125,16 +129,20 @@ impl IndexNode for LockedPS2KeyBoardInode {
_offset: usize,
_len: usize,
_buf: &[u8],
_data: &mut FilePrivateData,
_data: SpinLockGuard<FilePrivateData>,
) -> Result<usize, SystemError> {
return Err(SystemError::ENOSYS);
}

fn open(&self, _data: &mut FilePrivateData, _mode: &FileMode) -> Result<(), SystemError> {
fn open(
&self,
_data: SpinLockGuard<FilePrivateData>,
_mode: &FileMode,
) -> Result<(), SystemError> {
return Ok(());
}

fn close(&self, _data: &mut FilePrivateData) -> Result<(), SystemError> {
fn close(&self, _data: SpinLockGuard<FilePrivateData>) -> Result<(), SystemError> {
return Ok(());
}

Expand Down
8 changes: 7 additions & 1 deletion kernel/src/driver/tty/kthread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use kdepends::thingbuf::StaticThingBuf;

use crate::{
arch::sched::sched,
driver::tty::virtual_terminal::virtual_console::CURRENT_VCNUM,
process::{
kthread::{KernelThreadClosure, KernelThreadMechanism},
ProcessControlBlock, ProcessFlags,
Expand Down Expand Up @@ -54,7 +55,12 @@ fn tty_refresh_thread() -> i32 {
*item = KEYBUF.pop().unwrap();
}

let _ = current_tty_port().receive_buf(&data[0..to_dequeue], &[], to_dequeue);
if CURRENT_VCNUM.load(core::sync::atomic::Ordering::SeqCst) != -1 {
let _ = current_tty_port().receive_buf(&data[0..to_dequeue], &[], to_dequeue);
} else {
// 这里由于stdio未初始化,所以无法找到port
// TODO: 考虑改用双端队列,能够将丢失的输入插回
}
}
}

Expand Down
1 change: 1 addition & 0 deletions kernel/src/driver/tty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use alloc::vec::Vec;

pub mod console;
pub mod kthread;
pub mod pty;
mod sysfs;
pub mod termios;
pub mod tty_core;
Expand Down
Loading
Loading