This is an automated email from the ASF dual-hosted git repository.
michallenc 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 5d150b4109e fs/vfs: make FIOC_FILEPATH and F_GETPATH optional for
DEFAULT_SMALL
5d150b4109e is described below
commit 5d150b4109ec451b5bdd49633aae4819208c5a15
Author: Swatantra Yadav <[email protected]>
AuthorDate: Sun Nov 15 00:21:03 2026 +0530
fs/vfs: make FIOC_FILEPATH and F_GETPATH optional for DEFAULT_SMALL
The FIOC_FILEPATH ioctl and F_GETPATH fcntl command resolve the path
of an open file descriptor from its inode tree. In small memory-constrained
configurations (DEFAULT_SMALL=y), unconditionally handling this command
forces the inclusion of inode_getpath() and path reconstruction logic,
adding unnecessary Flash overhead on targets that do not require path
resolution from file descriptors.
This patch introduces CONFIG_FS_IOCTL_FILEPATH (default !DEFAULT_SMALL):
1. In fs/Kconfig, defines CONFIG_FS_IOCTL_FILEPATH.
2. In fs/vfs/Kconfig, selects FS_IOCTL_FILEPATH under CONFIG_FS_NOTIFY.
3. In fs/vfs/fs_ioctl.c, rejects FIOC_FILEPATH with -ENOTTY prior to
driver dispatch when disabled, and gates inode_getpath() fallback.
4. In fs/vfs/fs_fcntl.c, keeps F_GETPATH case and returns -ENOTTY when
disabled, matching FIOC_FILEPATH behavior.
5. In libs/libc/misc/lib_getfullpath.c, properly propagates F_GETPATH
failure (-get_errno()) so caller *at functions safely abort when
path resolution is unsupported or fails, rather than operating on
an uninitialized buffer.
Saves 240 bytes of Flash on stm32f103-minimum:nsh (text 53596 -> 53356
bytes).
Assisted-by: Google DeepMind:antigravity
Signed-off-by: Swatantra Yadav <[email protected]>
---
fs/Kconfig | 10 ++++++++++
fs/vfs/Kconfig | 1 +
fs/vfs/fs_fcntl.c | 4 ++++
fs/vfs/fs_ioctl.c | 9 +++++++++
libs/libc/misc/lib_getfullpath.c | 6 ++++--
5 files changed, 28 insertions(+), 2 deletions(-)
diff --git a/fs/Kconfig b/fs/Kconfig
index 5671e2bdb68..07af9f4c8f1 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -119,6 +119,16 @@ config DISABLE_DIRECTORY_OPERATIONS
available either. Useful for small systems that never list a
directory; the directory file layer is not built at all.
+config FS_IOCTL_FILEPATH
+ bool "Support FIOC_FILEPATH ioctl and F_GETPATH fcntl"
+ default !DEFAULT_SMALL
+ ---help---
+ Enable the FIOC_FILEPATH ioctl and F_GETPATH fcntl command to
resolve
+ the path of an open file descriptor from its inode tree.
+ When disabled, file_ioctl(FIOC_FILEPATH) returns -ENOTTY,
saving Flash
+ space on memory-constrained systems by eliminating path
reconstruction
+ machinery (inode_getpath).
+
config PSEUDOFS_ATTRIBUTES
bool "Pseudo-filesystem attributes"
default n
diff --git a/fs/vfs/Kconfig b/fs/vfs/Kconfig
index 858b3c07090..2afb1c276ad 100644
--- a/fs/vfs/Kconfig
+++ b/fs/vfs/Kconfig
@@ -90,6 +90,7 @@ endif # SIGNAL_FD
config FS_NOTIFY
bool "FS Notify System"
default n
+ select FS_IOCTL_FILEPATH
---help---
The Fsnotify System
diff --git a/fs/vfs/fs_fcntl.c b/fs/vfs/fs_fcntl.c
index f8267e6ab92..2a77286cdc9 100644
--- a/fs/vfs/fs_fcntl.c
+++ b/fs/vfs/fs_fcntl.c
@@ -178,6 +178,7 @@ static int file_vfcntl(FAR struct file *filep, int cmd,
va_list ap)
* of size PATH_MAX or greater.
*/
+#ifdef CONFIG_FS_IOCTL_FILEPATH
{
FAR char *path = va_arg(ap, FAR char *);
@@ -189,6 +190,9 @@ static int file_vfcntl(FAR struct file *filep, int cmd,
va_list ap)
ret = file_ioctl(filep, FIOC_FILEPATH, path);
}
+#else
+ ret = -ENOTTY;
+#endif
break;
case F_SETPIPE_SZ:
diff --git a/fs/vfs/fs_ioctl.c b/fs/vfs/fs_ioctl.c
index 5b0012f1577..35d98a2e0f6 100644
--- a/fs/vfs/fs_ioctl.c
+++ b/fs/vfs/fs_ioctl.c
@@ -61,12 +61,19 @@ static int file_vioctl(FAR struct file *filep, int req,
va_list ap)
return -EBADF;
}
+#ifdef CONFIG_FS_IOCTL_FILEPATH
/* A driver may return OK without filling the path buffer */
if (req == FIOC_FILEPATH && arg != 0)
{
*(FAR char *)(uintptr_t)arg = '\0';
}
+#else
+ if (req == FIOC_FILEPATH)
+ {
+ return -ENOTTY;
+ }
+#endif
/* Does the driver support the ioctl method? */
@@ -97,12 +104,14 @@ static int file_vioctl(FAR struct file *filep, int req,
va_list ap)
}
break;
+#ifdef CONFIG_FS_IOCTL_FILEPATH
case FIOC_FILEPATH:
if (ret == -ENOTTY && !INODE_IS_MOUNTPT(inode))
{
ret = inode_getpath(inode, (FAR char *)(uintptr_t)arg, PATH_MAX);
}
break;
+#endif
case FIOC_GETLK:
if (ret == -ENOTTY)
diff --git a/libs/libc/misc/lib_getfullpath.c b/libs/libc/misc/lib_getfullpath.c
index 05cbd256e43..d60a8dab093 100644
--- a/libs/libc/misc/lib_getfullpath.c
+++ b/libs/libc/misc/lib_getfullpath.c
@@ -26,6 +26,7 @@
#include <nuttx/config.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <string.h>
@@ -96,11 +97,12 @@ int lib_getfullpath(int dirfd, FAR const char *path,
/* Get real directory path by dirfd */
ret = fcntl(dirfd, F_GETPATH, fullpath);
- if (ret >= 0)
+ if (ret < 0)
{
- strlcat(fullpath, path, fulllen);
+ return -get_errno();
}
+ strlcat(fullpath, path, fulllen);
return 0;
}
}