From 6dc77d881b7fecf9818f272743eb8076275e7120 Mon Sep 17 00:00:00 2001 From: Björn Stenberg Date: Mon, 11 Nov 2002 11:16:49 +0000 Subject: Bug fix for previous commit: write() always returned 0 on even sector writes. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2822 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) (limited to 'firmware/common') diff --git a/firmware/common/file.c b/firmware/common/file.c index b2c2644725..d86609e470 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c @@ -292,29 +292,30 @@ static int readwrite(int fd, void* buf, int count, bool write) openfiles[fd].cacheoffset = -1; } } - openfiles[fd].fileoffset += nread; - nread = 0; /* any tail bytes? */ if ( count ) { if (write) { - /* sector is only partially filled. copy-back from disk */ - int rc; - LDEBUGF("Copy-back tail cache\n"); - rc = fat_readwrite(&(openfiles[fd].fatfile), 1, - openfiles[fd].cache, false ); - if ( rc < 0 ) { - DEBUGF("Failed reading\n"); - errno = EIO; - return -4; - } - /* seek back one sector to put file position right */ - rc = fat_seek(&(openfiles[fd].fatfile), - openfiles[fd].fileoffset / SECTOR_SIZE); - if ( rc < 0 ) { - DEBUGF("fat_seek() failed\n"); - errno = EIO; - return -5; + if ( openfiles[fd].fileoffset + nread < openfiles[fd].size ) { + /* sector is only partially filled. copy-back from disk */ + int rc; + LDEBUGF("Copy-back tail cache\n"); + rc = fat_readwrite(&(openfiles[fd].fatfile), 1, + openfiles[fd].cache, false ); + if ( rc < 0 ) { + DEBUGF("Failed reading\n"); + errno = EIO; + return -4; + } + /* seek back one sector to put file position right */ + rc = fat_seek(&(openfiles[fd].fatfile), + (openfiles[fd].fileoffset + nread) / + SECTOR_SIZE); + if ( rc < 0 ) { + DEBUGF("fat_seek() failed\n"); + errno = EIO; + return -5; + } } memcpy( openfiles[fd].cache, buf + nread, count ); } -- cgit v1.2.3