casaroli commented on code in PR #3952:
URL: https://github.com/apache/nuttx-apps/pull/3952#discussion_r4445606728
##########
system/nxinit/builtin.c:
##########
@@ -359,6 +398,186 @@ static int cmd_unlink(FAR struct action_manager_s *am,
return ret;
}
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+/* Take the flags (g_mount_flags) out of the comma-separated list in
+ * options and return them. The file system options stay in options.
+ */
+
+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;
+ size_t j;
+
+ while (*src != '\0')
+ {
+ end = strchrnul(src, ',');
+ len = end - src;
+
+ for (j = 0; j < nitems(g_mount_flags); j++)
+ {
+ if (!strncmp(g_mount_flags[j].name, src, len) &&
+ g_mount_flags[j].name[len] == '\0')
+ {
+ flags |= g_mount_flags[j].flag;
+ break;
+ }
+ }
+
+ if (j == nitems(g_mount_flags) && len > 0)
+ {
+ if (dst != options)
+ {
+ *dst++ = ',';
+ }
+
+ memmove(dst, src, len);
+ dst += len;
+ }
+
+ src = *end == ',' ? end + 1 : end;
+ }
+
+ *dst = '\0';
+ return flags;
+}
+
+/* mount <type> <device> <dir> [<flag>]* [<options>]
+ * mount -t <type> [-o <options>] [<device>] <dir>
+ *
+ * <flag> is one of g_mount_flags. In the first form, a last argument that
+ * is not a flag is the option string of the file system (the data of
+ * mount()). The second form is the one of the NSH command: <options> is a
+ * comma-separated list of flags and file system options.
+ */
+
+static int cmd_mount(FAR struct action_manager_s *am,
+ int argc, FAR char **argv)
+{
+ FAR const char *source = NULL;
+ FAR const char *target;
+ FAR const char *type = NULL;
+ FAR const char *data = NULL;
+ FAR char *options = NULL;
+ unsigned long flags = 0;
+ size_t j;
+ int ret;
+ int i;
+
+ UNUSED(am);
+
+ if (argc > 1 && argv[1][0] == '-')
+ {
+ for (i = 1; i < argc - 1 && argv[i][0] == '-'; i += 2)
+ {
+ if (!strcmp(argv[i], "-t"))
+ {
+ type = argv[i + 1];
+ }
+ else if (!strcmp(argv[i], "-o"))
+ {
+ data = argv[i + 1];
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (type == NULL || i >= argc || argv[i][0] == '-' || argc - i > 2)
+ {
+ init_err("mount: bad arguments");
+ return -EINVAL;
+ }
+
+ if (argc - i == 2)
+ {
+ source = argv[i++];
+ }
+
+ target = argv[i];
+
+ /* The command can run again: parse a copy of the options */
+
+ if (data != NULL)
+ {
+ options = strdup(data);
+ if (options == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ flags = mount_parse_options(options);
Review Comment:
Done.
##########
system/nxinit/builtin.c:
##########
@@ -359,6 +398,186 @@ static int cmd_unlink(FAR struct action_manager_s *am,
return ret;
}
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+/* Take the flags (g_mount_flags) out of the comma-separated list in
+ * options and return them. The file system options stay in options.
+ */
+
+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;
+ size_t j;
+
+ while (*src != '\0')
+ {
+ end = strchrnul(src, ',');
+ len = end - src;
+
+ for (j = 0; j < nitems(g_mount_flags); j++)
+ {
+ if (!strncmp(g_mount_flags[j].name, src, len) &&
+ g_mount_flags[j].name[len] == '\0')
+ {
+ flags |= g_mount_flags[j].flag;
+ break;
+ }
+ }
+
+ if (j == nitems(g_mount_flags) && len > 0)
+ {
+ if (dst != options)
+ {
+ *dst++ = ',';
+ }
+
+ memmove(dst, src, len);
+ dst += len;
+ }
+
+ src = *end == ',' ? end + 1 : end;
+ }
+
+ *dst = '\0';
+ return flags;
+}
+
+/* mount <type> <device> <dir> [<flag>]* [<options>]
+ * mount -t <type> [-o <options>] [<device>] <dir>
+ *
+ * <flag> is one of g_mount_flags. In the first form, a last argument that
+ * is not a flag is the option string of the file system (the data of
+ * mount()). The second form is the one of the NSH command: <options> is a
+ * comma-separated list of flags and file system options.
+ */
+
+static int cmd_mount(FAR struct action_manager_s *am,
+ int argc, FAR char **argv)
+{
+ FAR const char *source = NULL;
+ FAR const char *target;
+ FAR const char *type = NULL;
+ FAR const char *data = NULL;
+ FAR char *options = NULL;
+ unsigned long flags = 0;
+ size_t j;
+ int ret;
+ int i;
+
+ UNUSED(am);
+
+ if (argc > 1 && argv[1][0] == '-')
+ {
+ for (i = 1; i < argc - 1 && argv[i][0] == '-'; i += 2)
+ {
+ if (!strcmp(argv[i], "-t"))
+ {
+ type = argv[i + 1];
+ }
+ else if (!strcmp(argv[i], "-o"))
+ {
+ data = argv[i + 1];
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (type == NULL || i >= argc || argv[i][0] == '-' || argc - i > 2)
+ {
+ init_err("mount: bad arguments");
+ return -EINVAL;
+ }
+
+ if (argc - i == 2)
+ {
+ source = argv[i++];
+ }
+
+ target = argv[i];
+
+ /* The command can run again: parse a copy of the options */
+
+ if (data != NULL)
+ {
+ options = strdup(data);
+ if (options == NULL)
+ {
+ return -ENOMEM;
+ }
+
+ flags = mount_parse_options(options);
+ data = *options != '\0' ? options : NULL;
+ }
+ }
+ else
+ {
+ type = argv[1];
+ source = argv[2];
+ target = argv[3];
+
+ for (i = 4; i < argc; i++)
+ {
+ for (j = 0; j < nitems(g_mount_flags); j++)
Review Comment:
Done.
--
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]