int move_count);
STATIC int xfs_attr_leaf_entsize(xfs_attr_leafblock_t *leaf, int index);
+/* Compute the byte offset of the end of the leaf entry array. */
+static inline int
+xfs_attr_leaf_entries_end(
+ unsigned int hdrcount,
+ const struct xfs_attr_leafblock *leaf)
+{
+ return hdrcount * sizeof(struct xfs_attr_leaf_entry) +
+ xfs_attr3_leaf_hdr_size(leaf);
+}
+
/*
* attr3 block 'firstused' conversion helpers.
*
* Search through freemap for first-fit on new name length.
* (may need to figure in size of entry struct too)
*/
- tablesize = (ichdr.count + 1) * sizeof(xfs_attr_leaf_entry_t)
- + xfs_attr3_leaf_hdr_size(leaf);
+ tablesize = xfs_attr_leaf_entries_end(ichdr.count + 1, leaf);
for (sum = 0, i = XFS_ATTR_LEAF_MAPSIZE - 1; i >= 0; i--) {
if (tablesize > ichdr.firstused) {
sum += ichdr.freemap[i].size;
if (be16_to_cpu(entry->nameidx) < ichdr->firstused)
ichdr->firstused = be16_to_cpu(entry->nameidx);
- new_end = ichdr->count * sizeof(struct xfs_attr_leaf_entry) +
- xfs_attr3_leaf_hdr_size(leaf);
+ new_end = xfs_attr_leaf_entries_end(ichdr->count, leaf);
old_end = new_end - sizeof(struct xfs_attr_leaf_entry);
ASSERT(ichdr->firstused >= new_end);
/*
* leaf2 is the destination, compact it if it looks tight.
*/
- max = ichdr2.firstused - xfs_attr3_leaf_hdr_size(leaf1);
- max -= ichdr2.count * sizeof(xfs_attr_leaf_entry_t);
+ max = ichdr2.firstused -
+ xfs_attr_leaf_entries_end(ichdr2.count, leaf1);
if (space > max)
xfs_attr3_leaf_compact(args, &ichdr2, blk2->bp);
/*
* leaf1 is the destination, compact it if it looks tight.
*/
- max = ichdr1.firstused - xfs_attr3_leaf_hdr_size(leaf1);
- max -= ichdr1.count * sizeof(xfs_attr_leaf_entry_t);
+ max = ichdr1.firstused -
+ xfs_attr_leaf_entries_end(ichdr1.count, leaf1);
if (space > max)
xfs_attr3_leaf_compact(args, &ichdr1, blk1->bp);
blk = &state->path.blk[ state->path.active-1 ];
leaf = blk->bp->b_addr;
xfs_attr3_leaf_hdr_from_disk(state->args->geo, &ichdr, leaf);
- bytes = xfs_attr3_leaf_hdr_size(leaf) +
- ichdr.count * sizeof(xfs_attr_leaf_entry_t) +
- ichdr.usedbytes;
+ bytes = xfs_attr_leaf_entries_end(ichdr.count, leaf) + ichdr.usedbytes;
if (bytes > (state->args->geo->blksize >> 1)) {
*action = 0; /* blk over 50%, don't try to join */
return 0;
bytes = state->args->geo->blksize -
(state->args->geo->blksize >> 2) -
ichdr.usedbytes - ichdr2.usedbytes -
- ((ichdr.count + ichdr2.count) *
- sizeof(xfs_attr_leaf_entry_t)) -
- xfs_attr3_leaf_hdr_size(leaf);
+ xfs_attr_leaf_entries_end(ichdr.count + ichdr2.count,
+ leaf);
xfs_trans_brelse(state->args->trans, bp);
if (bytes >= 0)
ASSERT(ichdr.count > 0 && ichdr.count < args->geo->blksize / 8);
ASSERT(args->index >= 0 && args->index < ichdr.count);
- ASSERT(ichdr.firstused >= ichdr.count * sizeof(*entry) +
- xfs_attr3_leaf_hdr_size(leaf));
+ ASSERT(ichdr.firstused >= xfs_attr_leaf_entries_end(ichdr.count, leaf));
entry = &xfs_attr3_leaf_entryp(leaf)[args->index];
* find smallest free region in case we need to replace it,
* adjust any map that borders the entry table,
*/
- tablesize = ichdr.count * sizeof(xfs_attr_leaf_entry_t)
- + xfs_attr3_leaf_hdr_size(leaf);
+ tablesize = xfs_attr_leaf_entries_end(ichdr.count, leaf);
tmp = ichdr.freemap[0].size;
before = after = -1;
smallest = XFS_ATTR_LEAF_MAPSIZE - 1;
* Check if leaf is less than 50% full, caller may want to
* "join" the leaf with a sibling if so.
*/
- tmp = ichdr.usedbytes + xfs_attr3_leaf_hdr_size(leaf) +
- ichdr.count * sizeof(xfs_attr_leaf_entry_t);
+ tmp = ichdr.usedbytes + xfs_attr_leaf_entries_end(ichdr.count, leaf);
return tmp < args->geo->magicpct; /* leaf is < 37% full */
}
ichdr_s->magic == XFS_ATTR3_LEAF_MAGIC);
ASSERT(ichdr_s->magic == ichdr_d->magic);
ASSERT(ichdr_s->count > 0 && ichdr_s->count < args->geo->blksize / 8);
- ASSERT(ichdr_s->firstused >= (ichdr_s->count * sizeof(*entry_s))
- + xfs_attr3_leaf_hdr_size(leaf_s));
+ ASSERT(ichdr_s->firstused >=
+ xfs_attr_leaf_entries_end(ichdr_s->count, leaf_s));
ASSERT(ichdr_d->count < args->geo->blksize / 8);
- ASSERT(ichdr_d->firstused >= (ichdr_d->count * sizeof(*entry_d))
- + xfs_attr3_leaf_hdr_size(leaf_d));
+ ASSERT(ichdr_d->firstused >=
+ xfs_attr_leaf_entries_end(ichdr_d->count, leaf_d));
ASSERT(start_s < ichdr_s->count);
ASSERT(start_d <= ichdr_d->count);
ichdr_d->usedbytes += tmp;
ichdr_s->count -= 1;
ichdr_d->count += 1;
- tmp = ichdr_d->count * sizeof(xfs_attr_leaf_entry_t)
- + xfs_attr3_leaf_hdr_size(leaf_d);
+ tmp = xfs_attr_leaf_entries_end(ichdr_d->count, leaf_d);
ASSERT(ichdr_d->firstused >= tmp);
#ifdef GROT
}
/*
* Fill in the freemap information
*/
- ichdr_d->freemap[0].base = xfs_attr3_leaf_hdr_size(leaf_d);
- ichdr_d->freemap[0].base += ichdr_d->count * sizeof(xfs_attr_leaf_entry_t);
+ ichdr_d->freemap[0].base =
+ xfs_attr_leaf_entries_end(ichdr_d->count, leaf_d);
ichdr_d->freemap[0].size = ichdr_d->firstused - ichdr_d->freemap[0].base;
ichdr_d->freemap[1].base = 0;
ichdr_d->freemap[2].base = 0;