diff --git a/kernel/aster-nix/src/device/pty/mod.rs b/kernel/aster-nix/src/device/pty/mod.rs index 281cfc33b..22135e4a4 100644 --- a/kernel/aster-nix/src/device/pty/mod.rs +++ b/kernel/aster-nix/src/device/pty/mod.rs @@ -4,7 +4,7 @@ use crate::{ fs::{ devpts::DevPts, fs_resolver::{FsPath, FsResolver}, - utils::{Inode, InodeMode, InodeType, Path}, + utils::{DentryMnt, Inode, InodeMode, InodeType}, }, prelude::*, }; @@ -15,7 +15,7 @@ mod pty; pub use pty::{PtyMaster, PtySlave}; use spin::Once; -static DEV_PTS: Once> = Once::new(); +static DEV_PTS: Once> = Once::new(); pub fn init() -> Result<()> { let fs = FsResolver::new(); @@ -26,8 +26,8 @@ pub fn init() -> Result<()> { dev.dentry() .create("pts", InodeType::Dir, InodeMode::from_bits_truncate(0o755))?; let devpts_mount_node = - Path::new(dev.mount_node().clone(), devpts_dentry.clone()).mount(DevPts::new())?; - let devpts = Path::new( + DentryMnt::new(dev.mount_node().clone(), devpts_dentry.clone()).mount(DevPts::new())?; + let devpts = DentryMnt::new( devpts_mount_node.clone(), devpts_mount_node.root_dentry().clone(), ); diff --git a/kernel/aster-nix/src/fs/device.rs b/kernel/aster-nix/src/fs/device.rs index 5800e0be2..de3d7924c 100644 --- a/kernel/aster-nix/src/fs/device.rs +++ b/kernel/aster-nix/src/fs/device.rs @@ -85,11 +85,11 @@ impl From for u64 { /// If the parent path is not existing, `mkdir -p` the parent path. /// This function is used in registering device. pub fn add_node(device: Arc, pathname: &str) -> Result> { - let mut path = { + let mut dentrymnt = { let fs_resolver = FsResolver::new(); fs_resolver.lookup(&FsPath::try_from("/dev").unwrap())? }; - let mut dentry = path.dentry().clone(); + let mut dentry = dentrymnt.dentry().clone(); let mut relative_path = { let relative_path = pathname.trim_start_matches('/'); @@ -107,24 +107,24 @@ pub fn add_node(device: Arc, pathname: &str) -> Result> (relative_path, "") }; - match path.lookup(next_name) { - Ok(next_path) => { + match dentrymnt.lookup(next_name) { + Ok(next_dentrymnt) => { if path_remain.is_empty() { return_errno_with_message!(Errno::EEXIST, "device node is existing"); } - path = next_path; + dentrymnt = next_dentrymnt; } Err(_) => { if path_remain.is_empty() { // Create the device node - dentry = path.dentry().mknod( + dentry = dentrymnt.dentry().mknod( next_name, InodeMode::from_bits_truncate(0o666), device.clone(), )?; } else { // Mkdir parent path - dentry = path.dentry().create( + dentry = dentrymnt.dentry().create( next_name, InodeType::Dir, InodeMode::from_bits_truncate(0o755), @@ -150,11 +150,11 @@ pub fn delete_node(pathname: &str) -> Result<()> { String::from("/dev") + "/" + device_path }; - let (parent_path, name) = { + let (parent_dentrymnt, name) = { let fs_resolver = FsResolver::new(); fs_resolver.lookup_dir_and_base_name(&FsPath::try_from(abs_path.as_str()).unwrap())? }; - parent_path.dentry().unlink(&name)?; + parent_dentrymnt.dentry().unlink(&name)?; Ok(()) } diff --git a/kernel/aster-nix/src/fs/fs_resolver.rs b/kernel/aster-nix/src/fs/fs_resolver.rs index 2eea07b29..af46b02aa 100644 --- a/kernel/aster-nix/src/fs/fs_resolver.rs +++ b/kernel/aster-nix/src/fs/fs_resolver.rs @@ -7,15 +7,16 @@ use super::{ inode_handle::InodeHandle, rootfs::root_mount, utils::{ - AccessMode, CreationFlags, InodeMode, InodeType, Path, StatusFlags, PATH_MAX, SYMLINKS_MAX, + AccessMode, CreationFlags, DentryMnt, InodeMode, InodeType, StatusFlags, PATH_MAX, + SYMLINKS_MAX, }, }; use crate::prelude::*; #[derive(Debug)] pub struct FsResolver { - root: Arc, - cwd: Arc, + root: Arc, + cwd: Arc, } impl Clone for FsResolver { @@ -36,29 +37,29 @@ impl Default for FsResolver { impl FsResolver { pub fn new() -> Self { Self { - root: Path::new(root_mount().clone(), root_mount().root_dentry().clone()), - cwd: Path::new(root_mount().clone(), root_mount().root_dentry().clone()), + root: DentryMnt::new(root_mount().clone(), root_mount().root_dentry().clone()), + cwd: DentryMnt::new(root_mount().clone(), root_mount().root_dentry().clone()), } } /// Get the root directory - pub fn root(&self) -> &Arc { + pub fn root(&self) -> &Arc { &self.root } /// Get the current working directory - pub fn cwd(&self) -> &Arc { + pub fn cwd(&self) -> &Arc { &self.cwd } /// Set the current working directory. - pub fn set_cwd(&mut self, path: Arc) { - self.cwd = path; + pub fn set_cwd(&mut self, dentrymnt: Arc) { + self.cwd = dentrymnt; } /// Set the root directory - pub fn set_root(&mut self, path: Arc) { - self.root = path; + pub fn set_root(&mut self, dentrymnt: Arc) { + self.root = dentrymnt; } /// Open or create a file inode handler. @@ -71,9 +72,9 @@ impl FsResolver { let follow_tail_link = !(creation_flags.contains(CreationFlags::O_NOFOLLOW) || creation_flags.contains(CreationFlags::O_CREAT) && creation_flags.contains(CreationFlags::O_EXCL)); - let path = match self.lookup_inner(pathname, follow_tail_link) { - Ok(path) => { - let inode = path.dentry().inode(); + let dentrymnt = match self.lookup_inner(pathname, follow_tail_link) { + Ok(dentrymnt) => { + let inode = dentrymnt.dentry().inode(); if inode.type_() == InodeType::SymLink && creation_flags.contains(CreationFlags::O_NOFOLLOW) && !status_flags.contains(StatusFlags::O_PATH) @@ -93,7 +94,7 @@ impl FsResolver { "O_DIRECTORY is specified but file is not a directory" ); } - path + dentrymnt } Err(e) if e.error() == Errno::ENOENT @@ -102,39 +103,39 @@ impl FsResolver { if creation_flags.contains(CreationFlags::O_DIRECTORY) { return_errno_with_message!(Errno::ENOTDIR, "cannot create directory"); } - let (dir_path, file_name) = + let (dir_dentrymnt, file_name) = self.lookup_dir_and_base_name_inner(pathname, follow_tail_link)?; if file_name.ends_with('/') { return_errno_with_message!(Errno::EISDIR, "path refers to a directory"); } - if !dir_path.dentry().mode()?.is_writable() { + if !dir_dentrymnt.dentry().mode()?.is_writable() { return_errno_with_message!(Errno::EACCES, "file cannot be created"); } let dir_dentry = - dir_path + dir_dentrymnt .dentry() .create(&file_name, InodeType::File, inode_mode)?; - Path::new(dir_path.mount_node().clone(), dir_dentry.clone()) + DentryMnt::new(dir_dentrymnt.mount_node().clone(), dir_dentry.clone()) } Err(e) => return Err(e), }; - let inode_handle = InodeHandle::new(path, access_mode, status_flags)?; + let inode_handle = InodeHandle::new(dentrymnt, access_mode, status_flags)?; Ok(inode_handle) } - /// Lookup path according to FsPath, always follow symlinks - pub fn lookup(&self, pathname: &FsPath) -> Result> { + /// Lookup dentrymnt according to FsPath, always follow symlinks + pub fn lookup(&self, pathname: &FsPath) -> Result> { self.lookup_inner(pathname, true) } - /// Lookup path according to FsPath, do not follow it if last component is a symlink - pub fn lookup_no_follow(&self, pathname: &FsPath) -> Result> { + /// Lookup dentrymnt according to FsPath, do not follow it if last component is a symlink + pub fn lookup_no_follow(&self, pathname: &FsPath) -> Result> { self.lookup_inner(pathname, false) } - fn lookup_inner(&self, pathname: &FsPath, follow_tail_link: bool) -> Result> { - let path = match pathname.inner { + fn lookup_inner(&self, pathname: &FsPath, follow_tail_link: bool) -> Result> { + let dentrymnt = match pathname.inner { FsPathInner::Absolute(pathname) => self.lookup_from_parent( &self.root, pathname.trim_start_matches('/'), @@ -151,7 +152,7 @@ impl FsResolver { FsPathInner::Fd(fd) => self.lookup_from_fd(fd)?, }; - Ok(path) + Ok(dentrymnt) } /// Lookup dentry from parent @@ -167,10 +168,10 @@ impl FsResolver { /// Symlinks in earlier components of the path will always be followed. fn lookup_from_parent( &self, - parent: &Arc, + parent: &Arc, relative_path: &str, follow_tail_link: bool, - ) -> Result> { + ) -> Result> { debug_assert!(!relative_path.starts_with('/')); if relative_path.len() > PATH_MAX { @@ -181,8 +182,8 @@ impl FsResolver { let mut link_path = String::new(); let mut follows = 0; - // Initialize the first path and the relative path - let (mut path, mut relative_path) = (parent.clone(), relative_path); + // Initialize the first dentrymnt and the relative path + let (mut dentrymnt, mut relative_path) = (parent.clone(), relative_path); while !relative_path.is_empty() { let (next_name, path_remain, must_be_dir) = @@ -194,8 +195,8 @@ impl FsResolver { }; // Iterate next dentry - let next_path = path.lookup(next_name)?; - let next_dentry = next_path.dentry(); + let next_dentrymnt = dentrymnt.lookup(next_name)?; + let next_dentry = next_dentrymnt.dentry(); let next_type = next_dentry.type_(); let next_is_tail = path_remain.is_empty(); @@ -218,9 +219,9 @@ impl FsResolver { tmp_link_path }; - // Change the path and relative path according to symlink + // Change the dentrymnt and relative path according to symlink if link_path_remain.starts_with('/') { - path = self.root.clone(); + dentrymnt = self.root.clone(); } link_path.clear(); link_path.push_str(link_path_remain.trim_start_matches('/')); @@ -231,12 +232,12 @@ impl FsResolver { if must_be_dir && next_type != InodeType::Dir { return_errno_with_message!(Errno::ENOTDIR, "inode is not dir"); } - path = next_path; + dentrymnt = next_dentrymnt; relative_path = path_remain; } } - Ok(path) + Ok(dentrymnt) } /// Lookup dentry from the giving fd @@ -247,13 +248,13 @@ impl FsResolver { .get_file(fd)? .downcast_ref::() .ok_or(Error::with_message(Errno::EBADF, "not inode"))?; - Ok(inode_handle.path().clone()) + Ok(inode_handle.dentrymnt().clone()) } - /// Lookup the dir path and base file name of the giving pathname. + /// Lookup the dir dentrymnt and base file name of the giving pathname. /// /// If the last component is a symlink, do not deference it - pub fn lookup_dir_and_base_name(&self, pathname: &FsPath) -> Result<(Arc, String)> { + pub fn lookup_dir_and_base_name(&self, pathname: &FsPath) -> Result<(Arc, String)> { self.lookup_dir_and_base_name_inner(pathname, false) } @@ -261,8 +262,8 @@ impl FsResolver { &self, pathname: &FsPath, follow_tail_link: bool, - ) -> Result<(Arc, String)> { - let (mut dir_path, mut base_name) = match pathname.inner { + ) -> Result<(Arc, String)> { + let (mut dir_dentrymnt, mut base_name) = match pathname.inner { FsPathInner::Absolute(pathname) => { let (dir, file_name) = split_path(pathname); ( @@ -288,15 +289,15 @@ impl FsResolver { _ => return_errno!(Errno::ENOENT), }; if !follow_tail_link { - return Ok((dir_path, base_name)); + return Ok((dir_dentrymnt, base_name)); } // Dereference the tail symlinks if needed loop { - match dir_path.lookup(base_name.trim_end_matches('/')) { - Ok(path) if path.dentry().type_() == InodeType::SymLink => { + match dir_dentrymnt.lookup(base_name.trim_end_matches('/')) { + Ok(dentrymnt) if dentrymnt.dentry().type_() == InodeType::SymLink => { let link = { - let mut link = path.dentry().inode().read_link()?; + let mut link = dentrymnt.dentry().inode().read_link()?; if link.is_empty() { return_errno_with_message!(Errno::ENOENT, "invalid symlink"); } @@ -307,11 +308,11 @@ impl FsResolver { }; let (dir, file_name) = split_path(&link); if dir.starts_with('/') { - dir_path = + dir_dentrymnt = self.lookup_from_parent(&self.root, dir.trim_start_matches('/'), true)?; base_name = String::from(file_name); } else { - dir_path = self.lookup_from_parent(&dir_path, dir, true)?; + dir_dentrymnt = self.lookup_from_parent(&dir_dentrymnt, dir, true)?; base_name = String::from(file_name); } } @@ -319,7 +320,7 @@ impl FsResolver { } } - Ok((dir_path, base_name)) + Ok((dir_dentrymnt, base_name)) } } diff --git a/kernel/aster-nix/src/fs/inode_handle/dyn_cap.rs b/kernel/aster-nix/src/fs/inode_handle/dyn_cap.rs index 497aef45a..15c4cc01f 100644 --- a/kernel/aster-nix/src/fs/inode_handle/dyn_cap.rs +++ b/kernel/aster-nix/src/fs/inode_handle/dyn_cap.rs @@ -8,11 +8,11 @@ use crate::prelude::*; impl InodeHandle { pub fn new( - path: Arc, + dentrymnt: Arc, access_mode: AccessMode, status_flags: StatusFlags, ) -> Result { - let inode = path.dentry().inode(); + let inode = dentrymnt.dentry().inode(); if access_mode.is_readable() && !inode.mode()?.is_readable() { return_errno_with_message!(Errno::EACCES, "File is not readable"); } @@ -30,7 +30,7 @@ impl InodeHandle { }; let inner = Arc::new(InodeHandle_ { - path, + dentrymnt, file_io, offset: Mutex::new(0), access_mode, @@ -116,6 +116,6 @@ impl FileLike for InodeHandle { } fn as_device(&self) -> Option> { - self.0.path.dentry().inode().as_device() + self.0.dentrymnt.dentry().inode().as_device() } } diff --git a/kernel/aster-nix/src/fs/inode_handle/mod.rs b/kernel/aster-nix/src/fs/inode_handle/mod.rs index f48b044c0..6ce505614 100644 --- a/kernel/aster-nix/src/fs/inode_handle/mod.rs +++ b/kernel/aster-nix/src/fs/inode_handle/mod.rs @@ -16,8 +16,8 @@ use crate::{ device::Device, file_handle::FileLike, utils::{ - AccessMode, DirentVisitor, InodeMode, InodeType, IoctlCmd, Metadata, Path, SeekFrom, - StatusFlags, + AccessMode, DentryMnt, DirentVisitor, InodeMode, InodeType, IoctlCmd, Metadata, + SeekFrom, StatusFlags, }, }, prelude::*, @@ -28,7 +28,7 @@ use crate::{ pub struct InodeHandle(Arc, R); struct InodeHandle_ { - path: Arc, + dentrymnt: Arc, /// `file_io` is Similar to `file_private` field in `file` structure in linux. If /// `file_io` is Some, typical file operations including `read`, `write`, `poll`, /// `ioctl` will be provided by `file_io`, instead of `dentry`. @@ -47,9 +47,12 @@ impl InodeHandle_ { } let len = if self.status_flags().contains(StatusFlags::O_DIRECT) { - self.path.dentry().inode().read_direct_at(*offset, buf)? + self.dentrymnt + .dentry() + .inode() + .read_direct_at(*offset, buf)? } else { - self.path.dentry().inode().read_at(*offset, buf)? + self.dentrymnt.dentry().inode().read_at(*offset, buf)? }; *offset += len; @@ -64,12 +67,15 @@ impl InodeHandle_ { } if self.status_flags().contains(StatusFlags::O_APPEND) { - *offset = self.path.dentry().size(); + *offset = self.dentrymnt.dentry().size(); } let len = if self.status_flags().contains(StatusFlags::O_DIRECT) { - self.path.dentry().inode().write_direct_at(*offset, buf)? + self.dentrymnt + .dentry() + .inode() + .write_direct_at(*offset, buf)? } else { - self.path.dentry().inode().write_at(*offset, buf)? + self.dentrymnt.dentry().inode().write_at(*offset, buf)? }; *offset += len; @@ -82,9 +88,9 @@ impl InodeHandle_ { } let len = if self.status_flags().contains(StatusFlags::O_DIRECT) { - self.path.dentry().inode().read_direct_all(buf)? + self.dentrymnt.dentry().inode().read_direct_all(buf)? } else { - self.path.dentry().inode().read_all(buf)? + self.dentrymnt.dentry().inode().read_all(buf)? }; Ok(len) } @@ -99,7 +105,7 @@ impl InodeHandle_ { off as isize } SeekFrom::End(off /* as isize */) => { - let file_size = self.path.dentry().size() as isize; + let file_size = self.dentrymnt.dentry().size() as isize; assert!(file_size >= 0); file_size .checked_add(off) @@ -127,7 +133,7 @@ impl InodeHandle_ { if self.status_flags().contains(StatusFlags::O_APPEND) { return_errno_with_message!(Errno::EPERM, "can not resize append-only file"); } - self.path.dentry().resize(new_size) + self.dentrymnt.dentry().resize(new_size) } pub fn access_mode(&self) -> AccessMode { @@ -146,7 +152,11 @@ impl InodeHandle_ { pub fn readdir(&self, visitor: &mut dyn DirentVisitor) -> Result { let mut offset = self.offset.lock(); - let read_cnt = self.path.dentry().inode().readdir_at(*offset, visitor)?; + let read_cnt = self + .dentrymnt + .dentry() + .inode() + .readdir_at(*offset, visitor)?; *offset += read_cnt; Ok(read_cnt) } @@ -156,7 +166,7 @@ impl InodeHandle_ { return file_io.poll(mask, poller); } - self.path.dentry().inode().poll(mask, poller) + self.dentrymnt.dentry().inode().poll(mask, poller) } fn ioctl(&self, cmd: IoctlCmd, arg: usize) -> Result { @@ -164,11 +174,11 @@ impl InodeHandle_ { return file_io.ioctl(cmd, arg); } - self.path.dentry().inode().ioctl(cmd, arg) + self.dentrymnt.dentry().inode().ioctl(cmd, arg) } } -#[inherit_methods(from = "self.path.dentry()")] +#[inherit_methods(from = "self.dentrymnt.dentry()")] impl InodeHandle_ { pub fn size(&self) -> usize; pub fn metadata(&self) -> Metadata; @@ -183,7 +193,7 @@ impl InodeHandle_ { impl Debug for InodeHandle_ { fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { f.debug_struct("InodeHandle_") - .field("path", &self.path) + .field("dentrymnt", &self.dentrymnt) .field("offset", &self.offset()) .field("access_mode", &self.access_mode()) .field("status_flags", &self.status_flags()) @@ -193,8 +203,8 @@ impl Debug for InodeHandle_ { /// Methods for both dyn and static impl InodeHandle { - pub fn path(&self) -> &Arc { - &self.0.path + pub fn dentrymnt(&self) -> &Arc { + &self.0.dentrymnt } } diff --git a/kernel/aster-nix/src/fs/procfs/pid/fd.rs b/kernel/aster-nix/src/fs/procfs/pid/fd.rs index 47395103e..c3bbcc818 100644 --- a/kernel/aster-nix/src/fs/procfs/pid/fd.rs +++ b/kernel/aster-nix/src/fs/procfs/pid/fd.rs @@ -77,7 +77,7 @@ impl FileSymOps { impl SymOps for FileSymOps { fn read_link(&self) -> Result { let pathname = if let Some(inode_handle) = self.0.downcast_ref::() { - inode_handle.path().abs_path() + inode_handle.dentrymnt().abs_path() } else { // TODO: get the real path for other FileLike object String::from("/dev/tty") diff --git a/kernel/aster-nix/src/fs/rootfs.rs b/kernel/aster-nix/src/fs/rootfs.rs index 41c30c7bd..27d676772 100644 --- a/kernel/aster-nix/src/fs/rootfs.rs +++ b/kernel/aster-nix/src/fs/rootfs.rs @@ -75,11 +75,11 @@ pub fn init(initramfs_buf: &[u8]) -> Result<()> { } } // Mount ProcFS - let proc_path = fs.lookup(&FsPath::try_from("/proc")?)?; - proc_path.mount(ProcFS::new())?; + let proc_dentrymnt = fs.lookup(&FsPath::try_from("/proc")?)?; + proc_dentrymnt.mount(ProcFS::new())?; // Mount DevFS - let dev_path = fs.lookup(&FsPath::try_from("/dev")?)?; - dev_path.mount(RamFS::new())?; + let dev_dentrymnt = fs.lookup(&FsPath::try_from("/dev")?)?; + dev_dentrymnt.mount(RamFS::new())?; println!("[kernel] rootfs is ready"); @@ -87,8 +87,8 @@ pub fn init(initramfs_buf: &[u8]) -> Result<()> { } pub fn mount_fs_at(fs: Arc, fs_path: &FsPath) -> Result<()> { - let target_path = FsResolver::new().lookup(fs_path)?; - target_path.mount(fs)?; + let target_dentrymnt = FsResolver::new().lookup(fs_path)?; + target_dentrymnt.mount(fs)?; Ok(()) } diff --git a/kernel/aster-nix/src/fs/utils/path.rs b/kernel/aster-nix/src/fs/utils/dentrymnt.rs similarity index 78% rename from kernel/aster-nix/src/fs/utils/path.rs rename to kernel/aster-nix/src/fs/utils/dentrymnt.rs index 8a247504e..9d9efc66e 100644 --- a/kernel/aster-nix/src/fs/utils/path.rs +++ b/kernel/aster-nix/src/fs/utils/dentrymnt.rs @@ -3,15 +3,15 @@ use super::{Dentry, FileSystem, InodeType, MountNode, NAME_MAX}; use crate::prelude::*; -/// The Path can represent a location in the mount tree. +/// The DentryMnt can represent a location in the mount tree. #[derive(Debug)] -pub struct Path { +pub struct DentryMnt { mount_node: Arc, dentry: Arc, - this: Weak, + this: Weak, } -impl Path { +impl DentryMnt { pub fn new(mount_node: Arc, dentry: Arc) -> Arc { Arc::new_cyclic(|weak_self| Self { mount_node, @@ -20,7 +20,7 @@ impl Path { }) } - /// Lookup a path. + /// Lookup a dentrymnt. pub fn lookup(&self, name: &str) -> Result> { if self.dentry.inode().type_() != InodeType::Dir { return_errno!(Errno::ENOTDIR); @@ -32,22 +32,22 @@ impl Path { return_errno!(Errno::ENAMETOOLONG); } - let path = match name { + let dentrymnt = match name { "." => self.this(), ".." => self.effective_parent().unwrap_or(self.this()), name => { let children_dentry = self.dentry.lookup_fast(name); match children_dentry { - Some(dentry) => Path::new(self.mount_node().clone(), dentry.clone()), + Some(dentry) => Self::new(self.mount_node().clone(), dentry.clone()), None => { let slow_dentry = self.dentry.lookup_slow(name)?; - Path::new(self.mount_node().clone(), slow_dentry.clone()) + Self::new(self.mount_node().clone(), slow_dentry.clone()) } } } }; - let path = path.overlaid_path(); - Ok(path) + let dentrymnt = dentrymnt.overlaid_dentrymnt(); + Ok(dentrymnt) } // Get the absolute path. @@ -55,21 +55,21 @@ impl Path { // It will resolve the mountpoint automatically. pub fn abs_path(&self) -> String { let mut path = self.effective_name(); - let mut dir_path = self.this(); + let mut dir_dentrymnt = self.this(); loop { - match dir_path.effective_parent() { + match dir_dentrymnt.effective_parent() { None => break, - Some(parent_dir_path) => { + Some(parent_dir_dentrymnt) => { path = { - let parent_name = parent_dir_path.effective_name(); + let parent_name = parent_dir_dentrymnt.effective_name(); if parent_name != "/" { parent_name + "/" + &path } else { parent_name + &path } }; - dir_path = parent_dir_path; + dir_dentrymnt = parent_dir_dentrymnt; } } } @@ -77,7 +77,7 @@ impl Path { path } - /// Get the effective name of path. + /// Get the effective name of dentrymnt. /// /// If it is the root of mount, it will go up to the mountpoint to get the name /// of the mountpoint recursively. @@ -87,54 +87,53 @@ impl Path { } if self.mount_node.parent().is_some() & self.mount_node.mountpoint_dentry().is_some() { - let parent_path = Path::new( + let parent_dentrymnt = Self::new( self.mount_node.parent().unwrap().upgrade().unwrap().clone(), self.mount_node.mountpoint_dentry().unwrap().clone(), ); - parent_path.effective_name() + parent_dentrymnt.effective_name() } else { self.dentry.name() } } - /// Get the effective parent of path. + /// Get the effective parent of dentrymnt. /// /// If it is the root of mount, it will go up to the mountpoint to get the parent /// of the mountpoint recursively. fn effective_parent(&self) -> Option> { if !self.dentry.is_root_of_mount() { - return Some(Path::new( + return Some(Self::new( self.mount_node.clone(), self.dentry.parent().unwrap().clone(), )); } if self.mount_node.parent().is_some() & self.mount_node.mountpoint_dentry().is_some() { - let parent_path = Path::new( + let parent_dentrymnt = Self::new( self.mount_node.parent().unwrap().upgrade().unwrap().clone(), self.mount_node.mountpoint_dentry().unwrap().clone(), ); - parent_path.effective_parent() + parent_dentrymnt.effective_parent() } else { None } } - /// Get the overlaid path of self. + /// Get the overlaid dentrymnt of self. /// /// It will jump into the child mount if it is a mountpoint. - fn overlaid_path(&self) -> Arc { + fn overlaid_dentrymnt(&self) -> Arc { if !self.dentry.is_mountpoint() { return self.this(); } match self.mount_node.get(self) { - Some(child_mount) => { - Path::new(child_mount.clone(), child_mount.root_dentry().clone()).overlaid_path() - } + Some(child_mount) => Self::new(child_mount.clone(), child_mount.root_dentry().clone()) + .overlaid_dentrymnt(), None => self.this(), } } - /// Mount the fs on this path. It will make this path's dentry to be a mountpoint. + /// Mount the fs on this dentrymnt. It will make this dentrymnt's dentry to be a mountpoint. /// /// If the given mountpoint has already been mounted, then its mounted child mount /// will be updated. @@ -167,14 +166,15 @@ impl Path { }; let mountpoint_mount_node = mount_node.parent().unwrap().upgrade().unwrap(); - let mountpoint_path = Path::new(mountpoint_mount_node.clone(), mountpoint_dentry.clone()); + let mountpoint_dentrymnt = + Self::new(mountpoint_mount_node.clone(), mountpoint_dentry.clone()); - let child_mount = mountpoint_mount_node.umount(&mountpoint_path)?; + let child_mount = mountpoint_mount_node.umount(&mountpoint_dentrymnt)?; mountpoint_dentry.clear_mountpoint(); Ok(child_mount) } - /// Link a new name for the path's dentry by linking inode. + /// Link a new name for the dentrymnt's dentry by linking inode. pub fn link(&self, old: &Arc, name: &str) -> Result<()> { if self.dentry.inode().type_() != InodeType::Dir { return_errno!(Errno::ENOTDIR); @@ -198,12 +198,12 @@ impl Path { self.this.upgrade().unwrap() } - /// Get the mount node of this path. + /// Get the mount node of this dentrymnt. pub fn mount_node(&self) -> &Arc { &self.mount_node } - /// Get the dentry of this path. + /// Get the dentry of this dentrymnt. pub fn dentry(&self) -> &Arc { &self.dentry } diff --git a/kernel/aster-nix/src/fs/utils/mod.rs b/kernel/aster-nix/src/fs/utils/mod.rs index 734d696f5..6ca2b7d6c 100644 --- a/kernel/aster-nix/src/fs/utils/mod.rs +++ b/kernel/aster-nix/src/fs/utils/mod.rs @@ -6,6 +6,7 @@ pub use access_mode::AccessMode; pub use channel::{Channel, Consumer, Producer}; pub use creation_flags::CreationFlags; pub use dentry::{Dentry, DentryKey}; +pub use dentrymnt::DentryMnt; pub use dirent_visitor::DirentVisitor; pub use direntry_vec::DirEntryVecExt; pub use file_creation_mask::FileCreationMask; @@ -14,7 +15,6 @@ pub use inode::{Inode, InodeMode, InodeType, Metadata}; pub use ioctl::IoctlCmd; pub use mount::MountNode; pub use page_cache::{PageCache, PageCacheBackend}; -pub use path::Path; pub use random_test::{generate_random_operation, new_fs_in_memory}; pub use status_flags::StatusFlags; @@ -22,6 +22,7 @@ mod access_mode; mod channel; mod creation_flags; mod dentry; +mod dentrymnt; mod dirent_visitor; mod direntry_vec; mod file_creation_mask; @@ -30,7 +31,6 @@ mod inode; mod ioctl; mod mount; mod page_cache; -mod path; mod random_test; mod status_flags; diff --git a/kernel/aster-nix/src/fs/utils/mount.rs b/kernel/aster-nix/src/fs/utils/mount.rs index cc92269b9..7054d6aac 100644 --- a/kernel/aster-nix/src/fs/utils/mount.rs +++ b/kernel/aster-nix/src/fs/utils/mount.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use super::{Dentry, DentryKey, FileSystem, InodeType, Path}; +use super::{Dentry, DentryKey, DentryMnt, FileSystem, InodeType}; use crate::prelude::*; /// The MountNode can form a mount tree to maintain the mount information. @@ -61,7 +61,7 @@ impl MountNode { /// mountpoint. It is the fs's responsibility to ensure the data consistency. /// /// Return the mounted child mount. - pub fn mount(&self, fs: Arc, mountpoint: &Arc) -> Result> { + pub fn mount(&self, fs: Arc, mountpoint: &Arc) -> Result> { if !Arc::ptr_eq(mountpoint.mount_node(), &self.this()) { return_errno_with_message!(Errno::EINVAL, "mountpoint not belongs to this"); } @@ -82,7 +82,7 @@ impl MountNode { /// Unmount a child mount node from the mountpoint and return it. /// /// The mountpoint should belong to this mount node, or an error is returned. - pub fn umount(&self, mountpoint: &Path) -> Result> { + pub fn umount(&self, mountpoint: &DentryMnt) -> Result> { if !Arc::ptr_eq(mountpoint.mount_node(), &self.this()) { return_errno_with_message!(Errno::EINVAL, "mountpoint not belongs to this"); } @@ -96,7 +96,7 @@ impl MountNode { } /// Try to get a child mount node from the mountpoint. - pub fn get(&self, mountpoint: &Path) -> Option> { + pub fn get(&self, mountpoint: &DentryMnt) -> Option> { if !Arc::ptr_eq(mountpoint.mount_node(), &self.this()) { return None; } diff --git a/kernel/aster-nix/src/net/socket/unix/addr.rs b/kernel/aster-nix/src/net/socket/unix/addr.rs index 675d2e4f8..bfc36382b 100644 --- a/kernel/aster-nix/src/net/socket/unix/addr.rs +++ b/kernel/aster-nix/src/net/socket/unix/addr.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MPL-2.0 -use crate::{fs::utils::Path, net::socket::util::socket_addr::SocketAddr, prelude::*}; +use crate::{fs::utils::DentryMnt, net::socket::util::socket_addr::SocketAddr, prelude::*}; #[derive(Clone, Debug, PartialEq, Eq)] pub enum UnixSocketAddr { @@ -10,7 +10,7 @@ pub enum UnixSocketAddr { #[derive(Clone)] pub(super) enum UnixSocketAddrBound { - Path(Arc), + Path(Arc), Abstract(String), } @@ -40,8 +40,8 @@ impl TryFrom for UnixSocketAddr { impl From for UnixSocketAddr { fn from(value: UnixSocketAddrBound) -> Self { match value { - UnixSocketAddrBound::Path(path) => { - let abs_path = path.abs_path(); + UnixSocketAddrBound::Path(dentrymnt) => { + let abs_path = dentrymnt.abs_path(); Self::Path(abs_path) } UnixSocketAddrBound::Abstract(name) => Self::Abstract(name), diff --git a/kernel/aster-nix/src/net/socket/unix/stream/init.rs b/kernel/aster-nix/src/net/socket/unix/stream/init.rs index fe6b1ce58..107387c65 100644 --- a/kernel/aster-nix/src/net/socket/unix/stream/init.rs +++ b/kernel/aster-nix/src/net/socket/unix/stream/init.rs @@ -7,7 +7,7 @@ use crate::{ events::IoEvents, fs::{ fs_resolver::{split_path, FsPath}, - utils::{InodeMode, InodeType, Path}, + utils::{DentryMnt, InodeMode, InodeType}, }, net::socket::unix::addr::{UnixSocketAddr, UnixSocketAddrBound}, prelude::*, @@ -38,8 +38,8 @@ impl Init { let bound_addr = match addr_to_bind { UnixSocketAddr::Abstract(_) => todo!(), UnixSocketAddr::Path(pathname) => { - let path = create_socket_file(pathname)?; - UnixSocketAddrBound::Path(path) + let dentrymnt = create_socket_file(pathname)?; + UnixSocketAddrBound::Path(dentrymnt) } }; @@ -87,7 +87,7 @@ impl Init { } } -fn create_socket_file(pathname: &str) -> Result> { +fn create_socket_file(pathname: &str) -> Result> { let (parent_pathname, file_name) = split_path(pathname); let parent = { let current = current!(); @@ -100,6 +100,6 @@ fn create_socket_file(pathname: &str) -> Result> { InodeType::Socket, InodeMode::S_IRUSR | InodeMode::S_IWUSR, )?; - let path = Path::new(parent.mount_node().clone(), dentry.clone()); - Ok(path) + let dentrymnt = DentryMnt::new(parent.mount_node().clone(), dentry.clone()); + Ok(dentrymnt) } diff --git a/kernel/aster-nix/src/net/socket/unix/stream/listener.rs b/kernel/aster-nix/src/net/socket/unix/stream/listener.rs index a2173a938..433e0a5b4 100644 --- a/kernel/aster-nix/src/net/socket/unix/stream/listener.rs +++ b/kernel/aster-nix/src/net/socket/unix/stream/listener.rs @@ -9,7 +9,7 @@ use crate::{ events::IoEvents, fs::{ file_handle::FileLike, - utils::{Inode, Path}, + utils::{DentryMnt, Inode}, }, net::socket::{ unix::addr::{UnixSocketAddr, UnixSocketAddrBound}, @@ -91,10 +91,10 @@ impl BacklogTable { fn add_backlog(&self, addr: &UnixSocketAddrBound, backlog: usize) -> Result<()> { let inode = { - let UnixSocketAddrBound::Path(path) = addr else { + let UnixSocketAddrBound::Path(dentrymnt) = addr else { todo!() }; - create_keyable_inode(path) + create_keyable_inode(dentrymnt) }; let mut backlog_sockets = self.backlog_sockets.write(); @@ -108,10 +108,10 @@ impl BacklogTable { fn get_backlog(&self, addr: &UnixSocketAddrBound) -> Result> { let inode = { - let UnixSocketAddrBound::Path(path) = addr else { + let UnixSocketAddrBound::Path(dentrymnt) = addr else { todo!() }; - create_keyable_inode(path) + create_keyable_inode(dentrymnt) }; let backlog_sockets = self.backlog_sockets.read(); @@ -162,11 +162,11 @@ impl BacklogTable { } fn remove_backlog(&self, addr: &UnixSocketAddrBound) { - let UnixSocketAddrBound::Path(dentry) = addr else { + let UnixSocketAddrBound::Path(dentrymnt) = addr else { todo!() }; - let inode = create_keyable_inode(dentry); + let inode = create_keyable_inode(dentrymnt); self.backlog_sockets.write().remove(&inode); } } @@ -212,8 +212,8 @@ impl Backlog { } } -fn create_keyable_inode(path: &Arc) -> KeyableWeak { - let weak_inode = Arc::downgrade(path.dentry().inode()); +fn create_keyable_inode(dentrymnt: &Arc) -> KeyableWeak { + let weak_inode = Arc::downgrade(dentrymnt.dentry().inode()); KeyableWeak::from(weak_inode) } diff --git a/kernel/aster-nix/src/net/socket/unix/stream/socket.rs b/kernel/aster-nix/src/net/socket/unix/stream/socket.rs index 4632bd849..645c5bc3a 100644 --- a/kernel/aster-nix/src/net/socket/unix/stream/socket.rs +++ b/kernel/aster-nix/src/net/socket/unix/stream/socket.rs @@ -11,7 +11,7 @@ use crate::{ fs::{ file_handle::FileLike, fs_resolver::FsPath, - utils::{InodeType, Path, StatusFlags}, + utils::{DentryMnt, InodeType, StatusFlags}, }, net::socket::{ unix::{addr::UnixSocketAddrBound, UnixSocketAddr}, @@ -162,8 +162,8 @@ impl Socket for UnixStreamSocket { UnixSocketAddrBound::Abstract(abstract_name) } UnixSocketAddr::Path(pathname) => { - let path = lookup_socket_file(&pathname)?; - UnixSocketAddrBound::Path(path) + let dentrymnt = lookup_socket_file(&pathname)?; + UnixSocketAddrBound::Path(dentrymnt) } } }; @@ -287,20 +287,20 @@ impl Drop for UnixStreamSocket { } } -fn lookup_socket_file(pathname: &str) -> Result> { - let path = { +fn lookup_socket_file(pathname: &str) -> Result> { + let dentrymnt = { let current = current!(); let fs = current.fs().read(); let fs_path = FsPath::try_from(pathname)?; fs.lookup(&fs_path)? }; - if path.dentry().type_() != InodeType::Socket { + if dentrymnt.dentry().type_() != InodeType::Socket { return_errno_with_message!(Errno::ENOTSOCK, "not a socket file") } - if !path.dentry().mode()?.is_readable() || !path.dentry().mode()?.is_writable() { + if !dentrymnt.dentry().mode()?.is_readable() || !dentrymnt.dentry().mode()?.is_writable() { return_errno_with_message!(Errno::EACCES, "the socket cannot be read or written") } - Ok(path) + Ok(dentrymnt) } diff --git a/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs b/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs index 297debd4b..33f7bcc2d 100644 --- a/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs +++ b/kernel/aster-nix/src/process/program_loader/elf/load_elf.rs @@ -12,7 +12,7 @@ use super::elf_file::Elf; use crate::{ fs::{ fs_resolver::{FsPath, FsResolver, AT_FDCWD}, - utils::{Dentry, Path}, + utils::{Dentry, DentryMnt}, }, prelude::*, process::{ @@ -35,7 +35,7 @@ use crate::{ pub fn load_elf_to_vm( process_vm: &ProcessVm, file_header: &[u8], - elf_file: Arc, + elf_file: Arc, fs_resolver: &FsResolver, argv: Vec, envp: Vec, diff --git a/kernel/aster-nix/src/process/program_loader/mod.rs b/kernel/aster-nix/src/process/program_loader/mod.rs index 33995b79b..379444e9c 100644 --- a/kernel/aster-nix/src/process/program_loader/mod.rs +++ b/kernel/aster-nix/src/process/program_loader/mod.rs @@ -11,7 +11,7 @@ use super::process_vm::ProcessVm; use crate::{ fs::{ fs_resolver::{FsPath, FsResolver, AT_FDCWD}, - utils::{Dentry, Path}, + utils::{Dentry, DentryMnt}, }, prelude::*, }; @@ -25,7 +25,7 @@ use crate::{ /// because the interpreter is usually an elf binary(e.g., /bin/bash) pub fn load_program_to_vm( process_vm: &ProcessVm, - elf_file: Arc, + elf_file: Arc, argv: Vec, envp: Vec, fs_resolver: &FsResolver, diff --git a/kernel/aster-nix/src/syscall/chdir.rs b/kernel/aster-nix/src/syscall/chdir.rs index 064c2e549..dc84bb952 100644 --- a/kernel/aster-nix/src/syscall/chdir.rs +++ b/kernel/aster-nix/src/syscall/chdir.rs @@ -16,7 +16,7 @@ pub fn sys_chdir(pathname_addr: Vaddr) -> Result { let current = current!(); let mut fs = current.fs().write(); - let path = { + let dentrymnt = { let pathname = pathname.to_string_lossy(); if pathname.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); @@ -24,10 +24,10 @@ pub fn sys_chdir(pathname_addr: Vaddr) -> Result { let fs_path = FsPath::try_from(pathname.as_ref())?; fs.lookup(&fs_path)? }; - if path.dentry().type_() != InodeType::Dir { + if dentrymnt.dentry().type_() != InodeType::Dir { return_errno_with_message!(Errno::ENOTDIR, "must be directory"); } - fs.set_cwd(path); + fs.set_cwd(dentrymnt); Ok(SyscallReturn::Return(0)) } @@ -36,17 +36,17 @@ pub fn sys_fchdir(fd: FileDesc) -> Result { debug!("fd = {}", fd); let current = current!(); - let path = { + let dentrymnt = { let file_table = current.file_table().lock(); let file = file_table.get_file(fd)?; let inode_handle = file .downcast_ref::() .ok_or(Error::with_message(Errno::EBADF, "not inode"))?; - inode_handle.path().clone() + inode_handle.dentrymnt().clone() }; - if path.dentry().type_() != InodeType::Dir { + if dentrymnt.dentry().type_() != InodeType::Dir { return_errno_with_message!(Errno::ENOTDIR, "must be directory"); } - current.fs().write().set_cwd(path); + current.fs().write().set_cwd(dentrymnt); Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/chmod.rs b/kernel/aster-nix/src/syscall/chmod.rs index 8e2c18c5b..bb50d1fbc 100644 --- a/kernel/aster-nix/src/syscall/chmod.rs +++ b/kernel/aster-nix/src/syscall/chmod.rs @@ -35,22 +35,20 @@ pub fn sys_fchmodat( /* flags: u32, */ ) -> Result { log_syscall_entry!(SYS_FCHMODAT); - let pathname = read_cstring_from_user(path_ptr, PATH_MAX)?; - debug!( - "dirfd = {}, path = {:?}, mode = 0o{:o}", - dirfd, pathname, mode, - ); + let path = read_cstring_from_user(path_ptr, PATH_MAX)?; + debug!("dirfd = {}, path = {:?}, mode = 0o{:o}", dirfd, path, mode,); let current = current!(); - let path = { - let pathname = pathname.to_string_lossy(); - if pathname.is_empty() { + let dentrymnt = { + let path = path.to_string_lossy(); + if path.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); } - let fs_path = FsPath::new(dirfd, pathname.as_ref())?; + let fs_path = FsPath::new(dirfd, path.as_ref())?; current.fs().read().lookup(&fs_path)? }; - path.dentry() + dentrymnt + .dentry() .set_mode(InodeMode::from_bits_truncate(mode))?; Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/chown.rs b/kernel/aster-nix/src/syscall/chown.rs index d1c4d2cf4..d70c02778 100644 --- a/kernel/aster-nix/src/syscall/chown.rs +++ b/kernel/aster-nix/src/syscall/chown.rs @@ -57,15 +57,15 @@ pub fn sys_fchownat( flags: u32, ) -> Result { log_syscall_entry!(SYS_FCHOWNAT); - let pathname = read_cstring_from_user(path_ptr, PATH_MAX)?; + let path = read_cstring_from_user(path_ptr, PATH_MAX)?; let flags = ChownFlags::from_bits(flags) .ok_or_else(|| Error::with_message(Errno::EINVAL, "invalid flags"))?; debug!( "dirfd = {}, path = {:?}, uid = {}, gid = {}, flags = {:?}", - dirfd, pathname, uid, gid, flags + dirfd, path, uid, gid, flags ); - if pathname.is_empty() { + if path.is_empty() { if !flags.contains(ChownFlags::AT_EMPTY_PATH) { return_errno_with_message!(Errno::ENOENT, "path is empty"); } @@ -79,9 +79,9 @@ pub fn sys_fchownat( } let current = current!(); - let path = { - let pathname = pathname.to_string_lossy(); - let fs_path = FsPath::new(dirfd, pathname.as_ref())?; + let dentrymnt = { + let path = path.to_string_lossy(); + let fs_path = FsPath::new(dirfd, path.as_ref())?; let fs = current.fs().read(); if flags.contains(ChownFlags::AT_SYMLINK_NOFOLLOW) { fs.lookup_no_follow(&fs_path)? @@ -90,10 +90,10 @@ pub fn sys_fchownat( } }; if let Some(uid) = uid { - path.dentry().set_owner(uid)?; + dentrymnt.dentry().set_owner(uid)?; } if let Some(gid) = gid { - path.dentry().set_group(gid)?; + dentrymnt.dentry().set_group(gid)?; } Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/chroot.rs b/kernel/aster-nix/src/syscall/chroot.rs index 425d586c5..e96870754 100644 --- a/kernel/aster-nix/src/syscall/chroot.rs +++ b/kernel/aster-nix/src/syscall/chroot.rs @@ -16,7 +16,7 @@ pub fn sys_chroot(pathname_addr: Vaddr) -> Result { let current = current!(); let mut fs = current.fs().write(); - let path = { + let dentrymnt = { let pathname = pathname.to_string_lossy(); if pathname.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); @@ -24,9 +24,9 @@ pub fn sys_chroot(pathname_addr: Vaddr) -> Result { let fs_path = FsPath::try_from(pathname.as_ref())?; fs.lookup(&fs_path)? }; - if path.dentry().type_() != InodeType::Dir { + if dentrymnt.dentry().type_() != InodeType::Dir { return_errno_with_message!(Errno::ENOTDIR, "must be directory"); } - fs.set_root(path); + fs.set_root(dentrymnt); Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/execve.rs b/kernel/aster-nix/src/syscall/execve.rs index c542e093e..0039b7e9b 100644 --- a/kernel/aster-nix/src/syscall/execve.rs +++ b/kernel/aster-nix/src/syscall/execve.rs @@ -8,7 +8,7 @@ use crate::{ fs::{ file_table::FileDesc, fs_resolver::{FsPath, AT_FDCWD}, - utils::{Dentry, InodeType, Path}, + utils::{Dentry, DentryMnt, InodeType}, }, log_syscall_entry, prelude::*, @@ -61,29 +61,29 @@ fn lookup_executable_file( dfd: FileDesc, filename: String, flags: OpenFlags, -) -> Result> { +) -> Result> { let current = current!(); let fs_resolver = current.fs().read(); - let path = if flags.contains(OpenFlags::AT_EMPTY_PATH) && filename.is_empty() { + let dentrymnt = if flags.contains(OpenFlags::AT_EMPTY_PATH) && filename.is_empty() { fs_resolver.lookup_from_fd(dfd) } else { let fs_path = FsPath::new(dfd, &filename)?; if flags.contains(OpenFlags::AT_SYMLINK_NOFOLLOW) { - let path = fs_resolver.lookup_no_follow(&fs_path)?; - if path.dentry().type_() == InodeType::SymLink { + let dentrymnt = fs_resolver.lookup_no_follow(&fs_path)?; + if dentrymnt.dentry().type_() == InodeType::SymLink { return_errno_with_message!(Errno::ELOOP, "the executable file is a symlink"); } - Ok(path) + Ok(dentrymnt) } else { fs_resolver.lookup(&fs_path) } }?; - check_executable_file(path.dentry())?; - Ok(path) + check_executable_file(dentrymnt.dentry())?; + Ok(dentrymnt) } fn do_execve( - elf_file: Arc, + elf_file: Arc, argv_ptr_ptr: Vaddr, envp_ptr_ptr: Vaddr, context: &mut UserContext, diff --git a/kernel/aster-nix/src/syscall/fsync.rs b/kernel/aster-nix/src/syscall/fsync.rs index 5b3339d1e..74cdb6015 100644 --- a/kernel/aster-nix/src/syscall/fsync.rs +++ b/kernel/aster-nix/src/syscall/fsync.rs @@ -18,7 +18,7 @@ pub fn sys_fsync(fd: FileDesc) -> Result { let inode_handle = file .downcast_ref::() .ok_or(Error::with_message(Errno::EINVAL, "not inode"))?; - inode_handle.path().dentry().clone() + inode_handle.dentrymnt().dentry().clone() }; dentry.sync()?; Ok(SyscallReturn::Return(0)) diff --git a/kernel/aster-nix/src/syscall/getdents64.rs b/kernel/aster-nix/src/syscall/getdents64.rs index 3c4810157..e5f8261a5 100644 --- a/kernel/aster-nix/src/syscall/getdents64.rs +++ b/kernel/aster-nix/src/syscall/getdents64.rs @@ -29,7 +29,7 @@ pub fn sys_getdents64(fd: FileDesc, buf_addr: Vaddr, buf_len: usize) -> Result() .ok_or(Error::with_message(Errno::EBADF, "not inode"))?; - if inode_handle.path().dentry().type_() != InodeType::Dir { + if inode_handle.dentrymnt().dentry().type_() != InodeType::Dir { return_errno!(Errno::ENOTDIR); } let mut buffer = vec![0u8; buf_len]; diff --git a/kernel/aster-nix/src/syscall/link.rs b/kernel/aster-nix/src/syscall/link.rs index 326b6a9cb..42bec4bf4 100644 --- a/kernel/aster-nix/src/syscall/link.rs +++ b/kernel/aster-nix/src/syscall/link.rs @@ -30,7 +30,7 @@ pub fn sys_linkat( ); let current = current!(); - let (old_path, new_dir_path, new_name) = { + let (old_dentrymnt, new_dir_dentrymnt, new_name) = { let old_pathname = old_pathname.to_string_lossy(); if old_pathname.ends_with('/') { return_errno_with_message!(Errno::EPERM, "oldpath is dir"); @@ -46,15 +46,15 @@ pub fn sys_linkat( let old_fs_path = FsPath::new(old_dirfd, old_pathname.as_ref())?; let new_fs_path = FsPath::new(new_dirfd, new_pathname.as_ref())?; let fs = current.fs().read(); - let old_path = if flags.contains(LinkFlags::AT_SYMLINK_FOLLOW) { + let old_dentrymnt = if flags.contains(LinkFlags::AT_SYMLINK_FOLLOW) { fs.lookup(&old_fs_path)? } else { fs.lookup_no_follow(&old_fs_path)? }; - let (new_dir_path, new_name) = fs.lookup_dir_and_base_name(&new_fs_path)?; - (old_path, new_dir_path, new_name) + let (new_dir_dentrymnt, new_name) = fs.lookup_dir_and_base_name(&new_fs_path)?; + (old_dentrymnt, new_dir_dentrymnt, new_name) }; - new_dir_path.link(&old_path, &new_name)?; + new_dir_dentrymnt.link(&old_dentrymnt, &new_name)?; Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/mkdir.rs b/kernel/aster-nix/src/syscall/mkdir.rs index 18b083fb4..648f618ed 100644 --- a/kernel/aster-nix/src/syscall/mkdir.rs +++ b/kernel/aster-nix/src/syscall/mkdir.rs @@ -22,7 +22,7 @@ pub fn sys_mkdirat(dirfd: FileDesc, pathname_addr: Vaddr, mode: u16) -> Result Result Result Result Result let inode_handle = file .downcast_ref::() .ok_or(Error::with_message(Errno::EBADF, "not inode"))?; - let dentry = inode_handle.path().dentry(); + let dentry = inode_handle.dentrymnt().dentry(); let statfs = Statfs::from(dentry.fs().sb()); write_val_to_user(statfs_buf_ptr, &statfs)?; Ok(SyscallReturn::Return(0)) diff --git a/kernel/aster-nix/src/syscall/symlink.rs b/kernel/aster-nix/src/syscall/symlink.rs index c65a96ad8..7f56d28c1 100644 --- a/kernel/aster-nix/src/syscall/symlink.rs +++ b/kernel/aster-nix/src/syscall/symlink.rs @@ -31,7 +31,7 @@ pub fn sys_symlinkat( if target.is_empty() { return_errno_with_message!(Errno::ENOENT, "target is empty"); } - let (dir_path, link_name) = { + let (dir_dentrymnt, link_name) = { let linkpath = linkpath.to_string_lossy(); if linkpath.is_empty() { return_errno_with_message!(Errno::ENOENT, "linkpath is empty"); @@ -43,7 +43,7 @@ pub fn sys_symlinkat( current.fs().read().lookup_dir_and_base_name(&fs_path)? }; - let new_dentry = dir_path.dentry().create( + let new_dentry = dir_dentrymnt.dentry().create( &link_name, InodeType::SymLink, InodeMode::from_bits_truncate(0o777), diff --git a/kernel/aster-nix/src/syscall/truncate.rs b/kernel/aster-nix/src/syscall/truncate.rs index 4ee0c2cfa..fdc82dd26 100644 --- a/kernel/aster-nix/src/syscall/truncate.rs +++ b/kernel/aster-nix/src/syscall/truncate.rs @@ -34,7 +34,7 @@ pub fn sys_truncate(path_ptr: Vaddr, len: isize) -> Result { check_length(len)?; let current = current!(); - let path = { + let dir_dentrymnt = { let pathname = pathname.to_string_lossy(); if pathname.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); @@ -42,7 +42,7 @@ pub fn sys_truncate(path_ptr: Vaddr, len: isize) -> Result { let fs_path = FsPath::new(AT_FDCWD, pathname.as_ref())?; current.fs().read().lookup(&fs_path)? }; - path.dentry().resize(len as usize)?; + dir_dentrymnt.dentry().resize(len as usize)?; Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/unlink.rs b/kernel/aster-nix/src/syscall/unlink.rs index 0dd2ec35f..2c8b12f8a 100644 --- a/kernel/aster-nix/src/syscall/unlink.rs +++ b/kernel/aster-nix/src/syscall/unlink.rs @@ -24,7 +24,7 @@ pub fn sys_unlinkat(dirfd: FileDesc, pathname_addr: Vaddr, flags: u32) -> Result debug!("dirfd = {}, pathname = {:?}", dirfd, pathname); let current = current!(); - let (dir_path, name) = { + let (dir_dentrymnt, name) = { let pathname = pathname.to_string_lossy(); if pathname.is_empty() { return_errno_with_message!(Errno::ENOENT, "path is empty"); @@ -35,7 +35,7 @@ pub fn sys_unlinkat(dirfd: FileDesc, pathname_addr: Vaddr, flags: u32) -> Result let fs_path = FsPath::new(dirfd, pathname.as_ref())?; current.fs().read().lookup_dir_and_base_name(&fs_path)? }; - dir_path.dentry().unlink(&name)?; + dir_dentrymnt.dentry().unlink(&name)?; Ok(SyscallReturn::Return(0)) } diff --git a/kernel/aster-nix/src/syscall/utimens.rs b/kernel/aster-nix/src/syscall/utimens.rs index dc917d4c5..d356a0c37 100644 --- a/kernel/aster-nix/src/syscall/utimens.rs +++ b/kernel/aster-nix/src/syscall/utimens.rs @@ -61,7 +61,7 @@ pub fn sys_utimensat( return Ok(SyscallReturn::Return(0)); } let current = current!(); - let path = { + let dentrymnt = { let pathname = pathname.to_string_lossy(); if pathname.is_empty() { return_errno_with_message!(Errno::ENOENT, "pathname is empty"); @@ -75,10 +75,10 @@ pub fn sys_utimensat( } }; if let Some(time) = atime { - path.dentry().set_atime(Duration::from(time)); + dentrymnt.dentry().set_atime(Duration::from(time)); } if let Some(time) = mtime { - path.dentry().set_mtime(Duration::from(time)); + dentrymnt.dentry().set_mtime(Duration::from(time)); } Ok(SyscallReturn::Return(0)) }