fstatfs: Rethink last commit. Add verification that the file descriptor refers to an open file. This also should eliminate the warning while doing something useful.

This commit is contained in:
Gregory Nutt 2017-02-22 14:17:14 -06:00
parent 61322cbc6d
commit a78593d66d
2 changed files with 12 additions and 5 deletions

View File

@ -70,9 +70,7 @@
int fstatfs(int fd, FAR struct statfs *buf)
{
FAR struct file *filep;
#ifndef CONFIG_DISABLE_MOUNTPOINT
FAR struct inode *inode;
#endif
int ret;
DEBUGASSERT(buf != NULL);
@ -81,7 +79,7 @@ int fstatfs(int fd, FAR struct statfs *buf)
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
{
/* No networking... it is a bad descriptor in any event */
/* It is a bad, out-of-range descriptor */
set_errno(EBADF);
return ERROR;
@ -100,12 +98,21 @@ int fstatfs(int fd, FAR struct statfs *buf)
return ERROR;
}
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* Get the inode from the file structure */
inode = filep->f_inode;
DEBUGASSERT(inode != NULL);
/* Check if the file is open */
if (inode == NULL)
{
/* The descriptor does not refer to an open file. */
ret = -EBADF;
}
else
#ifndef CONFIG_DISABLE_MOUNTPOINT
/* The way we handle the stat depends on the type of inode that we
* are dealing with.
*/

View File

@ -92,7 +92,7 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
* method?
*/
else if (inode && inode->u.i_ops && inode->u.i_ops->read)
else if (inode != NULL && inode->u.i_ops && inode->u.i_ops->read)
{
/* Yes.. then let it perform the read. NOTE that for the case of the
* mountpoint, we depend on the read methods being identical in