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
This commit is contained in:
parent
6720018ae9
commit
89cd802c03
@ -708,14 +708,6 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
|
|||||||
|
|
||||||
while (buflen > 0)
|
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
|
/* Check if the user has provided a buffer large enough to
|
||||||
* hold one or more complete sectors.
|
* 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
|
/* 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);
|
(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)
|
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);
|
ret = fat_ffcacheread(fs, ff, ff->ff_currentsector);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
@ -778,9 +775,15 @@ static ssize_t fat_write(FAR struct file *filep, const char *buffer,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* But in this rare case, we do have to mark the unused cached
|
/* Flush unwritten data in the sector cache. */
|
||||||
* buffer as the current buffer.
|
|
||||||
*/
|
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;
|
ff->ff_cachesector = ff->ff_currentsector;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@
|
|||||||
#define F_DUPFD 0 /* Duplicate a file descriptor */
|
#define F_DUPFD 0 /* Duplicate a file descriptor */
|
||||||
#define F_GETFD 1 /* Read the file descriptor flags */
|
#define F_GETFD 1 /* Read the file descriptor flags */
|
||||||
#define F_GETFL 2 /* Read the file status flags */
|
#define F_GETFL 2 /* Read the file status flags */
|
||||||
#define F_GETLEASE 3 /* Indicas what type of lease is held on fd (linux) */
|
#define F_GETLEASE 3 /* Indicates what type of lease is held on fd (linux) */
|
||||||
#define F_GETLK 4 /* Check if we could place a lock */
|
#define F_GETLK 4 /* Check if we could place a lock */
|
||||||
#define F_GETOWN 5 /* Get the pid receiving SIGIO and SIGURG signals for fd */
|
#define F_GETOWN 5 /* Get the pid receiving SIGIO and SIGURG signals for fd */
|
||||||
#define F_GETSIG 6 /* Get the signal sent */
|
#define F_GETSIG 6 /* Get the signal sent */
|
||||||
|
Loading…
Reference in New Issue
Block a user