更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
jffs2_hash.c
浏览该文件的文档.
1/*
2 * Copyright (c) 2021-2021 Huawei Device Co., Ltd. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without modification,
5 * are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright notice, this list of
8 * conditions and the following disclaimer.
9 *
10 * 2. Redistributions in binary form must reproduce the above copyright notice, this list
11 * of conditions and the following disclaimer in the documentation and/or other materials
12 * provided with the distribution.
13 *
14 * 3. Neither the name of the copyright holder nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific prior written
16 * permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
20 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#include "jffs2_hash.h"
32
33#ifdef LOSCFG_FS_JFFS
34
36{
37 int ret;
38 for (int i = 0; i < JFFS2_NODE_HASH_BUCKETS; i++) {
39 LOS_ListInit(&heads[i]);
40 }
41
42 ret = LOS_MuxInit(lock, NULL);
43 if (ret != LOS_OK) {
44 PRINT_ERR("Create mutex for vnode hash list fail, status: %d", ret);
45 return ret;
46 }
47
48 return LOS_OK;
49}
50
52{
53 int ret;
54 ret = LOS_MuxDestroy(lock);
55 if (ret != LOS_OK) {
56 PRINT_ERR("Destroy mutex for vnode hash list fail, status: %d", ret);
57 return ret;
58 }
59
60 return LOS_OK;
61}
62
63void Jffs2HashDump(LosMux *lock, LOS_DL_LIST *heads)
64{
65 PRINTK("-------->Jffs2HashDump in\n");
66 (void)LOS_MuxLock(lock, LOS_WAIT_FOREVER);
67 for (int i = 0; i < JFFS2_NODE_HASH_BUCKETS; i++) {
68 LIST_HEAD *nhead = &heads[i];
69 struct jffs2_inode *node = NULL;
70
71 LOS_DL_LIST_FOR_EACH_ENTRY(node, nhead, struct jffs2_inode, i_hashlist) {
72 PRINTK(" vnode dump: col %d item %p\n", i, node);
73 }
74 }
75 (void)LOS_MuxUnlock(lock);
76 PRINTK("-------->Jffs2HashDump out\n");
77}
78
79static LOS_DL_LIST *Jffs2HashBucket(LOS_DL_LIST *heads, const uint32_t ino)
80{
81 LOS_DL_LIST *head = &(heads[ino & JFFS2_NODE_HASH_MASK]);
82 return head;
83}
84
85int Jffs2HashGet(LosMux *lock, LOS_DL_LIST *heads, const void *sb, const uint32_t ino, struct jffs2_inode **ppNode)
86{
87 struct jffs2_inode *node = NULL;
88
89 while (1) {
90 (void)LOS_MuxLock(lock, LOS_WAIT_FOREVER);
91 LOS_DL_LIST *list = Jffs2HashBucket(heads, ino);
92 LOS_DL_LIST_FOR_EACH_ENTRY(node, list, struct jffs2_inode, i_hashlist) {
93 if (node->i_ino != ino)
94 continue;
95 if (node->i_sb != sb)
96 continue;
97 (void)LOS_MuxUnlock(lock);
98 *ppNode = node;
99 return 0;
100 }
101 (void)LOS_MuxUnlock(lock);
102 *ppNode = NULL;
103 return 0;
104 }
105}
106
107void Jffs2HashRemove(LosMux *lock, struct jffs2_inode *node)
108{
109 (void)LOS_MuxLock(lock, LOS_WAIT_FOREVER);
110 LOS_ListDelete(&node->i_hashlist);
111 (void)LOS_MuxUnlock(lock);
112}
113
114int Jffs2HashInsert(LosMux *lock, LOS_DL_LIST *heads, struct jffs2_inode *node, const uint32_t ino)
115{
116 (void)LOS_MuxLock(lock, LOS_WAIT_FOREVER);
117 LOS_ListHeadInsert(Jffs2HashBucket(heads, ino), &node->i_hashlist);
118 (void)LOS_MuxUnlock(lock);
119 return 0;
120}
121
122#endif
123
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListInit(LOS_DL_LIST *list)
Definition: los_list.h:104
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListHeadInsert(LOS_DL_LIST *list, LOS_DL_LIST *node)
Insert a node to the head of a doubly linked list.
Definition: los_list.h:268
LITE_OS_SEC_ALW_INLINE STATIC INLINE VOID LOS_ListDelete(LOS_DL_LIST *node)
Definition: los_list.h:292
LITE_OS_SEC_TEXT UINT32 LOS_MuxInit(LosMux *mutex, const LosMuxAttr *attr)
初始化互斥锁
Definition: los_mux.c:262
LITE_OS_SEC_TEXT UINT32 LOS_MuxUnlock(LosMux *mutex)
释放锁
Definition: los_mux.c:559
LITE_OS_SEC_TEXT UINT32 LOS_MuxDestroy(LosMux *mutex)
销毁互斥锁
Definition: los_mux.c:289
LITE_OS_SEC_TEXT UINT32 LOS_MuxLock(LosMux *mutex, UINT32 timeout)
拿互斥锁,
Definition: los_mux.c:437
void Jffs2HashDump(LosMux *lock, LOS_DL_LIST *heads)
Definition: jffs2_hash.c:63
int Jffs2HashInsert(LosMux *lock, LOS_DL_LIST *heads, struct jffs2_inode *node, const uint32_t ino)
Definition: jffs2_hash.c:114
int Jffs2HashGet(LosMux *lock, LOS_DL_LIST *heads, const void *sb, const uint32_t ino, struct jffs2_inode **ppNode)
Definition: jffs2_hash.c:85
static LOS_DL_LIST * Jffs2HashBucket(LOS_DL_LIST *heads, const uint32_t ino)
Definition: jffs2_hash.c:79
int Jffs2HashInit(LosMux *lock, LOS_DL_LIST *heads)
Definition: jffs2_hash.c:35
void Jffs2HashRemove(LosMux *lock, struct jffs2_inode *node)
Definition: jffs2_hash.c:107
int Jffs2HashDeinit(LosMux *lock)
Definition: jffs2_hash.c:51
Definition: los_mux.h:73
ARG_NUM_3 ARG_NUM_1 ARG_NUM_2 ARG_NUM_2 ARG_NUM_3 ARG_NUM_1 ARG_NUM_4 ARG_NUM_2 ARG_NUM_2 ARG_NUM_5 ARG_NUM_2 void