Skip to content

Commit 0095009

Browse files
alexguirrexiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent 7ebb8af commit 0095009

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/nfs/nfs_vfsops.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ static int nfs_filecreate(FAR struct nfsmount *nmp, FAR struct nfsnode *np,
367367

368368
/* Save the attributes in the file data structure */
369369

370-
tmp = *ptr; /* attributes_follows */
370+
tmp = *ptr++; /* attributes_follows */
371371
if (!tmp)
372372
{
373373
fwarn("WARNING: no file attributes\n");
@@ -731,6 +731,15 @@ static int nfs_open(FAR struct file *filep, FAR const char *relpath,
731731

732732
filep->f_priv = np;
733733

734+
/* In write/append mode, we need to set the file pointer to the end of
735+
* the file.
736+
*/
737+
738+
if ((oflags & (O_APPEND | O_WRONLY)) == (O_APPEND | O_WRONLY))
739+
{
740+
filep->f_pos = (off_t)np->n_size;
741+
}
742+
734743
/* Then insert the new instance at the head of the list in the mountpoint
735744
* structure. It needs to be there (1) to handle error conditions that
736745
* effect all files, and (2) to inform the umount logic that we are busy.

0 commit comments

Comments
 (0)