summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c16
1 files changed, 13 insertions, 3 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 46af790bf7..01279d4421 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -348,8 +348,13 @@ static int flush_cache(int fd)
348 348
349 rc = fat_readwrite(&(file->fatfile), 1, 349 rc = fat_readwrite(&(file->fatfile), 1,
350 file->cache, true ); 350 file->cache, true );
351 if ( rc < 0 ) 351
352 if ( rc < 0 ) {
353 if(file->fatfile.eof)
354 errno = ENOSPC;
355
352 return rc * 10 - 2; 356 return rc * 10 - 2;
357 }
353 358
354 file->dirty = false; 359 file->dirty = false;
355 360
@@ -418,14 +423,19 @@ static int readwrite(int fd, void* buf, int count, bool write)
418 return rc * 10 - 3; 423 return rc * 10 - 3;
419 } 424 }
420 425
421 /* read whole sectors right into the supplied buffer */ 426 /* read/write whole sectors right into/from the supplied buffer */
422 sectors = count / SECTOR_SIZE; 427 sectors = count / SECTOR_SIZE;
423 if ( sectors ) { 428 if ( sectors ) {
424 int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write ); 429 int rc = fat_readwrite(&(file->fatfile), sectors, buf+nread, write );
425 if ( rc < 0 ) { 430 if ( rc < 0 ) {
426 DEBUGF("Failed read/writing %d sectors\n",sectors); 431 DEBUGF("Failed read/writing %d sectors\n",sectors);
427 errno = EIO; 432 errno = EIO;
428 file->fileoffset += nread; 433 if(write && file->fatfile.eof) {
434 DEBUGF("No space left on device\n");
435 errno = ENOSPC;
436 } else {
437 file->fileoffset += nread;
438 }
429 file->cacheoffset = -1; 439 file->cacheoffset = -1;
430 return nread ? nread : rc * 10 - 4; 440 return nread ? nread : rc * 10 - 4;
431 } 441 }