@@ -65,6 +65,7 @@ struct dd_s
65
65
int outfd ; /* File descriptor of the output device */
66
66
uint32_t nsectors ; /* Number of sectors to transfer */
67
67
uint32_t skip ; /* The number of sectors skipped on input */
68
+ uint32_t seek ; /* The number of sectors seeked on output */
68
69
bool eof ; /* true: The end of the input or output file has been hit */
69
70
uint16_t sectsize ; /* Size of one sector */
70
71
uint16_t nbytes ; /* Number of valid bytes in the buffer */
@@ -176,7 +177,7 @@ static void print_usage(void)
176
177
{
177
178
fprintf (stderr , "usage:\n" );
178
179
fprintf (stderr , " %s if=<infile> of=<outfile> [bs=<sectsize>] "
179
- "[count=<sectors>] [skip=<sectors>]\n" , g_dd );
180
+ "[count=<sectors>] [skip=<sectors>] [seek=<sectors>] \n" , g_dd );
180
181
}
181
182
182
183
/****************************************************************************
@@ -226,6 +227,10 @@ int main(int argc, FAR char **argv)
226
227
{
227
228
dd .skip = atoi (& argv [i ][5 ]);
228
229
}
230
+ else if (strncmp (argv [i ], "seek=" , 5 ) == 0 )
231
+ {
232
+ dd .seek = atoi (& argv [i ][5 ]);
233
+ }
229
234
}
230
235
231
236
if (infile == NULL || outfile == NULL )
@@ -262,7 +267,7 @@ int main(int argc, FAR char **argv)
262
267
if (dd .skip )
263
268
{
264
269
ret = lseek (dd .infd , dd .skip * dd .sectsize , SEEK_SET );
265
- if (ret < -1 )
270
+ if (ret < 0 )
266
271
{
267
272
fprintf (stderr , "%s: failed to lseek: %s\n" ,
268
273
g_dd , strerror (errno ));
@@ -271,6 +276,18 @@ int main(int argc, FAR char **argv)
271
276
}
272
277
}
273
278
279
+ if (dd .seek )
280
+ {
281
+ ret = lseek (dd .outfd , dd .seek * dd .sectsize , SEEK_SET );
282
+ if (ret < 0 )
283
+ {
284
+ fprintf (stderr , "%s: failed to lseek on output: %s\n" ,
285
+ g_dd , strerror (errno ));
286
+ ret = ERROR ;
287
+ goto errout_with_outf ;
288
+ }
289
+ }
290
+
274
291
/* Then perform the data transfer */
275
292
276
293
clock_gettime (CLOCK_MONOTONIC , & ts0 );
0 commit comments