Lines Matching refs:node

17 void hfs_bnode_read(struct hfs_bnode *node, void *buf,  in hfs_bnode_read()  argument
22 off += node->page_offset; in hfs_bnode_read()
23 page = node->page[0]; in hfs_bnode_read()
29 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
33 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
37 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
41 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
45 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
50 tree = node->tree; in hfs_bnode_read_key()
51 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
53 key_len = hfs_bnode_read_u8(node, off) + 1; in hfs_bnode_read_key()
57 hfs_bnode_read(node, key, off, key_len); in hfs_bnode_read_key()
60 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_write() argument
64 off += node->page_offset; in hfs_bnode_write()
65 page = node->page[0]; in hfs_bnode_write()
72 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
76 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
79 void hfs_bnode_write_u8(struct hfs_bnode *node, int off, u8 data) in hfs_bnode_write_u8() argument
82 hfs_bnode_write(node, &data, off, 1); in hfs_bnode_write_u8()
85 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
89 off += node->page_offset; in hfs_bnode_clear()
90 page = node->page[0]; in hfs_bnode_clear()
118 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
126 src += node->page_offset; in hfs_bnode_move()
127 dst += node->page_offset; in hfs_bnode_move()
128 page = node->page[0]; in hfs_bnode_move()
135 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
141 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
142 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
147 off = node->tree->node_size - 2; in hfs_bnode_dump()
149 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
151 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
154 if (node->tree->attributes & HFS_TREE_VARIDXKEYS) in hfs_bnode_dump()
155 tmp = (hfs_bnode_read_u8(node, key_off) | 1) + 1; in hfs_bnode_dump()
157 tmp = node->tree->max_key_len + 1; in hfs_bnode_dump()
159 tmp, hfs_bnode_read_u8(node, key_off)); in hfs_bnode_dump()
160 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
162 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
165 tmp = hfs_bnode_read_u8(node, key_off); in hfs_bnode_dump()
172 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
178 tree = node->tree; in hfs_bnode_unlink()
179 if (node->prev) { in hfs_bnode_unlink()
180 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
183 tmp->next = node->next; in hfs_bnode_unlink()
187 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
188 tree->leaf_head = node->next; in hfs_bnode_unlink()
190 if (node->next) { in hfs_bnode_unlink()
191 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
194 tmp->prev = node->prev; in hfs_bnode_unlink()
198 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
199 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
202 if (!node->prev && !node->next) { in hfs_bnode_unlink()
205 if (!node->parent) { in hfs_bnode_unlink()
209 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
221 struct hfs_bnode *node; in hfs_bnode_findhash() local
228 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
229 node; node = node->next_hash) { in hfs_bnode_findhash()
230 if (node->this == cnid) { in hfs_bnode_findhash()
231 return node; in hfs_bnode_findhash()
240 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
254 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
255 if (!node) in __hfs_bnode_create()
257 node->tree = tree; in __hfs_bnode_create()
258 node->this = cnid; in __hfs_bnode_create()
259 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
260 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
262 node->tree->cnid, node->this); in __hfs_bnode_create()
263 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
268 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
269 tree->node_hash[hash] = node; in __hfs_bnode_create()
273 kfree(node); in __hfs_bnode_create()
282 node->page_offset = off & ~PAGE_CACHE_MASK; in __hfs_bnode_create()
291 node->page[i] = page; in __hfs_bnode_create()
294 return node; in __hfs_bnode_create()
296 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
297 return node; in __hfs_bnode_create()
300 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
305 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
306 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
307 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
310 *p = node->next_hash; in hfs_bnode_unhash()
311 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
317 struct hfs_bnode *node; in hfs_bnode_find() local
323 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
324 if (node) { in hfs_bnode_find()
325 hfs_bnode_get(node); in hfs_bnode_find()
327 wait_event(node->lock_wq, !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
328 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
330 return node; in hfs_bnode_find()
333 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
334 if (!node) in hfs_bnode_find()
336 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
338 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
339 return node; in hfs_bnode_find()
341 desc = (struct hfs_bnode_desc *)(kmap(node->page[0]) + node->page_offset); in hfs_bnode_find()
342 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
343 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
344 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
345 node->type = desc->type; in hfs_bnode_find()
346 node->height = desc->height; in hfs_bnode_find()
347 kunmap(node->page[0]); in hfs_bnode_find()
349 switch (node->type) { in hfs_bnode_find()
352 if (node->height != 0) in hfs_bnode_find()
356 if (node->height != 1) in hfs_bnode_find()
360 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
368 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
371 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
373 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
379 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
380 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
382 key_size = hfs_bnode_read_u8(node, off) + 1; in hfs_bnode_find()
386 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
387 wake_up(&node->lock_wq); in hfs_bnode_find()
388 return node; in hfs_bnode_find()
391 set_bit(HFS_BNODE_ERROR, &node->flags); in hfs_bnode_find()
392 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
393 wake_up(&node->lock_wq); in hfs_bnode_find()
394 hfs_bnode_put(node); in hfs_bnode_find()
398 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
402 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
403 if (node->page[i]) in hfs_bnode_free()
404 page_cache_release(node->page[i]); in hfs_bnode_free()
405 kfree(node); in hfs_bnode_free()
410 struct hfs_bnode *node; in hfs_bnode_create() local
415 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
417 if (node) { in hfs_bnode_create()
420 return node; in hfs_bnode_create()
422 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
423 if (!node) in hfs_bnode_create()
425 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
426 hfs_bnode_put(node); in hfs_bnode_create()
430 pagep = node->page; in hfs_bnode_create()
431 memset(kmap(*pagep) + node->page_offset, 0, in hfs_bnode_create()
440 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
441 wake_up(&node->lock_wq); in hfs_bnode_create()
443 return node; in hfs_bnode_create()
446 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
448 if (node) { in hfs_bnode_get()
449 atomic_inc(&node->refcnt); in hfs_bnode_get()
451 node->tree->cnid, node->this, in hfs_bnode_get()
452 atomic_read(&node->refcnt)); in hfs_bnode_get()
457 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
459 if (node) { in hfs_bnode_put()
460 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
464 node->tree->cnid, node->this, in hfs_bnode_put()
465 atomic_read(&node->refcnt)); in hfs_bnode_put()
466 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
467 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
470 if (!node->page[i]) in hfs_bnode_put()
472 mark_page_accessed(node->page[i]); in hfs_bnode_put()
475 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
476 hfs_bnode_unhash(node); in hfs_bnode_put()
478 hfs_bmap_free(node); in hfs_bnode_put()
479 hfs_bnode_free(node); in hfs_bnode_put()