This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8439284bf25fc376e764e4ff73d1ee36d5d509f8
Author: Marco Casaroli <[email protected]>
AuthorDate: Mon Oct 19 17:38:53 2026 +0200

    arch/sim: Honour CH_STAT_NOFOLLOW in host_chstat().
    
    host_chstat() called chmod(), chown() and utimensat() without
    AT_SYMLINK_NOFOLLOW, so lchown(), lchmod() and lutimens() on a hostfs
    mount changed the file that the link points to.  Add
    NUTTX_CH_STAT_NOFOLLOW and use fchmodat(), fchownat() and utimensat()
    with AT_SYMLINK_NOFOLLOW when it is set.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/sim/src/sim/posix/sim_hostfs.c | 7 ++++---
 include/nuttx/fs/hostfs.h           | 1 +
 2 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/arch/sim/src/sim/posix/sim_hostfs.c 
b/arch/sim/src/sim/posix/sim_hostfs.c
index d139bb41863..7b28cb3377a 100644
--- a/arch/sim/src/sim/posix/sim_hostfs.c
+++ b/arch/sim/src/sim/posix/sim_hostfs.c
@@ -778,12 +778,13 @@ int host_stat(const char *path, struct nuttx_stat_s *buf)
 
 int host_chstat(const char *path, const struct nuttx_stat_s *buf, int flags)
 {
+  int nofollow = (flags & NUTTX_CH_STAT_NOFOLLOW) ? AT_SYMLINK_NOFOLLOW : 0;
   struct timespec times[2];
   int ret;
 
   if (flags & NUTTX_CH_STAT_MODE)
     {
-      ret = chmod(path, buf->st_mode);
+      ret = fchmodat(AT_FDCWD, path, buf->st_mode, nofollow);
       if (ret < 0)
         {
           return host_errno_convert(-errno);
@@ -792,7 +793,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s 
*buf, int flags)
 
   if (flags & (NUTTX_CH_STAT_UID | NUTTX_CH_STAT_GID))
     {
-      ret = chown(path, buf->st_uid, buf->st_gid);
+      ret = fchownat(AT_FDCWD, path, buf->st_uid, buf->st_gid, nofollow);
       if (ret < 0)
         {
           return host_errno_convert(-errno);
@@ -823,7 +824,7 @@ int host_chstat(const char *path, const struct nuttx_stat_s 
*buf, int flags)
           times[1].tv_nsec = UTIME_OMIT;
         }
 
-      ret = utimensat(AT_FDCWD, path, times, 0);
+      ret = utimensat(AT_FDCWD, path, times, nofollow);
       if (ret < 0)
         {
           return host_errno_convert(-errno);
diff --git a/include/nuttx/fs/hostfs.h b/include/nuttx/fs/hostfs.h
index e3e4aa6933c..95839f6e633 100644
--- a/include/nuttx/fs/hostfs.h
+++ b/include/nuttx/fs/hostfs.h
@@ -112,6 +112,7 @@
 #define NUTTX_CH_STAT_GID       (1 << 2)
 #define NUTTX_CH_STAT_ATIME     (1 << 3)
 #define NUTTX_CH_STAT_MTIME     (1 << 4)
+#define NUTTX_CH_STAT_NOFOLLOW  (1 << 8)
 
 /* These must exactly match the definitions from include/nuttx/fs/ioctl.h: */
 

Reply via email to