fix: 添加LOSCFG_MAX_OPEN_DIRS标识最大可打开dir数量

提供LOSCFG_MAX_OPEN_DIRS宏定义,标识最大可打开dir数量。新增g_dirNum静态变量,标识已打开的dir数量。
在opendir成功时g_dirNum++,在closedir成功时g_dirNum--。

BREAKING CHANGE:
新增LOSCFG_MAX_OPEN_DIRS宏定义,标识最大可打开dir数量。

fix: I62XEA

Signed-off-by: Hongjin Li <lihongjin1@huawei.com>
This commit is contained in:
Hongjin Li 2022-11-24 15:58:08 +08:00
parent 0841ece718
commit a288718c2c
2 changed files with 15 additions and 0 deletions

View File

@ -88,4 +88,9 @@
#define MAX_DIRENT_NUM 14 // 14 means 4096 length buffer can store 14 dirent, see struct DIR
/* max number of open directories */
#ifndef LOSCFG_MAX_OPEN_DIRS
#define LOSCFG_MAX_OPEN_DIRS 10
#endif
#endif

View File

@ -94,6 +94,7 @@ int PollQueryFd(int fd, struct PollTable *table)
#define IOV_MAX_CNT 4
UINT32 g_fsMutex;
static UINT32 g_dirNum = 0;
int VfsLock(void)
{
@ -663,6 +664,13 @@ static DIR *VfsOpendir(const char *path)
return NULL;
}
if (g_dirNum >= LOSCFG_MAX_OPEN_DIRS) {
VFS_ERRNO_SET(ENFILE);
VfsUnlock();
free(dir);
return NULL;
}
mp = VfsMpFind(path, &pathInMp);
if ((mp == NULL) || (pathInMp == NULL)) {
VFS_ERRNO_SET(ENOENT);
@ -684,6 +692,7 @@ static DIR *VfsOpendir(const char *path)
ret = (UINT32)mp->mFs->fsFops->opendir(dir, pathInMp);
if (ret == 0) {
mp->mRefs++;
g_dirNum++;
} else {
free(dir);
dir = NULL;
@ -749,6 +758,7 @@ static int VfsClosedir(DIR *d)
if (ret == 0) {
mp->mRefs--;
g_dirNum--;
} else {
VFS_ERRNO_SET(EBADF);
}