summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-11-11 11:16:49 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-11-11 11:16:49 +0000
commit6dc77d881b7fecf9818f272743eb8076275e7120 (patch)
tree737e762d2bc84cd9668dfa277f986056abde2d68 /firmware/common/file.c
parent11a09e632ceb5513aad54aa6b2c6031bb28b4533 (diff)
downloadrockbox-6dc77d881b7fecf9818f272743eb8076275e7120.tar.gz
rockbox-6dc77d881b7fecf9818f272743eb8076275e7120.zip
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
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c39
1 files changed, 20 insertions, 19 deletions
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)
292 openfiles[fd].cacheoffset = -1; 292 openfiles[fd].cacheoffset = -1;
293 } 293 }
294 } 294 }
295 openfiles[fd].fileoffset += nread;
296 nread = 0;
297 295
298 /* any tail bytes? */ 296 /* any tail bytes? */
299 if ( count ) { 297 if ( count ) {
300 if (write) { 298 if (write) {
301 /* sector is only partially filled. copy-back from disk */ 299 if ( openfiles[fd].fileoffset + nread < openfiles[fd].size ) {
302 int rc; 300 /* sector is only partially filled. copy-back from disk */
303 LDEBUGF("Copy-back tail cache\n"); 301 int rc;
304 rc = fat_readwrite(&(openfiles[fd].fatfile), 1, 302 LDEBUGF("Copy-back tail cache\n");
305 openfiles[fd].cache, false ); 303 rc = fat_readwrite(&(openfiles[fd].fatfile), 1,
306 if ( rc < 0 ) { 304 openfiles[fd].cache, false );
307 DEBUGF("Failed reading\n"); 305 if ( rc < 0 ) {
308 errno = EIO; 306 DEBUGF("Failed reading\n");
309 return -4; 307 errno = EIO;
310 } 308 return -4;
311 /* seek back one sector to put file position right */ 309 }
312 rc = fat_seek(&(openfiles[fd].fatfile), 310 /* seek back one sector to put file position right */
313 openfiles[fd].fileoffset / SECTOR_SIZE); 311 rc = fat_seek(&(openfiles[fd].fatfile),
314 if ( rc < 0 ) { 312 (openfiles[fd].fileoffset + nread) /
315 DEBUGF("fat_seek() failed\n"); 313 SECTOR_SIZE);
316 errno = EIO; 314 if ( rc < 0 ) {
317 return -5; 315 DEBUGF("fat_seek() failed\n");
316 errno = EIO;
317 return -5;
318 }
318 } 319 }
319 memcpy( openfiles[fd].cache, buf + nread, count ); 320 memcpy( openfiles[fd].cache, buf + nread, count );
320 } 321 }