mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-21 08:26:30 +00:00
Move FS things to PosixThread
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
fe7e4884c9
commit
36fc1d3757
@ -67,7 +67,7 @@ fn do_accept(
|
||||
}
|
||||
|
||||
let fd = {
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.insert(connected_socket, fd_flags)
|
||||
};
|
||||
|
||||
|
@ -69,7 +69,7 @@ pub fn do_faccessat(
|
||||
let dentry = {
|
||||
let path = path.to_string_lossy();
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
let fs = ctx.process.fs().read();
|
||||
let fs = ctx.posix_thread.fs().resolver().read();
|
||||
if flags.contains(FaccessatFlags::AT_SYMLINK_NOFOLLOW) {
|
||||
fs.lookup_no_follow(&fs_path)?
|
||||
} else {
|
||||
|
@ -11,7 +11,7 @@ pub fn sys_chdir(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let path = ctx.user_space().read_cstring(path_ptr, MAX_FILENAME_LEN)?;
|
||||
debug!("path = {:?}", path);
|
||||
|
||||
let mut fs = ctx.process.fs().write();
|
||||
let mut fs = ctx.posix_thread.fs().resolver().write();
|
||||
let dentry = {
|
||||
let path = path.to_string_lossy();
|
||||
if path.is_empty() {
|
||||
@ -31,7 +31,7 @@ pub fn sys_fchdir(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("fd = {}", fd);
|
||||
|
||||
let dentry = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let file = file_table.get_file(fd)?;
|
||||
let inode_handle = file
|
||||
.downcast_ref::<InodeHandle>()
|
||||
@ -41,6 +41,6 @@ pub fn sys_fchdir(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
if dentry.type_() != InodeType::Dir {
|
||||
return_errno_with_message!(Errno::ENOTDIR, "must be directory");
|
||||
}
|
||||
ctx.process.fs().write().set_cwd(dentry);
|
||||
ctx.posix_thread.fs().resolver().write().set_cwd(dentry);
|
||||
Ok(SyscallReturn::Return(0))
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ pub fn sys_fchmod(fd: FileDesc, mode: u16, ctx: &Context) -> Result<SyscallRetur
|
||||
debug!("fd = {}, mode = 0o{:o}", fd, mode);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
file.set_mode(InodeMode::from_bits_truncate(mode))?;
|
||||
@ -42,7 +42,7 @@ pub fn sys_fchmodat(
|
||||
return_errno_with_message!(Errno::ENOENT, "path is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
dentry.set_mode(InodeMode::from_bits_truncate(mode))?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
|
@ -21,7 +21,7 @@ pub fn sys_fchown(fd: FileDesc, uid: i32, gid: i32, ctx: &Context) -> Result<Sys
|
||||
}
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
if let Some(uid) = uid {
|
||||
@ -80,7 +80,7 @@ pub fn sys_fchownat(
|
||||
let dentry = {
|
||||
let path = path.to_string_lossy();
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
let fs = ctx.process.fs().read();
|
||||
let fs = ctx.posix_thread.fs().resolver().read();
|
||||
if flags.contains(ChownFlags::AT_SYMLINK_NOFOLLOW) {
|
||||
fs.lookup_no_follow(&fs_path)?
|
||||
} else {
|
||||
|
@ -11,7 +11,7 @@ pub fn sys_chroot(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let path = ctx.user_space().read_cstring(path_ptr, MAX_FILENAME_LEN)?;
|
||||
debug!("path = {:?}", path);
|
||||
|
||||
let mut fs = ctx.process.fs().write();
|
||||
let mut fs = ctx.posix_thread.fs().resolver().write();
|
||||
let dentry = {
|
||||
let path = path.to_string_lossy();
|
||||
if path.is_empty() {
|
||||
|
@ -7,7 +7,7 @@ pub fn sys_close(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("fd = {}", fd);
|
||||
|
||||
let file = {
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let _ = file_table.get_file(fd)?;
|
||||
file_table.close_file(fd).unwrap()
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ use crate::{
|
||||
pub fn sys_dup(old_fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("old_fd = {}", old_fd);
|
||||
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let new_fd = file_table.dup(old_fd, 0, FdFlags::empty())?;
|
||||
|
||||
Ok(SyscallReturn::Return(new_fd as _))
|
||||
@ -20,7 +20,7 @@ pub fn sys_dup2(old_fd: FileDesc, new_fd: FileDesc, ctx: &Context) -> Result<Sys
|
||||
debug!("old_fd = {}, new_fd = {}", old_fd, new_fd);
|
||||
|
||||
if old_fd == new_fd {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let _ = file_table.get_file(old_fd)?;
|
||||
return Ok(SyscallReturn::Return(new_fd as _));
|
||||
}
|
||||
@ -55,9 +55,9 @@ fn do_dup3(
|
||||
return_errno!(Errno::EINVAL);
|
||||
}
|
||||
|
||||
let current = ctx.process;
|
||||
if new_fd
|
||||
>= current
|
||||
>= ctx
|
||||
.process
|
||||
.resource_limits()
|
||||
.lock()
|
||||
.get_rlimit(ResourceType::RLIMIT_NOFILE)
|
||||
@ -66,7 +66,7 @@ fn do_dup3(
|
||||
return_errno!(Errno::EBADF);
|
||||
}
|
||||
|
||||
let mut file_table = current.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let _ = file_table.close_file(new_fd);
|
||||
let new_fd = file_table.dup(old_fd, new_fd, flags)?;
|
||||
|
||||
|
@ -41,7 +41,7 @@ pub fn sys_epoll_create1(flags: u32, ctx: &Context) -> Result<SyscallReturn> {
|
||||
};
|
||||
|
||||
let epoll_file: Arc<EpollFile> = EpollFile::new();
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let fd = file_table.insert(epoll_file, fd_flags);
|
||||
Ok(SyscallReturn::Return(fd as _))
|
||||
}
|
||||
@ -80,7 +80,7 @@ pub fn sys_epoll_ctl(
|
||||
};
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(epfd)?.clone()
|
||||
};
|
||||
let epoll_file = file
|
||||
@ -110,7 +110,7 @@ fn do_epoll_wait(
|
||||
};
|
||||
|
||||
let epoll_file_arc = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(epfd)?.clone()
|
||||
};
|
||||
let epoll_file = epoll_file_arc
|
||||
|
@ -54,7 +54,7 @@ pub fn sys_eventfd2(init_val: u64, flags: u32, ctx: &Context) -> Result<SyscallR
|
||||
fn do_sys_eventfd2(init_val: u64, flags: Flags, ctx: &Context) -> FileDesc {
|
||||
let event_file = EventFile::new(init_val, flags);
|
||||
let fd = {
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let fd_flags = if flags.contains(Flags::EFD_CLOEXEC) {
|
||||
FdFlags::CLOEXEC
|
||||
} else {
|
||||
|
@ -62,7 +62,7 @@ fn lookup_executable_file(
|
||||
flags: OpenFlags,
|
||||
ctx: &Context,
|
||||
) -> Result<Dentry> {
|
||||
let fs_resolver = ctx.process.fs().read();
|
||||
let fs_resolver = ctx.posix_thread.fs().resolver().read();
|
||||
let dentry = if flags.contains(OpenFlags::AT_EMPTY_PATH) && filename.is_empty() {
|
||||
fs_resolver.lookup_from_fd(dfd)
|
||||
} else {
|
||||
@ -110,12 +110,13 @@ fn do_execve(
|
||||
*posix_thread.clear_child_tid().lock() = 0;
|
||||
|
||||
// Ensure that the file descriptors with the close-on-exec flag are closed.
|
||||
let closed_files = process.file_table().lock().close_files_on_exec();
|
||||
// FIXME: This is just wrong if the file table is shared with other processes.
|
||||
let closed_files = posix_thread.file_table().lock().close_files_on_exec();
|
||||
drop(closed_files);
|
||||
|
||||
debug!("load program to root vmar");
|
||||
let (new_executable_path, elf_load_info) = {
|
||||
let fs_resolver = &*process.fs().read();
|
||||
let fs_resolver = &*posix_thread.fs().resolver().read();
|
||||
let process_vm = process.vm();
|
||||
load_program_to_vm(process_vm, elf_file.clone(), argv, envp, fs_resolver, 1)?
|
||||
};
|
||||
|
@ -22,7 +22,7 @@ pub fn sys_fallocate(
|
||||
check_offset_and_len(offset, len, ctx)?;
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
|
@ -33,13 +33,13 @@ pub fn sys_fcntl(fd: FileDesc, cmd: i32, arg: u64, ctx: &Context) -> Result<Sysc
|
||||
}
|
||||
|
||||
fn handle_dupfd(fd: FileDesc, arg: u64, flags: FdFlags, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let new_fd = file_table.dup(fd, arg as FileDesc, flags)?;
|
||||
Ok(SyscallReturn::Return(new_fd as _))
|
||||
}
|
||||
|
||||
fn handle_getfd(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let entry = file_table.get_entry(fd)?;
|
||||
let fd_flags = entry.flags();
|
||||
Ok(SyscallReturn::Return(fd_flags.bits() as _))
|
||||
@ -51,7 +51,7 @@ fn handle_setfd(fd: FileDesc, arg: u64, ctx: &Context) -> Result<SyscallReturn>
|
||||
} else {
|
||||
FdFlags::from_bits(arg as u8).ok_or(Error::with_message(Errno::EINVAL, "invalid flags"))?
|
||||
};
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let entry = file_table.get_entry(fd)?;
|
||||
entry.set_flags(flags);
|
||||
Ok(SyscallReturn::Return(0))
|
||||
@ -59,7 +59,7 @@ fn handle_setfd(fd: FileDesc, arg: u64, ctx: &Context) -> Result<SyscallReturn>
|
||||
|
||||
fn handle_getfl(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let status_flags = file.status_flags();
|
||||
@ -71,7 +71,7 @@ fn handle_getfl(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
|
||||
fn handle_setfl(fd: FileDesc, arg: u64, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let valid_flags_mask = StatusFlags::O_APPEND
|
||||
@ -88,7 +88,7 @@ fn handle_setfl(fd: FileDesc, arg: u64, ctx: &Context) -> Result<SyscallReturn>
|
||||
|
||||
fn handle_getlk(fd: FileDesc, arg: u64, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let lock_mut_ptr = arg as Vaddr;
|
||||
@ -117,7 +117,7 @@ fn handle_setlk(
|
||||
ctx: &Context,
|
||||
) -> Result<SyscallReturn> {
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let lock_mut_ptr = arg as Vaddr;
|
||||
@ -135,7 +135,7 @@ fn handle_setlk(
|
||||
}
|
||||
|
||||
fn handle_getown(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let file_entry = file_table.get_entry(fd)?;
|
||||
let pid = file_entry.owner().unwrap_or(0);
|
||||
Ok(SyscallReturn::Return(pid as _))
|
||||
@ -159,7 +159,7 @@ fn handle_setown(fd: FileDesc, arg: u64, ctx: &Context) -> Result<SyscallReturn>
|
||||
))?)
|
||||
};
|
||||
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let file_entry = file_table.get_entry_mut(fd)?;
|
||||
file_entry.set_owner(owner_process.as_ref())?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
|
@ -14,7 +14,7 @@ pub fn sys_flock(fd: FileDesc, ops: i32, ctx: &Context) -> Result<SyscallReturn>
|
||||
debug!("flock: fd: {}, ops: {:?}", fd, ops);
|
||||
|
||||
let file = {
|
||||
let current = ctx.process;
|
||||
let current = ctx.posix_thread;
|
||||
let file_table = current.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
@ -10,7 +10,7 @@ pub fn sys_fsync(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("fd = {}", fd);
|
||||
|
||||
let dentry = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let file = file_table.get_file(fd)?;
|
||||
let inode_handle = file
|
||||
.downcast_ref::<InodeHandle>()
|
||||
@ -25,7 +25,7 @@ pub fn sys_fdatasync(fd: FileDesc, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("fd = {}", fd);
|
||||
|
||||
let dentry = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let file = file_table.get_file(fd)?;
|
||||
let inode_handle = file
|
||||
.downcast_ref::<InodeHandle>()
|
||||
|
@ -7,9 +7,10 @@ use crate::{
|
||||
};
|
||||
|
||||
pub fn sys_getcwd(buf: Vaddr, len: usize, ctx: &Context) -> Result<SyscallReturn> {
|
||||
let current = ctx.process;
|
||||
let current = ctx.posix_thread;
|
||||
let dirent = current
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup(&FsPath::new(AT_FDCWD, "").unwrap())
|
||||
.unwrap();
|
||||
|
@ -24,7 +24,7 @@ pub fn sys_getdents(
|
||||
);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let inode_handle = file
|
||||
@ -54,7 +54,7 @@ pub fn sys_getdents64(
|
||||
);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let inode_handle = file
|
||||
|
@ -17,7 +17,7 @@ pub fn sys_ioctl(fd: FileDesc, cmd: u32, arg: Vaddr, ctx: &Context) -> Result<Sy
|
||||
);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
let res = match ioctl_cmd {
|
||||
@ -44,14 +44,14 @@ pub fn sys_ioctl(fd: FileDesc, cmd: u32, arg: Vaddr, ctx: &Context) -> Result<Sy
|
||||
// Follow the implementation of fcntl()
|
||||
|
||||
let flags = FdFlags::CLOEXEC;
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let entry = file_table.get_entry(fd)?;
|
||||
entry.set_flags(flags);
|
||||
0
|
||||
}
|
||||
IoctlCmd::FIONCLEX => {
|
||||
// Clears the close-on-exec flag of the file.
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let entry = file_table.get_entry(fd)?;
|
||||
entry.set_flags(entry.flags() & (!FdFlags::CLOEXEC));
|
||||
0
|
||||
|
@ -44,7 +44,7 @@ pub fn sys_linkat(
|
||||
|
||||
let old_fs_path = FsPath::new(old_dirfd, old_path.as_ref())?;
|
||||
let new_fs_path = FsPath::new(new_dirfd, new_path.as_ref())?;
|
||||
let fs = ctx.process.fs().read();
|
||||
let fs = ctx.posix_thread.fs().resolver().read();
|
||||
let old_dentry = if flags.contains(LinkFlags::AT_SYMLINK_FOLLOW) {
|
||||
fs.lookup(&old_fs_path)?
|
||||
} else {
|
||||
|
@ -21,7 +21,7 @@ pub fn sys_lseek(fd: FileDesc, offset: isize, whence: u32, ctx: &Context) -> Res
|
||||
_ => return_errno!(Errno::EINVAL),
|
||||
};
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
|
@ -20,7 +20,7 @@ pub fn sys_mkdirat(
|
||||
let path = ctx.user_space().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||
debug!("dirfd = {}, path = {:?}, mode = {}", dirfd, path, mode);
|
||||
|
||||
let current = ctx.process;
|
||||
let current = ctx.posix_thread;
|
||||
let (dir_dentry, name) = {
|
||||
let path = path.to_string_lossy();
|
||||
if path.is_empty() {
|
||||
@ -29,12 +29,13 @@ pub fn sys_mkdirat(
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
current
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_dir_and_new_basename(&fs_path, true)?
|
||||
};
|
||||
|
||||
let inode_mode = {
|
||||
let mask_mode = mode & !current.umask().read().get();
|
||||
let mask_mode = mode & !current.fs().umask().read().get();
|
||||
InodeMode::from_bits_truncate(mask_mode)
|
||||
};
|
||||
let _ = dir_dentry.new_fs_child(name.trim_end_matches('/'), InodeType::Dir, inode_mode)?;
|
||||
|
@ -20,9 +20,9 @@ pub fn sys_mknodat(
|
||||
ctx: &Context,
|
||||
) -> Result<SyscallReturn> {
|
||||
let path = ctx.user_space().read_cstring(path_addr, MAX_FILENAME_LEN)?;
|
||||
let current = ctx.process;
|
||||
let current = ctx.posix_thread;
|
||||
let inode_mode = {
|
||||
let mask_mode = mode & !current.umask().read().get();
|
||||
let mask_mode = mode & !current.fs().umask().read().get();
|
||||
InodeMode::from_bits_truncate(mask_mode)
|
||||
};
|
||||
let inode_type = InodeType::from_raw_mode(mode)?;
|
||||
@ -39,6 +39,7 @@ pub fn sys_mknodat(
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
current
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_dir_and_new_basename(&fs_path, false)?
|
||||
};
|
||||
|
@ -116,7 +116,7 @@ fn do_sys_mmap(
|
||||
}
|
||||
} else {
|
||||
let vmo = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let file = file_table.get_file(fd)?;
|
||||
let inode_handle = file
|
||||
.downcast_ref::<InodeHandle>()
|
||||
|
@ -40,7 +40,7 @@ pub fn sys_mount(
|
||||
return_errno_with_message!(Errno::ENOENT, "dirname is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(AT_FDCWD, dirname.as_ref())?;
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
|
||||
if mount_flags.contains(MountFlags::MS_REMOUNT) && mount_flags.contains(MountFlags::MS_BIND) {
|
||||
@ -93,7 +93,7 @@ fn do_bind_mount(
|
||||
return_errno_with_message!(Errno::ENOENT, "src_name is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(AT_FDCWD, src_name.as_ref())?;
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
|
||||
if src_dentry.type_() != InodeType::Dir {
|
||||
@ -116,7 +116,7 @@ fn do_move_mount_old(src_name: CString, dst_dentry: Dentry, ctx: &Context) -> Re
|
||||
return_errno_with_message!(Errno::ENOENT, "src_name is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(AT_FDCWD, src_name.as_ref())?;
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
|
||||
if !src_dentry.is_root_of_mount() {
|
||||
|
@ -24,12 +24,16 @@ pub fn sys_openat(
|
||||
dirfd, path, flags, mode
|
||||
);
|
||||
|
||||
let current = ctx.process;
|
||||
let current = ctx.posix_thread;
|
||||
let file_handle = {
|
||||
let path = path.to_string_lossy();
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
let mask_mode = mode & !current.umask().read().get();
|
||||
let inode_handle = current.fs().read().open(&fs_path, flags, mask_mode)?;
|
||||
let mask_mode = mode & !current.fs().umask().read().get();
|
||||
let inode_handle = current
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.open(&fs_path, flags, mask_mode)?;
|
||||
Arc::new(inode_handle)
|
||||
};
|
||||
let mut file_table = current.file_table().lock();
|
||||
|
@ -21,7 +21,7 @@ pub fn sys_pipe2(fds: Vaddr, flags: u32, ctx: &Context) -> Result<SyscallReturn>
|
||||
FdFlags::empty()
|
||||
};
|
||||
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
|
||||
let pipe_fds = PipeFds {
|
||||
reader_fd: file_table.insert(pipe_reader, fd_flags),
|
||||
|
@ -100,7 +100,7 @@ enum FileResult {
|
||||
|
||||
/// Holds all the files we're going to poll.
|
||||
fn hold_files(poll_fds: &[PollFd], ctx: &Context) -> (FileResult, Vec<Option<Arc<dyn FileLike>>>) {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
|
||||
let mut files = Vec::with_capacity(poll_fds.len());
|
||||
let mut result = FileResult::AllValid;
|
||||
|
@ -19,7 +19,7 @@ pub fn sys_pread64(
|
||||
return_errno_with_message!(Errno::EINVAL, "offset cannot be negative");
|
||||
}
|
||||
let file = {
|
||||
let filetable = ctx.process.file_table().lock();
|
||||
let filetable = ctx.posix_thread.file_table().lock();
|
||||
filetable.get_file(fd)?.clone()
|
||||
};
|
||||
// TODO: Check (f.file->f_mode & FMODE_PREAD); We don't have f_mode in our FileLike trait
|
||||
|
@ -66,7 +66,7 @@ fn do_sys_preadv(
|
||||
}
|
||||
|
||||
let file = {
|
||||
let filetable = ctx.process.file_table().lock();
|
||||
let filetable = ctx.posix_thread.file_table().lock();
|
||||
filetable.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
@ -128,7 +128,7 @@ fn do_sys_readv(
|
||||
);
|
||||
|
||||
let file = {
|
||||
let filetable = ctx.process.file_table().lock();
|
||||
let filetable = ctx.posix_thread.file_table().lock();
|
||||
filetable.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
|
@ -18,7 +18,7 @@ pub fn sys_pwrite64(
|
||||
return_errno_with_message!(Errno::EINVAL, "offset cannot be negative");
|
||||
}
|
||||
let file = {
|
||||
let filetable = ctx.process.file_table().lock();
|
||||
let filetable = ctx.posix_thread.file_table().lock();
|
||||
filetable.get_file(fd)?.clone()
|
||||
};
|
||||
// TODO: Check (f.file->f_mode & FMODE_PWRITE); We don't have f_mode in our FileLike trait
|
||||
|
@ -61,7 +61,7 @@ fn do_sys_pwritev(
|
||||
return_errno_with_message!(Errno::EINVAL, "offset cannot be negative");
|
||||
}
|
||||
let file = {
|
||||
let filetable = ctx.process.file_table().lock();
|
||||
let filetable = ctx.posix_thread.file_table().lock();
|
||||
filetable.get_file(fd)?.clone()
|
||||
};
|
||||
// TODO: Check (f.file->f_mode & FMODE_PREAD); We don't have f_mode in our FileLike trait
|
||||
@ -117,7 +117,7 @@ fn do_sys_writev(
|
||||
fd, io_vec_ptr, io_vec_count
|
||||
);
|
||||
let file = {
|
||||
let filetable = ctx.process.file_table().lock();
|
||||
let filetable = ctx.posix_thread.file_table().lock();
|
||||
filetable.get_file(fd)?.clone()
|
||||
};
|
||||
let mut total_len = 0;
|
||||
|
@ -15,7 +15,7 @@ pub fn sys_read(
|
||||
);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
|
@ -30,7 +30,11 @@ pub fn sys_readlinkat(
|
||||
return_errno_with_message!(Errno::ENOENT, "path is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
ctx.process.fs().read().lookup_no_follow(&fs_path)?
|
||||
ctx.posix_thread
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_no_follow(&fs_path)?
|
||||
};
|
||||
let linkpath = dentry.inode().read_link()?;
|
||||
let bytes = linkpath.as_bytes();
|
||||
|
@ -26,7 +26,7 @@ pub fn sys_renameat(
|
||||
old_dirfd, old_path, new_dirfd, new_path
|
||||
);
|
||||
|
||||
let fs = ctx.process.fs().read();
|
||||
let fs = ctx.posix_thread.fs().resolver().read();
|
||||
|
||||
let (old_dir_dentry, old_name) = {
|
||||
let old_path = old_path.to_string_lossy();
|
||||
|
@ -28,7 +28,11 @@ pub(super) fn sys_rmdirat(
|
||||
return_errno_with_message!(Errno::EBUSY, "is root directory");
|
||||
}
|
||||
let fs_path = FsPath::new(dirfd, path_addr.as_ref())?;
|
||||
ctx.process.fs().read().lookup_dir_and_base_name(&fs_path)?
|
||||
ctx.posix_thread
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_dir_and_base_name(&fs_path)?
|
||||
};
|
||||
dir_dentry.rmdir(name.trim_end_matches('/'))?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
|
@ -34,7 +34,7 @@ pub fn sys_sendfile(
|
||||
};
|
||||
|
||||
let (out_file, in_file) = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let out_file = file_table.get_file(out_fd)?.clone();
|
||||
// FIXME: the in_file must support mmap-like operations (i.e., it cannot be a socket).
|
||||
let in_file = file_table.get_file(in_fd)?.clone();
|
||||
|
@ -43,7 +43,7 @@ pub fn sys_socket(domain: i32, type_: i32, protocol: i32, ctx: &Context) -> Resu
|
||||
_ => return_errno_with_message!(Errno::EAFNOSUPPORT, "unsupported domain"),
|
||||
};
|
||||
let fd = {
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let fd_flags = if sock_flags.contains(SockFlags::SOCK_CLOEXEC) {
|
||||
FdFlags::CLOEXEC
|
||||
} else {
|
||||
|
@ -37,7 +37,7 @@ pub fn sys_socketpair(
|
||||
};
|
||||
|
||||
let socket_fds = {
|
||||
let mut file_table = ctx.process.file_table().lock();
|
||||
let mut file_table = ctx.posix_thread.file_table().lock();
|
||||
let fd_flags = if sock_flags.contains(SockFlags::SOCK_CLOEXEC) {
|
||||
FdFlags::CLOEXEC
|
||||
} else {
|
||||
|
@ -16,7 +16,7 @@ pub fn sys_fstat(fd: FileDesc, stat_buf_ptr: Vaddr, ctx: &Context) -> Result<Sys
|
||||
debug!("fd = {}, stat_buf_addr = 0x{:x}", fd, stat_buf_ptr);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
@ -66,7 +66,7 @@ pub fn sys_fstatat(
|
||||
let dentry = {
|
||||
let filename = filename.to_string_lossy();
|
||||
let fs_path = FsPath::new(dirfd, filename.as_ref())?;
|
||||
let fs = ctx.process.fs().read();
|
||||
let fs = ctx.posix_thread.fs().resolver().read();
|
||||
if flags.contains(StatFlags::AT_SYMLINK_NOFOLLOW) {
|
||||
fs.lookup_no_follow(&fs_path)?
|
||||
} else {
|
||||
|
@ -19,7 +19,7 @@ pub fn sys_statfs(path_ptr: Vaddr, statfs_buf_ptr: Vaddr, ctx: &Context) -> Resu
|
||||
let dentry = {
|
||||
let path = path.to_string_lossy();
|
||||
let fs_path = FsPath::try_from(path.as_ref())?;
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
let statfs = Statfs::from(dentry.fs().sb());
|
||||
user_space.write_val(statfs_buf_ptr, &statfs)?;
|
||||
@ -30,7 +30,7 @@ pub fn sys_fstatfs(fd: FileDesc, statfs_buf_ptr: Vaddr, ctx: &Context) -> Result
|
||||
debug!("fd = {}, statfs_buf_addr = 0x{:x}", fd, statfs_buf_ptr);
|
||||
|
||||
let fs = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
let file = file_table.get_file(fd)?;
|
||||
let inode_handle = file
|
||||
.downcast_ref::<InodeHandle>()
|
||||
|
@ -35,8 +35,9 @@ pub fn sys_symlinkat(
|
||||
return_errno_with_message!(Errno::ENOENT, "linkpath is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(dirfd, linkpath.as_ref())?;
|
||||
ctx.process
|
||||
ctx.posix_thread
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_dir_and_new_basename(&fs_path, false)?
|
||||
};
|
||||
|
@ -17,7 +17,7 @@ pub fn sys_ftruncate(fd: FileDesc, len: isize, ctx: &Context) -> Result<SyscallR
|
||||
check_length(len, ctx)?;
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
@ -37,7 +37,7 @@ pub fn sys_truncate(path_ptr: Vaddr, len: isize, ctx: &Context) -> Result<Syscal
|
||||
return_errno_with_message!(Errno::ENOENT, "path is empty");
|
||||
}
|
||||
let fs_path = FsPath::new(AT_FDCWD, path.as_ref())?;
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
dir_dentry.resize(len as usize)?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
|
@ -5,6 +5,6 @@ use crate::prelude::*;
|
||||
|
||||
pub fn sys_umask(mask: u16, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("mask = 0o{:o}", mask);
|
||||
let old_mask = ctx.process.umask().write().set(mask);
|
||||
let old_mask = ctx.posix_thread.fs().umask().write().set(mask);
|
||||
Ok(SyscallReturn::Return(old_mask as _))
|
||||
}
|
||||
|
@ -21,9 +21,13 @@ pub fn sys_umount(path_addr: Vaddr, flags: u64, ctx: &Context) -> Result<Syscall
|
||||
let fs_path = FsPath::new(AT_FDCWD, path.as_ref())?;
|
||||
|
||||
let target_dentry = if umount_flags.contains(UmountFlags::UMOUNT_NOFOLLOW) {
|
||||
ctx.process.fs().read().lookup_no_follow(&fs_path)?
|
||||
ctx.posix_thread
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_no_follow(&fs_path)?
|
||||
} else {
|
||||
ctx.process.fs().read().lookup(&fs_path)?
|
||||
ctx.posix_thread.fs().resolver().read().lookup(&fs_path)?
|
||||
};
|
||||
|
||||
target_dentry.unmount()?;
|
||||
|
@ -34,7 +34,11 @@ pub fn sys_unlinkat(
|
||||
return_errno_with_message!(Errno::EISDIR, "unlink on directory");
|
||||
}
|
||||
let fs_path = FsPath::new(dirfd, path.as_ref())?;
|
||||
ctx.process.fs().read().lookup_dir_and_base_name(&fs_path)?
|
||||
ctx.posix_thread
|
||||
.fs()
|
||||
.resolver()
|
||||
.read()
|
||||
.lookup_dir_and_base_name(&fs_path)?
|
||||
};
|
||||
dir_dentry.unlink(&name)?;
|
||||
Ok(SyscallReturn::Return(0))
|
||||
|
@ -168,7 +168,7 @@ fn do_utimes(
|
||||
let dentry = {
|
||||
// Determine the file system path and the corresponding entry
|
||||
let fs_path = FsPath::new(dirfd, pathname.as_ref())?;
|
||||
let fs = ctx.process.fs().read();
|
||||
let fs = ctx.posix_thread.fs().resolver().read();
|
||||
if flags.contains(UtimensFlags::AT_SYMLINK_NOFOLLOW) {
|
||||
fs.lookup_no_follow(&fs_path)?
|
||||
} else {
|
||||
|
@ -15,7 +15,7 @@ pub fn sys_write(
|
||||
);
|
||||
|
||||
let file = {
|
||||
let file_table = ctx.process.file_table().lock();
|
||||
let file_table = ctx.posix_thread.file_table().lock();
|
||||
file_table.get_file(fd)?.clone()
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user