mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-09 13:26:48 +00:00
Optimize the DirEntry
lookup in ext2
This commit is contained in:
parent
21da6d2b93
commit
104c8dfdde
@ -156,6 +156,7 @@ impl From<DirEntryFileType> for InodeType {
|
|||||||
/// A reader for reading `DirEntry` from the page cache.
|
/// A reader for reading `DirEntry` from the page cache.
|
||||||
pub struct DirEntryReader<'a> {
|
pub struct DirEntryReader<'a> {
|
||||||
page_cache: &'a PageCache,
|
page_cache: &'a PageCache,
|
||||||
|
name_buf: [u8; MAX_FNAME_LEN],
|
||||||
offset: usize,
|
offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -164,6 +165,7 @@ impl<'a> DirEntryReader<'a> {
|
|||||||
pub(super) fn new(page_cache: &'a PageCache, from_offset: usize) -> Self {
|
pub(super) fn new(page_cache: &'a PageCache, from_offset: usize) -> Self {
|
||||||
Self {
|
Self {
|
||||||
page_cache,
|
page_cache,
|
||||||
|
name_buf: [0u8; MAX_FNAME_LEN],
|
||||||
offset: from_offset,
|
offset: from_offset,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,13 +180,14 @@ impl<'a> DirEntryReader<'a> {
|
|||||||
return_errno!(Errno::ENOENT);
|
return_errno!(Errno::ENOENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut name = vec![0u8; header.name_len as _];
|
let name_len = header.name_len as usize;
|
||||||
self.page_cache
|
self.page_cache.pages().read_bytes(
|
||||||
.pages()
|
self.offset + DirEntry::header_len(),
|
||||||
.read_bytes(self.offset + DirEntry::header_len(), &mut name)?;
|
&mut self.name_buf[..name_len],
|
||||||
|
)?;
|
||||||
let entry = DirEntry {
|
let entry = DirEntry {
|
||||||
header,
|
header,
|
||||||
name: CStr256::from(name.as_slice()),
|
name: CStr256::from(&self.name_buf[..name_len]),
|
||||||
};
|
};
|
||||||
self.offset += entry.record_len();
|
self.offset += entry.record_len();
|
||||||
|
|
||||||
@ -214,6 +217,7 @@ pub struct DirEntryWriter<'a> {
|
|||||||
offset: usize,
|
offset: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Improve the efficiency of the writer operations.
|
||||||
impl<'a> DirEntryWriter<'a> {
|
impl<'a> DirEntryWriter<'a> {
|
||||||
/// Constructs a writer with the given page cache and offset.
|
/// Constructs a writer with the given page cache and offset.
|
||||||
pub(super) fn new(page_cache: &'a PageCache, from_offset: usize) -> Self {
|
pub(super) fn new(page_cache: &'a PageCache, from_offset: usize) -> Self {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user