diff --git a/kernel/src/fs/notify/mod.rs b/kernel/src/fs/notify/mod.rs index 9af2b5ef9..3d8e47bbe 100644 --- a/kernel/src/fs/notify/mod.rs +++ b/kernel/src/fs/notify/mod.rs @@ -419,7 +419,7 @@ fn notify_parent(path: &Path, mut events: FsEvents, name: String) { events |= FsEvents::ISDIR; } - let parent = path.effective_parent(); + let parent = path.parent_within_mount(); if let Some(parent) = parent { notify_inode(parent.inode(), events, Some(name)); } diff --git a/kernel/src/fs/path/mod.rs b/kernel/src/fs/path/mod.rs index 6cb7f3c42..cd80b16ad 100644 --- a/kernel/src/fs/path/mod.rs +++ b/kernel/src/fs/path/mod.rs @@ -165,7 +165,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. - pub fn effective_parent(&self) -> Option { + fn effective_parent(&self) -> Option { if !self.is_mount_root() { return Some(Self::new(self.mount.clone(), self.dentry.parent().unwrap())); } @@ -177,6 +177,18 @@ impl Path { mount_parent.effective_parent() } + /// Gets the parent `Path` within the same mount. + /// + /// This method returns the parent path within the same filesystem/mount. + /// It does NOT cross mount boundaries. If the current path is the root of a mount, + /// it will return `None`. + /// + /// For cross-filesystem parent lookup, use `effective_parent()` instead. + pub(super) fn parent_within_mount(&self) -> Option { + let parent = self.dentry.parent()?; + Some(Self::new(self.mount.clone(), parent)) + } + /// Gets the top `Path` of the current. /// /// Used when different file systems are mounted on the same mount point.