diff --git a/nshlib/nsh_command.c b/nshlib/nsh_command.c index af5a09933..6efbbee69 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= of= [bs=] [count=] " - "[skip=] [seek=] [verify]"), + "[skip=] [seek=] [verify] [conv=]"), #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 0f829314d..c56997ff6 100644 --- a/nshlib/nsh_ddcmd.c +++ b/nshlib/nsh_ddcmd.c @@ -76,8 +76,8 @@ struct dd_s 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 */ + int oflags; /* The open flags on output deivce */ 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 */ size_t nbytes; /* Number of valid bytes in the buffer */ FAR uint8_t *buffer; /* Buffer of data to write to the output file */ @@ -170,8 +170,7 @@ static inline int dd_infopen(FAR const char *name, FAR struct dd_s *dd) static inline int dd_outfopen(FAR const char *name, FAR struct dd_s *dd) { - dd->outfd = open(name, (dd->verify ? O_RDWR : O_WRONLY) | - O_CREAT | O_TRUNC, 0644); + dd->outfd = open(name, dd->oflags, 0644); if (dd->outfd < 0) { FAR struct nsh_vtbl_s *vtbl = dd->vtbl; @@ -282,6 +281,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) dd.vtbl = vtbl; /* For nsh_output */ dd.sectsize = DEFAULT_SECTSIZE; /* Sector size if 'bs=' not provided */ dd.nsectors = 0xffffffff; /* MAX_UINT32 */ + dd.oflags = O_WRONLY | O_CREAT | O_TRUNC; /* If no IF= option is provided on the command line, then read * from stdin. @@ -339,7 +339,18 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) } else if (strncmp(argv[i], "verify", 6) == 0) { - dd.verify = true; + dd.oflags |= O_RDONLY; + } + else if (strncmp(argv[i], "conv=", 5) == 0) + { + if (strstr(argv[i], "nocreat") != NULL) + { + dd.oflags &= ~(O_CREAT | O_TRUNC); + } + else if (strstr(argv[i], "notrunc") != NULL) + { + dd.oflags &= ~O_TRUNC; + } } } @@ -450,7 +461,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv) / ((double)elapsed / USEC_PER_SEC))); #endif - if (ret == 0 && dd.verify) + if (ret == 0 && (dd.oflags & O_RDONLY) != 0) { ret = dd_verify(infile, outfile, &dd); }