17
17
18
18
use aero_syscall:: prelude:: * ;
19
19
use aero_syscall:: signal:: SigProcMask ;
20
- use aero_syscall:: { OpenFlags , Stat , SyscallError , TimeSpec } ;
20
+ use aero_syscall:: { OpenFlags , Stat , SyscallError , TimeSpec , AT_FDCWD } ;
21
21
22
22
use crate :: fs:: cache:: { self , DirCacheImpl } ;
23
23
use crate :: fs:: epoll:: EPoll ;
@@ -70,7 +70,19 @@ pub fn read(fd: usize, buffer: &mut [u8]) -> Result<usize, SyscallError> {
70
70
}
71
71
72
72
#[ 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
+
74
86
let mut flags = OpenFlags :: from_bits ( mode) . ok_or ( SyscallError :: EINVAL ) ?;
75
87
76
88
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>
83
95
lookup_mode = LookupMode :: Create ;
84
96
}
85
97
86
- let inode = fs:: lookup_path_with_mode ( path, lookup_mode) ?;
98
+ let inode = fs:: lookup_path_with ( dir , path, lookup_mode) ?;
87
99
88
100
if flags. contains ( OpenFlags :: O_DIRECTORY ) && !inode. inode ( ) . metadata ( ) ?. is_directory ( ) {
89
101
return Err ( SyscallError :: ENOTDIR ) ;
0 commit comments