Lines Matching refs:node

18 void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len)  in hfs_bnode_read()  argument
25 off += node->page_offset; in hfs_bnode_read()
30 if (pagenum >= node->tree->pages_per_bnode) in hfs_bnode_read()
32 page = node->page[pagenum]; in hfs_bnode_read()
42 u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off) in hfs_bnode_read_u16() argument
46 hfs_bnode_read(node, &data, off, 2); in hfs_bnode_read_u16()
50 u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off) in hfs_bnode_read_u8() argument
54 hfs_bnode_read(node, &data, off, 1); in hfs_bnode_read_u8()
58 void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off) in hfs_bnode_read_key() argument
63 tree = node->tree; in hfs_bnode_read_key()
64 if (node->type == HFS_NODE_LEAF || in hfs_bnode_read_key()
66 key_len = hfs_bnode_read_u8(node, off) + 1; 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
77 off += node->page_offset; in hfs_bnode_write()
78 page = node->page[0]; in hfs_bnode_write()
84 void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data) in hfs_bnode_write_u16() argument
88 hfs_bnode_write(node, &v, off, 2); in hfs_bnode_write_u16()
91 void hfs_bnode_write_u8(struct hfs_bnode *node, int off, u8 data) in hfs_bnode_write_u8() argument
94 hfs_bnode_write(node, &data, off, 1); in hfs_bnode_write_u8()
97 void hfs_bnode_clear(struct hfs_bnode *node, int off, int len) in hfs_bnode_clear() argument
101 off += node->page_offset; in hfs_bnode_clear()
102 page = node->page[0]; in hfs_bnode_clear()
125 void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len) in hfs_bnode_move() argument
133 src += node->page_offset; in hfs_bnode_move()
134 dst += node->page_offset; in hfs_bnode_move()
135 page = node->page[0]; in hfs_bnode_move()
142 void hfs_bnode_dump(struct hfs_bnode *node) in hfs_bnode_dump() argument
148 hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this); in hfs_bnode_dump()
149 hfs_bnode_read(node, &desc, 0, sizeof(desc)); in hfs_bnode_dump()
154 off = node->tree->node_size - 2; in hfs_bnode_dump()
156 key_off = hfs_bnode_read_u16(node, off); in hfs_bnode_dump()
158 if (i && node->type == HFS_NODE_INDEX) { in hfs_bnode_dump()
161 if (node->tree->attributes & HFS_TREE_VARIDXKEYS) in hfs_bnode_dump()
162 tmp = (hfs_bnode_read_u8(node, key_off) | 1) + 1; in hfs_bnode_dump()
164 tmp = node->tree->max_key_len + 1; in hfs_bnode_dump()
166 tmp, hfs_bnode_read_u8(node, key_off)); in hfs_bnode_dump()
167 hfs_bnode_read(node, &cnid, key_off + tmp, 4); in hfs_bnode_dump()
169 } else if (i && node->type == HFS_NODE_LEAF) { in hfs_bnode_dump()
172 tmp = hfs_bnode_read_u8(node, key_off); in hfs_bnode_dump()
179 void hfs_bnode_unlink(struct hfs_bnode *node) in hfs_bnode_unlink() argument
185 tree = node->tree; in hfs_bnode_unlink()
186 if (node->prev) { in hfs_bnode_unlink()
187 tmp = hfs_bnode_find(tree, node->prev); in hfs_bnode_unlink()
190 tmp->next = node->next; in hfs_bnode_unlink()
194 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
195 tree->leaf_head = node->next; in hfs_bnode_unlink()
197 if (node->next) { in hfs_bnode_unlink()
198 tmp = hfs_bnode_find(tree, node->next); in hfs_bnode_unlink()
201 tmp->prev = node->prev; in hfs_bnode_unlink()
205 } else if (node->type == HFS_NODE_LEAF) in hfs_bnode_unlink()
206 tree->leaf_tail = node->prev; in hfs_bnode_unlink()
209 if (!node->prev && !node->next) { in hfs_bnode_unlink()
212 if (!node->parent) { in hfs_bnode_unlink()
216 set_bit(HFS_BNODE_DELETED, &node->flags); in hfs_bnode_unlink()
228 struct hfs_bnode *node; in hfs_bnode_findhash() local
235 for (node = tree->node_hash[hfs_bnode_hash(cnid)]; in hfs_bnode_findhash()
236 node; node = node->next_hash) { in hfs_bnode_findhash()
237 if (node->this == cnid) { in hfs_bnode_findhash()
238 return node; in hfs_bnode_findhash()
246 struct hfs_bnode *node, *node2; in __hfs_bnode_create() local
259 node = kzalloc(size, GFP_KERNEL); in __hfs_bnode_create()
260 if (!node) in __hfs_bnode_create()
262 node->tree = tree; in __hfs_bnode_create()
263 node->this = cnid; in __hfs_bnode_create()
264 set_bit(HFS_BNODE_NEW, &node->flags); in __hfs_bnode_create()
265 atomic_set(&node->refcnt, 1); in __hfs_bnode_create()
267 node->tree->cnid, node->this); in __hfs_bnode_create()
268 init_waitqueue_head(&node->lock_wq); in __hfs_bnode_create()
273 node->next_hash = tree->node_hash[hash]; in __hfs_bnode_create()
274 tree->node_hash[hash] = node; in __hfs_bnode_create()
279 kfree(node); in __hfs_bnode_create()
288 node->page_offset = off & ~PAGE_MASK; in __hfs_bnode_create()
293 node->page[i] = page; in __hfs_bnode_create()
296 return node; in __hfs_bnode_create()
298 set_bit(HFS_BNODE_ERROR, &node->flags); in __hfs_bnode_create()
299 return node; in __hfs_bnode_create()
302 void hfs_bnode_unhash(struct hfs_bnode *node) in hfs_bnode_unhash() argument
307 node->tree->cnid, node->this, atomic_read(&node->refcnt)); in hfs_bnode_unhash()
308 for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)]; in hfs_bnode_unhash()
309 *p && *p != node; p = &(*p)->next_hash) in hfs_bnode_unhash()
312 *p = node->next_hash; in hfs_bnode_unhash()
313 node->tree->node_hash_cnt--; in hfs_bnode_unhash()
319 struct hfs_bnode *node; in hfs_bnode_find() local
325 node = hfs_bnode_findhash(tree, num); in hfs_bnode_find()
326 if (node) { in hfs_bnode_find()
327 hfs_bnode_get(node); in hfs_bnode_find()
329 wait_event(node->lock_wq, !test_bit(HFS_BNODE_NEW, &node->flags)); in hfs_bnode_find()
330 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
332 return node; in hfs_bnode_find()
335 node = __hfs_bnode_create(tree, num); in hfs_bnode_find()
336 if (!node) in hfs_bnode_find()
338 if (test_bit(HFS_BNODE_ERROR, &node->flags)) in hfs_bnode_find()
340 if (!test_bit(HFS_BNODE_NEW, &node->flags)) in hfs_bnode_find()
341 return node; in hfs_bnode_find()
343 desc = (struct hfs_bnode_desc *)(kmap_local_page(node->page[0]) + in hfs_bnode_find()
344 node->page_offset); in hfs_bnode_find()
345 node->prev = be32_to_cpu(desc->prev); in hfs_bnode_find()
346 node->next = be32_to_cpu(desc->next); in hfs_bnode_find()
347 node->num_recs = be16_to_cpu(desc->num_recs); in hfs_bnode_find()
348 node->type = desc->type; in hfs_bnode_find()
349 node->height = desc->height; in hfs_bnode_find()
352 switch (node->type) { in hfs_bnode_find()
355 if (node->height != 0) in hfs_bnode_find()
359 if (node->height != 1) in hfs_bnode_find()
363 if (node->height <= 1 || node->height > tree->depth) in hfs_bnode_find()
371 off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
374 for (i = 1; i <= node->num_recs; off = next_off, i++) { in hfs_bnode_find()
376 next_off = hfs_bnode_read_u16(node, rec_off); in hfs_bnode_find()
382 if (node->type != HFS_NODE_INDEX && in hfs_bnode_find()
383 node->type != HFS_NODE_LEAF) in hfs_bnode_find()
385 key_size = hfs_bnode_read_u8(node, off) + 1; in hfs_bnode_find()
389 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
390 wake_up(&node->lock_wq); in hfs_bnode_find()
391 return node; in hfs_bnode_find()
394 set_bit(HFS_BNODE_ERROR, &node->flags); in hfs_bnode_find()
395 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_find()
396 wake_up(&node->lock_wq); in hfs_bnode_find()
397 hfs_bnode_put(node); in hfs_bnode_find()
401 void hfs_bnode_free(struct hfs_bnode *node) in hfs_bnode_free() argument
405 for (i = 0; i < node->tree->pages_per_bnode; i++) in hfs_bnode_free()
406 if (node->page[i]) in hfs_bnode_free()
407 put_page(node->page[i]); in hfs_bnode_free()
408 kfree(node); in hfs_bnode_free()
413 struct hfs_bnode *node; in hfs_bnode_create() local
418 node = hfs_bnode_findhash(tree, num); in hfs_bnode_create()
420 if (node) { in hfs_bnode_create()
423 return node; in hfs_bnode_create()
425 node = __hfs_bnode_create(tree, num); in hfs_bnode_create()
426 if (!node) in hfs_bnode_create()
428 if (test_bit(HFS_BNODE_ERROR, &node->flags)) { in hfs_bnode_create()
429 hfs_bnode_put(node); in hfs_bnode_create()
433 pagep = node->page; in hfs_bnode_create()
434 memzero_page(*pagep, node->page_offset, in hfs_bnode_create()
441 clear_bit(HFS_BNODE_NEW, &node->flags); in hfs_bnode_create()
442 wake_up(&node->lock_wq); in hfs_bnode_create()
444 return node; in hfs_bnode_create()
447 void hfs_bnode_get(struct hfs_bnode *node) in hfs_bnode_get() argument
449 if (node) { in hfs_bnode_get()
450 atomic_inc(&node->refcnt); in hfs_bnode_get()
452 node->tree->cnid, node->this, in hfs_bnode_get()
453 atomic_read(&node->refcnt)); in hfs_bnode_get()
458 void hfs_bnode_put(struct hfs_bnode *node) in hfs_bnode_put() argument
460 if (node) { in hfs_bnode_put()
461 struct hfs_btree *tree = node->tree; in hfs_bnode_put()
465 node->tree->cnid, node->this, in hfs_bnode_put()
466 atomic_read(&node->refcnt)); in hfs_bnode_put()
467 BUG_ON(!atomic_read(&node->refcnt)); in hfs_bnode_put()
468 if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock)) in hfs_bnode_put()
471 if (!node->page[i]) in hfs_bnode_put()
473 mark_page_accessed(node->page[i]); in hfs_bnode_put()
476 if (test_bit(HFS_BNODE_DELETED, &node->flags)) { in hfs_bnode_put()
477 hfs_bnode_unhash(node); in hfs_bnode_put()
479 hfs_bmap_free(node); in hfs_bnode_put()
480 hfs_bnode_free(node); in hfs_bnode_put()