diff --git a/fs/vfs/fs_fstatfs.c b/fs/vfs/fs_fstatfs.c index 43563a19a51..207311ea470 100644 --- a/fs/vfs/fs_fstatfs.c +++ b/fs/vfs/fs_fstatfs.c @@ -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. */ diff --git a/fs/vfs/fs_read.c b/fs/vfs/fs_read.c index 6da412c3793..b00616682a0 100644 --- a/fs/vfs/fs_read.c +++ b/fs/vfs/fs_read.c @@ -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