Lines Matching +full:key +full:- +full:release

1 // SPDX-License-Identifier: GPL-2.0
19 fd->tree = tree; in hfs_find_init()
20 fd->bnode = NULL; in hfs_find_init()
21 ptr = kmalloc(tree->max_key_len * 2 + 4, GFP_KERNEL); in hfs_find_init()
23 return -ENOMEM; in hfs_find_init()
24 fd->search_key = ptr; in hfs_find_init()
25 fd->key = ptr + tree->max_key_len + 2; in hfs_find_init()
27 tree->cnid, __builtin_return_address(0)); in hfs_find_init()
28 switch (tree->cnid) { in hfs_find_init()
30 mutex_lock_nested(&tree->tree_lock, CATALOG_BTREE_MUTEX); in hfs_find_init()
33 mutex_lock_nested(&tree->tree_lock, EXTENTS_BTREE_MUTEX); in hfs_find_init()
36 mutex_lock_nested(&tree->tree_lock, ATTR_BTREE_MUTEX); in hfs_find_init()
39 return -EINVAL; in hfs_find_init()
46 hfs_bnode_put(fd->bnode); in hfs_find_exit()
47 kfree(fd->search_key); in hfs_find_exit()
49 fd->tree->cnid, __builtin_return_address(0)); in hfs_find_exit()
50 mutex_unlock(&fd->tree->tree_lock); in hfs_find_exit()
51 fd->tree = NULL; in hfs_find_exit()
54 /* Find the record in bnode that best matches key (not greater than...)*/
64 e = bnode->num_recs - 1; in __hfs_brec_find()
65 res = -ENOENT; in __hfs_brec_find()
71 res = -EINVAL; in __hfs_brec_find()
74 hfs_bnode_read(bnode, fd->key, off, keylen); in __hfs_brec_find()
75 cmpval = bnode->tree->keycmp(fd->key, fd->search_key); in __hfs_brec_find()
84 e = rec - 1; in __hfs_brec_find()
90 res = -EINVAL; in __hfs_brec_find()
93 hfs_bnode_read(bnode, fd->key, off, keylen); in __hfs_brec_find()
96 fd->record = e; in __hfs_brec_find()
97 fd->keyoffset = off; in __hfs_brec_find()
98 fd->keylength = keylen; in __hfs_brec_find()
99 fd->entryoffset = off + keylen; in __hfs_brec_find()
100 fd->entrylength = len - keylen; in __hfs_brec_find()
105 /* Traverse a B*Tree from the root to a leaf finding best fit to key */
115 tree = fd->tree; in hfs_brec_find()
116 if (fd->bnode) in hfs_brec_find()
117 hfs_bnode_put(fd->bnode); in hfs_brec_find()
118 fd->bnode = NULL; in hfs_brec_find()
119 nidx = tree->root; in hfs_brec_find()
121 return -ENOENT; in hfs_brec_find()
122 height = tree->depth; in hfs_brec_find()
132 if (bnode->height != height) in hfs_brec_find()
134 if (bnode->type != (--height ? HFS_NODE_INDEX : HFS_NODE_LEAF)) in hfs_brec_find()
136 bnode->parent = parent; in hfs_brec_find()
141 if (fd->record < 0) in hfs_brec_find()
142 goto release; in hfs_brec_find()
145 hfs_bnode_read(bnode, &data, fd->entryoffset, 4); in hfs_brec_find()
149 fd->bnode = bnode; in hfs_brec_find()
154 height, bnode->height, bnode->type, nidx, parent); in hfs_brec_find()
155 res = -EIO; in hfs_brec_find()
156 release: in hfs_brec_find()
168 if (fd->entrylength > rec_len) in hfs_brec_read()
169 return -EINVAL; in hfs_brec_read()
170 hfs_bnode_read(fd->bnode, rec, fd->entryoffset, fd->entrylength); in hfs_brec_read()
181 bnode = fd->bnode; in hfs_brec_goto()
182 tree = bnode->tree; in hfs_brec_goto()
185 cnt = -cnt; in hfs_brec_goto()
186 while (cnt > fd->record) { in hfs_brec_goto()
187 cnt -= fd->record + 1; in hfs_brec_goto()
188 fd->record = bnode->num_recs - 1; in hfs_brec_goto()
189 idx = bnode->prev; in hfs_brec_goto()
191 res = -ENOENT; in hfs_brec_goto()
202 fd->record -= cnt; in hfs_brec_goto()
204 while (cnt >= bnode->num_recs - fd->record) { in hfs_brec_goto()
205 cnt -= bnode->num_recs - fd->record; in hfs_brec_goto()
206 fd->record = 0; in hfs_brec_goto()
207 idx = bnode->next; in hfs_brec_goto()
209 res = -ENOENT; in hfs_brec_goto()
220 fd->record += cnt; in hfs_brec_goto()
223 len = hfs_brec_lenoff(bnode, fd->record, &off); in hfs_brec_goto()
224 keylen = hfs_brec_keylen(bnode, fd->record); in hfs_brec_goto()
226 res = -EINVAL; in hfs_brec_goto()
229 fd->keyoffset = off; in hfs_brec_goto()
230 fd->keylength = keylen; in hfs_brec_goto()
231 fd->entryoffset = off + keylen; in hfs_brec_goto()
232 fd->entrylength = len - keylen; in hfs_brec_goto()
233 hfs_bnode_read(bnode, fd->key, off, keylen); in hfs_brec_goto()
235 fd->bnode = bnode; in hfs_brec_goto()