40 static void xfs_dir2_block_log_leaf(xfs_trans_t *tp,
struct xfs_buf *bp,
42 static void xfs_dir2_block_log_tail(xfs_trans_t *tp,
struct xfs_buf *bp);
45 static int xfs_dir2_block_sort(
const void *
a,
const void *
b);
47 static xfs_dahash_t xfs_dir_hash_dot, xfs_dir_hash_dotdot;
92 trace_xfs_dir2_block_addname(args);
115 len = xfs_dir2_data_entsize(args->
namelen);
120 btp = xfs_dir2_block_tail_p(mp, hdr);
121 blp = xfs_dir2_block_leaf_p(btp);
203 (
uint)
sizeof(*blp) < len)
240 needlog = needscan = 0;
251 highstale = lfloghigh = -1;
265 blp[toidx] = blp[fromidx];
274 &needlog, &needscan);
290 else if (btp->
stale) {
298 mid = (low +
high) >> 1;
301 if (hash < args->hashval)
321 &needlog, &needscan);
325 be32_add_cpu(&btp->
count, 1);
342 memmove(blp, &blp[1], mid *
sizeof(*blp));
356 for (highstale = mid + 1;
360 (lowstale < 0 || mid - lowstale > highstale -
mid);
368 mid - lowstale <= highstale -
mid)) {
370 memmove(&blp[lowstale], &blp[lowstale + 1],
371 (mid - lowstale) *
sizeof(*blp));
372 lfloglow =
MIN(lowstale, lfloglow);
373 lfloghigh =
MAX(mid, lfloghigh);
382 memmove(&blp[mid + 1], &blp[mid],
383 (highstale - mid) *
sizeof(*blp));
384 lfloglow =
MIN(mid, lfloglow);
385 lfloghigh =
MAX(highstale, lfloghigh);
387 be32_add_cpu(&btp->
stale, -1);
398 (
char *)dep - (
char *)hdr));
399 xfs_dir2_block_log_leaf(tp, bp, lfloglow, lfloghigh);
412 tagp = xfs_dir2_data_entry_tag_p(dep);
421 xfs_dir2_block_log_tail(tp, bp);
453 if (xfs_dir2_dataptr_to_db(mp, *offset) > mp->m_dirdatablk) {
469 wantoff = xfs_dir2_dataptr_to_off(mp, *offset);
475 btp = xfs_dir2_block_tail_p(mp, hdr);
476 ptr = (
char *)(hdr + 1);
477 endptr = (
char *)xfs_dir2_block_leaf_p(btp);
483 while (ptr < endptr) {
498 ptr += xfs_dir2_data_entsize(dep->
namelen);
502 if ((
char *)dep - (
char *)hdr < wantoff)
505 cook = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
506 (
char *)dep - (
char *)hdr);
511 if (filldir(dirent, (
char *)dep->
name, dep->
namelen,
514 *offset = cook & 0x7fffffff;
524 *offset = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk + 1, 0) &
534 xfs_dir2_block_log_leaf(
544 btp = xfs_dir2_block_tail_p(tp->t_mountp, hdr);
545 blp = xfs_dir2_block_leaf_p(btp);
547 (
uint)((
char *)&blp[last + 1] - (
char *)hdr - 1));
554 xfs_dir2_block_log_tail(
561 btp = xfs_dir2_block_tail_p(tp->t_mountp, hdr);
563 (
uint)((
char *)(btp + 1) - (
char *)hdr - 1));
584 trace_xfs_dir2_block_lookup(args);
590 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent)))
596 btp = xfs_dir2_block_tail_p(mp, hdr);
597 blp = xfs_dir2_block_leaf_p(btp);
616 xfs_dir2_block_lookup_int(
650 btp = xfs_dir2_block_tail_p(mp, hdr);
651 blp = xfs_dir2_block_leaf_p(btp);
658 mid = (low +
high) >> 1;
661 if (hash < args->hashval)
688 ((
char *)hdr + xfs_dir2_dataptr_to_off(mp, addr));
694 cmp = mp->m_dirnameops->compname(args, dep->
name, dep->
namelen);
742 trace_xfs_dir2_block_removename(args);
748 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) {
755 btp = xfs_dir2_block_tail_p(mp, hdr);
756 blp = xfs_dir2_block_leaf_p(btp);
761 ((
char *)hdr + xfs_dir2_dataptr_to_off(mp,
be32_to_cpu(blp[ent].address)));
765 needlog = needscan = 0;
768 xfs_dir2_data_entsize(dep->
namelen), &needlog, &needscan);
772 be32_add_cpu(&btp->
stale, 1);
773 xfs_dir2_block_log_tail(tp, bp);
778 xfs_dir2_block_log_leaf(tp, bp, ent, ent);
818 trace_xfs_dir2_block_replace(args);
824 if ((error = xfs_dir2_block_lookup_int(args, &bp, &ent))) {
830 btp = xfs_dir2_block_tail_p(mp, hdr);
831 blp = xfs_dir2_block_leaf_p(btp);
836 ((
char *)hdr + xfs_dir2_dataptr_to_off(mp,
be32_to_cpu(blp[ent].address)));
892 trace_xfs_dir2_leaf_to_block(args);
899 ltp = xfs_dir2_leaf_tail_p(mp, leaf);
906 while (dp->i_d.di_size > mp->m_dirblksize) {
907 bestsp = xfs_dir2_leaf_bests_p(ltp);
909 mp->m_dirblksize - (
uint)
sizeof(*hdr)) {
935 tagp = (
__be16 *)((
char *)hdr + mp->m_dirblksize) - 1;
954 &needlog, &needscan);
958 btp = xfs_dir2_block_tail_p(mp, hdr);
961 xfs_dir2_block_log_tail(tp, dbp);
965 lep = xfs_dir2_block_leaf_p(btp);
1029 trace_xfs_dir2_sf_to_block(args);
1039 ASSERT(XFS_FORCED_SHUTDOWN(mp));
1045 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
1047 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(oldsfp->
i8count));
1054 memcpy(sfp, oldsfp, dp->i_df.if_bytes);
1057 dp->i_d.di_size = 0;
1081 i = (
uint)
sizeof(*btp) +
1088 needlog = needscan = 0;
1095 btp = xfs_dir2_block_tail_p(mp, hdr);
1098 blp = xfs_dir2_block_leaf_p(btp);
1099 endoffset = (
uint)((
char *)blp - (
char *)hdr);
1114 tagp = xfs_dir2_data_entry_tag_p(dep);
1119 (
char *)dep - (
char *)hdr));
1128 tagp = xfs_dir2_data_entry_tag_p(dep);
1133 (
char *)dep - (
char *)hdr));
1142 sfep = xfs_dir2_sf_firstentry(sfp);
1147 while (offset < endoffset) {
1152 newoffset = endoffset;
1154 newoffset = xfs_dir2_sf_get_offset(sfep);
1158 if (offset < newoffset) {
1163 ((
char *)dup - (
char *)hdr));
1176 tagp = xfs_dir2_data_entry_tag_p(dep);
1184 (
char *)dep - (
char *)hdr));
1185 offset = (
int)((
char *)(tagp + 1) - (
char *)
hdr);
1186 if (++i == sfp->
count)
1189 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
1203 xfs_dir2_block_log_tail(tp, bp);