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

archer 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 b1899ffbfd fs: Support O_NOFOLLOW flag
b1899ffbfd is described below

commit b1899ffbfd7fbb7d3a2da64ff0f8774e26c51d81
Author: Xiang Xiao <[email protected]>
AuthorDate: Sun Jan 15 00:57:09 2023 +0800

    fs: Support O_NOFOLLOW flag
    
    
https://pubs.opengroup.org/onlinepubs/9699919799.2013edition/functions/open.html:
    O_NOFOLLOW
    If path names a symbolic link, fail and set errno to [ELOOP].
    
    Signed-off-by: Xiang Xiao <[email protected]>
---
 fs/vfs/fs_open.c | 7 ++++++-
 include/fcntl.h  | 1 +
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c
index 5f55462d97..014eed9b75 100644
--- a/fs/vfs/fs_open.c
+++ b/fs/vfs/fs_open.c
@@ -99,7 +99,7 @@ static int file_vopen(FAR struct file *filep, FAR const char 
*path,
 
   /* Get an inode for this file */
 
-  SETUP_SEARCH(&desc, path, false);
+  SETUP_SEARCH(&desc, path, (oflags & O_NOFOLLOW) != 0);
 
   ret = inode_find(&desc);
   if (ret < 0)
@@ -117,6 +117,11 @@ static int file_vopen(FAR struct file *filep, FAR const 
char *path,
   inode = desc.node;
   DEBUGASSERT(inode != NULL);
 
+  if (desc.nofollow && INODE_IS_SOFTLINK(inode))
+    {
+      return -ELOOP;
+    }
+
 #if defined(CONFIG_BCH) && \
     !defined(CONFIG_DISABLE_MOUNTPOINT) && \
     !defined(CONFIG_DISABLE_PSEUDOFS_OPERATIONS)
diff --git a/include/fcntl.h b/include/fcntl.h
index b6381d0cc9..1557c02fa4 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -53,6 +53,7 @@
 #define O_DIRECT    (1 << 9)        /* Avoid caching, write directly to 
hardware */
 #define O_CLOEXEC   (1 << 10)       /* Close on execute */
 #define O_DIRECTORY (1 << 11)       /* Must be a directory */
+#define O_NOFOLLOW  (1 << 12)       /* Don't follow links */
 
 /* Unsupported, but required open flags */
 

Reply via email to