mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH] lib: Add missing arguments to memcpy_parse_options()
@ 2019-07-09  7:22 Andrey Smirnov
  2019-07-09  9:41 ` Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Andrey Smirnov @ 2019-07-09  7:22 UTC (permalink / raw)
  To: barebox; +Cc: Andrey Smirnov, Peter Mamonov

Memcpy use-case differs from that of memcmp in default access type and
destination file mode. This was missed in original commit that
introduced memcpy_parse_options(). Add said parameters to
memcpy_parse_options(), so the can be correctly specified depending on
the use-case.

Fixes: ddf4cca339 ("commands: Introduce memcpy_parse_options()")
Reported-by: Peter Mamonov <pmamonov@gmail.com>
Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
---
 commands/memcmp.c | 3 ++-
 commands/memcpy.c | 3 ++-
 include/common.h  | 3 ++-
 lib/misc.c        | 7 ++++---
 4 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/commands/memcmp.c b/commands/memcmp.c
index d1c4f5205..76fbe078f 100644
--- a/commands/memcmp.c
+++ b/commands/memcmp.c
@@ -42,7 +42,8 @@ static int do_memcmp(int argc, char *argv[])
 	int     ret = 1;
 	int     offset = 0;
 
-	if (memcpy_parse_options(argc, argv, &sourcefd, &destfd, &count) < 0)
+	if (memcpy_parse_options(argc, argv, &sourcefd, &destfd, &count,
+				 O_RWSIZE_1, O_RDONLY) < 0)
 		return 1;
 
 	buf = xmalloc(RW_BUF_SIZE + RW_BUF_SIZE);
diff --git a/commands/memcpy.c b/commands/memcpy.c
index 5f0047f87..b2cea8c09 100644
--- a/commands/memcpy.c
+++ b/commands/memcpy.c
@@ -41,7 +41,8 @@ static int do_memcpy(int argc, char *argv[])
 	int ret = 0;
 	char *buf;
 
-	if (memcpy_parse_options(argc, argv, &sourcefd, &destfd, &count) < 0)
+	if (memcpy_parse_options(argc, argv, &sourcefd, &destfd, &count,
+				 0, O_WRONLY | O_CREAT) < 0)
 		return 1;
 
 	buf = xmalloc(RW_BUF_SIZE);
diff --git a/include/common.h b/include/common.h
index b1294978d..a947406e1 100644
--- a/include/common.h
+++ b/include/common.h
@@ -117,7 +117,8 @@ void shutdown_barebox(void);
 int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
 		char **sourcefile, char **destfile, int *swab);
 int memcpy_parse_options(int argc, char *argv[], int *sourcefd,
-			 int *destfd, loff_t *count);
+			 int *destfd, loff_t *count,
+			 int rwsize, int destmode);
 #define RW_BUF_SIZE	(unsigned)4096
 
 extern const char version_string[];
diff --git a/lib/misc.c b/lib/misc.c
index 18153bb4d..7add1fe3b 100644
--- a/lib/misc.c
+++ b/lib/misc.c
@@ -173,10 +173,11 @@ int mem_parse_options(int argc, char *argv[], char *optstr, int *mode,
 }
 
 int memcpy_parse_options(int argc, char *argv[], int *sourcefd,
-			 int *destfd, loff_t *count)
+			 int *destfd, loff_t *count,
+			 int rwsize, int destmode)
 {
 	loff_t dest, src;
-	int mode = 0;
+	int mode = rwsize;
 	char *sourcefile = NULL;
 	char *destfile = NULL;
 	struct  stat statbuf;
@@ -212,7 +213,7 @@ int memcpy_parse_options(int argc, char *argv[], int *sourcefd,
 	if (*sourcefd < 0)
 		return -1;
 
-	*destfd = open_and_lseek(destfile, O_WRONLY | O_CREAT | mode, dest);
+	*destfd = open_and_lseek(destfile, mode | destmode, dest);
 	if (*destfd < 0) {
 		close(*sourcefd);
 		return -1;
-- 
2.21.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] lib: Add missing arguments to memcpy_parse_options()
  2019-07-09  7:22 [PATCH] lib: Add missing arguments to memcpy_parse_options() Andrey Smirnov
@ 2019-07-09  9:41 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2019-07-09  9:41 UTC (permalink / raw)
  To: Andrey Smirnov; +Cc: barebox, Peter Mamonov

On Tue, Jul 09, 2019 at 12:22:53AM -0700, Andrey Smirnov wrote:
> Memcpy use-case differs from that of memcmp in default access type and
> destination file mode. This was missed in original commit that
> introduced memcpy_parse_options(). Add said parameters to
> memcpy_parse_options(), so the can be correctly specified depending on
> the use-case.
> 
> Fixes: ddf4cca339 ("commands: Introduce memcpy_parse_options()")
> Reported-by: Peter Mamonov <pmamonov@gmail.com>
> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
> ---
>  commands/memcmp.c | 3 ++-
>  commands/memcpy.c | 3 ++-
>  include/common.h  | 3 ++-
>  lib/misc.c        | 7 ++++---
>  4 files changed, 10 insertions(+), 6 deletions(-)

Applied, thanks

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-07-09  9:41 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-09  7:22 [PATCH] lib: Add missing arguments to memcpy_parse_options() Andrey Smirnov
2019-07-09  9:41 ` Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox