summaryrefslogtreecommitdiff
path: root/firmware/common
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/common')
-rw-r--r--firmware/common/file.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/firmware/common/file.c b/firmware/common/file.c
index 516618b460..17660d3dc7 100644
--- a/firmware/common/file.c
+++ b/firmware/common/file.c
@@ -183,6 +183,31 @@ int close(int fd)
183 return -2; 183 return -2;
184 } 184 }
185 if (file->write) { 185 if (file->write) {
186 rc = flush(fd);
187 if (rc < 0)
188 return rc * 10 - 3;
189 }
190
191 file->busy = false;
192 return 0;
193}
194
195int flush(int fd)
196{
197 struct filedesc* file = &openfiles[fd];
198 int rc = 0;
199
200 LDEBUGF("flush(%d)\n", fd);
201
202 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
203 errno = EINVAL;
204 return -1;
205 }
206 if (!file->busy) {
207 errno = EBADF;
208 return -2;
209 }
210 if (file->write) {
186 /* flush sector cache */ 211 /* flush sector cache */
187 if ( file->dirty ) { 212 if ( file->dirty ) {
188 rc = flush_cache(fd); 213 rc = flush_cache(fd);
@@ -202,7 +227,6 @@ int close(int fd)
202 if (rc < 0) 227 if (rc < 0)
203 return rc * 10 - 5; 228 return rc * 10 - 5;
204 } 229 }
205 file->busy = false;
206 return 0; 230 return 0;
207} 231}
208 232
@@ -318,9 +342,11 @@ static int flush_cache(int fd)
318 DEBUGF("Flushing dirty sector cache %x\n", sector); 342 DEBUGF("Flushing dirty sector cache %x\n", sector);
319 343
320 /* seek back one sector to get file position right */ 344 /* seek back one sector to get file position right */
345#if 0
321 rc = fat_seek(&(file->fatfile), sector); 346 rc = fat_seek(&(file->fatfile), sector);
322 if ( rc < 0 ) 347 if ( rc < 0 )
323 return rc * 10 - 1; 348 return rc * 10 - 1;
349#endif
324 350
325 rc = fat_readwrite(&(file->fatfile), 1, 351 rc = fat_readwrite(&(file->fatfile), 1,
326 file->cache, true ); 352 file->cache, true );