Lines Matching defs:node
8 * Handle basic btree node operations
20 /* Copy a specified range of bytes from the raw data of a node */
21 void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len)
26 off += node->page_offset;
27 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
42 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off)
46 hfs_bnode_read(node, &data, off, 2);
50 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off)
54 hfs_bnode_read(node, &data, off, 1);
58 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off)
63 tree = node->tree;
64 if (node->type == HFS_NODE_LEAF ||
66 key_len = hfs_bnode_read_u16(node, off) + 2;
70 hfs_bnode_read(node, key, off, key_len);
73 void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len)
78 off += node->page_offset;
79 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
96 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data)
100 hfs_bnode_write(node, &v, off, 2);
103 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len)
108 off += node->page_offset;
109 pagep = node->page + (off >> PAGE_CACHE_SHIFT);
185 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len)
193 src += node->page_offset;
194 dst += node->page_offset;
197 src_page = node->page + (src >> PAGE_CACHE_SHIFT);
200 dst_page = node->page + (dst >> PAGE_CACHE_SHIFT);
246 src_page = node->page + (src >> PAGE_CACHE_SHIFT);
248 dst_page = node->page + (dst >> PAGE_CACHE_SHIFT);
294 void hfs_bnode_dump(struct hfs_bnode *node)
300 dprint(DBG_BNODE_MOD, "bnode: %d\n", node->this);
301 hfs_bnode_read(node, &desc, 0, sizeof(desc));
306 off = node->tree->node_size - 2;
308 key_off = hfs_bnode_read_u16(node, off);
310 if (i && node->type == HFS_NODE_INDEX) {
313 if (node->tree->attributes & HFS_TREE_VARIDXKEYS)
314 tmp = hfs_bnode_read_u16(node, key_off) + 2;
316 tmp = node->tree->max_key_len + 2;
318 hfs_bnode_read(node, &cnid, key_off + tmp, 4);
320 } else if (i && node->type == HFS_NODE_LEAF) {
323 tmp = hfs_bnode_read_u16(node, key_off);
330 void hfs_bnode_unlink(struct hfs_bnode *node)
336 tree = node->tree;
337 if (node->prev) {
338 tmp = hfs_bnode_find(tree, node->prev);
341 tmp->next = node->next;
345 } else if (node->type == HFS_NODE_LEAF)
346 tree->leaf_head = node->next;
348 if (node->next) {
349 tmp = hfs_bnode_find(tree, node->next);
352 tmp->prev = node->prev;
356 } else if (node->type == HFS_NODE_LEAF)
357 tree->leaf_tail = node->prev;
360 if (!node->prev && !node->next) {
363 if (!node->parent) {
367 set_bit(HFS_BNODE_DELETED, &node->flags);
379 struct hfs_bnode *node;
382 printk(KERN_ERR "hfs: request for non-existent node %d in B*Tree\n", cnid);
386 for (node = tree->node_hash[hfs_bnode_hash(cnid)];
387 node; node = node->next_hash) {
388 if (node->this == cnid) {
389 return node;
398 struct hfs_bnode *node, *node2;
405 printk(KERN_ERR "hfs: request for non-existent node %d in B*Tree\n", cnid);
412 node = kzalloc(size, GFP_KERNEL);
413 if (!node)
415 node->tree = tree;
416 node->this = cnid;
417 set_bit(HFS_BNODE_NEW, &node->flags);
418 atomic_set(&node->refcnt, 1);
420 node->tree->cnid, node->this);
421 init_waitqueue_head(&node->lock_wq);
426 node->next_hash = tree->node_hash[hash];
427 tree->node_hash[hash] = node;
431 kfree(node);
440 node->page_offset = off & ~PAGE_CACHE_MASK;
450 node->page[i] = page;
453 return node;
455 set_bit(HFS_BNODE_ERROR, &node->flags);
456 return node;
459 void hfs_bnode_unhash(struct hfs_bnode *node)
464 node->tree->cnid, node->this, atomic_read(&node->refcnt));
465 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)];
466 *p && *p != node; p = &(*p)->next_hash)
469 *p = node->next_hash;
470 node->tree->node_hash_cnt--;
473 /* Load a particular node out of a tree */
476 struct hfs_bnode *node;
482 node = hfs_bnode_findhash(tree, num);
483 if (node) {
484 hfs_bnode_get(node);
486 wait_event(node->lock_wq, !test_bit(HFS_BNODE_NEW, &node->flags));
487 if (test_bit(HFS_BNODE_ERROR, &node->flags))
489 return node;
492 node = __hfs_bnode_create(tree, num);
493 if (!node)
495 if (test_bit(HFS_BNODE_ERROR, &node->flags))
497 if (!test_bit(HFS_BNODE_NEW, &node->flags))
498 return node;
500 desc = (struct hfs_bnode_desc *)(kmap(node->page[0]) + node->page_offset);
501 node->prev = be32_to_cpu(desc->prev);
502 node->next = be32_to_cpu(desc->next);
503 node->num_recs = be16_to_cpu(desc->num_recs);
504 node->type = desc->type;
505 node->height = desc->height;
506 kunmap(node->page[0]);
508 switch (node->type) {
511 if (node->height != 0)
515 if (node->height != 1)
519 if (node->height <= 1 || node->height > tree->depth)
527 off = hfs_bnode_read_u16(node, rec_off);
530 for (i = 1; i <= node->num_recs; off = next_off, i++) {
532 next_off = hfs_bnode_read_u16(node, rec_off);
538 if (node->type != HFS_NODE_INDEX &&
539 node->type != HFS_NODE_LEAF)
541 key_size = hfs_bnode_read_u16(node, off) + 2;
545 clear_bit(HFS_BNODE_NEW, &node->flags);
546 wake_up(&node->lock_wq);
547 return node;
550 set_bit(HFS_BNODE_ERROR, &node->flags);
551 clear_bit(HFS_BNODE_NEW, &node->flags);
552 wake_up(&node->lock_wq);
553 hfs_bnode_put(node);
557 void hfs_bnode_free(struct hfs_bnode *node)
561 //for (i = 0; i < node->tree->pages_per_bnode; i++)
562 // if (node->page[i])
563 // page_cache_release(node->page[i]);
564 kfree(node);
569 struct hfs_bnode *node;
574 node = hfs_bnode_findhash(tree, num);
576 if (node) {
577 printk(KERN_CRIT "new node %u already hashed?\n", num);
579 return node;
581 node = __hfs_bnode_create(tree, num);
582 if (!node)
584 if (test_bit(HFS_BNODE_ERROR, &node->flags)) {
585 hfs_bnode_put(node);
589 pagep = node->page;
590 memset(kmap(*pagep) + node->page_offset, 0,
599 clear_bit(HFS_BNODE_NEW, &node->flags);
600 wake_up(&node->lock_wq);
602 return node;
605 void hfs_bnode_get(struct hfs_bnode *node)
607 if (node) {
608 atomic_inc(&node->refcnt);
610 node->tree->cnid, node->this, atomic_read(&node->refcnt));
614 /* Dispose of resources used by a node */
615 void hfs_bnode_put(struct hfs_bnode *node)
617 if (node) {
618 struct hfs_btree *tree = node->tree;
622 node->tree->cnid, node->this, atomic_read(&node->refcnt));
623 BUG_ON(!atomic_read(&node->refcnt));
624 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock))
627 if (!node->page[i])
629 mark_page_accessed(node->page[i]);
632 if (test_bit(HFS_BNODE_DELETED, &node->flags)) {
633 hfs_bnode_unhash(node);
635 hfs_bmap_free(node);
636 hfs_bnode_free(node);