Move `Pipe` from `InodeImpl` to `Inode`

This commit is contained in:
Ruihan Li 2026-01-06 23:51:42 +08:00 committed by Jianfeng Jiang
parent 91604c7b51
commit 922b204280
3 changed files with 23 additions and 25 deletions

View File

@ -148,7 +148,11 @@ impl Inode for Ext2Inode {
Some(device.open()) Some(device.open())
} }
InodeType::NamedPipe => Some(self.open_named_pipe(access_mode, status_flags)), InodeType::NamedPipe => {
let pipe = self.named_pipe().unwrap();
Some(pipe.open_named(access_mode, status_flags))
}
_ => None, _ => None,
} }
} }

View File

@ -20,12 +20,11 @@ use super::{
}; };
use crate::{ use crate::{
fs::{ fs::{
inode_handle::FileIo,
path::{is_dot, is_dot_or_dotdot, is_dotdot}, path::{is_dot, is_dot_or_dotdot, is_dotdot},
pipe::Pipe, pipe::Pipe,
utils::{ utils::{
AccessMode, Extension, FallocMode, Inode as _, InodeMode, Metadata, Permission, Extension, FallocMode, Inode as _, InodeMode, Metadata, Permission, XattrName,
StatusFlags, XattrName, XattrNamespace, XattrSetFlags, XattrNamespace, XattrSetFlags,
}, },
}, },
process::{Gid, Uid, posix_thread::AsPosixThread}, process::{Gid, Uid, posix_thread::AsPosixThread},
@ -41,6 +40,9 @@ pub const MAX_FAST_SYMLINK_LEN: usize = MAX_BLOCK_PTRS * BID_SIZE;
pub struct Inode { pub struct Inode {
ino: u32, ino: u32,
type_: InodeType, type_: InodeType,
// This corresponds to the `i_pipe` field in `struct inode` in Linux.
// Reference: <https://elixir.bootlin.com/linux/v6.17/source/include/linux/fs.h#L771>.
named_pipe: Option<Box<Pipe>>,
block_group_idx: usize, block_group_idx: usize,
inner: RwMutex<InodeInner>, inner: RwMutex<InodeInner>,
fs: Weak<Ext2>, fs: Weak<Ext2>,
@ -58,6 +60,11 @@ impl Inode {
Arc::new_cyclic(|weak_self| Self { Arc::new_cyclic(|weak_self| Self {
ino, ino,
type_: desc.type_, type_: desc.type_,
named_pipe: if desc.type_ == InodeType::NamedPipe {
Some(Box::new(Pipe::new()))
} else {
None
},
block_group_idx, block_group_idx,
xattr: desc xattr: desc
.acl .acl
@ -76,6 +83,10 @@ impl Inode {
self.type_ self.type_
} }
pub(super) fn named_pipe(&self) -> Option<&Pipe> {
self.named_pipe.as_deref()
}
pub(super) fn block_group_idx(&self) -> usize { pub(super) fn block_group_idx(&self) -> usize {
self.block_group_idx self.block_group_idx
} }
@ -683,16 +694,6 @@ impl Inode {
inner.device_id() inner.device_id()
} }
pub(super) fn open_named_pipe(
&self,
access_mode: AccessMode,
status_flags: StatusFlags,
) -> Result<Box<dyn FileIo>> {
let inner = self.inner.read();
let named_pipe = inner.named_pipe.as_ref().unwrap();
named_pipe.open_named(access_mode, status_flags)
}
pub fn read_at(&self, offset: usize, writer: &mut VmWriter) -> Result<usize> { pub fn read_at(&self, offset: usize, writer: &mut VmWriter) -> Result<usize> {
if self.type_ != InodeType::File { if self.type_ != InodeType::File {
return_errno!(Errno::EISDIR); return_errno!(Errno::EISDIR);
@ -965,19 +966,11 @@ fn write_lock_multiple_inodes(inodes: Vec<&Inode>) -> Vec<RwMutexWriteGuard<'_,
struct InodeInner { struct InodeInner {
inode_impl: InodeImpl, inode_impl: InodeImpl,
page_cache: PageCache, page_cache: PageCache,
// This corresponds to the `i_pipe` field in `struct inode` in Linux.
// Reference: <https://elixir.bootlin.com/linux/v6.17/source/include/linux/fs.h#L771>.
named_pipe: Option<Pipe>,
} }
impl InodeInner { impl InodeInner {
pub fn new(desc: Dirty<InodeDesc>, weak_self: Weak<Inode>, fs: Weak<Ext2>) -> Self { pub fn new(desc: Dirty<InodeDesc>, weak_self: Weak<Inode>, fs: Weak<Ext2>) -> Self {
let num_page_bytes = desc.num_page_bytes(); let num_page_bytes = desc.num_page_bytes();
let named_pipe = if desc.type_ == InodeType::NamedPipe {
Some(Pipe::new())
} else {
None
};
let inode_impl = InodeImpl::new(desc, weak_self, fs); let inode_impl = InodeImpl::new(desc, weak_self, fs);
Self { Self {
page_cache: PageCache::with_capacity( page_cache: PageCache::with_capacity(
@ -986,7 +979,6 @@ impl InodeInner {
) )
.unwrap(), .unwrap(),
inode_impl, inode_impl,
named_pipe,
} }
} }

View File

@ -1,2 +1,4 @@
# TODO: Support pipe file in ext2 filesystem. # Nothing here. Pipe files are supported by the ext2 file system.
* #
# This file is kept to ensure that the `blocklists.ext2` directory
# is not empty, as it may become useful in the future.