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 <chenrun1@xiaomi.com>
This commit is contained in:
parent
31908b3128
commit
bd1cc85ad4
@ -188,7 +188,7 @@ static const struct cmdmap_s g_cmdmap[] =
|
|||||||
#ifndef CONFIG_NSH_DISABLE_DD
|
#ifndef CONFIG_NSH_DISABLE_DD
|
||||||
CMD_MAP("dd", cmd_dd, 3, 7,
|
CMD_MAP("dd", cmd_dd, 3, 7,
|
||||||
"if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] "
|
"if=<infile> of=<outfile> [bs=<sectsize>] [count=<sectors>] "
|
||||||
"[skip=<sectors>] [verify]"),
|
"[skip=<sectors>] [seek=<sectors>] [verify]"),
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_DELROUTE)
|
#if defined(CONFIG_NET) && defined(CONFIG_NET_ROUTE) && !defined(CONFIG_NSH_DISABLE_DELROUTE)
|
||||||
|
@ -75,6 +75,7 @@ struct dd_s
|
|||||||
int outfd; /* File descriptor of the output device */
|
int outfd; /* File descriptor of the output device */
|
||||||
uint32_t nsectors; /* Number of sectors to transfer */
|
uint32_t nsectors; /* Number of sectors to transfer */
|
||||||
uint32_t skip; /* The number of sectors skipped on input */
|
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 eof; /* true: The end of the input or output file has been hit */
|
||||||
bool verify; /* true: Verify infile and outfile correctness */
|
bool verify; /* true: Verify infile and outfile correctness */
|
||||||
size_t sectsize; /* Size of one sector */
|
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]);
|
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)
|
else if (strncmp(argv[i], "verify", 6) == 0)
|
||||||
{
|
{
|
||||||
dd.verify = true;
|
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);
|
ret = lseek(dd.infd, dd.skip * dd.sectsize, SEEK_SET);
|
||||||
if (ret < -1)
|
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;
|
ret = ERROR;
|
||||||
goto errout_with_outf;
|
goto errout_with_outf;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user