WIP: Add getdents opaque_id

This commit is contained in:
4lDO2
2024-09-10 09:10:41 +02:00
parent 339271b4d7
commit 97f60de4ef
10 changed files with 126 additions and 29 deletions
+18 -4
View File
@@ -1,5 +1,5 @@
use ::syscall::{
dirent::{DirentBuf, DirentKind},
dirent::{DirEntry, DirentBuf, DirentKind},
EIO, EISDIR, ENOTDIR,
};
use alloc::{collections::BTreeMap, vec::Vec};
@@ -150,13 +150,27 @@ impl KernelScheme for SysScheme {
}
}
}
fn getdents(&self, id: usize, buf: UserSliceWo, header_size: u16) -> Result<usize> {
fn getdents(
&self,
id: usize,
buf: UserSliceWo,
header_size: u16,
first_index: u64,
) -> Result<usize> {
let Ok(first_index) = usize::try_from(first_index) else {
return Ok(0);
};
match HANDLES.read().get(&id).ok_or(Error::new(EBADF))? {
Handle::Resource { .. } => return Err(Error::new(ENOTDIR)),
Handle::TopLevel => {
let mut buf = DirentBuf::new(buf, header_size).ok_or(Error::new(EIO))?;
for (name, _) in FILES {
buf.entry(DirentKind::Regular, name)?;
for (this_idx, (name, _)) in FILES.iter().enumerate().skip(first_index) {
buf.entry(DirEntry {
inode: this_idx as u64,
next_opaque_id: this_idx as u64 + 1,
kind: DirentKind::Regular,
name,
})?;
}
Ok(buf.finalize())
}