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

Thomas De Schampheleire patrickdepinguin at gmail.com
Tue Dec 2 08:48:32 CET 2008


Hi Peter,

On Mon, Dec 1, 2008 at 5:23 PM, Peter Korsgaard <jacmet at sunsite.dk> wrote:
> 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.
>
> Signed-off-by: Peter Korsgaard <jacmet at sunsite.dk>
> ---
>  tools/mkimage.c |    3 ++-
>  1 files changed, 2 insertions(+), 1 deletions(-)
>
> diff --git a/tools/mkimage.c b/tools/mkimage.c
> index 58fd20f..ca8254f 100644
> --- a/tools/mkimage.c
> +++ b/tools/mkimage.c
> @@ -205,7 +205,8 @@ NXTARG:             ;
>                /*
>                 * list header information of existing image
>                 */
> -               if (fstat(ifd, &sbuf) < 0) {
> +               sbuf.st_size = lseek(ifd, 0, SEEK_END);
> +               if (sbuf.st_size == (off_t)-1) {
>                        fprintf (stderr, "%s: Can't stat %s: %s\n",
>                                cmdname, imagefile, strerror(errno));

I'd change the error message as well, to be independent of the tool
used to get the file size. For example:
fprintf (stderr, "%s: Can't get size of %s: %s\n",


Best regards,
Thomas


More information about the U-Boot mailing list