Lines Matching refs: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()
41 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
45 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
49 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
53 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
57 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
62 tree = node->tree; in hfs_bnode_read_key()
63 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
65 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_read_key()
66 key_len = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_read_key()
70 hfs_bnode_read(node, key, off, key_len); in hfs_bnode_read_key()
73 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len) in hfs_bnode_write() argument
78 off += node->page_offset; in hfs_bnode_write()
79 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_write()
94 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
98 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
101 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
106 off += node->page_offset; in hfs_bnode_clear()
107 pagep = node->page + (off >> PAGE_SHIFT); in hfs_bnode_clear()
175 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
184 src += node->page_offset; in hfs_bnode_move()
185 dst += node->page_offset; in hfs_bnode_move()
188 src_page = node->page + (src >> PAGE_SHIFT); in hfs_bnode_move()
191 dst_page = node->page + (dst >> PAGE_SHIFT); in hfs_bnode_move()
239 src_page = node->page + (src >> PAGE_SHIFT); in hfs_bnode_move()
241 dst_page = node->page + (dst >> PAGE_SHIFT); in hfs_bnode_move()
291 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
297 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
298 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
303 off = node->tree->node_size - 2; in hfs_bnode_dump()
305 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
307 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
310 if (node->tree->attributes & HFS_TREE_VARIDXKEYS || in hfs_bnode_dump()
311 node->tree->cnid == HFSPLUS_ATTR_CNID) in hfs_bnode_dump()
312 tmp = hfs_bnode_read_u16(node, key_off) + 2; in hfs_bnode_dump()
314 tmp = node->tree->max_key_len + 2; in hfs_bnode_dump()
316 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
318 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
321 tmp = hfs_bnode_read_u16(node, key_off); in hfs_bnode_dump()
328 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
334 tree = node->tree; in hfs_bnode_unlink()
335 if (node->prev) { in hfs_bnode_unlink()
336 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
339 tmp->next = node->next; in hfs_bnode_unlink()
344 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
345 tree->leaf_head = node->next; in hfs_bnode_unlink()
347 if (node->next) { in hfs_bnode_unlink()
348 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
351 tmp->prev = node->prev; in hfs_bnode_unlink()
356 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
357 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
360 if (!node->prev && !node->next) in hfs_bnode_unlink()
362 if (!node->parent) { in hfs_bnode_unlink()
366 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
378 struct hfs_bnode *node; in hfs_bnode_findhash() local
386 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
387 node; node = node->next_hash) in hfs_bnode_findhash()
388 if (node->this == cnid) in hfs_bnode_findhash()
389 return node; in hfs_bnode_findhash()
395 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
409 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
410 if (!node) in __hfs_bnode_create()
412 node->tree = tree; in __hfs_bnode_create()
413 node->this = cnid; in __hfs_bnode_create()
414 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
415 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
417 node->tree->cnid, node->this); in __hfs_bnode_create()
418 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
423 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
424 tree->node_hash[hash] = node; in __hfs_bnode_create()
428 kfree(node); in __hfs_bnode_create()
438 node->page_offset = off & ~PAGE_MASK; in __hfs_bnode_create()
443 node->page[i] = page; in __hfs_bnode_create()
446 return node; in __hfs_bnode_create()
448 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
449 return node; in __hfs_bnode_create()
452 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
457 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
458 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
459 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
462 *p = node->next_hash; in hfs_bnode_unhash()
463 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
469 struct hfs_bnode *node; in hfs_bnode_find() local
475 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
476 if (node) { in hfs_bnode_find()
477 hfs_bnode_get(node); in hfs_bnode_find()
479 wait_event(node->lock_wq, in hfs_bnode_find()
480 !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
481 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
483 return node; in hfs_bnode_find()
486 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
487 if (!node) in hfs_bnode_find()
489 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
491 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
492 return node; in hfs_bnode_find()
494 desc = (struct hfs_bnode_desc *)(kmap_local_page(node->page[0]) + in hfs_bnode_find()
495 node->page_offset); in hfs_bnode_find()
496 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
497 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
498 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
499 node->type = desc->type; in hfs_bnode_find()
500 node->height = desc->height; in hfs_bnode_find()
503 switch (node->type) { in hfs_bnode_find()
506 if (node->height != 0) in hfs_bnode_find()
510 if (node->height != 1) in hfs_bnode_find()
514 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
522 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
525 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
527 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
533 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
534 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
536 key_size = hfs_bnode_read_u16(node, off) + 2; in hfs_bnode_find()
540 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
541 wake_up(&node->lock_wq); in hfs_bnode_find()
542 return node; in hfs_bnode_find()
545 set_bit(HFS_BNODE_ERROR, &node->flags); in hfs_bnode_find()
546 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
547 wake_up(&node->lock_wq); in hfs_bnode_find()
548 hfs_bnode_put(node); in hfs_bnode_find()
552 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
556 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
557 if (node->page[i]) in hfs_bnode_free()
558 put_page(node->page[i]); in hfs_bnode_free()
559 kfree(node); in hfs_bnode_free()
564 struct hfs_bnode *node; in hfs_bnode_create() local
569 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
571 if (node) { in hfs_bnode_create()
574 return node; in hfs_bnode_create()
576 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
577 if (!node) in hfs_bnode_create()
579 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
580 hfs_bnode_put(node); in hfs_bnode_create()
584 pagep = node->page; in hfs_bnode_create()
585 memzero_page(*pagep, node->page_offset, in hfs_bnode_create()
592 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
593 wake_up(&node->lock_wq); in hfs_bnode_create()
595 return node; in hfs_bnode_create()
598 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
600 if (node) { in hfs_bnode_get()
601 atomic_inc(&node->refcnt); in hfs_bnode_get()
603 node->tree->cnid, node->this, in hfs_bnode_get()
604 atomic_read(&node->refcnt)); in hfs_bnode_get()
609 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
611 if (node) { in hfs_bnode_put()
612 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
616 node->tree->cnid, node->this, in hfs_bnode_put()
617 atomic_read(&node->refcnt)); in hfs_bnode_put()
618 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
619 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
622 if (!node->page[i]) in hfs_bnode_put()
624 mark_page_accessed(node->page[i]); in hfs_bnode_put()
627 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
628 hfs_bnode_unhash(node); in hfs_bnode_put()
631 hfs_bnode_clear(node, 0, tree->node_size); in hfs_bnode_put()
632 hfs_bmap_free(node); in hfs_bnode_put()
633 hfs_bnode_free(node); in hfs_bnode_put()