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 bd1cc85ad dd:support "seek"
bd1cc85ad is described below

commit bd1cc85ad4a2015f0a1dda5bad0469e86468468a
Author: chenrun1 <chenr...@xiaomi.com>
AuthorDate: Thu Jan 11 11:28:49 2024 +0800

    dd:support "seek"
    
    Now the dd command can use the "seek" parameter to adjust how many bytes 
need to be skipped before being written to the target.
    
    Signed-off-by: chenrun1 <chenr...@xiaomi.com>
---
 nshlib/nsh_command.c |  2 +-
 nshlib/nsh_ddcmd.c   | 18 +++++++++++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c
index e15b8c672..24d3e828d 100644
--- a/nshlib/nsh_command.c
+++ b/nshlib/nsh_command.c
@@ -188,7 +188,7 @@ static const struct cmdmap_s g_cmdmap[] =
 #ifndef CONFIG_NSH_DISABLE_DD
   CMD_MAP("dd",       cmd_dd,       3, 7,
     "if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] "
-    "[skip=<sectors>] [verify]"),
+    "[skip=<sectors>] [seek=<sectors>] [verify]"),
 #endif
 
 #if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && 
!defined(CONFIG_NSH_DISABLE_DELROUTE)
diff --git a/nshlib/nsh_ddcmd.c b/nshlib/nsh_ddcmd.c
index 9f6bfd01a..5e7ebe957 100644
--- a/nshlib/nsh_ddcmd.c
+++ b/nshlib/nsh_ddcmd.c
@@ -75,6 +75,7 @@ struct dd_s
   int          outfd;      /* File descriptor of the output device */
   uint32_t     nsectors;   /* Number of sectors to transfer */
   uint32_t     skip;       /* The number of sectors skipped on input */
+  uint32_t     seek;       /* The number of bytes skipped on output */
   bool         eof;        /* true: The end of the input or output file has 
been hit */
   bool         verify;     /* true: Verify infile and outfile correctness */
   size_t       sectsize;   /* Size of one sector */
@@ -332,6 +333,10 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char 
**argv)
         {
           dd.skip = atoi(&argv[i][5]);
         }
+      else if (strncmp(argv[i], "seek=", 5) == 0)
+        {
+          dd.seek = atoi(&argv[i][5]);
+        }
       else if (strncmp(argv[i], "verify", 6) == 0)
         {
           dd.verify = true;
@@ -382,7 +387,18 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char 
**argv)
       ret = lseek(dd.infd, dd.skip * dd.sectsize, SEEK_SET);
       if (ret < -1)
         {
-          nsh_error(vtbl, g_fmtcmdfailed, g_dd, "lseek", NSH_ERRNO);
+          nsh_error(vtbl, g_fmtcmdfailed, g_dd, "skip lseek", NSH_ERRNO);
+          ret = ERROR;
+          goto errout_with_outf;
+        }
+    }
+
+  if (dd.seek)
+    {
+      ret = lseek(dd.outfd, dd.seek * dd.sectsize, SEEK_SET);
+      if (ret < -1)
+        {
+          nsh_error(vtbl, g_fmtcmdfailed, g_dd, "seek lseek", NSH_ERRNO);
           ret = ERROR;
           goto errout_with_outf;
         }

Reply via email to