更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
path_cache.h 文件参考

浏览源代码.

结构体

struct  PathCache
 

函数

int PathCacheInit (void)
 
int PathCacheFree (struct PathCache *cache)
 
struct PathCachePathCacheAlloc (struct Vnode *parent, struct Vnode *vnode, const char *name, uint8_t len)
 
int PathCacheLookup (struct Vnode *parent, const char *name, int len, struct Vnode **vnode)
 
void VnodePathCacheFree (struct Vnode *vnode)
 和长辈,晚辈告别,从此不再是父亲和孩子. 更多...
 
void PathCacheMemoryDump (void)
 
void PathCacheDump (void)
 
LIST_HEADGetPathCacheList (void)
 
void ResetPathCacheHitInfo (int *hit, int *try)
 

函数说明

◆ GetPathCacheList()

LIST_HEAD * GetPathCacheList ( void  )

在文件 path_cache.c208 行定义.

209{
211}
LIST_HEAD g_pathCacheHashEntrys[LOSCFG_MAX_PATH_CACHE_SIZE]
Definition: path_cache.c:39
这是这个函数的调用关系图:

◆ PathCacheAlloc()

struct PathCache * PathCacheAlloc ( struct Vnode parent,
struct Vnode vnode,
const char *  name,
uint8_t  len 
)

在文件 path_cache.c112 行定义.

113{
114 struct PathCache *pc = NULL;
115 size_t pathCacheSize;
116 int ret;
117
118 if (name == NULL || len > NAME_MAX || parent == NULL || vnode == NULL) {
119 return NULL;
120 }
121 pathCacheSize = sizeof(struct PathCache) + len + 1;
122
123 pc = (struct PathCache*)zalloc(pathCacheSize);
124 if (pc == NULL) {
125 PRINT_ERR("pathCache alloc failed, no memory!\n");
126 return NULL;
127 }
128
129 ret = strncpy_s(pc->name, len + 1, name, len);
130 if (ret != LOS_OK) {
131 free(pc);
132 return NULL;
133 }
134
135 pc->parentVnode = parent;
136 pc->nameLen = len;
137 pc->childVnode = vnode;
138
139 LOS_ListAdd((&(parent->childPathCaches)), (&(pc->childEntry)));
140 LOS_ListAdd((&(vnode->parentPathCaches)), (&(pc->parentEntry)));
141
142 PathCacheInsert(parent, pc, name, len);
143
144 return pc;
145}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListAdd(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a new node to a doubly linked list.
Definition: los_list.h:217
void * zalloc(size_t size)
Definition: malloc.c:91
void free(void *ptr)
释放ptr所指向的内存空间
Definition: malloc.c:66
static void PathCacheInsert(struct Vnode *parent, struct PathCache *cache, const char *name, int len)
Definition: path_cache.c:106
char name[0]
Definition: path_cache.h:48
LIST_HEAD childPathCaches
Definition: vnode.h:172
LIST_HEAD parentPathCaches
Definition: vnode.h:171
函数调用图:
这是这个函数的调用关系图:

◆ PathCacheDump()

void PathCacheDump ( void  )

在文件 path_cache.c66 行定义.

67{
68 PRINTK("-------->pathCache dump in\n");
69 for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
70 struct PathCache *pc = NULL;
72
73 LOS_DL_LIST_FOR_EACH_ENTRY(pc, nhead, struct PathCache, hashEntry) {
74 PRINTK(" pathCache dump hash %d item %s %p %p %d\n", i,
75 pc->name, pc->parentVnode, pc->childVnode, pc->nameLen);
76 }
77 }
78 PRINTK("-------->pathCache dump out\n");
79}
struct Vnode * childVnode
Definition: path_cache.h:40
uint8_t nameLen
Definition: path_cache.h:44
LIST_ENTRY hashEntry
Definition: path_cache.h:43
struct Vnode * parentVnode
Definition: path_cache.h:39

◆ PathCacheFree()

int PathCacheFree ( struct PathCache cache)

在文件 path_cache.c147 行定义.

148{
149 if (pc == NULL) {
150 PRINT_ERR("pathCache free: invalid pathCache\n");
151 return -ENOENT;
152 }
153
154 LOS_ListDelete(&pc->hashEntry);
155 LOS_ListDelete(&pc->parentEntry);
156 LOS_ListDelete(&pc->childEntry);
157 free(pc);
158
159 return LOS_OK;
160}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
函数调用图:
这是这个函数的调用关系图:

◆ PathCacheInit()

int PathCacheInit ( void  )

在文件 path_cache.c58 行定义.

59{
60 for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
62 }
63 return LOS_OK;
64}
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
函数调用图:
这是这个函数的调用关系图:

◆ PathCacheLookup()

int PathCacheLookup ( struct Vnode parent,
const char *  name,
int  len,
struct Vnode **  vnode 
)

在文件 path_cache.c162 行定义.

163{
164 struct PathCache *pc = NULL;
165 int hash = NameHash(name, len, parent) & PATH_CACHE_HASH_MASK;
166 LIST_HEAD *dhead = &g_pathCacheHashEntrys[hash];
167
168 TRACE_TRY_CACHE();
169 LOS_DL_LIST_FOR_EACH_ENTRY(pc, dhead, struct PathCache, hashEntry) {
170 if (pc->parentVnode == parent && pc->nameLen == len && !strncmp(pc->name, name, len)) {
171 *vnode = pc->childVnode;
172 TRACE_HIT_CACHE(pc);
173 return LOS_OK;
174 }
175 }
176 return -ENOENT;
177}
static uint32_t NameHash(const char *name, int len, struct Vnode *dvp)
Definition: path_cache.c:98
函数调用图:
这是这个函数的调用关系图:

◆ PathCacheMemoryDump()

void PathCacheMemoryDump ( void  )

在文件 path_cache.c81 行定义.

82{
83 int pathCacheNum = 0;
84 int nameSum = 0;
85 for (int i = 0; i < LOSCFG_MAX_PATH_CACHE_SIZE; i++) {
87 struct PathCache *dent = NULL;
88
89 LOS_DL_LIST_FOR_EACH_ENTRY(dent, dhead, struct PathCache, hashEntry) {
90 pathCacheNum++;
91 nameSum += dent->nameLen;
92 }
93 }
94 PRINTK("pathCache number = %d\n", pathCacheNum);
95 PRINTK("pathCache memory size = %d(B)\n", pathCacheNum * sizeof(struct PathCache) + nameSum);
96}
这是这个函数的调用关系图:

◆ ResetPathCacheHitInfo()

void ResetPathCacheHitInfo ( int hit,
int try 
)

在文件 path_cache.c46 行定义.

47{
52}
static int g_totalPathCacheHit
Definition: path_cache.c:41
static int g_totalPathCacheTry
Definition: path_cache.c:42
这是这个函数的调用关系图:

◆ VnodePathCacheFree()

void VnodePathCacheFree ( struct Vnode vnode)

和长辈,晚辈告别,从此不再是父亲和孩子.

在文件 path_cache.c199 行定义.

200{
201 if (vnode == NULL) {
202 return;
203 }
204 FreeParentPathCache(vnode);
205 FreeChildPathCache(vnode);
206}
static void FreeParentPathCache(struct Vnode *vnode)
Definition: path_cache.c:189
static void FreeChildPathCache(struct Vnode *vnode)
Definition: path_cache.c:179
函数调用图:
这是这个函数的调用关系图: