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 1852731df dd_main.c: Add oseek optional argument.
1852731df is described below
commit 1852731df87e5895e299b74aabdb1984b7e3f795
Author: Denis Ryndine <[email protected]>
AuthorDate: Fri Jul 5 10:22:22 2024 +1000
dd_main.c: Add oseek optional argument.
- If oseek=N passed, will seek N*bs on output file before writing.
---
system/dd/dd_main.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/system/dd/dd_main.c b/system/dd/dd_main.c
index 3466fc298..37526787a 100644
--- a/system/dd/dd_main.c
+++ b/system/dd/dd_main.c
@@ -65,6 +65,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 sectors seeked on output */
bool eof; /* true: The end of the input or output file has
been hit */
uint16_t sectsize; /* Size of one sector */
uint16_t nbytes; /* Number of valid bytes in the buffer */
@@ -176,7 +177,7 @@ static void print_usage(void)
{
fprintf(stderr, "usage:\n");
fprintf(stderr, " %s if=<infile> of=<outfile> [bs=<sectsize>] "
- "[count=<sectors>] [skip=<sectors>]\n", g_dd);
+ "[count=<sectors>] [skip=<sectors>] [seek=<sectors>]\n", g_dd);
}
/****************************************************************************
@@ -226,6 +227,10 @@ int main(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]);
+ }
}
if (infile == NULL || outfile == NULL)
@@ -262,7 +267,7 @@ int main(int argc, FAR char **argv)
if (dd.skip)
{
ret = lseek(dd.infd, dd.skip * dd.sectsize, SEEK_SET);
- if (ret < -1)
+ if (ret < 0)
{
fprintf(stderr, "%s: failed to lseek: %s\n",
g_dd, strerror(errno));
@@ -271,6 +276,18 @@ int main(int argc, FAR char **argv)
}
}
+ if (dd.seek)
+ {
+ ret = lseek(dd.outfd, dd.seek * dd.sectsize, SEEK_SET);
+ if (ret < 0)
+ {
+ fprintf(stderr, "%s: failed to lseek on output: %s\n",
+ g_dd, strerror(errno));
+ ret = ERROR;
+ goto errout_with_outf;
+ }
+ }
+
/* Then perform the data transfer */
clock_gettime(CLOCK_MONOTONIC, &ts0);