Lines Matching +full:record +full:- +full:size

1 // SPDX-License-Identifier: GPL-2.0
19 /* Get the length and offset of the given record in the given node */
25 dataoff = node->tree->node_size - (rec + 2) * 2; in hfs_brec_lenoff()
28 return be16_to_cpu(retval[0]) - *off; in hfs_brec_lenoff()
31 /* Get the length of the key from a keyed record */
36 if (node->type != HFS_NODE_INDEX && node->type != HFS_NODE_LEAF) in hfs_brec_keylen()
39 if ((node->type == HFS_NODE_INDEX) && in hfs_brec_keylen()
40 !(node->tree->attributes & HFS_TREE_VARIDXKEYS) && in hfs_brec_keylen()
41 (node->tree->cnid != HFSPLUS_ATTR_CNID)) { in hfs_brec_keylen()
42 retval = node->tree->max_key_len + 2; in hfs_brec_keylen()
45 node->tree->node_size - (rec + 1) * 2); in hfs_brec_keylen()
48 if (recoff > node->tree->node_size - 2) { in hfs_brec_keylen()
54 if (retval > node->tree->max_key_len + 2) { in hfs_brec_keylen()
67 int size, key_len, rec; in hfs_brec_insert() local
72 tree = fd->tree; in hfs_brec_insert()
73 if (!fd->bnode) { in hfs_brec_insert()
74 if (!tree->root) in hfs_brec_insert()
76 node = hfs_bnode_find(tree, tree->leaf_head); in hfs_brec_insert()
79 fd->bnode = node; in hfs_brec_insert()
80 fd->record = -1; in hfs_brec_insert()
83 key_len = be16_to_cpu(fd->search_key->key_len) + 2; in hfs_brec_insert()
85 /* new record idx and complete record size */ in hfs_brec_insert()
86 rec = fd->record + 1; in hfs_brec_insert()
87 size = key_len + entry_len; in hfs_brec_insert()
89 node = fd->bnode; in hfs_brec_insert()
92 end_rec_off = tree->node_size - (node->num_recs + 1) * 2; in hfs_brec_insert()
94 end_rec_off -= 2; in hfs_brec_insert()
96 rec, size, end_off, end_rec_off); in hfs_brec_insert()
97 if (size > end_rec_off - end_off) { in hfs_brec_insert()
105 if (node->type == HFS_NODE_LEAF) { in hfs_brec_insert()
106 tree->leaf_count++; in hfs_brec_insert()
107 mark_inode_dirty(tree->inode); in hfs_brec_insert()
109 node->num_recs++; in hfs_brec_insert()
113 node->num_recs); in hfs_brec_insert()
114 hfs_bnode_write_u16(node, end_rec_off, end_off + size); in hfs_brec_insert()
117 idx_rec_off = tree->node_size - (rec + 1) * 2; in hfs_brec_insert()
123 hfs_bnode_write_u16(node, data_rec_off, data_off + size); in hfs_brec_insert()
128 hfs_bnode_move(node, data_off + size, data_off, in hfs_brec_insert()
129 end_off - data_off); in hfs_brec_insert()
132 hfs_bnode_write(node, fd->search_key, data_off, key_len); in hfs_brec_insert()
141 hfs_bnode_read_key(node, fd->search_key, data_off + size); in hfs_brec_insert()
146 hfs_bnode_put(fd->bnode); in hfs_brec_insert()
147 if (!new_node->parent) { in hfs_brec_insert()
149 new_node->parent = tree->root; in hfs_brec_insert()
151 fd->bnode = hfs_bnode_find(tree, new_node->parent); in hfs_brec_insert()
154 cnid = cpu_to_be32(new_node->this); in hfs_brec_insert()
159 hfs_bnode_read_key(new_node, fd->search_key, 14); in hfs_brec_insert()
160 __hfs_brec_find(fd->bnode, fd, hfs_find_rec_by_key); in hfs_brec_insert()
165 if ((tree->attributes & HFS_TREE_VARIDXKEYS) || in hfs_brec_insert()
166 (tree->cnid == HFSPLUS_ATTR_CNID)) in hfs_brec_insert()
167 key_len = be16_to_cpu(fd->search_key->key_len) + 2; in hfs_brec_insert()
169 fd->search_key->key_len = in hfs_brec_insert()
170 cpu_to_be16(tree->max_key_len); in hfs_brec_insert()
171 key_len = tree->max_key_len + 2; in hfs_brec_insert()
183 int end_off, rec_off, data_off, size; in hfs_brec_remove() local
185 tree = fd->tree; in hfs_brec_remove()
186 node = fd->bnode; in hfs_brec_remove()
188 rec_off = tree->node_size - (fd->record + 2) * 2; in hfs_brec_remove()
189 end_off = tree->node_size - (node->num_recs + 1) * 2; in hfs_brec_remove()
191 if (node->type == HFS_NODE_LEAF) { in hfs_brec_remove()
192 tree->leaf_count--; in hfs_brec_remove()
193 mark_inode_dirty(tree->inode); in hfs_brec_remove()
197 fd->record, fd->keylength + fd->entrylength); in hfs_brec_remove()
198 if (!--node->num_recs) { in hfs_brec_remove()
200 if (!node->parent) in hfs_brec_remove()
202 parent = hfs_bnode_find(tree, node->parent); in hfs_brec_remove()
206 node = fd->bnode = parent; in hfs_brec_remove()
213 node->num_recs); in hfs_brec_remove()
217 size = fd->keylength + fd->entrylength; in hfs_brec_remove()
221 hfs_bnode_write_u16(node, rec_off + 2, data_off - size); in hfs_brec_remove()
222 rec_off -= 2; in hfs_brec_remove()
226 hfs_bnode_move(node, fd->keyoffset, fd->keyoffset + size, in hfs_brec_remove()
227 data_off - fd->keyoffset - size); in hfs_brec_remove()
230 if (!fd->record) in hfs_brec_remove()
241 int data_start, data_end, size; in hfs_bnode_split() local
243 tree = fd->tree; in hfs_bnode_split()
244 node = fd->bnode; in hfs_bnode_split()
249 hfs_dbg(BNODE_MOD, "split_nodes: %d - %d - %d\n", in hfs_bnode_split()
250 node->this, new_node->this, node->next); in hfs_bnode_split()
251 new_node->next = node->next; in hfs_bnode_split()
252 new_node->prev = node->this; in hfs_bnode_split()
253 new_node->parent = node->parent; in hfs_bnode_split()
254 new_node->type = node->type; in hfs_bnode_split()
255 new_node->height = node->height; in hfs_bnode_split()
257 if (node->next) in hfs_bnode_split()
258 next_node = hfs_bnode_find(tree, node->next); in hfs_bnode_split()
268 size = tree->node_size / 2 - node->num_recs * 2 - 14; in hfs_bnode_split()
269 old_rec_off = tree->node_size - 4; in hfs_bnode_split()
273 if (data_start > size) in hfs_bnode_split()
275 old_rec_off -= 2; in hfs_bnode_split()
276 if (++num_recs < node->num_recs) in hfs_bnode_split()
283 return ERR_PTR(-ENOSPC); in hfs_bnode_split()
286 if (fd->record + 1 < num_recs) { in hfs_bnode_split()
287 /* new record is in the lower half, in hfs_bnode_split()
291 num_recs--; in hfs_bnode_split()
296 fd->bnode = new_node; in hfs_bnode_split()
297 fd->record -= num_recs; in hfs_bnode_split()
298 fd->keyoffset -= data_start - 14; in hfs_bnode_split()
299 fd->entryoffset -= data_start - 14; in hfs_bnode_split()
301 new_node->num_recs = node->num_recs - num_recs; in hfs_bnode_split()
302 node->num_recs = num_recs; in hfs_bnode_split()
304 new_rec_off = tree->node_size - 2; in hfs_bnode_split()
306 size = data_start - new_off; in hfs_bnode_split()
307 num_recs = new_node->num_recs; in hfs_bnode_split()
311 old_rec_off -= 2; in hfs_bnode_split()
312 new_rec_off -= 2; in hfs_bnode_split()
314 new_off = data_end - size; in hfs_bnode_split()
315 num_recs--; in hfs_bnode_split()
318 hfs_bnode_copy(new_node, 14, node, data_start, data_end - data_start); in hfs_bnode_split()
321 node_desc.next = cpu_to_be32(new_node->next); in hfs_bnode_split()
322 node_desc.prev = cpu_to_be32(new_node->prev); in hfs_bnode_split()
323 node_desc.type = new_node->type; in hfs_bnode_split()
324 node_desc.height = new_node->height; in hfs_bnode_split()
325 node_desc.num_recs = cpu_to_be16(new_node->num_recs); in hfs_bnode_split()
330 node->next = new_node->this; in hfs_bnode_split()
332 node_desc.next = cpu_to_be32(node->next); in hfs_bnode_split()
333 node_desc.num_recs = cpu_to_be16(node->num_recs); in hfs_bnode_split()
338 next_node->prev = new_node->this; in hfs_bnode_split()
340 node_desc.prev = cpu_to_be32(next_node->prev); in hfs_bnode_split()
343 } else if (node->this == tree->leaf_tail) { in hfs_bnode_split()
345 tree->leaf_tail = new_node->this; in hfs_bnode_split()
346 mark_inode_dirty(tree->inode); in hfs_bnode_split()
364 tree = fd->tree; in hfs_brec_update_parent()
365 node = fd->bnode; in hfs_brec_update_parent()
367 if (!node->parent) in hfs_brec_update_parent()
371 parent = hfs_bnode_find(tree, node->parent); in hfs_brec_update_parent()
375 if (fd->record < 0) in hfs_brec_update_parent()
376 return -ENOENT; in hfs_brec_update_parent()
378 rec = fd->record; in hfs_brec_update_parent()
380 /* size difference between old and new key */ in hfs_brec_update_parent()
381 if ((tree->attributes & HFS_TREE_VARIDXKEYS) || in hfs_brec_update_parent()
382 (tree->cnid == HFSPLUS_ATTR_CNID)) in hfs_brec_update_parent()
385 fd->keylength = newkeylen = tree->max_key_len + 2; in hfs_brec_update_parent()
387 rec, fd->keylength, newkeylen); in hfs_brec_update_parent()
389 rec_off = tree->node_size - (rec + 2) * 2; in hfs_brec_update_parent()
390 end_rec_off = tree->node_size - (parent->num_recs + 1) * 2; in hfs_brec_update_parent()
391 diff = newkeylen - fd->keylength; in hfs_brec_update_parent()
396 if (end_rec_off - end_off < diff) { in hfs_brec_update_parent()
399 fd->bnode = parent; in hfs_brec_update_parent()
403 parent = fd->bnode; in hfs_brec_update_parent()
404 rec = fd->record; in hfs_brec_update_parent()
405 rec_off = tree->node_size - (rec + 2) * 2; in hfs_brec_update_parent()
406 end_rec_off = tree->node_size - in hfs_brec_update_parent()
407 (parent->num_recs + 1) * 2; in hfs_brec_update_parent()
413 start_off -= 4; /* move previous cnid too */ in hfs_brec_update_parent()
416 rec_off -= 2; in hfs_brec_update_parent()
421 end_off - start_off); in hfs_brec_update_parent()
423 hfs_bnode_copy(parent, fd->keyoffset, node, 14, newkeylen); in hfs_brec_update_parent()
432 if (!new_node->parent) { in hfs_brec_update_parent()
434 new_node->parent = tree->root; in hfs_brec_update_parent()
436 fd->bnode = hfs_bnode_find(tree, new_node->parent); in hfs_brec_update_parent()
438 hfs_bnode_read_key(new_node, fd->search_key, 14); in hfs_brec_update_parent()
439 cnid = cpu_to_be32(new_node->this); in hfs_brec_update_parent()
441 __hfs_brec_find(fd->bnode, fd, hfs_find_rec_by_key); in hfs_brec_update_parent()
443 hfs_bnode_put(fd->bnode); in hfs_brec_update_parent()
450 hfs_bnode_read_key(node, fd->search_key, 14); in hfs_brec_update_parent()
455 if (!rec && node->parent) in hfs_brec_update_parent()
458 fd->bnode = node; in hfs_brec_update_parent()
470 if (tree->root) { in hfs_btree_inc_height()
471 node = hfs_bnode_find(tree, tree->root); in hfs_btree_inc_height()
481 tree->root = new_node->this; in hfs_btree_inc_height()
482 if (!tree->depth) { in hfs_btree_inc_height()
483 tree->leaf_head = tree->leaf_tail = new_node->this; in hfs_btree_inc_height()
484 new_node->type = HFS_NODE_LEAF; in hfs_btree_inc_height()
485 new_node->num_recs = 0; in hfs_btree_inc_height()
487 new_node->type = HFS_NODE_INDEX; in hfs_btree_inc_height()
488 new_node->num_recs = 1; in hfs_btree_inc_height()
490 new_node->parent = 0; in hfs_btree_inc_height()
491 new_node->next = 0; in hfs_btree_inc_height()
492 new_node->prev = 0; in hfs_btree_inc_height()
493 new_node->height = ++tree->depth; in hfs_btree_inc_height()
495 node_desc.next = cpu_to_be32(new_node->next); in hfs_btree_inc_height()
496 node_desc.prev = cpu_to_be32(new_node->prev); in hfs_btree_inc_height()
497 node_desc.type = new_node->type; in hfs_btree_inc_height()
498 node_desc.height = new_node->height; in hfs_btree_inc_height()
499 node_desc.num_recs = cpu_to_be16(new_node->num_recs); in hfs_btree_inc_height()
503 rec = tree->node_size - 2; in hfs_btree_inc_height()
508 node->parent = tree->root; in hfs_btree_inc_height()
509 if (node->type == HFS_NODE_LEAF || in hfs_btree_inc_height()
510 tree->attributes & HFS_TREE_VARIDXKEYS || in hfs_btree_inc_height()
511 tree->cnid == HFSPLUS_ATTR_CNID) in hfs_btree_inc_height()
514 key_size = tree->max_key_len + 2; in hfs_btree_inc_height()
517 if (!(tree->attributes & HFS_TREE_VARIDXKEYS) && in hfs_btree_inc_height()
518 (tree->cnid != HFSPLUS_ATTR_CNID)) { in hfs_btree_inc_height()
519 key_size = tree->max_key_len + 2; in hfs_btree_inc_height()
520 hfs_bnode_write_u16(new_node, 14, tree->max_key_len); in hfs_btree_inc_height()
522 cnid = cpu_to_be32(node->this); in hfs_btree_inc_height()
525 rec -= 2; in hfs_btree_inc_height()
531 mark_inode_dirty(tree->inode); in hfs_btree_inc_height()