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 struct xfs_ifork
*ifp
;
42 struct xfs_dir2_sf_hdr
*sfp
;
45 bool parent_bypass
= false;
48 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
49 sfp
= (struct xfs_dir2_sf_hdr
*)ifp
->if_u1
.if_data
;
53 * If this is a shortform directory, phase4 may have set the parent
54 * inode to zero to indicate that it must be fixed. Temporarily
55 * set a valid parent so that the directory verifier will pass.
57 if (size
> offsetof(struct xfs_dir2_sf_hdr
, parent
) &&
58 size
>= xfs_dir2_sf_hdr_size(sfp
->i8count
)) {
59 old_parent
= libxfs_dir2_sf_get_parent_ino(sfp
);
60 if (old_parent
== 0) {
61 libxfs_dir2_sf_put_parent_ino(sfp
, mp
->m_sb
.sb_rootino
);
66 fa
= libxfs_default_ifork_ops
.verify_dir(ip
);
70 libxfs_dir2_sf_put_parent_ino(sfp
, old_parent
);
75 static struct xfs_ifork_ops phase6_ifork_ops
= {
76 .verify_attr
= xfs_attr_shortform_verify
,
77 .verify_dir
= phase6_verify_dir
,
78 .verify_symlink
= xfs_symlink_shortform_verify
,
82 * Data structures used to keep track of directories where the ".."
83 * entries are updated. These must be rebuilt after the initial pass
85 typedef struct dotdot_update
{
86 struct list_head list
;
87 ino_tree_node_t
*irec
;
92 static LIST_HEAD(dotdot_update_list
);
93 static int dotdot_update
;
98 ino_tree_node_t
*irec
,
101 dotdot_update_t
*dir
= malloc(sizeof(dotdot_update_t
));
104 do_error(_("malloc failed add_dotdot_update (%zu bytes)\n"),
105 sizeof(dotdot_update_t
));
107 INIT_LIST_HEAD(&dir
->list
);
110 dir
->ino_offset
= ino_offset
;
112 list_add(&dir
->list
, &dotdot_update_list
);
116 * Data structures and routines to keep track of directory entries
117 * and whether their leaf entry has been seen. Also used for name
118 * duplicate checking and rebuilding step if required.
120 typedef struct dir_hash_ent
{
121 struct dir_hash_ent
*nextbyaddr
; /* next in addr bucket */
122 struct dir_hash_ent
*nextbyhash
; /* next in name bucket */
123 struct dir_hash_ent
*nextbyorder
; /* next in order added */
124 xfs_dahash_t hashval
; /* hash value of name */
125 uint32_t address
; /* offset of data entry */
126 xfs_ino_t inum
; /* inode num of entry */
127 short junkit
; /* name starts with / */
128 short seen
; /* have seen leaf entry */
129 struct xfs_name name
;
132 typedef struct dir_hash_tab
{
133 int size
; /* size of hash tables */
134 int names_duped
; /* 1 = ent names malloced */
135 dir_hash_ent_t
*first
; /* ptr to first added entry */
136 dir_hash_ent_t
*last
; /* ptr to last added entry */
137 dir_hash_ent_t
**byhash
; /* ptr to name hash buckets */
138 dir_hash_ent_t
**byaddr
; /* ptr to addr hash buckets */
141 #define DIR_HASH_TAB_SIZE(n) \
142 (sizeof(dir_hash_tab_t) + (sizeof(dir_hash_ent_t *) * (n) * 2))
143 #define DIR_HASH_FUNC(t,a) ((a) % (t)->size)
146 * Track the contents of the freespace table in a directory.
148 typedef struct freetab
{
149 int naents
; /* expected number of data blocks */
150 int nents
; /* number of data blocks processed */
152 xfs_dir2_data_off_t v
;
156 #define FREETAB_SIZE(n) \
157 (offsetof(freetab_t, ents) + (sizeof(struct freetab_ent) * (n)))
159 #define DIR_HASH_CK_OK 0
160 #define DIR_HASH_CK_DUPLEAF 1
161 #define DIR_HASH_CK_BADHASH 2
162 #define DIR_HASH_CK_NODATA 3
163 #define DIR_HASH_CK_NOLEAF 4
164 #define DIR_HASH_CK_BADSTALE 5
165 #define DIR_HASH_CK_TOTAL 6
168 * Need to handle CRC and validation errors specially here. If there is a
169 * validator error, re-read without the verifier so that we get a buffer we can
170 * check and repair. Re-attach the ops to the buffer after the read so that when
171 * it is rewritten the CRC is recalculated.
173 * If the buffer was not read, we return an error. If the buffer was read but
174 * had a CRC or corruption error, we reread it without the verifier and if it is
175 * read successfully we increment *crc_error and return 0. Otherwise we
176 * return the read error.
180 struct xfs_inode
*ip
,
182 xfs_daddr_t mappedbno
,
183 struct xfs_buf
**bpp
,
184 const struct xfs_buf_ops
*ops
,
190 error
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
193 if (error
!= EFSBADCRC
&& error
!= EFSCORRUPTED
)
196 error2
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
197 XFS_DATA_FORK
, NULL
);
207 * Returns 0 if the name already exists (ie. a duplicate)
212 dir_hash_tab_t
*hashtab
,
219 xfs_dahash_t hash
= 0;
225 struct xfs_name xname
;
227 ASSERT(!hashtab
->names_duped
);
233 junk
= name
[0] == '/';
234 byaddr
= DIR_HASH_FUNC(hashtab
, addr
);
238 hash
= mp
->m_dirnameops
->hashname(&xname
);
239 byhash
= DIR_HASH_FUNC(hashtab
, hash
);
242 * search hash bucket for existing name.
244 for (p
= hashtab
->byhash
[byhash
]; p
; p
= p
->nextbyhash
) {
245 if (p
->hashval
== hash
&& p
->name
.len
== namelen
) {
246 if (memcmp(p
->name
.name
, name
, namelen
) == 0) {
255 if ((p
= malloc(sizeof(*p
))) == NULL
)
256 do_error(_("malloc failed in dir_hash_add (%zu bytes)\n"),
259 p
->nextbyaddr
= hashtab
->byaddr
[byaddr
];
260 hashtab
->byaddr
[byaddr
] = p
;
262 hashtab
->last
->nextbyorder
= p
;
265 p
->nextbyorder
= NULL
;
268 if (!(p
->junkit
= junk
)) {
270 p
->nextbyhash
= hashtab
->byhash
[byhash
];
271 hashtab
->byhash
[byhash
] = p
;
282 * checks to see if any data entries are not in the leaf blocks
286 dir_hash_tab_t
*hashtab
)
291 for (i
= 0; i
< hashtab
->size
; i
++) {
292 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
302 dir_hash_tab_t
*hashtab
,
306 static char *seevalstr
[DIR_HASH_CK_TOTAL
];
310 seevalstr
[DIR_HASH_CK_OK
] = _("ok");
311 seevalstr
[DIR_HASH_CK_DUPLEAF
] = _("duplicate leaf");
312 seevalstr
[DIR_HASH_CK_BADHASH
] = _("hash value mismatch");
313 seevalstr
[DIR_HASH_CK_NODATA
] = _("no data entry");
314 seevalstr
[DIR_HASH_CK_NOLEAF
] = _("no leaf entry");
315 seevalstr
[DIR_HASH_CK_BADSTALE
] = _("bad stale count");
319 if (seeval
== DIR_HASH_CK_OK
&& dir_hash_unseen(hashtab
))
320 seeval
= DIR_HASH_CK_NOLEAF
;
321 if (seeval
== DIR_HASH_CK_OK
)
323 do_warn(_("bad hash table for directory inode %" PRIu64
" (%s): "),
324 ip
->i_ino
, seevalstr
[seeval
]);
326 do_warn(_("rebuilding\n"));
328 do_warn(_("would rebuild\n"));
334 dir_hash_tab_t
*hashtab
)
340 for (i
= 0; i
< hashtab
->size
; i
++) {
341 for (p
= hashtab
->byaddr
[i
]; p
; p
= n
) {
343 if (hashtab
->names_duped
)
344 free((void *)p
->name
.name
);
351 static dir_hash_tab_t
*
355 dir_hash_tab_t
*hashtab
;
358 hsize
= size
/ (16 * 4);
363 if ((hashtab
= calloc(DIR_HASH_TAB_SIZE(hsize
), 1)) == NULL
)
364 do_error(_("calloc failed in dir_hash_init\n"));
365 hashtab
->size
= hsize
;
366 hashtab
->byhash
= (dir_hash_ent_t
**)((char *)hashtab
+
367 sizeof(dir_hash_tab_t
));
368 hashtab
->byaddr
= (dir_hash_ent_t
**)((char *)hashtab
+
369 sizeof(dir_hash_tab_t
) + sizeof(dir_hash_ent_t
*) * hsize
);
375 dir_hash_tab_t
*hashtab
,
377 xfs_dir2_dataptr_t addr
)
382 i
= DIR_HASH_FUNC(hashtab
, addr
);
383 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
384 if (p
->address
!= addr
)
387 return DIR_HASH_CK_DUPLEAF
;
388 if (p
->junkit
== 0 && p
->hashval
!= hash
)
389 return DIR_HASH_CK_BADHASH
;
391 return DIR_HASH_CK_OK
;
393 return DIR_HASH_CK_NODATA
;
397 dir_hash_update_ftype(
398 dir_hash_tab_t
*hashtab
,
399 xfs_dir2_dataptr_t addr
,
405 i
= DIR_HASH_FUNC(hashtab
, addr
);
406 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
407 if (p
->address
!= addr
)
409 p
->name
.type
= ftype
;
414 * checks to make sure leafs match a data entry, and that the stale
419 dir_hash_tab_t
*hashtab
,
420 xfs_dir2_leaf_entry_t
*ents
,
428 for (i
= j
= 0; i
< count
; i
++) {
429 if (be32_to_cpu(ents
[i
].address
) == XFS_DIR2_NULL_DATAPTR
) {
433 rval
= dir_hash_see(hashtab
, be32_to_cpu(ents
[i
].hashval
),
434 be32_to_cpu(ents
[i
].address
));
435 if (rval
!= DIR_HASH_CK_OK
)
438 return j
== stale
? DIR_HASH_CK_OK
: DIR_HASH_CK_BADSTALE
;
442 * Convert name pointers into locally allocated memory.
443 * This must only be done after all the entries have been added.
446 dir_hash_dup_names(dir_hash_tab_t
*hashtab
)
451 if (hashtab
->names_duped
)
454 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
455 name
= malloc(p
->name
.len
);
456 memcpy(name
, p
->name
.name
, p
->name
.len
);
459 hashtab
->names_duped
= 1;
463 * Given a block number in a fork, return the next valid block number
465 * If this is the last block number then NULLFILEOFF is returned.
467 * This was originally in the kernel, but only used in xfs_repair.
471 xfs_trans_t
*tp
, /* transaction pointer */
472 xfs_inode_t
*ip
, /* incore inode */
473 xfs_fileoff_t
*bnop
, /* current block */
474 int whichfork
) /* data or attr fork */
476 xfs_fileoff_t bno
; /* current block */
477 int error
; /* error return value */
478 xfs_bmbt_irec_t got
; /* current extent value */
479 struct xfs_ifork
*ifp
; /* inode fork pointer */
480 struct xfs_iext_cursor icur
;
482 if (XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_BTREE
&&
483 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_EXTENTS
&&
484 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_LOCAL
)
486 if (XFS_IFORK_FORMAT(ip
, whichfork
) == XFS_DINODE_FMT_LOCAL
) {
490 ifp
= XFS_IFORK_PTR(ip
, whichfork
);
491 if (!(ifp
->if_flags
& XFS_IFEXTENTS
) &&
492 (error
= -libxfs_iread_extents(tp
, ip
, whichfork
)))
495 if (!libxfs_iext_lookup_extent(ip
, ifp
, bno
, &icur
, &got
))
498 *bnop
= got
.br_startoff
< bno
? bno
: got
.br_startoff
;
508 do_error(_("ran out of disk space!\n"));
510 do_error(_("xfs_trans_reserve returned %d\n"), err
);
514 mk_rbmino(xfs_mount_t
*mp
)
523 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
531 i
= -libxfs_trans_alloc_rollable(mp
, 10, &tp
);
535 error
= -libxfs_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, &ip
,
536 &xfs_default_ifork_ops
);
539 _("couldn't iget realtime bitmap inode -- error - %d\n"),
543 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
544 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
546 VFS_I(ip
)->i_mode
= S_IFREG
;
547 ip
->i_d
.di_version
= vers
;
548 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
549 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
551 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
553 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
554 if (ip
->i_d
.di_version
== 3) {
555 VFS_I(ip
)->i_version
= 1;
556 ip
->i_d
.di_flags2
= 0;
557 times
|= XFS_ICHGTIME_CREATE
;
559 libxfs_trans_ichgtime(tp
, ip
, times
);
564 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
565 ip
->i_df
.if_bytes
= 0;
566 ip
->i_df
.if_u1
.if_root
= NULL
;
568 ip
->i_d
.di_size
= mp
->m_sb
.sb_rbmblocks
* mp
->m_sb
.sb_blocksize
;
573 libxfs_trans_ijoin(tp
, ip
, 0);
574 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
575 error
= -libxfs_trans_commit(tp
);
577 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
580 * then allocate blocks for file and fill with zeroes (stolen
583 blocks
= mp
->m_sb
.sb_rbmblocks
+
584 XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) - 1;
585 error
= -libxfs_trans_alloc_rollable(mp
, blocks
, &tp
);
589 libxfs_trans_ijoin(tp
, ip
, 0);
591 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
592 nmap
= XFS_BMAP_MAX_NMAP
;
593 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
594 (xfs_extlen_t
)(mp
->m_sb
.sb_rbmblocks
- bno
),
595 0, mp
->m_sb
.sb_rbmblocks
, map
, &nmap
);
598 _("couldn't allocate realtime bitmap, error = %d\n"),
601 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
602 libxfs_device_zero(mp
->m_ddev_targp
,
603 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
604 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
605 bno
+= ep
->br_blockcount
;
608 error
= -libxfs_trans_commit(tp
);
611 _("allocation of the realtime bitmap failed, error = %d\n"),
618 fill_rbmino(xfs_mount_t
*mp
)
632 error
= -libxfs_trans_alloc_rollable(mp
, 10, &tp
);
636 error
= -libxfs_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, &ip
,
637 &xfs_default_ifork_ops
);
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
648 libxfs_trans_ijoin(tp
, ip
, 0);
650 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0, 1, &map
, &nmap
);
651 if (error
|| nmap
!= 1) {
653 _("couldn't map realtime bitmap block %" PRIu64
", error = %d\n"),
657 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
659 error
= -libxfs_trans_read_buf(
661 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
662 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
666 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime bitmap inode %" PRIu64
"\n"),
667 bno
, map
.br_startblock
, mp
->m_sb
.sb_rbmino
);
671 memmove(bp
->b_addr
, bmp
, mp
->m_sb
.sb_blocksize
);
673 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
675 bmp
= (xfs_rtword_t
*)((intptr_t) bmp
+ mp
->m_sb
.sb_blocksize
);
679 error
= -libxfs_trans_commit(tp
);
681 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
687 fill_rsumino(xfs_mount_t
*mp
)
696 xfs_fileoff_t end_bno
;
701 end_bno
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
703 error
= -libxfs_trans_alloc_rollable(mp
, 10, &tp
);
707 error
= -libxfs_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, &ip
,
708 &xfs_default_ifork_ops
);
711 _("couldn't iget realtime summary inode -- error - %d\n"),
715 while (bno
< end_bno
) {
717 * fill the file one block at a time
719 libxfs_trans_ijoin(tp
, ip
, 0);
721 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0, 1, &map
, &nmap
);
722 if (error
|| nmap
!= 1) {
724 _("couldn't map realtime summary inode block %" PRIu64
", error = %d\n"),
728 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
730 error
= -libxfs_trans_read_buf(
732 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
733 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
737 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime summary inode %" PRIu64
"\n"),
738 bno
, map
.br_startblock
, mp
->m_sb
.sb_rsumino
);
743 memmove(bp
->b_addr
, smp
, mp
->m_sb
.sb_blocksize
);
745 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
747 smp
= (xfs_suminfo_t
*)((intptr_t)smp
+ mp
->m_sb
.sb_blocksize
);
751 error
= -libxfs_trans_commit(tp
);
753 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
759 mk_rsumino(xfs_mount_t
*mp
)
769 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
777 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
781 error
= -libxfs_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, &ip
,
782 &xfs_default_ifork_ops
);
785 _("couldn't iget realtime summary inode -- error - %d\n"),
789 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
790 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
792 VFS_I(ip
)->i_mode
= S_IFREG
;
793 ip
->i_d
.di_version
= vers
;
794 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
795 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
797 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
799 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
800 if (ip
->i_d
.di_version
== 3) {
801 VFS_I(ip
)->i_version
= 1;
802 ip
->i_d
.di_flags2
= 0;
803 times
|= XFS_ICHGTIME_CREATE
;
805 libxfs_trans_ichgtime(tp
, ip
, times
);
810 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
811 ip
->i_df
.if_bytes
= 0;
812 ip
->i_df
.if_u1
.if_root
= NULL
;
814 ip
->i_d
.di_size
= mp
->m_rsumsize
;
819 libxfs_trans_ijoin(tp
, ip
, 0);
820 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
821 error
= -libxfs_trans_commit(tp
);
823 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
826 * then allocate blocks for file and fill with zeroes (stolen
829 nsumblocks
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
830 blocks
= nsumblocks
+ XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) - 1;
831 error
= -libxfs_trans_alloc_rollable(mp
, blocks
, &tp
);
835 libxfs_trans_ijoin(tp
, ip
, 0);
837 while (bno
< nsumblocks
) {
838 nmap
= XFS_BMAP_MAX_NMAP
;
839 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
840 (xfs_extlen_t
)(nsumblocks
- bno
),
841 0, nsumblocks
, map
, &nmap
);
844 _("couldn't allocate realtime summary inode, error = %d\n"),
847 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
848 libxfs_device_zero(mp
->m_ddev_targp
,
849 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
850 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
851 bno
+= ep
->br_blockcount
;
854 error
= -libxfs_trans_commit(tp
);
857 _("allocation of the realtime summary ino failed, error = %d\n"),
864 * makes a new root directory.
867 mk_root_dir(xfs_mount_t
*mp
)
873 const mode_t mode
= 0755;
874 ino_tree_node_t
*irec
;
879 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
883 error
= -libxfs_iget(mp
, tp
, mp
->m_sb
.sb_rootino
, 0, &ip
,
884 &xfs_default_ifork_ops
);
886 do_error(_("could not iget root inode -- error - %d\n"), error
);
890 * take care of the core -- initialization from xfs_ialloc()
892 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
893 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
895 VFS_I(ip
)->i_mode
= mode
|S_IFDIR
;
896 ip
->i_d
.di_version
= vers
;
897 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
898 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
900 set_nlink(VFS_I(ip
), 2); /* account for . and .. */
902 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
903 if (ip
->i_d
.di_version
== 3) {
904 VFS_I(ip
)->i_version
= 1;
905 ip
->i_d
.di_flags2
= 0;
906 times
|= XFS_ICHGTIME_CREATE
;
908 libxfs_trans_ichgtime(tp
, ip
, times
);
909 libxfs_trans_ijoin(tp
, ip
, 0);
910 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
915 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
916 ip
->i_df
.if_bytes
= 0;
917 ip
->i_df
.if_u1
.if_root
= NULL
;
920 * initialize the directory
922 ip
->d_ops
= mp
->m_dir_inode_ops
;
923 libxfs_dir_init(tp
, ip
, ip
);
925 error
= -libxfs_trans_commit(tp
);
927 do_error(_("%s: commit failed, error %d\n"), __func__
, error
);
931 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
932 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
933 set_inode_isadir(irec
, XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
) -
938 * orphanage name == lost+found
941 mk_orphanage(xfs_mount_t
*mp
)
947 ino_tree_node_t
*irec
;
951 const int mode
= 0755;
953 struct xfs_name xname
;
956 * check for an existing lost+found first, if it exists, return
957 * its inode. Otherwise, we can create it. Bad lost+found inodes
958 * would have been cleared in phase3 and phase4.
961 i
= -libxfs_iget(mp
, NULL
, mp
->m_sb
.sb_rootino
, 0, &pip
,
962 &xfs_default_ifork_ops
);
964 do_error(_("%d - couldn't iget root inode to obtain %s\n"),
967 xname
.name
= (unsigned char *)ORPHANAGE
;
968 xname
.len
= strlen(ORPHANAGE
);
969 xname
.type
= XFS_DIR3_FT_DIR
;
971 if (libxfs_dir_lookup(NULL
, pip
, &xname
, &ino
, NULL
) == 0)
975 * could not be found, create it
977 nres
= XFS_MKDIR_SPACE_RES(mp
, xname
.len
);
978 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
, nres
, 0, 0, &tp
);
983 * use iget/ijoin instead of trans_iget because the ialloc
984 * wrapper can commit the transaction and start a new one
986 /* i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip,
987 &xfs_default_ifork_ops);
989 do_error(_("%d - couldn't iget root inode to make %s\n"),
992 error
= -libxfs_inode_alloc(&tp
, pip
, mode
|S_IFDIR
,
993 1, 0, &zerocr
, &zerofsx
, &ip
);
995 do_error(_("%s inode allocation failed %d\n"),
998 inc_nlink(VFS_I(ip
)); /* account for . */
1001 irec
= find_inode_rec(mp
,
1002 XFS_INO_TO_AGNO(mp
, ino
),
1003 XFS_INO_TO_AGINO(mp
, ino
));
1007 * This inode is allocated from a newly created inode
1008 * chunk and therefore did not exist when inode chunks
1009 * were processed in phase3. Add this group of inodes to
1010 * the entry avl tree as if they were discovered in phase3.
1012 irec
= set_inode_free_alloc(mp
, XFS_INO_TO_AGNO(mp
, ino
),
1013 XFS_INO_TO_AGINO(mp
, ino
));
1014 alloc_ex_data(irec
);
1016 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++)
1017 set_inode_free(irec
, i
);
1020 ino_offset
= get_inode_offset(mp
, ino
, irec
);
1023 * Mark the inode allocated to lost+found as used in the AVL tree
1024 * so it is not skipped in phase 7
1026 set_inode_used(irec
, ino_offset
);
1027 add_inode_ref(irec
, ino_offset
);
1028 add_inode_reached(irec
, ino_offset
);
1031 * now that we know the transaction will stay around,
1032 * add the root inode to it
1034 libxfs_trans_ijoin(tp
, pip
, 0);
1037 * create the actual entry
1039 error
= -libxfs_dir_createname(tp
, pip
, &xname
, ip
->i_ino
, nres
);
1042 _("can't make %s, createname error %d\n"),
1046 * bump up the link count in the root directory to account
1047 * for .. in the new directory, and update the irec copy of the
1048 * on-disk nlink so we don't fail the link count check later.
1050 inc_nlink(VFS_I(pip
));
1051 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
1052 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
1053 add_inode_ref(irec
, 0);
1054 set_inode_disk_nlinks(irec
, 0, get_inode_disk_nlinks(irec
, 0) + 1);
1056 libxfs_trans_log_inode(tp
, pip
, XFS_ILOG_CORE
);
1057 libxfs_dir_init(tp
, ip
, pip
);
1058 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1059 error
= -libxfs_trans_commit(tp
);
1061 do_error(_("%s directory creation failed -- bmapf error %d\n"),
1071 * move a file to the orphange.
1076 xfs_ino_t ino
, /* inode # to be moved */
1077 int isa_dir
) /* 1 if inode is a directory */
1079 xfs_inode_t
*orphanage_ip
;
1080 xfs_ino_t entry_ino_num
;
1084 unsigned char fname
[MAXPATHLEN
+ 1];
1087 ino_tree_node_t
*irec
;
1089 struct xfs_name xname
;
1092 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu",
1093 (unsigned long long)ino
);
1095 err
= -libxfs_iget(mp
, NULL
, orphanage_ino
, 0, &orphanage_ip
,
1096 &xfs_default_ifork_ops
);
1098 do_error(_("%d - couldn't iget orphanage inode\n"), err
);
1100 * Make sure the filename is unique in the lost+found
1103 while (libxfs_dir_lookup(NULL
, orphanage_ip
, &xname
, &entry_ino_num
,
1105 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu.%d",
1106 (unsigned long long)ino
, ++incr
);
1108 /* Orphans may not have a proper parent, so use custom ops here */
1109 err
= -libxfs_iget(mp
, NULL
, ino
, 0, &ino_p
, &phase6_ifork_ops
);
1111 do_error(_("%d - couldn't iget disconnected inode\n"), err
);
1113 xname
.type
= libxfs_mode_to_ftype(VFS_I(ino_p
)->i_mode
);
1116 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, orphanage_ino
),
1117 XFS_INO_TO_AGINO(mp
, orphanage_ino
));
1119 ino_offset
= XFS_INO_TO_AGINO(mp
, orphanage_ino
) -
1121 nres
= XFS_DIRENTER_SPACE_RES(mp
, fnamelen
) +
1122 XFS_DIRENTER_SPACE_RES(mp
, 2);
1123 err
= -libxfs_dir_lookup(NULL
, ino_p
, &xfs_name_dotdot
,
1124 &entry_ino_num
, NULL
);
1126 ASSERT(err
== ENOENT
);
1128 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1132 _("space reservation failed (%d), filesystem may be out of space\n"),
1135 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1136 libxfs_trans_ijoin(tp
, ino_p
, 0);
1138 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1142 _("name create failed in %s (%d), filesystem may be out of space\n"),
1146 add_inode_ref(irec
, ino_offset
);
1148 inc_nlink(VFS_I(orphanage_ip
));
1149 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1151 err
= -libxfs_dir_createname(tp
, ino_p
, &xfs_name_dotdot
,
1152 orphanage_ino
, nres
);
1155 _("creation of .. entry failed (%d), filesystem may be out of space\n"),
1158 inc_nlink(VFS_I(ino_p
));
1159 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1160 err
= -libxfs_trans_commit(tp
);
1163 _("creation of .. entry failed (%d)\n"), err
);
1165 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1169 _("space reservation failed (%d), filesystem may be out of space\n"),
1172 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1173 libxfs_trans_ijoin(tp
, ino_p
, 0);
1176 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1180 _("name create failed in %s (%d), filesystem may be out of space\n"),
1184 add_inode_ref(irec
, ino_offset
);
1186 inc_nlink(VFS_I(orphanage_ip
));
1187 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1190 * don't replace .. value if it already points
1191 * to us. that'll pop a libxfs/kernel ASSERT.
1193 if (entry_ino_num
!= orphanage_ino
) {
1194 err
= -libxfs_dir_replace(tp
, ino_p
,
1195 &xfs_name_dotdot
, orphanage_ino
,
1199 _("name replace op failed (%d), filesystem may be out of space\n"),
1203 err
= -libxfs_trans_commit(tp
);
1206 _("orphanage name replace op failed (%d)\n"), err
);
1211 * use the remove log reservation as that's
1212 * more accurate. we're only creating the
1213 * links, we're not doing the inode allocation
1214 * also accounted for in the create
1216 nres
= XFS_DIRENTER_SPACE_RES(mp
, xname
.len
);
1217 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
1221 _("space reservation failed (%d), filesystem may be out of space\n"),
1224 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1225 libxfs_trans_ijoin(tp
, ino_p
, 0);
1227 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
, ino
,
1231 _("name create failed in %s (%d), filesystem may be out of space\n"),
1235 set_nlink(VFS_I(ino_p
), 1);
1236 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1237 err
= -libxfs_trans_commit(tp
);
1240 _("orphanage name create failed (%d)\n"), err
);
1242 libxfs_irele(ino_p
);
1243 libxfs_irele(orphanage_ip
);
1253 do_warn(msg
, iname
, ino1
, ino2
);
1256 do_warn(_(", marking entry to be junked\n"));
1260 do_warn(_(", would junk entry\n"));
1264 /* Find and invalidate all the directory's buffers. */
1267 struct xfs_trans
*tp
,
1268 struct xfs_inode
*ip
,
1271 struct xfs_iext_cursor icur
;
1272 struct xfs_bmbt_irec rec
;
1273 struct xfs_ifork
*ifp
;
1274 struct xfs_da_geometry
*geo
;
1276 xfs_dablk_t dabno
, end_dabno
;
1279 if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_EXTENTS
&&
1280 ip
->i_d
.di_format
!= XFS_DINODE_FMT_BTREE
)
1283 geo
= tp
->t_mountp
->m_dir_geo
;
1284 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
1285 for_each_xfs_iext(ifp
, &icur
, &rec
) {
1286 dabno
= xfs_dir2_db_to_da(geo
, rec
.br_startoff
+
1288 end_dabno
= xfs_dir2_db_to_da(geo
, rec
.br_startoff
+
1290 for (; dabno
<= end_dabno
; dabno
+= geo
->fsbcount
) {
1292 error
= -libxfs_da_get_buf(tp
, ip
, dabno
, -2, &bp
,
1298 libxfs_trans_binval(tp
, bp
);
1299 libxfs_trans_brelse(tp
, bp
);
1307 * Unexpected failure during the rebuild will leave the entries in
1308 * lost+found on the next run
1312 longform_dir2_rebuild(
1316 ino_tree_node_t
*irec
,
1318 dir_hash_tab_t
*hashtab
)
1323 xfs_fileoff_t lastblock
;
1329 * trash directory completely and rebuild from scratch using the
1330 * name/inode pairs in the hash table
1333 do_warn(_("rebuilding directory inode %" PRIu64
"\n"), ino
);
1336 * first attempt to locate the parent inode, if it can't be
1337 * found, set it to the root inode and it'll be moved to the
1338 * orphanage later (the inode number here needs to be valid
1339 * for the libxfs_dir_init() call).
1341 pip
.i_ino
= get_inode_parent(irec
, ino_offset
);
1342 if (pip
.i_ino
== NULLFSINO
||
1343 libxfs_dir_ino_validate(mp
, pip
.i_ino
))
1344 pip
.i_ino
= mp
->m_sb
.sb_rootino
;
1346 nres
= XFS_REMOVE_SPACE_RES(mp
);
1347 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1350 libxfs_trans_ijoin(tp
, ip
, 0);
1352 error
= dir_binval(tp
, ip
, XFS_DATA_FORK
);
1354 do_error(_("error %d invalidating directory %llu blocks\n"),
1355 error
, (unsigned long long)ip
->i_ino
);
1357 if ((error
= -libxfs_bmap_last_offset(ip
, &lastblock
, XFS_DATA_FORK
)))
1358 do_error(_("xfs_bmap_last_offset failed -- error - %d\n"),
1361 /* free all data, leaf, node and freespace blocks */
1363 error
= -libxfs_bunmapi(tp
, ip
, 0, lastblock
, XFS_BMAPI_METADATA
,
1366 do_warn(_("xfs_bunmapi failed -- error - %d\n"), error
);
1367 goto out_bmap_cancel
;
1369 error
= -libxfs_defer_finish(&tp
);
1371 do_warn(("defer_finish failed -- error - %d\n"), error
);
1372 goto out_bmap_cancel
;
1375 * Close out trans and start the next one in the chain.
1377 error
= -libxfs_trans_roll_inode(&tp
, ip
);
1379 goto out_bmap_cancel
;
1382 error
= -libxfs_dir_init(tp
, ip
, &pip
);
1384 do_warn(_("xfs_dir_init failed -- error - %d\n"), error
);
1385 goto out_bmap_cancel
;
1388 error
= -libxfs_trans_commit(tp
);
1391 _("dir init failed (%d)\n"), error
);
1393 if (ino
== mp
->m_sb
.sb_rootino
)
1394 need_root_dotdot
= 0;
1396 /* go through the hash list and re-add the inodes */
1398 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
1400 if (p
->name
.name
[0] == '/' || (p
->name
.name
[0] == '.' &&
1401 (p
->name
.len
== 1 || (p
->name
.len
== 2 &&
1402 p
->name
.name
[1] == '.'))))
1405 nres
= XFS_CREATE_SPACE_RES(mp
, p
->name
.len
);
1406 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_create
,
1411 libxfs_trans_ijoin(tp
, ip
, 0);
1413 error
= -libxfs_dir_createname(tp
, ip
, &p
->name
, p
->inum
,
1417 _("name create failed in ino %" PRIu64
" (%d), filesystem may be out of space\n"),
1419 goto out_bmap_cancel
;
1422 error
= -libxfs_trans_commit(tp
);
1425 _("name create failed (%d) during rebuild\n"), error
);
1431 libxfs_trans_cancel(tp
);
1437 * Kill a block in a version 2 inode.
1438 * Makes its own transaction.
1452 nres
= XFS_REMOVE_SPACE_RES(mp
);
1453 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1456 libxfs_trans_ijoin(tp
, ip
, 0);
1457 libxfs_trans_bjoin(tp
, bp
);
1458 memset(&args
, 0, sizeof(args
));
1461 args
.whichfork
= XFS_DATA_FORK
;
1462 args
.geo
= mp
->m_dir_geo
;
1463 if (da_bno
>= mp
->m_dir_geo
->leafblk
&& da_bno
< mp
->m_dir_geo
->freeblk
)
1464 error
= -libxfs_da_shrink_inode(&args
, da_bno
, bp
);
1466 error
= -libxfs_dir2_shrink_inode(&args
,
1467 xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
), bp
);
1469 do_error(_("shrink_inode failed inode %" PRIu64
" block %u\n"),
1471 error
= -libxfs_trans_commit(tp
);
1474 _("directory shrink failed (%d)\n"), error
);
1478 * process a data block, also checks for .. entry
1479 * and corrects it to match what we think .. should be
1482 longform_dir2_entry_check_data(
1487 ino_tree_node_t
*current_irec
,
1488 int current_ino_offset
,
1489 struct xfs_buf
**bpp
,
1490 dir_hash_tab_t
*hashtab
,
1491 freetab_t
**freetabp
,
1495 xfs_dir2_dataptr_t addr
;
1496 xfs_dir2_leaf_entry_t
*blp
;
1498 xfs_dir2_block_tail_t
*btp
;
1499 struct xfs_dir2_data_hdr
*d
;
1501 xfs_dir2_data_entry_t
*dep
;
1502 xfs_dir2_data_unused_t
*dup
;
1503 struct xfs_dir2_data_free
*bf
;
1506 char fname
[MAXNAMELEN
+ 1];
1511 ino_tree_node_t
*irec
;
1522 struct xfs_da_args da
= {
1524 .geo
= mp
->m_dir_geo
,
1530 ptr
= (char *)d
+ mp
->m_dir_geo
->data_entry_offset
;
1532 needscan
= needlog
= 0;
1534 freetab
= *freetabp
;
1536 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, d
);
1537 blp
= xfs_dir2_block_leaf_p(btp
);
1538 endptr
= (char *)blp
;
1539 if (endptr
> (char *)btp
)
1540 endptr
= (char *)btp
;
1541 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1542 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1544 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1546 endptr
= (char *)d
+ mp
->m_dir_geo
->blksize
;
1547 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1548 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1550 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1552 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
1554 /* check for data block beyond expected end */
1555 if (freetab
->naents
<= db
) {
1556 struct freetab_ent e
;
1558 *freetabp
= freetab
= realloc(freetab
, FREETAB_SIZE(db
+ 1));
1560 do_error(_("realloc failed in %s (%zu bytes)\n"),
1561 __func__
, FREETAB_SIZE(db
+ 1));
1565 for (i
= freetab
->naents
; i
< db
; i
++)
1566 freetab
->ents
[i
] = e
;
1567 freetab
->naents
= db
+ 1;
1570 /* check the data block */
1571 while (ptr
< endptr
) {
1573 /* check for freespace */
1574 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1575 if (XFS_DIR2_DATA_FREE_TAG
== be16_to_cpu(dup
->freetag
)) {
1577 /* check for invalid freespace length */
1578 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1579 be16_to_cpu(dup
->length
) == 0 ||
1580 (be16_to_cpu(dup
->length
) &
1581 (XFS_DIR2_DATA_ALIGN
- 1)))
1584 /* check for invalid tag */
1585 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1586 (char *)dup
- (char *)d
)
1589 /* check for block with no data entries */
1590 if ((ptr
== (char *)d
+ mp
->m_dir_geo
->data_entry_offset
) &&
1591 (ptr
+ be16_to_cpu(dup
->length
) >= endptr
)) {
1597 /* continue at the end of the freespace */
1598 ptr
+= be16_to_cpu(dup
->length
);
1603 /* validate data entry size */
1604 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1605 if (ptr
+ libxfs_dir2_data_entsize(mp
, dep
->namelen
) > endptr
)
1607 if (be16_to_cpu(*libxfs_dir2_data_entry_tag_p(mp
, dep
)) !=
1608 (char *)dep
- (char *)d
)
1610 ptr
+= libxfs_dir2_data_entsize(mp
, dep
->namelen
);
1613 /* did we find an empty or corrupt block? */
1614 if (ptr
!= endptr
) {
1617 _("empty data block %u in directory inode %" PRIu64
": "),
1621 ("corrupt block %u in directory inode %" PRIu64
": "),
1625 do_warn(_("junking block\n"));
1626 dir2_kill_block(mp
, ip
, da_bno
, bp
);
1628 do_warn(_("would junk block\n"));
1631 freetab
->ents
[db
].v
= NULLDATAOFF
;
1636 /* update number of data blocks processed */
1637 if (freetab
->nents
< db
+ 1)
1638 freetab
->nents
= db
+ 1;
1640 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, 0, 0, 0, &tp
);
1644 libxfs_trans_ijoin(tp
, ip
, 0);
1645 libxfs_trans_bjoin(tp
, bp
);
1646 libxfs_trans_bhold(tp
, bp
);
1647 if (be32_to_cpu(d
->magic
) != wantmagic
) {
1649 _("bad directory block magic # %#x for directory inode %" PRIu64
" block %d: "),
1650 be32_to_cpu(d
->magic
), ip
->i_ino
, da_bno
);
1652 do_warn(_("fixing magic # to %#x\n"), wantmagic
);
1653 d
->magic
= cpu_to_be32(wantmagic
);
1656 do_warn(_("would fix magic # to %#x\n"), wantmagic
);
1659 ptr
= (char *)d
+ mp
->m_dir_geo
->data_entry_offset
;
1661 * look at each entry. reference inode pointed to by each
1662 * entry in the incore inode tree.
1663 * if not a directory, set reached flag, increment link count
1664 * if a directory and reached, mark entry as to be deleted.
1665 * if a directory, check to see if recorded parent
1666 * matches current inode #,
1667 * if so, then set reached flag, increment link count
1668 * of current and child dir inodes, push the child
1669 * directory inode onto the directory stack.
1670 * if current inode != parent, then mark entry to be deleted.
1672 while (ptr
< endptr
) {
1673 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1674 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1677 _("directory inode %" PRIu64
" block %u has consecutive free entries: "),
1681 do_warn(_("joining together\n"));
1682 len
= be16_to_cpu(dup
->length
);
1683 libxfs_dir2_data_use_free(&da
, bp
, dup
,
1684 ptr
- (char *)d
, len
, &needlog
,
1686 libxfs_dir2_data_make_free(&da
, bp
,
1687 ptr
- (char *)d
, len
, &needlog
,
1690 do_warn(_("would join together\n"));
1692 ptr
+= be16_to_cpu(dup
->length
);
1696 addr
= xfs_dir2_db_off_to_dataptr(mp
->m_dir_geo
, db
,
1698 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1699 ptr
+= libxfs_dir2_data_entsize(mp
, dep
->namelen
);
1700 inum
= be64_to_cpu(dep
->inumber
);
1703 * skip bogus entries (leading '/'). they'll be deleted
1704 * later. must still log it, else we leak references to
1707 if (dep
->name
[0] == '/') {
1710 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1714 memmove(fname
, dep
->name
, dep
->namelen
);
1715 fname
[dep
->namelen
] = '\0';
1716 ASSERT(inum
!= NULLFSINO
);
1718 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, inum
),
1719 XFS_INO_TO_AGINO(mp
, inum
));
1723 _("entry \"%s\" in directory inode %" PRIu64
" points to non-existent inode %" PRIu64
""),
1724 fname
, ip
->i_ino
, inum
)) {
1726 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1730 ino_offset
= XFS_INO_TO_AGINO(mp
, inum
) - irec
->ino_startnum
;
1733 * if it's a free inode, blow out the entry.
1734 * by now, any inode that we think is free
1737 if (is_inode_free(irec
, ino_offset
)) {
1740 _("entry \"%s\" in directory inode %" PRIu64
" points to free inode %" PRIu64
),
1741 fname
, ip
->i_ino
, inum
)) {
1743 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1749 * check if this inode is lost+found dir in the root
1751 if (inum
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
1753 * if it's not a directory, trash it
1755 if (!inode_isadir(irec
, ino_offset
)) {
1758 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
1759 ORPHANAGE
, inum
, ip
->i_ino
)) {
1761 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1766 * if this is a dup, it will be picked up below,
1767 * otherwise, mark it as the orphanage for later.
1770 orphanage_ino
= inum
;
1774 * check for duplicate names in directory.
1776 if (!dir_hash_add(mp
, hashtab
, addr
, inum
, dep
->namelen
,
1777 dep
->name
, M_DIROPS(mp
)->data_get_ftype(dep
))) {
1780 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
1781 fname
, inum
, ip
->i_ino
)) {
1783 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1785 if (inum
== orphanage_ino
)
1791 * if just scanning to rebuild a directory due to a ".."
1792 * update, just continue
1798 * skip the '..' entry since it's checked when the
1799 * directory is reached by something else. if it never
1800 * gets reached, it'll be moved to the orphanage and we'll
1801 * take care of it then. If it doesn't exist at all, the
1802 * directory needs to be rebuilt first before being added
1805 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
1806 dep
->name
[1] == '.') {
1808 /* ".." should be in the first block */
1811 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is not in the the first block"), fname
,
1814 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1819 ASSERT(no_modify
|| !verify_inum(mp
, inum
));
1821 * special case the . entry. we know there's only one
1822 * '.' and only '.' points to itself because bogus entries
1823 * got trashed in phase 3 if there were > 1.
1824 * bump up link count for '.' but don't set reached
1825 * until we're actually reached by another directory
1826 * '..' is already accounted for or will be taken care
1827 * of when directory is moved to orphanage.
1829 if (ip
->i_ino
== inum
) {
1831 (dep
->name
[0] == '.' && dep
->namelen
== 1));
1832 add_inode_ref(current_irec
, current_ino_offset
);
1834 dep
!= (void *)d
+ mp
->m_dir_geo
->data_entry_offset
) {
1835 /* "." should be the first entry */
1838 _("entry \"%s\" in dir %" PRIu64
" is not the first entry"),
1839 fname
, inum
, ip
->i_ino
)) {
1841 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1848 * skip entries with bogus inumbers if we're in no modify mode
1850 if (no_modify
&& verify_inum(mp
, inum
))
1853 /* validate ftype field if supported */
1854 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
1858 dir_ftype
= M_DIROPS(mp
)->data_get_ftype(dep
);
1859 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
1861 if (dir_ftype
!= ino_ftype
) {
1864 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1865 dir_ftype
, ino_ftype
,
1869 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1870 dir_ftype
, ino_ftype
,
1872 M_DIROPS(mp
)->data_put_ftype(dep
,
1874 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1875 dir_hash_update_ftype(hashtab
, addr
,
1882 * check easy case first, regular inode, just bump
1883 * the link count and continue
1885 if (!inode_isadir(irec
, ino_offset
)) {
1886 add_inode_reached(irec
, ino_offset
);
1889 parent
= get_inode_parent(irec
, ino_offset
);
1890 ASSERT(parent
!= 0);
1893 * bump up the link counts in parent and child
1894 * directory but if the link doesn't agree with
1895 * the .. in the child, blow out the entry.
1896 * if the directory has already been reached,
1897 * blow away the entry also.
1899 if (is_inode_reached(irec
, ino_offset
)) {
1902 _("entry \"%s\" in dir %" PRIu64
" points to an already connected directory inode %" PRIu64
"\n"),
1903 fname
, ip
->i_ino
, inum
);
1904 } else if (parent
== ip
->i_ino
) {
1905 add_inode_reached(irec
, ino_offset
);
1906 add_inode_ref(current_irec
, current_ino_offset
);
1907 } else if (parent
== NULLFSINO
) {
1908 /* ".." was missing, but this entry refers to it,
1909 so, set it as the parent and mark for rebuild */
1911 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
1912 fname
, ip
->i_ino
, inum
);
1913 set_inode_parent(irec
, ino_offset
, ip
->i_ino
);
1914 add_inode_reached(irec
, ino_offset
);
1915 add_inode_ref(current_irec
, current_ino_offset
);
1916 add_dotdot_update(XFS_INO_TO_AGNO(mp
, inum
), irec
,
1921 _("entry \"%s\" in dir inode %" PRIu64
" inconsistent with .. value (%" PRIu64
") in ino %" PRIu64
"\n"),
1922 fname
, ip
->i_ino
, parent
, inum
);
1925 if (inum
== orphanage_ino
)
1930 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1933 _("\twill clear entry \"%s\"\n"),
1936 do_warn(_("\twould clear entry \"%s\"\n"),
1941 *num_illegal
+= nbad
;
1943 libxfs_dir2_data_freescan_int(mp
, M_DIROPS(mp
), d
, &i
);
1945 libxfs_dir2_data_log_header(&da
, bp
);
1946 error
= -libxfs_trans_commit(tp
);
1949 _("directory block fixing failed (%d)\n"), error
);
1951 /* record the largest free space in the freetab for later checking */
1952 bf
= M_DIROPS(mp
)->data_bestfree_p(d
);
1953 freetab
->ents
[db
].v
= be16_to_cpu(bf
[0].length
);
1954 freetab
->ents
[db
].s
= 0;
1957 /* check v5 metadata */
1959 __check_dir3_header(
1960 struct xfs_mount
*mp
,
1969 if (be64_to_cpu(owner
) != ino
) {
1971 _("expected owner inode %" PRIu64
", got %llu, directory block %" PRIu64
"\n"),
1972 ino
, (unsigned long long)be64_to_cpu(owner
), bp
->b_bn
);
1975 /* verify block number */
1976 if (be64_to_cpu(blkno
) != bp
->b_bn
) {
1978 _("expected block %" PRIu64
", got %llu, directory inode %" PRIu64
"\n"),
1979 bp
->b_bn
, (unsigned long long)be64_to_cpu(blkno
), ino
);
1983 if (platform_uuid_compare(uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
1985 _("wrong FS UUID, directory inode %" PRIu64
" block %" PRIu64
"\n"),
1995 struct xfs_mount
*mp
,
1999 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
2001 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2007 struct xfs_mount
*mp
,
2011 struct xfs_dir3_blk_hdr
*info
= bp
->b_addr
;
2013 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2018 * Check contents of leaf-form block.
2021 longform_dir2_check_leaf(
2024 dir_hash_tab_t
*hashtab
,
2032 xfs_dir2_leaf_t
*leaf
;
2033 xfs_dir2_leaf_tail_t
*ltp
;
2035 struct xfs_dir2_leaf_entry
*ents
;
2036 struct xfs_dir3_icleaf_hdr leafhdr
;
2040 da_bno
= mp
->m_dir_geo
->leafblk
;
2041 error
= dir_read_buf(ip
, da_bno
, -1, &bp
, &xfs_dir3_leaf1_buf_ops
,
2043 if (error
== EFSBADCRC
|| error
== EFSCORRUPTED
|| fixit
) {
2045 _("leaf block %u for directory inode %" PRIu64
" bad CRC\n"),
2050 _("can't read block %u for directory inode %" PRIu64
", error %d\n"),
2051 da_bno
, ip
->i_ino
, error
);
2056 libxfs_dir2_leaf_hdr_from_disk(mp
, &leafhdr
, leaf
);
2057 ents
= leafhdr
.ents
;
2058 ltp
= xfs_dir2_leaf_tail_p(mp
->m_dir_geo
, leaf
);
2059 bestsp
= xfs_dir2_leaf_bests_p(ltp
);
2060 if (!(leafhdr
.magic
== XFS_DIR2_LEAF1_MAGIC
||
2061 leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) ||
2062 leafhdr
.forw
|| leafhdr
.back
||
2063 leafhdr
.count
< leafhdr
.stale
||
2064 leafhdr
.count
> mp
->m_dir_geo
->leaf_max_ents
||
2065 (char *)&ents
[leafhdr
.count
] > (char *)bestsp
) {
2067 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2073 if (leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) {
2074 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2081 seeval
= dir_hash_see_all(hashtab
, ents
, leafhdr
.count
, leafhdr
.stale
);
2082 if (dir_hash_check(hashtab
, ip
, seeval
)) {
2086 badtail
= freetab
->nents
!= be32_to_cpu(ltp
->bestcount
);
2087 for (i
= 0; !badtail
&& i
< be32_to_cpu(ltp
->bestcount
); i
++) {
2088 freetab
->ents
[i
].s
= 1;
2089 badtail
= freetab
->ents
[i
].v
!= be16_to_cpu(bestsp
[i
]);
2093 _("leaf block %u for directory inode %" PRIu64
" bad tail\n"),
2103 * Check contents of the node blocks (leaves)
2104 * Looks for matching hash values for the data entries.
2107 longform_dir2_check_node(
2110 dir_hash_tab_t
*hashtab
,
2116 xfs_dir2_free_t
*free
;
2118 xfs_dir2_leaf_t
*leaf
;
2119 xfs_fileoff_t next_da_bno
;
2122 struct xfs_dir2_leaf_entry
*ents
;
2123 struct xfs_dir3_icleaf_hdr leafhdr
;
2124 struct xfs_dir3_icfree_hdr freehdr
;
2129 for (da_bno
= mp
->m_dir_geo
->leafblk
, next_da_bno
= 0;
2130 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->freeblk
;
2131 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2132 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2133 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2137 * we need to use the da3 node verifier here as it handles the
2138 * fact that reading the leaf hash tree blocks can return either
2139 * leaf or node blocks and calls the correct verifier. If we get
2140 * a node block, then we'll skip it below based on a magic
2143 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2144 &xfs_da3_node_buf_ops
, &fixit
);
2147 _("can't read leaf block %u for directory inode %" PRIu64
", error %d\n"),
2148 da_bno
, ip
->i_ino
, error
);
2152 libxfs_dir2_leaf_hdr_from_disk(mp
, &leafhdr
, leaf
);
2153 ents
= leafhdr
.ents
;
2154 if (!(leafhdr
.magic
== XFS_DIR2_LEAFN_MAGIC
||
2155 leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2156 leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2157 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
)) {
2159 _("unknown magic number %#x for block %u in directory inode %" PRIu64
"\n"),
2160 leafhdr
.magic
, da_bno
, ip
->i_ino
);
2165 /* check v5 metadata */
2166 if (leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2167 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2168 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2176 if (leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2177 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2183 * If there's a validator error, we need to ensure that we got
2184 * the right ops on the buffer for when we write it back out.
2186 bp
->b_ops
= &xfs_dir3_leafn_buf_ops
;
2187 if (leafhdr
.count
> mp
->m_dir_geo
->leaf_max_ents
||
2188 leafhdr
.count
< leafhdr
.stale
) {
2190 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2195 seeval
= dir_hash_see_all(hashtab
, ents
,
2196 leafhdr
.count
, leafhdr
.stale
);
2198 if (seeval
!= DIR_HASH_CK_OK
)
2201 if (dir_hash_check(hashtab
, ip
, seeval
))
2204 for (da_bno
= mp
->m_dir_geo
->freeblk
, next_da_bno
= 0;
2205 next_da_bno
!= NULLFILEOFF
;
2206 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2207 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2208 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2211 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2212 &xfs_dir3_free_buf_ops
, &fixit
);
2215 _("can't read freespace block %u for directory inode %" PRIu64
", error %d\n"),
2216 da_bno
, ip
->i_ino
, error
);
2220 libxfs_dir2_free_hdr_from_disk(mp
, &freehdr
, free
);
2221 bests
= freehdr
.bests
;
2222 fdb
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2223 if (!(freehdr
.magic
== XFS_DIR2_FREE_MAGIC
||
2224 freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) ||
2226 (fdb
- xfs_dir2_byte_to_db(mp
->m_dir_geo
, XFS_DIR2_FREE_OFFSET
)) *
2227 mp
->m_dir_geo
->free_max_bests
||
2228 freehdr
.nvalid
< freehdr
.nused
) {
2230 _("free block %u for directory inode %" PRIu64
" bad header\n"),
2236 if (freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) {
2237 error
= check_dir3_header(mp
, bp
, ip
->i_ino
);
2243 for (i
= used
= 0; i
< freehdr
.nvalid
; i
++) {
2244 if (i
+ freehdr
.firstdb
>= freetab
->nents
||
2245 freetab
->ents
[i
+ freehdr
.firstdb
].v
!=
2246 be16_to_cpu(bests
[i
])) {
2248 _("free block %u entry %i for directory ino %" PRIu64
" bad\n"),
2249 da_bno
, i
, ip
->i_ino
);
2253 used
+= be16_to_cpu(bests
[i
]) != NULLDATAOFF
;
2254 freetab
->ents
[i
+ freehdr
.firstdb
].s
= 1;
2256 if (used
!= freehdr
.nused
) {
2258 _("free block %u for directory inode %" PRIu64
" bad nused\n"),
2265 for (i
= 0; i
< freetab
->nents
; i
++) {
2266 if ((freetab
->ents
[i
].s
== 0) &&
2267 (freetab
->ents
[i
].v
!= NULLDATAOFF
)) {
2269 _("missing freetab entry %u for directory inode %" PRIu64
"\n"),
2278 * If a directory is corrupt, we need to read in as many entries as possible,
2279 * destroy the entry and create a new one with recovered name/inode pairs.
2280 * (ie. get libxfs to do all the grunt work)
2283 longform_dir2_entry_check(xfs_mount_t
*mp
,
2288 ino_tree_node_t
*irec
,
2290 dir_hash_tab_t
*hashtab
)
2292 struct xfs_buf
**bplist
;
2299 xfs_fileoff_t next_da_bno
;
2303 struct xfs_da_args args
;
2306 freetab
= malloc(FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2308 do_error(_("malloc failed in %s (%" PRId64
" bytes)\n"),
2310 FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2313 freetab
->naents
= ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
;
2315 for (i
= 0; i
< freetab
->naents
; i
++) {
2316 freetab
->ents
[i
].v
= NULLDATAOFF
;
2317 freetab
->ents
[i
].s
= 0;
2319 num_bps
= freetab
->naents
;
2320 bplist
= calloc(num_bps
, sizeof(struct xfs_buf
*));
2322 do_error(_("calloc failed in %s (%zu bytes)\n"),
2323 __func__
, num_bps
* sizeof(struct xfs_buf
*));
2325 /* is this a block, leaf, or node directory? */
2327 args
.geo
= mp
->m_dir_geo
;
2328 libxfs_dir2_isblock(&args
, &isblock
);
2329 libxfs_dir2_isleaf(&args
, &isleaf
);
2331 /* check directory "data" blocks (ie. name/inode pairs) */
2332 for (da_bno
= 0, next_da_bno
= 0;
2333 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->leafblk
;
2334 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2335 const struct xfs_buf_ops
*ops
;
2337 struct xfs_dir2_data_hdr
*d
;
2339 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2340 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
)) {
2342 * if this is the first block, there isn't anything we
2343 * can recover so we just trash it.
2352 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2353 if (db
>= num_bps
) {
2354 int last_size
= num_bps
;
2356 /* more data blocks than expected */
2358 bplist
= realloc(bplist
, num_bps
* sizeof(struct xfs_buf
*));
2360 do_error(_("realloc failed in %s (%zu bytes)\n"),
2362 num_bps
* sizeof(struct xfs_buf
*));
2363 /* Initialize the new elements */
2364 for (i
= last_size
; i
< num_bps
; i
++)
2369 ops
= &xfs_dir3_block_buf_ops
;
2371 ops
= &xfs_dir3_data_buf_ops
;
2373 error
= dir_read_buf(ip
, da_bno
, -1, &bplist
[db
], ops
, &fixit
);
2376 _("can't read data block %u for directory inode %" PRIu64
" error %d\n"),
2377 da_bno
, ino
, error
);
2381 * we try to read all "data" blocks, but if we are in
2382 * block form and we fail, there isn't anything else to
2383 * read, and nothing we can do but trash it.
2392 /* check v5 metadata */
2393 d
= bplist
[db
]->b_addr
;
2394 if (be32_to_cpu(d
->magic
) == XFS_DIR3_BLOCK_MAGIC
||
2395 be32_to_cpu(d
->magic
) == XFS_DIR3_DATA_MAGIC
) {
2396 struct xfs_buf
*bp
= bplist
[db
];
2398 error
= check_dir3_header(mp
, bp
, ino
);
2405 longform_dir2_entry_check_data(mp
, ip
, num_illegal
, need_dot
,
2406 irec
, ino_offset
, &bplist
[db
], hashtab
,
2407 &freetab
, da_bno
, isblock
);
2409 fixit
|= (*num_illegal
!= 0) || dir2_is_badino(ino
) || *need_dot
;
2411 if (!dotdot_update
) {
2412 /* check btree and freespace */
2414 struct xfs_dir2_data_hdr
*block
;
2415 xfs_dir2_block_tail_t
*btp
;
2416 xfs_dir2_leaf_entry_t
*blp
;
2418 block
= bplist
[0]->b_addr
;
2419 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, block
);
2420 blp
= xfs_dir2_block_leaf_p(btp
);
2421 seeval
= dir_hash_see_all(hashtab
, blp
,
2422 be32_to_cpu(btp
->count
),
2423 be32_to_cpu(btp
->stale
));
2424 if (dir_hash_check(hashtab
, ip
, seeval
))
2426 } else if (isleaf
) {
2427 fixit
|= longform_dir2_check_leaf(mp
, ip
, hashtab
,
2430 fixit
|= longform_dir2_check_node(mp
, ip
, hashtab
,
2435 if (!no_modify
&& (fixit
|| dotdot_update
)) {
2436 dir_hash_dup_names(hashtab
);
2437 for (i
= 0; i
< num_bps
; i
++)
2439 libxfs_putbuf(bplist
[i
]);
2440 longform_dir2_rebuild(mp
, ino
, ip
, irec
, ino_offset
, hashtab
);
2444 for (i
= 0; i
< num_bps
; i
++)
2446 libxfs_putbuf(bplist
[i
]);
2454 * shortform directory v2 processing routines -- entry verification and
2455 * bad entry deletion (pruning).
2457 static struct xfs_dir2_sf_entry
*
2458 shortform_dir2_junk(
2459 struct xfs_mount
*mp
,
2460 struct xfs_dir2_sf_hdr
*sfp
,
2461 struct xfs_dir2_sf_entry
*sfep
,
2468 struct xfs_dir2_sf_entry
*next_sfep
;
2472 if (lino
== orphanage_ino
)
2475 next_elen
= libxfs_dir2_sf_entsize(mp
, sfp
, sfep
->namelen
);
2476 next_sfep
= libxfs_dir2_sf_nextentry(mp
, sfp
, sfep
);
2479 * if we are just checking, simply return the pointer to the next entry
2480 * here so that the checking loop can continue.
2483 do_warn(_("would junk entry\n"));
2488 * now move all the remaining entries down over the junked entry and
2489 * clear the newly unused bytes at the tail of the directory region.
2491 next_len
= *max_size
- ((intptr_t)next_sfep
- (intptr_t)sfp
);
2492 *max_size
-= next_elen
;
2493 *bytes_deleted
+= next_elen
;
2495 memmove(sfep
, next_sfep
, next_len
);
2496 memset((void *)((intptr_t)sfep
+ next_len
), 0, next_elen
);
2501 * WARNING: drop the index i by one so it matches the decremented count
2502 * for accurate comparisons in the loop test
2507 do_warn(_("junking entry\n"));
2514 shortform_dir2_entry_check(xfs_mount_t
*mp
,
2518 ino_tree_node_t
*current_irec
,
2519 int current_ino_offset
,
2520 dir_hash_tab_t
*hashtab
)
2524 struct xfs_dir2_sf_hdr
*sfp
;
2525 struct xfs_dir2_sf_entry
*sfep
;
2526 struct xfs_dir2_sf_entry
*next_sfep
;
2527 struct xfs_ifork
*ifp
;
2528 struct ino_tree_node
*irec
;
2535 char fname
[MAXNAMELEN
+ 1];
2539 sfp
= (struct xfs_dir2_sf_hdr
*) ifp
->if_u1
.if_data
;
2543 max_size
= ifp
->if_bytes
;
2544 ASSERT(ip
->i_d
.di_size
<= ifp
->if_bytes
);
2547 * if just rebuild a directory due to a "..", update and return
2549 if (dotdot_update
) {
2550 parent
= get_inode_parent(current_irec
, current_ino_offset
);
2553 _("would set .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2557 _("setting .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2559 libxfs_dir2_sf_put_parent_ino(sfp
, parent
);
2566 * no '.' entry in shortform dirs, just bump up ref count by 1
2567 * '..' was already (or will be) accounted for and checked when
2568 * the directory is reached or will be taken care of when the
2569 * directory is moved to orphanage.
2571 add_inode_ref(current_irec
, current_ino_offset
);
2574 * Initialise i8 counter -- the parent inode number counts as well.
2576 i8
= libxfs_dir2_sf_get_parent_ino(sfp
) > XFS_DIR2_MAX_SHORT_INUM
;
2579 * now run through entries, stop at first bad entry, don't need
2580 * to skip over '..' since that's encoded in its own field and
2581 * no need to worry about '.' since it doesn't exist.
2583 sfep
= next_sfep
= xfs_dir2_sf_firstentry(sfp
);
2585 for (i
= 0; i
< sfp
->count
&& max_size
>
2586 (intptr_t)next_sfep
- (intptr_t)sfp
;
2587 sfep
= next_sfep
, i
++) {
2590 lino
= libxfs_dir2_sf_get_ino(mp
, sfp
, sfep
);
2592 namelen
= sfep
->namelen
;
2594 ASSERT(no_modify
|| namelen
> 0);
2596 if (no_modify
&& namelen
== 0) {
2598 * if we're really lucky, this is
2599 * the last entry in which case we
2600 * can use the dir size to set the
2601 * namelen value. otherwise, forget
2602 * it because we're not going to be
2603 * able to find the next entry.
2607 if (i
== sfp
->count
- 1) {
2608 namelen
= ip
->i_d
.di_size
-
2609 ((intptr_t) &sfep
->name
[0] -
2613 * don't process the rest of the directory,
2614 * break out of processing loop
2618 } else if (no_modify
&& (intptr_t) sfep
- (intptr_t) sfp
+
2619 + libxfs_dir2_sf_entsize(mp
, sfp
, sfep
->namelen
)
2620 > ip
->i_d
.di_size
) {
2623 if (i
== sfp
->count
- 1) {
2624 namelen
= ip
->i_d
.di_size
-
2625 ((intptr_t) &sfep
->name
[0] -
2629 * don't process the rest of the directory,
2630 * break out of processing loop
2636 memmove(fname
, sfep
->name
, sfep
->namelen
);
2637 fname
[sfep
->namelen
] = '\0';
2639 ASSERT(no_modify
|| (lino
!= NULLFSINO
&& lino
!= 0));
2640 ASSERT(no_modify
|| !verify_inum(mp
, lino
));
2643 * Also skip entries with bogus inode numbers if we're
2644 * in no modify mode.
2647 if (no_modify
&& verify_inum(mp
, lino
)) {
2648 next_sfep
= libxfs_dir2_sf_nextentry(mp
, sfp
, sfep
);
2652 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, lino
),
2653 XFS_INO_TO_AGINO(mp
, lino
));
2657 _("entry \"%s\" in shortform directory %" PRIu64
" references non-existent inode %" PRIu64
"\n"),
2659 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2660 &max_size
, &i
, &bytes_deleted
,
2665 ino_offset
= XFS_INO_TO_AGINO(mp
, lino
) - irec
->ino_startnum
;
2668 * if it's a free inode, blow out the entry.
2669 * by now, any inode that we think is free
2672 if (is_inode_free(irec
, ino_offset
)) {
2674 _("entry \"%s\" in shortform directory inode %" PRIu64
" points to free inode %" PRIu64
"\n"),
2676 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2677 &max_size
, &i
, &bytes_deleted
,
2682 * check if this inode is lost+found dir in the root
2684 if (ino
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
2686 * if it's not a directory, trash it
2688 if (!inode_isadir(irec
, ino_offset
)) {
2690 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
2691 ORPHANAGE
, lino
, ino
);
2692 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2693 lino
, &max_size
, &i
,
2694 &bytes_deleted
, ino_dirty
);
2698 * if this is a dup, it will be picked up below,
2699 * otherwise, mark it as the orphanage for later.
2702 orphanage_ino
= lino
;
2705 * check for duplicate names in directory.
2707 if (!dir_hash_add(mp
, hashtab
, (xfs_dir2_dataptr_t
)
2708 (sfep
- xfs_dir2_sf_firstentry(sfp
)),
2709 lino
, sfep
->namelen
, sfep
->name
,
2710 libxfs_dir2_sf_get_ftype(mp
, sfep
))) {
2712 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
2714 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2715 &max_size
, &i
, &bytes_deleted
,
2720 if (!inode_isadir(irec
, ino_offset
)) {
2722 * check easy case first, regular inode, just bump
2725 add_inode_reached(irec
, ino_offset
);
2727 parent
= get_inode_parent(irec
, ino_offset
);
2730 * bump up the link counts in parent and child.
2731 * directory but if the link doesn't agree with
2732 * the .. in the child, blow out the entry
2734 if (is_inode_reached(irec
, ino_offset
)) {
2736 _("entry \"%s\" in directory inode %" PRIu64
2737 " references already connected inode %" PRIu64
".\n"),
2739 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2740 lino
, &max_size
, &i
,
2741 &bytes_deleted
, ino_dirty
);
2743 } else if (parent
== ino
) {
2744 add_inode_reached(irec
, ino_offset
);
2745 add_inode_ref(current_irec
, current_ino_offset
);
2746 } else if (parent
== NULLFSINO
) {
2747 /* ".." was missing, but this entry refers to it,
2748 so, set it as the parent and mark for rebuild */
2750 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
2752 set_inode_parent(irec
, ino_offset
, ino
);
2753 add_inode_reached(irec
, ino_offset
);
2754 add_inode_ref(current_irec
, current_ino_offset
);
2755 add_dotdot_update(XFS_INO_TO_AGNO(mp
, lino
),
2759 _("entry \"%s\" in directory inode %" PRIu64
2760 " not consistent with .. value (%" PRIu64
2761 ") in inode %" PRIu64
",\n"),
2762 fname
, ino
, parent
, lino
);
2763 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2764 lino
, &max_size
, &i
,
2765 &bytes_deleted
, ino_dirty
);
2770 /* validate ftype field if supported */
2771 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
2775 dir_ftype
= libxfs_dir2_sf_get_ftype(mp
, sfep
);
2776 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
2778 if (dir_ftype
!= ino_ftype
) {
2781 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2782 dir_ftype
, ino_ftype
,
2786 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2787 dir_ftype
, ino_ftype
,
2789 libxfs_dir2_sf_put_ftype(mp
, sfep
,
2791 dir_hash_update_ftype(hashtab
,
2792 (xfs_dir2_dataptr_t
)(sfep
- xfs_dir2_sf_firstentry(sfp
)),
2799 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
2803 * go onto next entry - we have to take entries with bad namelen
2804 * into account in no modify mode since we calculate size based
2807 ASSERT(no_modify
|| bad_sfnamelen
== 0);
2808 next_sfep
= (struct xfs_dir2_sf_entry
*)((intptr_t)sfep
+
2810 ? libxfs_dir2_sf_entsize(mp
, sfp
, namelen
)
2811 : libxfs_dir2_sf_entsize(mp
, sfp
, sfep
->namelen
)));
2814 if (sfp
->i8count
!= i8
) {
2816 do_warn(_("would fix i8count in inode %" PRIu64
"\n"),
2820 struct xfs_dir2_sf_entry
*tmp_sfep
;
2822 tmp_sfep
= next_sfep
;
2823 process_sf_dir2_fixi8(mp
, sfp
, &tmp_sfep
);
2825 (intptr_t)next_sfep
-
2827 next_sfep
= tmp_sfep
;
2831 do_warn(_("fixing i8count in inode %" PRIu64
"\n"),
2837 * sync up sizes if required
2839 if (*ino_dirty
&& bytes_deleted
> 0) {
2841 libxfs_idata_realloc(ip
, -bytes_deleted
, XFS_DATA_FORK
);
2842 ip
->i_d
.di_size
-= bytes_deleted
;
2845 if (ip
->i_d
.di_size
!= ip
->i_df
.if_bytes
) {
2846 ASSERT(ip
->i_df
.if_bytes
== (xfs_fsize_t
)
2847 ((intptr_t) next_sfep
- (intptr_t) sfp
));
2848 ip
->i_d
.di_size
= (xfs_fsize_t
)
2849 ((intptr_t) next_sfep
- (intptr_t) sfp
);
2851 _("setting size to %" PRId64
" bytes to reflect junked entries\n"),
2858 * processes all reachable inodes in directories
2863 xfs_agnumber_t agno
,
2864 ino_tree_node_t
*irec
,
2870 dir_hash_tab_t
*hashtab
;
2872 int dirty
, num_illegal
, error
, nres
;
2874 ino
= XFS_AGINO_TO_INO(mp
, agno
, irec
->ino_startnum
+ ino_offset
);
2877 * open up directory inode, check all entries,
2878 * then call prune_dir_entries to remove all
2879 * remaining illegal directory entries.
2882 ASSERT(!is_inode_refchecked(irec
, ino_offset
) || dotdot_update
);
2884 error
= -libxfs_iget(mp
, NULL
, ino
, 0, &ip
, &phase6_ifork_ops
);
2888 _("couldn't map inode %" PRIu64
", err = %d\n"),
2892 _("couldn't map inode %" PRIu64
", err = %d\n"),
2895 * see below for what we're doing if this
2896 * is root. Why do we need to do this here?
2897 * to ensure that the root doesn't show up
2898 * as being disconnected in the no_modify case.
2900 if (mp
->m_sb
.sb_rootino
== ino
) {
2901 add_inode_reached(irec
, 0);
2902 add_inode_ref(irec
, 0);
2906 add_inode_refchecked(irec
, 0);
2910 need_dot
= dirty
= num_illegal
= 0;
2912 if (mp
->m_sb
.sb_rootino
== ino
) {
2914 * mark root inode reached and bump up
2915 * link count for root inode to account
2916 * for '..' entry since the root inode is
2917 * never reached by a parent. we know
2918 * that root's '..' is always good --
2919 * guaranteed by phase 3 and/or below.
2921 add_inode_reached(irec
, ino_offset
);
2924 add_inode_refchecked(irec
, ino_offset
);
2926 hashtab
= dir_hash_init(ip
->i_d
.di_size
);
2929 * look for bogus entries
2931 switch (ip
->i_d
.di_format
) {
2932 case XFS_DINODE_FMT_EXTENTS
:
2933 case XFS_DINODE_FMT_BTREE
:
2935 * also check for missing '.' in longform dirs.
2936 * missing .. entries are added if required when
2937 * the directory is connected to lost+found. but
2938 * we need to create '.' entries here.
2940 longform_dir2_entry_check(mp
, ino
, ip
,
2941 &num_illegal
, &need_dot
,
2946 case XFS_DINODE_FMT_LOCAL
:
2948 * using the remove reservation is overkill
2949 * since at most we'll only need to log the
2950 * inode but it's easier than wedging a
2951 * new define in ourselves.
2953 nres
= no_modify
? 0 : XFS_REMOVE_SPACE_RES(mp
);
2954 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
2959 libxfs_trans_ijoin(tp
, ip
, 0);
2961 shortform_dir2_entry_check(mp
, ino
, ip
, &dirty
,
2965 ASSERT(dirty
== 0 || (dirty
&& !no_modify
));
2967 libxfs_trans_log_inode(tp
, ip
,
2968 XFS_ILOG_CORE
| XFS_ILOG_DDATA
);
2969 error
= -libxfs_trans_commit(tp
);
2972 _("error %d fixing shortform directory %llu\n"),
2974 (unsigned long long)ip
->i_ino
);
2976 libxfs_trans_cancel(tp
);
2983 dir_hash_done(hashtab
);
2986 * if we have to create a .. for /, do it now *before*
2987 * we delete the bogus entries, otherwise the directory
2988 * could transform into a shortform dir which would
2989 * probably cause the simulation to choke. Even
2990 * if the illegal entries get shifted around, it's ok
2991 * because the entries are structurally intact and in
2992 * in hash-value order so the simulation won't get confused
2993 * if it has to move them around.
2995 if (!no_modify
&& need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2996 ASSERT(ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
);
2998 do_warn(_("recreating root directory .. entry\n"));
3000 nres
= XFS_MKDIR_SPACE_RES(mp
, 2);
3001 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3006 libxfs_trans_ijoin(tp
, ip
, 0);
3008 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dotdot
,
3012 _("can't make \"..\" entry in root inode %" PRIu64
", createname error %d\n"), ino
, error
);
3014 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3015 error
= -libxfs_trans_commit(tp
);
3018 _("root inode \"..\" entry recreation failed (%d)\n"), error
);
3020 need_root_dotdot
= 0;
3021 } else if (need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
3022 do_warn(_("would recreate root directory .. entry\n"));
3026 * if we need to create the '.' entry, do so only if
3027 * the directory is a longform dir. if it's been
3028 * turned into a shortform dir, then the inode is ok
3029 * since shortform dirs have no '.' entry and the inode
3030 * has already been committed by prune_lf_dir_entry().
3034 * bump up our link count but don't
3035 * bump up the inode link count. chances
3036 * are good that even though we lost '.'
3037 * the inode link counts reflect '.' so
3038 * leave the inode link count alone and if
3039 * it turns out to be wrong, we'll catch
3042 add_inode_ref(irec
, ino_offset
);
3046 _("would create missing \".\" entry in dir ino %" PRIu64
"\n"),
3048 } else if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
) {
3050 * need to create . entry in longform dir.
3053 _("creating missing \".\" entry in dir ino %" PRIu64
"\n"), ino
);
3055 nres
= XFS_MKDIR_SPACE_RES(mp
, 1);
3056 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3061 libxfs_trans_ijoin(tp
, ip
, 0);
3063 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dot
,
3067 _("can't make \".\" entry in dir ino %" PRIu64
", createname error %d\n"),
3070 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3071 error
= -libxfs_trans_commit(tp
);
3074 _("root inode \".\" entry recreation failed (%d)\n"), error
);
3081 * mark realtime bitmap and summary inodes as reached.
3082 * quota inode will be marked here as well
3085 mark_standalone_inodes(xfs_mount_t
*mp
)
3087 ino_tree_node_t
*irec
;
3090 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rbmino
),
3091 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
));
3093 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
) -
3096 add_inode_reached(irec
, offset
);
3098 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rsumino
),
3099 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
));
3101 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
) -
3104 add_inode_reached(irec
, offset
);
3107 if (mp
->m_sb
.sb_uquotino
3108 && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
3109 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3110 mp
->m_sb
.sb_uquotino
),
3111 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
));
3112 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
)
3113 - irec
->ino_startnum
;
3114 add_inode_reached(irec
, offset
);
3116 if (mp
->m_sb
.sb_gquotino
3117 && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
3118 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3119 mp
->m_sb
.sb_gquotino
),
3120 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
));
3121 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
)
3122 - irec
->ino_startnum
;
3123 add_inode_reached(irec
, offset
);
3125 if (mp
->m_sb
.sb_pquotino
3126 && mp
->m_sb
.sb_pquotino
!= NULLFSINO
) {
3127 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3128 mp
->m_sb
.sb_pquotino
),
3129 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
));
3130 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
)
3131 - irec
->ino_startnum
;
3132 add_inode_reached(irec
, offset
);
3138 check_for_orphaned_inodes(
3140 xfs_agnumber_t agno
,
3141 ino_tree_node_t
*irec
)
3146 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3147 ASSERT(is_inode_confirmed(irec
, i
));
3148 if (is_inode_free(irec
, i
))
3151 if (is_inode_reached(irec
, i
))
3154 ASSERT(inode_isadir(irec
, i
) ||
3155 num_inode_references(irec
, i
) == 0);
3157 ino
= XFS_AGINO_TO_INO(mp
, agno
, i
+ irec
->ino_startnum
);
3158 if (inode_isadir(irec
, i
))
3159 do_warn(_("disconnected dir inode %" PRIu64
", "), ino
);
3161 do_warn(_("disconnected inode %" PRIu64
", "), ino
);
3164 orphanage_ino
= mk_orphanage(mp
);
3165 do_warn(_("moving to %s\n"), ORPHANAGE
);
3166 mv_orphanage(mp
, ino
, inode_isadir(irec
, i
));
3168 do_warn(_("would move to %s\n"), ORPHANAGE
);
3171 * for read-only case, even though the inode isn't
3172 * really reachable, set the flag (and bump our link
3173 * count) anyway to fool phase 7
3175 add_inode_reached(irec
, i
);
3181 struct workqueue
*wq
,
3182 xfs_agnumber_t agno
,
3185 ino_tree_node_t
*irec
;
3187 prefetch_args_t
*pf_args
= arg
;
3189 wait_for_inode_prefetch(pf_args
);
3192 do_log(_(" - agno = %d\n"), agno
);
3194 for (irec
= findfirst_inode_rec(agno
); irec
; irec
= next_ino_rec(irec
)) {
3195 if (irec
->ino_isa_dir
== 0)
3199 sem_post(&pf_args
->ra_count
);
3201 sem_getvalue(&pf_args
->ra_count
, &i
);
3203 "processing inode chunk %p in AG %d (sem count = %d)",
3208 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3209 if (inode_isadir(irec
, i
))
3210 process_dir_inode(wq
->wq_ctx
, agno
, irec
, i
);
3213 cleanup_inode_prefetch(pf_args
);
3217 update_missing_dotdot_entries(
3220 dotdot_update_t
*dir
;
3223 * these entries parents were updated, rebuild them again
3224 * set dotdot_update flag so processing routines do not count links
3227 while (!list_empty(&dotdot_update_list
)) {
3228 dir
= list_entry(dotdot_update_list
.prev
, struct dotdot_update
,
3230 list_del(&dir
->list
);
3231 process_dir_inode(mp
, dir
->agno
, dir
->irec
, dir
->ino_offset
);
3238 struct xfs_mount
*mp
)
3240 do_inode_prefetch(mp
, 0, traverse_function
, false, true);
3244 phase6(xfs_mount_t
*mp
)
3246 ino_tree_node_t
*irec
;
3249 memset(&zerocr
, 0, sizeof(struct cred
));
3250 memset(&zerofsx
, 0, sizeof(struct fsxattr
));
3253 do_log(_("Phase 6 - check inode connectivity...\n"));
3255 incore_ext_teardown(mp
);
3257 add_ino_ex_data(mp
);
3260 * verify existence of root directory - if we have to
3261 * make one, it's ok for the incore data structs not to
3262 * know about it since everything about it (and the other
3263 * inodes in its chunk if a new chunk was created) are ok
3265 if (need_root_inode
) {
3267 do_warn(_("reinitializing root directory\n"));
3269 need_root_inode
= 0;
3270 need_root_dotdot
= 0;
3272 do_warn(_("would reinitialize root directory\n"));
3278 do_warn(_("reinitializing realtime bitmap inode\n"));
3282 do_warn(_("would reinitialize realtime bitmap inode\n"));
3288 do_warn(_("reinitializing realtime summary inode\n"));
3292 do_warn(_("would reinitialize realtime summary inode\n"));
3298 _(" - resetting contents of realtime bitmap and summary inodes\n"));
3299 if (fill_rbmino(mp
)) {
3301 _("Warning: realtime bitmap may be inconsistent\n"));
3304 if (fill_rsumino(mp
)) {
3306 _("Warning: realtime bitmap may be inconsistent\n"));
3310 mark_standalone_inodes(mp
);
3312 do_log(_(" - traversing filesystem ...\n"));
3314 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
3315 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
3318 * we always have a root inode, even if it's free...
3319 * if the root is free, forget it, lost+found is already gone
3321 if (is_inode_free(irec
, 0) || !inode_isadir(irec
, 0)) {
3322 need_root_inode
= 1;
3326 * then process all inodes by walking incore inode tree
3331 * any directories that had updated ".." entries, rebuild them now
3333 update_missing_dotdot_entries(mp
);
3335 do_log(_(" - traversal finished ...\n"));
3336 do_log(_(" - moving disconnected inodes to %s ...\n"),
3340 * move all disconnected inodes to the orphanage
3342 for (i
= 0; i
< glob_agcount
; i
++) {
3343 irec
= findfirst_inode_rec(i
);
3344 while (irec
!= NULL
) {
3345 check_for_orphaned_inodes(mp
, i
, irec
);
3346 irec
= next_ino_rec(irec
);