diff options
-rw-r--r-- | apps/codecs/mp3_enc.c | 3 | ||||
-rw-r--r-- | apps/codecs/wav_enc.c | 8 | ||||
-rw-r--r-- | apps/codecs/wavpack_enc.c | 3 | ||||
-rw-r--r-- | firmware/common/file.c | 24 |
4 files changed, 35 insertions, 3 deletions
diff --git a/apps/codecs/mp3_enc.c b/apps/codecs/mp3_enc.c index 2dc9bcbb3d..26cc1dd73f 100644 --- a/apps/codecs/mp3_enc.c +++ b/apps/codecs/mp3_enc.c | |||
@@ -2329,6 +2329,9 @@ static bool on_start_file(struct enc_file_event_data *data) | |||
2329 | 2329 | ||
2330 | static bool on_end_file(struct enc_file_event_data *data) | 2330 | static bool on_end_file(struct enc_file_event_data *data) |
2331 | { | 2331 | { |
2332 | if (data->rec_file < 0) | ||
2333 | return false; /* file already closed, nothing more we can do */ | ||
2334 | |||
2332 | /* always _try_ to write the file header, even on error */ | 2335 | /* always _try_ to write the file header, even on error */ |
2333 | if (ci->close(data->rec_file) != 0) | 2336 | if (ci->close(data->rec_file) != 0) |
2334 | return false; | 2337 | return false; |
diff --git a/apps/codecs/wav_enc.c b/apps/codecs/wav_enc.c index 25d2838e7d..5932fd319d 100644 --- a/apps/codecs/wav_enc.c +++ b/apps/codecs/wav_enc.c | |||
@@ -144,10 +144,12 @@ static bool on_end_file(struct enc_file_event_data *data) | |||
144 | struct riff_header hdr; | 144 | struct riff_header hdr; |
145 | uint32_t data_size; | 145 | uint32_t data_size; |
146 | 146 | ||
147 | /* always _try_ to write the file header, even on error */ | 147 | if (data->rec_file < 0) |
148 | return false; /* file already closed, nothing more we can do */ | ||
148 | 149 | ||
149 | if (ci->lseek(data->rec_file, 0, SEEK_SET) != 0 || | 150 | /* always _try_ to write the file header, even on error */ |
150 | ci->read(data->rec_file, &hdr, sizeof (hdr)) != sizeof (hdr)) | 151 | if ((ci->lseek(data->rec_file, 0, SEEK_SET)) || |
152 | (ci->read(data->rec_file, &hdr, sizeof (hdr)) != sizeof (hdr))) | ||
151 | { | 153 | { |
152 | return false; | 154 | return false; |
153 | } | 155 | } |
diff --git a/apps/codecs/wavpack_enc.c b/apps/codecs/wavpack_enc.c index 70261e70e2..670a518d64 100644 --- a/apps/codecs/wavpack_enc.c +++ b/apps/codecs/wavpack_enc.c | |||
@@ -257,6 +257,9 @@ static bool on_end_file(struct enc_file_event_data *data) | |||
257 | 257 | ||
258 | uint32_t data_size; | 258 | uint32_t data_size; |
259 | 259 | ||
260 | if (data->rec_file < 0) | ||
261 | return false; /* file already closed, nothing more we can do */ | ||
262 | |||
260 | /* always _try_ to write the file header, even on error */ | 263 | /* always _try_ to write the file header, even on error */ |
261 | 264 | ||
262 | /* read template headers at start */ | 265 | /* read template headers at start */ |
diff --git a/firmware/common/file.c b/firmware/common/file.c index 9290f508b8..f0437f9e68 100644 --- a/firmware/common/file.c +++ b/firmware/common/file.c | |||
@@ -548,6 +548,14 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
548 | file->fileoffset += nread; | 548 | file->fileoffset += nread; |
549 | } | 549 | } |
550 | file->cacheoffset = -1; | 550 | file->cacheoffset = -1; |
551 | /* adjust file size to length written */ | ||
552 | if ( write && file->fileoffset > file->size ) | ||
553 | { | ||
554 | file->size = file->fileoffset; | ||
555 | #ifdef HAVE_DIRCACHE | ||
556 | dircache_update_filesize(fd, file->size, file->fatfile.firstcluster); | ||
557 | #endif | ||
558 | } | ||
551 | return nread ? nread : rc * 10 - 4; | 559 | return nread ? nread : rc * 10 - 4; |
552 | } | 560 | } |
553 | else { | 561 | else { |
@@ -580,6 +588,14 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
580 | errno = EIO; | 588 | errno = EIO; |
581 | file->fileoffset += nread; | 589 | file->fileoffset += nread; |
582 | file->cacheoffset = -1; | 590 | file->cacheoffset = -1; |
591 | /* adjust file size to length written */ | ||
592 | if ( file->fileoffset > file->size ) | ||
593 | { | ||
594 | file->size = file->fileoffset; | ||
595 | #ifdef HAVE_DIRCACHE | ||
596 | dircache_update_filesize(fd, file->size, file->fatfile.firstcluster); | ||
597 | #endif | ||
598 | } | ||
583 | return nread ? nread : rc * 10 - 5; | 599 | return nread ? nread : rc * 10 - 5; |
584 | } | 600 | } |
585 | /* seek back one sector to put file position right */ | 601 | /* seek back one sector to put file position right */ |
@@ -591,6 +607,14 @@ static int readwrite(int fd, void* buf, long count, bool write) | |||
591 | errno = EIO; | 607 | errno = EIO; |
592 | file->fileoffset += nread; | 608 | file->fileoffset += nread; |
593 | file->cacheoffset = -1; | 609 | file->cacheoffset = -1; |
610 | /* adjust file size to length written */ | ||
611 | if ( file->fileoffset > file->size ) | ||
612 | { | ||
613 | file->size = file->fileoffset; | ||
614 | #ifdef HAVE_DIRCACHE | ||
615 | dircache_update_filesize(fd, file->size, file->fatfile.firstcluster); | ||
616 | #endif | ||
617 | } | ||
594 | return nread ? nread : rc * 10 - 6; | 618 | return nread ? nread : rc * 10 - 6; |
595 | } | 619 | } |
596 | } | 620 | } |