Rename FsResolver to PathResolver and update all usages

This commit is contained in:
Chen Chengjun 2026-01-12 08:43:24 +00:00
parent e6c7533b43
commit dcd22e0e20
48 changed files with 176 additions and 173 deletions

View File

@ -14,7 +14,10 @@ pub use pty::{PtyMaster, PtySlave, new_pty_pair};
pub use registry::lookup;
use crate::{
fs::{fs_resolver::FsPath, path::PerMountFlags, ramfs::RamFs},
fs::{
path::{FsPath, PerMountFlags},
ramfs::RamFs,
},
prelude::*,
};
@ -29,16 +32,16 @@ pub fn init_in_first_kthread() {
/// Initializes the device nodes in devtmpfs after mounting rootfs.
pub fn init_in_first_process(ctx: &Context) -> Result<()> {
let fs = ctx.thread_local.borrow_fs();
let fs_resolver = fs.resolver().read();
let path_resolver = fs.resolver().read();
// Mount devtmpfs.
let dev_path = fs_resolver.lookup(&FsPath::try_from("/dev")?)?;
let dev_path = path_resolver.lookup(&FsPath::try_from("/dev")?)?;
dev_path.mount(RamFs::new(), PerMountFlags::default(), ctx)?;
tty::init_in_first_process()?;
pty::init_in_first_process(&fs_resolver, ctx)?;
shm::init_in_first_process(&fs_resolver, ctx)?;
registry::init_in_first_process(&fs_resolver)?;
pty::init_in_first_process(&path_resolver, ctx)?;
shm::init_in_first_process(&path_resolver, ctx)?;
registry::init_in_first_process(&path_resolver)?;
Ok(())
}

View File

@ -11,8 +11,8 @@ use crate::{
fs::{
devpts::Ptmx,
file_table::FdFlags,
fs_resolver::FsPath,
inode_handle::FileIo,
path::FsPath,
utils::{AccessMode, InodeIo, OpenArgs, StatusFlags, mkmod},
},
prelude::*,

View File

@ -3,8 +3,7 @@
use crate::{
fs::{
devpts::{DevPts, Ptmx},
fs_resolver::{FsPath, FsResolver},
path::{Path, PerMountFlags},
path::{FsPath, Path, PathResolver, PerMountFlags},
utils::{InodeType, mkmod},
},
prelude::*,
@ -21,8 +20,8 @@ use spin::Once;
static DEV_PTS: Once<Path> = Once::new();
pub fn init_in_first_process(fs_resolver: &FsResolver, ctx: &Context) -> Result<()> {
let dev = fs_resolver.lookup(&FsPath::try_from("/dev")?)?;
pub fn init_in_first_process(path_resolver: &PathResolver, ctx: &Context) -> Result<()> {
let dev = path_resolver.lookup(&FsPath::try_from("/dev")?)?;
// Create the "pts" directory and mount devpts on it.
let devpts_path = dev.new_fs_child("pts", InodeType::Dir, mkmod!(a+rx, u+w))?;
let devpts_mount = devpts_path.mount(DevPts::new(), PerMountFlags::default(), ctx)?;

View File

@ -9,8 +9,8 @@ use crate::{
events::IoEvents,
fs::{
device::{Device, DeviceType, add_node},
fs_resolver::FsResolver,
inode_handle::FileIo,
path::PathResolver,
utils::{InodeIo, StatusFlags},
},
prelude::*,
@ -35,12 +35,12 @@ pub(super) fn init_in_first_kthread() {
}
}
pub(super) fn init_in_first_process(fs_resolver: &FsResolver) -> Result<()> {
pub(super) fn init_in_first_process(path_resolver: &PathResolver) -> Result<()> {
for device in aster_block::collect_all() {
let device = Arc::new(BlockFile::new(device));
if let Some(devtmpfs_path) = device.devtmpfs_path() {
let dev_id = device.id().as_encoded_u64();
add_node(DeviceType::Block, dev_id, &devtmpfs_path, fs_resolver)?;
add_node(DeviceType::Block, dev_id, &devtmpfs_path, path_resolver)?;
}
}

View File

@ -9,7 +9,7 @@ use device_id::{DeviceId, MajorId};
use crate::{
fs::{
device::{Device, DeviceType, add_node},
fs_resolver::FsResolver,
path::PathResolver,
},
prelude::*,
};
@ -112,11 +112,11 @@ impl Drop for MajorIdOwner {
}
}
pub(super) fn init_in_first_process(fs_resolver: &FsResolver) -> Result<()> {
pub(super) fn init_in_first_process(path_resolver: &PathResolver) -> Result<()> {
for device in collect_all() {
if let Some(devtmpfs_path) = device.devtmpfs_path() {
let dev_id = device.id().as_encoded_u64();
add_node(DeviceType::Char, dev_id, &devtmpfs_path, fs_resolver)?;
add_node(DeviceType::Char, dev_id, &devtmpfs_path, path_resolver)?;
}
}

View File

@ -5,7 +5,7 @@ use device_id::DeviceId;
use crate::{
fs::{
device::{Device, DeviceType},
fs_resolver::FsResolver,
path::PathResolver,
},
prelude::*,
};
@ -17,9 +17,9 @@ pub(super) fn init_in_first_kthread() {
block::init_in_first_kthread();
}
pub(super) fn init_in_first_process(fs_resolver: &FsResolver) -> Result<()> {
char::init_in_first_process(fs_resolver)?;
block::init_in_first_process(fs_resolver)?;
pub(super) fn init_in_first_process(path_resolver: &PathResolver) -> Result<()> {
char::init_in_first_process(path_resolver)?;
block::init_in_first_process(path_resolver)?;
Ok(())
}

View File

@ -2,8 +2,7 @@
use crate::{
fs::{
fs_resolver::{FsPath, FsResolver},
path::PerMountFlags,
path::{FsPath, PathResolver, PerMountFlags},
ramfs::RamFs,
utils::{InodeType, chmod},
},
@ -11,10 +10,10 @@ use crate::{
};
/// Initializes "/dev/shm" for POSIX shared memory usage.
pub fn init_in_first_process(fs_resolver: &FsResolver, ctx: &Context) -> Result<()> {
pub fn init_in_first_process(path_resolver: &PathResolver, ctx: &Context) -> Result<()> {
use crate::fs::utils::InodeMode;
let dev_path = fs_resolver.lookup(&FsPath::try_from("/dev")?)?;
let dev_path = path_resolver.lookup(&FsPath::try_from("/dev")?)?;
// Create the "shm" directory under "/dev" and mount a ramfs on it.
let shm_path =

View File

@ -5,8 +5,7 @@ use device_id::DeviceId;
use super::inode_handle::FileIo;
use crate::{
fs::{
fs_resolver::{FsPath, FsResolver},
path::Path,
path::{FsPath, Path, PathResolver},
utils::{InodeType, MknodType, mkmod},
},
prelude::*,
@ -55,9 +54,9 @@ pub fn add_node(
dev_type: DeviceType,
dev_id: u64,
path: &str,
fs_resolver: &FsResolver,
path_resolver: &PathResolver,
) -> Result<Path> {
let mut dev_path = fs_resolver.lookup(&FsPath::try_from("/dev").unwrap())?;
let mut dev_path = path_resolver.lookup(&FsPath::try_from("/dev").unwrap())?;
let mut relative_path = {
let relative_path = path.trim_start_matches('/');
if relative_path.is_empty() {

View File

@ -9,7 +9,6 @@ pub mod exfat;
pub mod ext2;
pub mod file_handle;
pub mod file_table;
pub mod fs_resolver;
pub mod inode_handle;
pub mod notify;
pub mod overlayfs;
@ -28,7 +27,7 @@ pub mod utils;
use crate::{
fs::{
file_table::FdFlags,
fs_resolver::{FsPath, FsResolver},
path::{FsPath, PathResolver},
utils::{AccessMode, OpenArgs, mkmod},
},
prelude::*,
@ -57,19 +56,19 @@ pub fn init_on_each_cpu() {
procfs::init_on_each_cpu();
}
pub fn init_in_first_kthread(fs_resolver: &FsResolver) {
rootfs::init_in_first_kthread(fs_resolver).unwrap();
pub fn init_in_first_kthread(path_resolver: &PathResolver) {
rootfs::init_in_first_kthread(path_resolver).unwrap();
}
pub fn init_in_first_process(ctx: &Context) {
let fs = ctx.thread_local.borrow_fs();
let fs_resolver = fs.resolver().read();
let path_resolver = fs.resolver().read();
// Initialize the file table for the first process.
let tty_path = FsPath::try_from("/dev/console").unwrap();
let stdin = {
let open_args = OpenArgs::from_modes(AccessMode::O_RDONLY, mkmod!(u+r));
fs_resolver
path_resolver
.lookup(&tty_path)
.unwrap()
.open(open_args)
@ -77,7 +76,7 @@ pub fn init_in_first_process(ctx: &Context) {
};
let stdout = {
let open_args = OpenArgs::from_modes(AccessMode::O_WRONLY, mkmod!(u+w));
fs_resolver
path_resolver
.lookup(&tty_path)
.unwrap()
.open(open_args)
@ -85,7 +84,7 @@ pub fn init_in_first_process(ctx: &Context) {
};
let stderr = {
let open_args = OpenArgs::from_modes(AccessMode::O_WRONLY, mkmod!(u+w));
fs_resolver
path_resolver
.lookup(&tty_path)
.unwrap()
.open(open_args)

View File

@ -19,9 +19,8 @@ use ostd::{
use crate::{
fs::{
fs_resolver::FsPath,
inode_handle::FileIo,
path::Path,
path::{FsPath, Path},
registry::{FsProperties, FsType},
utils::{
AccessMode, DirentCounter, DirentVisitor, Extension, FallocMode, FileSystem,
@ -1180,14 +1179,18 @@ impl FsType for OverlayFsType {
let task = Task::current().unwrap();
let thread_local = task.as_thread_local().unwrap();
let fs_ref = thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let upper = fs.lookup(&FsPath::try_from(upper)?)?;
let upper = path_resolver.lookup(&FsPath::try_from(upper)?)?;
let lower = lower
.iter()
.map(|&lower| fs.lookup(&FsPath::try_from(lower).unwrap()).unwrap())
.map(|&lower| {
path_resolver
.lookup(&FsPath::try_from(lower).unwrap())
.unwrap()
})
.collect();
let work = fs.lookup(&FsPath::try_from(work)?)?;
let work = path_resolver.lookup(&FsPath::try_from(work)?)?;
OverlayFs::new(upper, lower, work).map(|fs| fs as _)
}

View File

@ -7,6 +7,7 @@ use core::time::Duration;
use inherit_methods_macro::inherit_methods;
pub use mount::{Mount, MountPropType, PerMountFlags};
pub use mount_namespace::MountNamespace;
pub use resolver::{AT_FDCWD, FsPath, LookupResult, PathResolver, SplitPath};
use crate::{
fs::{
@ -24,6 +25,7 @@ use crate::{
mod dentry;
mod mount;
mod mount_namespace;
mod resolver;
/// A `Path` is used to represent an exact location in the VFS tree.
///

View File

@ -4,8 +4,7 @@ use spin::Once;
use crate::{
fs::{
fs_resolver::FsResolver,
path::{Mount, Path},
path::{Mount, Path, PathResolver},
ramfs::RamFs,
},
prelude::*,
@ -54,10 +53,10 @@ impl MountNamespace {
///
/// The "effective root" refers to the currently visible root directory, which
/// may differ from the original root filesystem if overlay mounts exist.
pub fn new_fs_resolver(&self) -> FsResolver {
pub fn new_path_resolver(&self) -> PathResolver {
let root = Path::new_fs_root(self.root.clone()).get_top_path();
let cwd = Path::new_fs_root(self.root.clone()).get_top_path();
FsResolver::new(root, cwd)
PathResolver::new(root, cwd)
}
/// Creates a deep copy of this mount namespace, including the entire mount tree.

View File

@ -4,13 +4,13 @@ use alloc::str;
use ostd::task::Task;
use super::{
file_table::{FileDesc, get_file_fast},
path::Path,
utils::{InodeType, PATH_MAX, SYMLINKS_MAX},
};
use super::Path;
use crate::{
fs::{path::MountNamespace, utils::SymbolicLink},
fs::{
file_table::{FileDesc, get_file_fast},
path::MountNamespace,
utils::{InodeType, PATH_MAX, SYMLINKS_MAX, SymbolicLink},
},
prelude::*,
process::posix_thread::AsThreadLocal,
};
@ -20,13 +20,13 @@ pub const AT_FDCWD: FileDesc = -100;
/// File system resolver.
#[derive(Debug, Clone)]
pub struct FsResolver {
pub struct PathResolver {
root: Path,
cwd: Path,
}
impl FsResolver {
/// Creates a new `FsResolver` with the given `root` and `cwd`.
impl PathResolver {
/// Creates a new `PathResolver` with the given `root` and `cwd`.
pub(super) fn new(root: Path, cwd: Path) -> Self {
Self { root, cwd }
}
@ -51,7 +51,7 @@ impl FsResolver {
self.root = path;
}
/// Switches the `FsResolver` to the given mount namespace.
/// Switches the `PathResolver` to the given mount namespace.
///
/// If the target namespace already owns both the current root and working directory's
/// mount nodes, the operation is a no-op and returns immediately.

View File

@ -29,8 +29,8 @@ impl FileOps for MountInfoFileOps {
let posix_thread = thread.as_posix_thread().unwrap();
let fs = posix_thread.read_fs();
let fs_resolver = fs.resolver().read();
let root_mount = fs_resolver.root().mount_node();
let path_resolver = fs.resolver().read();
let root_mount = path_resolver.root().mount_node();
root_mount.read_mount_info(offset, writer)
}

View File

@ -7,7 +7,7 @@ use libflate::gzip::Decoder as GZipDecoder;
use ostd::boot::boot_info;
use super::{
fs_resolver::{FsPath, FsResolver},
path::{FsPath, PathResolver},
utils::{InodeMode, InodeType},
};
use crate::{fs::path::is_dot, prelude::*};
@ -27,7 +27,7 @@ impl Read for BoxedReader<'_> {
}
/// Unpack and prepare the rootfs from the initramfs CPIO buffer.
pub fn init_in_first_kthread(fs_resolver: &FsResolver) -> Result<()> {
pub fn init_in_first_kthread(path_resolver: &PathResolver) -> Result<()> {
let initramfs_buf = boot_info().initramfs.expect("No initramfs found!");
let reader = {
@ -73,9 +73,9 @@ pub fn init_in_first_kthread(fs_resolver: &FsResolver) -> Result<()> {
// The mkinitramfs script uses `find` command to ensure that the entries are
// sorted that a directory always appears before its child directories and files.
let (parent, name) = if let Some((prefix, last)) = entry_name.rsplit_once('/') {
(fs_resolver.lookup(&FsPath::try_from(prefix)?)?, last)
(path_resolver.lookup(&FsPath::try_from(prefix)?)?, last)
} else {
(fs_resolver.root().clone(), entry_name)
(path_resolver.root().clone(), entry_name)
};
let metadata = entry.metadata();

View File

@ -4,26 +4,26 @@ use core::sync::atomic::Ordering;
use ostd::sync::RwMutex;
use super::{fs_resolver::FsResolver, utils::AtomicFileCreationMask};
use super::{path::PathResolver, utils::AtomicFileCreationMask};
use crate::fs::utils::FileCreationMask;
/// FS information for a POSIX thread.
pub struct ThreadFsInfo {
resolver: RwMutex<FsResolver>,
resolver: RwMutex<PathResolver>,
umask: AtomicFileCreationMask,
}
impl ThreadFsInfo {
/// Creates a new `ThreadFsInfo` with the given [`FsResolver`].
pub fn new(fs_resolver: FsResolver) -> Self {
/// Creates a new `ThreadFsInfo` with the given [`PathResolver`].
pub fn new(path_resolver: PathResolver) -> Self {
Self {
resolver: RwMutex::new(fs_resolver),
resolver: RwMutex::new(path_resolver),
umask: AtomicFileCreationMask::new(FileCreationMask::default()),
}
}
/// Returns the associated `FsResolver`.
pub fn resolver(&self) -> &RwMutex<FsResolver> {
/// Returns the associated `PathResolver`.
pub fn resolver(&self) -> &RwMutex<PathResolver> {
&self.resolver
}

View File

@ -8,7 +8,7 @@ use ostd::{cpu::CpuId, util::id_set::Id};
use spin::once::Once;
use crate::{
fs::{fs_resolver::FsResolver, path::MountNamespace},
fs::path::{MountNamespace, PathResolver},
prelude::*,
process::{Process, spawn_init_process},
sched::SchedPolicy,
@ -137,7 +137,7 @@ fn first_kthread() {
println!("[kernel] Spawn the first kernel thread");
let init_mnt_ns = MountNamespace::get_init_singleton();
let fs_resolver = init_mnt_ns.new_fs_resolver();
let fs_resolver = init_mnt_ns.new_path_resolver();
init_in_first_kthread(&fs_resolver);
print_banner();
@ -155,14 +155,14 @@ fn first_kthread() {
static INIT_PROCESS: Once<Arc<Process>> = Once::new();
fn init_in_first_kthread(fs_resolver: &FsResolver) {
fn init_in_first_kthread(path_resolver: &PathResolver) {
component::init_all(InitStage::Kthread, component::parse_metadata!()).unwrap();
// Work queue should be initialized before interrupt is enabled,
// in case any irq handler uses work queue as bottom half
crate::thread::work_queue::init_in_first_kthread();
crate::device::init_in_first_kthread();
crate::net::init_in_first_kthread();
crate::fs::init_in_first_kthread(fs_resolver);
crate::fs::init_in_first_kthread(path_resolver);
crate::ipc::init_in_first_kthread();
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))]
crate::vdso::init_in_first_kthread();

View File

@ -4,8 +4,7 @@ use ostd::task::Task;
use crate::{
fs::{
fs_resolver::{FsPath, SplitPath},
path::Path,
path::{FsPath, Path, SplitPath},
utils::{InodeType, Permission, mkmod},
},
prelude::*,
@ -15,9 +14,9 @@ pub fn lookup_socket_file(path: &str) -> Result<Path> {
let path = {
let current = Task::current().unwrap();
let fs_ref = current.as_thread_local().unwrap().borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let fs_path = FsPath::try_from(path)?;
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
};
if path
@ -44,9 +43,9 @@ pub fn create_socket_file(path_name: &str) -> Result<Path> {
let parent = {
let current = Task::current().unwrap();
let fs_ref = current.as_thread_local().unwrap().borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let parent_path = FsPath::try_from(parent_path_name)?;
fs.lookup(&parent_path)?
path_resolver.lookup(&parent_path)?
};
parent

View File

@ -48,14 +48,14 @@ pub fn do_execve(
);
let fs_ref = ctx.thread_local.borrow_fs();
let fs_resolver = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let elf_inode = elf_file.inode();
let program_to_load =
ProgramToLoad::build_from_inode(elf_inode.clone(), &fs_resolver, argv, envp)?;
ProgramToLoad::build_from_inode(elf_inode.clone(), &path_resolver, argv, envp)?;
let new_vmar = Vmar::new(ProcessVm::new(elf_file.clone()));
let elf_load_info = program_to_load.load_to_vmar(new_vmar.as_ref(), &fs_resolver)?;
let elf_load_info = program_to_load.load_to_vmar(new_vmar.as_ref(), &path_resolver)?;
// Ensure no other thread is concurrently performing exit_group or execve.
// If such an operation is in progress, return EAGAIN.

View File

@ -170,7 +170,7 @@ impl ContextSetNsAdminApi for Context<'_> {
// other dependent fields of a posix thread may also need to be updated.
if !Arc::ptr_eq(&thread_local_ns_proxy.unwrap().mnt_ns, &ns_proxy.mnt_ns) {
*self.thread_local.borrow_fs().resolver().write() = ns_proxy.mnt_ns.new_fs_resolver();
*self.thread_local.borrow_fs().resolver().write() = ns_proxy.mnt_ns.new_path_resolver();
}
*pthread_ns_proxy = Some(ns_proxy.clone());

View File

@ -158,8 +158,8 @@ impl PosixThreadBuilder {
let user_ns = user_ns.unwrap_or_else(|| UserNamespace::get_init_singleton().clone());
let ns_proxy = ns_proxy.unwrap_or_else(|| NsProxy::get_init_singleton().clone());
let fs =
fs.unwrap_or_else(|| Arc::new(ThreadFsInfo::new(ns_proxy.mnt_ns().new_fs_resolver())));
let fs = fs
.unwrap_or_else(|| Arc::new(ThreadFsInfo::new(ns_proxy.mnt_ns().new_path_resolver())));
let vmar = process.upgrade().unwrap().lock_vmar().dup_vmar().unwrap();

View File

@ -7,8 +7,7 @@ use ostd::{arch::cpu::context::UserContext, task::Task, user::UserContextApi};
use super::Process;
use crate::{
fs::{
fs_resolver::FsPath,
path::{MountNamespace, Path},
path::{FsPath, MountNamespace, Path},
thread_info::ThreadFsInfo,
},
prelude::*,
@ -49,7 +48,7 @@ fn create_init_process(
envp: Vec<CString>,
) -> Result<Arc<Process>> {
let fs = {
let fs_resolver = MountNamespace::get_init_singleton().new_fs_resolver();
let fs_resolver = MountNamespace::get_init_singleton().new_path_resolver();
ThreadFsInfo::new(fs_resolver)
};
let fs_path = FsPath::try_from(executable_path)?;
@ -108,11 +107,11 @@ fn create_init_task(
let credentials = Credentials::new_root();
let elf_load_info = {
let fs_resolver = fs.resolver().read();
let path_resolver = fs.resolver().read();
let program_to_load =
ProgramToLoad::build_from_inode(elf_path.inode().clone(), &fs_resolver, argv, envp)?;
ProgramToLoad::build_from_inode(elf_path.inode().clone(), &path_resolver, argv, envp)?;
let vmar = process.lock_vmar();
program_to_load.load_to_vmar(vmar.unwrap(), &fs_resolver)?
program_to_load.load_to_vmar(vmar.unwrap(), &path_resolver)?
};
let mut user_ctx = UserContext::default();
user_ctx.set_instruction_pointer(elf_load_info.entry_point as _);

View File

@ -10,8 +10,7 @@ use super::{
};
use crate::{
fs::{
fs_resolver::{FsPath, FsResolver},
path::Path,
path::{FsPath, Path, PathResolver},
utils::Inode,
},
prelude::*,
@ -53,12 +52,12 @@ pub struct ElfLoadInfo {
pub fn load_elf_to_vmar(
vmar: &Vmar,
elf_inode: &Arc<dyn Inode>,
fs_resolver: &FsResolver,
path_resolver: &PathResolver,
elf_headers: ElfHeaders,
argv: Vec<CString>,
envp: Vec<CString>,
) -> Result<ElfLoadInfo> {
let ldso = lookup_and_parse_ldso(&elf_headers, elf_inode, fs_resolver)?;
let ldso = lookup_and_parse_ldso(&elf_headers, elf_inode, path_resolver)?;
#[cfg_attr(
not(any(target_arch = "x86_64", target_arch = "riscv64")),
@ -95,7 +94,7 @@ pub fn load_elf_to_vmar(
fn lookup_and_parse_ldso(
headers: &ElfHeaders,
elf_inode: &Arc<dyn Inode>,
fs_resolver: &FsResolver,
path_resolver: &PathResolver,
) -> Result<Option<(Path, ElfHeaders)>> {
let ldso_file = {
let ldso_path = if let Some(interp_phdr) = headers.interp_phdr() {
@ -113,7 +112,7 @@ fn lookup_and_parse_ldso(
})?;
let fs_path = FsPath::try_from(ldso_path.as_str())?;
fs_resolver.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
};
let ldso_elf = {

View File

@ -9,7 +9,7 @@ use self::{
};
use crate::{
fs::{
fs_resolver::{FsPath, FsResolver},
path::{FsPath, PathResolver},
utils::{Inode, InodeType, Permission},
},
prelude::*,
@ -32,7 +32,7 @@ impl ProgramToLoad {
/// necessary.
pub(super) fn build_from_inode(
mut elf_inode: Arc<dyn Inode>,
fs_resolver: &FsResolver,
path_resolver: &PathResolver,
mut argv: Vec<CString>,
envp: Vec<CString>,
) -> Result<Self> {
@ -64,7 +64,7 @@ impl ProgramToLoad {
let interpreter = {
let filename = new_argv[0].to_str()?.to_string();
let fs_path = FsPath::try_from(filename.as_str())?;
fs_resolver.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
};
check_executable_inode(interpreter.inode().as_ref())?;
@ -87,11 +87,15 @@ impl ProgramToLoad {
/// Loads the executable into the specified virtual memory space.
///
/// Returns the information about the ELF loading process.
pub(super) fn load_to_vmar(self, vmar: &Vmar, fs_resolver: &FsResolver) -> Result<ElfLoadInfo> {
pub(super) fn load_to_vmar(
self,
vmar: &Vmar,
path_resolver: &PathResolver,
) -> Result<ElfLoadInfo> {
let elf_load_info = load_elf_to_vmar(
vmar,
&self.elf_inode,
fs_resolver,
path_resolver,
self.elf_headers,
self.argv,
self.envp,

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::{PATH_MAX, Permission},
},
prelude::*,
@ -90,11 +90,11 @@ pub fn do_faccessat(
};
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(FaccessatFlags::AT_SYMLINK_NOFOLLOW) {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::{FileDesc, get_file_fast},
fs_resolver::FsPath,
path::FsPath,
utils::InodeType,
},
prelude::*,
@ -16,19 +16,19 @@ pub fn sys_chdir(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
debug!("path = {:?}", path_name);
let fs_ref = ctx.thread_local.borrow_fs();
let mut fs = fs_ref.resolver().write();
let mut path_resolver = fs_ref.resolver().write();
let path = {
let path_name = path_name.to_string_lossy();
if path_name.is_empty() {
return_errno_with_message!(Errno::ENOENT, "path is empty");
}
let fs_path = FsPath::try_from(path_name.as_ref())?;
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
};
if path.type_() != InodeType::Dir {
return_errno_with_message!(Errno::ENOTDIR, "must be directory");
}
fs.set_cwd(path);
path_resolver.set_cwd(path);
Ok(SyscallReturn::Return(0))
}

View File

@ -5,7 +5,7 @@ use crate::{
fs,
fs::{
file_table::{FileDesc, get_file_fast},
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::{InodeMode, PATH_MAX},
},
prelude::*,
@ -70,11 +70,11 @@ fn do_fchmodat(
};
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(ChmodFlags::AT_SYMLINK_NOFOLLOW) {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::{FileDesc, get_file_fast},
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::PATH_MAX,
},
prelude::*,
@ -78,11 +78,11 @@ pub fn sys_fchownat(
let fs_path = FsPath::from_fd_and_path(dirfd, &path_name)?;
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(ChownFlags::AT_SYMLINK_NOFOLLOW) {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};

View File

@ -2,7 +2,7 @@
use super::SyscallReturn;
use crate::{
fs::{fs_resolver::FsPath, utils::InodeType},
fs::{path::FsPath, utils::InodeType},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,
};
@ -12,19 +12,19 @@ pub fn sys_chroot(path_ptr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
debug!("path_name = {:?}", path_name);
let fs_ref = ctx.thread_local.borrow_fs();
let mut fs = fs_ref.resolver().write();
let mut path_resolver = fs_ref.resolver().write();
let path = {
let path_name = path_name.to_string_lossy();
if path_name.is_empty() {
return_errno_with_message!(Errno::ENOENT, "path is empty");
}
let fs_path = FsPath::try_from(path_name.as_ref())?;
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
};
if path.type_() != InodeType::Dir {
return_errno_with_message!(Errno::ENOTDIR, "must be directory");
}
fs.set_root(path);
path_resolver.set_root(path);
Ok(SyscallReturn::Return(0))
}

View File

@ -6,8 +6,7 @@ use super::{SyscallReturn, constants::*};
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::Path,
path::{AT_FDCWD, FsPath, Path},
},
prelude::*,
process::do_execve,
@ -67,11 +66,11 @@ fn lookup_executable_file(
};
let fs_ref = ctx.thread_local.borrow_fs();
let fs_resolver = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(OpenFlags::AT_SYMLINK_NOFOLLOW) {
fs_resolver.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs_resolver.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};

View File

@ -4,8 +4,8 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::{FdFlags, FileDesc, get_file_fast},
fs_resolver::FsPath,
notify::inotify::{InotifyControls, InotifyEvents, InotifyFile},
path::FsPath,
utils::{InodeType, Permission},
},
prelude::*,

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::InodeType,
},
prelude::*,
@ -42,18 +42,18 @@ pub fn sys_linkat(
let new_fs_path = FsPath::from_fd_and_path(new_dirfd, &new_path_name)?;
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let old_path = if flags.contains(LinkFlags::AT_SYMLINK_FOLLOW) {
fs.lookup(&old_fs_path)?
path_resolver.lookup(&old_fs_path)?
} else {
fs.lookup_no_follow(&old_fs_path)?
path_resolver.lookup_no_follow(&old_fs_path)?
};
if old_path.type_() == InodeType::Dir {
return_errno_with_message!(Errno::EPERM, "the link path is a directory");
}
let (new_path, new_name) = fs
let (new_path, new_name) = path_resolver
.lookup_unresolved_no_follow(&new_fs_path)?
.into_parent_and_filename()?;

View File

@ -5,7 +5,7 @@ use crate::{
fs,
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::{InodeMode, InodeType},
},
prelude::*,

View File

@ -5,7 +5,7 @@ use crate::{
fs::{
self,
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::{InodeMode, InodeType, MknodType},
},
prelude::*,

View File

@ -5,8 +5,7 @@ use device_id::DeviceId;
use super::SyscallReturn;
use crate::{
fs::{
fs_resolver::{AT_FDCWD, FsPath},
path::{MountPropType, Path, PerMountFlags},
path::{AT_FDCWD, FsPath, MountPropType, Path, PerMountFlags},
registry::FsProperties,
utils::{FileSystem, FsFlags, InodeType},
},

View File

@ -6,8 +6,8 @@ use crate::{
fs::{
file_handle::FileLike,
file_table::{FdFlags, FileDesc},
fs_resolver::{AT_FDCWD, FsPath, FsResolver, LookupResult},
inode_handle::InodeHandle,
path::{AT_FDCWD, FsPath, LookupResult, PathResolver},
utils::{AccessMode, CreationFlags, InodeMode, InodeType, OpenArgs, StatusFlags},
},
prelude::*,
@ -34,9 +34,9 @@ pub fn sys_openat(
let fs_ref = ctx.thread_local.borrow_fs();
let mask_mode = mode & !fs_ref.umask().get();
let fs_resolver = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
do_open(
&fs_resolver,
&path_resolver,
&fs_path,
flags,
InodeMode::from_bits_truncate(mask_mode),
@ -74,7 +74,7 @@ pub fn sys_creat(path_addr: Vaddr, mode: u16, ctx: &Context) -> Result<SyscallRe
}
fn do_open(
fs_resolver: &FsResolver,
path_resolver: &PathResolver,
fs_path: &FsPath,
flags: u32,
mode: InodeMode,
@ -82,9 +82,9 @@ fn do_open(
let open_args = OpenArgs::from_flags_and_mode(flags, mode)?;
let lookup_res = if open_args.follow_tail_link() {
fs_resolver.lookup_unresolved(fs_path)?
path_resolver.lookup_unresolved(fs_path)?
} else {
fs_resolver.lookup_unresolved_no_follow(fs_path)?
path_resolver.lookup_unresolved_no_follow(fs_path)?
};
let file_handle: Arc<dyn FileLike> = match lookup_res {

View File

@ -6,7 +6,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath, SplitPath},
path::{AT_FDCWD, FsPath, SplitPath},
utils::InodeType,
},
prelude::*,
@ -36,13 +36,13 @@ pub fn sys_renameat2(
}
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let old_path_name = old_path_name.to_string_lossy();
let (old_dir_path, old_name) = {
let (old_parent_path_name, old_name) = old_path_name.split_dirname_and_basename()?;
let old_fs_path = FsPath::from_fd_and_path(old_dirfd, old_parent_path_name)?;
(fs.lookup(&old_fs_path)?, old_name)
(path_resolver.lookup(&old_fs_path)?, old_name)
};
let old_path = old_dir_path.lookup(old_name)?;
if old_path.type_() != InodeType::Dir && old_path_name.ends_with('/') {
@ -56,7 +56,7 @@ pub fn sys_renameat2(
}
let (new_parent_path_name, new_name) = new_path_name.split_dirname_and_basename()?;
let new_fs_path = FsPath::from_fd_and_path(new_dirfd, new_parent_path_name)?;
(fs.lookup(&new_fs_path)?, new_name)
(path_resolver.lookup(&new_fs_path)?, new_name)
};
// Check the absolute path

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath, SplitPath},
path::{AT_FDCWD, FsPath, SplitPath},
},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,

View File

@ -8,8 +8,7 @@ use crate::{
fs::{
file_handle::FileLike,
file_table::{FileDesc, get_file_fast},
fs_resolver::{AT_FDCWD, FsPath},
path::Path,
path::{AT_FDCWD, FsPath, Path},
utils::{
XATTR_NAME_MAX_LEN, XATTR_VALUE_MAX_LEN, XattrName, XattrNamespace, XattrSetFlags,
},
@ -136,11 +135,11 @@ pub(super) fn lookup_path_for_xattr<'a>(
let path = path.to_string_lossy();
let fs_path = FsPath::from_fd_and_path(AT_FDCWD, &path)?;
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
let path = if symlink_no_follow {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
};
Ok(Cow::Owned(path))
};

View File

@ -6,7 +6,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::{FileDesc, get_file_fast},
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::Metadata,
},
prelude::*,
@ -65,11 +65,11 @@ pub fn sys_fstatat(
let fs_path = FsPath::from_fd_and_path(dirfd, &filename)?;
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(StatFlags::AT_SYMLINK_NOFOLLOW) {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};

View File

@ -6,7 +6,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::{FileDesc, get_file_fast},
fs_resolver::FsPath,
path::FsPath,
utils::{PATH_MAX, SuperBlock},
},
prelude::*,

View File

@ -6,7 +6,10 @@ use ostd::mm::VmIo;
use super::SyscallReturn;
use crate::{
fs::{file_table::FileDesc, fs_resolver::FsPath, path::Path},
fs::{
file_table::FileDesc,
path::{FsPath, Path},
},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,
};
@ -54,11 +57,11 @@ pub fn sys_statx(
};
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(StatxFlags::AT_SYMLINK_NOFOLLOW) {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};

View File

@ -5,7 +5,7 @@ use crate::{
fs,
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::{InodeType, mkmod},
},
prelude::*,

View File

@ -5,7 +5,7 @@ use crate::{
fs,
fs::{
file_table::{FileDesc, get_file_fast},
fs_resolver::{AT_FDCWD, FsPath},
path::{AT_FDCWD, FsPath},
utils::PATH_MAX,
},
prelude::*,

View File

@ -2,7 +2,7 @@
use super::SyscallReturn;
use crate::{
fs::fs_resolver::{AT_FDCWD, FsPath},
fs::path::{AT_FDCWD, FsPath},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,
};

View File

@ -4,7 +4,7 @@ use super::SyscallReturn;
use crate::{
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath, SplitPath},
path::{AT_FDCWD, FsPath, SplitPath},
},
prelude::*,
syscall::constants::MAX_FILENAME_LEN,

View File

@ -9,8 +9,7 @@ use crate::{
fs,
fs::{
file_table::FileDesc,
fs_resolver::{AT_FDCWD, FsPath},
path::Path,
path::{AT_FDCWD, FsPath, Path},
},
prelude::*,
time::{clocks::RealTimeCoarseClock, timespec_t, timeval_t},
@ -179,11 +178,11 @@ fn do_utimes(
};
let fs_ref = ctx.thread_local.borrow_fs();
let fs = fs_ref.resolver().read();
let path_resolver = fs_ref.resolver().read();
if flags.contains(UtimensFlags::AT_SYMLINK_NOFOLLOW) {
fs.lookup_no_follow(&fs_path)?
path_resolver.lookup_no_follow(&fs_path)?
} else {
fs.lookup(&fs_path)?
path_resolver.lookup(&fs_path)?
}
};