Skip to content

Commit 0fbb8ea

Browse files
feat(open): make use of the provided dirfd
Signed-off-by: Anhad Singh <[email protected]>
1 parent 684d342 commit 0fbb8ea

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/aero_kernel/src/fs/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -291,16 +291,6 @@ pub fn lookup_path_with(
291291
Ok(cwd)
292292
}
293293

294-
pub fn lookup_path_with_mode(path: &Path, mode: LookupMode) -> Result<DirCacheItem> {
295-
let cwd = if !path.is_absolute() {
296-
scheduler::get_scheduler().current_task().cwd_dirent()
297-
} else {
298-
root_dir().clone()
299-
};
300-
301-
lookup_path_with(cwd, path, mode)
302-
}
303-
304294
pub fn lookup_path(path: &Path) -> Result<DirCacheItem> {
305295
let cwd = if !path.is_absolute() {
306296
scheduler::get_scheduler().current_task().cwd_dirent()

src/aero_kernel/src/syscall/fs.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
use aero_syscall::prelude::*;
1919
use aero_syscall::signal::SigProcMask;
20-
use aero_syscall::{OpenFlags, Stat, SyscallError, TimeSpec};
20+
use aero_syscall::{OpenFlags, Stat, SyscallError, TimeSpec, AT_FDCWD};
2121

2222
use crate::fs::cache::{self, DirCacheImpl};
2323
use crate::fs::epoll::EPoll;
@@ -70,7 +70,19 @@ pub fn read(fd: usize, buffer: &mut [u8]) -> Result<usize, SyscallError> {
7070
}
7171

7272
#[syscall]
73-
pub fn open(_fd: usize, path: &Path, mode: usize) -> Result<usize, SyscallError> {
73+
pub fn open(fd: usize, path: &Path, mode: usize) -> Result<usize, SyscallError> {
74+
let dir = match fd as isize {
75+
AT_FDCWD => {
76+
if !path.is_absolute() {
77+
scheduler::get_scheduler().current_task().cwd_dirent()
78+
} else {
79+
crate::fs::root_dir().clone()
80+
}
81+
}
82+
83+
_ => todo!(),
84+
};
85+
7486
let mut flags = OpenFlags::from_bits(mode).ok_or(SyscallError::EINVAL)?;
7587

7688
if !flags.intersects(OpenFlags::O_RDONLY | OpenFlags::O_RDWR | OpenFlags::O_WRONLY) {
@@ -83,7 +95,7 @@ pub fn open(_fd: usize, path: &Path, mode: usize) -> Result<usize, SyscallError>
8395
lookup_mode = LookupMode::Create;
8496
}
8597

86-
let inode = fs::lookup_path_with_mode(path, lookup_mode)?;
98+
let inode = fs::lookup_path_with(dir, path, lookup_mode)?;
8799

88100
if flags.contains(OpenFlags::O_DIRECTORY) && !inode.inode().metadata()?.is_directory() {
89101
return Err(SyscallError::ENOTDIR);

0 commit comments

Comments
 (0)