Index: apps/codecs/wav_enc.c =================================================================== --- apps/codecs/wav_enc.c (revision 14972) +++ apps/codecs/wav_enc.c (working copy) @@ -144,8 +144,10 @@ struct riff_header hdr; uint32_t data_size; + /* always _try_ to write the file header, even on error if (!is_file_data_ok(data)) return false; + */ if (ci->lseek(data->rec_file, 0, SEEK_SET) != 0 || ci->read(data->rec_file, &hdr, sizeof (hdr)) != sizeof (hdr)) @@ -387,7 +389,7 @@ /* reset parameters to initial state */ ci->enc_set_parameters(NULL); - + /* main application waits for this flag during encoder removing */ ci->enc_codec_loaded = 0; Index: firmware/common/file.c =================================================================== --- firmware/common/file.c (revision 14972) +++ firmware/common/file.c (working copy) @@ -7,7 +7,7 @@ * \/ \/ \/ \/ \/ * $Id$ * - * Copyright (C) 2002 by Björn Stenberg + * Copyright (C) 2002 by Bj�rn Stenberg * * All files in this archive are subject to the GNU General Public License. * See the file COPYING in the source tree root for full license agreement. @@ -278,14 +278,22 @@ 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 */ Index: firmware/pcm_record.c =================================================================== --- firmware/pcm_record.c (revision 14972) +++ firmware/pcm_record.c (working copy) @@ -918,7 +918,10 @@ INC_ENC_INDEX(enc_rd_index); if (errors != 0) + { + pcmrec_end_file(); break; + } if (flush_num == PCMREC_FLUSH_MINI && ++chunks_flushed >= MINI_CHUNKS) Index: firmware/drivers/fat.c =================================================================== --- firmware/drivers/fat.c (revision 14972) +++ firmware/drivers/fat.c (working copy) @@ -2084,6 +2084,8 @@ numsec++; if ( numsec > (long)fat_bpb->bpb_secperclus || !cluster ) { long oldcluster = cluster; + long oldsector = sector; + long oldnumsec = numsec; if (write) cluster = next_write_cluster(file, cluster, §or); else { @@ -2099,7 +2101,9 @@ if ( write ) { /* remember last cluster, in case we want to append to the file */ + sector = oldsector; cluster = oldcluster; + numsec = oldnumsec; clusternum--; i = -1; /* Error code */ break;