mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-26 02:43:24 +00:00
Remove the shim kernel crate
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
d76c7a5b1e
commit
dafd16075f
36
kernel/src/fs/utils/dirent_visitor.rs
Normal file
36
kernel/src/fs/utils/dirent_visitor.rs
Normal file
@ -0,0 +1,36 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
#![allow(unused_variables)]
|
||||
|
||||
use super::InodeType;
|
||||
use crate::prelude::*;
|
||||
|
||||
/// A visitor for dir entries.
|
||||
pub trait DirentVisitor {
|
||||
/// Visit a dir entry.
|
||||
///
|
||||
/// If the visitor succeeds in visiting the given inode, an `Ok(())` is returned;
|
||||
/// Otherwise, an error is returned. Different implementations for `DirentVisitor`
|
||||
/// may choose to report errors for different reasons. Regardless of the exact
|
||||
/// errors and reasons, `readdir`-family methods shall stop feeding the visitor
|
||||
/// with the next inode as long as an error is returned by the visitor.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// `Vec<String>` is implemented as `DirentVisitor` so that the file names
|
||||
/// under a dir can be easily collected, which is convenient for testing purposes.
|
||||
///
|
||||
/// ```no_run
|
||||
/// let mut all_dirents = Vec::new();
|
||||
/// let dir_inode = todo!("create an inode");
|
||||
/// dir_inode.readdir_at(0, &mut all_dirents).unwrap();
|
||||
/// ```
|
||||
fn visit(&mut self, name: &str, ino: u64, type_: InodeType, offset: usize) -> Result<()>;
|
||||
}
|
||||
|
||||
impl DirentVisitor for Vec<String> {
|
||||
fn visit(&mut self, name: &str, ino: u64, type_: InodeType, offset: usize) -> Result<()> {
|
||||
self.push(name.into());
|
||||
Ok(())
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user