summaryrefslogtreecommitdiff
path: root/nuttx/fs
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-09-15 23:06:41 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-09-15 23:06:41 +0000
commit7da9d707ebf877eeda8d126a8489997cc32eaa5d (patch)
tree540eb2a0ff127b4240be66e1daddbc4211a634ec /nuttx/fs
parentdfcb307e3869a6df376eb0c663e1798235a1c40e (diff)
downloadpx4-nuttx-7da9d707ebf877eeda8d126a8489997cc32eaa5d.tar.gz
px4-nuttx-7da9d707ebf877eeda8d126a8489997cc32eaa5d.tar.bz2
px4-nuttx-7da9d707ebf877eeda8d126a8489997cc32eaa5d.zip
Small improvement in FAT buffering logic on write()
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3957 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/fs')
-rw-r--r--nuttx/fs/fat/fs_fat32.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c
index 4dfda324f..8a7f6e29a 100644
--- a/nuttx/fs/fat/fs_fat32.c
+++ b/nuttx/fs/fat/fs_fat32.c
@@ -708,14 +708,6 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
while (buflen > 0)
{
- /* Check if there is unwritten data in the file buffer */
-
- ret = fat_ffcacheflush(fs, ff);
- if (ret < 0)
- {
- goto errout_with_semaphore;
- }
-
/* Check if the user has provided a buffer large enough to
* hold one or more complete sectors.
*/
@@ -737,7 +729,8 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
}
/* We are not sure of the state of the file buffer so
- * the safest thing to do is just invalidate it
+ * the safest thing to do is write back any dirty, cached sector
+ * and invalidate the current cache content.
*/
(void)fat_ffcacheinvalidate(fs, ff);
@@ -770,6 +763,10 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
if (filep->f_pos < ff->ff_size || sectorindex != 0)
{
+ /* Read the current sector into memory (perhaps first flushing
+ * the old, dirty sector to disk).
+ */
+
ret = fat_ffcacheread(fs, ff, ff->ff_currentsector);
if (ret < 0)
{
@@ -778,9 +775,15 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
}
else
{
- /* But in this rare case, we do have to mark the unused cached
- * buffer as the current buffer.
- */
+ /* Flush unwritten data in the sector cache. */
+
+ ret = fat_ffcacheflush(fs, ff);
+ if (ret < 0)
+ {
+ goto errout_with_semaphore;
+ }
+
+ /* Now mark the clean cache buffer as the current sector. */
ff->ff_cachesector = ff->ff_currentsector;
}