fs:fs_getfilep changes fd judgment method
if a fd was closed,need return EBADF Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
5b6dd876b8
commit
bc998f6072
1 changed files with 16 additions and 5 deletions
|
@ -361,7 +361,7 @@ int fs_getfilep(int fd, FAR struct file **filep)
|
|||
return -EAGAIN;
|
||||
}
|
||||
|
||||
if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS_PER_BLOCK * list->fl_rows)
|
||||
if (fd < 0 || fd >= list->fl_rows * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK)
|
||||
{
|
||||
return -EBADF;
|
||||
}
|
||||
|
@ -373,13 +373,24 @@ int fs_getfilep(int fd, FAR struct file **filep)
|
|||
/* And return the file pointer from the list */
|
||||
|
||||
ret = _files_semtake(list);
|
||||
if (ret >= 0)
|
||||
if (ret < 0)
|
||||
{
|
||||
*filep = &list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]
|
||||
[fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK];
|
||||
_files_semgive(list);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*filep = &list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]
|
||||
[fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK];
|
||||
|
||||
/* if f_inode is NULL, fd was closed */
|
||||
|
||||
if (!(*filep)->f_inode)
|
||||
{
|
||||
*filep = (FAR struct file *)NULL;
|
||||
ret = -EBADF;
|
||||
}
|
||||
|
||||
_files_semgive(list);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue