fs/vfs/fs_fstat.c: Add file_fstat() function for internal OS use.
This commit is contained in:
parent
6361f93fda
commit
aa52c457cc
@ -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 */
|
||||
|
||||
|
@ -499,7 +499,7 @@ void fs_initialize(void);
|
||||
* Input Parameters:
|
||||
* path - The path to the inode to create
|
||||
* fops - The file operations structure
|
||||
* mode - inmode privileges (not used)
|
||||
* mode - Access privileges (not used)
|
||||
* priv - Private, user data that will be associated with the inode.
|
||||
*
|
||||
* Returned Value:
|
||||
@ -526,7 +526,7 @@ int register_driver(FAR const char *path,
|
||||
* Input Parameters:
|
||||
* path - The path to the inode to create
|
||||
* bops - The block driver operations structure
|
||||
* mode - inmode privileges (not used)
|
||||
* mode - Access privileges (not used)
|
||||
* priv - Private, user data that will be associated with the inode.
|
||||
*
|
||||
* Returned Value:
|
||||
@ -881,7 +881,7 @@ int fs_getfilep(int fd, FAR struct file **filep);
|
||||
* Name: file_read
|
||||
*
|
||||
* Description:
|
||||
* file_read() is an interanl OS interface. It is functionally similar to
|
||||
* file_read() is an internal OS interface. It is functionally similar to
|
||||
* the standard read() interface except:
|
||||
*
|
||||
* - It does not modify the errno variable,
|
||||
@ -908,7 +908,7 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes);
|
||||
* Name: nx_read
|
||||
*
|
||||
* Description:
|
||||
* nx_read() is an interanl OS interface. It is functionally similar to
|
||||
* nx_read() is an internal OS interface. It is functionally similar to
|
||||
* the standard read() interface except:
|
||||
*
|
||||
* - It does not modify the errno variable, and
|
||||
@ -945,7 +945,7 @@ ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes);
|
||||
* Name: nx_write
|
||||
*
|
||||
* Description:
|
||||
* nx_write() writes up to nytes bytes to the file referenced by the file
|
||||
* nx_write() writes up to nbytes bytes to the file referenced by the file
|
||||
* descriptor fd from the buffer starting at buf. nx_write() is an
|
||||
* internal OS function. It is functionally equivalent to write() except
|
||||
* that:
|
||||
@ -961,7 +961,7 @@ ssize_t file_write(FAR struct file *filep, FAR const void *buf, size_t nbytes);
|
||||
* Returned Value:
|
||||
* On success, the number of bytes written are returned (zero indicates
|
||||
* nothing was written). On any failure, a negated errno value is returned
|
||||
* (see comments withwrite() for a description of the appropriate errno
|
||||
* (see comments with write() for a description of the appropriate errno
|
||||
* values).
|
||||
*
|
||||
****************************************************************************/
|
||||
@ -1089,7 +1089,7 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap);
|
||||
* Name: file_poll
|
||||
*
|
||||
* Description:
|
||||
* Low-level poll operation based on struc file. This is used both to (1)
|
||||
* Low-level poll operation based on struct file. This is used both to (1)
|
||||
* support detached file, and also (2) by fdesc_poll() to perform all
|
||||
* normal operations on file descriptors descriptors.
|
||||
*
|
||||
@ -1108,6 +1108,33 @@ int file_vfcntl(FAR struct file *filep, int cmd, va_list ap);
|
||||
int file_poll(FAR struct file *filep, FAR struct pollfd *fds, bool setup);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if CONFIG_NFILE_DESCRIPTORS > 0
|
||||
int file_fstat(FAR struct file *filep, FAR struct stat *buf);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: fdesc_poll
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user