Skip to content

Commit f37046f

Browse files
feat(access): more complete
* Check the flags + check the FD Signed-off-by: Anhad Singh <[email protected]>
1 parent 4601c2f commit f37046f

File tree

1 file changed

+14
-9
lines changed
  • src/aero_kernel/src/syscall

1 file changed

+14
-9
lines changed

src/aero_kernel/src/syscall/fs.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use crate::fs::eventfd::EventFd;
2828
use crate::fs::file_table::{DuplicateHint, FileHandle};
2929
use crate::fs::inode::{DirEntry, PollTable};
3030
use crate::fs::pipe::Pipe;
31-
use crate::fs::{self, lookup_path, LookupMode};
31+
use crate::fs::{self, LookupMode};
3232
use crate::syscall::SysArg;
3333
use crate::userland::scheduler;
3434

@@ -353,14 +353,19 @@ pub fn unlink(_fd: usize, _path: &Path, _flags: usize) -> Result<usize, SyscallE
353353
}
354354

355355
#[syscall]
356-
pub fn access(fd: usize, path: &Path, _mode: usize, _flags: usize) -> Result<usize, SyscallError> {
357-
if fd as isize == aero_syscall::AT_FDCWD {
358-
lookup_path(path)?;
359-
Ok(0x00)
360-
} else {
361-
// TODO: Implement atfd access
362-
unimplemented!()
363-
}
356+
pub fn access(fd: usize, path: &Path, _mode: usize, flags: usize) -> Result<usize, SyscallError> {
357+
let at = match fd as isize {
358+
AT_FDCWD if !path.is_absolute() => scheduler::current_thread().cwd_dirent(),
359+
_ if !path.is_absolute() => FileDescriptor::from_usize(fd).handle()?.inode.clone(),
360+
_ => fs::root_dir().clone(),
361+
};
362+
363+
let flags = AtFlags::from_bits(flags).ok_or(SyscallError::EINVAL)?;
364+
365+
let resolve_last = !flags.contains(AtFlags::SYMLINK_NOFOLLOW);
366+
let _ = fs::lookup_path_with(at, path, LookupMode::None, resolve_last)?;
367+
368+
Ok(0)
364369
}
365370

366371
const SETFL_MASK: OpenFlags = OpenFlags::from_bits_truncate(

0 commit comments

Comments
 (0)