mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset
@ 2019-09-12 10:28 Ahmad Fatoum
  2019-09-12 10:29 ` [PATCH 2/7] ARM: Layerscape: add bootm handler for images Ahmad Fatoum
                   ` (6 more replies)
  0 siblings, 7 replies; 11+ messages in thread
From: Ahmad Fatoum @ 2019-09-12 10:28 UTC (permalink / raw)
  To: barebox; +Cc: Ahmad Fatoum

barebox already has a copy_file for copying files. Extend the API by a
copy_file_2 that takes a source offset into account.

This is useful for handling SoC-specific image formats which have a
fixed-size header, as copy_file_2 can now skip that header and create a
file with the full barebox image in one go.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 include/libfile.h |  1 +
 lib/libfile.c     | 25 +++++++++++++++++++------
 2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/include/libfile.h b/include/libfile.h
index f1d695187790..02269f4877e6 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -16,6 +16,7 @@ int write_file(const char *filename, const void *buf, size_t size);
 int write_file_flash(const char *filename, const void *buf, size_t size);
 
 int copy_file(const char *src, const char *dst, int verbose);
+int copy_file_2(const char *src, const char *dst, loff_t pos, int verbose);
 
 int copy_recursive(const char *src, const char *dst);
 
diff --git a/lib/libfile.c b/lib/libfile.c
index b42753c2b5ea..4bc980816a67 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -318,14 +318,15 @@ out_close:
 EXPORT_SYMBOL(write_file_flash);
 
 /**
- * copy_file - Copy a file
+ * copy_file_2 - Copy a file
  * @src:	The source filename
  * @dst:	The destination filename
+ * @pos:	source file position to start reading at
  * @verbose:	if true, show a progression bar
  *
  * Return: 0 for success or negative error code
  */
-int copy_file(const char *src, const char *dst, int verbose)
+int copy_file_2(const char *src, const char *dst, loff_t pos, int verbose)
 {
 	char *rw_buf = NULL;
 	int srcfd = 0, dstfd = 0;
@@ -337,11 +338,9 @@ int copy_file(const char *src, const char *dst, int verbose)
 
 	rw_buf = xmalloc(RW_BUF_SIZE);
 
-	srcfd = open(src, O_RDONLY);
-	if (srcfd < 0) {
-		printf("could not open %s: %s\n", src, errno_str());
+	srcfd = open_and_lseek(src, O_RDONLY, pos);
+	if (srcfd < 0)
 		goto out;
-	}
 
 	mode = O_WRONLY | O_CREAT;
 
@@ -403,6 +402,20 @@ out:
 
 	return ret ?: err1;
 }
+EXPORT_SYMBOL(copy_file_2);
+
+/**
+ * copy_file - Copy a file
+ * @src:	The source filename
+ * @dst:	The destination filename
+ * @verbose:	if true, show a progression bar
+ *
+ * Return: 0 for success or negative error code
+ */
+int copy_file(const char *src, const char *dst, int verbose)
+{
+	return copy_file_2(src, dst, 0, verbose);
+}
 EXPORT_SYMBOL(copy_file);
 
 int copy_recursive(const char *src, const char *dst)
-- 
2.23.0


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

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

end of thread, other threads:[~2019-09-13 14:38 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-12 10:28 [PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset Ahmad Fatoum
2019-09-12 10:29 ` [PATCH 2/7] ARM: Layerscape: add bootm handler for images Ahmad Fatoum
2019-09-12 10:29 ` [PATCH 3/7] ARM: Layerscape: don't generate second-stage 2nd.image Ahmad Fatoum
2019-09-12 10:29 ` [PATCH 4/7] filetype: support fastboot barebox_update with layerscape image Ahmad Fatoum
2019-09-12 10:29 ` [PATCH 5/7] scripts: pblimage: explicitly set architecture to ARM Ahmad Fatoum
2019-09-13 14:38   ` Roland Hieber
2019-09-12 10:29 ` [PATCH 6/7] ARM: layerscape: tqmls1046a: disable all SGMII PHYs Ahmad Fatoum
2019-09-12 10:29 ` [PATCH 7/7] Documentation: boards: document layerscape support Ahmad Fatoum
2019-09-12 13:06 ` [PATCH 1/7] libfile: introduce copy_file_2 for copying starting with offset Uwe Kleine-König
2019-09-12 13:37   ` Ahmad Fatoum
2019-09-12 14:30     ` Sascha Hauer

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