summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-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 }