diff options
author | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-10-10 23:26:17 +0000 |
---|---|---|
committer | Peter D'Hoye <peter.dhoye@gmail.com> | 2007-10-10 23:26:17 +0000 |
commit | 85058f5d9caa0f9768b155c8963eaed6aa989ed5 (patch) | |
tree | b26d50bf03fce5d8b7cea32a9bcb34d340c60015 /firmware/common/file.c | |
parent | bcdb3217deba791d05ecd46328622831d8ed3b14 (diff) | |
download | rockbox-85058f5d9caa0f9768b155c8963eaed6aa989ed5.tar.gz rockbox-85058f5d9caa0f9768b155c8963eaed6aa989ed5.zip |
Fix FS #5852 by trying to properly close and update the recorded file, and give the FAT the correct file info. Add filehandle checks to some file functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15072 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/file.c')
-rw-r--r-- | firmware/common/file.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c index ea2471ae92..9cab001e8d 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -278,14 +278,22 @@ int fsync(int fd) | |||
278 | if ( file->dirty ) { | 278 | if ( file->dirty ) { |
279 | rc = flush_cache(fd); | 279 | rc = flush_cache(fd); |
280 | if (rc < 0) | 280 | if (rc < 0) |
281 | { | ||
282 | /* when failing, try to close the file anyway */ | ||
283 | fat_closewrite(&(file->fatfile), file->size, file->attr); | ||
281 | return rc * 10 - 3; | 284 | return rc * 10 - 3; |
285 | } | ||
282 | } | 286 | } |
283 | 287 | ||
284 | /* truncate? */ | 288 | /* truncate? */ |
285 | if (file->trunc) { | 289 | if (file->trunc) { |
286 | rc = ftruncate(fd, file->size); | 290 | rc = ftruncate(fd, file->size); |
287 | if (rc < 0) | 291 | if (rc < 0) |
292 | { | ||
293 | /* when failing, try to close the file anyway */ | ||
294 | fat_closewrite(&(file->fatfile), file->size, file->attr); | ||
288 | return rc * 10 - 4; | 295 | return rc * 10 - 4; |
296 | } | ||
289 | } | 297 | } |
290 | 298 | ||
291 | /* tie up all loose ends */ | 299 | /* tie up all loose ends */ |
@@ -475,6 +483,10 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
475 | struct filedesc* file = &openfiles[fd]; | 483 | struct filedesc* file = &openfiles[fd]; |
476 | int rc; | 484 | int rc; |
477 | 485 | ||
486 | if (fd < 0 || fd > MAX_OPEN_FILES-1) { | ||
487 | errno = EINVAL; | ||
488 | return -1; | ||
489 | } | ||
478 | if ( !file->busy ) { | 490 | if ( !file->busy ) { |
479 | errno = EBADF; | 491 | errno = EBADF; |
480 | return -1; | 492 | return -1; |
@@ -643,6 +655,10 @@ off_t lseek(int fd, off_t offset, int whence) | |||
643 | 655 | ||
644 | LDEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence); | 656 | LDEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence); |
645 | 657 | ||
658 | if (fd < 0 || fd > MAX_OPEN_FILES-1) { | ||
659 | errno = EINVAL; | ||
660 | return -1; | ||
661 | } | ||
646 | if ( !file->busy ) { | 662 | if ( !file->busy ) { |
647 | errno = EBADF; | 663 | errno = EBADF; |
648 | return -1; | 664 | return -1; |
@@ -716,6 +732,10 @@ off_t filesize(int fd) | |||
716 | { | 732 | { |
717 | struct filedesc* file = &openfiles[fd]; | 733 | struct filedesc* file = &openfiles[fd]; |
718 | 734 | ||
735 | if (fd < 0 || fd > MAX_OPEN_FILES-1) { | ||
736 | errno = EINVAL; | ||
737 | return -1; | ||
738 | } | ||
719 | if ( !file->busy ) { | 739 | if ( !file->busy ) { |
720 | errno = EBADF; | 740 | errno = EBADF; |
721 | return -1; | 741 | return -1; |
@@ -743,3 +763,4 @@ int release_files(int volume) | |||
743 | return closed; /* return how many we did */ | 763 | return closed; /* return how many we did */ |
744 | } | 764 | } |
745 | #endif /* #ifdef HAVE_HOTSWAP */ | 765 | #endif /* #ifdef HAVE_HOTSWAP */ |
766 | |||