diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-10-31 19:05:25 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-10-31 19:05:25 +0000 |
commit | 08356fb50a70bc44e598ff49ab61bd149060a668 (patch) | |
tree | 00a9d8d7f42a5102643b228f58ff2c85932478fb /firmware/common | |
parent | 0d79fa127dfc1f5650d3701a174983de8f9e5e4d (diff) | |
download | rockbox-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')
-rw-r--r-- | firmware/common/file.c | 22 |
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 | ||