diff mbox

[U-Boot,1/8] fs/fs.c: read up to EOF when len would read past EOF

Message ID 7a14941b6bdb958d25899d6a6cc2481e8043df3a.1435791392.git.marcel.ziswiler@toradex.com
State Superseded
Headers show

Commit Message

Marcel Ziswiler July 1, 2015, 11:04 p.m. UTC
From: Max Krummenacher <max.krummenacher@toradex.com>

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.

Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>
---
 fs/fs.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Marek Vasut July 2, 2015, 5:46 a.m. UTC | #1
On Thursday, July 02, 2015 at 01:04:46 AM, Marcel Ziswiler wrote:
> From: Max Krummenacher <max.krummenacher@toradex.com>
> 
> 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.
> 
> Signed-off-by: Max Krummenacher <max.krummenacher@toradex.com>
> Signed-off-by: Marcel Ziswiler <marcel.ziswiler@toradex.com>

So this behaves like read(2) now, right ?

Acked-by: Marek Vasut <marex@denx.de>

Best regards,
Marek Vasut
Marcel Ziswiler July 2, 2015, 6:01 a.m. UTC | #2
On 2 July 2015 07:46:19 CEST, Marek Vasut <marex@denx.de> wrote:

>So this behaves like read(2) now, right ?

Exactly for convenient use in U-Boot scripts.
diff mbox

Patch

diff --git a/fs/fs.c b/fs/fs.c
index ac0897d..827b143 100644
--- 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;