From 631b8d3bb8af7d3abf86d658054f6f88f78173a2 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Tue, 15 Apr 2003 08:07:50 +0000 Subject: Update fileoffset and cacheoffset on error. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3556 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/firmware/common/file.c b/firmware/common/file.c index 8c0f9a8951..46af790bf7 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -421,11 +421,12 @@ static int readwrite(int fd, void* buf, int count, bool write) /* read whole sectors right into the supplied buffer */ sectors = count / SECTOR_SIZE; if ( sectors ) { - int rc = fat_readwrite(&(file->fatfile), sectors, - buf+nread, write ); + int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write ); if ( rc < 0 ) { DEBUGF("Failed read/writing %d sectors\n",sectors); errno = EIO; + file->fileoffset += nread; + file->cacheoffset = -1; return nread ? nread : rc * 10 - 4; } else { @@ -453,11 +454,12 @@ static int readwrite(int fd, void* buf, int count, bool write) /* sector is only partially filled. copy-back from disk */ int rc; LDEBUGF("Copy-back tail cache\n"); - rc = fat_readwrite(&(file->fatfile), 1, - file->cache, false ); + rc = fat_readwrite(&(file->fatfile), 1, file->cache, false ); if ( rc < 0 ) { DEBUGF("Failed writing\n"); errno = EIO; + file->fileoffset += nread; + file->cacheoffset = -1; return nread ? nread : rc * 10 - 5; } /* seek back one sector to put file position right */ @@ -467,6 +469,8 @@ static int readwrite(int fd, void* buf, int count, bool write) if ( rc < 0 ) { DEBUGF("fat_seek() failed\n"); errno = EIO; + file->fileoffset += nread; + file->cacheoffset = -1; return nread ? nread : rc * 10 - 6; } } @@ -478,6 +482,8 @@ static int readwrite(int fd, void* buf, int count, bool write) if (rc < 1 ) { DEBUGF("Failed caching sector\n"); errno = EIO; + file->fileoffset += nread; + file->cacheoffset = -1; return nread ? nread : rc * 10 - 7; } memcpy( buf + nread, file->cache, count ); -- cgit v1.2.3