Fix error in FAT FS when file opened for O_APPEND
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@827 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
0ef52f153e
commit
6adab3df7c
@ -406,4 +406,10 @@
|
|||||||
int and unsigned int.
|
int and unsigned int.
|
||||||
* Add support for redirection of command output in NSH
|
* Add support for redirection of command output in NSH
|
||||||
* NSH can now use both telnet and serial front ends together
|
* 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.
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<tr align="center" bgcolor="#e4e4e4">
|
<tr align="center" bgcolor="#e4e4e4">
|
||||||
<td>
|
<td>
|
||||||
<h1><big><font color="#3c34ec"><i>NuttX RTOS</i></font></big></h1>
|
<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>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
@ -1040,6 +1040,12 @@ nuttx-0.3.13 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
|||||||
int and unsigned int.
|
int and unsigned int.
|
||||||
* Add support for redirection of command output in NSH
|
* Add support for redirection of command output in NSH
|
||||||
* NSH can now use both telnet and serial front ends together
|
* 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 <spudmonkey@racsa.co.cr>
|
pascal-0.1.3 2008-xx-xx Gregory Nutt <spudmonkey@racsa.co.cr>
|
||||||
|
|
||||||
|
2
TODO
2
TODO
@ -10,7 +10,7 @@ NuttX TODO List (Last updated July 31, 2008)
|
|||||||
(11) Network (net/, netutils/)
|
(11) Network (net/, netutils/)
|
||||||
(2) USB (drivers/usbdev)
|
(2) USB (drivers/usbdev)
|
||||||
(3) Libraries (lib/)
|
(3) Libraries (lib/)
|
||||||
(5) File system/Generic drivers (fs/, drivers/)
|
(4) File system/Generic drivers (fs/, drivers/)
|
||||||
(1) Pascal add-on (pcode/)
|
(1) Pascal add-on (pcode/)
|
||||||
(2) Documentation (Documentation/)
|
(2) Documentation (Documentation/)
|
||||||
(3) Build system
|
(3) Build system
|
||||||
|
@ -318,13 +318,6 @@ static int fat_open(FAR struct file *filp, const char *relpath,
|
|||||||
|
|
||||||
ff->ff_size = DIR_GETFILESIZE(dirinfo.fd_entry);
|
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 */
|
/* Attach the private date to the struct file instance */
|
||||||
|
|
||||||
filp->f_priv = ff;
|
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;
|
fs->fs_head = ff->ff_next;
|
||||||
|
|
||||||
fat_semgive(fs);
|
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;
|
return OK;
|
||||||
|
|
||||||
/* Error exits -- goto's are nasty things, but they sure can make error
|
/* 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;
|
byteswritten = 0;
|
||||||
writesector = ff->ff_currentsector;
|
writesector = ff->ff_currentsector;
|
||||||
while (buflen > 0)
|
while (buflen > 0)
|
||||||
{
|
{
|
||||||
/* Get offset into the sector where we begin the read */
|
/* 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
|
else
|
||||||
{
|
{
|
||||||
/* Extend the chain by adding a new cluster after
|
/* Extend the chain by adding a new cluster after
|
||||||
* the last one
|
* the last one
|
||||||
*/
|
*/
|
||||||
|
|
||||||
cluster = fat_extendchain(fs, ff->ff_currentcluster);
|
cluster = fat_extendchain(fs, ff->ff_currentcluster);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify the cluster number */
|
/* 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;
|
nsectors = buflen / fs->fs_hwsectorsize;
|
||||||
if (nsectors > 0)
|
if (nsectors > 0 && sectorindex == 0)
|
||||||
{
|
{
|
||||||
/* Write maximum contiguous sectors directly from the user's
|
/* Write maximum contiguous sectors directly from the user's
|
||||||
* buffer without using our tiny read buffer.
|
* buffer without using our tiny read buffer.
|
||||||
@ -804,12 +810,18 @@ static ssize_t fat_write(FAR struct file *filp, const char *buffer,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* We are write a partial sector. We will first have to
|
/* We are writing a partial sector -OR- the current sector
|
||||||
* read the full sector in memory as part of a read-modify-write
|
* has not yet been filled.
|
||||||
* operation.
|
*
|
||||||
|
* 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;
|
ff->ff_currentsector = writesector;
|
||||||
ret = fat_ffcacheread(fs, ff, 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
|
else
|
||||||
{
|
{
|
||||||
/* Other we can only follong the existing chain */
|
/* Otherwise we can only follong the existing chain */
|
||||||
|
|
||||||
cluster = fat_getcluster(fs, cluster);
|
cluster = fat_getcluster(fs, cluster);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user