bnode.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /*
  2. * linux/fs/hfsplus/bnode.c
  3. *
  4. * Copyright (C) 2001
  5. * Brad Boyer (flar@allandria.com)
  6. * (C) 2003 Ardis Technologies <roman@ardistech.com>
  7. *
  8. * Handle basic btree node operations
  9. */
  10. #include <linux/string.h>
  11. #include <linux/slab.h>
  12. #include <linux/pagemap.h>
  13. #include <linux/fs.h>
  14. #include <linux/swap.h>
  15. #include "hfsplus_fs.h"
  16. #include "hfsplus_raw.h"
  17. /* Copy a specified range of bytes from the raw data of a node */
  18. void hfs_bnode_read(struct hfs_bnode *node, void *buf, int off, int len)
  19. {
  20. struct page **pagep;
  21. int l;
  22. off += node->page_offset;
  23. pagep = node->page + (off >> PAGE_CACHE_SHIFT);
  24. off &= ~PAGE_CACHE_MASK;
  25. l = min(len, (int)PAGE_CACHE_SIZE - off);
  26. memcpy(buf, kmap(*pagep) + off, l);
  27. kunmap(*pagep);
  28. while ((len -= l) != 0) {
  29. buf += l;
  30. l = min(len, (int)PAGE_CACHE_SIZE);
  31. memcpy(buf, kmap(*++pagep), l);
  32. kunmap(*pagep);
  33. }
  34. }
  35. u16 hfs_bnode_read_u16(struct hfs_bnode *node, int off)
  36. {
  37. __be16 data;
  38. /* TODO: optimize later... */
  39. hfs_bnode_read(node, &data, off, 2);
  40. return be16_to_cpu(data);
  41. }
  42. u8 hfs_bnode_read_u8(struct hfs_bnode *node, int off)
  43. {
  44. u8 data;
  45. /* TODO: optimize later... */
  46. hfs_bnode_read(node, &data, off, 1);
  47. return data;
  48. }
  49. void hfs_bnode_read_key(struct hfs_bnode *node, void *key, int off)
  50. {
  51. struct hfs_btree *tree;
  52. int key_len;
  53. tree = node->tree;
  54. if (node->type == HFS_NODE_LEAF ||
  55. tree->attributes & HFS_TREE_VARIDXKEYS)
  56. key_len = hfs_bnode_read_u16(node, off) + 2;
  57. else
  58. key_len = tree->max_key_len + 2;
  59. hfs_bnode_read(node, key, off, key_len);
  60. }
  61. void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len)
  62. {
  63. struct page **pagep;
  64. int l;
  65. off += node->page_offset;
  66. pagep = node->page + (off >> PAGE_CACHE_SHIFT);
  67. off &= ~PAGE_CACHE_MASK;
  68. l = min(len, (int)PAGE_CACHE_SIZE - off);
  69. memcpy(kmap(*pagep) + off, buf, l);
  70. set_page_dirty(*pagep);
  71. kunmap(*pagep);
  72. while ((len -= l) != 0) {
  73. buf += l;
  74. l = min(len, (int)PAGE_CACHE_SIZE);
  75. memcpy(kmap(*++pagep), buf, l);
  76. set_page_dirty(*pagep);
  77. kunmap(*pagep);
  78. }
  79. }
  80. void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data)
  81. {
  82. __be16 v = cpu_to_be16(data);
  83. /* TODO: optimize later... */
  84. hfs_bnode_write(node, &v, off, 2);
  85. }
  86. void hfs_bnode_clear(struct hfs_bnode *node, int off, int len)
  87. {
  88. struct page **pagep;
  89. int l;
  90. off += node->page_offset;
  91. pagep = node->page + (off >> PAGE_CACHE_SHIFT);
  92. off &= ~PAGE_CACHE_MASK;
  93. l = min(len, (int)PAGE_CACHE_SIZE - off);
  94. memset(kmap(*pagep) + off, 0, l);
  95. set_page_dirty(*pagep);
  96. kunmap(*pagep);
  97. while ((len -= l) != 0) {
  98. l = min(len, (int)PAGE_CACHE_SIZE);
  99. memset(kmap(*++pagep), 0, l);
  100. set_page_dirty(*pagep);
  101. kunmap(*pagep);
  102. }
  103. }
  104. void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst,
  105. struct hfs_bnode *src_node, int src, int len)
  106. {
  107. struct hfs_btree *tree;
  108. struct page **src_page, **dst_page;
  109. int l;
  110. dprint(DBG_BNODE_MOD, "copybytes: %u,%u,%u\n", dst, src, len);
  111. if (!len)
  112. return;
  113. tree = src_node->tree;
  114. src += src_node->page_offset;
  115. dst += dst_node->page_offset;
  116. src_page = src_node->page + (src >> PAGE_CACHE_SHIFT);
  117. src &= ~PAGE_CACHE_MASK;
  118. dst_page = dst_node->page + (dst >> PAGE_CACHE_SHIFT);
  119. dst &= ~PAGE_CACHE_MASK;
  120. if (src == dst) {
  121. l = min(len, (int)PAGE_CACHE_SIZE - src);
  122. memcpy(kmap(*dst_page) + src, kmap(*src_page) + src, l);
  123. kunmap(*src_page);
  124. set_page_dirty(*dst_page);
  125. kunmap(*dst_page);
  126. while ((len -= l) != 0) {
  127. l = min(len, (int)PAGE_CACHE_SIZE);
  128. memcpy(kmap(*++dst_page), kmap(*++src_page), l);
  129. kunmap(*src_page);
  130. set_page_dirty(*dst_page);
  131. kunmap(*dst_page);
  132. }
  133. } else {
  134. void *src_ptr, *dst_ptr;
  135. do {
  136. src_ptr = kmap(*src_page) + src;
  137. dst_ptr = kmap(*dst_page) + dst;
  138. if (PAGE_CACHE_SIZE - src < PAGE_CACHE_SIZE - dst) {
  139. l = PAGE_CACHE_SIZE - src;
  140. src = 0;
  141. dst += l;
  142. } else {
  143. l = PAGE_CACHE_SIZE - dst;
  144. src += l;
  145. dst = 0;
  146. }
  147. l = min(len, l);
  148. memcpy(dst_ptr, src_ptr, l);
  149. kunmap(*src_page);
  150. set_page_dirty(*dst_page);
  151. kunmap(*dst_page);
  152. if (!dst)
  153. dst_page++;
  154. else
  155. src_page++;
  156. } while ((len -= l));
  157. }
  158. }
  159. void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len)
  160. {
  161. struct page **src_page, **dst_page;
  162. int l;
  163. dprint(DBG_BNODE_MOD, "movebytes: %u,%u,%u\n", dst, src, len);
  164. if (!len)
  165. return;
  166. src += node->page_offset;
  167. dst += node->page_offset;
  168. if (dst > src) {
  169. src += len - 1;
  170. src_page = node->page + (src >> PAGE_CACHE_SHIFT);
  171. src = (src & ~PAGE_CACHE_MASK) + 1;
  172. dst += len - 1;
  173. dst_page = node->page + (dst >> PAGE_CACHE_SHIFT);
  174. dst = (dst & ~PAGE_CACHE_MASK) + 1;
  175. if (src == dst) {
  176. while (src < len) {
  177. memmove(kmap(*dst_page), kmap(*src_page), src);
  178. kunmap(*src_page);
  179. set_page_dirty(*dst_page);
  180. kunmap(*dst_page);
  181. len -= src;
  182. src = PAGE_CACHE_SIZE;
  183. src_page--;
  184. dst_page--;
  185. }
  186. src -= len;
  187. memmove(kmap(*dst_page) + src,
  188. kmap(*src_page) + src, len);
  189. kunmap(*src_page);
  190. set_page_dirty(*dst_page);
  191. kunmap(*dst_page);
  192. } else {
  193. void *src_ptr, *dst_ptr;
  194. do {
  195. src_ptr = kmap(*src_page) + src;
  196. dst_ptr = kmap(*dst_page) + dst;
  197. if (src < dst) {
  198. l = src;
  199. src = PAGE_CACHE_SIZE;
  200. dst -= l;
  201. } else {
  202. l = dst;
  203. src -= l;
  204. dst = PAGE_CACHE_SIZE;
  205. }
  206. l = min(len, l);
  207. memmove(dst_ptr - l, src_ptr - l, l);
  208. kunmap(*src_page);
  209. set_page_dirty(*dst_page);
  210. kunmap(*dst_page);
  211. if (dst == PAGE_CACHE_SIZE)
  212. dst_page--;
  213. else
  214. src_page--;
  215. } while ((len -= l));
  216. }
  217. } else {
  218. src_page = node->page + (src >> PAGE_CACHE_SHIFT);
  219. src &= ~PAGE_CACHE_MASK;
  220. dst_page = node->page + (dst >> PAGE_CACHE_SHIFT);
  221. dst &= ~PAGE_CACHE_MASK;
  222. if (src == dst) {
  223. l = min(len, (int)PAGE_CACHE_SIZE - src);
  224. memmove(kmap(*dst_page) + src,
  225. kmap(*src_page) + src, l);
  226. kunmap(*src_page);
  227. set_page_dirty(*dst_page);
  228. kunmap(*dst_page);
  229. while ((len -= l) != 0) {
  230. l = min(len, (int)PAGE_CACHE_SIZE);
  231. memmove(kmap(*++dst_page),
  232. kmap(*++src_page), l);
  233. kunmap(*src_page);
  234. set_page_dirty(*dst_page);
  235. kunmap(*dst_page);
  236. }
  237. } else {
  238. void *src_ptr, *dst_ptr;
  239. do {
  240. src_ptr = kmap(*src_page) + src;
  241. dst_ptr = kmap(*dst_page) + dst;
  242. if (PAGE_CACHE_SIZE - src <
  243. PAGE_CACHE_SIZE - dst) {
  244. l = PAGE_CACHE_SIZE - src;
  245. src = 0;
  246. dst += l;
  247. } else {
  248. l = PAGE_CACHE_SIZE - dst;
  249. src += l;
  250. dst = 0;
  251. }
  252. l = min(len, l);
  253. memmove(dst_ptr, src_ptr, l);
  254. kunmap(*src_page);
  255. set_page_dirty(*dst_page);
  256. kunmap(*dst_page);
  257. if (!dst)
  258. dst_page++;
  259. else
  260. src_page++;
  261. } while ((len -= l));
  262. }
  263. }
  264. }
  265. void hfs_bnode_dump(struct hfs_bnode *node)
  266. {
  267. struct hfs_bnode_desc desc;
  268. __be32 cnid;
  269. int i, off, key_off;
  270. dprint(DBG_BNODE_MOD, "bnode: %d\n", node->this);
  271. hfs_bnode_read(node, &desc, 0, sizeof(desc));
  272. dprint(DBG_BNODE_MOD, "%d, %d, %d, %d, %d\n",
  273. be32_to_cpu(desc.next), be32_to_cpu(desc.prev),
  274. desc.type, desc.height, be16_to_cpu(desc.num_recs));
  275. off = node->tree->node_size - 2;
  276. for (i = be16_to_cpu(desc.num_recs); i >= 0; off -= 2, i--) {
  277. key_off = hfs_bnode_read_u16(node, off);
  278. dprint(DBG_BNODE_MOD, " %d", key_off);
  279. if (i && node->type == HFS_NODE_INDEX) {
  280. int tmp;
  281. if (node->tree->attributes & HFS_TREE_VARIDXKEYS)
  282. tmp = hfs_bnode_read_u16(node, key_off) + 2;
  283. else
  284. tmp = node->tree->max_key_len + 2;
  285. dprint(DBG_BNODE_MOD, " (%d", tmp);
  286. hfs_bnode_read(node, &cnid, key_off + tmp, 4);
  287. dprint(DBG_BNODE_MOD, ",%d)", be32_to_cpu(cnid));
  288. } else if (i && node->type == HFS_NODE_LEAF) {
  289. int tmp;
  290. tmp = hfs_bnode_read_u16(node, key_off);
  291. dprint(DBG_BNODE_MOD, " (%d)", tmp);
  292. }
  293. }
  294. dprint(DBG_BNODE_MOD, "\n");
  295. }
  296. void hfs_bnode_unlink(struct hfs_bnode *node)
  297. {
  298. struct hfs_btree *tree;
  299. struct hfs_bnode *tmp;
  300. __be32 cnid;
  301. tree = node->tree;
  302. if (node->prev) {
  303. tmp = hfs_bnode_find(tree, node->prev);
  304. if (IS_ERR(tmp))
  305. return;
  306. tmp->next = node->next;
  307. cnid = cpu_to_be32(tmp->next);
  308. hfs_bnode_write(tmp, &cnid,
  309. offsetof(struct hfs_bnode_desc, next), 4);
  310. hfs_bnode_put(tmp);
  311. } else if (node->type == HFS_NODE_LEAF)
  312. tree->leaf_head = node->next;
  313. if (node->next) {
  314. tmp = hfs_bnode_find(tree, node->next);
  315. if (IS_ERR(tmp))
  316. return;
  317. tmp->prev = node->prev;
  318. cnid = cpu_to_be32(tmp->prev);
  319. hfs_bnode_write(tmp, &cnid,
  320. offsetof(struct hfs_bnode_desc, prev), 4);
  321. hfs_bnode_put(tmp);
  322. } else if (node->type == HFS_NODE_LEAF)
  323. tree->leaf_tail = node->prev;
  324. /* move down? */
  325. if (!node->prev && !node->next)
  326. dprint(DBG_BNODE_MOD, "hfs_btree_del_level\n");
  327. if (!node->parent) {
  328. tree->root = 0;
  329. tree->depth = 0;
  330. }
  331. set_bit(HFS_BNODE_DELETED, &node->flags);
  332. }
  333. static inline int hfs_bnode_hash(u32 num)
  334. {
  335. num = (num >> 16) + num;
  336. num += num >> 8;
  337. return num & (NODE_HASH_SIZE - 1);
  338. }
  339. struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid)
  340. {
  341. struct hfs_bnode *node;
  342. if (cnid >= tree->node_count) {
  343. printk(KERN_ERR "hfs: request for non-existent node "
  344. "%d in B*Tree\n",
  345. cnid);
  346. return NULL;
  347. }
  348. for (node = tree->node_hash[hfs_bnode_hash(cnid)];
  349. node; node = node->next_hash)
  350. if (node->this == cnid)
  351. return node;
  352. return NULL;
  353. }
  354. static struct hfs_bnode *__hfs_bnode_create(struct hfs_btree *tree, u32 cnid)
  355. {
  356. struct super_block *sb;
  357. struct hfs_bnode *node, *node2;
  358. struct address_space *mapping;
  359. struct page *page;
  360. int size, block, i, hash;
  361. loff_t off;
  362. if (cnid >= tree->node_count) {
  363. printk(KERN_ERR "hfs: request for non-existent node "
  364. "%d in B*Tree\n",
  365. cnid);
  366. return NULL;
  367. }
  368. sb = tree->inode->i_sb;
  369. size = sizeof(struct hfs_bnode) + tree->pages_per_bnode *
  370. sizeof(struct page *);
  371. node = kzalloc(size, GFP_KERNEL);
  372. if (!node)
  373. return NULL;
  374. node->tree = tree;
  375. node->this = cnid;
  376. set_bit(HFS_BNODE_NEW, &node->flags);
  377. atomic_set(&node->refcnt, 1);
  378. dprint(DBG_BNODE_REFS, "new_node(%d:%d): 1\n",
  379. node->tree->cnid, node->this);
  380. init_waitqueue_head(&node->lock_wq);
  381. spin_lock(&tree->hash_lock);
  382. node2 = hfs_bnode_findhash(tree, cnid);
  383. if (!node2) {
  384. hash = hfs_bnode_hash(cnid);
  385. node->next_hash = tree->node_hash[hash];
  386. tree->node_hash[hash] = node;
  387. tree->node_hash_cnt++;
  388. } else {
  389. spin_unlock(&tree->hash_lock);
  390. kfree(node);
  391. wait_event(node2->lock_wq,
  392. !test_bit(HFS_BNODE_NEW, &node2->flags));
  393. return node2;
  394. }
  395. spin_unlock(&tree->hash_lock);
  396. mapping = tree->inode->i_mapping;
  397. off = (loff_t)cnid << tree->node_size_shift;
  398. block = off >> PAGE_CACHE_SHIFT;
  399. node->page_offset = off & ~PAGE_CACHE_MASK;
  400. for (i = 0; i < tree->pages_per_bnode; block++, i++) {
  401. page = read_mapping_page(mapping, block, NULL);
  402. if (IS_ERR(page))
  403. goto fail;
  404. if (PageError(page)) {
  405. page_cache_release(page);
  406. goto fail;
  407. }
  408. node->page[i] = page;
  409. }
  410. return node;
  411. fail:
  412. set_bit(HFS_BNODE_ERROR, &node->flags);
  413. return node;
  414. }
  415. void hfs_bnode_unhash(struct hfs_bnode *node)
  416. {
  417. struct hfs_bnode **p;
  418. dprint(DBG_BNODE_REFS, "remove_node(%d:%d): %d\n",
  419. node->tree->cnid, node->this, atomic_read(&node->refcnt));
  420. for (p = &node->tree->node_hash[hfs_bnode_hash(node->this)];
  421. *p && *p != node; p = &(*p)->next_hash)
  422. ;
  423. BUG_ON(!*p);
  424. *p = node->next_hash;
  425. node->tree->node_hash_cnt--;
  426. }
  427. /* Load a particular node out of a tree */
  428. struct hfs_bnode *hfs_bnode_find(struct hfs_btree *tree, u32 num)
  429. {
  430. struct hfs_bnode *node;
  431. struct hfs_bnode_desc *desc;
  432. int i, rec_off, off, next_off;
  433. int entry_size, key_size;
  434. spin_lock(&tree->hash_lock);
  435. node = hfs_bnode_findhash(tree, num);
  436. if (node) {
  437. hfs_bnode_get(node);
  438. spin_unlock(&tree->hash_lock);
  439. wait_event(node->lock_wq,
  440. !test_bit(HFS_BNODE_NEW, &node->flags));
  441. if (test_bit(HFS_BNODE_ERROR, &node->flags))
  442. goto node_error;
  443. return node;
  444. }
  445. spin_unlock(&tree->hash_lock);
  446. node = __hfs_bnode_create(tree, num);
  447. if (!node)
  448. return ERR_PTR(-ENOMEM);
  449. if (test_bit(HFS_BNODE_ERROR, &node->flags))
  450. goto node_error;
  451. if (!test_bit(HFS_BNODE_NEW, &node->flags))
  452. return node;
  453. desc = (struct hfs_bnode_desc *)(kmap(node->page[0]) +
  454. node->page_offset);
  455. node->prev = be32_to_cpu(desc->prev);
  456. node->next = be32_to_cpu(desc->next);
  457. node->num_recs = be16_to_cpu(desc->num_recs);
  458. node->type = desc->type;
  459. node->height = desc->height;
  460. kunmap(node->page[0]);
  461. switch (node->type) {
  462. case HFS_NODE_HEADER:
  463. case HFS_NODE_MAP:
  464. if (node->height != 0)
  465. goto node_error;
  466. break;
  467. case HFS_NODE_LEAF:
  468. if (node->height != 1)
  469. goto node_error;
  470. break;
  471. case HFS_NODE_INDEX:
  472. if (node->height <= 1 || node->height > tree->depth)
  473. goto node_error;
  474. break;
  475. default:
  476. goto node_error;
  477. }
  478. rec_off = tree->node_size - 2;
  479. off = hfs_bnode_read_u16(node, rec_off);
  480. if (off != sizeof(struct hfs_bnode_desc))
  481. goto node_error;
  482. for (i = 1; i <= node->num_recs; off = next_off, i++) {
  483. rec_off -= 2;
  484. next_off = hfs_bnode_read_u16(node, rec_off);
  485. if (next_off <= off ||
  486. next_off > tree->node_size ||
  487. next_off & 1)
  488. goto node_error;
  489. entry_size = next_off - off;
  490. if (node->type != HFS_NODE_INDEX &&
  491. node->type != HFS_NODE_LEAF)
  492. continue;
  493. key_size = hfs_bnode_read_u16(node, off) + 2;
  494. if (key_size >= entry_size || key_size & 1)
  495. goto node_error;
  496. }
  497. clear_bit(HFS_BNODE_NEW, &node->flags);
  498. wake_up(&node->lock_wq);
  499. return node;
  500. node_error:
  501. set_bit(HFS_BNODE_ERROR, &node->flags);
  502. clear_bit(HFS_BNODE_NEW, &node->flags);
  503. wake_up(&node->lock_wq);
  504. hfs_bnode_put(node);
  505. return ERR_PTR(-EIO);
  506. }
  507. void hfs_bnode_free(struct hfs_bnode *node)
  508. {
  509. int i;
  510. for (i = 0; i < node->tree->pages_per_bnode; i++)
  511. if (node->page[i])
  512. page_cache_release(node->page[i]);
  513. kfree(node);
  514. }
  515. struct hfs_bnode *hfs_bnode_create(struct hfs_btree *tree, u32 num)
  516. {
  517. struct hfs_bnode *node;
  518. struct page **pagep;
  519. int i;
  520. spin_lock(&tree->hash_lock);
  521. node = hfs_bnode_findhash(tree, num);
  522. spin_unlock(&tree->hash_lock);
  523. if (node) {
  524. printk(KERN_CRIT "new node %u already hashed?\n", num);
  525. WARN_ON(1);
  526. return node;
  527. }
  528. node = __hfs_bnode_create(tree, num);
  529. if (!node)
  530. return ERR_PTR(-ENOMEM);
  531. if (test_bit(HFS_BNODE_ERROR, &node->flags)) {
  532. hfs_bnode_put(node);
  533. return ERR_PTR(-EIO);
  534. }
  535. pagep = node->page;
  536. memset(kmap(*pagep) + node->page_offset, 0,
  537. min((int)PAGE_CACHE_SIZE, (int)tree->node_size));
  538. set_page_dirty(*pagep);
  539. kunmap(*pagep);
  540. for (i = 1; i < tree->pages_per_bnode; i++) {
  541. memset(kmap(*++pagep), 0, PAGE_CACHE_SIZE);
  542. set_page_dirty(*pagep);
  543. kunmap(*pagep);
  544. }
  545. clear_bit(HFS_BNODE_NEW, &node->flags);
  546. wake_up(&node->lock_wq);
  547. return node;
  548. }
  549. void hfs_bnode_get(struct hfs_bnode *node)
  550. {
  551. if (node) {
  552. atomic_inc(&node->refcnt);
  553. dprint(DBG_BNODE_REFS, "get_node(%d:%d): %d\n",
  554. node->tree->cnid, node->this,
  555. atomic_read(&node->refcnt));
  556. }
  557. }
  558. /* Dispose of resources used by a node */
  559. void hfs_bnode_put(struct hfs_bnode *node)
  560. {
  561. if (node) {
  562. struct hfs_btree *tree = node->tree;
  563. int i;
  564. dprint(DBG_BNODE_REFS, "put_node(%d:%d): %d\n",
  565. node->tree->cnid, node->this,
  566. atomic_read(&node->refcnt));
  567. BUG_ON(!atomic_read(&node->refcnt));
  568. if (!atomic_dec_and_lock(&node->refcnt, &tree->hash_lock))
  569. return;
  570. for (i = 0; i < tree->pages_per_bnode; i++) {
  571. if (!node->page[i])
  572. continue;
  573. mark_page_accessed(node->page[i]);
  574. }
  575. if (test_bit(HFS_BNODE_DELETED, &node->flags)) {
  576. hfs_bnode_unhash(node);
  577. spin_unlock(&tree->hash_lock);
  578. hfs_bmap_free(node);
  579. hfs_bnode_free(node);
  580. return;
  581. }
  582. spin_unlock(&tree->hash_lock);
  583. }
  584. }