mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 12:08:36 +08:00
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;
|
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;
|
return -EBADF;
|
||||||
}
|
}
|
||||||
|
@ -373,13 +373,24 @@ int fs_getfilep(int fd, FAR struct file **filep)
|
||||||
/* And return the file pointer from the list */
|
/* And return the file pointer from the list */
|
||||||
|
|
||||||
ret = _files_semtake(list);
|
ret = _files_semtake(list);
|
||||||
if (ret >= 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
*filep = &list->fl_files[fd / CONFIG_NFILE_DESCRIPTORS_PER_BLOCK]
|
return ret;
|
||||||
[fd % CONFIG_NFILE_DESCRIPTORS_PER_BLOCK];
|
|
||||||
_files_semgive(list);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*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;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue