]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
fs/fs.c: read up to EOF when len would read past EOF
authorMax Krummenacher <max.krummenacher@toradex.com>
Wed, 5 Aug 2015 15:16:58 +0000 (17:16 +0200)
committerTom Rini <trini@konsulko.com>
Thu, 13 Aug 2015 11:19:35 +0000 (07:19 -0400)
http://lists.denx.de/pipermail/u-boot/2012-September/134347.html
allows for reading files in chunks from the shell.

When this feature is used to read past the end of a file an error
was returned instead of returning the bytes read up to the end of
file. Thus the following fails in the shell:

offset = 0
len = chunksize
do
read file, offset, len
write data
until bytes_read < len

The patch changes the behaviour to printing an informational
message and returning the actual read number of bytes aka read(2)
behaviour for convenient use in U-Boot scripts.

Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
Acked-by: Marek Vasut <marex@denx.de>
Signed-off-by: Stefan Agner <stefan.agner@toradex.com>
Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
fs/fs.c

diff --git a/fs/fs.c b/fs/fs.c
index ac0897d94a08625de0bca16a913d8fcdb6392884..827b143e85e5538f9a250565ce2a54b0455fdab8 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -301,10 +301,8 @@ int fs_read(const char *filename, ulong addr, loff_t offset, loff_t len,
        unmap_sysmem(buf);
 
        /* If we requested a specific number of bytes, check we got it */
-       if (ret == 0 && len && *actread != len) {
-               printf("** Unable to read file %s **\n", filename);
-               ret = -1;
-       }
+       if (ret == 0 && len && *actread != len)
+               printf("** %s shorter than offset + len **\n", filename);
        fs_close();
 
        return ret;