fs/vfs/fs_fstat.c: Add file_fstat() function for internal OS use.

This commit is contained in:
ligd
2018-08-26 13:26:37 -06:00
committed by Gregory Nutt
parent 6361f93fda
commit aa52c457cc
2 changed files with 103 additions and 42 deletions
+69 -35
View File
@@ -52,6 +52,71 @@
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: file_fstat
*
* Description:
* file_fstat() is an internal OS interface. It is functionally similar to
* the standard fstat() interface except:
*
* - It does not modify the errno variable,
* - It is not a cancellation point,
* - It does not handle socket descriptors, and
* - It accepts a file structure instance instead of file descriptor.
*
* Input Parameters:
* filep - File structure instance
* buf - The caller provide location in which to return information about
* the open file.
*
* Returned Value:
* Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
* returned and errno set to indicate the error.
*
****************************************************************************/
int file_fstat(FAR struct file *filep, FAR struct stat *buf)
{
FAR struct inode *inode;
int ret;
DEBUGASSERT(filep != NULL);
/* Get the inode from the file structure */
inode = filep->f_inode;
DEBUGASSERT(inode != NULL);
/* The way we handle the stat depends on the type of inode that we
* are dealing with.
*/
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_MOUNTPT(inode))
{
/* The inode is a file system mountpoint. Verify that the mountpoint
* supports the fstat() method
*/
ret = -ENOSYS;
if (inode->u.i_mops && inode->u.i_mops->fstat)
{
/* Perform the fstat() operation */
ret = inode->u.i_mops->fstat(filep, buf);
}
}
else
#endif
{
/* The inode is part of the root pseudo file system. */
ret = inode_stat(inode, buf);
}
return ret;
}
/****************************************************************************
* Name: fstat
*
@@ -77,7 +142,6 @@
int fstat(int fd, FAR struct stat *buf)
{
FAR struct file *filep;
FAR struct inode *inode;
int ret;
/* Did we get a valid file descriptor? */
@@ -102,8 +166,8 @@ int fstat(int fd, FAR struct stat *buf)
#endif
}
/* The descriptor is in a valid range to file descriptor... do the
* read. First, get the file structure. Note that on failure,
/* The descriptor is in a valid range for a file descriptor... do the
* fstat. First, get the file structure. Note that on failure,
* fs_getfilep() will set the errno variable.
*/
@@ -113,39 +177,9 @@ int fstat(int fd, FAR struct stat *buf)
goto errout;
}
DEBUGASSERT(filep != NULL);
/* Perform the fstat operation */
/* Get the inode from the file structure */
inode = filep->f_inode;
DEBUGASSERT(inode != NULL);
/* The way we handle the stat depends on the type of inode that we
* are dealing with.
*/
#ifndef CONFIG_DISABLE_MOUNTPOINT
if (INODE_IS_MOUNTPT(inode))
{
/* The inode is a file system mointpoint. Verify that the mountpoint
* supports the fstat() method
*/
ret = -ENOSYS;
if (inode->u.i_mops && inode->u.i_mops->fstat)
{
/* Perform the fstat() operation */
ret = inode->u.i_mops->fstat(filep, buf);
}
}
else
#endif
{
/* The inode is part of the root pseudo file system. */
ret = inode_stat(inode, buf);
}
ret = file_fstat(filep, buf);
/* Check if the fstat operation was successful */