@@ -76,8 +76,8 @@ struct dd_s
76
76
uint32_t nsectors ; /* Number of sectors to transfer */
77
77
uint32_t skip ; /* The number of sectors skipped on input */
78
78
uint32_t seek ; /* The number of bytes skipped on output */
79
+ int oflags ; /* The open flags on output deivce */
79
80
bool eof ; /* true: The end of the input or output file has been hit */
80
- bool verify ; /* true: Verify infile and outfile correctness */
81
81
size_t sectsize ; /* Size of one sector */
82
82
size_t nbytes ; /* Number of valid bytes in the buffer */
83
83
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)
170
170
171
171
static inline int dd_outfopen (FAR const char * name , FAR struct dd_s * dd )
172
172
{
173
- dd -> outfd = open (name , (dd -> verify ? O_RDWR : O_WRONLY ) |
174
- O_CREAT | O_TRUNC , 0644 );
173
+ dd -> outfd = open (name , dd -> oflags , 0644 );
175
174
if (dd -> outfd < 0 )
176
175
{
177
176
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)
282
281
dd .vtbl = vtbl ; /* For nsh_output */
283
282
dd .sectsize = DEFAULT_SECTSIZE ; /* Sector size if 'bs=' not provided */
284
283
dd .nsectors = 0xffffffff ; /* MAX_UINT32 */
284
+ dd .oflags = O_WRONLY | O_CREAT | O_TRUNC ;
285
285
286
286
/* If no IF= option is provided on the command line, then read
287
287
* from stdin.
@@ -339,7 +339,18 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
339
339
}
340
340
else if (strncmp (argv [i ], "verify" , 6 ) == 0 )
341
341
{
342
- dd .verify = true;
342
+ dd .oflags |= O_RDONLY ;
343
+ }
344
+ else if (strncmp (argv [i ], "conv=" , 5 ) == 0 )
345
+ {
346
+ if (strstr (argv [i ], "nocreat" ) != NULL )
347
+ {
348
+ dd .oflags &= ~(O_CREAT | O_TRUNC );
349
+ }
350
+ else if (strstr (argv [i ], "notrunc" ) != NULL )
351
+ {
352
+ dd .oflags &= ~O_TRUNC ;
353
+ }
343
354
}
344
355
}
345
356
@@ -450,7 +461,7 @@ int cmd_dd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
450
461
/ ((double )elapsed / USEC_PER_SEC )));
451
462
#endif
452
463
453
- if (ret == 0 && dd .verify )
464
+ if (ret == 0 && ( dd .oflags & O_RDONLY ) != 0 )
454
465
{
455
466
ret = dd_verify (infile , outfile , & dd );
456
467
}
0 commit comments