Add struct Path for VFS

Signed-off-by: Zhenchen Wang <m202372036@hust.edu.cn>
This commit is contained in:
plucky
2024-04-09 09:30:58 +08:00
committed by Tate, Hongliang Tian
parent bc1bf4cb53
commit 6d486c6c01
39 changed files with 561 additions and 447 deletions

View File

@ -35,18 +35,22 @@ pub fn sys_fchmodat(
/* flags: u32, */
) -> Result<SyscallReturn> {
log_syscall_entry!(SYS_FCHMODAT);
let path = read_cstring_from_user(path_ptr, PATH_MAX)?;
debug!("dirfd = {}, path = {:?}, mode = 0o{:o}", dirfd, path, mode,);
let pathname = read_cstring_from_user(path_ptr, PATH_MAX)?;
debug!(
"dirfd = {}, path = {:?}, mode = 0o{:o}",
dirfd, pathname, mode,
);
let current = current!();
let dentry = {
let path = path.to_string_lossy();
if path.is_empty() {
let path = {
let pathname = pathname.to_string_lossy();
if pathname.is_empty() {
return_errno_with_message!(Errno::ENOENT, "path is empty");
}
let fs_path = FsPath::new(dirfd, path.as_ref())?;
let fs_path = FsPath::new(dirfd, pathname.as_ref())?;
current.fs().read().lookup(&fs_path)?
};
dentry.set_mode(InodeMode::from_bits_truncate(mode))?;
path.dentry()
.set_mode(InodeMode::from_bits_truncate(mode))?;
Ok(SyscallReturn::Return(0))
}