67 int *number_entries_in_blk1,
68 int *number_usedbytes_in_blk1);
86 int dst_start,
int move_count,
126 xfs_mount_t *
mp = dp->i_mount;
130 switch (dp->i_d.di_format) {
132 minforkoff =
roundup(
sizeof(xfs_dev_t), 8) >> 3;
133 return (offset >= minforkoff) ? minforkoff : 0;
136 return (offset >= minforkoff) ? minforkoff : 0;
150 return dp->i_d.di_forkoff;
157 if (!(mp->m_flags & XFS_MOUNT_ATTR2))
160 dsize = dp->i_df.if_bytes;
162 switch (dp->i_d.di_format) {
171 if (!dp->i_d.di_forkoff && dp->i_df.if_bytes >
182 if (dp->i_d.di_forkoff) {
185 return dp->i_d.di_forkoff;
196 minforkoff =
roundup(minforkoff, 8) >> 3;
200 maxforkoff = maxforkoff >> 3;
202 if (offset >= maxforkoff)
204 if (offset >= minforkoff)
215 if ((mp->m_flags & XFS_MOUNT_ATTR2) &&
216 !(xfs_sb_version_hasattr2(&mp->m_sb))) {
217 spin_lock(&mp->m_sb_lock);
218 if (!xfs_sb_version_hasattr2(&mp->m_sb)) {
219 xfs_sb_version_addattr2(&mp->m_sb);
220 spin_unlock(&mp->m_sb_lock);
223 spin_unlock(&mp->m_sb_lock);
237 trace_xfs_attr_sf_create(args);
272 trace_xfs_attr_sf_add(args);
276 dp->i_d.di_forkoff = forkoff;
284 if (sfe->namelen != args->
namelen)
294 offset = (
char *)sfe - (
char *)
sf;
306 be16_add_cpu(&sf->
hdr.totsize, size);
318 struct xfs_inode *
ip,
319 struct xfs_trans *tp)
322 ip->i_d.di_forkoff = 0;
325 ASSERT(ip->i_d.di_anextents == 0);
343 trace_xfs_attr_sf_remove(args);
354 if (sfe->namelen != args->
namelen)
371 memmove(&((
char *)sf)[base], &((
char *)sf)[end], totsize - end);
373 be16_add_cpu(&sf->
hdr.totsize, -size);
380 (mp->m_flags & XFS_MOUNT_ATTR2) &&
387 ASSERT(dp->i_d.di_forkoff);
390 !(mp->m_flags & XFS_MOUNT_ATTR2) ||
413 trace_xfs_attr_sf_lookup(args);
415 ifp = args->
dp->i_afp;
419 for (i = 0; i < sf->
hdr.count;
421 if (sfe->namelen != args->
namelen)
446 for (i = 0; i < sf->
hdr.count;
448 if (sfe->namelen != args->
namelen)
458 if (args->
valuelen < sfe->valuelen) {
486 trace_xfs_attr_sf_to_leaf(args);
524 memset((
char *)&nargs, 0,
sizeof(nargs));
534 for (i = 0; i < sf->
hdr.count; i++) {
535 nargs.
name = sfe->nameval;
574 #define XFS_ISRESET_CURSOR(cursor) \
575 (!((cursor)->initted) && !((cursor)->hashval) && \
576 !((cursor)->blkno) && !((cursor)->offset))
593 int sbsize, nsbuf,
count,
i;
607 trace_xfs_attr_list_sf(context);
620 (dp->i_afp->if_bytes + sf->
hdr.count * 16) < context->
bufsize)) {
621 for (i = 0, sfe = &sf->
list[0]; i < sf->
hdr.count; i++) {
627 &sfe->nameval[sfe->namelen]);
640 trace_xfs_attr_list_sf_all(context);
651 sbsize = sf->
hdr.count *
sizeof(*sbuf);
659 for (i = 0, sfe = &sf->
list[0]; i < sf->
hdr.count; i++) {
661 ((
char *)sfe < (
char *)sf) ||
662 ((
char *)sfe >= ((
char *)sf + dp->i_afp->if_bytes)))) {
665 context->
dp->i_mount, sfe);
672 sbp->
name = sfe->nameval;
676 sbp->
flags = sfe->flags;
693 for (sbp = sbuf, i = 0; i < nsbuf; i++, sbp++) {
695 if (cursor->
offset == count) {
711 for ( ; i < nsbuf; i++, sbp++) {
740 struct xfs_inode *
dp)
751 bytes =
sizeof(
struct xfs_attr_sf_hdr);
762 bytes +=
sizeof(
struct xfs_attr_sf_entry)-1
764 + be16_to_cpu(name_loc->valuelen);
766 if ((dp->i_mount->m_flags & XFS_MOUNT_ATTR2) &&
768 (bytes ==
sizeof(
struct xfs_attr_sf_hdr)))
790 trace_xfs_attr_leaf_to_sf(args);
810 ASSERT(dp->i_mount->m_flags & XFS_MOUNT_ATTR2);
821 memset((
char *)&nargs, 0,
sizeof(nargs));
865 trace_xfs_attr_leaf_to_node(args);
897 node->
btree[0].hashval =
928 trace_xfs_attr_leaf_create(args);
967 trace_xfs_attr_leaf_split(state->
args);
979 newblk->
blkno = blkno;
999 trace_xfs_attr_leaf_add_old(state->
args);
1002 trace_xfs_attr_leaf_add_new(state->
args);
1025 int tablesize, entsize,
sum,
tmp,
i;
1027 trace_xfs_attr_leaf_add(args);
1035 args->
trans->t_mountp->m_sb.sb_blocksize,
NULL);
1067 if (!hdr->
holes && (sum < entsize))
1118 memmove((
char *)(entry+1), (
char *)entry, tmp);
1122 be16_add_cpu(&hdr->
count, 1);
1127 map = &hdr->
freemap[mapindex];
1128 mp = args->
trans->t_mountp;
1133 mp->m_sb.sb_blocksize,
NULL));
1136 be16_add_cpu(&map->
size,
1138 mp->m_sb.sb_blocksize, &tmp));
1202 be16_add_cpu(&map->
size,
1217 struct xfs_trans *
trans,
1225 mp = trans->t_mountp;
1236 hdr_s = &leaf_s->
hdr;
1237 hdr_d = &leaf_d->
hdr;
1290 leaf1 = blk1->
bp->b_addr;
1291 leaf2 = blk2->
bp->b_addr;
1297 trace_xfs_attr_leaf_rebalance(args);
1310 leaf1 = blk1->
bp->b_addr;
1311 leaf2 = blk2->
bp->b_addr;
1356 leaf2, 0, count, state->
mp);
1464 int *countarg,
int *usedbytesarg)
1470 int lastdelta, foundit,
tmp;
1475 leaf1 = blk1->
bp->b_addr;
1476 leaf2 = blk2->
bp->b_addr;
1487 half = (max+1) *
sizeof(*entry);
1497 for (count = index = 0; count <
max; entry++, index++, count++) {
1499 #define XFS_ATTR_ABS(A) (((A) < 0) ? -(A) : (A))
1503 if (count == blk1->
index) {
1504 tmp = totallen +
sizeof(*entry) +
1541 totallen -= count *
sizeof(*entry);
1543 totallen -=
sizeof(*entry) +
1551 *usedbytesarg = totallen;
1586 info = blk->
bp->b_addr;
1609 forward = (info->
forw != 0);
1632 for (i = 0; i < 2; forward = !forward, i++) {
1669 if (blkno < blk->blkno) {
1701 int before,
after, smallest, entsize;
1702 int tablesize,
tmp,
i;
1708 mp = args->
trans->t_mountp;
1729 before = after = -1;
1736 be16_add_cpu(&map->
base,
1757 if ((before >= 0) || (after >= 0)) {
1758 if ((before >= 0) && (after >= 0)) {
1760 be16_add_cpu(&map->
size, entsize);
1761 be16_add_cpu(&map->
size,
1765 }
else if (before >= 0) {
1767 be16_add_cpu(&map->
size, entsize);
1772 be16_add_cpu(&map->
size, entsize);
1778 map = &hdr->
freemap[smallest];
1796 memset(xfs_attr_leaf_name(leaf, args->
index), 0, entsize);
1797 be16_add_cpu(&hdr->
usedbytes, -entsize);
1804 memmove((
char *)entry, (
char *)(entry+1), tmp);
1805 be16_add_cpu(&hdr->
count, -1);
1846 return(tmp < mp->m_attr_magicpct);
1861 trace_xfs_attr_leaf_unbalance(state->
args);
1869 drop_leaf = drop_blk->
bp->b_addr;
1870 save_leaf = save_blk->
bp->b_addr;
1873 drop_hdr = &drop_leaf->
hdr;
1874 save_hdr = &save_leaf->
hdr;
1887 if (save_hdr->
holes == 0) {
1909 tmp_hdr = &tmp_leaf->
hdr;
1974 trace_xfs_attr_leaf_lookup(args);
1986 for (entry = &leaf->
entries[probe]; span > 4;
1987 entry = &leaf->
entries[probe]) {
2016 args->
index = probe;
2045 args->
index = probe;
2056 args->
index = probe;
2063 args->
index = probe;
2153 hdr_s = &leaf_s->
hdr;
2154 hdr_d = &leaf_d->
hdr;
2159 *
sizeof(*entry_s))+
sizeof(*hdr_s)));
2163 *
sizeof(*entry_d))+
sizeof(*hdr_d)));
2175 entry_s = &leaf_d->
entries[start_d];
2177 memmove((
char *)entry_d, (
char *)entry_s, tmp);
2184 entry_s = &leaf_s->
entries[start_s];
2185 entry_d = &leaf_d->
entries[start_d];
2187 for (i = 0; i <
count; entry_s++, entry_d++, desti++, i++) {
2198 memset(xfs_attr_leaf_name(leaf_s, start_s + i), 0, tmp);
2200 be16_add_cpu(&hdr_s->
count, -1);
2203 if ((start_s + i) <
offset)
2209 entry_d->hashval = entry_s->
hashval;
2212 entry_d->flags = entry_s->
flags;
2215 memmove(xfs_attr_leaf_name(leaf_d, desti),
2216 xfs_attr_leaf_name(leaf_s, start_s + i), tmp);
2219 memset(xfs_attr_leaf_name(leaf_s, start_s + i), 0, tmp);
2222 be16_add_cpu(&hdr_s->
count, -1);
2223 be16_add_cpu(&hdr_d->
count, 1);
2238 entry_s = &leaf_s->
entries[start_s];
2239 ASSERT(((
char *)entry_s + tmp) <=
2241 memset((
char *)entry_s, 0, tmp);
2250 entry_d = &leaf_s->
entries[start_s];
2251 memmove((
char *)entry_d, (
char *)entry_s, tmp);
2255 ASSERT(((
char *)entry_s + tmp) <=
2257 memset((
char *)entry_s, 0, tmp);
2286 leaf1 = leaf1_bp->
b_addr;
2287 leaf2 = leaf2_bp->
b_addr;
2336 size = xfs_attr_leaf_entsize_local(name_loc->
namelen,
2340 size = xfs_attr_leaf_entsize_remote(name_rmt->
namelen);
2356 size = xfs_attr_leaf_entsize_local(namelen, valuelen);
2357 if (size < xfs_attr_leaf_entsize_local_max(blocksize)) {
2362 size = xfs_attr_leaf_entsize_remote(namelen);
2385 cursor = context->
cursor;
2388 trace_xfs_attr_list_leaf(context);
2409 trace_xfs_attr_list_notfound(context);
2452 memset((
char *)&args, 0,
sizeof(args));
2453 args.
dp = context->
dp;
2484 trace_xfs_attr_list_leaf_end(context);
2510 trace_xfs_attr_leaf_clearflag(args);
2532 name = (
char *)name_loc->
nameval;
2536 name = (
char *)name_rmt->
name;
2574 trace_xfs_attr_leaf_setflag(args);
2627 int namelen1, namelen2;
2628 char *name1, *name2;
2631 trace_xfs_attr_leaf_flipflags(args);
2673 name1 = (
char *)name_loc->
nameval;
2677 name1 = (
char *)name_rmt->
name;
2682 name2 = (
char *)name_loc->
nameval;
2686 name2 = (
char *)name_rmt->
name;
2689 ASSERT(namelen1 == namelen2);
2791 struct xfs_trans **
trans,
2792 struct xfs_inode *
dp,
2799 xfs_daddr_t parent_blkno, child_blkno;
2827 for (i = 0; i <
count; i++) {
2874 if ((i+1) < count) {
2901 struct xfs_trans **
trans,
2902 struct xfs_inode *
dp,
2965 for (lp = list, i = 0; i <
count; i++, lp++) {
2987 int tblkcnt, dblkcnt, nmap,
error;
2997 while (tblkcnt > 0) {
3020 bp = xfs_trans_get_buf(*trans,
3021 dp->i_mount->m_ddev_targp,
3022 dblkno, dblkcnt, 0);