Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * linux/fs/hfs/btree.c |
| 4 | * |
| 5 | * Copyright (C) 2001 |
| 6 | * Brad Boyer (flar@allandria.com) |
| 7 | * (C) 2003 Ardis Technologies <roman@ardistech.com> |
| 8 | * |
| 9 | * Handle opening/closing btree |
| 10 | */ |
| 11 | |
| 12 | #include <linux/pagemap.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 13 | #include <linux/slab.h> |
Vignesh Babu BM | e1b5c1d | 2007-05-08 00:24:30 -0700 | [diff] [blame] | 14 | #include <linux/log2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 16 | #include "btree.h" |
| 17 | |
| 18 | /* Get a reference to a B*Tree and do some initial checks */ |
| 19 | struct hfs_btree *hfs_btree_open(struct super_block *sb, u32 id, btree_keycmp keycmp) |
| 20 | { |
| 21 | struct hfs_btree *tree; |
| 22 | struct hfs_btree_header_rec *head; |
| 23 | struct address_space *mapping; |
| 24 | struct page *page; |
| 25 | unsigned int size; |
| 26 | |
Panagiotis Issaris | f8314dc | 2006-09-27 01:49:37 -0700 | [diff] [blame] | 27 | tree = kzalloc(sizeof(*tree), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | if (!tree) |
| 29 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
Thomas Gleixner | 4a94103 | 2010-09-07 14:33:08 +0000 | [diff] [blame] | 31 | mutex_init(&tree->tree_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | spin_lock_init(&tree->hash_lock); |
| 33 | /* Set the correct compare function */ |
| 34 | tree->sb = sb; |
| 35 | tree->cnid = id; |
| 36 | tree->keycmp = keycmp; |
| 37 | |
| 38 | tree->inode = iget_locked(sb, id); |
| 39 | if (!tree->inode) |
| 40 | goto free_tree; |
Eric Sesterhenn | 4d4ef9a | 2006-03-26 18:26:51 +0200 | [diff] [blame] | 41 | BUG_ON(!(tree->inode->i_state & I_NEW)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
| 43 | struct hfs_mdb *mdb = HFS_SB(sb)->mdb; |
| 44 | HFS_I(tree->inode)->flags = 0; |
Matthias Kaehlcke | 39f8d47 | 2008-07-25 01:46:35 -0700 | [diff] [blame] | 45 | mutex_init(&HFS_I(tree->inode)->extents_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | switch (id) { |
| 47 | case HFS_EXT_CNID: |
| 48 | hfs_inode_read_fork(tree->inode, mdb->drXTExtRec, mdb->drXTFlSize, |
| 49 | mdb->drXTFlSize, be32_to_cpu(mdb->drXTClpSiz)); |
Phillip Lougher | 434a964 | 2011-11-02 13:38:01 -0700 | [diff] [blame] | 50 | if (HFS_I(tree->inode)->alloc_blocks > |
| 51 | HFS_I(tree->inode)->first_blocks) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 52 | pr_err("invalid btree extent records\n"); |
Phillip Lougher | 434a964 | 2011-11-02 13:38:01 -0700 | [diff] [blame] | 53 | unlock_new_inode(tree->inode); |
| 54 | goto free_inode; |
| 55 | } |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | tree->inode->i_mapping->a_ops = &hfs_btree_aops; |
| 58 | break; |
| 59 | case HFS_CAT_CNID: |
| 60 | hfs_inode_read_fork(tree->inode, mdb->drCTExtRec, mdb->drCTFlSize, |
| 61 | mdb->drCTFlSize, be32_to_cpu(mdb->drCTClpSiz)); |
Phillip Lougher | 434a964 | 2011-11-02 13:38:01 -0700 | [diff] [blame] | 62 | |
| 63 | if (!HFS_I(tree->inode)->first_blocks) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 64 | pr_err("invalid btree extent records (0 size)\n"); |
Phillip Lougher | 434a964 | 2011-11-02 13:38:01 -0700 | [diff] [blame] | 65 | unlock_new_inode(tree->inode); |
| 66 | goto free_inode; |
| 67 | } |
| 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | tree->inode->i_mapping->a_ops = &hfs_btree_aops; |
| 70 | break; |
| 71 | default: |
| 72 | BUG(); |
| 73 | } |
| 74 | } |
| 75 | unlock_new_inode(tree->inode); |
| 76 | |
| 77 | mapping = tree->inode->i_mapping; |
Pekka Enberg | 090d2b1 | 2006-06-23 02:05:08 -0700 | [diff] [blame] | 78 | page = read_mapping_page(mapping, 0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | if (IS_ERR(page)) |
Eric Sandeen | 46a39c1 | 2008-01-17 15:21:09 -0800 | [diff] [blame] | 80 | goto free_inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | /* Load the header */ |
| 83 | head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc)); |
| 84 | tree->root = be32_to_cpu(head->root); |
| 85 | tree->leaf_count = be32_to_cpu(head->leaf_count); |
| 86 | tree->leaf_head = be32_to_cpu(head->leaf_head); |
| 87 | tree->leaf_tail = be32_to_cpu(head->leaf_tail); |
| 88 | tree->node_count = be32_to_cpu(head->node_count); |
| 89 | tree->free_nodes = be32_to_cpu(head->free_nodes); |
| 90 | tree->attributes = be32_to_cpu(head->attributes); |
| 91 | tree->node_size = be16_to_cpu(head->node_size); |
| 92 | tree->max_key_len = be16_to_cpu(head->max_key_len); |
| 93 | tree->depth = be16_to_cpu(head->depth); |
| 94 | |
| 95 | size = tree->node_size; |
Vignesh Babu BM | e1b5c1d | 2007-05-08 00:24:30 -0700 | [diff] [blame] | 96 | if (!is_power_of_2(size)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | goto fail_page; |
| 98 | if (!tree->node_count) |
| 99 | goto fail_page; |
Eric Sandeen | 55581d0 | 2008-02-06 01:37:10 -0800 | [diff] [blame] | 100 | switch (id) { |
| 101 | case HFS_EXT_CNID: |
| 102 | if (tree->max_key_len != HFS_MAX_EXT_KEYLEN) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 103 | pr_err("invalid extent max_key_len %d\n", |
| 104 | tree->max_key_len); |
Eric Sandeen | 55581d0 | 2008-02-06 01:37:10 -0800 | [diff] [blame] | 105 | goto fail_page; |
| 106 | } |
| 107 | break; |
| 108 | case HFS_CAT_CNID: |
| 109 | if (tree->max_key_len != HFS_MAX_CAT_KEYLEN) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 110 | pr_err("invalid catalog max_key_len %d\n", |
| 111 | tree->max_key_len); |
Eric Sandeen | 55581d0 | 2008-02-06 01:37:10 -0800 | [diff] [blame] | 112 | goto fail_page; |
| 113 | } |
| 114 | break; |
| 115 | default: |
| 116 | BUG(); |
Eric Sandeen | cf05946 | 2008-01-08 15:33:20 -0800 | [diff] [blame] | 117 | } |
| 118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | tree->node_size_shift = ffs(size) - 1; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 120 | tree->pages_per_bnode = (tree->node_size + PAGE_SIZE - 1) >> PAGE_SHIFT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
| 122 | kunmap(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 123 | put_page(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | return tree; |
| 125 | |
Eric Sandeen | 46a39c1 | 2008-01-17 15:21:09 -0800 | [diff] [blame] | 126 | fail_page: |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 127 | put_page(page); |
Eric Sandeen | 46a39c1 | 2008-01-17 15:21:09 -0800 | [diff] [blame] | 128 | free_inode: |
Eric Sandeen | cf05946 | 2008-01-08 15:33:20 -0800 | [diff] [blame] | 129 | tree->inode->i_mapping->a_ops = &hfs_aops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | iput(tree->inode); |
Eric Sandeen | 46a39c1 | 2008-01-17 15:21:09 -0800 | [diff] [blame] | 131 | free_tree: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | kfree(tree); |
| 133 | return NULL; |
| 134 | } |
| 135 | |
| 136 | /* Release resources used by a btree */ |
| 137 | void hfs_btree_close(struct hfs_btree *tree) |
| 138 | { |
| 139 | struct hfs_bnode *node; |
| 140 | int i; |
| 141 | |
| 142 | if (!tree) |
| 143 | return; |
| 144 | |
| 145 | for (i = 0; i < NODE_HASH_SIZE; i++) { |
| 146 | while ((node = tree->node_hash[i])) { |
| 147 | tree->node_hash[i] = node->next_hash; |
| 148 | if (atomic_read(&node->refcnt)) |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 149 | pr_err("node %d:%d still has %d user(s)!\n", |
| 150 | node->tree->cnid, node->this, |
| 151 | atomic_read(&node->refcnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | hfs_bnode_free(node); |
| 153 | tree->node_hash_cnt--; |
| 154 | } |
| 155 | } |
| 156 | iput(tree->inode); |
| 157 | kfree(tree); |
| 158 | } |
| 159 | |
| 160 | void hfs_btree_write(struct hfs_btree *tree) |
| 161 | { |
| 162 | struct hfs_btree_header_rec *head; |
| 163 | struct hfs_bnode *node; |
| 164 | struct page *page; |
| 165 | |
| 166 | node = hfs_bnode_find(tree, 0); |
| 167 | if (IS_ERR(node)) |
| 168 | /* panic? */ |
| 169 | return; |
| 170 | /* Load the header */ |
| 171 | page = node->page[0]; |
| 172 | head = (struct hfs_btree_header_rec *)(kmap(page) + sizeof(struct hfs_bnode_desc)); |
| 173 | |
| 174 | head->root = cpu_to_be32(tree->root); |
| 175 | head->leaf_count = cpu_to_be32(tree->leaf_count); |
| 176 | head->leaf_head = cpu_to_be32(tree->leaf_head); |
| 177 | head->leaf_tail = cpu_to_be32(tree->leaf_tail); |
| 178 | head->node_count = cpu_to_be32(tree->node_count); |
| 179 | head->free_nodes = cpu_to_be32(tree->free_nodes); |
| 180 | head->attributes = cpu_to_be32(tree->attributes); |
| 181 | head->depth = cpu_to_be16(tree->depth); |
| 182 | |
| 183 | kunmap(page); |
| 184 | set_page_dirty(page); |
| 185 | hfs_bnode_put(node); |
| 186 | } |
| 187 | |
| 188 | static struct hfs_bnode *hfs_bmap_new_bmap(struct hfs_bnode *prev, u32 idx) |
| 189 | { |
| 190 | struct hfs_btree *tree = prev->tree; |
| 191 | struct hfs_bnode *node; |
| 192 | struct hfs_bnode_desc desc; |
| 193 | __be32 cnid; |
| 194 | |
| 195 | node = hfs_bnode_create(tree, idx); |
| 196 | if (IS_ERR(node)) |
| 197 | return node; |
| 198 | |
| 199 | if (!tree->free_nodes) |
| 200 | panic("FIXME!!!"); |
| 201 | tree->free_nodes--; |
| 202 | prev->next = idx; |
| 203 | cnid = cpu_to_be32(idx); |
| 204 | hfs_bnode_write(prev, &cnid, offsetof(struct hfs_bnode_desc, next), 4); |
| 205 | |
| 206 | node->type = HFS_NODE_MAP; |
| 207 | node->num_recs = 1; |
| 208 | hfs_bnode_clear(node, 0, tree->node_size); |
| 209 | desc.next = 0; |
| 210 | desc.prev = 0; |
| 211 | desc.type = HFS_NODE_MAP; |
| 212 | desc.height = 0; |
| 213 | desc.num_recs = cpu_to_be16(1); |
| 214 | desc.reserved = 0; |
| 215 | hfs_bnode_write(node, &desc, 0, sizeof(desc)); |
| 216 | hfs_bnode_write_u16(node, 14, 0x8000); |
| 217 | hfs_bnode_write_u16(node, tree->node_size - 2, 14); |
| 218 | hfs_bnode_write_u16(node, tree->node_size - 4, tree->node_size - 6); |
| 219 | |
| 220 | return node; |
| 221 | } |
| 222 | |
Ernesto A. Fernández | 54640c7 | 2018-10-30 15:06:17 -0700 | [diff] [blame] | 223 | /* Make sure @tree has enough space for the @rsvd_nodes */ |
| 224 | int hfs_bmap_reserve(struct hfs_btree *tree, int rsvd_nodes) |
| 225 | { |
| 226 | struct inode *inode = tree->inode; |
| 227 | u32 count; |
| 228 | int res; |
| 229 | |
| 230 | while (tree->free_nodes < rsvd_nodes) { |
| 231 | res = hfs_extend_file(inode); |
| 232 | if (res) |
| 233 | return res; |
| 234 | HFS_I(inode)->phys_size = inode->i_size = |
| 235 | (loff_t)HFS_I(inode)->alloc_blocks * |
| 236 | HFS_SB(tree->sb)->alloc_blksz; |
| 237 | HFS_I(inode)->fs_blocks = inode->i_size >> |
| 238 | tree->sb->s_blocksize_bits; |
| 239 | inode_set_bytes(inode, inode->i_size); |
| 240 | count = inode->i_size >> tree->node_size_shift; |
| 241 | tree->free_nodes += count - tree->node_count; |
| 242 | tree->node_count = count; |
| 243 | } |
| 244 | return 0; |
| 245 | } |
| 246 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | struct hfs_bnode *hfs_bmap_alloc(struct hfs_btree *tree) |
| 248 | { |
| 249 | struct hfs_bnode *node, *next_node; |
| 250 | struct page **pagep; |
| 251 | u32 nidx, idx; |
Andrew Morton | 3e5a509 | 2008-04-30 00:54:53 -0700 | [diff] [blame] | 252 | unsigned off; |
| 253 | u16 off16; |
| 254 | u16 len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | u8 *data, byte, m; |
Ernesto A. Fernández | 54640c7 | 2018-10-30 15:06:17 -0700 | [diff] [blame] | 256 | int i, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | |
Ernesto A. Fernández | 54640c7 | 2018-10-30 15:06:17 -0700 | [diff] [blame] | 258 | res = hfs_bmap_reserve(tree, 1); |
| 259 | if (res) |
| 260 | return ERR_PTR(res); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | nidx = 0; |
| 263 | node = hfs_bnode_find(tree, nidx); |
| 264 | if (IS_ERR(node)) |
| 265 | return node; |
Andrew Morton | 3e5a509 | 2008-04-30 00:54:53 -0700 | [diff] [blame] | 266 | len = hfs_brec_lenoff(node, 2, &off16); |
| 267 | off = off16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
| 269 | off += node->page_offset; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 270 | pagep = node->page + (off >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | data = kmap(*pagep); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 272 | off &= ~PAGE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | idx = 0; |
| 274 | |
| 275 | for (;;) { |
| 276 | while (len) { |
| 277 | byte = data[off]; |
| 278 | if (byte != 0xff) { |
| 279 | for (m = 0x80, i = 0; i < 8; m >>= 1, i++) { |
| 280 | if (!(byte & m)) { |
| 281 | idx += i; |
| 282 | data[off] |= m; |
| 283 | set_page_dirty(*pagep); |
| 284 | kunmap(*pagep); |
| 285 | tree->free_nodes--; |
| 286 | mark_inode_dirty(tree->inode); |
| 287 | hfs_bnode_put(node); |
| 288 | return hfs_bnode_create(tree, idx); |
| 289 | } |
| 290 | } |
| 291 | } |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 292 | if (++off >= PAGE_SIZE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | kunmap(*pagep); |
| 294 | data = kmap(*++pagep); |
| 295 | off = 0; |
| 296 | } |
| 297 | idx += 8; |
| 298 | len--; |
| 299 | } |
| 300 | kunmap(*pagep); |
| 301 | nidx = node->next; |
| 302 | if (!nidx) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 303 | printk(KERN_DEBUG "create new bmap node...\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | next_node = hfs_bmap_new_bmap(node, idx); |
| 305 | } else |
| 306 | next_node = hfs_bnode_find(tree, nidx); |
| 307 | hfs_bnode_put(node); |
| 308 | if (IS_ERR(next_node)) |
| 309 | return next_node; |
| 310 | node = next_node; |
| 311 | |
Andrew Morton | 3e5a509 | 2008-04-30 00:54:53 -0700 | [diff] [blame] | 312 | len = hfs_brec_lenoff(node, 0, &off16); |
| 313 | off = off16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | off += node->page_offset; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 315 | pagep = node->page + (off >> PAGE_SHIFT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | data = kmap(*pagep); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 317 | off &= ~PAGE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | |
| 321 | void hfs_bmap_free(struct hfs_bnode *node) |
| 322 | { |
| 323 | struct hfs_btree *tree; |
| 324 | struct page *page; |
| 325 | u16 off, len; |
| 326 | u32 nidx; |
| 327 | u8 *data, byte, m; |
| 328 | |
Joe Perches | c2b3e1f | 2013-04-30 15:27:54 -0700 | [diff] [blame] | 329 | hfs_dbg(BNODE_MOD, "btree_free_node: %u\n", node->this); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | tree = node->tree; |
| 331 | nidx = node->this; |
| 332 | node = hfs_bnode_find(tree, 0); |
| 333 | if (IS_ERR(node)) |
| 334 | return; |
| 335 | len = hfs_brec_lenoff(node, 2, &off); |
| 336 | while (nidx >= len * 8) { |
| 337 | u32 i; |
| 338 | |
| 339 | nidx -= len * 8; |
| 340 | i = node->next; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | if (!i) { |
| 342 | /* panic */; |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 343 | pr_crit("unable to free bnode %u. bmap not found!\n", |
| 344 | node->this); |
Pan Bian | ce96a40 | 2018-11-30 14:09:14 -0800 | [diff] [blame] | 345 | hfs_bnode_put(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | return; |
| 347 | } |
Pan Bian | ce96a40 | 2018-11-30 14:09:14 -0800 | [diff] [blame] | 348 | hfs_bnode_put(node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | node = hfs_bnode_find(tree, i); |
| 350 | if (IS_ERR(node)) |
| 351 | return; |
| 352 | if (node->type != HFS_NODE_MAP) { |
| 353 | /* panic */; |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 354 | pr_crit("invalid bmap found! (%u,%d)\n", |
| 355 | node->this, node->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | hfs_bnode_put(node); |
| 357 | return; |
| 358 | } |
| 359 | len = hfs_brec_lenoff(node, 0, &off); |
| 360 | } |
| 361 | off += node->page_offset + nidx / 8; |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 362 | page = node->page[off >> PAGE_SHIFT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | data = kmap(page); |
Kirill A. Shutemov | 09cbfea | 2016-04-01 15:29:47 +0300 | [diff] [blame] | 364 | off &= ~PAGE_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | m = 1 << (~nidx & 7); |
| 366 | byte = data[off]; |
| 367 | if (!(byte & m)) { |
Joe Perches | d614267 | 2013-04-30 15:27:55 -0700 | [diff] [blame] | 368 | pr_crit("trying to free free bnode %u(%d)\n", |
| 369 | node->this, node->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | kunmap(page); |
| 371 | hfs_bnode_put(node); |
| 372 | return; |
| 373 | } |
| 374 | data[off] = byte & ~m; |
| 375 | set_page_dirty(page); |
| 376 | kunmap(page); |
| 377 | hfs_bnode_put(node); |
| 378 | tree->free_nodes++; |
| 379 | mark_inode_dirty(tree->inode); |
| 380 | } |