diff --git a/kernel/src/fs/path/dentry.rs b/kernel/src/fs/path/dentry.rs index b5b42ce4f..3e112a811 100644 --- a/kernel/src/fs/path/dentry.rs +++ b/kernel/src/fs/path/dentry.rs @@ -140,11 +140,6 @@ impl Dentry { } } - /// Currently, the root `Dentry` of a fs is the root of a mount. - pub(super) fn is_mount_root(&self) -> bool { - self.name_and_parent.read().as_ref().is_none() - } - /// Creates a `Dentry_` by creating a new inode of the `type_` with the `mode`. pub(super) fn create( &self, diff --git a/kernel/src/fs/path/mod.rs b/kernel/src/fs/path/mod.rs index 85f4f3c5e..254939ffc 100644 --- a/kernel/src/fs/path/mod.rs +++ b/kernel/src/fs/path/mod.rs @@ -61,6 +61,11 @@ impl Path { &self.mount } + /// Returns true if the current `Path` is the root of its mount. + pub(super) fn is_mount_root(&self) -> bool { + Arc::ptr_eq(&self.dentry, self.mount.root_dentry()) + } + /// Lookups the target `Path` given the `name`. pub fn lookup(&self, name: &str) -> Result { if self.type_() != InodeType::Dir { @@ -119,7 +124,7 @@ impl Path { /// If it is the root of a mount, it will go up to the mountpoint /// to get the name of the mountpoint recursively. fn effective_name(&self) -> String { - if !self.dentry.is_mount_root() { + if !self.is_mount_root() { return self.dentry.name(); } @@ -139,7 +144,7 @@ impl Path { /// If it is the root of a 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_mount_root() { + if !self.is_mount_root() { return Some(Self::new(self.mount.clone(), self.dentry.parent().unwrap())); } @@ -201,7 +206,7 @@ impl Path { /// /// Note that the root mount cannot be unmounted. pub fn unmount(&self) -> Result> { - if !self.dentry.is_mount_root() { + if !self.is_mount_root() { return_errno_with_message!(Errno::EINVAL, "not mounted"); } @@ -291,7 +296,6 @@ impl Path { pub fn set_ctime(&self, time: Duration); pub fn key(&self) -> DentryKey; pub fn inode(&self) -> &Arc; - pub fn is_mount_root(&self) -> bool; pub fn is_mountpoint(&self) -> bool; pub fn set_xattr( &self,