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:
parent
61322cbc6d
commit
a78593d66d
@ -70,9 +70,7 @@
|
|||||||
int fstatfs(int fd, FAR struct statfs *buf)
|
int fstatfs(int fd, FAR struct statfs *buf)
|
||||||
{
|
{
|
||||||
FAR struct file *filep;
|
FAR struct file *filep;
|
||||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
|
||||||
FAR struct inode *inode;
|
FAR struct inode *inode;
|
||||||
#endif
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(buf != NULL);
|
DEBUGASSERT(buf != NULL);
|
||||||
@ -81,7 +79,7 @@ int fstatfs(int fd, FAR struct statfs *buf)
|
|||||||
|
|
||||||
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
|
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);
|
set_errno(EBADF);
|
||||||
return ERROR;
|
return ERROR;
|
||||||
@ -100,12 +98,21 @@ int fstatfs(int fd, FAR struct statfs *buf)
|
|||||||
return ERROR;
|
return ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef CONFIG_DISABLE_MOUNTPOINT
|
|
||||||
/* Get the inode from the file structure */
|
/* Get the inode from the file structure */
|
||||||
|
|
||||||
inode = filep->f_inode;
|
inode = filep->f_inode;
|
||||||
DEBUGASSERT(inode != NULL);
|
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
|
/* The way we handle the stat depends on the type of inode that we
|
||||||
* are dealing with.
|
* are dealing with.
|
||||||
*/
|
*/
|
||||||
|
@ -92,7 +92,7 @@ ssize_t file_read(FAR struct file *filep, FAR void *buf, size_t nbytes)
|
|||||||
* method?
|
* 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
|
/* Yes.. then let it perform the read. NOTE that for the case of the
|
||||||
* mountpoint, we depend on the read methods being identical in
|
* mountpoint, we depend on the read methods being identical in
|
||||||
|
Loading…
x
Reference in New Issue
Block a user