[U-Boot] [PATCH] tools/mkimage: use lseek rather than fstat for file size for -l option

Wolfgang Denk wd at denx.de
Wed Dec 3 01:22:54 CET 2008


Dear Peter Korsgaard,

In message <87vdu2tka2.fsf at macbook.be.48ers.dk> you wrote:
> >>>>> "Thomas" == Thomas De Schampheleire <patrickdepinguin at gmail.com> writes:
> 
>  Thomas> I'd change the error message as well, to be independent of the tool
>  Thomas> used to get the file size. For example:
>  Thomas> fprintf (stderr, "%s: Can't get size of %s: %s\n",
> 
> Ahh yes, good idea.
> 
> From d7c4cb9f290e22d3fc97e43816158c9fd744200c Mon Sep 17 00:00:00 2001
> From: Peter Korsgaard <jacmet at sunsite.dk>
> Date: Mon, 1 Dec 2008 17:13:17 +0100
> Subject: [PATCH] tools/mkimage: use lseek rather than fstat for file size for -l option
> 
> Use lseek rather than fstat for file size for list mode, so
> mkimage -l /dev/mtdblockN works (stat returns st_size == 0 for devices).
> 
> Notice that you have to use /dev/mtdblockN and not /dev/mtdN, as the
> latter doesn't support mmap.

Hm... but lseek() on /dev/mtdblockN will return the size of the MTD
device, not of the image that may be stored in it, right?

Later, you should get data checksum errors because of  the  incorrect
lenght,  i.  e.  a  ``ERROR:  "<image>"  has  corrupted data!'' error
message.

I don't think this works.

> -		if (fstat(ifd, &sbuf) < 0) {
> -			fprintf (stderr, "%s: Can't stat %s: %s\n",
> +		sbuf.st_size = lseek(ifd, 0, SEEK_END);
> +		if (sbuf.st_size == (off_t)-1) {
> +			fprintf (stderr, "%s: Can't get size of %s: %s\n",

If you don't use *stat(), you should not use any struct stat type
either.

Best regards,

Wolfgang Denk

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Der Horizont vieler Menschen ist ein Kreis mit Radius Null --
und das nennen sie ihren Standpunkt.


More information about the U-Boot mailing list