Lines Matching refs:node
22 bool is_bnode_offset_valid(struct hfs_bnode *node, int off) in is_bnode_offset_valid() argument
24 bool is_valid = off < node->tree->node_size; in is_bnode_offset_valid()
30 node->this, node->type, node->height, in is_bnode_offset_valid()
31 node->tree->node_size, off); in is_bnode_offset_valid()
38 int check_and_correct_requested_length(struct hfs_bnode *node, int off, int len) in check_and_correct_requested_length() argument
42 if (!is_bnode_offset_valid(node, off)) in check_and_correct_requested_length()
45 node_size = node->tree->node_size; in check_and_correct_requested_length()
54 node->this, node->type, node->height, in check_and_correct_requested_length()
55 node->tree->node_size, off, len, new_len); in check_and_correct_requested_length()
64 void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_read() argument
69 if (!is_bnode_offset_valid(node, off)) in hfs_bnode_read()
76 node->this, node->type, node->height, in hfs_bnode_read()
77 node->tree->node_size, off, len); in hfs_bnode_read()
81 len = check_and_correct_requested_length(node, off, len); in hfs_bnode_read()
83 off += node->page_offset; in hfs_bnode_read()
84 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_read()
97 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
101 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
105 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
109 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
113 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
118 tree = node->tree; in hfs_bnode_read_key()
119 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
121 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_read_key()
122 key_len = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_read_key()
132 hfs_bnode_read(node, key, off, key_len); in hfs_bnode_read_key()
135 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_write() argument
140 if (!is_bnode_offset_valid(node, off)) in hfs_bnode_write()
147 node->this, node->type, node->height, in hfs_bnode_write()
148 node->tree->node_size, off, len); in hfs_bnode_write()
152 len = check_and_correct_requested_length(node, off, len); in hfs_bnode_write()
154 off += node->page_offset; in hfs_bnode_write()
155 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_write()
170 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
174 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
177 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
182 if (!is_bnode_offset_valid(node, off)) in hfs_bnode_clear()
189 node->this, node->type, node->height, in hfs_bnode_clear()
190 node->tree->node_size, off, len); in hfs_bnode_clear()
194 len = check_and_correct_requested_length(node, off, len); in hfs_bnode_clear()
196 off += node->page_offset; in hfs_bnode_clear()
197 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_clear()
269 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
279 len = check_and_correct_requested_length(node, src, len); in hfs_bnode_move()
280 len = check_and_correct_requested_length(node, dst, len); in hfs_bnode_move()
282 src += node->page_offset; in hfs_bnode_move()
283 dst += node->page_offset; in hfs_bnode_move()
286 src_page = node->page + (src >> PAGE_SHIFT); in hfs_bnode_move()
289 dst_page = node->page + (dst >> PAGE_SHIFT); in hfs_bnode_move()
337 src_page = node->page + (src >> PAGE_SHIFT); in hfs_bnode_move()
339 dst_page = node->page + (dst >> PAGE_SHIFT); in hfs_bnode_move()
389 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
395 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
396 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
401 off = node->tree->node_size - 2; in hfs_bnode_dump()
403 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
405 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
408 if (node->tree->attributes & HFS_TREE_VARIDXKEYS || in hfs_bnode_dump()
409 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_dump()
410 tmp = hfs_bnode_read_u16(node, key_off) + 2; in hfs_bnode_dump()
412 tmp = node->tree->max_key_len + 2; in hfs_bnode_dump()
414 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
416 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
419 tmp = hfs_bnode_read_u16(node, key_off); in hfs_bnode_dump()
426 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
432 tree = node->tree; in hfs_bnode_unlink()
433 if (node->prev) { in hfs_bnode_unlink()
434 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
437 tmp->next = node->next; in hfs_bnode_unlink()
442 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
443 tree->leaf_head = node->next; in hfs_bnode_unlink()
445 if (node->next) { in hfs_bnode_unlink()
446 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
449 tmp->prev = node->prev; in hfs_bnode_unlink()
454 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
455 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
458 if (!node->prev && !node->next) in hfs_bnode_unlink()
460 if (!node->parent) { in hfs_bnode_unlink()
464 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
476 struct hfs_bnode *node; in hfs_bnode_findhash() local
484 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
485 node; node = node->next_hash) in hfs_bnode_findhash()
486 if (node->this == cnid) in hfs_bnode_findhash()
487 return node; in hfs_bnode_findhash()
493 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
507 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
508 if (!node) in __hfs_bnode_create()
510 node->tree = tree; in __hfs_bnode_create()
511 node->this = cnid; in __hfs_bnode_create()
512 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
513 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
515 node->tree->cnid, node->this); in __hfs_bnode_create()
516 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
521 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
522 tree->node_hash[hash] = node; in __hfs_bnode_create()
526 kfree(node); in __hfs_bnode_create()
536 node->page_offset = off & ~PAGE_MASK; in __hfs_bnode_create()
541 node->page[i] = page; in __hfs_bnode_create()
544 return node; in __hfs_bnode_create()
546 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
547 return node; in __hfs_bnode_create()
550 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
555 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
556 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
557 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
560 *p = node->next_hash; in hfs_bnode_unhash()
561 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
567 struct hfs_bnode *node; in hfs_bnode_find() local
573 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
574 if (node) { in hfs_bnode_find()
575 hfs_bnode_get(node); in hfs_bnode_find()
577 wait_event(node->lock_wq, in hfs_bnode_find()
578 !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
579 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
581 return node; in hfs_bnode_find()
584 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
585 if (!node) in hfs_bnode_find()
587 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
589 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
590 return node; in hfs_bnode_find()
592 desc = (struct hfs_bnode_desc *)(kmap_local_page(node->page[0]) + in hfs_bnode_find()
593 node->page_offset); in hfs_bnode_find()
594 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
595 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
596 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
597 node->type = desc->type; in hfs_bnode_find()
598 node->height = desc->height; in hfs_bnode_find()
601 switch (node->type) { in hfs_bnode_find()
604 if (node->height != 0) in hfs_bnode_find()
608 if (node->height != 1) in hfs_bnode_find()
612 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
620 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
623 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
625 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
631 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
632 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
634 key_size = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_find()
638 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
639 wake_up(&node->lock_wq); in hfs_bnode_find()
640 return node; in hfs_bnode_find()
643 set_bit(HFS_BNODE_ERROR, &node->flags); in hfs_bnode_find()
644 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
645 wake_up(&node->lock_wq); in hfs_bnode_find()
646 hfs_bnode_put(node); in hfs_bnode_find()
650 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
654 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
655 if (node->page[i]) in hfs_bnode_free()
656 put_page(node->page[i]); in hfs_bnode_free()
657 kfree(node); in hfs_bnode_free()
662 struct hfs_bnode *node; in hfs_bnode_create() local
667 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
669 if (node) { in hfs_bnode_create()
672 return node; in hfs_bnode_create()
674 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
675 if (!node) in hfs_bnode_create()
677 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
678 hfs_bnode_put(node); in hfs_bnode_create()
682 pagep = node->page; in hfs_bnode_create()
683 memzero_page(*pagep, node->page_offset, in hfs_bnode_create()
690 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
691 wake_up(&node->lock_wq); in hfs_bnode_create()
693 return node; in hfs_bnode_create()
696 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
698 if (node) { in hfs_bnode_get()
699 atomic_inc(&node->refcnt); in hfs_bnode_get()
701 node->tree->cnid, node->this, in hfs_bnode_get()
702 atomic_read(&node->refcnt)); in hfs_bnode_get()
707 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
709 if (node) { in hfs_bnode_put()
710 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
714 node->tree->cnid, node->this, in hfs_bnode_put()
715 atomic_read(&node->refcnt)); in hfs_bnode_put()
716 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
717 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
720 if (!node->page[i]) in hfs_bnode_put()
722 mark_page_accessed(node->page[i]); in hfs_bnode_put()
725 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
726 hfs_bnode_unhash(node); in hfs_bnode_put()
729 hfs_bnode_clear(node, 0, tree->node_size); in hfs_bnode_put()
730 hfs_bmap_free(node); in hfs_bnode_put()
731 hfs_bnode_free(node); in hfs_bnode_put()