diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/file.c | 21 | ||||
-rw-r--r-- | firmware/drivers/fat.c | 4 | ||||
-rw-r--r-- | firmware/pcm_record.c | 3 |
3 files changed, 28 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 | |||
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c index f117119258..a4fa7aa933 100644 --- a/firmware/drivers/fat.c +++ b/firmware/drivers/fat.c | |||
@@ -2084,6 +2084,8 @@ long fat_readwrite( struct fat_file *file, long sectorcount, | |||
2084 | numsec++; | 2084 | numsec++; |
2085 | if ( numsec > (long)fat_bpb->bpb_secperclus || !cluster ) { | 2085 | if ( numsec > (long)fat_bpb->bpb_secperclus || !cluster ) { |
2086 | long oldcluster = cluster; | 2086 | long oldcluster = cluster; |
2087 | long oldsector = sector; | ||
2088 | long oldnumsec = numsec; | ||
2087 | if (write) | 2089 | if (write) |
2088 | cluster = next_write_cluster(file, cluster, §or); | 2090 | cluster = next_write_cluster(file, cluster, §or); |
2089 | else { | 2091 | else { |
@@ -2099,7 +2101,9 @@ long fat_readwrite( struct fat_file *file, long sectorcount, | |||
2099 | if ( write ) { | 2101 | if ( write ) { |
2100 | /* remember last cluster, in case | 2102 | /* remember last cluster, in case |
2101 | we want to append to the file */ | 2103 | we want to append to the file */ |
2104 | sector = oldsector; | ||
2102 | cluster = oldcluster; | 2105 | cluster = oldcluster; |
2106 | numsec = oldnumsec; | ||
2103 | clusternum--; | 2107 | clusternum--; |
2104 | i = -1; /* Error code */ | 2108 | i = -1; /* Error code */ |
2105 | break; | 2109 | break; |
diff --git a/firmware/pcm_record.c b/firmware/pcm_record.c index ac12fe2ba0..361689de3a 100644 --- a/firmware/pcm_record.c +++ b/firmware/pcm_record.c | |||
@@ -901,7 +901,10 @@ static void pcmrec_flush(unsigned flush_num) | |||
901 | INC_ENC_INDEX(enc_rd_index); | 901 | INC_ENC_INDEX(enc_rd_index); |
902 | 902 | ||
903 | if (errors != 0) | 903 | if (errors != 0) |
904 | { | ||
905 | pcmrec_end_file(); | ||
904 | break; | 906 | break; |
907 | } | ||
905 | 908 | ||
906 | if (flush_num == PCMREC_FLUSH_MINI && | 909 | if (flush_num == PCMREC_FLUSH_MINI && |
907 | ++chunks_flushed >= MINI_CHUNKS) | 910 | ++chunks_flushed >= MINI_CHUNKS) |