From 188be8ec579e257a3d2905ff974c3571a02770d0 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Wed, 12 Mar 2003 15:06:57 +0000 Subject: Bug fix: If head bytes were read but sector read failed, return head byte count instead of error. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3432 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/common/file.c b/firmware/common/file.c index dd953f44c5..3755560998 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -409,7 +409,7 @@ static int readwrite(int fd, void* buf, int count, bool write) if (count && file->dirty) { rc = flush_cache(fd); if (rc < 0) - return rc * 10 - 3; + return nread ? nread : rc * 10 - 3; } /* read whole sectors right into the supplied buffer */ @@ -420,7 +420,7 @@ static int readwrite(int fd, void* buf, int count, bool write) if ( rc < 0 ) { DEBUGF("Failed read/writing %d sectors\n",sectors); errno = EIO; - return rc * 10 - 4; + return nread ? nread : rc * 10 - 4; } else { if ( rc > 0 ) { @@ -452,7 +452,7 @@ static int readwrite(int fd, void* buf, int count, bool write) if ( rc < 0 ) { DEBUGF("Failed writing\n"); errno = EIO; - return rc * 10 - 5; + return nread ? nread : rc * 10 - 5; } /* seek back one sector to put file position right */ rc = fat_seek(&(file->fatfile), @@ -461,7 +461,7 @@ static int readwrite(int fd, void* buf, int count, bool write) if ( rc < 0 ) { DEBUGF("fat_seek() failed\n"); errno = EIO; - return rc * 10 - 6; + return nread ? nread : rc * 10 - 6; } } memcpy( file->cache, buf + nread, count ); @@ -472,7 +472,7 @@ static int readwrite(int fd, void* buf, int count, bool write) if (rc < 1 ) { DEBUGF("Failed caching sector\n"); errno = EIO; - return rc * 10 - 7; + return nread ? nread : rc * 10 - 7; } memcpy( buf + nread, file->cache, count ); } -- cgit v1.2.3