fs/nfs: fix offset in append mode and attributes after create

- When opening a NFS file in append mode, its file pointer was at offset
  0 instead of the end of file.

- When creating a NFS file, the response read pointer wasn't advanced
  after reading the attributes_follows bool, which caused the attributes
  to be off by 4 bytes. For example, the file size read the GID.

Signed-off-by: Alejandro Aguirre <alejandro.aguirre@midokura.com>
This commit is contained in:
Alejandro Aguirre 2024-10-26 20:20:04 +02:00 committed by Xiang Xiao
parent 7ebb8af454
commit 0095009076

View file

@ -367,7 +367,7 @@ static int nfs_filecreate(FAR struct nfsmount *nmp, FAR struct nfsnode *np,
/* Save the attributes in the file data structure */
tmp = *ptr; /* attributes_follows */
tmp = *ptr++; /* attributes_follows */
if (!tmp)
{
fwarn("WARNING: no file attributes\n");
@ -731,6 +731,15 @@ static int nfs_open(FAR struct file *filep, FAR const char *relpath,
filep->f_priv = np;
/* 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))
{
filep->f_pos = (off_t)np->n_size;
}
/* Then insert the new instance at the head of the list in the mountpoint
* structure. It needs to be there (1) to handle error conditions that
* effect all files, and (2) to inform the umount logic that we are busy.