Lines Matching refs:node
21 void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_read() argument
26 off += node->page_offset; in hfs_bnode_read()
27 pagep = node->page + (off >> PAGE_CACHE_SHIFT); in hfs_bnode_read()
42 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
46 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
50 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
54 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
58 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
63 tree = node->tree; in hfs_bnode_read_key()
64 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
66 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_read_key()
67 key_len = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_read_key()
71 hfs_bnode_read(node, key, off, key_len); in hfs_bnode_read_key()
74 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_write() argument
79 off += node->page_offset; in hfs_bnode_write()
80 pagep = node->page + (off >> PAGE_CACHE_SHIFT); in hfs_bnode_write()
97 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
101 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
104 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
109 off += node->page_offset; in hfs_bnode_clear()
110 pagep = node->page + (off >> PAGE_CACHE_SHIFT); in hfs_bnode_clear()
186 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
194 src += node->page_offset; in hfs_bnode_move()
195 dst += node->page_offset; in hfs_bnode_move()
198 src_page = node->page + (src >> PAGE_CACHE_SHIFT); in hfs_bnode_move()
201 dst_page = node->page + (dst >> PAGE_CACHE_SHIFT); in hfs_bnode_move()
248 src_page = node->page + (src >> PAGE_CACHE_SHIFT); in hfs_bnode_move()
250 dst_page = node->page + (dst >> PAGE_CACHE_SHIFT); in hfs_bnode_move()
299 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
305 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
306 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
311 off = node->tree->node_size - 2; in hfs_bnode_dump()
313 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
315 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
318 if (node->tree->attributes & HFS_TREE_VARIDXKEYS || in hfs_bnode_dump()
319 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_dump()
320 tmp = hfs_bnode_read_u16(node, key_off) + 2; in hfs_bnode_dump()
322 tmp = node->tree->max_key_len + 2; in hfs_bnode_dump()
324 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
326 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
329 tmp = hfs_bnode_read_u16(node, key_off); in hfs_bnode_dump()
336 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
342 tree = node->tree; in hfs_bnode_unlink()
343 if (node->prev) { in hfs_bnode_unlink()
344 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
347 tmp->next = node->next; in hfs_bnode_unlink()
352 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
353 tree->leaf_head = node->next; in hfs_bnode_unlink()
355 if (node->next) { in hfs_bnode_unlink()
356 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
359 tmp->prev = node->prev; in hfs_bnode_unlink()
364 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
365 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
368 if (!node->prev && !node->next) in hfs_bnode_unlink()
370 if (!node->parent) { in hfs_bnode_unlink()
374 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
386 struct hfs_bnode *node; in hfs_bnode_findhash() local
395 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
396 node; node = node->next_hash) in hfs_bnode_findhash()
397 if (node->this == cnid) in hfs_bnode_findhash()
398 return node; in hfs_bnode_findhash()
405 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
421 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
422 if (!node) in __hfs_bnode_create()
424 node->tree = tree; in __hfs_bnode_create()
425 node->this = cnid; in __hfs_bnode_create()
426 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
427 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
429 node->tree->cnid, node->this); in __hfs_bnode_create()
430 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
435 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
436 tree->node_hash[hash] = node; in __hfs_bnode_create()
440 kfree(node); in __hfs_bnode_create()
450 node->page_offset = off & ~PAGE_CACHE_MASK; in __hfs_bnode_create()
460 node->page[i] = page; in __hfs_bnode_create()
463 return node; in __hfs_bnode_create()
465 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
466 return node; in __hfs_bnode_create()
469 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
474 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
475 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
476 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
479 *p = node->next_hash; in hfs_bnode_unhash()
480 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
486 struct hfs_bnode *node; in hfs_bnode_find() local
492 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
493 if (node) { in hfs_bnode_find()
494 hfs_bnode_get(node); in hfs_bnode_find()
496 wait_event(node->lock_wq, in hfs_bnode_find()
497 !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
498 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
500 return node; in hfs_bnode_find()
503 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
504 if (!node) in hfs_bnode_find()
506 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
508 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
509 return node; in hfs_bnode_find()
511 desc = (struct hfs_bnode_desc *)(kmap(node->page[0]) + in hfs_bnode_find()
512 node->page_offset); in hfs_bnode_find()
513 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
514 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
515 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
516 node->type = desc->type; in hfs_bnode_find()
517 node->height = desc->height; in hfs_bnode_find()
518 kunmap(node->page[0]); in hfs_bnode_find()
520 switch (node->type) { in hfs_bnode_find()
523 if (node->height != 0) in hfs_bnode_find()
527 if (node->height != 1) in hfs_bnode_find()
531 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
539 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
542 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
544 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
550 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
551 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
553 key_size = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_find()
557 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
558 wake_up(&node->lock_wq); in hfs_bnode_find()
559 return node; in hfs_bnode_find()
562 set_bit(HFS_BNODE_ERROR, &node->flags); in hfs_bnode_find()
563 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
564 wake_up(&node->lock_wq); in hfs_bnode_find()
565 hfs_bnode_put(node); in hfs_bnode_find()
569 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
574 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
575 if (node->page[i]) in hfs_bnode_free()
576 page_cache_release(node->page[i]); in hfs_bnode_free()
578 kfree(node); in hfs_bnode_free()
583 struct hfs_bnode *node; in hfs_bnode_create() local
588 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
590 if (node) { in hfs_bnode_create()
593 return node; in hfs_bnode_create()
595 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
596 if (!node) in hfs_bnode_create()
598 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
599 hfs_bnode_put(node); in hfs_bnode_create()
603 pagep = node->page; in hfs_bnode_create()
604 memset(kmap(*pagep) + node->page_offset, 0, in hfs_bnode_create()
613 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
614 wake_up(&node->lock_wq); in hfs_bnode_create()
616 return node; in hfs_bnode_create()
619 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
621 if (node) { in hfs_bnode_get()
622 atomic_inc(&node->refcnt); in hfs_bnode_get()
624 node->tree->cnid, node->this, in hfs_bnode_get()
625 atomic_read(&node->refcnt)); in hfs_bnode_get()
630 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
632 if (node) { in hfs_bnode_put()
633 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
637 node->tree->cnid, node->this, in hfs_bnode_put()
638 atomic_read(&node->refcnt)); in hfs_bnode_put()
639 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
640 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
643 if (!node->page[i]) in hfs_bnode_put()
645 mark_page_accessed(node->page[i]); in hfs_bnode_put()
648 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
649 hfs_bnode_unhash(node); in hfs_bnode_put()
651 hfs_bnode_clear(node, 0, in hfs_bnode_put()
653 hfs_bmap_free(node); in hfs_bnode_put()
654 hfs_bnode_free(node); in hfs_bnode_put()