1
0
Fork 0
forked from len0rd/rockbox

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
This commit is contained in:
Björn Stenberg 2003-03-12 15:06:57 +00:00
parent cad6f24a50
commit 188be8ec57

View file

@ -409,7 +409,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
if (count && file->dirty) { if (count && file->dirty) {
rc = flush_cache(fd); rc = flush_cache(fd);
if (rc < 0) if (rc < 0)
return rc * 10 - 3; return nread ? nread : rc * 10 - 3;
} }
/* read whole sectors right into the supplied buffer */ /* 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 ) { if ( rc < 0 ) {
DEBUGF("Failed read/writing %d sectors\n",sectors); DEBUGF("Failed read/writing %d sectors\n",sectors);
errno = EIO; errno = EIO;
return rc * 10 - 4; return nread ? nread : rc * 10 - 4;
} }
else { else {
if ( rc > 0 ) { if ( rc > 0 ) {
@ -452,7 +452,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
if ( rc < 0 ) { if ( rc < 0 ) {
DEBUGF("Failed writing\n"); DEBUGF("Failed writing\n");
errno = EIO; errno = EIO;
return rc * 10 - 5; return nread ? nread : rc * 10 - 5;
} }
/* seek back one sector to put file position right */ /* seek back one sector to put file position right */
rc = fat_seek(&(file->fatfile), rc = fat_seek(&(file->fatfile),
@ -461,7 +461,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
if ( rc < 0 ) { if ( rc < 0 ) {
DEBUGF("fat_seek() failed\n"); DEBUGF("fat_seek() failed\n");
errno = EIO; errno = EIO;
return rc * 10 - 6; return nread ? nread : rc * 10 - 6;
} }
} }
memcpy( file->cache, buf + nread, count ); memcpy( file->cache, buf + nread, count );
@ -472,7 +472,7 @@ static int readwrite(int fd, void* buf, int count, bool write)
if (rc < 1 ) { if (rc < 1 ) {
DEBUGF("Failed caching sector\n"); DEBUGF("Failed caching sector\n");
errno = EIO; errno = EIO;
return rc * 10 - 7; return nread ? nread : rc * 10 - 7;
} }
memcpy( buf + nread, file->cache, count ); memcpy( buf + nread, file->cache, count );
} }