This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 8c829bdc3a0 fs/mount: Do not unmount a volume for a path in it.
8c829bdc3a0 is described below
commit 8c829bdc3a0813056b4b1b72cf44de827430c6c3
Author: Marco Casaroli <[email protected]>
AuthorDate: Fri Oct 23 05:37:36 2026 +0200
fs/mount: Do not unmount a volume for a path in it.
umount2() looked the target up with inode_find(), which stops at the
mount point of a path in a mounted volume and gives the rest of the path
in relpath. umount2() did not check relpath, so a path such as
/mnt/sd/dir unmounted the volume at /mnt/sd.
Fail with EINVAL when the target is not the mount point itself, as POSIX
and Linux do for a path that is not a mount point.
Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <[email protected]>
---
fs/mount/fs_umount2.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/fs/mount/fs_umount2.c b/fs/mount/fs_umount2.c
index 66c68adaed6..8acd3de249b 100644
--- a/fs/mount/fs_umount2.c
+++ b/fs/mount/fs_umount2.c
@@ -94,9 +94,12 @@ int nx_umount2(FAR const char *target, unsigned int flags)
DEBUGASSERT(mountpt_inode != NULL);
- /* Verify that the inode is a mountpoint */
+ /* Verify that the inode is a mountpoint and that the path names the
+ * mountpoint itself, not a file or directory in the mounted volume.
+ */
- if (!INODE_IS_MOUNTPT(mountpt_inode))
+ if (!INODE_IS_MOUNTPT(mountpt_inode) ||
+ (desc.relpath != NULL && *desc.relpath != '\0'))
{
ret = -EINVAL;
goto errout_with_mountpt;