-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
syscall/class1: Implement opendir() and readdir()
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
1 parent
30435c7
commit 2b4ab32
Showing
3 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters