bnode.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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_SHIFT);
  24. off &= ~PAGE_MASK;
  25. l = min_t(int, len, PAGE_SIZE - off);
  26. memcpy(buf, kmap(*pagep) + off, l);
  27. kunmap(*pagep);
  28. while ((len -= l) != 0) {
  29. buf += l;
  30. l = min_t(int, len, PAGE_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. node->tree->cnid == HFSPLUS_ATTR_CNID)
  57. key_len = hfs_bnode_read_u16(node, off) + 2;
  58. else
  59. key_len = tree->max_key_len + 2;
  60. hfs_bnode_read(node, key, off, key_len);
  61. }
  62. void hfs_bnode_write(struct hfs_bnode *node, void *buf, int off, int len)
  63. {
  64. struct page **pagep;
  65. int l;
  66. off += node->page_offset;
  67. pagep = node->page + (off >> PAGE_SHIFT);
  68. off &= ~PAGE_MASK;
  69. l = min_t(int, len, PAGE_SIZE - off);
  70. memcpy(kmap(*pagep) + off, buf, l);
  71. set_page_dirty(*pagep);
  72. kunmap(*pagep);
  73. while ((len -= l) != 0) {
  74. buf += l;
  75. l = min_t(int, len, PAGE_SIZE);
  76. memcpy(kmap(*++pagep), buf, l);
  77. set_page_dirty(*pagep);
  78. kunmap(*pagep);
  79. }
  80. }
  81. void hfs_bnode_write_u16(struct hfs_bnode *node, int off, u16 data)
  82. {
  83. __be16 v = cpu_to_be16(data);
  84. /* TODO: optimize later... */
  85. hfs_bnode_write(node, &v, off, 2);
  86. }
  87. void hfs_bnode_clear(struct hfs_bnode *node, int off, int len)
  88. {
  89. struct page **pagep;
  90. int l;
  91. off += node->page_offset;
  92. pagep = node->page + (off >> PAGE_SHIFT);
  93. off &= ~PAGE_MASK;
  94. l = min_t(int, len, PAGE_SIZE - off);
  95. memset(kmap(*pagep) + off, 0, l);
  96. set_page_dirty(*pagep);
  97. kunmap(*pagep);
  98. while ((len -= l) != 0) {
  99. l = min_t(int, len, PAGE_SIZE);
  100. memset(kmap(*++pagep), 0, l);
  101. set_page_dirty(*pagep);
  102. kunmap(*pagep);
  103. }
  104. }
  105. void hfs_bnode_copy(struct hfs_bnode *dst_node, int dst,
  106. struct hfs_bnode *src_node, int src, int len)
  107. {
  108. struct hfs_btree *tree;
  109. struct page **src_page, **dst_page;
  110. int l;
  111. hfs_dbg(BNODE_MOD, "copybytes: %u,%u,%u\n", dst, src, len);
  112. if (!len)
  113. return;
  114. tree = src_node->tree;
  115. src += src_node->page_offset;
  116. dst += dst_node->page_offset;
  117. src_page = src_node->page + (src >> PAGE_SHIFT);
  118. src &= ~PAGE_MASK;
  119. dst_page = dst_node->page + (dst >> PAGE_SHIFT);
  120. dst &= ~PAGE_MASK;
  121. if (src == dst) {
  122. l = min_t(int, len, PAGE_SIZE - src);
  123. memcpy(kmap(*dst_page) + src, kmap(*src_page) + src, l);
  124. kunmap(*src_page);
  125. set_page_dirty(*dst_page);
  126. kunmap(*dst_page);
  127. while ((len -= l) != 0) {
  128. l = min_t(int, len, PAGE_SIZE);
  129. memcpy(kmap(*++dst_page), kmap(*++src_page), l);
  130. kunmap(*src_page);
  131. set_page_dirty(*dst_page);
  132. kunmap(*dst_page);
  133. }
  134. } else {
  135. void *src_ptr, *dst_ptr;
  136. do {
  137. src_ptr = kmap(*src_page) + src;
  138. dst_ptr = kmap(*dst_page) + dst;
  139. if (PAGE_SIZE - src < PAGE_SIZE - dst) {
  140. l = PAGE_SIZE - src;
  141. src = 0;
  142. dst += l;
  143. } else {
  144. l = PAGE_SIZE - dst;
  145. src += l;
  146. dst = 0;
  147. }
  148. l = min(len, l);
  149. memcpy(dst_ptr, src_ptr, l);
  150. kunmap(*src_page);
  151. set_page_dirty(*dst_page);
  152. kunmap(*dst_page);
  153. if (!dst)
  154. dst_page++;
  155. else
  156. src_page++;
  157. } while ((len -= l));
  158. }
  159. }
  160. void hfs_bnode_move(struct hfs_bnode *node, int dst, int src, int len)
  161. {
  162. struct page **src_page, **dst_page;
  163. int l;
  164. hfs_dbg(BNODE_MOD, "movebytes: %u,%u,%u\n", dst, src, len);
  165. if (!len)
  166. return;
  167. src += node->page_offset;
  168. dst += node->page_offset;
  169. if (dst > src) {
  170. src += len - 1;
  171. src_page = node->page + (src >> PAGE_SHIFT);
  172. src = (src & ~PAGE_MASK) + 1;
  173. dst += len - 1;
  174. dst_page = node->page + (dst >> PAGE_SHIFT);
  175. dst = (dst & ~PAGE_MASK) + 1;
  176. if (src == dst) {
  177. while (src < len) {
  178. memmove(kmap(*dst_page), kmap(*src_page), src);
  179. kunmap(*src_page);
  180. set_page_dirty(*dst_page);
  181. kunmap(*dst_page);
  182. len -= src;
  183. src = PAGE_SIZE;
  184. src_page--;
  185. dst_page--;
  186. }
  187. src -= len;
  188. memmove(kmap(*dst_page) + src,
  189. kmap(*src_page) + src, len);
  190. kunmap(*src_page);
  191. set_page_dirty(*dst_page);
  192. kunmap(*dst_page);
  193. } else {
  194. void *src_ptr, *dst_ptr;
  195. do {
  196. src_ptr = kmap(*src_page) + src;
  197. dst_ptr = kmap(*dst_page) + dst;
  198. if (src < dst) {
  199. l = src;
  200. src = PAGE_SIZE;
  201. dst -= l;
  202. } else {
  203. l = dst;
  204. src -= l;
  205. dst = PAGE_SIZE;
  206. }
  207. l = min(len, l);
  208. memmove(dst_ptr - l, src_ptr - l, l);
  209. kunmap(*src_page);
  210. set_page_dirty(*dst_page);
  211. kunmap(*dst_page);
  212. if (dst == PAGE_SIZE)
  213. dst_page--;
  214. else
  215. src_page--;
  216. } while ((len -= l));
  217. }
  218. } else {
  219. src_page = node->page + (src >> PAGE_SHIFT);
  220. src &= ~PAGE_MASK;
  221. dst_page = node->page + (dst >> PAGE_SHIFT);
  222. dst &= ~PAGE_MASK;
  223. if (src == dst) {
  224. l = min_t(int, len, PAGE_SIZE - src);
  225. memmove(kmap(*dst_page) + src,
  226. kmap(*src_page) + src, l);
  227. kunmap(*src_page);
  228. set_page_dirty(*dst_page);
  229. kunmap(*dst_page);
  230. while ((len -= l) != 0) {
  231. l = min_t(int, len, PAGE_SIZE);
  232. memmove(kmap(*++dst_page),
  233. kmap(*++src_page), l);
  234. kunmap(*src_page);
  235. set_page_dirty(*dst_page);
  236. kunmap(*dst_page);
  237. }
  238. } else {
  239. void *src_ptr, *dst_ptr;
  240. do {
  241. src_ptr = kmap(*src_page) + src;
  242. dst_ptr = kmap(*dst_page) + dst;
  243. if (PAGE_SIZE - src <
  244. PAGE_SIZE - dst) {
  245. l = PAGE_SIZE - src;
  246. src = 0;
  247. dst += l;
  248. } else {
  249. l = PAGE_SIZE - dst;
  250. src += l;
  251. dst = 0;
  252. }
  253. l = min(len, l);
  254. memmove(dst_ptr, src_ptr, l);
  255. kunmap(*src_page);
  256. set_page_dirty(*dst_page);
  257. kunmap(*dst_page);
  258. if (!dst)
  259. dst_page++;
  260. else
  261. src_page++;
  262. } while ((len -= l));
  263. }
  264. }
  265. }
  266. void hfs_bnode_dump(struct hfs_bnode *node)
  267. {
  268. struct hfs_bnode_desc desc;
  269. __be32 cnid;
  270. int i, off, key_off;
  271. hfs_dbg(BNODE_MOD, "bnode: %d\n", node->this);
  272. hfs_bnode_read(node, &desc, 0, sizeof(desc));
  273. hfs_dbg(BNODE_MOD, "%d, %d, %d, %d, %d\n",
  274. be32_to_cpu(desc.next), be32_to_cpu(desc.prev),
  275. desc.type, desc.height, be16_to_cpu(desc.num_recs));
  276. off = node->tree->node_size - 2;
  277. for (i = be16_to_cpu(desc.num_recs); i >= 0; off -= 2, i--) {
  278. key_off = hfs_bnode_read_u16(node, off);
  279. hfs_dbg(BNODE_MOD, " %d", key_off);
  280. if (i && node->type == HFS_NODE_INDEX) {
  281. int tmp;
  282. if (node->tree->attributes & HFS_TREE_VARIDXKEYS ||
  283. node->tree->cnid == HFSPLUS_ATTR_CNID)
  284. tmp = hfs_bnode_read_u16(node, key_off) + 2;
  285. else
  286. tmp = node->tree->max_key_len + 2;
  287. hfs_dbg_cont(BNODE_MOD, " (%d", tmp);
  288. hfs_bnode_read(node, &cnid, key_off + tmp, 4);
  289. hfs_dbg_cont(BNODE_MOD, ",%d)", be32_to_cpu(cnid));
  290. } else if (i && node->type == HFS_NODE_LEAF) {
  291. int tmp;
  292. tmp = hfs_bnode_read_u16(node, key_off);
  293. hfs_dbg_cont(BNODE_MOD, " (%d)", tmp);
  294. }
  295. }
  296. hfs_dbg_cont(BNODE_MOD, "\n");
  297. }
  298. void hfs_bnode_unlink(struct hfs_bnode *node)
  299. {
  300. struct hfs_btree *tree;
  301. struct hfs_bnode *tmp;
  302. __be32 cnid;
  303. tree = node->tree;
  304. if (node->prev) {
  305. tmp = hfs_bnode_find(tree, node->prev);
  306. if (IS_ERR(tmp))
  307. return;
  308. tmp->next = node->next;
  309. cnid = cpu_to_be32(tmp->next);
  310. hfs_bnode_write(tmp, &cnid,
  311. offsetof(struct hfs_bnode_desc, next), 4);
  312. hfs_bnode_put(tmp);
  313. } else if (node->type == HFS_NODE_LEAF)
  314. tree->leaf_head = node->next;
  315. if (node->next) {
  316. tmp = hfs_bnode_find(tree, node->next);
  317. if (IS_ERR(tmp))
  318. return;
  319. tmp->prev = node->prev;
  320. cnid = cpu_to_be32(tmp->prev);
  321. hfs_bnode_write(tmp, &cnid,
  322. offsetof(struct hfs_bnode_desc, prev), 4);
  323. hfs_bnode_put(tmp);
  324. } else if (node->type == HFS_NODE_LEAF)
  325. tree->leaf_tail = node->prev;
  326. /* move down? */
  327. if (!node->prev && !node->next)
  328. hfs_dbg(BNODE_MOD, "hfs_btree_del_level\n");
  329. if (!node->parent) {
  330. tree->root = 0;
  331. tree->depth = 0;
  332. }
  333. set_bit(HFS_BNODE_DELETED, &node->flags);
  334. }
  335. static inline int hfs_bnode_hash(u32 num)
  336. {
  337. num = (num >> 16) + num;
  338. num += num >> 8;
  339. return num & (NODE_HASH_SIZE - 1);
  340. }
  341. struct hfs_bnode *hfs_bnode_findhash(struct hfs_btree *tree, u32 cnid)
  342. {
  343. struct hfs_bnode *node;
  344. if (cnid >= tree->node_count) {
  345. pr_err("request for non-existent node %d in B*Tree\n",
  346. cnid);
  347. return NULL;
  348. }
  349. for (node = tree->node_hash[hfs_bnode_hash(cnid)];
  350. node; node = node->next_hash)
  351. if (node->this == cnid)
  352. return node;
  353. return NULL;
  354. }
  355. static struct hfs_bnode *__hfs_bnode_create(struct hfs_btree *tree, u32 cnid)
  356. {
  357. struct super_block *sb;
  358. struct hfs_bnode *node, *node2;
  359. struct address_space *mapping;
  360. struct page *page;
  361. int size, block, i, hash;
  362. loff_t off;
  363. if (cnid >= tree->node_count) {
  364. pr_err("request for non-existent node %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. hfs_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_SHIFT;
  399. node->page_offset = off & ~PAGE_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. put_page(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. hfs_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. put_page(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. pr_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_t(int, PAGE_SIZE, 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_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. hfs_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. hfs_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. if (hfs_bnode_need_zeroout(tree))
  579. hfs_bnode_clear(node, 0, tree->node_size);
  580. hfs_bmap_free(node);
  581. hfs_bnode_free(node);
  582. return;
  583. }
  584. spin_unlock(&tree->hash_lock);
  585. }
  586. }
  587. /*
  588. * Unused nodes have to be zeroed if this is the catalog tree and
  589. * a corresponding flag in the volume header is set.
  590. */
  591. bool hfs_bnode_need_zeroout(struct hfs_btree *tree)
  592. {
  593. struct super_block *sb = tree->inode->i_sb;
  594. struct hfsplus_sb_info *sbi = HFSPLUS_SB(sb);
  595. const u32 volume_attr = be32_to_cpu(sbi->s_vhdr->attributes);
  596. return tree->cnid == HFSPLUS_CAT_CNID &&
  597. volume_attr & HFSPLUS_VOL_UNUSED_NODE_FIX;
  598. }