summaryrefslogtreecommitdiff
path: root/firmware/common/file.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-10-31 19:05:25 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-10-31 19:05:25 +0000
commit08356fb50a70bc44e598ff49ab61bd149060a668 (patch)
tree00a9d8d7f42a5102643b228f58ff2c85932478fb /firmware/common/file.c
parent0d79fa127dfc1f5650d3701a174983de8f9e5e4d (diff)
downloadrockbox-08356fb50a70bc44e598ff49ab61bd149060a668.tar.gz
rockbox-08356fb50a70bc44e598ff49ab61bd149060a668.zip
More graceful handling when running out of space.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2793 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r--firmware/common/file.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 0cde938a70..3e730c2880 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -197,13 +197,9 @@ static int readwrite(int fd, void* buf, int count, bool write)
197 LDEBUGF( "readwrite(%d,%x,%d,%s)\n", 197 LDEBUGF( "readwrite(%d,%x,%d,%s)\n",
198 fd,buf,count,write?"write":"read"); 198 fd,buf,count,write?"write":"read");
199 199
200 /* attempt to access past EOF? */ 200 /* attempt to read past EOF? */
201 if (count > openfiles[fd].size - openfiles[fd].fileoffset) { 201 if (!write && count > openfiles[fd].size - openfiles[fd].fileoffset)
202 if ( write ) 202 count = openfiles[fd].size - openfiles[fd].fileoffset;
203 openfiles[fd].size = openfiles[fd].fileoffset + count;
204 else
205 count = openfiles[fd].size - openfiles[fd].fileoffset;
206 }
207 203
208 /* any head bytes? */ 204 /* any head bytes? */
209 if ( openfiles[fd].cacheoffset != -1 ) { 205 if ( openfiles[fd].cacheoffset != -1 ) {
@@ -253,8 +249,12 @@ static int readwrite(int fd, void* buf, int count, bool write)
253 } 249 }
254 else { 250 else {
255 if ( rc > 0 ) { 251 if ( rc > 0 ) {
256 nread += sectors * SECTOR_SIZE; 252 nread += rc * SECTOR_SIZE;
257 count -= sectors * SECTOR_SIZE; 253 count -= sectors * SECTOR_SIZE;
254
255 /* if eof, skip tail bytes */
256 if ( rc < sectors )
257 count = 0;
258 } 258 }
259 else { 259 else {
260 /* eof */ 260 /* eof */
@@ -285,6 +285,12 @@ static int readwrite(int fd, void* buf, int count, bool write)
285 } 285 }
286 286
287 openfiles[fd].fileoffset += nread; 287 openfiles[fd].fileoffset += nread;
288 LDEBUGF("fileoffset: %d\n", openfiles[fd].fileoffset);
289
290 /* adjust file size to length written */
291 if ( write && openfiles[fd].fileoffset > openfiles[fd].size )
292 openfiles[fd].size = openfiles[fd].fileoffset;
293
288 return nread; 294 return nread;
289} 295}
290 296