Lines Matching full:node

9  * Handle basic btree node operations
21 /* Copy a specified range of bytes from the raw data of a node */
22 void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_read() argument
27 off += node->page_offset; in hfs_bnode_read()
28 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_read()
43 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
47 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
51 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
55 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
59 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
64 tree = node->tree; in hfs_bnode_read_key()
65 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
67 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_read_key()
68 key_len = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_read_key()
72 hfs_bnode_read(node, key, off, key_len); in hfs_bnode_read_key()
75 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_write() argument
80 off += node->page_offset; in hfs_bnode_write()
81 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_write()
98 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
102 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
105 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
110 off += node->page_offset; in hfs_bnode_clear()
111 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_clear()
185 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
193 src += node->page_offset; in hfs_bnode_move()
194 dst += node->page_offset; in hfs_bnode_move()
197 src_page = node->page + (src >> PAGE_SHIFT); in hfs_bnode_move()
200 dst_page = node->page + (dst >> PAGE_SHIFT); in hfs_bnode_move()
247 src_page = node->page + (src >> PAGE_SHIFT); in hfs_bnode_move()
249 dst_page = node->page + (dst >> PAGE_SHIFT); in hfs_bnode_move()
298 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
304 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
305 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
310 off = node->tree->node_size - 2; in hfs_bnode_dump()
312 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
314 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
317 if (node->tree->attributes & HFS_TREE_VARIDXKEYS || in hfs_bnode_dump()
318 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_dump()
319 tmp = hfs_bnode_read_u16(node, key_off) + 2; in hfs_bnode_dump()
321 tmp = node->tree->max_key_len + 2; in hfs_bnode_dump()
323 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
325 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
328 tmp = hfs_bnode_read_u16(node, key_off); in hfs_bnode_dump()
335 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
341 tree = node->tree; in hfs_bnode_unlink()
342 if (node->prev) { in hfs_bnode_unlink()
343 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
346 tmp->next = node->next; in hfs_bnode_unlink()
351 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
352 tree->leaf_head = node->next; in hfs_bnode_unlink()
354 if (node->next) { in hfs_bnode_unlink()
355 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
358 tmp->prev = node->prev; in hfs_bnode_unlink()
363 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
364 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
367 if (!node->prev && !node->next) in hfs_bnode_unlink()
369 if (!node->parent) { in hfs_bnode_unlink()
373 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
385 struct hfs_bnode *node; in hfs_bnode_findhash() local
388 pr_err("request for non-existent node %d in B*Tree\n", in hfs_bnode_findhash()
393 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
394 node; node = node->next_hash) in hfs_bnode_findhash()
395 if (node->this == cnid) in hfs_bnode_findhash()
396 return node; in hfs_bnode_findhash()
402 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
409 pr_err("request for non-existent node %d in B*Tree\n", in __hfs_bnode_create()
416 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
417 if (!node) in __hfs_bnode_create()
419 node->tree = tree; in __hfs_bnode_create()
420 node->this = cnid; in __hfs_bnode_create()
421 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
422 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
424 node->tree->cnid, node->this); in __hfs_bnode_create()
425 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
430 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
431 tree->node_hash[hash] = node; in __hfs_bnode_create()
435 kfree(node); in __hfs_bnode_create()
445 node->page_offset = off & ~PAGE_MASK; in __hfs_bnode_create()
454 node->page[i] = page; in __hfs_bnode_create()
457 return node; in __hfs_bnode_create()
459 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
460 return node; in __hfs_bnode_create()
463 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
468 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
469 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
470 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
473 *p = node->next_hash; in hfs_bnode_unhash()
474 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
477 /* Load a particular node out of a tree */
480 struct hfs_bnode *node; in hfs_bnode_find() local
486 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
487 if (node) { in hfs_bnode_find()
488 hfs_bnode_get(node); in hfs_bnode_find()
490 wait_event(node->lock_wq, in hfs_bnode_find()
491 !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
492 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
494 return node; in hfs_bnode_find()
497 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
498 if (!node) in hfs_bnode_find()
500 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
502 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
503 return node; in hfs_bnode_find()
505 desc = (struct hfs_bnode_desc *)(kmap(node->page[0]) + in hfs_bnode_find()
506 node->page_offset); in hfs_bnode_find()
507 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
508 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
509 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
510 node->type = desc->type; in hfs_bnode_find()
511 node->height = desc->height; in hfs_bnode_find()
512 kunmap(node->page[0]); in hfs_bnode_find()
514 switch (node->type) { in hfs_bnode_find()
517 if (node->height != 0) in hfs_bnode_find()
521 if (node->height != 1) in hfs_bnode_find()
525 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
533 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
536 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
538 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
544 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
545 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
547 key_size = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_find()
551 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
552 wake_up(&node->lock_wq); in hfs_bnode_find()
553 return node; in hfs_bnode_find()
556 set_bit(HFS_BNODE_ERROR, &node->flags); 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 hfs_bnode_put(node); in hfs_bnode_find()
563 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
567 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
568 if (node->page[i]) in hfs_bnode_free()
569 put_page(node->page[i]); in hfs_bnode_free()
570 kfree(node); in hfs_bnode_free()
575 struct hfs_bnode *node; in hfs_bnode_create() local
580 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
582 if (node) { in hfs_bnode_create()
583 pr_crit("new node %u already hashed?\n", num); in hfs_bnode_create()
585 return node; in hfs_bnode_create()
587 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
588 if (!node) in hfs_bnode_create()
590 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
591 hfs_bnode_put(node); in hfs_bnode_create()
595 pagep = node->page; in hfs_bnode_create()
596 memset(kmap(*pagep) + node->page_offset, 0, in hfs_bnode_create()
605 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
606 wake_up(&node->lock_wq); in hfs_bnode_create()
608 return node; in hfs_bnode_create()
611 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
613 if (node) { in hfs_bnode_get()
614 atomic_inc(&node->refcnt); in hfs_bnode_get()
616 node->tree->cnid, node->this, in hfs_bnode_get()
617 atomic_read(&node->refcnt)); in hfs_bnode_get()
621 /* Dispose of resources used by a node */
622 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
624 if (node) { in hfs_bnode_put()
625 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
629 node->tree->cnid, node->this, in hfs_bnode_put()
630 atomic_read(&node->refcnt)); in hfs_bnode_put()
631 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
632 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
635 if (!node->page[i]) in hfs_bnode_put()
637 mark_page_accessed(node->page[i]); in hfs_bnode_put()
640 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
641 hfs_bnode_unhash(node); in hfs_bnode_put()
644 hfs_bnode_clear(node, 0, tree->node_size); in hfs_bnode_put()
645 hfs_bmap_free(node); in hfs_bnode_put()
646 hfs_bnode_free(node); in hfs_bnode_put()