This is an automated email from the ASF dual-hosted git repository. gnutt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 65308eabb4aed7c12febcc5276e4148a0d241d3a Author: Xiang Xiao <xiaoxi...@xiaomi.com> AuthorDate: Sun May 3 16:17:44 2020 +0800 fs/vfs: Add nx_stat function Signed-off-by: Xiang Xiao <xiaoxi...@xiaomi.com> --- fs/vfs/fs_stat.c | 89 ++++++++++++++++++++++++++------------------------- include/nuttx/fs/fs.h | 19 +++++++++++ 2 files changed, 64 insertions(+), 44 deletions(-) diff --git a/fs/vfs/fs_stat.c b/fs/vfs/fs_stat.c index 2ab3fd0..4f64d89 100644 --- a/fs/vfs/fs_stat.c +++ b/fs/vfs/fs_stat.c @@ -94,7 +94,7 @@ static inline int statroot(FAR struct stat *buf) * Name: stat_recursive * * Returned Value: - * Zero on success; -1 on failure with errno set: + * Zero on success; < 0 on failure: * * EACCES Search permission is denied for one of the directories in the * path prefix of path. @@ -123,7 +123,6 @@ int stat_recursive(FAR const char *path, FAR struct stat *buf) * there is no mountpoint that includes in this path. */ - ret = -ret; goto errout_with_search; } @@ -160,29 +159,10 @@ int stat_recursive(FAR const char *path, FAR struct stat *buf) ret = inode_stat(inode, buf); } - /* Check if the stat operation was successful */ - - if (ret < 0) - { - ret = -ret; - goto errout_with_inode; - } - - /* Successfully stat'ed the file */ - inode_release(inode); - RELEASE_SEARCH(&desc); - return OK; - - /* Failure conditions always set the errno appropriately */ - -errout_with_inode: - inode_release(inode); - errout_with_search: RELEASE_SEARCH(&desc); - set_errno(ret); - return ERROR; + return ret; } /**************************************************************************** @@ -190,37 +170,32 @@ errout_with_search: ****************************************************************************/ /**************************************************************************** - * Name: stat + * Name: nx_stat * - * Returned Value: - * Zero on success; -1 on failure with errno set: + * Description: + * nx_stat() is similar to the standard 'stat' interface except that is + * not a cancellation point and it does not modify the errno variable. * - * EACCES Search permission is denied for one of the directories in the - * path prefix of path. - * EFAULT Bad address. - * ENOENT A component of the path path does not exist, or the path is an - * empty string. - * ENOMEM Out of memory - * ENOTDIR A component of the path is not a directory. + * nx_stat() is an internal NuttX interface and should not be called from + * applications. + * + * Returned Value: + * Zero is returned on success; a negated value is returned on any failure. * ****************************************************************************/ -int stat(FAR const char *path, FAR struct stat *buf) +int nx_stat(FAR const char *path, FAR struct stat *buf) { - int ret; - /* Sanity checks */ if (path == NULL || buf == NULL) { - ret = EFAULT; - goto errout; + return -EFAULT; } if (*path == '\0') { - ret = ENOENT; - goto errout; + return -ENOENT; } /* Check for the fake root directory (which has no inode) */ @@ -238,10 +213,36 @@ int stat(FAR const char *path, FAR struct stat *buf) buf->st_count = 0; #endif return stat_recursive(path, buf); +} + +/**************************************************************************** + * Name: stat + * + * Returned Value: + * Zero on success; -1 on failure with errno set: + * + * EACCES Search permission is denied for one of the directories in the + * path prefix of path. + * EFAULT Bad address. + * ENOENT A component of the path path does not exist, or the path is an + * empty string. + * ENOMEM Out of memory + * ENOTDIR A component of the path is not a directory. + * + ****************************************************************************/ + +int stat(FAR const char *path, FAR struct stat *buf) +{ + int ret; + + ret = nx_stat(path, buf); + if (ret < 0) + { + set_errno(-ret); + ret = ERROR; + } -errout: - set_errno(ret); - return ERROR; + return ret; } /**************************************************************************** @@ -249,7 +250,7 @@ errout: * * Description: * The inode_stat() function will obtain information about an 'inode' in - * the pseudo file system and will write it to the area pointed to by 'buf'. + * the pseudo file system and write it to the area pointed to by 'buf'. * * The 'buf' argument is a pointer to a stat structure, as defined in * <sys/stat.h>, into which information is placed concerning the file. @@ -347,7 +348,7 @@ int inode_stat(FAR struct inode *inode, FAR struct stat *buf) RESET_BUF(buf); } - /* Make sure that the caller knows that this really a symbolic link. */ + /* Make sure the caller knows that this really a symbolic link. */ buf->st_mode |= S_IFLNK; } diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h index 0855d95..f55fb74 100644 --- a/include/nuttx/fs/fs.h +++ b/include/nuttx/fs/fs.h @@ -81,6 +81,7 @@ # define _NX_READ(f,b,s) nx_read(f,b,s) # define _NX_WRITE(f,b,s) nx_write(f,b,s) # define _NX_SEEK(f,o,w) nx_seek(f,o,w) +# define _NX_STAT(p,s) nx_stat(p,s) # define _NX_GETERRNO(r) (-(r)) # define _NX_SETERRNO(r) set_errno(-(r)) # define _NX_GETERRVAL(r) (r) @@ -94,6 +95,7 @@ # define _NX_READ(f,b,s) read(f,b,s) # define _NX_WRITE(f,b,s) write(f,b,s) # define _NX_SEEK(f,o,w) lseek(f,o,w) +# define _NX_STAT(p,s) stat(p,s) # define _NX_GETERRNO(r) errno # define _NX_SETERRNO(r) # define _NX_GETERRVAL(r) (-errno) @@ -1335,6 +1337,23 @@ int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup); int file_fstat(FAR struct file *filep, FAR struct stat *buf); /**************************************************************************** + * Name: nx_stat + * + * Description: + * nx_stat() is similar to the standard 'stat' interface except that is + * not a cancellation point and it does not modify the errno variable. + * + * nx_stat() is an internal NuttX interface and should not be called from + * applications. + * + * Returned Value: + * Zero is returned on success; a negated value is returned on any failure. + * + ****************************************************************************/ + +int nx_stat(FAR const char *path, FAR struct stat *buf); + +/**************************************************************************** * Name: fdesc_poll * * Description: