Skip to content

Commit

Permalink
syscall/class1: Implement opendir() and readdir()
Browse files Browse the repository at this point in the history
Implement the OPENDIR and READDIR syscall interface in user space.

Co-developed-by: Vijay Dhanraj <[email protected]>
Signed-off-by: Peter Fang <[email protected]>
  • Loading branch information
peterfang authored and vijaydhanraj committed Nov 13, 2024
1 parent 30435c7 commit 2b4ab32
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions syscall/src/class1.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: MIT OR Apache-2.0
//
// Copyright (c) 2024 Intel Corporation.
//
// Author: Peter Fang <[email protected]>

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<FsObjHandle, SysCallError> {
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<usize, SysCallError> {
unsafe {
syscall3(
SYS_READDIR,
fs.id().into(),
dirents.as_mut_ptr() as u64,
dirents.len() as u64,
)
.map(|ret| ret.try_into().unwrap())
}
}
2 changes: 2 additions & 0 deletions syscall/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
1 change: 0 additions & 1 deletion syscall/src/obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down

0 comments on commit 2b4ab32

Please sign in to comment.