fs/fs.c: read up to EOF when len would read past EOF
authorMax Krummenacher <max.krummenacher@toradex.com>
Thu, 4 Sep 2014 11:46:02 +0000 (13:46 +0200)
committerMarcel Ziswiler <marcel.ziswiler@toradex.com>
Wed, 15 Apr 2015 11:56:53 +0000 (13:56 +0200)
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.

(cherry picked from commit 4641b92713300089c5980259ba31e668657aa75d)

Conflicts:
fs/fs.c

fs/fs.c

diff --git a/fs/fs.c b/fs/fs.c
index 483273fe20b8212075f74526cb86aa2ae3e36988..1433d35ab2ea44d537b7ce2a4182c199283268b8 100644 (file)
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -300,10 +300,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;