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


##########
nshlib/nsh_fscmds.c:
##########
@@ -998,6 +1001,170 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
 #endif
 #endif
 
+/****************************************************************************
+ * Name: cmd_lomtd
+ ****************************************************************************/
+
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+#   if defined(CONFIG_MTD_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOMTD)

Review Comment:
   ```suggestion
   #  if defined(CONFIG_MTD_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOMTD)
   ```



##########
nshlib/nsh_fscmds.c:
##########
@@ -998,6 +1001,170 @@ int cmd_losmart(FAR struct nsh_vtbl_s *vtbl, int argc, 
FAR char **argv)
 #endif
 #endif
 
+/****************************************************************************
+ * Name: cmd_lomtd
+ ****************************************************************************/
+
+#ifndef CONFIG_DISABLE_MOUNTPOINT
+#   if defined(CONFIG_MTD_DEV_LOOP) && !defined(CONFIG_NSH_DISABLE_LOMTD)
+int cmd_lomtd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+  FAR char *loopdev = NULL;
+  FAR char *filepath = NULL;
+  struct mtd_losetup_s setup;
+  bool teardown = false;
+  int erasesize = -1;
+  int sectsize = -1;
+  off_t offset = 0;
+  bool badarg = false;
+  int ret = ERROR;
+  int option;
+  int fd;
+
+  /* Get the lomtd options:  Two forms are supported:
+   *
+   *   lomtd -d <loop-device>
+   *   lomtd [-o <offset>] [-e erasesize] [-s sectsize]
+   *         <loop-device> <filename>
+   *
+   * NOTE that the -o and -r options are accepted with the -d option, but
+   * will be ignored.
+   */
+
+  while ((option = getopt(argc, argv, "d:o:e:s:")) != ERROR)
+    {
+      switch (option)
+        {
+        case 'd':
+          loopdev  = nsh_getfullpath(vtbl, optarg);
+          teardown = true;
+          break;
+
+        case 'e':
+          erasesize = atoi(optarg);
+          break;
+
+        case 'o':
+          offset = atoi(optarg);
+          break;
+
+        case 's':
+          sectsize = atoi(optarg);
+          break;
+
+        case '?':
+        default:
+          nsh_error(vtbl, g_fmtarginvalid, argv[0]);
+          badarg = true;
+          break;
+        }
+    }
+
+  /* If a bad argument was encountered,
+   * then return without processing the command
+   */
+
+  if (badarg)
+    {
+      goto errout_with_paths;
+    }
+
+  /* If this is not a tear down operation, then additional command line
+   * parameters are required.
+   */
+
+  if (!teardown)
+    {
+      /* There must be two arguments on the command line after the options */
+
+      if (optind + 1 < argc)
+        {
+          loopdev = nsh_getfullpath(vtbl, argv[optind]);
+          optind++;
+
+          filepath = nsh_getfullpath(vtbl, argv[optind]);
+          optind++;
+        }
+      else
+        {
+          nsh_error(vtbl, g_fmtargrequired, argv[0]);
+          goto errout_with_paths;
+        }
+    }
+
+  /* There should be nothing else on the command line */
+
+  if (optind < argc)
+    {
+      nsh_error(vtbl, g_fmttoomanyargs, argv[0]);
+      goto errout_with_paths;
+    }
+
+  /* Open the loop device */
+
+  fd = open("/dev/loopmtd", O_RDONLY);
+  if (fd < 0)
+    {
+      nsh_error(vtbl, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
+      goto errout_with_paths;
+    }
+
+  /* Perform the teardown operation */
+
+  if (teardown)
+    {
+      /* Tear down the loop device. */
+
+      ret = ioctl(fd, MTD_LOOPIOC_TEARDOWN,
+                 (unsigned long)((uintptr_t) loopdev));

Review Comment:
   ```suggestion
                    (unsigned long)((uintptr_t)loopdev));
   ```



-- 
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: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to