!937 添加MAX_OPEN_DIRS宏,标识最大可打开dir数量
Merge pull request !937 from Hongjin Li/max_open_dirs
This commit is contained in:
commit
68b8deea89
|
@ -88,4 +88,9 @@
|
||||||
|
|
||||||
#define MAX_DIRENT_NUM 14 // 14 means 4096 length buffer can store 14 dirent, see struct DIR
|
#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
|
#endif
|
||||||
|
|
|
@ -94,6 +94,7 @@ int PollQueryFd(int fd, struct PollTable *table)
|
||||||
#define IOV_MAX_CNT 4
|
#define IOV_MAX_CNT 4
|
||||||
|
|
||||||
UINT32 g_fsMutex;
|
UINT32 g_fsMutex;
|
||||||
|
static UINT32 g_dirNum = 0;
|
||||||
|
|
||||||
int VfsLock(void)
|
int VfsLock(void)
|
||||||
{
|
{
|
||||||
|
@ -666,6 +667,13 @@ static DIR *VfsOpendir(const char *path)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (g_dirNum >= LOSCFG_MAX_OPEN_DIRS) {
|
||||||
|
VFS_ERRNO_SET(ENFILE);
|
||||||
|
VfsUnlock();
|
||||||
|
free(dir);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
mp = VfsMpFind(path, &pathInMp);
|
mp = VfsMpFind(path, &pathInMp);
|
||||||
if ((mp == NULL) || (pathInMp == NULL)) {
|
if ((mp == NULL) || (pathInMp == NULL)) {
|
||||||
VFS_ERRNO_SET(ENOENT);
|
VFS_ERRNO_SET(ENOENT);
|
||||||
|
@ -687,6 +695,7 @@ static DIR *VfsOpendir(const char *path)
|
||||||
ret = (UINT32)mp->mFs->fsFops->opendir(dir, pathInMp);
|
ret = (UINT32)mp->mFs->fsFops->opendir(dir, pathInMp);
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
mp->mRefs++;
|
mp->mRefs++;
|
||||||
|
g_dirNum++;
|
||||||
} else {
|
} else {
|
||||||
LOSCFG_FS_FREE_HOOK(dir);
|
LOSCFG_FS_FREE_HOOK(dir);
|
||||||
dir = NULL;
|
dir = NULL;
|
||||||
|
@ -752,6 +761,7 @@ static int VfsClosedir(DIR *d)
|
||||||
|
|
||||||
if (ret == 0) {
|
if (ret == 0) {
|
||||||
mp->mRefs--;
|
mp->mRefs--;
|
||||||
|
g_dirNum--;
|
||||||
} else {
|
} else {
|
||||||
VFS_ERRNO_SET(EBADF);
|
VFS_ERRNO_SET(EBADF);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue