Patchwork [U-Boot] unzip: return uncompressed size in `filesize', and print it.

login
register
mail settings
Submitter Wolfgang Denk
Date Feb. 11, 2011, 1:31 p.m.
Message ID <1297431070-29533-1-git-send-email-wd@denx.de>
Download mbox | patch
Permalink /patch/82755/
State Superseded
Headers show

Comments

Wolfgang Denk - Feb. 11, 2011, 1:31 p.m.
The unzip command did not provide a way for the caller to get any
information about the uncompressed size.  To make it better usable in
scripts, we now store the uncompressed size in the `filesize'
variable, like we do when for example loading a file over the network
or when reading it from a file system.  Following that analogy, it is
only consequent to also print the size.

Signed-off-by: Wolfgang Denk <wd@denx.de>
---
 common/cmd_mem.c |   10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)
Peter Tyser - Feb. 11, 2011, 4:57 p.m.
Hi Wolfgang,

> -	return !!gunzip((void *) dst, dst_len, (void *) src, &src_len);
> +	rc = gunzip((void *) dst, dst_len, (void *) src, &src_len);
> +
> +	printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
> +	sprintf(buf, "%lX", src_len);
> +	setenv("filesize", buf);
> +
> +	return !!rc;

What about:
if (rc)
	return rc;

printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
sprintf(buf, "%lX", src_len);
setenv("filesize", buf);

return 0;


This will prevent printing and setting of bogus values when an invalid
or overly large image is unzipped.

Best,
Peter
Wolfgang Denk - Feb. 11, 2011, 7:21 p.m.
Dear Peter Tyser,

In message <1297443439.965.1208.camel@petert> you wrote:
> 
> > -	return !!gunzip((void *) dst, dst_len, (void *) src, &src_len);
> > +	rc = gunzip((void *) dst, dst_len, (void *) src, &src_len);
> > +
> > +	printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
> > +	sprintf(buf, "%lX", src_len);
> > +	setenv("filesize", buf);
> > +
> > +	return !!rc;
> 
> What about:
> if (rc)
> 	return rc;
> 
> printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
> sprintf(buf, "%lX", src_len);
> setenv("filesize", buf);
> 
> return 0;
> 
> 
> This will prevent printing and setting of bogus values when an invalid
> or overly large image is unzipped.

Good point, will fix.  Thanks!

Best regards,

Wolfgang Denk

Patch

diff --git a/common/cmd_mem.c b/common/cmd_mem.c
index ccf420a..54e581a 100644
--- a/common/cmd_mem.c
+++ b/common/cmd_mem.c
@@ -1212,6 +1212,8 @@  int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 {
 	unsigned long src, dst;
 	unsigned long src_len = ~0UL, dst_len = ~0UL;
+	int rc;
+	char buf[32];
 
 	switch (argc) {
 		case 4:
@@ -1225,7 +1227,13 @@  int do_unzip ( cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 			return cmd_usage(cmdtp);
 	}
 
-	return !!gunzip((void *) dst, dst_len, (void *) src, &src_len);
+	rc = gunzip((void *) dst, dst_len, (void *) src, &src_len);
+
+	printf("Uncompressed size: %ld = 0x%lX\n", src_len, src_len);
+	sprintf(buf, "%lX", src_len);
+	setenv("filesize", buf);
+
+	return !!rc;
 }
 #endif /* CONFIG_CMD_UNZIP */