9
0
Fork 0

Fix error in FAT FS when file opened for O_APPEND

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@827 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-08-17 16:19:13 +00:00
parent 7031259b45
commit 3d8559c17d
4 changed files with 44 additions and 20 deletions

View File

@ -406,4 +406,10 @@
int and unsigned int.
* Add support for redirection of command output in NSH
* NSH can now use both telnet and serial front ends together
* $variable can be used for any command value in NSH.
* Fixed an error in opendir() that could cause an assertion to fail
inappropriately.
* Correct an error in the FAT that caused files opened for writing with
O_APPEND to fail. The file was not being properly positioned to the
end of the file in that case.

View File

@ -8,7 +8,7 @@
<tr align="center" bgcolor="#e4e4e4">
<td>
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
<p>Last Updated: August 16, 2008</p>
<p>Last Updated: August 17, 2008</p>
</td>
</tr>
</table>
@ -1040,6 +1040,12 @@ nuttx-0.3.13 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;
int and unsigned int.
* Add support for redirection of command output in NSH
* NSH can now use both telnet and serial front ends together
* $variable can be used for any command value in NSH.
* Fixed an error in opendir() that could cause an assertion to fail
inappropriately.
* Correct an error in the FAT that caused files opened for writing with
O_APPEND to fail. The file was not being properly positioned to the
end of the file in that case.
pascal-0.1.3 2008-xx-xx Gregory Nutt &lt;spudmonkey@racsa.co.cr&gt;

View File

@ -10,7 +10,7 @@ NuttX TODO List (Last updated July 31, 2008)
(11) Network (net/, netutils/)
(2) USB (drivers/usbdev)
(3) Libraries (lib/)
(5) File system/Generic drivers (fs/, drivers/)
(4) File system/Generic drivers (fs/, drivers/)
(1) Pascal add-on (pcode/)
(2) Documentation (Documentation/)
(3) Build system

View File

@ -318,13 +318,6 @@ static int fat_open(FAR struct file *filp, const char *relpath,
ff->ff_size = DIR_GETFILESIZE(dirinfo.fd_entry);
/* In write/append mode, we need to set the file pointer to the end of the file */
if ((oflags & (O_APPEND|O_WRONLY)) == (O_APPEND|O_WRONLY))
{
ff->ff_position = ff->ff_size;
}
/* Attach the private date to the struct file instance */
filp->f_priv = ff;
@ -339,6 +332,19 @@ static int fat_open(FAR struct file *filp, const char *relpath,
fs->fs_head = ff->ff_next;
fat_semgive(fs);
/* In write/append mode, we need to set the file pointer to the end of the file */
if ((oflags & (O_APPEND|O_WRONLY)) == (O_APPEND|O_WRONLY))
{
ssize_t offset = (ssize_t)fat_seek(filp, ff->ff_size, SEEK_SET);
if (offset < 0)
{
free(ff);
return (int)offset;
}
}
return OK;
/* Error exits -- goto's are nasty things, but they sure can make error
@ -670,7 +676,7 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
*/
byteswritten = 0;
writesector = ff->ff_currentsector;
writesector = ff->ff_currentsector;
while (buflen > 0)
{
/* Get offset into the sector where we begin the read */
@ -727,11 +733,11 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
else
{
/* Extend the chain by adding a new cluster after
* the last one
*/
/* Extend the chain by adding a new cluster after
* the last one
*/
cluster = fat_extendchain(fs, ff->ff_currentcluster);
cluster = fat_extendchain(fs, ff->ff_currentcluster);
}
/* Verify the cluster number */
@ -768,7 +774,7 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
*/
nsectors = buflen / fs->fs_hwsectorsize;
if (nsectors > 0)
if (nsectors > 0 && sectorindex == 0)
{
/* Write maximum contiguous sectors directly from the user's
* buffer without using our tiny read buffer.
@ -804,12 +810,18 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
}
else
{
/* We are write a partial sector. We will first have to
* read the full sector in memory as part of a read-modify-write
* operation.
/* We are writing a partial sector -OR- the current sector
* has not yet been filled.
*
* We will first have to read the full sector in memory as
* part of a read-modify-write operation. NOTE we don't
* have to read the data on a rare case: When we are extending
* the file (ff->ff_position == ff->ff_size) -AND- the new data
* happens to be aligned at the beginning of the sector
* (sectorindex == 0).
*/
if (ff->ff_position < ff->ff_size)
if (ff->ff_position < ff->ff_size || sectorindex != 0)
{
ff->ff_currentsector = writesector;
ret = fat_ffcacheread(fs, ff, writesector);
@ -997,7 +1009,7 @@ static off_t fat_seek(FAR struct file *filp, off_t offset, int whence)
}
else
{
/* Other we can only follong the existing chain */
/* Otherwise we can only follong the existing chain */
cluster = fat_getcluster(fs, cluster);
}