Lines Matching refs:node

18 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()
31 if (pagenum >= node->tree->pages_per_bnode) in hfs_bnode_read()
33 page = node->page[pagenum]; in hfs_bnode_read()
45 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
49 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
53 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
57 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
61 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
66 tree = node->tree; in hfs_bnode_read_key()
67 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
69 key_len = hfs_bnode_read_u8(node, off) + 1; in hfs_bnode_read_key()
73 hfs_bnode_read(node, key, off, key_len); in hfs_bnode_read_key()
76 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 page = node->page[0]; in hfs_bnode_write()
88 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
92 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
95 void hfs_bnode_write_u8(struct hfs_bnode *node, int off, u8 data) in hfs_bnode_write_u8() argument
98 hfs_bnode_write(node, &data, off, 1); in hfs_bnode_write_u8()
101 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
105 off += node->page_offset; in hfs_bnode_clear()
106 page = node->page[0]; in hfs_bnode_clear()
132 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
140 src += node->page_offset; in hfs_bnode_move()
141 dst += node->page_offset; in hfs_bnode_move()
142 page = node->page[0]; in hfs_bnode_move()
149 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
155 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
156 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
161 off = node->tree->node_size - 2; in hfs_bnode_dump()
163 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
165 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
168 if (node->tree->attributes & HFS_TREE_VARIDXKEYS) in hfs_bnode_dump()
169 tmp = (hfs_bnode_read_u8(node, key_off) | 1) + 1; in hfs_bnode_dump()
171 tmp = node->tree->max_key_len + 1; in hfs_bnode_dump()
173 tmp, hfs_bnode_read_u8(node, key_off)); in hfs_bnode_dump()
174 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
176 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
179 tmp = hfs_bnode_read_u8(node, key_off); in hfs_bnode_dump()
186 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
192 tree = node->tree; in hfs_bnode_unlink()
193 if (node->prev) { in hfs_bnode_unlink()
194 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
197 tmp->next = node->next; in hfs_bnode_unlink()
201 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
202 tree->leaf_head = node->next; in hfs_bnode_unlink()
204 if (node->next) { in hfs_bnode_unlink()
205 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
208 tmp->prev = node->prev; in hfs_bnode_unlink()
212 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
213 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
216 if (!node->prev && !node->next) { in hfs_bnode_unlink()
219 if (!node->parent) { in hfs_bnode_unlink()
223 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
235 struct hfs_bnode *node; in hfs_bnode_findhash() local
242 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
243 node; node = node->next_hash) { in hfs_bnode_findhash()
244 if (node->this == cnid) { in hfs_bnode_findhash()
245 return node; in hfs_bnode_findhash()
253 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
266 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
267 if (!node) in __hfs_bnode_create()
269 node->tree = tree; in __hfs_bnode_create()
270 node->this = cnid; in __hfs_bnode_create()
271 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
272 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
274 node->tree->cnid, node->this); in __hfs_bnode_create()
275 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
280 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
281 tree->node_hash[hash] = node; in __hfs_bnode_create()
286 kfree(node); in __hfs_bnode_create()
295 node->page_offset = off & ~PAGE_MASK; in __hfs_bnode_create()
304 node->page[i] = page; in __hfs_bnode_create()
307 return node; in __hfs_bnode_create()
309 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
310 return node; in __hfs_bnode_create()
313 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
318 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
319 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
320 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
323 *p = node->next_hash; in hfs_bnode_unhash()
324 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
330 struct hfs_bnode *node; in hfs_bnode_find() local
336 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
337 if (node) { in hfs_bnode_find()
338 hfs_bnode_get(node); in hfs_bnode_find()
340 wait_event(node->lock_wq, !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
341 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
343 return node; in hfs_bnode_find()
346 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
347 if (!node) in hfs_bnode_find()
349 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
351 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
352 return node; in hfs_bnode_find()
354 desc = (struct hfs_bnode_desc *)(kmap(node->page[0]) + node->page_offset); in hfs_bnode_find()
355 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
356 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
357 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
358 node->type = desc->type; in hfs_bnode_find()
359 node->height = desc->height; in hfs_bnode_find()
360 kunmap(node->page[0]); in hfs_bnode_find()
362 switch (node->type) { in hfs_bnode_find()
365 if (node->height != 0) in hfs_bnode_find()
369 if (node->height != 1) in hfs_bnode_find()
373 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
381 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
384 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
386 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
392 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
393 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
395 key_size = hfs_bnode_read_u8(node, off) + 1; in hfs_bnode_find()
399 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
400 wake_up(&node->lock_wq); in hfs_bnode_find()
401 return node; in hfs_bnode_find()
404 set_bit(HFS_BNODE_ERROR, &node->flags); in hfs_bnode_find()
405 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
406 wake_up(&node->lock_wq); in hfs_bnode_find()
407 hfs_bnode_put(node); in hfs_bnode_find()
411 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
415 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
416 if (node->page[i]) in hfs_bnode_free()
417 put_page(node->page[i]); in hfs_bnode_free()
418 kfree(node); in hfs_bnode_free()
423 struct hfs_bnode *node; in hfs_bnode_create() local
428 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
430 if (node) { in hfs_bnode_create()
433 return node; in hfs_bnode_create()
435 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
436 if (!node) in hfs_bnode_create()
438 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
439 hfs_bnode_put(node); in hfs_bnode_create()
443 pagep = node->page; in hfs_bnode_create()
444 memset(kmap(*pagep) + node->page_offset, 0, in hfs_bnode_create()
453 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
454 wake_up(&node->lock_wq); in hfs_bnode_create()
456 return node; in hfs_bnode_create()
459 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
461 if (node) { in hfs_bnode_get()
462 atomic_inc(&node->refcnt); in hfs_bnode_get()
464 node->tree->cnid, node->this, in hfs_bnode_get()
465 atomic_read(&node->refcnt)); in hfs_bnode_get()
470 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
472 if (node) { in hfs_bnode_put()
473 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
477 node->tree->cnid, node->this, in hfs_bnode_put()
478 atomic_read(&node->refcnt)); in hfs_bnode_put()
479 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
480 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
483 if (!node->page[i]) in hfs_bnode_put()
485 mark_page_accessed(node->page[i]); in hfs_bnode_put()
488 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
489 hfs_bnode_unhash(node); in hfs_bnode_put()
491 hfs_bmap_free(node); in hfs_bnode_put()
492 hfs_bnode_free(node); in hfs_bnode_put()