diff --git a/cykusz-rs/src/kernel/fs/mod.rs b/cykusz-rs/src/kernel/fs/mod.rs index 3733584b..8c41cb08 100644 --- a/cykusz-rs/src/kernel/fs/mod.rs +++ b/cykusz-rs/src/kernel/fs/mod.rs @@ -326,7 +326,15 @@ pub fn lookup_by_path_at( path: Path, lookup_mode: LookupMode, ) -> Result { - lookup_by_path_from(path, lookup_mode, dir, false, 0) + if let Some(cur) = if !path.is_absolute() { + Some(dir) + } else { + root_dentry().cloned() + } { + lookup_by_path_from(path, lookup_mode, cur, false, 0) + } else { + return Err(FsError::NotSupported); + } } pub fn lookup_by_path(path: Path, lookup_mode: LookupMode) -> Result { diff --git a/cykusz-rs/src/kernel/syscall/mod.rs b/cykusz-rs/src/kernel/syscall/mod.rs index 5e6247d2..654eb999 100644 --- a/cykusz-rs/src/kernel/syscall/mod.rs +++ b/cykusz-rs/src/kernel/syscall/mod.rs @@ -77,8 +77,7 @@ pub fn syscall_handler(num: u64, a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) SYS_PIPE => sys::sys_pipe(a, b), SYS_DUP => sys::sys_dup(a, b), SYS_DUP2 => sys::sys_dup2(a, b, c), - SYS_STAT => sys::sys_stat(a, b, c), - SYS_FSTAT => sys::sys_fstat(a, b), + SYS_STAT => sys::sys_stat(a, b, c, d), SYS_GETRLIMIT => sys::sys_getrlimit(a, b), SYS_DEBUG => sys::sys_debug(a, b), SYS_ACCESS => sys::sys_access(a, b, c, d, e), @@ -88,7 +87,6 @@ pub fn syscall_handler(num: u64, a: u64, b: u64, c: u64, d: u64, e: u64, f: u64) SYS_TICKSNS => sys::sys_ticksns(), SYS_GETPPID => sys::sys_getppid(), SYS_GETPGID => sys::sys_getpgid(a), - SYS_FSTATAT => sys::sys_fstatat(a, b, c, d), a => { logln!("NO SYS????? {}", a); Err(SyscallError::ENOSYS) diff --git a/cykusz-rs/src/kernel/syscall/sys.rs b/cykusz-rs/src/kernel/syscall/sys.rs index ef944af2..c160ac9e 100644 --- a/cykusz-rs/src/kernel/syscall/sys.rs +++ b/cykusz-rs/src/kernel/syscall/sys.rs @@ -1087,43 +1087,17 @@ pub fn sys_futex_wake(uaddr: u64) -> SyscallResult { crate::kernel::futex::futex().wake(uaddr) } -pub fn sys_stat(path: u64, path_len: u64, stat: u64) -> SyscallResult { - let _str = make_str(path, path_len); - let path = Path::new(make_str(path, path_len)); - - let stat = unsafe { VirtAddr(stat as usize).read_mut::() }; - - let inode = lookup_by_path(path, LookupMode::None)?; - - *stat = inode.inode().stat()?; - - logln!("stat {}, {:?}", _str, stat); - - Ok(0) -} - -pub fn sys_fstat(fd: u64, stat: u64) -> SyscallResult { - let file = current_task_ref() - .filetable() - .get_handle(fd as usize) - .ok_or(SyscallError::EBADFD)?; - - let stat = unsafe { VirtAddr(stat as usize).read_mut::() }; - - *stat = file.inode.inode().stat()?; - - logln!("fstat {}, {:?}", fd, stat); - - Ok(0) -} - -pub fn sys_fstatat(fd: u64, path: u64, path_len: u64, stat: u64) -> SyscallResult { +pub fn sys_stat(fd: u64, path: u64, path_len: u64, stat: u64) -> SyscallResult { let fd = OpenFD::try_from(fd)?; - let path = Path::new(make_str(path, path_len)); + let path = if path != 0 { + Some(Path::new(make_str(path, path_len))) + } else { + None + }; let task = current_task_ref(); - let dirent = match fd { + let file_dir = match fd { OpenFD::Fd(fd) => { task.get_handle(fd).ok_or(SyscallError::EBADFD)?.inode.clone() } @@ -1137,9 +1111,13 @@ pub fn sys_fstatat(fd: u64, path: u64, path_len: u64, stat: u64) -> SyscallResul let stat = unsafe { VirtAddr(stat as usize).read_mut::() }; - let file = lookup_by_path_at(dirent, path, LookupMode::None)?; + if let Some(path) = path { + let file = lookup_by_path_at(file_dir, path, LookupMode::None)?; - *stat = file.inode().stat()?; + *stat = file.inode().stat()?; + } else { + *stat = file_dir.inode().stat()?; + } logln!("fstatat {:?}, {:?}", fd, stat); diff --git a/syscall-defs/src/lib.rs b/syscall-defs/src/lib.rs index ac55b2a6..e6b60188 100644 --- a/syscall-defs/src/lib.rs +++ b/syscall-defs/src/lib.rs @@ -73,7 +73,6 @@ pub const SYS_PIPE: usize = 47; pub const SYS_DUP: usize = 48; pub const SYS_DUP2: usize = 49; pub const SYS_STAT: usize = 50; -pub const SYS_FSTAT: usize = 51; pub const SYS_GETRLIMIT: usize = 52; pub const SYS_DEBUG: usize = 53; @@ -86,7 +85,6 @@ pub const SYS_TICKSNS: usize = 58; pub const SYS_GETPPID: usize = 59; pub const SYS_GETPGID: usize = 60; -pub const SYS_FSTATAT: usize = 61; #[derive(Copy, Clone, PartialEq, Debug)] #[repr(u64)]