Implement pseudo terminal

This commit is contained in:
Jianfeng Jiang
2023-08-01 14:35:35 +08:00
committed by Tate, Hongliang Tian
parent a042da1847
commit f802ff40c5
10 changed files with 369 additions and 107 deletions

View File

@ -9,9 +9,10 @@ use core::time::Duration;
use jinux_frame::vm::VmFrame;
use jinux_util::{id_allocator::IdAlloc, slot_vec::SlotVec};
use self::master::{PtyMaster, PtyMasterInode};
use self::master::PtyMasterInode;
use self::ptmx::Ptmx;
use self::slave::{PtySlave, PtySlaveInode};
use self::slave::PtySlaveInode;
use crate::device::PtyMaster;
mod master;
mod ptmx;
@ -60,8 +61,7 @@ impl DevPts {
.alloc()
.ok_or_else(|| Error::with_message(Errno::EIO, "cannot alloc index"))?;
let master = PtyMaster::new(index as u32, self.root.ptmx.clone());
let slave = PtySlave::new(master.clone());
let (master, slave) = PtyMaster::new_pair(index as u32, self.root.ptmx.clone())?;
let master_inode = PtyMasterInode::new(master);
let slave_inode = PtySlaveInode::new(slave, self.this.clone());
@ -73,10 +73,10 @@ impl DevPts {
/// Remove the slave from fs.
///
/// This is called when the master is being dropped.
fn remove_slave(&self, index: u32) -> Option<Arc<PtySlaveInode>> {
fn remove_slave(&self, index: usize) -> Option<Arc<PtySlaveInode>> {
let removed_slave = self.root.remove_slave(&index.to_string());
if removed_slave.is_some() {
self.index_alloc.lock().free(index as usize);
self.index_alloc.lock().free(index);
}
removed_slave
}