This is an automated email from the ASF dual-hosted git repository.
GUIDINGLI pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 85f0991bd4c fs/nfs: support FIOC_FILEPATH
85f0991bd4c is described below
commit 85f0991bd4c69404702b5d70a067e2549856fe5c
Author: zhengyu16 <[email protected]>
AuthorDate: Thu Nov 12 16:30:30 2026 +0800
fs/nfs: support FIOC_FILEPATH
NFS has no ioctl method, so FIOC_FILEPATH (and F_GETPATH) on an NFS
file fails with ENOTTY: the VFS fallback in file_ioctl() only covers
non-mountpoint inodes.
Keep the path relative to the mount point in the nfsnode at open time
and return the mount point path joined with it, as hostfs does.
Signed-off-by: zhengyu16 <[email protected]>
Signed-off-by: jingfei <[email protected]>
---
fs/nfs/nfs_node.h | 1 +
fs/nfs/nfs_vfsops.c | 40 ++++++++++++++++++++++++++++++++++++++--
2 files changed, 39 insertions(+), 2 deletions(-)
diff --git a/fs/nfs/nfs_node.h b/fs/nfs/nfs_node.h
index e2e609206a3..58170e85926 100644
--- a/fs/nfs/nfs_node.h
+++ b/fs/nfs/nfs_node.h
@@ -71,6 +71,7 @@ struct nfsnode
struct timespec n_ctime; /* File creation time */
nfsfh_t n_fhandle; /* NFS File Handle */
uint64_t n_size; /* Current size of file */
+ char n_relpath[1]; /* Relative path from mount point */
};
#endif /* __FS_NFS_NFS_NODE_H */
diff --git a/fs/nfs/nfs_vfsops.c b/fs/nfs/nfs_vfsops.c
index 13245ad8bdb..2b6cb4fbe7a 100644
--- a/fs/nfs/nfs_vfsops.c
+++ b/fs/nfs/nfs_vfsops.c
@@ -76,6 +76,7 @@
#include "fs_heap.h"
+#include "inode/inode.h"
#include "nfs.h"
#include "rpc.h"
#include "nfs_proto.h"
@@ -145,6 +146,7 @@ static ssize_t nfs_read(FAR struct file *filep, FAR char
*buffer,
static ssize_t nfs_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static off_t nfs_seek(FAR struct file *filep, off_t offset, int whence);
+static int nfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg);
static int nfs_sync(FAR struct file *filep);
static int nfs_dup(FAR const struct file *oldp, FAR struct file *newp);
static int nfs_fsinfo(FAR struct nfsmount *nmp);
@@ -210,7 +212,7 @@ const struct mountpt_operations g_nfs_operations =
nfs_read, /* read */
nfs_write, /* write */
nfs_seek, /* seek */
- NULL, /* ioctl */
+ nfs_ioctl, /* ioctl */
NULL, /* mmap */
nfs_truncate, /* truncate */
NULL, /* poll */
@@ -676,6 +678,7 @@ static int nfs_open(FAR struct file *filep, FAR const char
*relpath,
{
FAR struct nfsmount *nmp;
FAR struct nfsnode *np;
+ size_t len;
int ret;
/* Get the mountpoint inode reference from the file structure and the
@@ -687,7 +690,8 @@ static int nfs_open(FAR struct file *filep, FAR const char
*relpath,
/* Pre-allocate the file private data to describe the opened file. */
- np = fs_heap_zalloc(sizeof(struct nfsnode));
+ len = strlen(relpath);
+ np = fs_heap_zalloc(sizeof(struct nfsnode) + len);
if (!np)
{
ferr("ERROR: Failed to allocate private data\n");
@@ -753,6 +757,8 @@ static int nfs_open(FAR struct file *filep, FAR const char
*relpath,
filep->f_priv = np;
+ memcpy(np->n_relpath, relpath, len + 1);
+
/* In write/append mode, we need to set the file pointer to the end of
* the file.
*/
@@ -1321,6 +1327,36 @@ static int nfs_sync(FAR struct file *filep)
return 0;
}
+/****************************************************************************
+ * Name: nfs_ioctl
+ *
+ * Description:
+ * Handle I/O control commands for NFS files.
+ *
+ ****************************************************************************/
+
+static int nfs_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
+{
+ FAR struct nfsnode *np;
+ int ret = -ENOTTY;
+
+ DEBUGASSERT(filep->f_priv != NULL && filep->f_inode != NULL);
+ np = filep->f_priv;
+
+ if (cmd == FIOC_FILEPATH)
+ {
+ FAR char *path = (FAR char *)(uintptr_t)arg;
+
+ ret = inode_getpath(filep->f_inode, path, PATH_MAX);
+ if (ret >= 0)
+ {
+ strlcat(path, np->n_relpath, PATH_MAX);
+ }
+ }
+
+ return ret;
+}
+
/****************************************************************************
* Name: nfs_dup
*