1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
16 #include "err_protos.h"
21 static struct cred zerocr
;
22 static struct fsxattr zerofsx
;
23 static xfs_ino_t orphanage_ino
;
25 static struct xfs_name xfs_name_dot
= {(unsigned char *)".",
30 * When we're checking directory inodes, we're allowed to set a directory's
31 * dotdot entry to zero to signal that the parent needs to be reconnected
32 * during phase 6. If we're handling a shortform directory the ifork
33 * verifiers will fail, so temporarily patch out this canary so that we can
34 * verify the rest of the fork and move on to fixing the dir.
40 struct xfs_mount
*mp
= ip
->i_mount
;
41 const struct xfs_dir_ops
*dops
;
42 struct xfs_ifork
*ifp
;
43 struct xfs_dir2_sf_hdr
*sfp
;
46 bool parent_bypass
= false;
49 dops
= libxfs_dir_get_ops(mp
, NULL
);
51 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
52 sfp
= (struct xfs_dir2_sf_hdr
*)ifp
->if_u1
.if_data
;
56 * If this is a shortform directory, phase4 may have set the parent
57 * inode to zero to indicate that it must be fixed. Temporarily
58 * set a valid parent so that the directory verifier will pass.
60 if (size
> offsetof(struct xfs_dir2_sf_hdr
, parent
) &&
61 size
>= xfs_dir2_sf_hdr_size(sfp
->i8count
)) {
62 old_parent
= dops
->sf_get_parent_ino(sfp
);
63 if (old_parent
== 0) {
64 dops
->sf_put_parent_ino(sfp
, mp
->m_sb
.sb_rootino
);
69 fa
= libxfs_default_ifork_ops
.verify_dir(ip
);
73 dops
->sf_put_parent_ino(sfp
, old_parent
);
78 static struct xfs_ifork_ops phase6_ifork_ops
= {
79 .verify_attr
= xfs_attr_shortform_verify
,
80 .verify_dir
= phase6_verify_dir
,
81 .verify_symlink
= xfs_symlink_shortform_verify
,
85 * Data structures used to keep track of directories where the ".."
86 * entries are updated. These must be rebuilt after the initial pass
88 typedef struct dotdot_update
{
89 struct list_head list
;
90 ino_tree_node_t
*irec
;
95 static LIST_HEAD(dotdot_update_list
);
96 static int dotdot_update
;
101 ino_tree_node_t
*irec
,
104 dotdot_update_t
*dir
= malloc(sizeof(dotdot_update_t
));
107 do_error(_("malloc failed add_dotdot_update (%zu bytes)\n"),
108 sizeof(dotdot_update_t
));
110 INIT_LIST_HEAD(&dir
->list
);
113 dir
->ino_offset
= ino_offset
;
115 list_add(&dir
->list
, &dotdot_update_list
);
119 * Data structures and routines to keep track of directory entries
120 * and whether their leaf entry has been seen. Also used for name
121 * duplicate checking and rebuilding step if required.
123 typedef struct dir_hash_ent
{
124 struct dir_hash_ent
*nextbyaddr
; /* next in addr bucket */
125 struct dir_hash_ent
*nextbyhash
; /* next in name bucket */
126 struct dir_hash_ent
*nextbyorder
; /* next in order added */
127 xfs_dahash_t hashval
; /* hash value of name */
128 uint32_t address
; /* offset of data entry */
129 xfs_ino_t inum
; /* inode num of entry */
130 short junkit
; /* name starts with / */
131 short seen
; /* have seen leaf entry */
132 struct xfs_name name
;
135 typedef struct dir_hash_tab
{
136 int size
; /* size of hash tables */
137 int names_duped
; /* 1 = ent names malloced */
138 dir_hash_ent_t
*first
; /* ptr to first added entry */
139 dir_hash_ent_t
*last
; /* ptr to last added entry */
140 dir_hash_ent_t
**byhash
; /* ptr to name hash buckets */
141 dir_hash_ent_t
**byaddr
; /* ptr to addr hash buckets */
144 #define DIR_HASH_TAB_SIZE(n) \
145 (sizeof(dir_hash_tab_t) + (sizeof(dir_hash_ent_t *) * (n) * 2))
146 #define DIR_HASH_FUNC(t,a) ((a) % (t)->size)
149 * Track the contents of the freespace table in a directory.
151 typedef struct freetab
{
152 int naents
; /* expected number of data blocks */
153 int nents
; /* number of data blocks processed */
155 xfs_dir2_data_off_t v
;
159 #define FREETAB_SIZE(n) \
160 (offsetof(freetab_t, ents) + (sizeof(struct freetab_ent) * (n)))
162 #define DIR_HASH_CK_OK 0
163 #define DIR_HASH_CK_DUPLEAF 1
164 #define DIR_HASH_CK_BADHASH 2
165 #define DIR_HASH_CK_NODATA 3
166 #define DIR_HASH_CK_NOLEAF 4
167 #define DIR_HASH_CK_BADSTALE 5
168 #define DIR_HASH_CK_TOTAL 6
171 * Need to handle CRC and validation errors specially here. If there is a
172 * validator error, re-read without the verifier so that we get a buffer we can
173 * check and repair. Re-attach the ops to the buffer after the read so that when
174 * it is rewritten the CRC is recalculated.
176 * If the buffer was not read, we return an error. If the buffer was read but
177 * had a CRC or corruption error, we reread it without the verifier and if it is
178 * read successfully we increment *crc_error and return 0. Otherwise we
179 * return the read error.
183 struct xfs_inode
*ip
,
185 xfs_daddr_t mappedbno
,
186 struct xfs_buf
**bpp
,
187 const struct xfs_buf_ops
*ops
,
193 error
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
196 if (error
!= EFSBADCRC
&& error
!= EFSCORRUPTED
)
199 error2
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
200 XFS_DATA_FORK
, NULL
);
210 * Returns 0 if the name already exists (ie. a duplicate)
215 dir_hash_tab_t
*hashtab
,
222 xfs_dahash_t hash
= 0;
228 struct xfs_name xname
;
230 ASSERT(!hashtab
->names_duped
);
236 junk
= name
[0] == '/';
237 byaddr
= DIR_HASH_FUNC(hashtab
, addr
);
241 hash
= mp
->m_dirnameops
->hashname(&xname
);
242 byhash
= DIR_HASH_FUNC(hashtab
, hash
);
245 * search hash bucket for existing name.
247 for (p
= hashtab
->byhash
[byhash
]; p
; p
= p
->nextbyhash
) {
248 if (p
->hashval
== hash
&& p
->name
.len
== namelen
) {
249 if (memcmp(p
->name
.name
, name
, namelen
) == 0) {
258 if ((p
= malloc(sizeof(*p
))) == NULL
)
259 do_error(_("malloc failed in dir_hash_add (%zu bytes)\n"),
262 p
->nextbyaddr
= hashtab
->byaddr
[byaddr
];
263 hashtab
->byaddr
[byaddr
] = p
;
265 hashtab
->last
->nextbyorder
= p
;
268 p
->nextbyorder
= NULL
;
271 if (!(p
->junkit
= junk
)) {
273 p
->nextbyhash
= hashtab
->byhash
[byhash
];
274 hashtab
->byhash
[byhash
] = p
;
285 * checks to see if any data entries are not in the leaf blocks
289 dir_hash_tab_t
*hashtab
)
294 for (i
= 0; i
< hashtab
->size
; i
++) {
295 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
305 dir_hash_tab_t
*hashtab
,
309 static char *seevalstr
[DIR_HASH_CK_TOTAL
];
313 seevalstr
[DIR_HASH_CK_OK
] = _("ok");
314 seevalstr
[DIR_HASH_CK_DUPLEAF
] = _("duplicate leaf");
315 seevalstr
[DIR_HASH_CK_BADHASH
] = _("hash value mismatch");
316 seevalstr
[DIR_HASH_CK_NODATA
] = _("no data entry");
317 seevalstr
[DIR_HASH_CK_NOLEAF
] = _("no leaf entry");
318 seevalstr
[DIR_HASH_CK_BADSTALE
] = _("bad stale count");
322 if (seeval
== DIR_HASH_CK_OK
&& dir_hash_unseen(hashtab
))
323 seeval
= DIR_HASH_CK_NOLEAF
;
324 if (seeval
== DIR_HASH_CK_OK
)
326 do_warn(_("bad hash table for directory inode %" PRIu64
" (%s): "),
327 ip
->i_ino
, seevalstr
[seeval
]);
329 do_warn(_("rebuilding\n"));
331 do_warn(_("would rebuild\n"));
337 dir_hash_tab_t
*hashtab
)
343 for (i
= 0; i
< hashtab
->size
; i
++) {
344 for (p
= hashtab
->byaddr
[i
]; p
; p
= n
) {
346 if (hashtab
->names_duped
)
347 free((void *)p
->name
.name
);
354 static dir_hash_tab_t
*
358 dir_hash_tab_t
*hashtab
;
361 hsize
= size
/ (16 * 4);
366 if ((hashtab
= calloc(DIR_HASH_TAB_SIZE(hsize
), 1)) == NULL
)
367 do_error(_("calloc failed in dir_hash_init\n"));
368 hashtab
->size
= hsize
;
369 hashtab
->byhash
= (dir_hash_ent_t
**)((char *)hashtab
+
370 sizeof(dir_hash_tab_t
));
371 hashtab
->byaddr
= (dir_hash_ent_t
**)((char *)hashtab
+
372 sizeof(dir_hash_tab_t
) + sizeof(dir_hash_ent_t
*) * hsize
);
378 dir_hash_tab_t
*hashtab
,
380 xfs_dir2_dataptr_t addr
)
385 i
= DIR_HASH_FUNC(hashtab
, addr
);
386 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
387 if (p
->address
!= addr
)
390 return DIR_HASH_CK_DUPLEAF
;
391 if (p
->junkit
== 0 && p
->hashval
!= hash
)
392 return DIR_HASH_CK_BADHASH
;
394 return DIR_HASH_CK_OK
;
396 return DIR_HASH_CK_NODATA
;
400 dir_hash_update_ftype(
401 dir_hash_tab_t
*hashtab
,
402 xfs_dir2_dataptr_t addr
,
408 i
= DIR_HASH_FUNC(hashtab
, addr
);
409 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
410 if (p
->address
!= addr
)
412 p
->name
.type
= ftype
;
417 * checks to make sure leafs match a data entry, and that the stale
422 dir_hash_tab_t
*hashtab
,
423 xfs_dir2_leaf_entry_t
*ents
,
431 for (i
= j
= 0; i
< count
; i
++) {
432 if (be32_to_cpu(ents
[i
].address
) == XFS_DIR2_NULL_DATAPTR
) {
436 rval
= dir_hash_see(hashtab
, be32_to_cpu(ents
[i
].hashval
),
437 be32_to_cpu(ents
[i
].address
));
438 if (rval
!= DIR_HASH_CK_OK
)
441 return j
== stale
? DIR_HASH_CK_OK
: DIR_HASH_CK_BADSTALE
;
445 * Convert name pointers into locally allocated memory.
446 * This must only be done after all the entries have been added.
449 dir_hash_dup_names(dir_hash_tab_t
*hashtab
)
454 if (hashtab
->names_duped
)
457 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
458 name
= malloc(p
->name
.len
);
459 memcpy(name
, p
->name
.name
, p
->name
.len
);
462 hashtab
->names_duped
= 1;
466 * Given a block number in a fork, return the next valid block number
468 * If this is the last block number then NULLFILEOFF is returned.
470 * This was originally in the kernel, but only used in xfs_repair.
474 xfs_trans_t
*tp
, /* transaction pointer */
475 xfs_inode_t
*ip
, /* incore inode */
476 xfs_fileoff_t
*bnop
, /* current block */
477 int whichfork
) /* data or attr fork */
479 xfs_fileoff_t bno
; /* current block */
480 int error
; /* error return value */
481 xfs_bmbt_irec_t got
; /* current extent value */
482 struct xfs_ifork
*ifp
; /* inode fork pointer */
483 struct xfs_iext_cursor icur
;
485 if (XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_BTREE
&&
486 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_EXTENTS
&&
487 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_LOCAL
)
489 if (XFS_IFORK_FORMAT(ip
, whichfork
) == XFS_DINODE_FMT_LOCAL
) {
493 ifp
= XFS_IFORK_PTR(ip
, whichfork
);
494 if (!(ifp
->if_flags
& XFS_IFEXTENTS
) &&
495 (error
= -libxfs_iread_extents(tp
, ip
, whichfork
)))
498 if (!libxfs_iext_lookup_extent(ip
, ifp
, bno
, &icur
, &got
))
501 *bnop
= got
.br_startoff
< bno
? bno
: got
.br_startoff
;
511 do_error(_("ran out of disk space!\n"));
513 do_error(_("xfs_trans_reserve returned %d\n"), err
);
517 mk_rbmino(xfs_mount_t
*mp
)
526 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
534 i
= -libxfs_trans_alloc_rollable(mp
, 10, &tp
);
538 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
541 _("couldn't iget realtime bitmap inode -- error - %d\n"),
545 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
546 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
548 VFS_I(ip
)->i_mode
= S_IFREG
;
549 ip
->i_d
.di_version
= vers
;
550 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
551 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
553 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
555 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
556 if (ip
->i_d
.di_version
== 3) {
557 VFS_I(ip
)->i_version
= 1;
558 ip
->i_d
.di_flags2
= 0;
559 times
|= XFS_ICHGTIME_CREATE
;
561 libxfs_trans_ichgtime(tp
, ip
, times
);
566 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
567 ip
->i_df
.if_bytes
= 0;
568 ip
->i_df
.if_u1
.if_root
= NULL
;
570 ip
->i_d
.di_size
= mp
->m_sb
.sb_rbmblocks
* mp
->m_sb
.sb_blocksize
;
575 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
576 error
= -libxfs_trans_commit(tp
);
578 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
581 * then allocate blocks for file and fill with zeroes (stolen
584 blocks
= mp
->m_sb
.sb_rbmblocks
+
585 XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) - 1;
586 error
= -libxfs_trans_alloc_rollable(mp
, blocks
, &tp
);
590 libxfs_trans_ijoin(tp
, ip
, 0);
592 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
593 nmap
= XFS_BMAP_MAX_NMAP
;
594 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
595 (xfs_extlen_t
)(mp
->m_sb
.sb_rbmblocks
- bno
),
596 0, mp
->m_sb
.sb_rbmblocks
, map
, &nmap
);
599 _("couldn't allocate realtime bitmap, error = %d\n"),
602 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
603 libxfs_device_zero(mp
->m_ddev_targp
,
604 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
605 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
606 bno
+= ep
->br_blockcount
;
609 error
= -libxfs_trans_commit(tp
);
612 _("allocation of the realtime bitmap failed, error = %d\n"),
619 fill_rbmino(xfs_mount_t
*mp
)
633 error
= -libxfs_trans_alloc_rollable(mp
, 10, &tp
);
637 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
640 _("couldn't iget realtime bitmap inode -- error - %d\n"),
644 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
646 * fill the file one block at a time
649 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0, 1, &map
, &nmap
);
650 if (error
|| nmap
!= 1) {
652 _("couldn't map realtime bitmap block %" PRIu64
", error = %d\n"),
656 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
658 error
= -libxfs_trans_read_buf(
660 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
661 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
665 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime bitmap inode %" PRIu64
"\n"),
666 bno
, map
.br_startblock
, mp
->m_sb
.sb_rbmino
);
670 memmove(bp
->b_addr
, bmp
, mp
->m_sb
.sb_blocksize
);
672 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
674 bmp
= (xfs_rtword_t
*)((intptr_t) bmp
+ mp
->m_sb
.sb_blocksize
);
678 error
= -libxfs_trans_commit(tp
);
680 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
686 fill_rsumino(xfs_mount_t
*mp
)
695 xfs_fileoff_t end_bno
;
700 end_bno
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
702 error
= -libxfs_trans_alloc_rollable(mp
, 10, &tp
);
706 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
709 _("couldn't iget realtime summary inode -- error - %d\n"),
713 while (bno
< end_bno
) {
715 * fill the file one block at a time
718 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0, 1, &map
, &nmap
);
719 if (error
|| nmap
!= 1) {
721 _("couldn't map realtime summary inode block %" PRIu64
", error = %d\n"),
725 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
727 error
= -libxfs_trans_read_buf(
729 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
730 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
734 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime summary inode %" PRIu64
"\n"),
735 bno
, map
.br_startblock
, mp
->m_sb
.sb_rsumino
);
740 memmove(bp
->b_addr
, smp
, mp
->m_sb
.sb_blocksize
);
742 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
744 smp
= (xfs_suminfo_t
*)((intptr_t)smp
+ mp
->m_sb
.sb_blocksize
);
748 error
= -libxfs_trans_commit(tp
);
750 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
756 mk_rsumino(xfs_mount_t
*mp
)
766 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
774 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
778 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
781 _("couldn't iget realtime summary inode -- error - %d\n"),
785 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
786 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
788 VFS_I(ip
)->i_mode
= S_IFREG
;
789 ip
->i_d
.di_version
= vers
;
790 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
791 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
793 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
795 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
796 if (ip
->i_d
.di_version
== 3) {
797 VFS_I(ip
)->i_version
= 1;
798 ip
->i_d
.di_flags2
= 0;
799 times
|= XFS_ICHGTIME_CREATE
;
801 libxfs_trans_ichgtime(tp
, ip
, times
);
806 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
807 ip
->i_df
.if_bytes
= 0;
808 ip
->i_df
.if_u1
.if_root
= NULL
;
810 ip
->i_d
.di_size
= mp
->m_rsumsize
;
815 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
816 error
= -libxfs_trans_commit(tp
);
818 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
821 * then allocate blocks for file and fill with zeroes (stolen
824 nsumblocks
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
825 blocks
= nsumblocks
+ XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) - 1;
826 error
= -libxfs_trans_alloc_rollable(mp
, blocks
, &tp
);
830 libxfs_trans_ijoin(tp
, ip
, 0);
832 while (bno
< nsumblocks
) {
833 nmap
= XFS_BMAP_MAX_NMAP
;
834 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
835 (xfs_extlen_t
)(nsumblocks
- bno
),
836 0, nsumblocks
, map
, &nmap
);
839 _("couldn't allocate realtime summary inode, error = %d\n"),
842 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
843 libxfs_device_zero(mp
->m_ddev_targp
,
844 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
845 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
846 bno
+= ep
->br_blockcount
;
849 error
= -libxfs_trans_commit(tp
);
852 _("allocation of the realtime summary ino failed, error = %d\n"),
859 * makes a new root directory.
862 mk_root_dir(xfs_mount_t
*mp
)
868 const mode_t mode
= 0755;
869 ino_tree_node_t
*irec
;
874 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
878 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rootino
, 0, 0, &ip
);
880 do_error(_("could not iget root inode -- error - %d\n"), error
);
884 * take care of the core -- initialization from xfs_ialloc()
886 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
887 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
889 VFS_I(ip
)->i_mode
= mode
|S_IFDIR
;
890 ip
->i_d
.di_version
= vers
;
891 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
892 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
894 set_nlink(VFS_I(ip
), 1); /* account for . */
896 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
897 if (ip
->i_d
.di_version
== 3) {
898 VFS_I(ip
)->i_version
= 1;
899 ip
->i_d
.di_flags2
= 0;
900 times
|= XFS_ICHGTIME_CREATE
;
902 libxfs_trans_ichgtime(tp
, ip
, times
);
904 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
909 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
910 ip
->i_df
.if_bytes
= 0;
911 ip
->i_df
.if_u1
.if_root
= NULL
;
914 * initialize the directory
916 ip
->d_ops
= mp
->m_dir_inode_ops
;
917 libxfs_dir_init(tp
, ip
, ip
);
919 error
= -libxfs_trans_commit(tp
);
921 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
925 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
926 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
927 set_inode_isadir(irec
, XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
) -
932 * orphanage name == lost+found
935 mk_orphanage(xfs_mount_t
*mp
)
941 ino_tree_node_t
*irec
;
945 const int mode
= 0755;
947 struct xfs_name xname
;
950 * check for an existing lost+found first, if it exists, return
951 * its inode. Otherwise, we can create it. Bad lost+found inodes
952 * would have been cleared in phase3 and phase4.
955 i
= -libxfs_iget(mp
, NULL
, mp
->m_sb
.sb_rootino
, 0, &pip
,
956 &xfs_default_ifork_ops
);
958 do_error(_("%d - couldn't iget root inode to obtain %s\n"),
961 xname
.name
= (unsigned char *)ORPHANAGE
;
962 xname
.len
= strlen(ORPHANAGE
);
963 xname
.type
= XFS_DIR3_FT_DIR
;
965 if (libxfs_dir_lookup(NULL
, pip
, &xname
, &ino
, NULL
) == 0)
969 * could not be found, create it
971 nres
= XFS_MKDIR_SPACE_RES(mp
, xname
.len
);
972 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
, nres
, 0, 0, &tp
);
977 * use iget/ijoin instead of trans_iget because the ialloc
978 * wrapper can commit the transaction and start a new one
980 /* i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip,
981 &xfs_default_ifork_ops);
983 do_error(_("%d - couldn't iget root inode to make %s\n"),
986 error
= -libxfs_inode_alloc(&tp
, pip
, mode
|S_IFDIR
,
987 1, 0, &zerocr
, &zerofsx
, &ip
);
989 do_error(_("%s inode allocation failed %d\n"),
992 inc_nlink(VFS_I(ip
)); /* account for . */
995 irec
= find_inode_rec(mp
,
996 XFS_INO_TO_AGNO(mp
, ino
),
997 XFS_INO_TO_AGINO(mp
, ino
));
1001 * This inode is allocated from a newly created inode
1002 * chunk and therefore did not exist when inode chunks
1003 * were processed in phase3. Add this group of inodes to
1004 * the entry avl tree as if they were discovered in phase3.
1006 irec
= set_inode_free_alloc(mp
, XFS_INO_TO_AGNO(mp
, ino
),
1007 XFS_INO_TO_AGINO(mp
, ino
));
1008 alloc_ex_data(irec
);
1010 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++)
1011 set_inode_free(irec
, i
);
1014 ino_offset
= get_inode_offset(mp
, ino
, irec
);
1017 * Mark the inode allocated to lost+found as used in the AVL tree
1018 * so it is not skipped in phase 7
1020 set_inode_used(irec
, ino_offset
);
1021 add_inode_ref(irec
, ino_offset
);
1024 * now that we know the transaction will stay around,
1025 * add the root inode to it
1027 libxfs_trans_ijoin(tp
, pip
, 0);
1030 * create the actual entry
1032 error
= -libxfs_dir_createname(tp
, pip
, &xname
, ip
->i_ino
, nres
);
1035 _("can't make %s, createname error %d\n"),
1039 * bump up the link count in the root directory to account
1040 * for .. in the new directory
1042 inc_nlink(VFS_I(pip
));
1043 add_inode_ref(find_inode_rec(mp
,
1044 XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
1045 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
)), 0);
1049 libxfs_trans_log_inode(tp
, pip
, XFS_ILOG_CORE
);
1050 libxfs_dir_init(tp
, ip
, pip
);
1051 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1052 error
= -libxfs_trans_commit(tp
);
1054 do_error(_("%s directory creation failed -- bmapf error %d\n"),
1059 add_inode_reached(irec
,ino_offset
);
1065 * move a file to the orphange.
1070 xfs_ino_t ino
, /* inode # to be moved */
1071 int isa_dir
) /* 1 if inode is a directory */
1073 xfs_inode_t
*orphanage_ip
;
1074 xfs_ino_t entry_ino_num
;
1078 unsigned char fname
[MAXPATHLEN
+ 1];
1081 ino_tree_node_t
*irec
;
1083 struct xfs_name xname
;
1086 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu",
1087 (unsigned long long)ino
);
1089 err
= -libxfs_iget(mp
, NULL
, orphanage_ino
, 0, &orphanage_ip
,
1090 &xfs_default_ifork_ops
);
1092 do_error(_("%d - couldn't iget orphanage inode\n"), err
);
1094 * Make sure the filename is unique in the lost+found
1097 while (libxfs_dir_lookup(NULL
, orphanage_ip
, &xname
, &entry_ino_num
,
1099 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu.%d",
1100 (unsigned long long)ino
, ++incr
);
1102 /* Orphans may not have a proper parent, so use custom ops here */
1103 err
= -libxfs_iget(mp
, NULL
, ino
, 0, &ino_p
, &phase6_ifork_ops
);
1105 do_error(_("%d - couldn't iget disconnected inode\n"), err
);
1107 xname
.type
= libxfs_mode_to_ftype(VFS_I(ino_p
)->i_mode
);
1110 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, orphanage_ino
),
1111 XFS_INO_TO_AGINO(mp
, orphanage_ino
));
1113 ino_offset
= XFS_INO_TO_AGINO(mp
, orphanage_ino
) -
1115 nres
= XFS_DIRENTER_SPACE_RES(mp
, fnamelen
) +
1116 XFS_DIRENTER_SPACE_RES(mp
, 2);
1117 err
= -libxfs_dir_lookup(NULL
, ino_p
, &xfs_name_dotdot
,
1118 &entry_ino_num
, NULL
);
1120 ASSERT(err
== ENOENT
);
1122 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1126 _("space reservation failed (%d), filesystem may be out of space\n"),
1129 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1130 libxfs_trans_ijoin(tp
, ino_p
, 0);
1132 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1136 _("name create failed in %s (%d), filesystem may be out of space\n"),
1140 add_inode_ref(irec
, ino_offset
);
1142 inc_nlink(VFS_I(orphanage_ip
));
1143 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1145 err
= -libxfs_dir_createname(tp
, ino_p
, &xfs_name_dotdot
,
1146 orphanage_ino
, nres
);
1149 _("creation of .. entry failed (%d), filesystem may be out of space\n"),
1152 inc_nlink(VFS_I(ino_p
));
1153 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1154 err
= -libxfs_trans_commit(tp
);
1157 _("creation of .. entry failed (%d)\n"), err
);
1159 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1163 _("space reservation failed (%d), filesystem may be out of space\n"),
1166 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1167 libxfs_trans_ijoin(tp
, ino_p
, 0);
1170 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1174 _("name create failed in %s (%d), filesystem may be out of space\n"),
1178 add_inode_ref(irec
, ino_offset
);
1180 inc_nlink(VFS_I(orphanage_ip
));
1181 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1184 * don't replace .. value if it already points
1185 * to us. that'll pop a libxfs/kernel ASSERT.
1187 if (entry_ino_num
!= orphanage_ino
) {
1188 err
= -libxfs_dir_replace(tp
, ino_p
,
1189 &xfs_name_dotdot
, orphanage_ino
,
1193 _("name replace op failed (%d), filesystem may be out of space\n"),
1197 err
= -libxfs_trans_commit(tp
);
1200 _("orphanage name replace op failed (%d)\n"), err
);
1205 * use the remove log reservation as that's
1206 * more accurate. we're only creating the
1207 * links, we're not doing the inode allocation
1208 * also accounted for in the create
1210 nres
= XFS_DIRENTER_SPACE_RES(mp
, xname
.len
);
1211 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
1215 _("space reservation failed (%d), filesystem may be out of space\n"),
1218 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1219 libxfs_trans_ijoin(tp
, ino_p
, 0);
1221 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
, ino
,
1225 _("name create failed in %s (%d), filesystem may be out of space\n"),
1229 set_nlink(VFS_I(ino_p
), 1);
1230 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1231 err
= -libxfs_trans_commit(tp
);
1234 _("orphanage name create failed (%d)\n"), err
);
1236 libxfs_irele(ino_p
);
1237 libxfs_irele(orphanage_ip
);
1247 do_warn(msg
, iname
, ino1
, ino2
);
1250 do_warn(_(", marking entry to be junked\n"));
1254 do_warn(_(", would junk entry\n"));
1258 /* Find and invalidate all the directory's buffers. */
1261 struct xfs_trans
*tp
,
1262 struct xfs_inode
*ip
,
1265 struct xfs_iext_cursor icur
;
1266 struct xfs_bmbt_irec rec
;
1267 struct xfs_ifork
*ifp
;
1268 struct xfs_da_geometry
*geo
;
1270 xfs_dablk_t dabno
, end_dabno
;
1273 if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_EXTENTS
&&
1274 ip
->i_d
.di_format
!= XFS_DINODE_FMT_BTREE
)
1277 geo
= tp
->t_mountp
->m_dir_geo
;
1278 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
1279 for_each_xfs_iext(ifp
, &icur
, &rec
) {
1280 dabno
= xfs_dir2_db_to_da(geo
, rec
.br_startoff
+
1282 end_dabno
= xfs_dir2_db_to_da(geo
, rec
.br_startoff
+
1284 for (; dabno
<= end_dabno
; dabno
+= geo
->fsbcount
) {
1286 error
= -libxfs_da_get_buf(tp
, ip
, dabno
, -2, &bp
,
1292 libxfs_trans_binval(tp
, bp
);
1293 libxfs_trans_brelse(tp
, bp
);
1301 * Unexpected failure during the rebuild will leave the entries in
1302 * lost+found on the next run
1306 longform_dir2_rebuild(
1310 ino_tree_node_t
*irec
,
1312 dir_hash_tab_t
*hashtab
)
1317 xfs_fileoff_t lastblock
;
1323 * trash directory completely and rebuild from scratch using the
1324 * name/inode pairs in the hash table
1327 do_warn(_("rebuilding directory inode %" PRIu64
"\n"), ino
);
1330 * first attempt to locate the parent inode, if it can't be
1331 * found, set it to the root inode and it'll be moved to the
1332 * orphanage later (the inode number here needs to be valid
1333 * for the libxfs_dir_init() call).
1335 pip
.i_ino
= get_inode_parent(irec
, ino_offset
);
1336 if (pip
.i_ino
== NULLFSINO
||
1337 libxfs_dir_ino_validate(mp
, pip
.i_ino
))
1338 pip
.i_ino
= mp
->m_sb
.sb_rootino
;
1340 nres
= XFS_REMOVE_SPACE_RES(mp
);
1341 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1344 libxfs_trans_ijoin(tp
, ip
, 0);
1346 error
= dir_binval(tp
, ip
, XFS_DATA_FORK
);
1350 if ((error
= -libxfs_bmap_last_offset(ip
, &lastblock
, XFS_DATA_FORK
)))
1351 do_error(_("xfs_bmap_last_offset failed -- error - %d\n"),
1354 /* free all data, leaf, node and freespace blocks */
1355 error
= -libxfs_bunmapi(tp
, ip
, 0, lastblock
, XFS_BMAPI_METADATA
, 0,
1358 do_warn(_("xfs_bunmapi failed -- error - %d\n"), error
);
1359 goto out_bmap_cancel
;
1364 error
= -libxfs_dir_init(tp
, ip
, &pip
);
1366 do_warn(_("xfs_dir_init failed -- error - %d\n"), error
);
1367 goto out_bmap_cancel
;
1370 error
= -libxfs_trans_commit(tp
);
1373 _("dir init failed (%d)\n"), error
);
1375 if (ino
== mp
->m_sb
.sb_rootino
)
1376 need_root_dotdot
= 0;
1378 /* go through the hash list and re-add the inodes */
1380 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
1382 if (p
->name
.name
[0] == '/' || (p
->name
.name
[0] == '.' &&
1383 (p
->name
.len
== 1 || (p
->name
.len
== 2 &&
1384 p
->name
.name
[1] == '.'))))
1387 nres
= XFS_CREATE_SPACE_RES(mp
, p
->name
.len
);
1388 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_create
,
1393 libxfs_trans_ijoin(tp
, ip
, 0);
1395 error
= -libxfs_dir_createname(tp
, ip
, &p
->name
, p
->inum
,
1399 _("name create failed in ino %" PRIu64
" (%d), filesystem may be out of space\n"),
1401 goto out_bmap_cancel
;
1404 error
= -libxfs_trans_commit(tp
);
1407 _("name create failed (%d) during rebuild\n"), error
);
1413 libxfs_trans_cancel(tp
);
1419 * Kill a block in a version 2 inode.
1420 * Makes its own transaction.
1434 nres
= XFS_REMOVE_SPACE_RES(mp
);
1435 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1438 libxfs_trans_ijoin(tp
, ip
, 0);
1439 libxfs_trans_bjoin(tp
, bp
);
1440 memset(&args
, 0, sizeof(args
));
1443 args
.whichfork
= XFS_DATA_FORK
;
1444 args
.geo
= mp
->m_dir_geo
;
1445 if (da_bno
>= mp
->m_dir_geo
->leafblk
&& da_bno
< mp
->m_dir_geo
->freeblk
)
1446 error
= -libxfs_da_shrink_inode(&args
, da_bno
, bp
);
1448 error
= -libxfs_dir2_shrink_inode(&args
,
1449 xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
), bp
);
1451 do_error(_("shrink_inode failed inode %" PRIu64
" block %u\n"),
1453 error
= -libxfs_trans_commit(tp
);
1456 _("directory shrink failed (%d)\n"), error
);
1460 * process a data block, also checks for .. entry
1461 * and corrects it to match what we think .. should be
1464 longform_dir2_entry_check_data(
1469 ino_tree_node_t
*current_irec
,
1470 int current_ino_offset
,
1471 struct xfs_buf
**bpp
,
1472 dir_hash_tab_t
*hashtab
,
1473 freetab_t
**freetabp
,
1477 xfs_dir2_dataptr_t addr
;
1478 xfs_dir2_leaf_entry_t
*blp
;
1480 xfs_dir2_block_tail_t
*btp
;
1481 struct xfs_dir2_data_hdr
*d
;
1483 xfs_dir2_data_entry_t
*dep
;
1484 xfs_dir2_data_unused_t
*dup
;
1485 struct xfs_dir2_data_free
*bf
;
1488 char fname
[MAXNAMELEN
+ 1];
1493 ino_tree_node_t
*irec
;
1504 struct xfs_da_args da
= {
1506 .geo
= mp
->m_dir_geo
,
1512 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1514 needscan
= needlog
= 0;
1516 freetab
= *freetabp
;
1518 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, d
);
1519 blp
= xfs_dir2_block_leaf_p(btp
);
1520 endptr
= (char *)blp
;
1521 if (endptr
> (char *)btp
)
1522 endptr
= (char *)btp
;
1523 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1524 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1526 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1528 endptr
= (char *)d
+ mp
->m_dir_geo
->blksize
;
1529 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1530 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1532 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1534 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
1536 /* check for data block beyond expected end */
1537 if (freetab
->naents
<= db
) {
1538 struct freetab_ent e
;
1540 *freetabp
= freetab
= realloc(freetab
, FREETAB_SIZE(db
+ 1));
1542 do_error(_("realloc failed in %s (%zu bytes)\n"),
1543 __func__
, FREETAB_SIZE(db
+ 1));
1547 for (i
= freetab
->naents
; i
< db
; i
++)
1548 freetab
->ents
[i
] = e
;
1549 freetab
->naents
= db
+ 1;
1552 /* check the data block */
1553 while (ptr
< endptr
) {
1555 /* check for freespace */
1556 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1557 if (XFS_DIR2_DATA_FREE_TAG
== be16_to_cpu(dup
->freetag
)) {
1559 /* check for invalid freespace length */
1560 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1561 be16_to_cpu(dup
->length
) == 0 ||
1562 (be16_to_cpu(dup
->length
) &
1563 (XFS_DIR2_DATA_ALIGN
- 1)))
1566 /* check for invalid tag */
1567 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1568 (char *)dup
- (char *)d
)
1571 /* check for block with no data entries */
1572 if ((ptr
== (char *)M_DIROPS(mp
)->data_entry_p(d
)) &&
1573 (ptr
+ be16_to_cpu(dup
->length
) >= endptr
)) {
1579 /* continue at the end of the freespace */
1580 ptr
+= be16_to_cpu(dup
->length
);
1585 /* validate data entry size */
1586 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1587 if (ptr
+ M_DIROPS(mp
)->data_entsize(dep
->namelen
) > endptr
)
1589 if (be16_to_cpu(*M_DIROPS(mp
)->data_entry_tag_p(dep
)) !=
1590 (char *)dep
- (char *)d
)
1592 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1595 /* did we find an empty or corrupt block? */
1596 if (ptr
!= endptr
) {
1599 _("empty data block %u in directory inode %" PRIu64
": "),
1603 ("corrupt block %u in directory inode %" PRIu64
": "),
1607 do_warn(_("junking block\n"));
1608 dir2_kill_block(mp
, ip
, da_bno
, bp
);
1610 do_warn(_("would junk block\n"));
1613 freetab
->ents
[db
].v
= NULLDATAOFF
;
1618 /* update number of data blocks processed */
1619 if (freetab
->nents
< db
+ 1)
1620 freetab
->nents
= db
+ 1;
1622 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, 0, 0, 0, &tp
);
1626 libxfs_trans_ijoin(tp
, ip
, 0);
1627 libxfs_trans_bjoin(tp
, bp
);
1628 libxfs_trans_bhold(tp
, bp
);
1629 if (be32_to_cpu(d
->magic
) != wantmagic
) {
1631 _("bad directory block magic # %#x for directory inode %" PRIu64
" block %d: "),
1632 be32_to_cpu(d
->magic
), ip
->i_ino
, da_bno
);
1634 do_warn(_("fixing magic # to %#x\n"), wantmagic
);
1635 d
->magic
= cpu_to_be32(wantmagic
);
1638 do_warn(_("would fix magic # to %#x\n"), wantmagic
);
1641 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1643 * look at each entry. reference inode pointed to by each
1644 * entry in the incore inode tree.
1645 * if not a directory, set reached flag, increment link count
1646 * if a directory and reached, mark entry as to be deleted.
1647 * if a directory, check to see if recorded parent
1648 * matches current inode #,
1649 * if so, then set reached flag, increment link count
1650 * of current and child dir inodes, push the child
1651 * directory inode onto the directory stack.
1652 * if current inode != parent, then mark entry to be deleted.
1654 while (ptr
< endptr
) {
1655 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1656 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1659 _("directory inode %" PRIu64
" block %u has consecutive free entries: "),
1663 do_warn(_("joining together\n"));
1664 len
= be16_to_cpu(dup
->length
);
1665 libxfs_dir2_data_use_free(&da
, bp
, dup
,
1666 ptr
- (char *)d
, len
, &needlog
,
1668 libxfs_dir2_data_make_free(&da
, bp
,
1669 ptr
- (char *)d
, len
, &needlog
,
1672 do_warn(_("would join together\n"));
1674 ptr
+= be16_to_cpu(dup
->length
);
1678 addr
= xfs_dir2_db_off_to_dataptr(mp
->m_dir_geo
, db
,
1680 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1681 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1682 inum
= be64_to_cpu(dep
->inumber
);
1685 * skip bogus entries (leading '/'). they'll be deleted
1686 * later. must still log it, else we leak references to
1689 if (dep
->name
[0] == '/') {
1692 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1696 memmove(fname
, dep
->name
, dep
->namelen
);
1697 fname
[dep
->namelen
] = '\0';
1698 ASSERT(inum
!= NULLFSINO
);
1700 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, inum
),
1701 XFS_INO_TO_AGINO(mp
, inum
));
1705 _("entry \"%s\" in directory inode %" PRIu64
" points to non-existent inode %" PRIu64
""),
1706 fname
, ip
->i_ino
, inum
)) {
1708 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1712 ino_offset
= XFS_INO_TO_AGINO(mp
, inum
) - irec
->ino_startnum
;
1715 * if it's a free inode, blow out the entry.
1716 * by now, any inode that we think is free
1719 if (is_inode_free(irec
, ino_offset
)) {
1722 _("entry \"%s\" in directory inode %" PRIu64
" points to free inode %" PRIu64
),
1723 fname
, ip
->i_ino
, inum
)) {
1725 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1731 * check if this inode is lost+found dir in the root
1733 if (inum
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
1735 * if it's not a directory, trash it
1737 if (!inode_isadir(irec
, ino_offset
)) {
1740 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
1741 ORPHANAGE
, inum
, ip
->i_ino
)) {
1743 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1748 * if this is a dup, it will be picked up below,
1749 * otherwise, mark it as the orphanage for later.
1752 orphanage_ino
= inum
;
1756 * check for duplicate names in directory.
1758 if (!dir_hash_add(mp
, hashtab
, addr
, inum
, dep
->namelen
,
1759 dep
->name
, M_DIROPS(mp
)->data_get_ftype(dep
))) {
1762 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
1763 fname
, inum
, ip
->i_ino
)) {
1765 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1767 if (inum
== orphanage_ino
)
1773 * if just scanning to rebuild a directory due to a ".."
1774 * update, just continue
1780 * skip the '..' entry since it's checked when the
1781 * directory is reached by something else. if it never
1782 * gets reached, it'll be moved to the orphanage and we'll
1783 * take care of it then. If it doesn't exist at all, the
1784 * directory needs to be rebuilt first before being added
1787 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
1788 dep
->name
[1] == '.') {
1790 /* ".." should be in the first block */
1793 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is not in the the first block"), fname
,
1796 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1801 ASSERT(no_modify
|| !verify_inum(mp
, inum
));
1803 * special case the . entry. we know there's only one
1804 * '.' and only '.' points to itself because bogus entries
1805 * got trashed in phase 3 if there were > 1.
1806 * bump up link count for '.' but don't set reached
1807 * until we're actually reached by another directory
1808 * '..' is already accounted for or will be taken care
1809 * of when directory is moved to orphanage.
1811 if (ip
->i_ino
== inum
) {
1813 (dep
->name
[0] == '.' && dep
->namelen
== 1));
1814 add_inode_ref(current_irec
, current_ino_offset
);
1816 dep
!= M_DIROPS(mp
)->data_entry_p(d
)) {
1817 /* "." should be the first entry */
1820 _("entry \"%s\" in dir %" PRIu64
" is not the first entry"),
1821 fname
, inum
, ip
->i_ino
)) {
1823 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1830 * skip entries with bogus inumbers if we're in no modify mode
1832 if (no_modify
&& verify_inum(mp
, inum
))
1835 /* validate ftype field if supported */
1836 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
1840 dir_ftype
= M_DIROPS(mp
)->data_get_ftype(dep
);
1841 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
1843 if (dir_ftype
!= ino_ftype
) {
1846 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1847 dir_ftype
, ino_ftype
,
1851 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1852 dir_ftype
, ino_ftype
,
1854 M_DIROPS(mp
)->data_put_ftype(dep
,
1856 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1857 dir_hash_update_ftype(hashtab
, addr
,
1864 * check easy case first, regular inode, just bump
1865 * the link count and continue
1867 if (!inode_isadir(irec
, ino_offset
)) {
1868 add_inode_reached(irec
, ino_offset
);
1871 parent
= get_inode_parent(irec
, ino_offset
);
1872 ASSERT(parent
!= 0);
1875 * bump up the link counts in parent and child
1876 * directory but if the link doesn't agree with
1877 * the .. in the child, blow out the entry.
1878 * if the directory has already been reached,
1879 * blow away the entry also.
1881 if (is_inode_reached(irec
, ino_offset
)) {
1884 _("entry \"%s\" in dir %" PRIu64
" points to an already connected directory inode %" PRIu64
"\n"),
1885 fname
, ip
->i_ino
, inum
);
1886 } else if (parent
== ip
->i_ino
) {
1887 add_inode_reached(irec
, ino_offset
);
1888 add_inode_ref(current_irec
, current_ino_offset
);
1889 } else if (parent
== NULLFSINO
) {
1890 /* ".." was missing, but this entry refers to it,
1891 so, set it as the parent and mark for rebuild */
1893 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
1894 fname
, ip
->i_ino
, inum
);
1895 set_inode_parent(irec
, ino_offset
, ip
->i_ino
);
1896 add_inode_reached(irec
, ino_offset
);
1897 add_inode_ref(current_irec
, current_ino_offset
);
1898 add_dotdot_update(XFS_INO_TO_AGNO(mp
, inum
), irec
,
1903 _("entry \"%s\" in dir inode %" PRIu64
" inconsistent with .. value (%" PRIu64
") in ino %" PRIu64
"\n"),
1904 fname
, ip
->i_ino
, parent
, inum
);
1907 if (inum
== orphanage_ino
)
1912 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1915 _("\twill clear entry \"%s\"\n"),
1918 do_warn(_("\twould clear entry \"%s\"\n"),
1923 *num_illegal
+= nbad
;
1925 libxfs_dir2_data_freescan_int(mp
->m_dir_geo
, M_DIROPS(mp
),
1928 libxfs_dir2_data_log_header(&da
, bp
);
1929 error
= -libxfs_trans_commit(tp
);
1932 _("directory block fixing failed (%d)\n"), error
);
1934 /* record the largest free space in the freetab for later checking */
1935 bf
= M_DIROPS(mp
)->data_bestfree_p(d
);
1936 freetab
->ents
[db
].v
= be16_to_cpu(bf
[0].length
);
1937 freetab
->ents
[db
].s
= 0;
1940 /* check v5 metadata */
1942 __check_dir3_header(
1943 struct xfs_mount
*mp
,
1952 if (be64_to_cpu(owner
) != ino
) {
1954 _("expected owner inode %" PRIu64
", got %llu, directory block %" PRIu64
"\n"),
1955 ino
, (unsigned long long)be64_to_cpu(owner
), bp
->b_bn
);
1958 /* verify block number */
1959 if (be64_to_cpu(blkno
) != bp
->b_bn
) {
1961 _("expected block %" PRIu64
", got %llu, directory inode %" PRIu64
"\n"),
1962 bp
->b_bn
, (unsigned long long)be64_to_cpu(blkno
), ino
);
1966 if (platform_uuid_compare(uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
1968 _("wrong FS UUID, directory inode %" PRIu64
" block %" PRIu64
"\n"),
1978 struct xfs_mount
*mp
,
1982 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
1984 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
1990 struct xfs_mount
*mp
,
1994 struct xfs_dir3_blk_hdr
*info
= bp
->b_addr
;
1996 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2001 * Check contents of leaf-form block.
2004 longform_dir2_check_leaf(
2007 dir_hash_tab_t
*hashtab
,
2015 xfs_dir2_leaf_t
*leaf
;
2016 xfs_dir2_leaf_tail_t
*ltp
;
2018 struct xfs_dir2_leaf_entry
*ents
;
2019 struct xfs_dir3_icleaf_hdr leafhdr
;
2023 da_bno
= mp
->m_dir_geo
->leafblk
;
2024 error
= dir_read_buf(ip
, da_bno
, -1, &bp
, &xfs_dir3_leaf1_buf_ops
,
2026 if (error
== EFSBADCRC
|| error
== EFSCORRUPTED
|| fixit
) {
2028 _("leaf block %u for directory inode %" PRIu64
" bad CRC\n"),
2033 _("can't read block %u for directory inode %" PRIu64
", error %d\n"),
2034 da_bno
, ip
->i_ino
, error
);
2039 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2040 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2041 ltp
= xfs_dir2_leaf_tail_p(mp
->m_dir_geo
, leaf
);
2042 bestsp
= xfs_dir2_leaf_bests_p(ltp
);
2043 if (!(leafhdr
.magic
== XFS_DIR2_LEAF1_MAGIC
||
2044 leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) ||
2045 leafhdr
.forw
|| leafhdr
.back
||
2046 leafhdr
.count
< leafhdr
.stale
||
2048 M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2049 (char *)&ents
[leafhdr
.count
] > (char *)bestsp
) {
2051 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2057 if (leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) {
2058 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2065 seeval
= dir_hash_see_all(hashtab
, ents
, leafhdr
.count
, leafhdr
.stale
);
2066 if (dir_hash_check(hashtab
, ip
, seeval
)) {
2070 badtail
= freetab
->nents
!= be32_to_cpu(ltp
->bestcount
);
2071 for (i
= 0; !badtail
&& i
< be32_to_cpu(ltp
->bestcount
); i
++) {
2072 freetab
->ents
[i
].s
= 1;
2073 badtail
= freetab
->ents
[i
].v
!= be16_to_cpu(bestsp
[i
]);
2077 _("leaf block %u for directory inode %" PRIu64
" bad tail\n"),
2087 * Check contents of the node blocks (leaves)
2088 * Looks for matching hash values for the data entries.
2091 longform_dir2_check_node(
2094 dir_hash_tab_t
*hashtab
,
2100 xfs_dir2_free_t
*free
;
2102 xfs_dir2_leaf_t
*leaf
;
2103 xfs_fileoff_t next_da_bno
;
2106 struct xfs_dir2_leaf_entry
*ents
;
2107 struct xfs_dir3_icleaf_hdr leafhdr
;
2108 struct xfs_dir3_icfree_hdr freehdr
;
2113 for (da_bno
= mp
->m_dir_geo
->leafblk
, next_da_bno
= 0;
2114 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->freeblk
;
2115 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2116 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2117 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2121 * we need to use the da3 node verifier here as it handles the
2122 * fact that reading the leaf hash tree blocks can return either
2123 * leaf or node blocks and calls the correct verifier. If we get
2124 * a node block, then we'll skip it below based on a magic
2127 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2128 &xfs_da3_node_buf_ops
, &fixit
);
2131 _("can't read leaf block %u for directory inode %" PRIu64
", error %d\n"),
2132 da_bno
, ip
->i_ino
, error
);
2136 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2137 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2138 if (!(leafhdr
.magic
== XFS_DIR2_LEAFN_MAGIC
||
2139 leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2140 leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2141 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
)) {
2143 _("unknown magic number %#x for block %u in directory inode %" PRIu64
"\n"),
2144 leafhdr
.magic
, da_bno
, ip
->i_ino
);
2149 /* check v5 metadata */
2150 if (leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2151 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2152 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2160 if (leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2161 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2167 * If there's a validator error, we need to ensure that we got
2168 * the right ops on the buffer for when we write it back out.
2170 bp
->b_ops
= &xfs_dir3_leafn_buf_ops
;
2171 if (leafhdr
.count
> M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2172 leafhdr
.count
< leafhdr
.stale
) {
2174 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2179 seeval
= dir_hash_see_all(hashtab
, ents
,
2180 leafhdr
.count
, leafhdr
.stale
);
2182 if (seeval
!= DIR_HASH_CK_OK
)
2185 if (dir_hash_check(hashtab
, ip
, seeval
))
2188 for (da_bno
= mp
->m_dir_geo
->freeblk
, next_da_bno
= 0;
2189 next_da_bno
!= NULLFILEOFF
;
2190 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2191 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2192 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2195 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2196 &xfs_dir3_free_buf_ops
, &fixit
);
2199 _("can't read freespace block %u for directory inode %" PRIu64
", error %d\n"),
2200 da_bno
, ip
->i_ino
, error
);
2204 M_DIROPS(mp
)->free_hdr_from_disk(&freehdr
, free
);
2205 bests
= M_DIROPS(mp
)->free_bests_p(free
);
2206 fdb
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2207 if (!(freehdr
.magic
== XFS_DIR2_FREE_MAGIC
||
2208 freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) ||
2210 (fdb
- xfs_dir2_byte_to_db(mp
->m_dir_geo
, XFS_DIR2_FREE_OFFSET
)) *
2211 M_DIROPS(mp
)->free_max_bests(mp
->m_dir_geo
) ||
2212 freehdr
.nvalid
< freehdr
.nused
) {
2214 _("free block %u for directory inode %" PRIu64
" bad header\n"),
2220 if (freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) {
2221 error
= check_dir3_header(mp
, bp
, ip
->i_ino
);
2227 for (i
= used
= 0; i
< freehdr
.nvalid
; i
++) {
2228 if (i
+ freehdr
.firstdb
>= freetab
->nents
||
2229 freetab
->ents
[i
+ freehdr
.firstdb
].v
!=
2230 be16_to_cpu(bests
[i
])) {
2232 _("free block %u entry %i for directory ino %" PRIu64
" bad\n"),
2233 da_bno
, i
, ip
->i_ino
);
2237 used
+= be16_to_cpu(bests
[i
]) != NULLDATAOFF
;
2238 freetab
->ents
[i
+ freehdr
.firstdb
].s
= 1;
2240 if (used
!= freehdr
.nused
) {
2242 _("free block %u for directory inode %" PRIu64
" bad nused\n"),
2249 for (i
= 0; i
< freetab
->nents
; i
++) {
2250 if ((freetab
->ents
[i
].s
== 0) &&
2251 (freetab
->ents
[i
].v
!= NULLDATAOFF
)) {
2253 _("missing freetab entry %u for directory inode %" PRIu64
"\n"),
2262 * If a directory is corrupt, we need to read in as many entries as possible,
2263 * destroy the entry and create a new one with recovered name/inode pairs.
2264 * (ie. get libxfs to do all the grunt work)
2267 longform_dir2_entry_check(xfs_mount_t
*mp
,
2272 ino_tree_node_t
*irec
,
2274 dir_hash_tab_t
*hashtab
)
2276 struct xfs_buf
**bplist
;
2283 xfs_fileoff_t next_da_bno
;
2287 struct xfs_da_args args
;
2290 freetab
= malloc(FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2292 do_error(_("malloc failed in %s (%" PRId64
" bytes)\n"),
2294 FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2297 freetab
->naents
= ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
;
2299 for (i
= 0; i
< freetab
->naents
; i
++) {
2300 freetab
->ents
[i
].v
= NULLDATAOFF
;
2301 freetab
->ents
[i
].s
= 0;
2303 num_bps
= freetab
->naents
;
2304 bplist
= calloc(num_bps
, sizeof(struct xfs_buf
*));
2306 do_error(_("calloc failed in %s (%zu bytes)\n"),
2307 __func__
, num_bps
* sizeof(struct xfs_buf
*));
2309 /* is this a block, leaf, or node directory? */
2311 args
.geo
= mp
->m_dir_geo
;
2312 libxfs_dir2_isblock(&args
, &isblock
);
2313 libxfs_dir2_isleaf(&args
, &isleaf
);
2315 /* check directory "data" blocks (ie. name/inode pairs) */
2316 for (da_bno
= 0, next_da_bno
= 0;
2317 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->leafblk
;
2318 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2319 const struct xfs_buf_ops
*ops
;
2321 struct xfs_dir2_data_hdr
*d
;
2323 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2324 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
)) {
2326 * if this is the first block, there isn't anything we
2327 * can recover so we just trash it.
2336 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2337 if (db
>= num_bps
) {
2338 /* more data blocks than expected */
2340 bplist
= realloc(bplist
, num_bps
* sizeof(struct xfs_buf
*));
2342 do_error(_("realloc failed in %s (%zu bytes)\n"),
2344 num_bps
* sizeof(struct xfs_buf
*));
2348 ops
= &xfs_dir3_block_buf_ops
;
2350 ops
= &xfs_dir3_data_buf_ops
;
2352 error
= dir_read_buf(ip
, da_bno
, -1, &bplist
[db
], ops
, &fixit
);
2355 _("can't read data block %u for directory inode %" PRIu64
" error %d\n"),
2356 da_bno
, ino
, error
);
2360 * we try to read all "data" blocks, but if we are in
2361 * block form and we fail, there isn't anything else to
2362 * read, and nothing we can do but trash it.
2371 /* check v5 metadata */
2372 d
= bplist
[db
]->b_addr
;
2373 if (be32_to_cpu(d
->magic
) == XFS_DIR3_BLOCK_MAGIC
||
2374 be32_to_cpu(d
->magic
) == XFS_DIR3_DATA_MAGIC
) {
2375 struct xfs_buf
*bp
= bplist
[db
];
2377 error
= check_dir3_header(mp
, bp
, ino
);
2384 longform_dir2_entry_check_data(mp
, ip
, num_illegal
, need_dot
,
2385 irec
, ino_offset
, &bplist
[db
], hashtab
,
2386 &freetab
, da_bno
, isblock
);
2388 fixit
|= (*num_illegal
!= 0) || dir2_is_badino(ino
) || *need_dot
;
2390 if (!dotdot_update
) {
2391 /* check btree and freespace */
2393 struct xfs_dir2_data_hdr
*block
;
2394 xfs_dir2_block_tail_t
*btp
;
2395 xfs_dir2_leaf_entry_t
*blp
;
2397 block
= bplist
[0]->b_addr
;
2398 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, block
);
2399 blp
= xfs_dir2_block_leaf_p(btp
);
2400 seeval
= dir_hash_see_all(hashtab
, blp
,
2401 be32_to_cpu(btp
->count
),
2402 be32_to_cpu(btp
->stale
));
2403 if (dir_hash_check(hashtab
, ip
, seeval
))
2405 } else if (isleaf
) {
2406 fixit
|= longform_dir2_check_leaf(mp
, ip
, hashtab
,
2409 fixit
|= longform_dir2_check_node(mp
, ip
, hashtab
,
2414 if (!no_modify
&& (fixit
|| dotdot_update
)) {
2415 dir_hash_dup_names(hashtab
);
2416 for (i
= 0; i
< num_bps
; i
++)
2418 libxfs_putbuf(bplist
[i
]);
2419 longform_dir2_rebuild(mp
, ino
, ip
, irec
, ino_offset
, hashtab
);
2423 for (i
= 0; i
< num_bps
; i
++)
2425 libxfs_putbuf(bplist
[i
]);
2433 * shortform directory v2 processing routines -- entry verification and
2434 * bad entry deletion (pruning).
2436 static struct xfs_dir2_sf_entry
*
2437 shortform_dir2_junk(
2438 struct xfs_mount
*mp
,
2439 struct xfs_dir2_sf_hdr
*sfp
,
2440 struct xfs_dir2_sf_entry
*sfep
,
2447 struct xfs_dir2_sf_entry
*next_sfep
;
2451 if (lino
== orphanage_ino
)
2454 next_elen
= M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
);
2455 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2458 * if we are just checking, simply return the pointer to the next entry
2459 * here so that the checking loop can continue.
2462 do_warn(_("would junk entry\n"));
2467 * now move all the remaining entries down over the junked entry and
2468 * clear the newly unused bytes at the tail of the directory region.
2470 next_len
= *max_size
- ((intptr_t)next_sfep
- (intptr_t)sfp
);
2471 *max_size
-= next_elen
;
2472 *bytes_deleted
+= next_elen
;
2474 memmove(sfep
, next_sfep
, next_len
);
2475 memset((void *)((intptr_t)sfep
+ next_len
), 0, next_elen
);
2480 * WARNING: drop the index i by one so it matches the decremented count
2481 * for accurate comparisons in the loop test
2486 do_warn(_("junking entry\n"));
2493 shortform_dir2_entry_check(xfs_mount_t
*mp
,
2497 ino_tree_node_t
*current_irec
,
2498 int current_ino_offset
,
2499 dir_hash_tab_t
*hashtab
)
2503 struct xfs_dir2_sf_hdr
*sfp
;
2504 struct xfs_dir2_sf_entry
*sfep
;
2505 struct xfs_dir2_sf_entry
*next_sfep
;
2506 struct xfs_ifork
*ifp
;
2507 struct ino_tree_node
*irec
;
2514 char fname
[MAXNAMELEN
+ 1];
2518 sfp
= (struct xfs_dir2_sf_hdr
*) ifp
->if_u1
.if_data
;
2522 max_size
= ifp
->if_bytes
;
2523 ASSERT(ip
->i_d
.di_size
<= ifp
->if_bytes
);
2526 * if just rebuild a directory due to a "..", update and return
2528 if (dotdot_update
) {
2529 parent
= get_inode_parent(current_irec
, current_ino_offset
);
2532 _("would set .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2536 _("setting .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2538 M_DIROPS(mp
)->sf_put_parent_ino(sfp
, parent
);
2545 * no '.' entry in shortform dirs, just bump up ref count by 1
2546 * '..' was already (or will be) accounted for and checked when
2547 * the directory is reached or will be taken care of when the
2548 * directory is moved to orphanage.
2550 add_inode_ref(current_irec
, current_ino_offset
);
2553 * Initialise i8 counter -- the parent inode number counts as well.
2555 i8
= M_DIROPS(mp
)->sf_get_parent_ino(sfp
) > XFS_DIR2_MAX_SHORT_INUM
;
2558 * now run through entries, stop at first bad entry, don't need
2559 * to skip over '..' since that's encoded in its own field and
2560 * no need to worry about '.' since it doesn't exist.
2562 sfep
= next_sfep
= xfs_dir2_sf_firstentry(sfp
);
2564 for (i
= 0; i
< sfp
->count
&& max_size
>
2565 (intptr_t)next_sfep
- (intptr_t)sfp
;
2566 sfep
= next_sfep
, i
++) {
2569 lino
= M_DIROPS(mp
)->sf_get_ino(sfp
, sfep
);
2571 namelen
= sfep
->namelen
;
2573 ASSERT(no_modify
|| namelen
> 0);
2575 if (no_modify
&& namelen
== 0) {
2577 * if we're really lucky, this is
2578 * the last entry in which case we
2579 * can use the dir size to set the
2580 * namelen value. otherwise, forget
2581 * it because we're not going to be
2582 * able to find the next entry.
2586 if (i
== sfp
->count
- 1) {
2587 namelen
= ip
->i_d
.di_size
-
2588 ((intptr_t) &sfep
->name
[0] -
2592 * don't process the rest of the directory,
2593 * break out of processing loop
2597 } else if (no_modify
&& (intptr_t) sfep
- (intptr_t) sfp
+
2598 + M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)
2599 > ip
->i_d
.di_size
) {
2602 if (i
== sfp
->count
- 1) {
2603 namelen
= ip
->i_d
.di_size
-
2604 ((intptr_t) &sfep
->name
[0] -
2608 * don't process the rest of the directory,
2609 * break out of processing loop
2615 memmove(fname
, sfep
->name
, sfep
->namelen
);
2616 fname
[sfep
->namelen
] = '\0';
2618 ASSERT(no_modify
|| (lino
!= NULLFSINO
&& lino
!= 0));
2619 ASSERT(no_modify
|| !verify_inum(mp
, lino
));
2622 * Also skip entries with bogus inode numbers if we're
2623 * in no modify mode.
2626 if (no_modify
&& verify_inum(mp
, lino
)) {
2627 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2631 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, lino
),
2632 XFS_INO_TO_AGINO(mp
, lino
));
2636 _("entry \"%s\" in shortform directory %" PRIu64
" references non-existent inode %" PRIu64
"\n"),
2638 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2639 &max_size
, &i
, &bytes_deleted
,
2644 ino_offset
= XFS_INO_TO_AGINO(mp
, lino
) - irec
->ino_startnum
;
2647 * if it's a free inode, blow out the entry.
2648 * by now, any inode that we think is free
2651 if (is_inode_free(irec
, ino_offset
)) {
2653 _("entry \"%s\" in shortform directory inode %" PRIu64
" points to free inode %" PRIu64
"\n"),
2655 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2656 &max_size
, &i
, &bytes_deleted
,
2661 * check if this inode is lost+found dir in the root
2663 if (ino
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
2665 * if it's not a directory, trash it
2667 if (!inode_isadir(irec
, ino_offset
)) {
2669 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
2670 ORPHANAGE
, lino
, ino
);
2671 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2672 lino
, &max_size
, &i
,
2673 &bytes_deleted
, ino_dirty
);
2677 * if this is a dup, it will be picked up below,
2678 * otherwise, mark it as the orphanage for later.
2681 orphanage_ino
= lino
;
2684 * check for duplicate names in directory.
2686 if (!dir_hash_add(mp
, hashtab
, (xfs_dir2_dataptr_t
)
2687 (sfep
- xfs_dir2_sf_firstentry(sfp
)),
2688 lino
, sfep
->namelen
, sfep
->name
,
2689 M_DIROPS(mp
)->sf_get_ftype(sfep
))) {
2691 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
2693 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2694 &max_size
, &i
, &bytes_deleted
,
2699 if (!inode_isadir(irec
, ino_offset
)) {
2701 * check easy case first, regular inode, just bump
2704 add_inode_reached(irec
, ino_offset
);
2706 parent
= get_inode_parent(irec
, ino_offset
);
2709 * bump up the link counts in parent and child.
2710 * directory but if the link doesn't agree with
2711 * the .. in the child, blow out the entry
2713 if (is_inode_reached(irec
, ino_offset
)) {
2715 _("entry \"%s\" in directory inode %" PRIu64
2716 " references already connected inode %" PRIu64
".\n"),
2718 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2719 lino
, &max_size
, &i
,
2720 &bytes_deleted
, ino_dirty
);
2722 } else if (parent
== ino
) {
2723 add_inode_reached(irec
, ino_offset
);
2724 add_inode_ref(current_irec
, current_ino_offset
);
2725 } else if (parent
== NULLFSINO
) {
2726 /* ".." was missing, but this entry refers to it,
2727 so, set it as the parent and mark for rebuild */
2729 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
2731 set_inode_parent(irec
, ino_offset
, ino
);
2732 add_inode_reached(irec
, ino_offset
);
2733 add_inode_ref(current_irec
, current_ino_offset
);
2734 add_dotdot_update(XFS_INO_TO_AGNO(mp
, lino
),
2738 _("entry \"%s\" in directory inode %" PRIu64
2739 " not consistent with .. value (%" PRIu64
2740 ") in inode %" PRIu64
",\n"),
2741 fname
, ino
, parent
, lino
);
2742 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2743 lino
, &max_size
, &i
,
2744 &bytes_deleted
, ino_dirty
);
2749 /* validate ftype field if supported */
2750 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
2754 dir_ftype
= M_DIROPS(mp
)->sf_get_ftype(sfep
);
2755 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
2757 if (dir_ftype
!= ino_ftype
) {
2760 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2761 dir_ftype
, ino_ftype
,
2765 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2766 dir_ftype
, ino_ftype
,
2768 M_DIROPS(mp
)->sf_put_ftype(sfep
,
2770 dir_hash_update_ftype(hashtab
,
2771 (xfs_dir2_dataptr_t
)(sfep
- xfs_dir2_sf_firstentry(sfp
)),
2778 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
2782 * go onto next entry - we have to take entries with bad namelen
2783 * into account in no modify mode since we calculate size based
2786 ASSERT(no_modify
|| bad_sfnamelen
== 0);
2787 next_sfep
= (struct xfs_dir2_sf_entry
*)((intptr_t)sfep
+
2789 ? M_DIROPS(mp
)->sf_entsize(sfp
, namelen
)
2790 : M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)));
2793 if (sfp
->i8count
!= i8
) {
2795 do_warn(_("would fix i8count in inode %" PRIu64
"\n"),
2799 struct xfs_dir2_sf_entry
*tmp_sfep
;
2801 tmp_sfep
= next_sfep
;
2802 process_sf_dir2_fixi8(mp
, sfp
, &tmp_sfep
);
2804 (intptr_t)next_sfep
-
2806 next_sfep
= tmp_sfep
;
2810 do_warn(_("fixing i8count in inode %" PRIu64
"\n"),
2816 * sync up sizes if required
2818 if (*ino_dirty
&& bytes_deleted
> 0) {
2820 libxfs_idata_realloc(ip
, -bytes_deleted
, XFS_DATA_FORK
);
2821 ip
->i_d
.di_size
-= bytes_deleted
;
2824 if (ip
->i_d
.di_size
!= ip
->i_df
.if_bytes
) {
2825 ASSERT(ip
->i_df
.if_bytes
== (xfs_fsize_t
)
2826 ((intptr_t) next_sfep
- (intptr_t) sfp
));
2827 ip
->i_d
.di_size
= (xfs_fsize_t
)
2828 ((intptr_t) next_sfep
- (intptr_t) sfp
);
2830 _("setting size to %" PRId64
" bytes to reflect junked entries\n"),
2837 * processes all reachable inodes in directories
2842 xfs_agnumber_t agno
,
2843 ino_tree_node_t
*irec
,
2849 dir_hash_tab_t
*hashtab
;
2851 int dirty
, num_illegal
, error
, nres
;
2853 ino
= XFS_AGINO_TO_INO(mp
, agno
, irec
->ino_startnum
+ ino_offset
);
2856 * open up directory inode, check all entries,
2857 * then call prune_dir_entries to remove all
2858 * remaining illegal directory entries.
2861 ASSERT(!is_inode_refchecked(irec
, ino_offset
) || dotdot_update
);
2863 error
= -libxfs_iget(mp
, NULL
, ino
, 0, &ip
, &phase6_ifork_ops
);
2867 _("couldn't map inode %" PRIu64
", err = %d\n"),
2871 _("couldn't map inode %" PRIu64
", err = %d\n"),
2874 * see below for what we're doing if this
2875 * is root. Why do we need to do this here?
2876 * to ensure that the root doesn't show up
2877 * as being disconnected in the no_modify case.
2879 if (mp
->m_sb
.sb_rootino
== ino
) {
2880 add_inode_reached(irec
, 0);
2881 add_inode_ref(irec
, 0);
2885 add_inode_refchecked(irec
, 0);
2889 need_dot
= dirty
= num_illegal
= 0;
2891 if (mp
->m_sb
.sb_rootino
== ino
) {
2893 * mark root inode reached and bump up
2894 * link count for root inode to account
2895 * for '..' entry since the root inode is
2896 * never reached by a parent. we know
2897 * that root's '..' is always good --
2898 * guaranteed by phase 3 and/or below.
2900 add_inode_reached(irec
, ino_offset
);
2903 add_inode_refchecked(irec
, ino_offset
);
2905 hashtab
= dir_hash_init(ip
->i_d
.di_size
);
2908 * look for bogus entries
2910 switch (ip
->i_d
.di_format
) {
2911 case XFS_DINODE_FMT_EXTENTS
:
2912 case XFS_DINODE_FMT_BTREE
:
2914 * also check for missing '.' in longform dirs.
2915 * missing .. entries are added if required when
2916 * the directory is connected to lost+found. but
2917 * we need to create '.' entries here.
2919 longform_dir2_entry_check(mp
, ino
, ip
,
2920 &num_illegal
, &need_dot
,
2925 case XFS_DINODE_FMT_LOCAL
:
2927 * using the remove reservation is overkill
2928 * since at most we'll only need to log the
2929 * inode but it's easier than wedging a
2930 * new define in ourselves.
2932 nres
= no_modify
? 0 : XFS_REMOVE_SPACE_RES(mp
);
2933 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
2938 libxfs_trans_ijoin(tp
, ip
, 0);
2940 shortform_dir2_entry_check(mp
, ino
, ip
, &dirty
,
2944 ASSERT(dirty
== 0 || (dirty
&& !no_modify
));
2946 libxfs_trans_log_inode(tp
, ip
,
2947 XFS_ILOG_CORE
| XFS_ILOG_DDATA
);
2948 error
= -libxfs_trans_commit(tp
);
2952 libxfs_trans_cancel(tp
);
2959 dir_hash_done(hashtab
);
2962 * if we have to create a .. for /, do it now *before*
2963 * we delete the bogus entries, otherwise the directory
2964 * could transform into a shortform dir which would
2965 * probably cause the simulation to choke. Even
2966 * if the illegal entries get shifted around, it's ok
2967 * because the entries are structurally intact and in
2968 * in hash-value order so the simulation won't get confused
2969 * if it has to move them around.
2971 if (!no_modify
&& need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2972 ASSERT(ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
);
2974 do_warn(_("recreating root directory .. entry\n"));
2976 nres
= XFS_MKDIR_SPACE_RES(mp
, 2);
2977 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
2982 libxfs_trans_ijoin(tp
, ip
, 0);
2984 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dotdot
,
2988 _("can't make \"..\" entry in root inode %" PRIu64
", createname error %d\n"), ino
, error
);
2990 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2991 error
= -libxfs_trans_commit(tp
);
2994 _("root inode \"..\" entry recreation failed (%d)\n"), error
);
2996 need_root_dotdot
= 0;
2997 } else if (need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2998 do_warn(_("would recreate root directory .. entry\n"));
3002 * if we need to create the '.' entry, do so only if
3003 * the directory is a longform dir. if it's been
3004 * turned into a shortform dir, then the inode is ok
3005 * since shortform dirs have no '.' entry and the inode
3006 * has already been committed by prune_lf_dir_entry().
3010 * bump up our link count but don't
3011 * bump up the inode link count. chances
3012 * are good that even though we lost '.'
3013 * the inode link counts reflect '.' so
3014 * leave the inode link count alone and if
3015 * it turns out to be wrong, we'll catch
3018 add_inode_ref(irec
, ino_offset
);
3022 _("would create missing \".\" entry in dir ino %" PRIu64
"\n"),
3024 } else if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
) {
3026 * need to create . entry in longform dir.
3029 _("creating missing \".\" entry in dir ino %" PRIu64
"\n"), ino
);
3031 nres
= XFS_MKDIR_SPACE_RES(mp
, 1);
3032 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3037 libxfs_trans_ijoin(tp
, ip
, 0);
3039 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dot
,
3043 _("can't make \".\" entry in dir ino %" PRIu64
", createname error %d\n"),
3046 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3047 error
= -libxfs_trans_commit(tp
);
3050 _("root inode \".\" entry recreation failed (%d)\n"), error
);
3057 * mark realtime bitmap and summary inodes as reached.
3058 * quota inode will be marked here as well
3061 mark_standalone_inodes(xfs_mount_t
*mp
)
3063 ino_tree_node_t
*irec
;
3066 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rbmino
),
3067 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
));
3069 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
) -
3072 add_inode_reached(irec
, offset
);
3074 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rsumino
),
3075 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
));
3077 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
) -
3080 add_inode_reached(irec
, offset
);
3083 if (mp
->m_sb
.sb_uquotino
3084 && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
3085 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3086 mp
->m_sb
.sb_uquotino
),
3087 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
));
3088 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
)
3089 - irec
->ino_startnum
;
3090 add_inode_reached(irec
, offset
);
3092 if (mp
->m_sb
.sb_gquotino
3093 && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
3094 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3095 mp
->m_sb
.sb_gquotino
),
3096 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
));
3097 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
)
3098 - irec
->ino_startnum
;
3099 add_inode_reached(irec
, offset
);
3101 if (mp
->m_sb
.sb_pquotino
3102 && mp
->m_sb
.sb_pquotino
!= NULLFSINO
) {
3103 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3104 mp
->m_sb
.sb_pquotino
),
3105 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
));
3106 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
)
3107 - irec
->ino_startnum
;
3108 add_inode_reached(irec
, offset
);
3114 check_for_orphaned_inodes(
3116 xfs_agnumber_t agno
,
3117 ino_tree_node_t
*irec
)
3122 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3123 ASSERT(is_inode_confirmed(irec
, i
));
3124 if (is_inode_free(irec
, i
))
3127 if (is_inode_reached(irec
, i
))
3130 ASSERT(inode_isadir(irec
, i
) ||
3131 num_inode_references(irec
, i
) == 0);
3133 ino
= XFS_AGINO_TO_INO(mp
, agno
, i
+ irec
->ino_startnum
);
3134 if (inode_isadir(irec
, i
))
3135 do_warn(_("disconnected dir inode %" PRIu64
", "), ino
);
3137 do_warn(_("disconnected inode %" PRIu64
", "), ino
);
3140 orphanage_ino
= mk_orphanage(mp
);
3141 do_warn(_("moving to %s\n"), ORPHANAGE
);
3142 mv_orphanage(mp
, ino
, inode_isadir(irec
, i
));
3144 do_warn(_("would move to %s\n"), ORPHANAGE
);
3147 * for read-only case, even though the inode isn't
3148 * really reachable, set the flag (and bump our link
3149 * count) anyway to fool phase 7
3151 add_inode_reached(irec
, i
);
3157 struct workqueue
*wq
,
3158 xfs_agnumber_t agno
,
3161 ino_tree_node_t
*irec
;
3163 prefetch_args_t
*pf_args
= arg
;
3165 wait_for_inode_prefetch(pf_args
);
3168 do_log(_(" - agno = %d\n"), agno
);
3170 for (irec
= findfirst_inode_rec(agno
); irec
; irec
= next_ino_rec(irec
)) {
3171 if (irec
->ino_isa_dir
== 0)
3175 sem_post(&pf_args
->ra_count
);
3177 sem_getvalue(&pf_args
->ra_count
, &i
);
3179 "processing inode chunk %p in AG %d (sem count = %d)",
3184 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3185 if (inode_isadir(irec
, i
))
3186 process_dir_inode(wq
->wq_ctx
, agno
, irec
, i
);
3189 cleanup_inode_prefetch(pf_args
);
3193 update_missing_dotdot_entries(
3196 dotdot_update_t
*dir
;
3199 * these entries parents were updated, rebuild them again
3200 * set dotdot_update flag so processing routines do not count links
3203 while (!list_empty(&dotdot_update_list
)) {
3204 dir
= list_entry(dotdot_update_list
.prev
, struct dotdot_update
,
3206 list_del(&dir
->list
);
3207 process_dir_inode(mp
, dir
->agno
, dir
->irec
, dir
->ino_offset
);
3214 struct xfs_mount
*mp
)
3216 do_inode_prefetch(mp
, 0, traverse_function
, false, true);
3220 phase6(xfs_mount_t
*mp
)
3222 ino_tree_node_t
*irec
;
3225 memset(&zerocr
, 0, sizeof(struct cred
));
3226 memset(&zerofsx
, 0, sizeof(struct fsxattr
));
3229 do_log(_("Phase 6 - check inode connectivity...\n"));
3231 incore_ext_teardown(mp
);
3233 add_ino_ex_data(mp
);
3236 * verify existence of root directory - if we have to
3237 * make one, it's ok for the incore data structs not to
3238 * know about it since everything about it (and the other
3239 * inodes in its chunk if a new chunk was created) are ok
3241 if (need_root_inode
) {
3243 do_warn(_("reinitializing root directory\n"));
3245 need_root_inode
= 0;
3246 need_root_dotdot
= 0;
3248 do_warn(_("would reinitialize root directory\n"));
3254 do_warn(_("reinitializing realtime bitmap inode\n"));
3258 do_warn(_("would reinitialize realtime bitmap inode\n"));
3264 do_warn(_("reinitializing realtime summary inode\n"));
3268 do_warn(_("would reinitialize realtime summary inode\n"));
3274 _(" - resetting contents of realtime bitmap and summary inodes\n"));
3275 if (fill_rbmino(mp
)) {
3277 _("Warning: realtime bitmap may be inconsistent\n"));
3280 if (fill_rsumino(mp
)) {
3282 _("Warning: realtime bitmap may be inconsistent\n"));
3286 mark_standalone_inodes(mp
);
3288 do_log(_(" - traversing filesystem ...\n"));
3290 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
3291 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
3294 * we always have a root inode, even if it's free...
3295 * if the root is free, forget it, lost+found is already gone
3297 if (is_inode_free(irec
, 0) || !inode_isadir(irec
, 0)) {
3298 need_root_inode
= 1;
3302 * then process all inodes by walking incore inode tree
3307 * any directories that had updated ".." entries, rebuild them now
3309 update_missing_dotdot_entries(mp
);
3311 do_log(_(" - traversal finished ...\n"));
3312 do_log(_(" - moving disconnected inodes to %s ...\n"),
3316 * move all disconnected inodes to the orphanage
3318 for (i
= 0; i
< glob_agcount
; i
++) {
3319 irec
= findfirst_inode_rec(i
);
3320 while (irec
!= NULL
) {
3321 check_for_orphaned_inodes(mp
, i
, irec
);
3322 irec
= next_ino_rec(irec
);