summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-17 16:19:13 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2008-08-17 16:19:13 +0000
commitef3f1a8672de0cc79514af2139c1a567a36a3783 (patch)
treed725e5e9ea7a7bd7a172dfa6f9b491c499d06cb9
parent002549e43c326202f941483a7249a8f088c842ea (diff)
downloadpx4-nuttx-ef3f1a8672de0cc79514af2139c1a567a36a3783.tar.gz
px4-nuttx-ef3f1a8672de0cc79514af2139c1a567a36a3783.tar.bz2
px4-nuttx-ef3f1a8672de0cc79514af2139c1a567a36a3783.zip
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
-rw-r--r--nuttx/ChangeLog6
-rw-r--r--nuttx/Documentation/NuttX.html8
-rw-r--r--nuttx/TODO2
-rw-r--r--nuttx/fs/fat/fs_fat32.c48
4 files changed, 44 insertions, 20 deletions
diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog
index 7e7ce7c6c..1c828cf7e 100644
--- a/nuttx/ChangeLog
+++ b/nuttx/ChangeLog
@@ -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.
diff --git a/nuttx/Documentation/NuttX.html b/nuttx/Documentation/NuttX.html
index fdf88f3af..c4bbf8b42 100644
--- a/nuttx/Documentation/NuttX.html
+++ b/nuttx/Documentation/NuttX.html
@@ -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;
diff --git a/nuttx/TODO b/nuttx/TODO
index a19239b54..1c307d6f1 100644
--- a/nuttx/TODO
+++ b/nuttx/TODO
@@ -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
diff --git a/nuttx/fs/fat/fs_fat32.c b/nuttx/fs/fat/fs_fat32.c
index a54298bce..d4be115fd 100644
--- a/nuttx/fs/fat/fs_fat32.c
+++ b/nuttx/fs/fat/fs_fat32.c
@@ -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);
}