diff --git a/syscall/src/class1.rs b/syscall/src/class1.rs new file mode 100644 index 000000000..89f8b4ffd --- /dev/null +++ b/syscall/src/class1.rs @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: MIT OR Apache-2.0 +// +// Copyright (c) 2024 Intel Corporation. +// +// Author: Peter Fang + +use super::call::{syscall1, syscall3, SysCallError}; +use super::def::{SYS_OPENDIR, SYS_READDIR}; +use super::{DirEnt, Obj, ObjHandle}; +use core::ffi::CStr; + +#[derive(Debug)] +pub struct FsObjHandle(ObjHandle); + +impl Obj for FsObjHandle { + fn id(&self) -> u32 { + u32::from(&self.0) + } +} + +pub fn opendir(path: &CStr) -> Result { + unsafe { + syscall1(SYS_OPENDIR, path.as_ptr() as u64) + .map(|ret| FsObjHandle(ObjHandle::new(ret as u32))) + } +} + +pub fn readdir(fs: &FsObjHandle, dirents: &mut [DirEnt]) -> Result { + unsafe { + syscall3( + SYS_READDIR, + fs.id().into(), + dirents.as_mut_ptr() as u64, + dirents.len() as u64, + ) + .map(|ret| ret.try_into().unwrap()) + } +} diff --git a/syscall/src/lib.rs b/syscall/src/lib.rs index 9cc6c5ebe..119160c36 100644 --- a/syscall/src/lib.rs +++ b/syscall/src/lib.rs @@ -7,10 +7,12 @@ mod call; mod class0; +mod class1; mod def; mod obj; pub use call::SysCallError; pub use class0::*; +pub use class1::*; pub use def::*; pub use obj::*; diff --git a/syscall/src/obj.rs b/syscall/src/obj.rs index ce3ea2f5e..772c90c3a 100644 --- a/syscall/src/obj.rs +++ b/syscall/src/obj.rs @@ -18,7 +18,6 @@ use super::SYS_CLOSE; pub struct ObjHandle(u32); impl ObjHandle { - #[expect(dead_code)] pub(crate) fn new(id: u32) -> Self { Self(id) }