Skip to contentSkip to conversation

lib: Fix copy_file when filesize is FILESIZE_MAX

PATCH Applied Teresa Gámez 2 participants 2 messages Sep 27, 2013 Library code

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: Fix copy_file when filesize is FILESIZE_MAX

Using tftp command does not work proper when files have FILESIZE_MAX, as copy_file and show_progress can not handle it. Check the file size for FILESIZE_MAX and handle it as file size = 0.

---
 lib/copy_file.c     |    8 ++++++--
 lib/show_progress.c |    5 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)
lib/copy_file.c +6 -2
index ab3d845..55dee38 100644
@@ -63,8 +63,12 @@ int copy_file(const char *src, const char *dst, int verbose)
 			total += w;
 		}
 
-		if (verbose)
-			show_progress(statbuf.st_size ? total : total / 16384);
+		if (verbose) {
+			if (statbuf.st_size && statbuf.st_size != FILESIZE_MAX)
+				show_progress(total);
+			else
+				show_progress(total / 16384);
+		}
 	}
 
 	ret = 0;
lib/show_progress.c +3 -2
index bc067ea..98dc849 100644
@@ -18,6 +18,7 @@
  */
 
 #include <common.h>
+#include <fs.h>
 #include <progress.h>
 #include <asm-generic/div64.h>
 #include <linux/stringify.h>
@@ -37,7 +38,7 @@ void show_progress(int now)
 		return;
 	}
 
-	if (progress_max) {
+	if (progress_max && progress_max != FILESIZE_MAX) {
 		uint64_t tmp = (int64_t)now * HASHES_PER_LINE;
 		do_div(tmp, progress_max);
 		now = tmp;
@@ -56,7 +57,7 @@ void init_progression_bar(int max)
 	printed = 0;
 	progress_max = max;
 	spin = 0;
-	if (progress_max)
+	if (progress_max && progress_max != FILESIZE_MAX)
 		printf("\t[%"__stringify(HASHES_PER_LINE)"s]\r\t[", "");
 	else
 		printf("\t");
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Applied
#1 lore raw
Quoted 6 lines · Teresa Gámez

Using tftp command does not work proper when files have FILESIZE_MAX, as copy_file and show_progress can not handle it. Check the file size for FILESIZE_MAX and handle it as file size = 0.

Applied, thanks

Sascha

Quoted 62 lines
---
 lib/copy_file.c     |    8 ++++++--
 lib/show_progress.c |    5 +++--
 2 files changed, 9 insertions(+), 4 deletions(-)
lib/copy_file.c +6 -2
index ab3d845..55dee38 100644
@@ -63,8 +63,12 @@ int copy_file(const char *src, const char *dst, int verbose)
 			total += w;
 		}
 
-		if (verbose)
-			show_progress(statbuf.st_size ? total : total / 16384);
+		if (verbose) {
+			if (statbuf.st_size && statbuf.st_size != FILESIZE_MAX)
+				show_progress(total);
+			else
+				show_progress(total / 16384);
+		}
 	}
 
 	ret = 0;
lib/show_progress.c +3 -2
index bc067ea..98dc849 100644
@@ -18,6 +18,7 @@
  */
 
 #include <common.h>
+#include <fs.h>
 #include <progress.h>
 #include <asm-generic/div64.h>
 #include <linux/stringify.h>
@@ -37,7 +38,7 @@ void show_progress(int now)
 		return;
 	}
 
-	if (progress_max) {
+	if (progress_max && progress_max != FILESIZE_MAX) {
 		uint64_t tmp = (int64_t)now * HASHES_PER_LINE;
 		do_div(tmp, progress_max);
 		now = tmp;
@@ -56,7 +57,7 @@ void init_progression_bar(int max)
 	printed = 0;
 	progress_max = max;
 	spin = 0;
-	if (progress_max)
+	if (progress_max && progress_max != FILESIZE_MAX)
 		printf("\t[%"__stringify(HASHES_PER_LINE)"s]\r\t[", "");
 	else
 		printf("\t");
Signature · 7 lines
1.7.0.4


_______________________________________________
barebox mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox
Signature · 9 lines
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
[email protected]
http://lists.infradead.org/mailman/listinfo/barebox