xiaoxiang781216 commented on code in PR #3865:
URL: https://github.com/apache/nuttx-apps/pull/3865#discussion_r4305647451


##########
nshlib/nsh_mntcmds.c:
##########
@@ -46,6 +47,106 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_MOUNT)
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct mount_flag_s
+{
+  FAR const char *name;  /* Option name in the -o list */
+  unsigned long set;     /* Mount flags that the option sets */
+  unsigned long clear;   /* Mount flags that the option clears */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct mount_flag_s g_mount_flags[] =
+{
+  { "ro",      MS_RDONLY,      0              },
+  { "rw",      0,              MS_RDONLY      },
+  { "noexec",  MS_NOEXEC,      0              },
+  { "exec",    0,              MS_NOEXEC      },
+  { "nosuid",  MS_NOSUID,      0              },
+  { "suid",    0,              MS_NOSUID      },
+  { "nodev",   MS_NODEV,       0              },
+  { "dev",     0,              MS_NODEV       },
+  { "sync",    MS_SYNCHRONOUS, 0              },
+  { "async",   0,              MS_SYNCHRONOUS },
+  { "noatime", MS_NOATIME,     0              },
+  { "atime",   0,              MS_NOATIME     },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mount_parse_options
+ *
+ * Description:
+ *   Remove the generic options (ro, noexec, ...) from the comma-separated
+ *   list in options, and return them as mount flags.  The other options
+ *   stay in options for the file system.  options is empty if no option
+ *   is left.
+ *
+ ****************************************************************************/
+
+static unsigned long mount_parse_options(FAR char *options)
+{
+  FAR char *src = options;
+  FAR char *dst = options;
+  unsigned long flags = 0;
+  FAR char *end;
+  size_t len;
+  int i;
+
+  while (*src != '\0')
+    {
+      end = strchr(src, ',');
+      len = end != NULL ? (size_t)(end - src) : strlen(src);

Review Comment:
   remove the cast



##########
nshlib/nsh_mntcmds.c:
##########
@@ -46,6 +47,106 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_MOUNT)
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct mount_flag_s
+{
+  FAR const char *name;  /* Option name in the -o list */
+  unsigned long set;     /* Mount flags that the option sets */
+  unsigned long clear;   /* Mount flags that the option clears */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct mount_flag_s g_mount_flags[] =
+{
+  { "ro",      MS_RDONLY,      0              },
+  { "rw",      0,              MS_RDONLY      },
+  { "noexec",  MS_NOEXEC,      0              },
+  { "exec",    0,              MS_NOEXEC      },
+  { "nosuid",  MS_NOSUID,      0              },
+  { "suid",    0,              MS_NOSUID      },
+  { "nodev",   MS_NODEV,       0              },
+  { "dev",     0,              MS_NODEV       },
+  { "sync",    MS_SYNCHRONOUS, 0              },
+  { "async",   0,              MS_SYNCHRONOUS },
+  { "noatime", MS_NOATIME,     0              },
+  { "atime",   0,              MS_NOATIME     },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mount_parse_options
+ *
+ * Description:
+ *   Remove the generic options (ro, noexec, ...) from the comma-separated
+ *   list in options, and return them as mount flags.  The other options
+ *   stay in options for the file system.  options is empty if no option
+ *   is left.
+ *
+ ****************************************************************************/
+
+static unsigned long mount_parse_options(FAR char *options)
+{
+  FAR char *src = options;
+  FAR char *dst = options;
+  unsigned long flags = 0;
+  FAR char *end;
+  size_t len;
+  int i;
+
+  while (*src != '\0')
+    {
+      end = strchr(src, ',');

Review Comment:
   strchrnul



##########
nshlib/nsh_mntcmds.c:
##########
@@ -46,6 +47,106 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_MOUNT)
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct mount_flag_s
+{
+  FAR const char *name;  /* Option name in the -o list */
+  unsigned long set;     /* Mount flags that the option sets */
+  unsigned long clear;   /* Mount flags that the option clears */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct mount_flag_s g_mount_flags[] =
+{
+  { "ro",      MS_RDONLY,      0              },
+  { "rw",      0,              MS_RDONLY      },
+  { "noexec",  MS_NOEXEC,      0              },
+  { "exec",    0,              MS_NOEXEC      },
+  { "nosuid",  MS_NOSUID,      0              },
+  { "suid",    0,              MS_NOSUID      },
+  { "nodev",   MS_NODEV,       0              },
+  { "dev",     0,              MS_NODEV       },
+  { "sync",    MS_SYNCHRONOUS, 0              },
+  { "async",   0,              MS_SYNCHRONOUS },
+  { "noatime", MS_NOATIME,     0              },
+  { "atime",   0,              MS_NOATIME     },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mount_parse_options
+ *
+ * Description:
+ *   Remove the generic options (ro, noexec, ...) from the comma-separated
+ *   list in options, and return them as mount flags.  The other options
+ *   stay in options for the file system.  options is empty if no option
+ *   is left.
+ *
+ ****************************************************************************/
+
+static unsigned long mount_parse_options(FAR char *options)

Review Comment:
   can we remove known options in place to avoiding malloc/free?



##########
nshlib/nsh_mntcmds.c:
##########
@@ -46,6 +47,106 @@
 #include "nsh.h"
 #include "nsh_console.h"
 
+#if !defined(CONFIG_DISABLE_MOUNTPOINT) && !defined(CONFIG_NSH_DISABLE_MOUNT)
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct mount_flag_s
+{
+  FAR const char *name;  /* Option name in the -o list */
+  unsigned long set;     /* Mount flags that the option sets */
+  unsigned long clear;   /* Mount flags that the option clears */
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static const struct mount_flag_s g_mount_flags[] =
+{
+  { "ro",      MS_RDONLY,      0              },
+  { "rw",      0,              MS_RDONLY      },
+  { "noexec",  MS_NOEXEC,      0              },
+  { "exec",    0,              MS_NOEXEC      },
+  { "nosuid",  MS_NOSUID,      0              },
+  { "suid",    0,              MS_NOSUID      },
+  { "nodev",   MS_NODEV,       0              },
+  { "dev",     0,              MS_NODEV       },
+  { "sync",    MS_SYNCHRONOUS, 0              },
+  { "async",   0,              MS_SYNCHRONOUS },
+  { "noatime", MS_NOATIME,     0              },
+  { "atime",   0,              MS_NOATIME     },
+};
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mount_parse_options
+ *
+ * Description:
+ *   Remove the generic options (ro, noexec, ...) from the comma-separated
+ *   list in options, and return them as mount flags.  The other options
+ *   stay in options for the file system.  options is empty if no option
+ *   is left.
+ *
+ ****************************************************************************/
+
+static unsigned long mount_parse_options(FAR char *options)
+{
+  FAR char *src = options;
+  FAR char *dst = options;
+  unsigned long flags = 0;
+  FAR char *end;
+  size_t len;
+  int i;
+
+  while (*src != '\0')
+    {
+      end = strchr(src, ',');
+      len = end != NULL ? (size_t)(end - src) : strlen(src);
+
+      for (i = 0; i < nitems(g_mount_flags); i++)
+        {
+          if (strlen(g_mount_flags[i].name) == len &&

Review Comment:
   ```suggestion
             if (strncmp(g_mount_flags[i].name, src, len) == 0 &&
                 g_mount_flags[i].name[len] = '\0')
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to