This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx-apps.git


The following commit(s) were added to refs/heads/master by this push:
     new cfff7f5a2 nshlib: add -f for umount
cfff7f5a2 is described below

commit cfff7f5a22aecdfd7799add706c48d6968769cdc
Author: zhengyu16 <[email protected]>
AuthorDate: Thu Sep 11 05:16:12 2025 -0400

    nshlib: add -f for umount
    
    adds support for the -f (force) option to the NSH umount command
    
    Signed-off-by: zhengyu16 <[email protected]>
---
 nshlib/nsh_command.c |  2 +-
 nshlib/nsh_mntcmds.c | 29 +++++++++++++++++++++++++----
 2 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index 3275756b3..2f05557cb 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -621,7 +621,7 @@ static const struct cmdmap_s g_cmdmap[] =
 
 #if !defined(CONFIG_DISABLE_MOUNTPOINT)
 #  ifndef CONFIG_NSH_DISABLE_UMOUNT
-  CMD_MAP("umount",   cmd_umount,   2, 2, "<dir-path>"),
+  CMD_MAP("umount",   cmd_umount,   2, 3, "[-f] <dir-path>"),
 #  endif
 #endif
 
diff --git a/nshlib/nsh_mntcmds.c b/nshlib/nsh_mntcmds.c
index 62579d8b7..f4a2e903b 100644
--- a/nshlib/nsh_mntcmds.c
+++ b/nshlib/nsh_mntcmds.c
@@ -363,16 +363,37 @@ int cmd_nfsmount(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
 #if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_UMOUNT)
 int cmd_umount(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
 {
-  UNUSED(argc);
-
-  FAR char *fullpath = nsh_getfullpath(vtbl, argv[1]);
+  unsigned int flags = 0;
+  FAR char *fullpath;
   int ret = ERROR;
+  int option;
+
+  while ((option = getopt(argc, argv, "f")) != ERROR)
+    {
+      switch (option)
+        {
+          case 'f':
+            flags |= MNT_FORCE;
+            break;
+
+          default:
+            nsh_error(vtbl, g_fmtarginvalid, argv[0]);
+            return ERROR;
+        }
+    }
+
+  if (optind >= argc)
+    {
+      nsh_error(vtbl, g_fmtargrequired, argv[0]);
+      return ret;
+    }
 
+  fullpath = nsh_getfullpath(vtbl, argv[optind]);
   if (fullpath)
     {
       /* Perform the umount */
 
-      ret = umount(fullpath);
+      ret = umount2(fullpath, flags);
       if (ret < 0)
         {
           nsh_error(vtbl, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO);

Reply via email to