mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Adrian Negreanu <adrian.negreanu@nxp.com>,
	Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 08/11] libfile: give copy_file a flags parameter
Date: Thu, 13 Mar 2025 11:17:25 +0100	[thread overview]
Message-ID: <20250313101728.3546902-9-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20250313101728.3546902-1-a.fatoum@pengutronix.de>

In preparation for adding an additional flag input to copy_file, let's
turn the current copy_file verbose parameter in a bitmask.

Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
 commands/cp.c     |  8 ++++----
 commands/tftp.c   |  2 +-
 common/fastboot.c |  2 +-
 include/libfile.h |  5 ++++-
 lib/libfile.c     | 12 +++++++-----
 5 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/commands/cp.c b/commands/cp.c
index 71448f9aff6f..e2f91123ca92 100644
--- a/commands/cp.c
+++ b/commands/cp.c
@@ -25,13 +25,13 @@ static int do_cp(int argc, char *argv[])
 	int last_is_dir = 0;
 	int i;
 	int opt;
-	int verbose = 0, recursive = 0;
+	int flags = 0, recursive = 0;
 	int argc_min;
 
 	while ((opt = getopt(argc, argv, "vr")) > 0) {
 		switch (opt) {
 		case 'v':
-			verbose = 1;
+			flags |= COPY_FILE_VERBOSE;
 			break;
 		case 'r':
 			recursive = 1;
@@ -68,9 +68,9 @@ static int do_cp(int argc, char *argv[])
 		if (recursive)
 			ret = copy_recursive(argv[i], dst);
 		else if (last_is_dir)
-			ret = copy_file(argv[i], dst, verbose);
+			ret = copy_file(argv[i], dst, flags);
 		else
-			ret = copy_file(argv[i], argv[argc - 1], verbose);
+			ret = copy_file(argv[i], argv[argc - 1], flags);
 
 		free(dst);
 		if (ret)
diff --git a/commands/tftp.c b/commands/tftp.c
index 5e8d8d17761d..f17b589ee62d 100644
--- a/commands/tftp.c
+++ b/commands/tftp.c
@@ -81,7 +81,7 @@ static int do_tftpb(int argc, char *argv[])
 
 	debug("%s: %s -> %s\n", __func__, source, dest);
 
-	ret = copy_file(source, dest, 1);
+	ret = copy_file(source, dest, COPY_FILE_VERBOSE);
 
 	umount(TFTP_MOUNT_PATH);
 
diff --git a/common/fastboot.c b/common/fastboot.c
index 60bef0ec776b..9088b988cb6c 100644
--- a/common/fastboot.c
+++ b/common/fastboot.c
@@ -741,7 +741,7 @@ static void cb_flash(struct fastboot *fb, const char *cmd)
 	}
 
 copy:
-	ret = copy_file(fb->tempname, filename, 1);
+	ret = copy_file(fb->tempname, filename, COPY_FILE_VERBOSE);
 	if (ret)
 		fastboot_tx_print(fb, FASTBOOT_MSG_FAIL,
 				  "write partition: %s", strerror(-ret));
diff --git a/include/libfile.h b/include/libfile.h
index bf775b022dc4..a9bef5065d08 100644
--- a/include/libfile.h
+++ b/include/libfile.h
@@ -3,6 +3,7 @@
 #define __LIBFILE_H
 
 #include <linux/types.h>
+#include <linux/bits.h>
 
 struct resource;
 
@@ -26,7 +27,9 @@ int read_file_2(const char *filename, size_t *size, void **outbuf,
 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);
+#define COPY_FILE_VERBOSE	BIT(0)
+
+int copy_file(const char *src, const char *dst, unsigned flags);
 
 int copy_recursive(const char *src, const char *dst);
 
diff --git a/lib/libfile.c b/lib/libfile.c
index 80d4591dd6e5..76a091878ebb 100644
--- a/lib/libfile.c
+++ b/lib/libfile.c
@@ -432,11 +432,13 @@ EXPORT_SYMBOL(write_file_flash);
  * copy_file - Copy a file
  * @src:	The source filename
  * @dst:	The destination filename
- * @verbose:	if true, show a progression bar
+ * @flags:	A bitmask of COPY_FILE_* flags. Possible values:
+ *
+ *                COPY_FILE_VERBOSE: 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(const char *src, const char *dst, unsigned flags)
 {
 	char *rw_buf = NULL;
 	int srcfd = 0, dstfd = 0;
@@ -488,7 +490,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 		}
 	}
 
-	if (verbose)
+	if (flags & COPY_FILE_VERBOSE)
 		init_progression_bar(srcstat.st_size);
 
 	while (1) {
@@ -509,7 +511,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 
 		total += r;
 
-		if (verbose) {
+		if (flags & COPY_FILE_VERBOSE) {
 			if (srcstat.st_size && srcstat.st_size != FILESIZE_MAX)
 				show_progress(total);
 			else
@@ -519,7 +521,7 @@ int copy_file(const char *src, const char *dst, int verbose)
 
 	ret = 0;
 out:
-	if (verbose)
+	if (flags & COPY_FILE_VERBOSE)
 		putchar('\n');
 
 	free(rw_buf);
-- 
2.39.5




  parent reply	other threads:[~2025-03-13 10:18 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 10:17 [PATCH 00/11] firmware: qemu_fw_cfg: implement file system Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 01/11] video: ramfb: fix frame buffer screen size Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 02/11] firmware: qemu_fw_cfg: drop duplicate definitions Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 03/11] firmware: qemu_fw_cfg: add support for seeking Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 04/11] firmware: qemu_fw_cfg: rename from /dev/fw_cfg0 to /dev/fw_cfg Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 05/11] fs: add qemu_fw_cfg file system Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 06/11] firmware: qemu_fw_cfg: register at device initcall level Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 07/11] video: ramfb: use new qemu fw_cfg FS Ahmad Fatoum
2025-03-13 10:17 ` Ahmad Fatoum [this message]
2025-03-13 10:17 ` [PATCH 09/11] libfile: pass copy_file flags through copy_recursive Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 10/11] libfile: add support for not clobbering files in copy_file Ahmad Fatoum
2025-03-13 10:17 ` [PATCH 11/11] fs: qemu_fw_cfg: support populating environment via QEMU fw_cfg Ahmad Fatoum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250313101728.3546902-9-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=adrian.negreanu@nxp.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox