Refine Devpts with new metadata api

This commit is contained in:
LI Qing
2024-05-24 10:33:38 +08:00
committed by Tate, Hongliang Tian
parent 494c88e993
commit ce2e0cee92
3 changed files with 9 additions and 10 deletions

View File

@ -41,18 +41,17 @@ const MAX_PTY_NUM: usize = 4096;
/// ///
/// Actually, the "/dev/ptmx" is a symlink to the real device at "/dev/pts/ptmx". /// Actually, the "/dev/ptmx" is a symlink to the real device at "/dev/pts/ptmx".
pub struct DevPts { pub struct DevPts {
root: Arc<RootInode>,
sb: SuperBlock, sb: SuperBlock,
root: Arc<RootInode>,
index_alloc: Mutex<IdAlloc>, index_alloc: Mutex<IdAlloc>,
this: Weak<Self>, this: Weak<Self>,
} }
impl DevPts { impl DevPts {
pub fn new() -> Arc<Self> { pub fn new() -> Arc<Self> {
let sb = SuperBlock::new(DEVPTS_MAGIC, BLOCK_SIZE, NAME_MAX);
Arc::new_cyclic(|weak_self| Self { Arc::new_cyclic(|weak_self| Self {
root: RootInode::new(weak_self.clone(), &sb), sb: SuperBlock::new(DEVPTS_MAGIC, BLOCK_SIZE, NAME_MAX),
sb, root: RootInode::new(weak_self.clone()),
index_alloc: Mutex::new(IdAlloc::with_capacity(MAX_PTY_NUM)), index_alloc: Mutex::new(IdAlloc::with_capacity(MAX_PTY_NUM)),
this: weak_self.clone(), this: weak_self.clone(),
}) })
@ -112,14 +111,14 @@ struct RootInode {
} }
impl RootInode { impl RootInode {
pub fn new(fs: Weak<DevPts>, sb: &SuperBlock) -> Arc<Self> { pub fn new(fs: Weak<DevPts>) -> Arc<Self> {
Arc::new(Self { Arc::new(Self {
ptmx: Ptmx::new(sb, fs.clone()), ptmx: Ptmx::new(fs.clone()),
slaves: RwLock::new(SlotVec::new()), slaves: RwLock::new(SlotVec::new()),
metadata: RwLock::new(Metadata::new_dir( metadata: RwLock::new(Metadata::new_dir(
ROOT_INO, ROOT_INO,
InodeMode::from_bits_truncate(0o755), InodeMode::from_bits_truncate(0o755),
sb, BLOCK_SIZE,
)), )),
fs, fs,
}) })

View File

@ -24,13 +24,13 @@ pub struct Ptmx {
struct Inner(Weak<DevPts>); struct Inner(Weak<DevPts>);
impl Ptmx { impl Ptmx {
pub fn new(sb: &SuperBlock, fs: Weak<DevPts>) -> Arc<Self> { pub fn new(fs: Weak<DevPts>) -> Arc<Self> {
let inner = Inner(fs); let inner = Inner(fs);
Arc::new(Self { Arc::new(Self {
metadata: RwLock::new(Metadata::new_device( metadata: RwLock::new(Metadata::new_device(
PTMX_INO, PTMX_INO,
InodeMode::from_bits_truncate(0o666), InodeMode::from_bits_truncate(0o666),
sb, super::BLOCK_SIZE,
&inner, &inner,
)), )),
inner, inner,

View File

@ -24,7 +24,7 @@ impl PtySlaveInode {
metadata: RwLock::new(Metadata::new_device( metadata: RwLock::new(Metadata::new_device(
device.index() as usize + FIRST_SLAVE_INO, device.index() as usize + FIRST_SLAVE_INO,
InodeMode::from_bits_truncate(0o620), InodeMode::from_bits_truncate(0o620),
&fs.upgrade().unwrap().sb(), super::BLOCK_SIZE,
device.as_ref(), device.as_ref(),
)), )),
device, device,