mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
fs/vfs/fs_fstat.c: Add file_fstat() function for internal OS use.
This commit is contained in:
+69
-35
@@ -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 */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user