1f678331aShanjiezhou use crate::{ 2f678331aShanjiezhou arch::{sched::sched, CurrentIrqArch}, 3f678331aShanjiezhou exception::InterruptArch, 4f678331aShanjiezhou filesystem::vfs::{ 56b4e7a29SLoGin core::generate_inode_id, file::FileMode, syscall::ModeType, FilePrivateData, FileSystem, 640609970SGnoCiYeH FileType, IndexNode, Metadata, 7f678331aShanjiezhou }, 8f678331aShanjiezhou libs::{spinlock::SpinLock, wait_queue::WaitQueue}, 95e948c56SGnoCiYeH net::event_poll::{EPollEventType, EPollItem, EventPoll}, 101496ba7bSLoGin process::ProcessState, 11f678331aShanjiezhou time::TimeSpec, 12f678331aShanjiezhou }; 13f678331aShanjiezhou 145e948c56SGnoCiYeH use alloc::{ 155e948c56SGnoCiYeH collections::LinkedList, 165e948c56SGnoCiYeH sync::{Arc, Weak}, 175e948c56SGnoCiYeH }; 1891e9d4abSLoGin use system_error::SystemError; 19f678331aShanjiezhou 20f678331aShanjiezhou /// 我们设定pipe_buff的总大小为1024字节 21f678331aShanjiezhou const PIPE_BUFF_SIZE: usize = 1024; 22f678331aShanjiezhou 23876cb89eSGnoCiYeH #[derive(Debug, Clone)] 24876cb89eSGnoCiYeH pub struct PipeFsPrivateData { 25876cb89eSGnoCiYeH mode: FileMode, 26876cb89eSGnoCiYeH } 27876cb89eSGnoCiYeH 28876cb89eSGnoCiYeH impl PipeFsPrivateData { 29876cb89eSGnoCiYeH pub fn new(mode: FileMode) -> Self { 304ad52e57S裕依2439 return PipeFsPrivateData { mode }; 31876cb89eSGnoCiYeH } 325e948c56SGnoCiYeH 335e948c56SGnoCiYeH pub fn set_mode(&mut self, mode: FileMode) { 345e948c56SGnoCiYeH self.mode = mode; 355e948c56SGnoCiYeH } 36876cb89eSGnoCiYeH } 37876cb89eSGnoCiYeH 38f678331aShanjiezhou /// @brief 管道文件i节点(锁) 39f678331aShanjiezhou #[derive(Debug)] 40f678331aShanjiezhou pub struct LockedPipeInode(SpinLock<InnerPipeInode>); 41f678331aShanjiezhou 42f678331aShanjiezhou /// @brief 管道文件i节点(无锁) 43f678331aShanjiezhou #[derive(Debug)] 44f678331aShanjiezhou pub struct InnerPipeInode { 45f678331aShanjiezhou self_ref: Weak<LockedPipeInode>, 465e948c56SGnoCiYeH /// 管道内可读的数据数 47f678331aShanjiezhou valid_cnt: i32, 48f678331aShanjiezhou read_pos: i32, 49f678331aShanjiezhou write_pos: i32, 50f678331aShanjiezhou read_wait_queue: WaitQueue, 51f678331aShanjiezhou write_wait_queue: WaitQueue, 52f678331aShanjiezhou data: [u8; PIPE_BUFF_SIZE], 53f678331aShanjiezhou /// INode 元数据 54f678331aShanjiezhou metadata: Metadata, 55876cb89eSGnoCiYeH reader: u32, 56876cb89eSGnoCiYeH writer: u32, 575e948c56SGnoCiYeH epitems: SpinLock<LinkedList<Arc<EPollItem>>>, 585e948c56SGnoCiYeH } 595e948c56SGnoCiYeH 605e948c56SGnoCiYeH impl InnerPipeInode { 615e948c56SGnoCiYeH pub fn poll(&self, private_data: &FilePrivateData) -> Result<usize, SystemError> { 625e948c56SGnoCiYeH let mut events = EPollEventType::empty(); 635e948c56SGnoCiYeH 645e948c56SGnoCiYeH let mode = if let FilePrivateData::Pipefs(PipeFsPrivateData { mode }) = private_data { 655e948c56SGnoCiYeH mode 665e948c56SGnoCiYeH } else { 675e948c56SGnoCiYeH return Err(SystemError::EBADFD); 685e948c56SGnoCiYeH }; 695e948c56SGnoCiYeH 705e948c56SGnoCiYeH if mode.contains(FileMode::O_RDONLY) { 715e948c56SGnoCiYeH if self.valid_cnt != 0 { 725e948c56SGnoCiYeH // 有数据可读 735e948c56SGnoCiYeH events.insert(EPollEventType::EPOLLIN & EPollEventType::EPOLLRDNORM); 745e948c56SGnoCiYeH } 755e948c56SGnoCiYeH 765e948c56SGnoCiYeH // 没有写者 775e948c56SGnoCiYeH if self.writer == 0 { 785e948c56SGnoCiYeH events.insert(EPollEventType::EPOLLHUP) 795e948c56SGnoCiYeH } 805e948c56SGnoCiYeH } 815e948c56SGnoCiYeH 825e948c56SGnoCiYeH if mode.contains(FileMode::O_WRONLY) { 835e948c56SGnoCiYeH // 管道内数据未满 845e948c56SGnoCiYeH if self.valid_cnt as usize != PIPE_BUFF_SIZE { 855e948c56SGnoCiYeH events.insert(EPollEventType::EPOLLIN & EPollEventType::EPOLLWRNORM); 865e948c56SGnoCiYeH } 875e948c56SGnoCiYeH 885e948c56SGnoCiYeH // 没有读者 895e948c56SGnoCiYeH if self.reader == 0 { 905e948c56SGnoCiYeH events.insert(EPollEventType::EPOLLERR); 915e948c56SGnoCiYeH } 925e948c56SGnoCiYeH } 935e948c56SGnoCiYeH 945e948c56SGnoCiYeH Ok(events.bits() as usize) 955e948c56SGnoCiYeH } 965e948c56SGnoCiYeH 975e948c56SGnoCiYeH pub fn add_epoll(&mut self, epitem: Arc<EPollItem>) -> Result<(), SystemError> { 985e948c56SGnoCiYeH self.epitems.lock().push_back(epitem); 995e948c56SGnoCiYeH Ok(()) 1005e948c56SGnoCiYeH } 101f678331aShanjiezhou } 102f678331aShanjiezhou 103f678331aShanjiezhou impl LockedPipeInode { 104876cb89eSGnoCiYeH pub fn new() -> Arc<Self> { 105f678331aShanjiezhou let inner = InnerPipeInode { 106f678331aShanjiezhou self_ref: Weak::default(), 107f678331aShanjiezhou valid_cnt: 0, 108f678331aShanjiezhou read_pos: 0, 109f678331aShanjiezhou write_pos: 0, 110*b5b571e0SLoGin read_wait_queue: WaitQueue::default(), 111*b5b571e0SLoGin write_wait_queue: WaitQueue::default(), 112f678331aShanjiezhou data: [0; PIPE_BUFF_SIZE], 113f678331aShanjiezhou 114f678331aShanjiezhou metadata: Metadata { 115f678331aShanjiezhou dev_id: 0, 116f678331aShanjiezhou inode_id: generate_inode_id(), 11722c9db31Shanjiezhou size: PIPE_BUFF_SIZE as i64, 118f678331aShanjiezhou blk_size: 0, 119f678331aShanjiezhou blocks: 0, 120f678331aShanjiezhou atime: TimeSpec::default(), 121f678331aShanjiezhou mtime: TimeSpec::default(), 122f678331aShanjiezhou ctime: TimeSpec::default(), 123f678331aShanjiezhou file_type: FileType::Pipe, 1246b4e7a29SLoGin mode: ModeType::from_bits_truncate(0o666), 125f678331aShanjiezhou nlinks: 1, 126f678331aShanjiezhou uid: 0, 127f678331aShanjiezhou gid: 0, 12802343d0bSLoGin raw_dev: Default::default(), 129f678331aShanjiezhou }, 130876cb89eSGnoCiYeH reader: 0, 131876cb89eSGnoCiYeH writer: 0, 1325e948c56SGnoCiYeH epitems: SpinLock::new(LinkedList::new()), 133f678331aShanjiezhou }; 134f678331aShanjiezhou let result = Arc::new(Self(SpinLock::new(inner))); 135f678331aShanjiezhou let mut guard = result.0.lock(); 136f678331aShanjiezhou guard.self_ref = Arc::downgrade(&result); 137f678331aShanjiezhou // 释放锁 138f678331aShanjiezhou drop(guard); //这一步其实不需要,只要离开作用域,guard生命周期结束,自会解锁 139f678331aShanjiezhou return result; 140f678331aShanjiezhou } 1415e948c56SGnoCiYeH 1425e948c56SGnoCiYeH pub fn inner(&self) -> &SpinLock<InnerPipeInode> { 1435e948c56SGnoCiYeH &self.0 1445e948c56SGnoCiYeH } 145f678331aShanjiezhou } 146f678331aShanjiezhou 147f678331aShanjiezhou impl IndexNode for LockedPipeInode { 148f678331aShanjiezhou fn read_at( 149f678331aShanjiezhou &self, 150f678331aShanjiezhou _offset: usize, 151f678331aShanjiezhou len: usize, 152f678331aShanjiezhou buf: &mut [u8], 153876cb89eSGnoCiYeH data: &mut FilePrivateData, 15491e9d4abSLoGin ) -> Result<usize, SystemError> { 155876cb89eSGnoCiYeH // 获取mode 156876cb89eSGnoCiYeH let mode: FileMode; 157876cb89eSGnoCiYeH if let FilePrivateData::Pipefs(pdata) = data { 158876cb89eSGnoCiYeH mode = pdata.mode; 159876cb89eSGnoCiYeH } else { 160876cb89eSGnoCiYeH return Err(SystemError::EBADF); 161876cb89eSGnoCiYeH } 162876cb89eSGnoCiYeH 163f678331aShanjiezhou if buf.len() < len { 164f678331aShanjiezhou return Err(SystemError::EINVAL); 165f678331aShanjiezhou } 166f678331aShanjiezhou // 加锁 167f678331aShanjiezhou let mut inode = self.0.lock(); 168f678331aShanjiezhou 169f678331aShanjiezhou // 如果管道里面没有数据,则唤醒写端, 170f678331aShanjiezhou while inode.valid_cnt == 0 { 171876cb89eSGnoCiYeH // 如果当前管道写者数为0,则返回EOF 172876cb89eSGnoCiYeH if inode.writer == 0 { 173876cb89eSGnoCiYeH return Ok(0); 174876cb89eSGnoCiYeH } 175876cb89eSGnoCiYeH 1761496ba7bSLoGin inode 1771496ba7bSLoGin .write_wait_queue 1781496ba7bSLoGin .wakeup(Some(ProcessState::Blocked(true))); 1791496ba7bSLoGin 18022c9db31Shanjiezhou // 如果为非阻塞管道,直接返回错误 181876cb89eSGnoCiYeH if mode.contains(FileMode::O_NONBLOCK) { 18222c9db31Shanjiezhou drop(inode); 18322c9db31Shanjiezhou return Err(SystemError::EAGAIN_OR_EWOULDBLOCK); 18422c9db31Shanjiezhou } 1851496ba7bSLoGin 18622c9db31Shanjiezhou // 否则在读等待队列中睡眠,并释放锁 187f678331aShanjiezhou unsafe { 188f678331aShanjiezhou let irq_guard = CurrentIrqArch::save_and_disable_irq(); 189bf4a4899SLoGin 190f678331aShanjiezhou inode.read_wait_queue.sleep_without_schedule(); 191f678331aShanjiezhou drop(inode); 192f678331aShanjiezhou 193f678331aShanjiezhou drop(irq_guard); 194f678331aShanjiezhou } 195f678331aShanjiezhou sched(); 196f678331aShanjiezhou inode = self.0.lock(); 197f678331aShanjiezhou } 198f678331aShanjiezhou 199f678331aShanjiezhou let mut num = inode.valid_cnt as usize; 200f678331aShanjiezhou //决定要输出的字节 201f678331aShanjiezhou let start = inode.read_pos as usize; 202f678331aShanjiezhou //如果读端希望读取的字节数大于有效字节数,则输出有效字节 203f678331aShanjiezhou let mut end = (inode.valid_cnt as usize + inode.read_pos as usize) % PIPE_BUFF_SIZE; 204f678331aShanjiezhou //如果读端希望读取的字节数少于有效字节数,则输出希望读取的字节 205f678331aShanjiezhou if len < inode.valid_cnt as usize { 206f678331aShanjiezhou end = (len + inode.read_pos as usize) % PIPE_BUFF_SIZE; 207f678331aShanjiezhou num = len; 208f678331aShanjiezhou } 209f678331aShanjiezhou 210f678331aShanjiezhou // 从管道拷贝数据到用户的缓冲区 211f678331aShanjiezhou 212f678331aShanjiezhou if end < start { 213f678331aShanjiezhou buf[0..(PIPE_BUFF_SIZE - start)].copy_from_slice(&inode.data[start..PIPE_BUFF_SIZE]); 214f678331aShanjiezhou buf[(PIPE_BUFF_SIZE - start)..num].copy_from_slice(&inode.data[0..end]); 215f678331aShanjiezhou } else { 216f678331aShanjiezhou buf[0..num].copy_from_slice(&inode.data[start..end]); 217f678331aShanjiezhou } 218f678331aShanjiezhou 219f678331aShanjiezhou //更新读位置以及valid_cnt 220f678331aShanjiezhou inode.read_pos = (inode.read_pos + num as i32) % PIPE_BUFF_SIZE as i32; 221f678331aShanjiezhou inode.valid_cnt -= num as i32; 222f678331aShanjiezhou 2235e948c56SGnoCiYeH // 读完以后如果未读完,则唤醒下一个读者 2245e948c56SGnoCiYeH if inode.valid_cnt > 0 { 2255e948c56SGnoCiYeH inode 2265e948c56SGnoCiYeH .read_wait_queue 2275e948c56SGnoCiYeH .wakeup(Some(ProcessState::Blocked(true))); 2285e948c56SGnoCiYeH } 2295e948c56SGnoCiYeH 230f678331aShanjiezhou //读完后解锁并唤醒等待在写等待队列中的进程 2311496ba7bSLoGin inode 2321496ba7bSLoGin .write_wait_queue 2331496ba7bSLoGin .wakeup(Some(ProcessState::Blocked(true))); 2345e948c56SGnoCiYeH 235*b5b571e0SLoGin let pollflag = EPollEventType::from_bits_truncate(inode.poll(data)? as u32); 2365e948c56SGnoCiYeH // 唤醒epoll中等待的进程 237*b5b571e0SLoGin EventPoll::wakeup_epoll(&inode.epitems, pollflag)?; 2385e948c56SGnoCiYeH 239f678331aShanjiezhou //返回读取的字节数 240f678331aShanjiezhou return Ok(num); 241f678331aShanjiezhou } 242f678331aShanjiezhou 243f678331aShanjiezhou fn open( 244f678331aShanjiezhou &self, 245876cb89eSGnoCiYeH data: &mut FilePrivateData, 246876cb89eSGnoCiYeH mode: &crate::filesystem::vfs::file::FileMode, 247f678331aShanjiezhou ) -> Result<(), SystemError> { 248876cb89eSGnoCiYeH let mut guard = self.0.lock(); 249876cb89eSGnoCiYeH // 不能以读写方式打开管道 250876cb89eSGnoCiYeH if mode.contains(FileMode::O_RDWR) { 251876cb89eSGnoCiYeH return Err(SystemError::EACCES); 252876cb89eSGnoCiYeH } 253876cb89eSGnoCiYeH if mode.contains(FileMode::O_RDONLY) { 254876cb89eSGnoCiYeH guard.reader += 1; 255876cb89eSGnoCiYeH } 256876cb89eSGnoCiYeH if mode.contains(FileMode::O_WRONLY) { 257876cb89eSGnoCiYeH guard.writer += 1; 258876cb89eSGnoCiYeH } 259876cb89eSGnoCiYeH 260876cb89eSGnoCiYeH // 设置mode 261876cb89eSGnoCiYeH *data = FilePrivateData::Pipefs(PipeFsPrivateData { mode: *mode }); 262876cb89eSGnoCiYeH 263f678331aShanjiezhou return Ok(()); 264f678331aShanjiezhou } 265f678331aShanjiezhou 266f678331aShanjiezhou fn metadata(&self) -> Result<crate::filesystem::vfs::Metadata, SystemError> { 267f678331aShanjiezhou let inode = self.0.lock(); 268f678331aShanjiezhou let mut metadata = inode.metadata.clone(); 269f678331aShanjiezhou metadata.size = inode.data.len() as i64; 270f678331aShanjiezhou 271f678331aShanjiezhou return Ok(metadata); 272f678331aShanjiezhou } 273f678331aShanjiezhou 274876cb89eSGnoCiYeH fn close(&self, data: &mut FilePrivateData) -> Result<(), SystemError> { 275876cb89eSGnoCiYeH let mode: FileMode; 276876cb89eSGnoCiYeH if let FilePrivateData::Pipefs(pipe_data) = data { 277876cb89eSGnoCiYeH mode = pipe_data.mode; 278876cb89eSGnoCiYeH } else { 279876cb89eSGnoCiYeH return Err(SystemError::EBADF); 280876cb89eSGnoCiYeH } 281876cb89eSGnoCiYeH let mut guard = self.0.lock(); 282876cb89eSGnoCiYeH 283876cb89eSGnoCiYeH // 写端关闭 284876cb89eSGnoCiYeH if mode.contains(FileMode::O_WRONLY) { 285876cb89eSGnoCiYeH assert!(guard.writer > 0); 286876cb89eSGnoCiYeH guard.writer -= 1; 287876cb89eSGnoCiYeH // 如果已经没有写端了,则唤醒读端 288876cb89eSGnoCiYeH if guard.writer == 0 { 289876cb89eSGnoCiYeH guard 290876cb89eSGnoCiYeH .read_wait_queue 291876cb89eSGnoCiYeH .wakeup_all(Some(ProcessState::Blocked(true))); 292876cb89eSGnoCiYeH } 293876cb89eSGnoCiYeH } 294876cb89eSGnoCiYeH 295876cb89eSGnoCiYeH // 读端关闭 296876cb89eSGnoCiYeH if mode.contains(FileMode::O_RDONLY) { 297876cb89eSGnoCiYeH assert!(guard.reader > 0); 298876cb89eSGnoCiYeH guard.reader -= 1; 299876cb89eSGnoCiYeH // 如果已经没有写端了,则唤醒读端 300876cb89eSGnoCiYeH if guard.reader == 0 { 301876cb89eSGnoCiYeH guard 302876cb89eSGnoCiYeH .write_wait_queue 303876cb89eSGnoCiYeH .wakeup_all(Some(ProcessState::Blocked(true))); 304876cb89eSGnoCiYeH } 305876cb89eSGnoCiYeH } 306876cb89eSGnoCiYeH 307f678331aShanjiezhou return Ok(()); 308f678331aShanjiezhou } 309f678331aShanjiezhou 310f678331aShanjiezhou fn write_at( 311f678331aShanjiezhou &self, 312f678331aShanjiezhou _offset: usize, 313f678331aShanjiezhou len: usize, 314f678331aShanjiezhou buf: &[u8], 315876cb89eSGnoCiYeH data: &mut FilePrivateData, 31691e9d4abSLoGin ) -> Result<usize, SystemError> { 317876cb89eSGnoCiYeH // 获取mode 318876cb89eSGnoCiYeH let mode: FileMode; 319876cb89eSGnoCiYeH if let FilePrivateData::Pipefs(pdata) = data { 320876cb89eSGnoCiYeH mode = pdata.mode; 321876cb89eSGnoCiYeH } else { 322876cb89eSGnoCiYeH return Err(SystemError::EBADF); 323876cb89eSGnoCiYeH } 324876cb89eSGnoCiYeH 325f678331aShanjiezhou if buf.len() < len || len > PIPE_BUFF_SIZE { 326f678331aShanjiezhou return Err(SystemError::EINVAL); 327f678331aShanjiezhou } 328f678331aShanjiezhou // 加锁 329f678331aShanjiezhou 330f678331aShanjiezhou let mut inode = self.0.lock(); 331f678331aShanjiezhou 332*b5b571e0SLoGin if inode.reader == 0 { 333876cb89eSGnoCiYeH // TODO: 如果已经没有读端存在了,则向写端进程发送SIGPIPE信号 334*b5b571e0SLoGin } 335876cb89eSGnoCiYeH 336f678331aShanjiezhou // 如果管道空间不够 337f678331aShanjiezhou 338f678331aShanjiezhou while len + inode.valid_cnt as usize > PIPE_BUFF_SIZE { 339f678331aShanjiezhou // 唤醒读端 3401496ba7bSLoGin inode 3411496ba7bSLoGin .read_wait_queue 3421496ba7bSLoGin .wakeup(Some(ProcessState::Blocked(true))); 3431496ba7bSLoGin 34422c9db31Shanjiezhou // 如果为非阻塞管道,直接返回错误 345876cb89eSGnoCiYeH if mode.contains(FileMode::O_NONBLOCK) { 34622c9db31Shanjiezhou drop(inode); 34722c9db31Shanjiezhou return Err(SystemError::ENOMEM); 34822c9db31Shanjiezhou } 3491496ba7bSLoGin 350f678331aShanjiezhou // 解锁并睡眠 351f678331aShanjiezhou unsafe { 352f678331aShanjiezhou let irq_guard = CurrentIrqArch::save_and_disable_irq(); 353f678331aShanjiezhou inode.write_wait_queue.sleep_without_schedule(); 354f678331aShanjiezhou drop(inode); 355f678331aShanjiezhou drop(irq_guard); 356f678331aShanjiezhou } 357f678331aShanjiezhou sched(); 358f678331aShanjiezhou inode = self.0.lock(); 359f678331aShanjiezhou } 360f678331aShanjiezhou 361f678331aShanjiezhou // 决定要输入的字节 362f678331aShanjiezhou let start = inode.write_pos as usize; 363f678331aShanjiezhou let end = (inode.write_pos as usize + len) % PIPE_BUFF_SIZE; 364f678331aShanjiezhou // 从用户的缓冲区拷贝数据到管道 365f678331aShanjiezhou 366f678331aShanjiezhou if end < start { 367f678331aShanjiezhou inode.data[start..PIPE_BUFF_SIZE].copy_from_slice(&buf[0..(PIPE_BUFF_SIZE - start)]); 368f678331aShanjiezhou inode.data[0..end].copy_from_slice(&buf[(PIPE_BUFF_SIZE - start)..len]); 369f678331aShanjiezhou } else { 370f678331aShanjiezhou inode.data[start..end].copy_from_slice(&buf[0..len]); 371f678331aShanjiezhou } 372f678331aShanjiezhou // 更新写位置以及valid_cnt 373f678331aShanjiezhou inode.write_pos = (inode.write_pos + len as i32) % PIPE_BUFF_SIZE as i32; 374f678331aShanjiezhou inode.valid_cnt += len as i32; 375f678331aShanjiezhou 3765e948c56SGnoCiYeH // 写完后还有位置,则唤醒下一个写者 3775e948c56SGnoCiYeH if (inode.valid_cnt as usize) < PIPE_BUFF_SIZE { 3785e948c56SGnoCiYeH inode 3795e948c56SGnoCiYeH .write_wait_queue 3805e948c56SGnoCiYeH .wakeup(Some(ProcessState::Blocked(true))); 3815e948c56SGnoCiYeH } 3825e948c56SGnoCiYeH 383f678331aShanjiezhou // 读完后解锁并唤醒等待在读等待队列中的进程 3841496ba7bSLoGin inode 3851496ba7bSLoGin .read_wait_queue 3861496ba7bSLoGin .wakeup(Some(ProcessState::Blocked(true))); 3875e948c56SGnoCiYeH 388*b5b571e0SLoGin let pollflag = EPollEventType::from_bits_truncate(inode.poll(data)? as u32); 3895e948c56SGnoCiYeH // 唤醒epoll中等待的进程 390*b5b571e0SLoGin EventPoll::wakeup_epoll(&inode.epitems, pollflag)?; 3915e948c56SGnoCiYeH 392f678331aShanjiezhou // 返回写入的字节数 393f678331aShanjiezhou return Ok(len); 394f678331aShanjiezhou } 395f678331aShanjiezhou 396f678331aShanjiezhou fn as_any_ref(&self) -> &dyn core::any::Any { 397f678331aShanjiezhou self 398f678331aShanjiezhou } 399f678331aShanjiezhou 400f678331aShanjiezhou fn get_entry_name_and_metadata( 401f678331aShanjiezhou &self, 402f678331aShanjiezhou ino: crate::filesystem::vfs::InodeId, 403f678331aShanjiezhou ) -> Result<(alloc::string::String, crate::filesystem::vfs::Metadata), SystemError> { 404f678331aShanjiezhou // 如果有条件,请在文件系统中使用高效的方式实现本接口,而不是依赖这个低效率的默认实现。 405f678331aShanjiezhou let name = self.get_entry_name(ino)?; 406f678331aShanjiezhou let entry = self.find(&name)?; 407f678331aShanjiezhou return Ok((name, entry.metadata()?)); 408f678331aShanjiezhou } 409f678331aShanjiezhou 410f678331aShanjiezhou fn fs(&self) -> Arc<(dyn FileSystem)> { 411f678331aShanjiezhou todo!() 412f678331aShanjiezhou } 413f678331aShanjiezhou 414f678331aShanjiezhou fn list(&self) -> Result<alloc::vec::Vec<alloc::string::String>, SystemError> { 415f678331aShanjiezhou return Err(SystemError::EOPNOTSUPP_OR_ENOTSUP); 416f678331aShanjiezhou } 4175e948c56SGnoCiYeH 4185e948c56SGnoCiYeH fn poll(&self, private_data: &FilePrivateData) -> Result<usize, SystemError> { 4195e948c56SGnoCiYeH return self.0.lock().poll(private_data); 4205e948c56SGnoCiYeH } 421f678331aShanjiezhou } 422