fs/smartfs/smartfs_smart.c: Honor O_APPEND on writes. Also document pwrite() bug/limitation.
This commit is contained in:
parent
3268eb882e
commit
a085a0a70b
@ -673,6 +673,20 @@ static ssize_t smartfs_write(FAR struct file *filep, const char *buffer,
|
||||
goto errout_with_semaphore;
|
||||
}
|
||||
|
||||
/* Test if we opened for APPEND mode. If we did, then seek to the
|
||||
* end of the file.
|
||||
*/
|
||||
|
||||
if (sf->oflags & O_APPEND)
|
||||
{
|
||||
ret = smartfs_seek_internal(fs, sf, 0, SEEK_END);
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -EIO;
|
||||
goto errout_with_semaphore;
|
||||
}
|
||||
}
|
||||
|
||||
/* First test if we are overwriting an existing location or writing to
|
||||
* a new one.
|
||||
*/
|
||||
|
@ -1901,7 +1901,7 @@ int smartfs_extendfile(FAR struct smartfs_mountpt_s *fs,
|
||||
|
||||
/* Loop until either (1) the file has been fully extended with zeroed data
|
||||
* or (2) an error occurs. We assume we start with the current sector in
|
||||
* cache (ff_currentsector)
|
||||
* cache (ff_currentsector).
|
||||
*/
|
||||
|
||||
oldsize = sf->entry.datlen;
|
||||
@ -1909,7 +1909,7 @@ int smartfs_extendfile(FAR struct smartfs_mountpt_s *fs,
|
||||
DEBUGASSERT(length > oldsize);
|
||||
|
||||
/* Seek to the end of the file for the append/write operation, remembering
|
||||
* the current file position. It will be retored before returneding; the
|
||||
* the current file position. It will be restored before returning; the
|
||||
* truncate operation must not alter the file position.
|
||||
*/
|
||||
|
||||
|
@ -131,6 +131,12 @@ ssize_t file_pwrite(FAR struct file *filep, FAR const void *buf,
|
||||
* end-of-file condition, or -1 on failure with errno set appropriately.
|
||||
* See write() return values
|
||||
*
|
||||
* Assumptions/Limitations:
|
||||
* POSIX requires that opening a file with the O_APPEND flag should have no
|
||||
* effect on the location at which pwrite() writes data. However, on NuttX
|
||||
* like on Linux, if a file is opened with O_APPEND, pwrite() appends data
|
||||
* to the end of the file, regardless of the value of offset.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ssize_t pwrite(int fd, FAR const void *buf, size_t nbytes, off_t offset)
|
||||
|
Loading…
Reference in New Issue
Block a user