From c6db7870ef001ffd7a64884b3e03d3b4cfc67b1d Mon Sep 17 00:00:00 2001 From: Linus Nielsen Feltzing Date: Thu, 19 Jun 2003 12:08:22 +0000 Subject: Slightly better handling of disk-full situations git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3756 a1c6a512-1295-4272-9138-f99709370657 --- firmware/common/file.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'firmware/common') 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) rc = fat_readwrite(&(file->fatfile), 1, file->cache, true ); - if ( rc < 0 ) + + if ( rc < 0 ) { + if(file->fatfile.eof) + errno = ENOSPC; + return rc * 10 - 2; + } file->dirty = false; @@ -418,14 +423,19 @@ static int readwrite(int fd, void* buf, int count, bool write) return rc * 10 - 3; } - /* read whole sectors right into the supplied buffer */ + /* read/write whole sectors right into/from the supplied buffer */ sectors = count / SECTOR_SIZE; if ( sectors ) { 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; + if(write && file->fatfile.eof) { + DEBUGF("No space left on device\n"); + errno = ENOSPC; + } else { + file->fileoffset += nread; + } file->cacheoffset = -1; return nread ? nread : rc * 10 - 4; } -- cgit v1.2.3