2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "err_protos.h"
33 static struct cred zerocr
;
34 static struct fsxattr zerofsx
;
35 static xfs_ino_t orphanage_ino
;
37 static struct xfs_name xfs_name_dot
= {(unsigned char *)".",
42 * When we're checking directory inodes, we're allowed to set a directory's
43 * dotdot entry to zero to signal that the parent needs to be reconnected
44 * during phase 6. If we're handling a shortform directory the ifork
45 * verifiers will fail, so temporarily patch out this canary so that we can
46 * verify the rest of the fork and move on to fixing the dir.
52 struct xfs_mount
*mp
= ip
->i_mount
;
53 const struct xfs_dir_ops
*dops
;
54 struct xfs_ifork
*ifp
;
55 struct xfs_dir2_sf_hdr
*sfp
;
58 bool parent_bypass
= false;
61 dops
= libxfs_dir_get_ops(mp
, NULL
);
63 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
64 sfp
= (struct xfs_dir2_sf_hdr
*)ifp
->if_u1
.if_data
;
68 * If this is a shortform directory, phase4 may have set the parent
69 * inode to zero to indicate that it must be fixed. Temporarily
70 * set a valid parent so that the directory verifier will pass.
72 if (size
> offsetof(struct xfs_dir2_sf_hdr
, parent
) &&
73 size
>= xfs_dir2_sf_hdr_size(sfp
->i8count
)) {
74 old_parent
= dops
->sf_get_parent_ino(sfp
);
75 if (old_parent
== 0) {
76 dops
->sf_put_parent_ino(sfp
, mp
->m_sb
.sb_rootino
);
81 fa
= libxfs_default_ifork_ops
.verify_dir(ip
);
85 dops
->sf_put_parent_ino(sfp
, old_parent
);
90 static struct xfs_ifork_ops phase6_ifork_ops
= {
91 .verify_attr
= xfs_attr_shortform_verify
,
92 .verify_dir
= phase6_verify_dir
,
93 .verify_symlink
= xfs_symlink_shortform_verify
,
97 * Data structures used to keep track of directories where the ".."
98 * entries are updated. These must be rebuilt after the initial pass
100 typedef struct dotdot_update
{
101 struct list_head list
;
102 ino_tree_node_t
*irec
;
107 static LIST_HEAD(dotdot_update_list
);
108 static int dotdot_update
;
113 ino_tree_node_t
*irec
,
116 dotdot_update_t
*dir
= malloc(sizeof(dotdot_update_t
));
119 do_error(_("malloc failed add_dotdot_update (%zu bytes)\n"),
120 sizeof(dotdot_update_t
));
122 INIT_LIST_HEAD(&dir
->list
);
125 dir
->ino_offset
= ino_offset
;
127 list_add(&dir
->list
, &dotdot_update_list
);
131 * Data structures and routines to keep track of directory entries
132 * and whether their leaf entry has been seen. Also used for name
133 * duplicate checking and rebuilding step if required.
135 typedef struct dir_hash_ent
{
136 struct dir_hash_ent
*nextbyaddr
; /* next in addr bucket */
137 struct dir_hash_ent
*nextbyhash
; /* next in name bucket */
138 struct dir_hash_ent
*nextbyorder
; /* next in order added */
139 xfs_dahash_t hashval
; /* hash value of name */
140 uint32_t address
; /* offset of data entry */
141 xfs_ino_t inum
; /* inode num of entry */
142 short junkit
; /* name starts with / */
143 short seen
; /* have seen leaf entry */
144 struct xfs_name name
;
147 typedef struct dir_hash_tab
{
148 int size
; /* size of hash tables */
149 int names_duped
; /* 1 = ent names malloced */
150 dir_hash_ent_t
*first
; /* ptr to first added entry */
151 dir_hash_ent_t
*last
; /* ptr to last added entry */
152 dir_hash_ent_t
**byhash
; /* ptr to name hash buckets */
153 dir_hash_ent_t
**byaddr
; /* ptr to addr hash buckets */
156 #define DIR_HASH_TAB_SIZE(n) \
157 (sizeof(dir_hash_tab_t) + (sizeof(dir_hash_ent_t *) * (n) * 2))
158 #define DIR_HASH_FUNC(t,a) ((a) % (t)->size)
161 * Track the contents of the freespace table in a directory.
163 typedef struct freetab
{
164 int naents
; /* expected number of data blocks */
165 int nents
; /* number of data blocks processed */
167 xfs_dir2_data_off_t v
;
171 #define FREETAB_SIZE(n) \
172 (offsetof(freetab_t, ents) + (sizeof(struct freetab_ent) * (n)))
174 #define DIR_HASH_CK_OK 0
175 #define DIR_HASH_CK_DUPLEAF 1
176 #define DIR_HASH_CK_BADHASH 2
177 #define DIR_HASH_CK_NODATA 3
178 #define DIR_HASH_CK_NOLEAF 4
179 #define DIR_HASH_CK_BADSTALE 5
180 #define DIR_HASH_CK_TOTAL 6
183 * Need to handle CRC and validation errors specially here. If there is a
184 * validator error, re-read without the verifier so that we get a buffer we can
185 * check and repair. Re-attach the ops to the buffer after the read so that when
186 * it is rewritten the CRC is recalculated.
188 * If the buffer was not read, we return an error. If the buffer was read but
189 * had a CRC or corruption error, we reread it without the verifier and if it is
190 * read successfully we increment *crc_error and return 0. Otherwise we
191 * return the read error.
195 struct xfs_inode
*ip
,
197 xfs_daddr_t mappedbno
,
198 struct xfs_buf
**bpp
,
199 const struct xfs_buf_ops
*ops
,
205 error
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
208 if (error
!= EFSBADCRC
&& error
!= EFSCORRUPTED
)
211 error2
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
212 XFS_DATA_FORK
, NULL
);
222 * Returns 0 if the name already exists (ie. a duplicate)
227 dir_hash_tab_t
*hashtab
,
234 xfs_dahash_t hash
= 0;
240 struct xfs_name xname
;
242 ASSERT(!hashtab
->names_duped
);
248 junk
= name
[0] == '/';
249 byaddr
= DIR_HASH_FUNC(hashtab
, addr
);
253 hash
= mp
->m_dirnameops
->hashname(&xname
);
254 byhash
= DIR_HASH_FUNC(hashtab
, hash
);
257 * search hash bucket for existing name.
259 for (p
= hashtab
->byhash
[byhash
]; p
; p
= p
->nextbyhash
) {
260 if (p
->hashval
== hash
&& p
->name
.len
== namelen
) {
261 if (memcmp(p
->name
.name
, name
, namelen
) == 0) {
270 if ((p
= malloc(sizeof(*p
))) == NULL
)
271 do_error(_("malloc failed in dir_hash_add (%zu bytes)\n"),
274 p
->nextbyaddr
= hashtab
->byaddr
[byaddr
];
275 hashtab
->byaddr
[byaddr
] = p
;
277 hashtab
->last
->nextbyorder
= p
;
280 p
->nextbyorder
= NULL
;
283 if (!(p
->junkit
= junk
)) {
285 p
->nextbyhash
= hashtab
->byhash
[byhash
];
286 hashtab
->byhash
[byhash
] = p
;
297 * checks to see if any data entries are not in the leaf blocks
301 dir_hash_tab_t
*hashtab
)
306 for (i
= 0; i
< hashtab
->size
; i
++) {
307 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
317 dir_hash_tab_t
*hashtab
,
321 static char *seevalstr
[DIR_HASH_CK_TOTAL
];
325 seevalstr
[DIR_HASH_CK_OK
] = _("ok");
326 seevalstr
[DIR_HASH_CK_DUPLEAF
] = _("duplicate leaf");
327 seevalstr
[DIR_HASH_CK_BADHASH
] = _("hash value mismatch");
328 seevalstr
[DIR_HASH_CK_NODATA
] = _("no data entry");
329 seevalstr
[DIR_HASH_CK_NOLEAF
] = _("no leaf entry");
330 seevalstr
[DIR_HASH_CK_BADSTALE
] = _("bad stale count");
334 if (seeval
== DIR_HASH_CK_OK
&& dir_hash_unseen(hashtab
))
335 seeval
= DIR_HASH_CK_NOLEAF
;
336 if (seeval
== DIR_HASH_CK_OK
)
338 do_warn(_("bad hash table for directory inode %" PRIu64
" (%s): "),
339 ip
->i_ino
, seevalstr
[seeval
]);
341 do_warn(_("rebuilding\n"));
343 do_warn(_("would rebuild\n"));
349 dir_hash_tab_t
*hashtab
)
355 for (i
= 0; i
< hashtab
->size
; i
++) {
356 for (p
= hashtab
->byaddr
[i
]; p
; p
= n
) {
358 if (hashtab
->names_duped
)
359 free((void *)p
->name
.name
);
366 static dir_hash_tab_t
*
370 dir_hash_tab_t
*hashtab
;
373 hsize
= size
/ (16 * 4);
378 if ((hashtab
= calloc(DIR_HASH_TAB_SIZE(hsize
), 1)) == NULL
)
379 do_error(_("calloc failed in dir_hash_init\n"));
380 hashtab
->size
= hsize
;
381 hashtab
->byhash
= (dir_hash_ent_t
**)((char *)hashtab
+
382 sizeof(dir_hash_tab_t
));
383 hashtab
->byaddr
= (dir_hash_ent_t
**)((char *)hashtab
+
384 sizeof(dir_hash_tab_t
) + sizeof(dir_hash_ent_t
*) * hsize
);
390 dir_hash_tab_t
*hashtab
,
392 xfs_dir2_dataptr_t addr
)
397 i
= DIR_HASH_FUNC(hashtab
, addr
);
398 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
399 if (p
->address
!= addr
)
402 return DIR_HASH_CK_DUPLEAF
;
403 if (p
->junkit
== 0 && p
->hashval
!= hash
)
404 return DIR_HASH_CK_BADHASH
;
406 return DIR_HASH_CK_OK
;
408 return DIR_HASH_CK_NODATA
;
412 dir_hash_update_ftype(
413 dir_hash_tab_t
*hashtab
,
414 xfs_dir2_dataptr_t addr
,
420 i
= DIR_HASH_FUNC(hashtab
, addr
);
421 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
422 if (p
->address
!= addr
)
424 p
->name
.type
= ftype
;
429 * checks to make sure leafs match a data entry, and that the stale
434 dir_hash_tab_t
*hashtab
,
435 xfs_dir2_leaf_entry_t
*ents
,
443 for (i
= j
= 0; i
< count
; i
++) {
444 if (be32_to_cpu(ents
[i
].address
) == XFS_DIR2_NULL_DATAPTR
) {
448 rval
= dir_hash_see(hashtab
, be32_to_cpu(ents
[i
].hashval
),
449 be32_to_cpu(ents
[i
].address
));
450 if (rval
!= DIR_HASH_CK_OK
)
453 return j
== stale
? DIR_HASH_CK_OK
: DIR_HASH_CK_BADSTALE
;
457 * Convert name pointers into locally allocated memory.
458 * This must only be done after all the entries have been added.
461 dir_hash_dup_names(dir_hash_tab_t
*hashtab
)
466 if (hashtab
->names_duped
)
469 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
470 name
= malloc(p
->name
.len
);
471 memcpy(name
, p
->name
.name
, p
->name
.len
);
474 hashtab
->names_duped
= 1;
478 * Given a block number in a fork, return the next valid block number
480 * If this is the last block number then NULLFILEOFF is returned.
482 * This was originally in the kernel, but only used in xfs_repair.
486 xfs_trans_t
*tp
, /* transaction pointer */
487 xfs_inode_t
*ip
, /* incore inode */
488 xfs_fileoff_t
*bnop
, /* current block */
489 int whichfork
) /* data or attr fork */
491 xfs_fileoff_t bno
; /* current block */
492 int error
; /* error return value */
493 xfs_bmbt_irec_t got
; /* current extent value */
494 xfs_ifork_t
*ifp
; /* inode fork pointer */
495 struct xfs_iext_cursor icur
;
497 if (XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_BTREE
&&
498 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_EXTENTS
&&
499 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_LOCAL
)
501 if (XFS_IFORK_FORMAT(ip
, whichfork
) == XFS_DINODE_FMT_LOCAL
) {
505 ifp
= XFS_IFORK_PTR(ip
, whichfork
);
506 if (!(ifp
->if_flags
& XFS_IFEXTENTS
) &&
507 (error
= -libxfs_iread_extents(tp
, ip
, whichfork
)))
510 if (!libxfs_iext_lookup_extent(ip
, ifp
, bno
, &icur
, &got
))
513 *bnop
= got
.br_startoff
< bno
? bno
: got
.br_startoff
;
523 do_error(_("ran out of disk space!\n"));
525 do_error(_("xfs_trans_reserve returned %d\n"), err
);
529 mk_rbmino(xfs_mount_t
*mp
)
538 struct xfs_defer_ops dfops
;
540 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
543 struct xfs_trans_res tres
= {0};
548 i
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
552 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
555 _("couldn't iget realtime bitmap inode -- error - %d\n"),
559 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
560 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
562 VFS_I(ip
)->i_mode
= S_IFREG
;
563 ip
->i_d
.di_version
= vers
;
564 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
565 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
567 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
569 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
570 if (ip
->i_d
.di_version
== 3) {
571 VFS_I(ip
)->i_version
= 1;
572 ip
->i_d
.di_flags2
= 0;
573 times
|= XFS_ICHGTIME_CREATE
;
575 libxfs_trans_ichgtime(tp
, ip
, times
);
580 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
581 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
582 ip
->i_df
.if_u1
.if_root
= NULL
;
584 ip
->i_d
.di_size
= mp
->m_sb
.sb_rbmblocks
* mp
->m_sb
.sb_blocksize
;
589 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
590 libxfs_trans_commit(tp
);
593 * then allocate blocks for file and fill with zeroes (stolen
596 error
= -libxfs_trans_alloc(mp
, &tres
,
597 mp
->m_sb
.sb_rbmblocks
+ (XFS_BM_MAXLEVELS(mp
,XFS_DATA_FORK
) - 1),
602 libxfs_trans_ijoin(tp
, ip
, 0);
604 libxfs_defer_init(&dfops
, &first
);
605 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
606 nmap
= XFS_BMAP_MAX_NMAP
;
607 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
608 (xfs_extlen_t
)(mp
->m_sb
.sb_rbmblocks
- bno
),
609 0, &first
, mp
->m_sb
.sb_rbmblocks
,
613 _("couldn't allocate realtime bitmap, error = %d\n"),
616 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
617 libxfs_device_zero(mp
->m_ddev_targp
,
618 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
619 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
620 bno
+= ep
->br_blockcount
;
623 libxfs_defer_ijoin(&dfops
, ip
);
624 error
= -libxfs_defer_finish(&tp
, &dfops
);
627 _("allocation of the realtime bitmap failed, error = %d\n"),
630 libxfs_trans_commit(tp
);
635 fill_rbmino(xfs_mount_t
*mp
)
646 struct xfs_trans_res tres
= {0};
651 error
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
655 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
658 _("couldn't iget realtime bitmap inode -- error - %d\n"),
663 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
665 * fill the file one block at a time
668 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
669 &first
, 1, &map
, &nmap
, NULL
);
670 if (error
|| nmap
!= 1) {
672 _("couldn't map realtime bitmap block %" PRIu64
", error = %d\n"),
676 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
678 error
= -libxfs_trans_read_buf(
680 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
681 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
685 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime bitmap inode %" PRIu64
"\n"),
686 bno
, map
.br_startblock
, mp
->m_sb
.sb_rbmino
);
690 memmove(XFS_BUF_PTR(bp
), bmp
, mp
->m_sb
.sb_blocksize
);
692 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
694 bmp
= (xfs_rtword_t
*)((intptr_t) bmp
+ mp
->m_sb
.sb_blocksize
);
698 libxfs_trans_commit(tp
);
704 fill_rsumino(xfs_mount_t
*mp
)
714 xfs_fileoff_t end_bno
;
716 struct xfs_trans_res tres
= {0};
720 end_bno
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
722 error
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
726 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
729 _("couldn't iget realtime summary inode -- error - %d\n"),
734 while (bno
< end_bno
) {
736 * fill the file one block at a time
739 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
740 &first
, 1, &map
, &nmap
, NULL
);
741 if (error
|| nmap
!= 1) {
743 _("couldn't map realtime summary inode block %" PRIu64
", error = %d\n"),
747 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
749 error
= -libxfs_trans_read_buf(
751 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
752 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
756 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime summary inode %" PRIu64
"\n"),
757 bno
, map
.br_startblock
, mp
->m_sb
.sb_rsumino
);
762 memmove(XFS_BUF_PTR(bp
), smp
, mp
->m_sb
.sb_blocksize
);
764 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
766 smp
= (xfs_suminfo_t
*)((intptr_t)smp
+ mp
->m_sb
.sb_blocksize
);
770 libxfs_trans_commit(tp
);
776 mk_rsumino(xfs_mount_t
*mp
)
786 struct xfs_defer_ops dfops
;
788 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
791 struct xfs_trans_res tres
= {0};
796 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
800 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
803 _("couldn't iget realtime summary inode -- error - %d\n"),
807 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
808 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
810 VFS_I(ip
)->i_mode
= S_IFREG
;
811 ip
->i_d
.di_version
= vers
;
812 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
813 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
815 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
817 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
818 if (ip
->i_d
.di_version
== 3) {
819 VFS_I(ip
)->i_version
= 1;
820 ip
->i_d
.di_flags2
= 0;
821 times
|= XFS_ICHGTIME_CREATE
;
823 libxfs_trans_ichgtime(tp
, ip
, times
);
828 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
829 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
830 ip
->i_df
.if_u1
.if_root
= NULL
;
832 ip
->i_d
.di_size
= mp
->m_rsumsize
;
837 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
838 libxfs_trans_commit(tp
);
841 * then allocate blocks for file and fill with zeroes (stolen
844 libxfs_defer_init(&dfops
, &first
);
846 nsumblocks
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
847 tres
.tr_logres
= BBTOB(128);
848 tres
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
849 tres
.tr_logflags
= XFS_TRANS_PERM_LOG_RES
;
850 error
= -libxfs_trans_alloc(mp
, &tres
,
851 mp
->m_sb
.sb_rbmblocks
+ (XFS_BM_MAXLEVELS(mp
,XFS_DATA_FORK
) - 1),
856 libxfs_trans_ijoin(tp
, ip
, 0);
858 libxfs_defer_init(&dfops
, &first
);
859 while (bno
< nsumblocks
) {
860 nmap
= XFS_BMAP_MAX_NMAP
;
861 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
862 (xfs_extlen_t
)(nsumblocks
- bno
),
863 0, &first
, nsumblocks
, map
, &nmap
, &dfops
);
866 _("couldn't allocate realtime summary inode, error = %d\n"),
869 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
870 libxfs_device_zero(mp
->m_ddev_targp
,
871 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
872 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
873 bno
+= ep
->br_blockcount
;
876 libxfs_defer_ijoin(&dfops
, ip
);
877 error
= -libxfs_defer_finish(&tp
, &dfops
);
880 _("allocation of the realtime summary ino failed, error = %d\n"),
883 libxfs_trans_commit(tp
);
888 * makes a new root directory.
891 mk_root_dir(xfs_mount_t
*mp
)
897 const mode_t mode
= 0755;
898 ino_tree_node_t
*irec
;
903 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
907 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rootino
, 0, 0, &ip
);
909 do_error(_("could not iget root inode -- error - %d\n"), error
);
913 * take care of the core -- initialization from xfs_ialloc()
915 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
916 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
918 VFS_I(ip
)->i_mode
= mode
|S_IFDIR
;
919 ip
->i_d
.di_version
= vers
;
920 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
921 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
923 set_nlink(VFS_I(ip
), 1); /* account for . */
925 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
926 if (ip
->i_d
.di_version
== 3) {
927 VFS_I(ip
)->i_version
= 1;
928 ip
->i_d
.di_flags2
= 0;
929 times
|= XFS_ICHGTIME_CREATE
;
931 libxfs_trans_ichgtime(tp
, ip
, times
);
933 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
938 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
939 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
940 ip
->i_df
.if_u1
.if_root
= NULL
;
945 * initialize the directory
947 ip
->d_ops
= mp
->m_dir_inode_ops
;
948 libxfs_dir_init(tp
, ip
, ip
);
950 libxfs_trans_commit(tp
);
953 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
954 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
955 set_inode_isadir(irec
, XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
) -
960 * orphanage name == lost+found
963 mk_orphanage(xfs_mount_t
*mp
)
970 ino_tree_node_t
*irec
;
974 struct xfs_defer_ops dfops
;
975 const int mode
= 0755;
977 struct xfs_name xname
;
980 * check for an existing lost+found first, if it exists, return
981 * its inode. Otherwise, we can create it. Bad lost+found inodes
982 * would have been cleared in phase3 and phase4.
985 i
= -libxfs_iget(mp
, NULL
, mp
->m_sb
.sb_rootino
, 0, &pip
,
986 &xfs_default_ifork_ops
);
988 do_error(_("%d - couldn't iget root inode to obtain %s\n"),
991 xname
.name
= (unsigned char *)ORPHANAGE
;
992 xname
.len
= strlen(ORPHANAGE
);
993 xname
.type
= XFS_DIR3_FT_DIR
;
995 if (libxfs_dir_lookup(NULL
, pip
, &xname
, &ino
, NULL
) == 0)
999 * could not be found, create it
1001 libxfs_defer_init(&dfops
, &first
);
1002 nres
= XFS_MKDIR_SPACE_RES(mp
, xname
.len
);
1003 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
, nres
, 0, 0, &tp
);
1008 * use iget/ijoin instead of trans_iget because the ialloc
1009 * wrapper can commit the transaction and start a new one
1011 /* i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip,
1012 &xfs_default_ifork_ops);
1014 do_error(_("%d - couldn't iget root inode to make %s\n"),
1017 error
= -libxfs_inode_alloc(&tp
, pip
, mode
|S_IFDIR
,
1018 1, 0, &zerocr
, &zerofsx
, &ip
);
1020 do_error(_("%s inode allocation failed %d\n"),
1023 inc_nlink(VFS_I(ip
)); /* account for . */
1026 irec
= find_inode_rec(mp
,
1027 XFS_INO_TO_AGNO(mp
, ino
),
1028 XFS_INO_TO_AGINO(mp
, ino
));
1032 * This inode is allocated from a newly created inode
1033 * chunk and therefore did not exist when inode chunks
1034 * were processed in phase3. Add this group of inodes to
1035 * the entry avl tree as if they were discovered in phase3.
1037 irec
= set_inode_free_alloc(mp
, XFS_INO_TO_AGNO(mp
, ino
),
1038 XFS_INO_TO_AGINO(mp
, ino
));
1039 alloc_ex_data(irec
);
1041 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++)
1042 set_inode_free(irec
, i
);
1045 ino_offset
= get_inode_offset(mp
, ino
, irec
);
1048 * Mark the inode allocated to lost+found as used in the AVL tree
1049 * so it is not skipped in phase 7
1051 set_inode_used(irec
, ino_offset
);
1052 add_inode_ref(irec
, ino_offset
);
1055 * now that we know the transaction will stay around,
1056 * add the root inode to it
1058 libxfs_trans_ijoin(tp
, pip
, 0);
1061 * create the actual entry
1063 error
= -libxfs_dir_createname(tp
, pip
, &xname
, ip
->i_ino
, &first
,
1067 _("can't make %s, createname error %d\n"),
1071 * bump up the link count in the root directory to account
1072 * for .. in the new directory
1074 inc_nlink(VFS_I(pip
));
1075 add_inode_ref(find_inode_rec(mp
,
1076 XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
1077 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
)), 0);
1081 libxfs_trans_log_inode(tp
, pip
, XFS_ILOG_CORE
);
1082 libxfs_dir_init(tp
, ip
, pip
);
1083 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1085 libxfs_defer_ijoin(&dfops
, ip
);
1086 error
= -libxfs_defer_finish(&tp
, &dfops
);
1088 do_error(_("%s directory creation failed -- bmapf error %d\n"),
1093 libxfs_trans_commit(tp
);
1096 add_inode_reached(irec
,ino_offset
);
1102 * move a file to the orphange.
1107 xfs_ino_t ino
, /* inode # to be moved */
1108 int isa_dir
) /* 1 if inode is a directory */
1110 xfs_inode_t
*orphanage_ip
;
1111 xfs_ino_t entry_ino_num
;
1114 xfs_fsblock_t first
;
1115 struct xfs_defer_ops dfops
;
1117 unsigned char fname
[MAXPATHLEN
+ 1];
1120 ino_tree_node_t
*irec
;
1122 struct xfs_name xname
;
1125 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu",
1126 (unsigned long long)ino
);
1128 err
= -libxfs_iget(mp
, NULL
, orphanage_ino
, 0, &orphanage_ip
,
1129 &xfs_default_ifork_ops
);
1131 do_error(_("%d - couldn't iget orphanage inode\n"), err
);
1133 * Make sure the filename is unique in the lost+found
1136 while (libxfs_dir_lookup(NULL
, orphanage_ip
, &xname
, &entry_ino_num
,
1138 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu.%d",
1139 (unsigned long long)ino
, ++incr
);
1141 /* Orphans may not have a proper parent, so use custom ops here */
1142 err
= -libxfs_iget(mp
, NULL
, ino
, 0, &ino_p
, &phase6_ifork_ops
);
1144 do_error(_("%d - couldn't iget disconnected inode\n"), err
);
1146 xname
.type
= libxfs_mode_to_ftype(VFS_I(ino_p
)->i_mode
);
1149 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, orphanage_ino
),
1150 XFS_INO_TO_AGINO(mp
, orphanage_ino
));
1152 ino_offset
= XFS_INO_TO_AGINO(mp
, orphanage_ino
) -
1154 nres
= XFS_DIRENTER_SPACE_RES(mp
, fnamelen
) +
1155 XFS_DIRENTER_SPACE_RES(mp
, 2);
1156 err
= -libxfs_dir_lookup(NULL
, ino_p
, &xfs_name_dotdot
,
1157 &entry_ino_num
, NULL
);
1159 ASSERT(err
== ENOENT
);
1161 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1165 _("space reservation failed (%d), filesystem may be out of space\n"),
1168 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1169 libxfs_trans_ijoin(tp
, ino_p
, 0);
1171 libxfs_defer_init(&dfops
, &first
);
1172 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1173 ino
, &first
, &dfops
, nres
);
1176 _("name create failed in %s (%d), filesystem may be out of space\n"),
1180 add_inode_ref(irec
, ino_offset
);
1182 inc_nlink(VFS_I(orphanage_ip
));
1183 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1185 err
= -libxfs_dir_createname(tp
, ino_p
, &xfs_name_dotdot
,
1186 orphanage_ino
, &first
, &dfops
, nres
);
1189 _("creation of .. entry failed (%d), filesystem may be out of space\n"),
1192 inc_nlink(VFS_I(ino_p
));
1193 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1195 libxfs_defer_ijoin(&dfops
, ino_p
);
1196 err
= -libxfs_defer_finish(&tp
, &dfops
);
1199 _("bmap finish failed (err - %d), filesystem may be out of space\n"),
1202 libxfs_trans_commit(tp
);
1204 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1208 _("space reservation failed (%d), filesystem may be out of space\n"),
1211 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1212 libxfs_trans_ijoin(tp
, ino_p
, 0);
1214 libxfs_defer_init(&dfops
, &first
);
1216 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1217 ino
, &first
, &dfops
, nres
);
1220 _("name create failed in %s (%d), filesystem may be out of space\n"),
1224 add_inode_ref(irec
, ino_offset
);
1226 inc_nlink(VFS_I(orphanage_ip
));
1227 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1230 * don't replace .. value if it already points
1231 * to us. that'll pop a libxfs/kernel ASSERT.
1233 if (entry_ino_num
!= orphanage_ino
) {
1234 err
= -libxfs_dir_replace(tp
, ino_p
,
1235 &xfs_name_dotdot
, orphanage_ino
,
1236 &first
, &dfops
, nres
);
1239 _("name replace op failed (%d), filesystem may be out of space\n"),
1243 libxfs_defer_ijoin(&dfops
, ino_p
);
1244 err
= -libxfs_defer_finish(&tp
, &dfops
);
1247 _("bmap finish failed (%d), filesystem may be out of space\n"),
1250 libxfs_trans_commit(tp
);
1255 * use the remove log reservation as that's
1256 * more accurate. we're only creating the
1257 * links, we're not doing the inode allocation
1258 * also accounted for in the create
1260 nres
= XFS_DIRENTER_SPACE_RES(mp
, xname
.len
);
1261 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
1265 _("space reservation failed (%d), filesystem may be out of space\n"),
1268 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1269 libxfs_trans_ijoin(tp
, ino_p
, 0);
1271 libxfs_defer_init(&dfops
, &first
);
1272 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
, ino
,
1273 &first
, &dfops
, nres
);
1276 _("name create failed in %s (%d), filesystem may be out of space\n"),
1280 set_nlink(VFS_I(ino_p
), 1);
1281 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1283 libxfs_defer_ijoin(&dfops
, ino_p
);
1284 err
= -libxfs_defer_finish(&tp
, &dfops
);
1287 _("bmap finish failed (%d), filesystem may be out of space\n"),
1290 libxfs_trans_commit(tp
);
1293 IRELE(orphanage_ip
);
1303 do_warn(msg
, iname
, ino1
, ino2
);
1306 do_warn(_(", marking entry to be junked\n"));
1310 do_warn(_(", would junk entry\n"));
1315 * Unexpected failure during the rebuild will leave the entries in
1316 * lost+found on the next run
1320 longform_dir2_rebuild(
1324 ino_tree_node_t
*irec
,
1326 dir_hash_tab_t
*hashtab
)
1331 xfs_fileoff_t lastblock
;
1332 xfs_fsblock_t firstblock
;
1333 struct xfs_defer_ops dfops
;
1339 * trash directory completely and rebuild from scratch using the
1340 * name/inode pairs in the hash table
1343 do_warn(_("rebuilding directory inode %" PRIu64
"\n"), ino
);
1346 * first attempt to locate the parent inode, if it can't be
1347 * found, set it to the root inode and it'll be moved to the
1348 * orphanage later (the inode number here needs to be valid
1349 * for the libxfs_dir_init() call).
1351 pip
.i_ino
= get_inode_parent(irec
, ino_offset
);
1352 if (pip
.i_ino
== NULLFSINO
||
1353 libxfs_dir_ino_validate(mp
, pip
.i_ino
))
1354 pip
.i_ino
= mp
->m_sb
.sb_rootino
;
1356 libxfs_defer_init(&dfops
, &firstblock
);
1358 nres
= XFS_REMOVE_SPACE_RES(mp
);
1359 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1362 libxfs_trans_ijoin(tp
, ip
, 0);
1364 if ((error
= -libxfs_bmap_last_offset(ip
, &lastblock
, XFS_DATA_FORK
)))
1365 do_error(_("xfs_bmap_last_offset failed -- error - %d\n"),
1368 /* free all data, leaf, node and freespace blocks */
1369 error
= -libxfs_bunmapi(tp
, ip
, 0, lastblock
, XFS_BMAPI_METADATA
, 0,
1370 &firstblock
, &dfops
, &done
);
1372 do_warn(_("xfs_bunmapi failed -- error - %d\n"), error
);
1373 goto out_bmap_cancel
;
1378 error
= -libxfs_dir_init(tp
, ip
, &pip
);
1380 do_warn(_("xfs_dir_init failed -- error - %d\n"), error
);
1381 goto out_bmap_cancel
;
1384 libxfs_defer_ijoin(&dfops
, ip
);
1385 error
= -libxfs_defer_finish(&tp
, &dfops
);
1387 libxfs_trans_commit(tp
);
1389 if (ino
== mp
->m_sb
.sb_rootino
)
1390 need_root_dotdot
= 0;
1392 /* go through the hash list and re-add the inodes */
1394 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
1396 if (p
->name
.name
[0] == '/' || (p
->name
.name
[0] == '.' &&
1397 (p
->name
.len
== 1 || (p
->name
.len
== 2 &&
1398 p
->name
.name
[1] == '.'))))
1401 nres
= XFS_CREATE_SPACE_RES(mp
, p
->name
.len
);
1402 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_create
,
1407 libxfs_trans_ijoin(tp
, ip
, 0);
1409 libxfs_defer_init(&dfops
, &firstblock
);
1410 error
= -libxfs_dir_createname(tp
, ip
, &p
->name
, p
->inum
,
1411 &firstblock
, &dfops
, nres
);
1414 _("name create failed in ino %" PRIu64
" (%d), filesystem may be out of space\n"),
1416 goto out_bmap_cancel
;
1419 libxfs_defer_ijoin(&dfops
, ip
);
1420 error
= -libxfs_defer_finish(&tp
, &dfops
);
1423 _("bmap finish failed (%d), filesystem may be out of space\n"),
1425 goto out_bmap_cancel
;
1428 libxfs_trans_commit(tp
);
1434 libxfs_defer_cancel(&dfops
);
1435 libxfs_trans_cancel(tp
);
1441 * Kill a block in a version 2 inode.
1442 * Makes its own transaction.
1453 xfs_fsblock_t firstblock
;
1454 struct xfs_defer_ops dfops
;
1458 nres
= XFS_REMOVE_SPACE_RES(mp
);
1459 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1462 libxfs_trans_ijoin(tp
, ip
, 0);
1463 libxfs_trans_bjoin(tp
, bp
);
1464 memset(&args
, 0, sizeof(args
));
1465 libxfs_defer_init(&dfops
, &firstblock
);
1468 args
.firstblock
= &firstblock
;
1469 args
.dfops
= &dfops
;
1470 args
.whichfork
= XFS_DATA_FORK
;
1471 args
.geo
= mp
->m_dir_geo
;
1472 if (da_bno
>= mp
->m_dir_geo
->leafblk
&& da_bno
< mp
->m_dir_geo
->freeblk
)
1473 error
= -libxfs_da_shrink_inode(&args
, da_bno
, bp
);
1475 error
= -libxfs_dir2_shrink_inode(&args
,
1476 xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
), bp
);
1478 do_error(_("shrink_inode failed inode %" PRIu64
" block %u\n"),
1480 libxfs_defer_ijoin(&dfops
, ip
);
1481 libxfs_defer_finish(&tp
, &dfops
);
1482 libxfs_trans_commit(tp
);
1486 * process a data block, also checks for .. entry
1487 * and corrects it to match what we think .. should be
1490 longform_dir2_entry_check_data(
1495 ino_tree_node_t
*current_irec
,
1496 int current_ino_offset
,
1497 struct xfs_buf
**bpp
,
1498 dir_hash_tab_t
*hashtab
,
1499 freetab_t
**freetabp
,
1503 xfs_dir2_dataptr_t addr
;
1504 xfs_dir2_leaf_entry_t
*blp
;
1506 xfs_dir2_block_tail_t
*btp
;
1507 struct xfs_dir2_data_hdr
*d
;
1509 xfs_dir2_data_entry_t
*dep
;
1510 xfs_dir2_data_unused_t
*dup
;
1511 struct xfs_dir2_data_free
*bf
;
1514 xfs_fsblock_t firstblock
;
1515 struct xfs_defer_ops dfops
;
1516 char fname
[MAXNAMELEN
+ 1];
1521 ino_tree_node_t
*irec
;
1532 struct xfs_da_args da
= {
1534 .geo
= mp
->m_dir_geo
,
1540 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1542 needscan
= needlog
= 0;
1544 freetab
= *freetabp
;
1546 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, d
);
1547 blp
= xfs_dir2_block_leaf_p(btp
);
1548 endptr
= (char *)blp
;
1549 if (endptr
> (char *)btp
)
1550 endptr
= (char *)btp
;
1551 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1552 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1554 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1556 endptr
= (char *)d
+ mp
->m_dir_geo
->blksize
;
1557 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1558 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1560 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1562 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
1564 /* check for data block beyond expected end */
1565 if (freetab
->naents
<= db
) {
1566 struct freetab_ent e
;
1568 *freetabp
= freetab
= realloc(freetab
, FREETAB_SIZE(db
+ 1));
1570 do_error(_("realloc failed in %s (%zu bytes)\n"),
1571 __func__
, FREETAB_SIZE(db
+ 1));
1575 for (i
= freetab
->naents
; i
< db
; i
++)
1576 freetab
->ents
[i
] = e
;
1577 freetab
->naents
= db
+ 1;
1580 /* check the data block */
1581 while (ptr
< endptr
) {
1583 /* check for freespace */
1584 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1585 if (XFS_DIR2_DATA_FREE_TAG
== be16_to_cpu(dup
->freetag
)) {
1587 /* check for invalid freespace length */
1588 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1589 be16_to_cpu(dup
->length
) == 0 ||
1590 (be16_to_cpu(dup
->length
) &
1591 (XFS_DIR2_DATA_ALIGN
- 1)))
1594 /* check for invalid tag */
1595 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1596 (char *)dup
- (char *)d
)
1599 /* check for block with no data entries */
1600 if ((ptr
== (char *)M_DIROPS(mp
)->data_entry_p(d
)) &&
1601 (ptr
+ be16_to_cpu(dup
->length
) >= endptr
)) {
1607 /* continue at the end of the freespace */
1608 ptr
+= be16_to_cpu(dup
->length
);
1613 /* validate data entry size */
1614 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1615 if (ptr
+ M_DIROPS(mp
)->data_entsize(dep
->namelen
) > endptr
)
1617 if (be16_to_cpu(*M_DIROPS(mp
)->data_entry_tag_p(dep
)) !=
1618 (char *)dep
- (char *)d
)
1620 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1623 /* did we find an empty or corrupt block? */
1624 if (ptr
!= endptr
) {
1627 _("empty data block %u in directory inode %" PRIu64
": "),
1631 ("corrupt block %u in directory inode %" PRIu64
": "),
1635 do_warn(_("junking block\n"));
1636 dir2_kill_block(mp
, ip
, da_bno
, bp
);
1638 do_warn(_("would junk block\n"));
1641 freetab
->ents
[db
].v
= NULLDATAOFF
;
1646 /* update number of data blocks processed */
1647 if (freetab
->nents
< db
+ 1)
1648 freetab
->nents
= db
+ 1;
1650 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, 0, 0, 0, &tp
);
1654 libxfs_trans_ijoin(tp
, ip
, 0);
1655 libxfs_trans_bjoin(tp
, bp
);
1656 libxfs_trans_bhold(tp
, bp
);
1657 libxfs_defer_init(&dfops
, &firstblock
);
1658 if (be32_to_cpu(d
->magic
) != wantmagic
) {
1660 _("bad directory block magic # %#x for directory inode %" PRIu64
" block %d: "),
1661 be32_to_cpu(d
->magic
), ip
->i_ino
, da_bno
);
1663 do_warn(_("fixing magic # to %#x\n"), wantmagic
);
1664 d
->magic
= cpu_to_be32(wantmagic
);
1667 do_warn(_("would fix magic # to %#x\n"), wantmagic
);
1670 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1672 * look at each entry. reference inode pointed to by each
1673 * entry in the incore inode tree.
1674 * if not a directory, set reached flag, increment link count
1675 * if a directory and reached, mark entry as to be deleted.
1676 * if a directory, check to see if recorded parent
1677 * matches current inode #,
1678 * if so, then set reached flag, increment link count
1679 * of current and child dir inodes, push the child
1680 * directory inode onto the directory stack.
1681 * if current inode != parent, then mark entry to be deleted.
1683 while (ptr
< endptr
) {
1684 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1685 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1688 _("directory inode %" PRIu64
" block %u has consecutive free entries: "),
1692 do_warn(_("joining together\n"));
1693 len
= be16_to_cpu(dup
->length
);
1694 libxfs_dir2_data_use_free(&da
, bp
, dup
,
1695 ptr
- (char *)d
, len
, &needlog
,
1697 libxfs_dir2_data_make_free(&da
, bp
,
1698 ptr
- (char *)d
, len
, &needlog
,
1701 do_warn(_("would join together\n"));
1703 ptr
+= be16_to_cpu(dup
->length
);
1707 addr
= xfs_dir2_db_off_to_dataptr(mp
->m_dir_geo
, db
,
1709 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1710 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1711 inum
= be64_to_cpu(dep
->inumber
);
1714 * skip bogus entries (leading '/'). they'll be deleted
1715 * later. must still log it, else we leak references to
1718 if (dep
->name
[0] == '/') {
1721 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1725 memmove(fname
, dep
->name
, dep
->namelen
);
1726 fname
[dep
->namelen
] = '\0';
1727 ASSERT(inum
!= NULLFSINO
);
1729 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, inum
),
1730 XFS_INO_TO_AGINO(mp
, inum
));
1734 _("entry \"%s\" in directory inode %" PRIu64
" points to non-existent inode %" PRIu64
""),
1735 fname
, ip
->i_ino
, inum
)) {
1737 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1741 ino_offset
= XFS_INO_TO_AGINO(mp
, inum
) - irec
->ino_startnum
;
1744 * if it's a free inode, blow out the entry.
1745 * by now, any inode that we think is free
1748 if (is_inode_free(irec
, ino_offset
)) {
1751 _("entry \"%s\" in directory inode %" PRIu64
" points to free inode %" PRIu64
),
1752 fname
, ip
->i_ino
, inum
)) {
1754 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1760 * check if this inode is lost+found dir in the root
1762 if (inum
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
1764 * if it's not a directory, trash it
1766 if (!inode_isadir(irec
, ino_offset
)) {
1769 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
1770 ORPHANAGE
, inum
, ip
->i_ino
)) {
1772 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1777 * if this is a dup, it will be picked up below,
1778 * otherwise, mark it as the orphanage for later.
1781 orphanage_ino
= inum
;
1785 * check for duplicate names in directory.
1787 if (!dir_hash_add(mp
, hashtab
, addr
, inum
, dep
->namelen
,
1788 dep
->name
, M_DIROPS(mp
)->data_get_ftype(dep
))) {
1791 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
1792 fname
, inum
, ip
->i_ino
)) {
1794 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1796 if (inum
== orphanage_ino
)
1802 * if just scanning to rebuild a directory due to a ".."
1803 * update, just continue
1809 * skip the '..' entry since it's checked when the
1810 * directory is reached by something else. if it never
1811 * gets reached, it'll be moved to the orphanage and we'll
1812 * take care of it then. If it doesn't exist at all, the
1813 * directory needs to be rebuilt first before being added
1816 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
1817 dep
->name
[1] == '.') {
1819 /* ".." should be in the first block */
1822 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is not in the the first block"), fname
,
1825 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1830 ASSERT(no_modify
|| !verify_inum(mp
, inum
));
1832 * special case the . entry. we know there's only one
1833 * '.' and only '.' points to itself because bogus entries
1834 * got trashed in phase 3 if there were > 1.
1835 * bump up link count for '.' but don't set reached
1836 * until we're actually reached by another directory
1837 * '..' is already accounted for or will be taken care
1838 * of when directory is moved to orphanage.
1840 if (ip
->i_ino
== inum
) {
1841 ASSERT(dep
->name
[0] == '.' && dep
->namelen
== 1);
1842 add_inode_ref(current_irec
, current_ino_offset
);
1844 dep
!= M_DIROPS(mp
)->data_entry_p(d
)) {
1845 /* "." should be the first entry */
1848 _("entry \"%s\" in dir %" PRIu64
" is not the first entry"),
1849 fname
, inum
, ip
->i_ino
)) {
1851 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1858 * skip entries with bogus inumbers if we're in no modify mode
1860 if (no_modify
&& verify_inum(mp
, inum
))
1863 /* validate ftype field if supported */
1864 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
1868 dir_ftype
= M_DIROPS(mp
)->data_get_ftype(dep
);
1869 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
1871 if (dir_ftype
!= ino_ftype
) {
1874 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1875 dir_ftype
, ino_ftype
,
1879 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1880 dir_ftype
, ino_ftype
,
1882 M_DIROPS(mp
)->data_put_ftype(dep
,
1884 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1885 dir_hash_update_ftype(hashtab
, addr
,
1892 * check easy case first, regular inode, just bump
1893 * the link count and continue
1895 if (!inode_isadir(irec
, ino_offset
)) {
1896 add_inode_reached(irec
, ino_offset
);
1899 parent
= get_inode_parent(irec
, ino_offset
);
1900 ASSERT(parent
!= 0);
1903 * bump up the link counts in parent and child
1904 * directory but if the link doesn't agree with
1905 * the .. in the child, blow out the entry.
1906 * if the directory has already been reached,
1907 * blow away the entry also.
1909 if (is_inode_reached(irec
, ino_offset
)) {
1912 _("entry \"%s\" in dir %" PRIu64
" points to an already connected directory inode %" PRIu64
"\n"),
1913 fname
, ip
->i_ino
, inum
);
1914 } else if (parent
== ip
->i_ino
) {
1915 add_inode_reached(irec
, ino_offset
);
1916 add_inode_ref(current_irec
, current_ino_offset
);
1917 } else if (parent
== NULLFSINO
) {
1918 /* ".." was missing, but this entry refers to it,
1919 so, set it as the parent and mark for rebuild */
1921 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
1922 fname
, ip
->i_ino
, inum
);
1923 set_inode_parent(irec
, ino_offset
, ip
->i_ino
);
1924 add_inode_reached(irec
, ino_offset
);
1925 add_inode_ref(current_irec
, current_ino_offset
);
1926 add_dotdot_update(XFS_INO_TO_AGNO(mp
, inum
), irec
,
1931 _("entry \"%s\" in dir inode %" PRIu64
" inconsistent with .. value (%" PRIu64
") in ino %" PRIu64
"\n"),
1932 fname
, ip
->i_ino
, parent
, inum
);
1935 if (inum
== orphanage_ino
)
1940 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1943 _("\twill clear entry \"%s\"\n"),
1946 do_warn(_("\twould clear entry \"%s\"\n"),
1951 *num_illegal
+= nbad
;
1953 libxfs_dir2_data_freescan_int(mp
->m_dir_geo
, M_DIROPS(mp
),
1956 libxfs_dir2_data_log_header(&da
, bp
);
1957 libxfs_defer_ijoin(&dfops
, ip
);
1958 libxfs_defer_finish(&tp
, &dfops
);
1959 libxfs_trans_commit(tp
);
1961 /* record the largest free space in the freetab for later checking */
1962 bf
= M_DIROPS(mp
)->data_bestfree_p(d
);
1963 freetab
->ents
[db
].v
= be16_to_cpu(bf
[0].length
);
1964 freetab
->ents
[db
].s
= 0;
1967 /* check v5 metadata */
1969 __check_dir3_header(
1970 struct xfs_mount
*mp
,
1979 if (be64_to_cpu(owner
) != ino
) {
1981 _("expected owner inode %" PRIu64
", got %llu, directory block %" PRIu64
"\n"),
1982 ino
, (unsigned long long)be64_to_cpu(owner
), bp
->b_bn
);
1985 /* verify block number */
1986 if (be64_to_cpu(blkno
) != bp
->b_bn
) {
1988 _("expected block %" PRIu64
", got %llu, directory inode %" PRIu64
"\n"),
1989 bp
->b_bn
, (unsigned long long)be64_to_cpu(blkno
), ino
);
1993 if (platform_uuid_compare(uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
1995 _("wrong FS UUID, directory inode %" PRIu64
" block %" PRIu64
"\n"),
2005 struct xfs_mount
*mp
,
2009 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
2011 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2017 struct xfs_mount
*mp
,
2021 struct xfs_dir3_blk_hdr
*info
= bp
->b_addr
;
2023 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2028 * Check contents of leaf-form block.
2031 longform_dir2_check_leaf(
2034 dir_hash_tab_t
*hashtab
,
2042 xfs_dir2_leaf_t
*leaf
;
2043 xfs_dir2_leaf_tail_t
*ltp
;
2045 struct xfs_dir2_leaf_entry
*ents
;
2046 struct xfs_dir3_icleaf_hdr leafhdr
;
2050 da_bno
= mp
->m_dir_geo
->leafblk
;
2051 error
= dir_read_buf(ip
, da_bno
, -1, &bp
, &xfs_dir3_leaf1_buf_ops
,
2053 if (error
== EFSBADCRC
|| error
== EFSCORRUPTED
|| fixit
) {
2055 _("leaf block %u for directory inode %" PRIu64
" bad CRC\n"),
2060 _("can't read block %u for directory inode %" PRIu64
", error %d\n"),
2061 da_bno
, ip
->i_ino
, error
);
2066 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2067 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2068 ltp
= xfs_dir2_leaf_tail_p(mp
->m_dir_geo
, leaf
);
2069 bestsp
= xfs_dir2_leaf_bests_p(ltp
);
2070 if (!(leafhdr
.magic
== XFS_DIR2_LEAF1_MAGIC
||
2071 leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) ||
2072 leafhdr
.forw
|| leafhdr
.back
||
2073 leafhdr
.count
< leafhdr
.stale
||
2075 M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2076 (char *)&ents
[leafhdr
.count
] > (char *)bestsp
) {
2078 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2084 if (leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) {
2085 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2092 seeval
= dir_hash_see_all(hashtab
, ents
, leafhdr
.count
, leafhdr
.stale
);
2093 if (dir_hash_check(hashtab
, ip
, seeval
)) {
2097 badtail
= freetab
->nents
!= be32_to_cpu(ltp
->bestcount
);
2098 for (i
= 0; !badtail
&& i
< be32_to_cpu(ltp
->bestcount
); i
++) {
2099 freetab
->ents
[i
].s
= 1;
2100 badtail
= freetab
->ents
[i
].v
!= be16_to_cpu(bestsp
[i
]);
2104 _("leaf block %u for directory inode %" PRIu64
" bad tail\n"),
2114 * Check contents of the node blocks (leaves)
2115 * Looks for matching hash values for the data entries.
2118 longform_dir2_check_node(
2121 dir_hash_tab_t
*hashtab
,
2127 xfs_dir2_free_t
*free
;
2129 xfs_dir2_leaf_t
*leaf
;
2130 xfs_fileoff_t next_da_bno
;
2133 struct xfs_dir2_leaf_entry
*ents
;
2134 struct xfs_dir3_icleaf_hdr leafhdr
;
2135 struct xfs_dir3_icfree_hdr freehdr
;
2140 for (da_bno
= mp
->m_dir_geo
->leafblk
, next_da_bno
= 0;
2141 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->freeblk
;
2142 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2143 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2144 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2148 * we need to use the da3 node verifier here as it handles the
2149 * fact that reading the leaf hash tree blocks can return either
2150 * leaf or node blocks and calls the correct verifier. If we get
2151 * a node block, then we'll skip it below based on a magic
2154 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2155 &xfs_da3_node_buf_ops
, &fixit
);
2158 _("can't read leaf block %u for directory inode %" PRIu64
", error %d\n"),
2159 da_bno
, ip
->i_ino
, error
);
2163 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2164 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2165 if (!(leafhdr
.magic
== XFS_DIR2_LEAFN_MAGIC
||
2166 leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2167 leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2168 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
)) {
2170 _("unknown magic number %#x for block %u in directory inode %" PRIu64
"\n"),
2171 leafhdr
.magic
, da_bno
, ip
->i_ino
);
2176 /* check v5 metadata */
2177 if (leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2178 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2179 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2187 if (leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2188 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2194 * If there's a validator error, we need to ensure that we got
2195 * the right ops on the buffer for when we write it back out.
2197 bp
->b_ops
= &xfs_dir3_leafn_buf_ops
;
2198 if (leafhdr
.count
> M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2199 leafhdr
.count
< leafhdr
.stale
) {
2201 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2206 seeval
= dir_hash_see_all(hashtab
, ents
,
2207 leafhdr
.count
, leafhdr
.stale
);
2209 if (seeval
!= DIR_HASH_CK_OK
)
2212 if (dir_hash_check(hashtab
, ip
, seeval
))
2215 for (da_bno
= mp
->m_dir_geo
->freeblk
, next_da_bno
= 0;
2216 next_da_bno
!= NULLFILEOFF
;
2217 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2218 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2219 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2222 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2223 &xfs_dir3_free_buf_ops
, &fixit
);
2226 _("can't read freespace block %u for directory inode %" PRIu64
", error %d\n"),
2227 da_bno
, ip
->i_ino
, error
);
2231 M_DIROPS(mp
)->free_hdr_from_disk(&freehdr
, free
);
2232 bests
= M_DIROPS(mp
)->free_bests_p(free
);
2233 fdb
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2234 if (!(freehdr
.magic
== XFS_DIR2_FREE_MAGIC
||
2235 freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) ||
2237 (fdb
- xfs_dir2_byte_to_db(mp
->m_dir_geo
, XFS_DIR2_FREE_OFFSET
)) *
2238 M_DIROPS(mp
)->free_max_bests(mp
->m_dir_geo
) ||
2239 freehdr
.nvalid
< freehdr
.nused
) {
2241 _("free block %u for directory inode %" PRIu64
" bad header\n"),
2247 if (freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) {
2248 error
= check_dir3_header(mp
, bp
, ip
->i_ino
);
2254 for (i
= used
= 0; i
< freehdr
.nvalid
; i
++) {
2255 if (i
+ freehdr
.firstdb
>= freetab
->nents
||
2256 freetab
->ents
[i
+ freehdr
.firstdb
].v
!=
2257 be16_to_cpu(bests
[i
])) {
2259 _("free block %u entry %i for directory ino %" PRIu64
" bad\n"),
2260 da_bno
, i
, ip
->i_ino
);
2264 used
+= be16_to_cpu(bests
[i
]) != NULLDATAOFF
;
2265 freetab
->ents
[i
+ freehdr
.firstdb
].s
= 1;
2267 if (used
!= freehdr
.nused
) {
2269 _("free block %u for directory inode %" PRIu64
" bad nused\n"),
2276 for (i
= 0; i
< freetab
->nents
; i
++) {
2277 if ((freetab
->ents
[i
].s
== 0) &&
2278 (freetab
->ents
[i
].v
!= NULLDATAOFF
)) {
2280 _("missing freetab entry %u for directory inode %" PRIu64
"\n"),
2289 * If a directory is corrupt, we need to read in as many entries as possible,
2290 * destroy the entry and create a new one with recovered name/inode pairs.
2291 * (ie. get libxfs to do all the grunt work)
2294 longform_dir2_entry_check(xfs_mount_t
*mp
,
2299 ino_tree_node_t
*irec
,
2301 dir_hash_tab_t
*hashtab
)
2303 struct xfs_buf
**bplist
;
2310 xfs_fileoff_t next_da_bno
;
2314 struct xfs_da_args args
;
2317 freetab
= malloc(FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2319 do_error(_("malloc failed in %s (%" PRId64
" bytes)\n"),
2321 FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2324 freetab
->naents
= ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
;
2326 for (i
= 0; i
< freetab
->naents
; i
++) {
2327 freetab
->ents
[i
].v
= NULLDATAOFF
;
2328 freetab
->ents
[i
].s
= 0;
2330 num_bps
= freetab
->naents
;
2331 bplist
= calloc(num_bps
, sizeof(struct xfs_buf
*));
2333 do_error(_("calloc failed in %s (%zu bytes)\n"),
2334 __func__
, num_bps
* sizeof(struct xfs_buf
*));
2336 /* is this a block, leaf, or node directory? */
2338 args
.geo
= mp
->m_dir_geo
;
2339 libxfs_dir2_isblock(&args
, &isblock
);
2340 libxfs_dir2_isleaf(&args
, &isleaf
);
2342 /* check directory "data" blocks (ie. name/inode pairs) */
2343 for (da_bno
= 0, next_da_bno
= 0;
2344 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->leafblk
;
2345 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2346 const struct xfs_buf_ops
*ops
;
2348 struct xfs_dir2_data_hdr
*d
;
2350 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2351 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
)) {
2353 * if this is the first block, there isn't anything we
2354 * can recover so we just trash it.
2363 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2364 if (db
>= num_bps
) {
2365 /* more data blocks than expected */
2367 bplist
= realloc(bplist
, num_bps
* sizeof(struct xfs_buf
*));
2369 do_error(_("realloc failed in %s (%zu bytes)\n"),
2371 num_bps
* sizeof(struct xfs_buf
*));
2375 ops
= &xfs_dir3_block_buf_ops
;
2377 ops
= &xfs_dir3_data_buf_ops
;
2379 error
= dir_read_buf(ip
, da_bno
, -1, &bplist
[db
], ops
, &fixit
);
2382 _("can't read data block %u for directory inode %" PRIu64
" error %d\n"),
2383 da_bno
, ino
, error
);
2387 * we try to read all "data" blocks, but if we are in
2388 * block form and we fail, there isn't anything else to
2389 * read, and nothing we can do but trash it.
2398 /* check v5 metadata */
2399 d
= bplist
[db
]->b_addr
;
2400 if (be32_to_cpu(d
->magic
) == XFS_DIR3_BLOCK_MAGIC
||
2401 be32_to_cpu(d
->magic
) == XFS_DIR3_DATA_MAGIC
) {
2402 struct xfs_buf
*bp
= bplist
[db
];
2404 error
= check_dir3_header(mp
, bp
, ino
);
2411 longform_dir2_entry_check_data(mp
, ip
, num_illegal
, need_dot
,
2412 irec
, ino_offset
, &bplist
[db
], hashtab
,
2413 &freetab
, da_bno
, isblock
);
2415 fixit
|= (*num_illegal
!= 0) || dir2_is_badino(ino
) || *need_dot
;
2417 if (!dotdot_update
) {
2418 /* check btree and freespace */
2420 struct xfs_dir2_data_hdr
*block
;
2421 xfs_dir2_block_tail_t
*btp
;
2422 xfs_dir2_leaf_entry_t
*blp
;
2424 block
= bplist
[0]->b_addr
;
2425 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, block
);
2426 blp
= xfs_dir2_block_leaf_p(btp
);
2427 seeval
= dir_hash_see_all(hashtab
, blp
,
2428 be32_to_cpu(btp
->count
),
2429 be32_to_cpu(btp
->stale
));
2430 if (dir_hash_check(hashtab
, ip
, seeval
))
2432 } else if (isleaf
) {
2433 fixit
|= longform_dir2_check_leaf(mp
, ip
, hashtab
,
2436 fixit
|= longform_dir2_check_node(mp
, ip
, hashtab
,
2441 if (!no_modify
&& (fixit
|| dotdot_update
)) {
2442 dir_hash_dup_names(hashtab
);
2443 for (i
= 0; i
< num_bps
; i
++)
2445 libxfs_putbuf(bplist
[i
]);
2446 longform_dir2_rebuild(mp
, ino
, ip
, irec
, ino_offset
, hashtab
);
2450 for (i
= 0; i
< num_bps
; i
++)
2452 libxfs_putbuf(bplist
[i
]);
2460 * shortform directory v2 processing routines -- entry verification and
2461 * bad entry deletion (pruning).
2463 static struct xfs_dir2_sf_entry
*
2464 shortform_dir2_junk(
2465 struct xfs_mount
*mp
,
2466 struct xfs_dir2_sf_hdr
*sfp
,
2467 struct xfs_dir2_sf_entry
*sfep
,
2474 struct xfs_dir2_sf_entry
*next_sfep
;
2478 if (lino
== orphanage_ino
)
2481 next_elen
= M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
);
2482 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2485 * if we are just checking, simply return the pointer to the next entry
2486 * here so that the checking loop can continue.
2489 do_warn(_("would junk entry\n"));
2494 * now move all the remaining entries down over the junked entry and
2495 * clear the newly unused bytes at the tail of the directory region.
2497 next_len
= *max_size
- ((intptr_t)next_sfep
- (intptr_t)sfp
);
2498 *max_size
-= next_elen
;
2499 *bytes_deleted
+= next_elen
;
2501 memmove(sfep
, next_sfep
, next_len
);
2502 memset((void *)((intptr_t)sfep
+ next_len
), 0, next_elen
);
2507 * WARNING: drop the index i by one so it matches the decremented count
2508 * for accurate comparisons in the loop test
2513 do_warn(_("junking entry\n"));
2520 shortform_dir2_entry_check(xfs_mount_t
*mp
,
2524 ino_tree_node_t
*current_irec
,
2525 int current_ino_offset
,
2526 dir_hash_tab_t
*hashtab
)
2530 struct xfs_dir2_sf_hdr
*sfp
;
2531 struct xfs_dir2_sf_entry
*sfep
;
2532 struct xfs_dir2_sf_entry
*next_sfep
;
2533 struct xfs_ifork
*ifp
;
2534 struct ino_tree_node
*irec
;
2541 char fname
[MAXNAMELEN
+ 1];
2545 sfp
= (struct xfs_dir2_sf_hdr
*) ifp
->if_u1
.if_data
;
2549 max_size
= ifp
->if_bytes
;
2550 ASSERT(ip
->i_d
.di_size
<= ifp
->if_bytes
);
2553 * if just rebuild a directory due to a "..", update and return
2555 if (dotdot_update
) {
2556 parent
= get_inode_parent(current_irec
, current_ino_offset
);
2559 _("would set .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2563 _("setting .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2565 M_DIROPS(mp
)->sf_put_parent_ino(sfp
, parent
);
2572 * no '.' entry in shortform dirs, just bump up ref count by 1
2573 * '..' was already (or will be) accounted for and checked when
2574 * the directory is reached or will be taken care of when the
2575 * directory is moved to orphanage.
2577 add_inode_ref(current_irec
, current_ino_offset
);
2580 * Initialise i8 counter -- the parent inode number counts as well.
2582 i8
= M_DIROPS(mp
)->sf_get_parent_ino(sfp
) > XFS_DIR2_MAX_SHORT_INUM
;
2585 * now run through entries, stop at first bad entry, don't need
2586 * to skip over '..' since that's encoded in its own field and
2587 * no need to worry about '.' since it doesn't exist.
2589 sfep
= next_sfep
= xfs_dir2_sf_firstentry(sfp
);
2591 for (i
= 0; i
< sfp
->count
&& max_size
>
2592 (intptr_t)next_sfep
- (intptr_t)sfp
;
2593 sfep
= next_sfep
, i
++) {
2596 lino
= M_DIROPS(mp
)->sf_get_ino(sfp
, sfep
);
2598 namelen
= sfep
->namelen
;
2600 ASSERT(no_modify
|| namelen
> 0);
2602 if (no_modify
&& namelen
== 0) {
2604 * if we're really lucky, this is
2605 * the last entry in which case we
2606 * can use the dir size to set the
2607 * namelen value. otherwise, forget
2608 * it because we're not going to be
2609 * able to find the next entry.
2613 if (i
== sfp
->count
- 1) {
2614 namelen
= ip
->i_d
.di_size
-
2615 ((intptr_t) &sfep
->name
[0] -
2619 * don't process the rest of the directory,
2620 * break out of processing loop
2624 } else if (no_modify
&& (intptr_t) sfep
- (intptr_t) sfp
+
2625 + M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)
2626 > ip
->i_d
.di_size
) {
2629 if (i
== sfp
->count
- 1) {
2630 namelen
= ip
->i_d
.di_size
-
2631 ((intptr_t) &sfep
->name
[0] -
2635 * don't process the rest of the directory,
2636 * break out of processing loop
2642 memmove(fname
, sfep
->name
, sfep
->namelen
);
2643 fname
[sfep
->namelen
] = '\0';
2645 ASSERT(no_modify
|| (lino
!= NULLFSINO
&& lino
!= 0));
2646 ASSERT(no_modify
|| !verify_inum(mp
, lino
));
2649 * Also skip entries with bogus inode numbers if we're
2650 * in no modify mode.
2653 if (no_modify
&& verify_inum(mp
, lino
)) {
2654 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2658 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, lino
),
2659 XFS_INO_TO_AGINO(mp
, lino
));
2663 _("entry \"%s\" in shortform directory %" PRIu64
" references non-existent inode %" PRIu64
"\n"),
2665 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2666 &max_size
, &i
, &bytes_deleted
,
2671 ino_offset
= XFS_INO_TO_AGINO(mp
, lino
) - irec
->ino_startnum
;
2674 * if it's a free inode, blow out the entry.
2675 * by now, any inode that we think is free
2678 if (is_inode_free(irec
, ino_offset
)) {
2680 _("entry \"%s\" in shortform directory inode %" PRIu64
" points to free inode %" PRIu64
"\n"),
2682 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2683 &max_size
, &i
, &bytes_deleted
,
2688 * check if this inode is lost+found dir in the root
2690 if (ino
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
2692 * if it's not a directory, trash it
2694 if (!inode_isadir(irec
, ino_offset
)) {
2696 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
2697 ORPHANAGE
, lino
, ino
);
2698 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2699 lino
, &max_size
, &i
,
2700 &bytes_deleted
, ino_dirty
);
2704 * if this is a dup, it will be picked up below,
2705 * otherwise, mark it as the orphanage for later.
2708 orphanage_ino
= lino
;
2711 * check for duplicate names in directory.
2713 if (!dir_hash_add(mp
, hashtab
, (xfs_dir2_dataptr_t
)
2714 (sfep
- xfs_dir2_sf_firstentry(sfp
)),
2715 lino
, sfep
->namelen
, sfep
->name
,
2716 M_DIROPS(mp
)->sf_get_ftype(sfep
))) {
2718 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
2720 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2721 &max_size
, &i
, &bytes_deleted
,
2726 if (!inode_isadir(irec
, ino_offset
)) {
2728 * check easy case first, regular inode, just bump
2731 add_inode_reached(irec
, ino_offset
);
2733 parent
= get_inode_parent(irec
, ino_offset
);
2736 * bump up the link counts in parent and child.
2737 * directory but if the link doesn't agree with
2738 * the .. in the child, blow out the entry
2740 if (is_inode_reached(irec
, ino_offset
)) {
2742 _("entry \"%s\" in directory inode %" PRIu64
2743 " references already connected inode %" PRIu64
".\n"),
2745 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2746 lino
, &max_size
, &i
,
2747 &bytes_deleted
, ino_dirty
);
2749 } else if (parent
== ino
) {
2750 add_inode_reached(irec
, ino_offset
);
2751 add_inode_ref(current_irec
, current_ino_offset
);
2752 } else if (parent
== NULLFSINO
) {
2753 /* ".." was missing, but this entry refers to it,
2754 so, set it as the parent and mark for rebuild */
2756 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
2758 set_inode_parent(irec
, ino_offset
, ino
);
2759 add_inode_reached(irec
, ino_offset
);
2760 add_inode_ref(current_irec
, current_ino_offset
);
2761 add_dotdot_update(XFS_INO_TO_AGNO(mp
, lino
),
2765 _("entry \"%s\" in directory inode %" PRIu64
2766 " not consistent with .. value (%" PRIu64
2767 ") in inode %" PRIu64
",\n"),
2768 fname
, ino
, parent
, lino
);
2769 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2770 lino
, &max_size
, &i
,
2771 &bytes_deleted
, ino_dirty
);
2776 /* validate ftype field if supported */
2777 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
2781 dir_ftype
= M_DIROPS(mp
)->sf_get_ftype(sfep
);
2782 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
2784 if (dir_ftype
!= ino_ftype
) {
2787 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2788 dir_ftype
, ino_ftype
,
2792 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2793 dir_ftype
, ino_ftype
,
2795 M_DIROPS(mp
)->sf_put_ftype(sfep
,
2797 dir_hash_update_ftype(hashtab
,
2798 (xfs_dir2_dataptr_t
)(sfep
- xfs_dir2_sf_firstentry(sfp
)),
2805 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
2809 * go onto next entry - we have to take entries with bad namelen
2810 * into account in no modify mode since we calculate size based
2813 ASSERT(no_modify
|| bad_sfnamelen
== 0);
2814 next_sfep
= (struct xfs_dir2_sf_entry
*)((intptr_t)sfep
+
2816 ? M_DIROPS(mp
)->sf_entsize(sfp
, namelen
)
2817 : M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)));
2820 if (sfp
->i8count
!= i8
) {
2822 do_warn(_("would fix i8count in inode %" PRIu64
"\n"),
2826 struct xfs_dir2_sf_entry
*tmp_sfep
;
2828 tmp_sfep
= next_sfep
;
2829 process_sf_dir2_fixi8(mp
, sfp
, &tmp_sfep
);
2831 (intptr_t)next_sfep
-
2833 next_sfep
= tmp_sfep
;
2837 do_warn(_("fixing i8count in inode %" PRIu64
"\n"),
2843 * sync up sizes if required
2845 if (*ino_dirty
&& bytes_deleted
> 0) {
2847 libxfs_idata_realloc(ip
, -bytes_deleted
, XFS_DATA_FORK
);
2848 ip
->i_d
.di_size
-= bytes_deleted
;
2851 if (ip
->i_d
.di_size
!= ip
->i_df
.if_bytes
) {
2852 ASSERT(ip
->i_df
.if_bytes
== (xfs_fsize_t
)
2853 ((intptr_t) next_sfep
- (intptr_t) sfp
));
2854 ip
->i_d
.di_size
= (xfs_fsize_t
)
2855 ((intptr_t) next_sfep
- (intptr_t) sfp
);
2857 _("setting size to %" PRId64
" bytes to reflect junked entries\n"),
2864 * processes all reachable inodes in directories
2869 xfs_agnumber_t agno
,
2870 ino_tree_node_t
*irec
,
2874 struct xfs_defer_ops dfops
;
2875 xfs_fsblock_t first
;
2878 dir_hash_tab_t
*hashtab
;
2880 int dirty
, num_illegal
, error
, nres
;
2882 ino
= XFS_AGINO_TO_INO(mp
, agno
, irec
->ino_startnum
+ ino_offset
);
2885 * open up directory inode, check all entries,
2886 * then call prune_dir_entries to remove all
2887 * remaining illegal directory entries.
2890 ASSERT(!is_inode_refchecked(irec
, ino_offset
) || dotdot_update
);
2892 error
= -libxfs_iget(mp
, NULL
, ino
, 0, &ip
, &phase6_ifork_ops
);
2896 _("couldn't map inode %" PRIu64
", err = %d\n"),
2900 _("couldn't map inode %" PRIu64
", err = %d\n"),
2903 * see below for what we're doing if this
2904 * is root. Why do we need to do this here?
2905 * to ensure that the root doesn't show up
2906 * as being disconnected in the no_modify case.
2908 if (mp
->m_sb
.sb_rootino
== ino
) {
2909 add_inode_reached(irec
, 0);
2910 add_inode_ref(irec
, 0);
2914 add_inode_refchecked(irec
, 0);
2918 need_dot
= dirty
= num_illegal
= 0;
2920 if (mp
->m_sb
.sb_rootino
== ino
) {
2922 * mark root inode reached and bump up
2923 * link count for root inode to account
2924 * for '..' entry since the root inode is
2925 * never reached by a parent. we know
2926 * that root's '..' is always good --
2927 * guaranteed by phase 3 and/or below.
2929 add_inode_reached(irec
, ino_offset
);
2932 add_inode_refchecked(irec
, ino_offset
);
2934 hashtab
= dir_hash_init(ip
->i_d
.di_size
);
2937 * look for bogus entries
2939 switch (ip
->i_d
.di_format
) {
2940 case XFS_DINODE_FMT_EXTENTS
:
2941 case XFS_DINODE_FMT_BTREE
:
2943 * also check for missing '.' in longform dirs.
2944 * missing .. entries are added if required when
2945 * the directory is connected to lost+found. but
2946 * we need to create '.' entries here.
2948 longform_dir2_entry_check(mp
, ino
, ip
,
2949 &num_illegal
, &need_dot
,
2954 case XFS_DINODE_FMT_LOCAL
:
2956 * using the remove reservation is overkill
2957 * since at most we'll only need to log the
2958 * inode but it's easier than wedging a
2959 * new define in ourselves.
2961 nres
= no_modify
? 0 : XFS_REMOVE_SPACE_RES(mp
);
2962 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
2967 libxfs_trans_ijoin(tp
, ip
, 0);
2969 shortform_dir2_entry_check(mp
, ino
, ip
, &dirty
,
2973 ASSERT(dirty
== 0 || (dirty
&& !no_modify
));
2975 libxfs_trans_log_inode(tp
, ip
,
2976 XFS_ILOG_CORE
| XFS_ILOG_DDATA
);
2977 libxfs_trans_commit(tp
);
2979 libxfs_trans_cancel(tp
);
2986 dir_hash_done(hashtab
);
2989 * if we have to create a .. for /, do it now *before*
2990 * we delete the bogus entries, otherwise the directory
2991 * could transform into a shortform dir which would
2992 * probably cause the simulation to choke. Even
2993 * if the illegal entries get shifted around, it's ok
2994 * because the entries are structurally intact and in
2995 * in hash-value order so the simulation won't get confused
2996 * if it has to move them around.
2998 if (!no_modify
&& need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2999 ASSERT(ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
);
3001 do_warn(_("recreating root directory .. entry\n"));
3003 nres
= XFS_MKDIR_SPACE_RES(mp
, 2);
3004 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3009 libxfs_trans_ijoin(tp
, ip
, 0);
3011 libxfs_defer_init(&dfops
, &first
);
3013 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dotdot
,
3014 ip
->i_ino
, &first
, &dfops
, nres
);
3017 _("can't make \"..\" entry in root inode %" PRIu64
", createname error %d\n"), ino
, error
);
3019 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3021 libxfs_defer_ijoin(&dfops
, ip
);
3022 error
= -libxfs_defer_finish(&tp
, &dfops
);
3024 libxfs_trans_commit(tp
);
3026 need_root_dotdot
= 0;
3027 } else if (need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
3028 do_warn(_("would recreate root directory .. entry\n"));
3032 * if we need to create the '.' entry, do so only if
3033 * the directory is a longform dir. if it's been
3034 * turned into a shortform dir, then the inode is ok
3035 * since shortform dirs have no '.' entry and the inode
3036 * has already been committed by prune_lf_dir_entry().
3040 * bump up our link count but don't
3041 * bump up the inode link count. chances
3042 * are good that even though we lost '.'
3043 * the inode link counts reflect '.' so
3044 * leave the inode link count alone and if
3045 * it turns out to be wrong, we'll catch
3048 add_inode_ref(irec
, ino_offset
);
3052 _("would create missing \".\" entry in dir ino %" PRIu64
"\n"),
3054 } else if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
) {
3056 * need to create . entry in longform dir.
3059 _("creating missing \".\" entry in dir ino %" PRIu64
"\n"), ino
);
3061 nres
= XFS_MKDIR_SPACE_RES(mp
, 1);
3062 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3067 libxfs_trans_ijoin(tp
, ip
, 0);
3069 libxfs_defer_init(&dfops
, &first
);
3071 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dot
,
3072 ip
->i_ino
, &first
, &dfops
, nres
);
3075 _("can't make \".\" entry in dir ino %" PRIu64
", createname error %d\n"),
3078 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3080 libxfs_defer_ijoin(&dfops
, ip
);
3081 error
= -libxfs_defer_finish(&tp
, &dfops
);
3083 libxfs_trans_commit(tp
);
3090 * mark realtime bitmap and summary inodes as reached.
3091 * quota inode will be marked here as well
3094 mark_standalone_inodes(xfs_mount_t
*mp
)
3096 ino_tree_node_t
*irec
;
3099 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rbmino
),
3100 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
));
3102 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
) -
3105 add_inode_reached(irec
, offset
);
3107 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rsumino
),
3108 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
));
3110 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
) -
3113 add_inode_reached(irec
, offset
);
3116 if (mp
->m_sb
.sb_uquotino
3117 && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
3118 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3119 mp
->m_sb
.sb_uquotino
),
3120 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
));
3121 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
)
3122 - irec
->ino_startnum
;
3123 add_inode_reached(irec
, offset
);
3125 if (mp
->m_sb
.sb_gquotino
3126 && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
3127 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3128 mp
->m_sb
.sb_gquotino
),
3129 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
));
3130 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
)
3131 - irec
->ino_startnum
;
3132 add_inode_reached(irec
, offset
);
3134 if (mp
->m_sb
.sb_pquotino
3135 && mp
->m_sb
.sb_pquotino
!= NULLFSINO
) {
3136 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3137 mp
->m_sb
.sb_pquotino
),
3138 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
));
3139 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
)
3140 - irec
->ino_startnum
;
3141 add_inode_reached(irec
, offset
);
3147 check_for_orphaned_inodes(
3149 xfs_agnumber_t agno
,
3150 ino_tree_node_t
*irec
)
3155 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3156 ASSERT(is_inode_confirmed(irec
, i
));
3157 if (is_inode_free(irec
, i
))
3160 if (is_inode_reached(irec
, i
))
3163 ASSERT(inode_isadir(irec
, i
) ||
3164 num_inode_references(irec
, i
) == 0);
3166 ino
= XFS_AGINO_TO_INO(mp
, agno
, i
+ irec
->ino_startnum
);
3167 if (inode_isadir(irec
, i
))
3168 do_warn(_("disconnected dir inode %" PRIu64
", "), ino
);
3170 do_warn(_("disconnected inode %" PRIu64
", "), ino
);
3173 orphanage_ino
= mk_orphanage(mp
);
3174 do_warn(_("moving to %s\n"), ORPHANAGE
);
3175 mv_orphanage(mp
, ino
, inode_isadir(irec
, i
));
3177 do_warn(_("would move to %s\n"), ORPHANAGE
);
3180 * for read-only case, even though the inode isn't
3181 * really reachable, set the flag (and bump our link
3182 * count) anyway to fool phase 7
3184 add_inode_reached(irec
, i
);
3190 struct workqueue
*wq
,
3191 xfs_agnumber_t agno
,
3194 ino_tree_node_t
*irec
;
3196 prefetch_args_t
*pf_args
= arg
;
3198 wait_for_inode_prefetch(pf_args
);
3201 do_log(_(" - agno = %d\n"), agno
);
3203 for (irec
= findfirst_inode_rec(agno
); irec
; irec
= next_ino_rec(irec
)) {
3204 if (irec
->ino_isa_dir
== 0)
3208 sem_post(&pf_args
->ra_count
);
3210 sem_getvalue(&pf_args
->ra_count
, &i
);
3212 "processing inode chunk %p in AG %d (sem count = %d)",
3217 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3218 if (inode_isadir(irec
, i
))
3219 process_dir_inode(wq
->wq_ctx
, agno
, irec
, i
);
3222 cleanup_inode_prefetch(pf_args
);
3226 update_missing_dotdot_entries(
3229 dotdot_update_t
*dir
;
3232 * these entries parents were updated, rebuild them again
3233 * set dotdot_update flag so processing routines do not count links
3236 while (!list_empty(&dotdot_update_list
)) {
3237 dir
= list_entry(dotdot_update_list
.prev
, struct dotdot_update
,
3239 list_del(&dir
->list
);
3240 process_dir_inode(mp
, dir
->agno
, dir
->irec
, dir
->ino_offset
);
3247 struct xfs_mount
*mp
)
3249 do_inode_prefetch(mp
, 0, traverse_function
, false, true);
3253 phase6(xfs_mount_t
*mp
)
3255 ino_tree_node_t
*irec
;
3258 memset(&zerocr
, 0, sizeof(struct cred
));
3259 memset(&zerofsx
, 0, sizeof(struct fsxattr
));
3262 do_log(_("Phase 6 - check inode connectivity...\n"));
3264 incore_ext_teardown(mp
);
3266 add_ino_ex_data(mp
);
3269 * verify existence of root directory - if we have to
3270 * make one, it's ok for the incore data structs not to
3271 * know about it since everything about it (and the other
3272 * inodes in its chunk if a new chunk was created) are ok
3274 if (need_root_inode
) {
3276 do_warn(_("reinitializing root directory\n"));
3278 need_root_inode
= 0;
3279 need_root_dotdot
= 0;
3281 do_warn(_("would reinitialize root directory\n"));
3287 do_warn(_("reinitializing realtime bitmap inode\n"));
3291 do_warn(_("would reinitialize realtime bitmap inode\n"));
3297 do_warn(_("reinitializing realtime summary inode\n"));
3301 do_warn(_("would reinitialize realtime summary inode\n"));
3307 _(" - resetting contents of realtime bitmap and summary inodes\n"));
3308 if (fill_rbmino(mp
)) {
3310 _("Warning: realtime bitmap may be inconsistent\n"));
3313 if (fill_rsumino(mp
)) {
3315 _("Warning: realtime bitmap may be inconsistent\n"));
3319 mark_standalone_inodes(mp
);
3321 do_log(_(" - traversing filesystem ...\n"));
3323 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
3324 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
3327 * we always have a root inode, even if it's free...
3328 * if the root is free, forget it, lost+found is already gone
3330 if (is_inode_free(irec
, 0) || !inode_isadir(irec
, 0)) {
3331 need_root_inode
= 1;
3335 * then process all inodes by walking incore inode tree
3340 * any directories that had updated ".." entries, rebuild them now
3342 update_missing_dotdot_entries(mp
);
3344 do_log(_(" - traversal finished ...\n"));
3345 do_log(_(" - moving disconnected inodes to %s ...\n"),
3349 * move all disconnected inodes to the orphanage
3351 for (i
= 0; i
< glob_agcount
; i
++) {
3352 irec
= findfirst_inode_rec(i
);
3353 while (irec
!= NULL
) {
3354 check_for_orphaned_inodes(mp
, i
, irec
);
3355 irec
= next_ino_rec(irec
);