diff --git a/fs/vfs/fs_open.c b/fs/vfs/fs_open.c index 5f55462d979..014eed9b750 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 b6381d0cc98..1557c02fa4f 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 */