From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Korsgaard Date: Wed, 03 Dec 2008 08:43:52 +0100 Subject: [U-Boot] [PATCH] tools/mkimage: use lseek rather than fstat for file size for -l option In-Reply-To: <20081203002254.473EB834B020@gemini.denx.de> (Wolfgang Denk's message of "Wed\, 03 Dec 2008 01\:22\:54 +0100") References: <1228148597-22359-1-git-send-email-jacmet@sunsite.dk> <1228148597-22359-2-git-send-email-jacmet@sunsite.dk> <9d133f60812012348o663f24d5g774dbceaa71a0e66@mail.gmail.com> <87vdu2tka2.fsf@macbook.be.48ers.dk> <20081203002254.473EB834B020@gemini.denx.de> Message-ID: <87ljuxzosn.fsf@macbook.be.48ers.dk> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de >>>>> "Wolfgang" == Wolfgang Denk writes: Hi, Wolfgang> Hm... but lseek() on /dev/mtdblockN will return the size of Wolfgang> the MTD device, not of the image that may be stored in it, Wolfgang> right? Yes. Wolfgang> Later, you should get data checksum errors because of the Wolfgang> incorrect lenght, i. e. a ``ERROR: "" has Wolfgang> corrupted data!'' error message. Exactly, hence my other patch (tools/mkimage: ignore trailing garbage) to only error out if the size is smaller than the size defined in the header. Wolfgang> 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", Wolfgang> If you don't use *stat(), you should not use any struct Wolfgang> stat type either. Ok, I kept it like that to keep the patch as minimal as possible - I'll change it and resend. -- Bye, Peter Korsgaard