summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
authorPeter D'Hoye <peter.dhoye@gmail.com>2007-10-10 23:26:17 +0000
committerPeter D'Hoye <peter.dhoye@gmail.com>2007-10-10 23:26:17 +0000
commit85058f5d9caa0f9768b155c8963eaed6aa989ed5 (patch)
treeb26d50bf03fce5d8b7cea32a9bcb34d340c60015 /firmware/common
parentbcdb3217deba791d05ecd46328622831d8ed3b14 (diff)
downloadrockbox-85058f5d9caa0f9768b155c8963eaed6aa989ed5.zip
rockbox-85058f5d9caa0f9768b155c8963eaed6aa989ed5.tar.gz
rockbox-85058f5d9caa0f9768b155c8963eaed6aa989ed5.tar.bz2
rockbox-85058f5d9caa0f9768b155c8963eaed6aa989ed5.tar.xz
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')
-rw-r--r--firmware/common/file.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index ea2471a..9cab001 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -278,14 +278,22 @@ int fsync(int fd)
if ( file->dirty ) {
rc = flush_cache(fd);
if (rc < 0)
+ {
+ /* when failing, try to close the file anyway */
+ fat_closewrite(&(file->fatfile), file->size, file->attr);
return rc * 10 - 3;
+ }
}
/* truncate? */
if (file->trunc) {
rc = ftruncate(fd, file->size);
if (rc < 0)
+ {
+ /* when failing, try to close the file anyway */
+ fat_closewrite(&(file->fatfile), file->size, file->attr);
return rc * 10 - 4;
+ }
}
/* tie up all loose ends */
@@ -475,6 +483,10 @@ static int readwrite(int fd, void* buf, long count, bool write)
struct filedesc* file = &openfiles[fd];
int rc;
+ if (fd < 0 || fd > MAX_OPEN_FILES-1) {
+ errno = EINVAL;
+ return -1;
+ }
if ( !file->busy ) {
errno = EBADF;
return -1;
@@ -643,6 +655,10 @@ off_t lseek(int fd, off_t offset, int whence)
LDEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence);
+ if (fd < 0 || fd > MAX_OPEN_FILES-1) {
+ errno = EINVAL;
+ return -1;
+ }
if ( !file->busy ) {
errno = EBADF;
return -1;
@@ -716,6 +732,10 @@ off_t filesize(int fd)
{
struct filedesc* file = &openfiles[fd];
+ if (fd < 0 || fd > MAX_OPEN_FILES-1) {
+ errno = EINVAL;
+ return -1;
+ }
if ( !file->busy ) {
errno = EBADF;
return -1;
@@ -743,3 +763,4 @@ int release_files(int volume)
return closed; /* return how many we did */
}
#endif /* #ifdef HAVE_HOTSWAP */
+