diff options
author | Linus Nielsen Feltzing <linus@haxx.se> | 2003-03-10 17:10:46 +0000 |
---|---|---|
committer | Linus Nielsen Feltzing <linus@haxx.se> | 2003-03-10 17:10:46 +0000 |
commit | 44e51833ed83c165b22026e7943461f419bccc0e (patch) | |
tree | 327ce89685730e7aa3d7d6e2767b3e9bb94f268e /firmware | |
parent | c5aaab4a36e8010e628cf3846d0fcf3039cb27be (diff) | |
download | rockbox-44e51833ed83c165b22026e7943461f419bccc0e.tar.gz rockbox-44e51833ed83c165b22026e7943461f419bccc0e.zip |
Zagor added the flush() function
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3416 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/common/file.c | 28 | ||||
-rw-r--r-- | firmware/include/file.h | 1 |
2 files changed, 28 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 | |||
195 | int 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 ); |
diff --git a/firmware/include/file.h b/firmware/include/file.h index 6c81cb93d7..75c55bbac9 100644 --- a/firmware/include/file.h +++ b/firmware/include/file.h | |||
@@ -56,6 +56,7 @@ extern int remove(const char*); | |||
56 | #ifndef SIMULATOR | 56 | #ifndef SIMULATOR |
57 | extern int open(const char* pathname, int flags); | 57 | extern int open(const char* pathname, int flags); |
58 | extern int close(int fd); | 58 | extern int close(int fd); |
59 | extern int flush(int fd); | ||
59 | extern int read(int fd, void* buf, int count); | 60 | extern int read(int fd, void* buf, int count); |
60 | extern int lseek(int fd, int offset, int whence); | 61 | extern int lseek(int fd, int offset, int whence); |
61 | extern int creat(const char *pathname, int mode); | 62 | extern int creat(const char *pathname, int mode); |