44 static void xfs_dir2_sf_addname_hard(
xfs_da_args_t *args,
int objchange,
46 static int xfs_dir2_sf_addname_pick(
xfs_da_args_t *args,
int objchange,
52 #define xfs_dir2_sf_check(args)
83 ASSERT((ino & 0xff00000000000000ULL) == 0);
95 return xfs_dir2_sf_get_ino(hdr, &hdr->
parent);
99 xfs_dir2_sf_put_parent_ino(
103 xfs_dir2_sf_put_ino(hdr, &hdr->
parent, ino);
123 return xfs_dir2_sf_get_ino(hdr, xfs_dir2_sfe_inop(sfep));
127 xfs_dir2_sfe_put_ino(
132 xfs_dir2_sf_put_ino(hdr, xfs_dir2_sfe_inop(sfep), ino);
163 count = i8count = namelen = 0;
164 btp = xfs_dir2_block_tail_p(mp, hdr);
165 blp = xfs_dir2_block_leaf_p(btp);
177 ((
char *)hdr + xfs_dir2_dataptr_to_off(mp, addr));
186 dep->
name[0] ==
'.' && dep->
name[1] ==
'.';
191 if (!isdot && !isdotdot) {
199 size = xfs_dir2_sf_hdr_size(i8count) +
201 count * (
uint)
sizeof(xfs_dir2_sf_off_t) +
214 xfs_dir2_sf_put_parent_ino(sfhp, parent);
242 trace_xfs_dir2_block_to_sf(args);
268 ASSERT(dp->i_df.if_bytes == 0);
276 dp->i_d.di_size =
size;
280 btp = xfs_dir2_block_tail_p(mp, hdr);
281 ptr = (
char *)(hdr + 1);
282 endptr = (
char *)xfs_dir2_block_leaf_p(btp);
283 sfep = xfs_dir2_sf_firstentry(sfp);
288 while (ptr < endptr) {
307 dep->
name[0] ==
'.' && dep->
name[1] ==
'.')
315 xfs_dir2_sf_put_offset(sfep,
317 ((
char *)dep - (
char *)hdr));
319 xfs_dir2_sfe_put_ino(sfp, sfep,
322 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
324 ptr += xfs_dir2_data_entsize(dep->
namelen);
326 ASSERT((
char *)sfep - (
char *)sfp == size);
356 trace_xfs_dir2_sf_addname(args);
365 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
368 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
371 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->
i8count));
375 add_entsize = xfs_dir2_sf_entsize(sfp, args->
namelen);
376 incr_isize = add_entsize;
396 old_isize = (
int)dp->i_d.di_size;
397 new_isize = old_isize + incr_isize;
404 xfs_dir2_sf_addname_pick(args, objchange, &sfep, &offset)) == 0) {
427 xfs_dir2_sf_addname_easy(args, sfep, offset, new_isize);
436 xfs_dir2_sf_toino8(args);
438 xfs_dir2_sf_addname_hard(args, objchange, new_isize);
452 xfs_dir2_sf_addname_easy(
465 byteoff = (
int)((
char *)sfep - (
char *)sfp);
480 xfs_dir2_sf_put_offset(sfep, offset);
482 xfs_dir2_sfe_put_ino(sfp, sfep, args->
inumber);
491 dp->i_d.di_size = new_isize;
505 xfs_dir2_sf_addname_hard(
529 old_isize = (
int)dp->i_d.di_size;
532 memcpy(oldsfp, sfp, old_isize);
539 oldsfep = xfs_dir2_sf_firstentry(oldsfp),
540 add_datasize = xfs_dir2_data_entsize(args->
namelen),
541 eof = (
char *)oldsfep == &buf[old_isize];
543 offset = new_offset + xfs_dir2_data_entsize(oldsfep->
namelen),
544 oldsfep = xfs_dir2_sf_nextentry(oldsfp, oldsfep),
545 eof = (
char *)oldsfep == &buf[old_isize]) {
546 new_offset = xfs_dir2_sf_get_offset(oldsfep);
547 if (offset + add_datasize <= new_offset)
564 nbytes = (
int)((
char *)oldsfep - (
char *)oldsfp);
565 memcpy(sfp, oldsfp, nbytes);
571 xfs_dir2_sf_put_offset(sfep, offset);
573 xfs_dir2_sfe_put_ino(sfp, sfep, args->
inumber);
583 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
584 memcpy(sfep, oldsfep, old_isize - nbytes);
587 dp->i_d.di_size = new_isize;
599 xfs_dir2_sf_addname_pick(
619 size = xfs_dir2_data_entsize(args->
namelen);
621 sfep = xfs_dir2_sf_firstentry(sfp);
628 for (i = 0; i < sfp->
count; i++) {
630 holefit = offset + size <= xfs_dir2_sf_get_offset(sfep);
631 offset = xfs_dir2_sf_get_offset(sfep) +
632 xfs_dir2_data_entsize(sfep->
namelen);
633 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
647 if (used + (holefit ? 0 : size) > mp->m_dirblksize)
662 if (used + size > mp->m_dirblksize)
695 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp);
697 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
698 ASSERT(xfs_dir2_sf_get_offset(sfep) >= offset);
702 xfs_dir2_sf_get_offset(sfep) +
703 xfs_dir2_data_entsize(sfep->namelen);
707 ASSERT((
char *)sfep - (
char *)sfp == dp->i_d.di_size);
710 (
uint)
sizeof(xfs_dir2_block_tail_t) <=
711 dp->i_mount->m_dirblksize);
728 trace_xfs_dir2_sf_create(args);
733 ASSERT(dp->i_d.di_size == 0);
745 ASSERT(dp->i_df.if_bytes == 0);
747 size = xfs_dir2_sf_hdr_size(i8count);
760 xfs_dir2_sf_put_parent_ino(sfp, pino);
762 dp->i_d.di_size =
size;
791 ASSERT(XFS_FORCED_SHUTDOWN(mp));
795 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
800 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->
i8count));
805 if (xfs_dir2_dataptr_to_db(mp, *offset) > mp->m_dirdatablk)
814 dot_offset = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
816 dotdot_offset = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
822 if (*offset <= dot_offset) {
823 if (filldir(dirent,
".", 1, dot_offset & 0x7fffffff, dp->i_ino,
DT_DIR)) {
824 *offset = dot_offset & 0x7fffffff;
832 if (*offset <= dotdot_offset) {
834 if (filldir(dirent,
"..", 2, dotdot_offset & 0x7fffffff, ino,
DT_DIR)) {
835 *offset = dotdot_offset & 0x7fffffff;
843 sfep = xfs_dir2_sf_firstentry(sfp);
844 for (i = 0; i < sfp->
count; i++) {
845 off = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk,
846 xfs_dir2_sf_get_offset(sfep));
849 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
854 if (filldir(dirent, (
char *)sfep->
name, sfep->
namelen,
856 *offset = off & 0x7fffffff;
859 sfep = xfs_dir2_sf_nextentry(sfp, sfep);
862 *offset = xfs_dir2_db_off_to_dataptr(mp, mp->m_dirdatablk + 1, 0) &
883 trace_xfs_dir2_sf_lookup(args);
893 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
896 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
899 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->
i8count));
912 args->
name[0] ==
'.' && args->
name[1] ==
'.') {
921 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->
count;
922 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
928 cmp = dp->i_mount->m_dirnameops->compname(args, sfep->
name,
966 trace_xfs_dir2_sf_removename(args);
971 oldsize = (
int)dp->i_d.di_size;
976 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
979 ASSERT(dp->i_df.if_bytes == oldsize);
987 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp); i < sfp->
count;
988 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
1004 byteoff = (
int)((
char *)sfep - (
char *)sfp);
1005 entsize = xfs_dir2_sf_entsize(sfp, args->
namelen);
1006 newsize = oldsize - entsize;
1010 if (byteoff + entsize < oldsize)
1011 memmove((
char *)sfp + byteoff, (
char *)sfp + byteoff + entsize,
1012 oldsize - (byteoff + entsize));
1017 dp->i_d.di_size = newsize;
1027 if (args->
inumber > XFS_DIR2_MAX_SHORT_INUM) {
1028 if (sfp->i8count == 1)
1029 xfs_dir2_sf_toino4(args);
1048 #if XFS_BIG_INUMS || defined(DEBUG)
1057 trace_xfs_dir2_sf_replace(args);
1066 ASSERT(XFS_FORCED_SHUTDOWN(dp->i_mount));
1069 ASSERT(dp->i_df.if_bytes == dp->i_d.di_size);
1072 ASSERT(dp->i_d.di_size >= xfs_dir2_sf_hdr_size(sfp->
i8count));
1077 if (args->
inumber > XFS_DIR2_MAX_SHORT_INUM && sfp->
i8count == 0) {
1099 xfs_dir2_sf_toino8(args);
1110 args->
name[0] ==
'.' && args->
name[1] ==
'.') {
1111 #if XFS_BIG_INUMS || defined(DEBUG)
1115 xfs_dir2_sf_put_parent_ino(sfp, args->
inumber);
1121 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp);
1123 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep)) {
1126 #if XFS_BIG_INUMS || defined(DEBUG)
1130 xfs_dir2_sfe_put_ino(sfp, sfep, args->
inumber);
1137 if (i == sfp->
count) {
1141 xfs_dir2_sf_toino4(args);
1150 if (ino > XFS_DIR2_MAX_SHORT_INUM &&
1151 args->
inumber <= XFS_DIR2_MAX_SHORT_INUM) {
1156 xfs_dir2_sf_toino4(args);
1163 if (ino <= XFS_DIR2_MAX_SHORT_INUM &&
1164 args->
inumber > XFS_DIR2_MAX_SHORT_INUM) {
1198 trace_xfs_dir2_sf_toino4(args);
1207 oldsize = dp->i_df.if_bytes;
1211 memcpy(buf, oldsfp, oldsize);
1217 (oldsfp->
count + 1) *
1235 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp),
1236 oldsfep = xfs_dir2_sf_firstentry(oldsfp);
1238 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep),
1239 oldsfep = xfs_dir2_sf_nextentry(oldsfp, oldsfep)) {
1240 sfep->namelen = oldsfep->namelen;
1241 sfep->offset = oldsfep->offset;
1242 memcpy(sfep->name, oldsfep->name, sfep->namelen);
1243 xfs_dir2_sfe_put_ino(sfp, sfep,
1250 dp->i_d.di_size = newsize;
1273 trace_xfs_dir2_sf_toino8(args);
1282 oldsize = dp->i_df.if_bytes;
1286 memcpy(buf, oldsfp, oldsize);
1292 (oldsfp->
count + 1) *
1310 for (i = 0, sfep = xfs_dir2_sf_firstentry(sfp),
1311 oldsfep = xfs_dir2_sf_firstentry(oldsfp);
1313 i++, sfep = xfs_dir2_sf_nextentry(sfp, sfep),
1314 oldsfep = xfs_dir2_sf_nextentry(oldsfp, oldsfep)) {
1315 sfep->namelen = oldsfep->namelen;
1316 sfep->offset = oldsfep->offset;
1317 memcpy(sfep->name, oldsfep->name, sfep->namelen);
1318 xfs_dir2_sfe_put_ino(sfp, sfep,
1325 dp->i_d.di_size = newsize;