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 * Data structures used to keep track of directories where the ".."
43 * entries are updated. These must be rebuilt after the initial pass
45 typedef struct dotdot_update
{
46 struct list_head list
;
47 ino_tree_node_t
*irec
;
52 static LIST_HEAD(dotdot_update_list
);
53 static int dotdot_update
;
58 ino_tree_node_t
*irec
,
61 dotdot_update_t
*dir
= malloc(sizeof(dotdot_update_t
));
64 do_error(_("malloc failed add_dotdot_update (%zu bytes)\n"),
65 sizeof(dotdot_update_t
));
67 INIT_LIST_HEAD(&dir
->list
);
70 dir
->ino_offset
= ino_offset
;
72 list_add(&dir
->list
, &dotdot_update_list
);
76 * Data structures and routines to keep track of directory entries
77 * and whether their leaf entry has been seen. Also used for name
78 * duplicate checking and rebuilding step if required.
80 typedef struct dir_hash_ent
{
81 struct dir_hash_ent
*nextbyaddr
; /* next in addr bucket */
82 struct dir_hash_ent
*nextbyhash
; /* next in name bucket */
83 struct dir_hash_ent
*nextbyorder
; /* next in order added */
84 xfs_dahash_t hashval
; /* hash value of name */
85 __uint32_t address
; /* offset of data entry */
86 xfs_ino_t inum
; /* inode num of entry */
87 short junkit
; /* name starts with / */
88 short seen
; /* have seen leaf entry */
92 typedef struct dir_hash_tab
{
93 int size
; /* size of hash tables */
94 int names_duped
; /* 1 = ent names malloced */
95 dir_hash_ent_t
*first
; /* ptr to first added entry */
96 dir_hash_ent_t
*last
; /* ptr to last added entry */
97 dir_hash_ent_t
**byhash
; /* ptr to name hash buckets */
98 dir_hash_ent_t
**byaddr
; /* ptr to addr hash buckets */
101 #define DIR_HASH_TAB_SIZE(n) \
102 (sizeof(dir_hash_tab_t) + (sizeof(dir_hash_ent_t *) * (n) * 2))
103 #define DIR_HASH_FUNC(t,a) ((a) % (t)->size)
106 * Track the contents of the freespace table in a directory.
108 typedef struct freetab
{
109 int naents
; /* expected number of data blocks */
110 int nents
; /* number of data blocks processed */
112 xfs_dir2_data_off_t v
;
116 #define FREETAB_SIZE(n) \
117 (offsetof(freetab_t, ents) + (sizeof(struct freetab_ent) * (n)))
119 #define DIR_HASH_CK_OK 0
120 #define DIR_HASH_CK_DUPLEAF 1
121 #define DIR_HASH_CK_BADHASH 2
122 #define DIR_HASH_CK_NODATA 3
123 #define DIR_HASH_CK_NOLEAF 4
124 #define DIR_HASH_CK_BADSTALE 5
125 #define DIR_HASH_CK_TOTAL 6
128 * Need to handle CRC and validation errors specially here. If there is a
129 * validator error, re-read without the verifier so that we get a buffer we can
130 * check and repair. Re-attach the ops to the buffer after the read so that when
131 * it is rewritten the CRC is recalculated.
133 * If the buffer was not read, we return an error. If the buffer was read but
134 * had a CRC or corruption error, we reread it without the verifier and if it is
135 * read successfully we increment *crc_error and return 0. Otherwise we
136 * return the read error.
140 struct xfs_inode
*ip
,
142 xfs_daddr_t mappedbno
,
143 struct xfs_buf
**bpp
,
144 const struct xfs_buf_ops
*ops
,
150 error
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
153 if (error
!= EFSBADCRC
&& error
!= EFSCORRUPTED
)
156 error2
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
157 XFS_DATA_FORK
, NULL
);
167 * Returns 0 if the name already exists (ie. a duplicate)
172 dir_hash_tab_t
*hashtab
,
179 xfs_dahash_t hash
= 0;
185 struct xfs_name xname
;
187 ASSERT(!hashtab
->names_duped
);
193 junk
= name
[0] == '/';
194 byaddr
= DIR_HASH_FUNC(hashtab
, addr
);
198 hash
= mp
->m_dirnameops
->hashname(&xname
);
199 byhash
= DIR_HASH_FUNC(hashtab
, hash
);
202 * search hash bucket for existing name.
204 for (p
= hashtab
->byhash
[byhash
]; p
; p
= p
->nextbyhash
) {
205 if (p
->hashval
== hash
&& p
->name
.len
== namelen
) {
206 if (memcmp(p
->name
.name
, name
, namelen
) == 0) {
215 if ((p
= malloc(sizeof(*p
))) == NULL
)
216 do_error(_("malloc failed in dir_hash_add (%zu bytes)\n"),
219 p
->nextbyaddr
= hashtab
->byaddr
[byaddr
];
220 hashtab
->byaddr
[byaddr
] = p
;
222 hashtab
->last
->nextbyorder
= p
;
225 p
->nextbyorder
= NULL
;
228 if (!(p
->junkit
= junk
)) {
230 p
->nextbyhash
= hashtab
->byhash
[byhash
];
231 hashtab
->byhash
[byhash
] = p
;
242 * checks to see if any data entries are not in the leaf blocks
246 dir_hash_tab_t
*hashtab
)
251 for (i
= 0; i
< hashtab
->size
; i
++) {
252 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
262 dir_hash_tab_t
*hashtab
,
266 static char *seevalstr
[DIR_HASH_CK_TOTAL
];
270 seevalstr
[DIR_HASH_CK_OK
] = _("ok");
271 seevalstr
[DIR_HASH_CK_DUPLEAF
] = _("duplicate leaf");
272 seevalstr
[DIR_HASH_CK_BADHASH
] = _("hash value mismatch");
273 seevalstr
[DIR_HASH_CK_NODATA
] = _("no data entry");
274 seevalstr
[DIR_HASH_CK_NOLEAF
] = _("no leaf entry");
275 seevalstr
[DIR_HASH_CK_BADSTALE
] = _("bad stale count");
279 if (seeval
== DIR_HASH_CK_OK
&& dir_hash_unseen(hashtab
))
280 seeval
= DIR_HASH_CK_NOLEAF
;
281 if (seeval
== DIR_HASH_CK_OK
)
283 do_warn(_("bad hash table for directory inode %" PRIu64
" (%s): "),
284 ip
->i_ino
, seevalstr
[seeval
]);
286 do_warn(_("rebuilding\n"));
288 do_warn(_("would rebuild\n"));
294 dir_hash_tab_t
*hashtab
)
300 for (i
= 0; i
< hashtab
->size
; i
++) {
301 for (p
= hashtab
->byaddr
[i
]; p
; p
= n
) {
303 if (hashtab
->names_duped
)
304 free((void *)p
->name
.name
);
311 static dir_hash_tab_t
*
315 dir_hash_tab_t
*hashtab
;
318 hsize
= size
/ (16 * 4);
323 if ((hashtab
= calloc(DIR_HASH_TAB_SIZE(hsize
), 1)) == NULL
)
324 do_error(_("calloc failed in dir_hash_init\n"));
325 hashtab
->size
= hsize
;
326 hashtab
->byhash
= (dir_hash_ent_t
**)((char *)hashtab
+
327 sizeof(dir_hash_tab_t
));
328 hashtab
->byaddr
= (dir_hash_ent_t
**)((char *)hashtab
+
329 sizeof(dir_hash_tab_t
) + sizeof(dir_hash_ent_t
*) * hsize
);
335 dir_hash_tab_t
*hashtab
,
337 xfs_dir2_dataptr_t addr
)
342 i
= DIR_HASH_FUNC(hashtab
, addr
);
343 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
344 if (p
->address
!= addr
)
347 return DIR_HASH_CK_DUPLEAF
;
348 if (p
->junkit
== 0 && p
->hashval
!= hash
)
349 return DIR_HASH_CK_BADHASH
;
351 return DIR_HASH_CK_OK
;
353 return DIR_HASH_CK_NODATA
;
357 dir_hash_update_ftype(
358 dir_hash_tab_t
*hashtab
,
359 xfs_dir2_dataptr_t addr
,
365 i
= DIR_HASH_FUNC(hashtab
, addr
);
366 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
367 if (p
->address
!= addr
)
369 p
->name
.type
= ftype
;
374 * checks to make sure leafs match a data entry, and that the stale
379 dir_hash_tab_t
*hashtab
,
380 xfs_dir2_leaf_entry_t
*ents
,
388 for (i
= j
= 0; i
< count
; i
++) {
389 if (be32_to_cpu(ents
[i
].address
) == XFS_DIR2_NULL_DATAPTR
) {
393 rval
= dir_hash_see(hashtab
, be32_to_cpu(ents
[i
].hashval
),
394 be32_to_cpu(ents
[i
].address
));
395 if (rval
!= DIR_HASH_CK_OK
)
398 return j
== stale
? DIR_HASH_CK_OK
: DIR_HASH_CK_BADSTALE
;
402 * Convert name pointers into locally allocated memory.
403 * This must only be done after all the entries have been added.
406 dir_hash_dup_names(dir_hash_tab_t
*hashtab
)
411 if (hashtab
->names_duped
)
414 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
415 name
= malloc(p
->name
.len
);
416 memcpy(name
, p
->name
.name
, p
->name
.len
);
419 hashtab
->names_duped
= 1;
423 * Given a block number in a fork, return the next valid block number
425 * If this is the last block number then NULLFILEOFF is returned.
427 * This was originally in the kernel, but only used in xfs_repair.
431 xfs_trans_t
*tp
, /* transaction pointer */
432 xfs_inode_t
*ip
, /* incore inode */
433 xfs_fileoff_t
*bnop
, /* current block */
434 int whichfork
) /* data or attr fork */
436 xfs_fileoff_t bno
; /* current block */
437 int eof
; /* hit end of file */
438 int error
; /* error return value */
439 xfs_bmbt_irec_t got
; /* current extent value */
440 xfs_ifork_t
*ifp
; /* inode fork pointer */
441 xfs_extnum_t lastx
; /* last extent used */
442 xfs_bmbt_irec_t prev
; /* previous extent value */
444 if (XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_BTREE
&&
445 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_EXTENTS
&&
446 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_LOCAL
)
448 if (XFS_IFORK_FORMAT(ip
, whichfork
) == XFS_DINODE_FMT_LOCAL
) {
452 ifp
= XFS_IFORK_PTR(ip
, whichfork
);
453 if (!(ifp
->if_flags
& XFS_IFEXTENTS
) &&
454 (error
= xfs_iread_extents(tp
, ip
, whichfork
)))
457 libxfs_bmap_search_extents(ip
, bno
, whichfork
, &eof
, &lastx
,
462 *bnop
= got
.br_startoff
< bno
? bno
: got
.br_startoff
;
472 do_error(_("ran out of disk space!\n"));
474 do_error(_("xfs_trans_reserve returned %d\n"), err
);
478 mk_rbmino(xfs_mount_t
*mp
)
487 xfs_bmap_free_t flist
;
489 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
492 struct xfs_trans_res tres
= {0};
497 tp
= libxfs_trans_alloc(mp
, 0);
499 i
= -libxfs_trans_reserve(tp
, &tres
, 10, 0);
503 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
506 _("couldn't iget realtime bitmap inode -- error - %d\n"),
510 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
511 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
513 VFS_I(ip
)->i_mode
= S_IFREG
;
514 ip
->i_d
.di_version
= vers
;
515 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
516 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
518 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
520 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
521 if (ip
->i_d
.di_version
== 3) {
522 VFS_I(ip
)->i_version
= 1;
523 ip
->i_d
.di_flags2
= 0;
524 times
|= XFS_ICHGTIME_CREATE
;
526 libxfs_trans_ichgtime(tp
, ip
, times
);
531 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
532 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
533 ip
->i_df
.if_u1
.if_extents
= NULL
;
535 ip
->i_d
.di_size
= mp
->m_sb
.sb_rbmblocks
* mp
->m_sb
.sb_blocksize
;
540 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
541 libxfs_trans_commit(tp
);
544 * then allocate blocks for file and fill with zeroes (stolen
547 tp
= libxfs_trans_alloc(mp
, 0);
548 error
= -libxfs_trans_reserve(tp
, &tres
, mp
->m_sb
.sb_rbmblocks
+
549 (XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) - 1), 0);
553 libxfs_trans_ijoin(tp
, ip
, 0);
555 xfs_bmap_init(&flist
, &first
);
556 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
557 nmap
= XFS_BMAP_MAX_NMAP
;
558 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
559 (xfs_extlen_t
)(mp
->m_sb
.sb_rbmblocks
- bno
),
560 0, &first
, mp
->m_sb
.sb_rbmblocks
,
564 _("couldn't allocate realtime bitmap, error = %d\n"),
567 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
568 libxfs_device_zero(mp
->m_ddev_targp
,
569 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
570 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
571 bno
+= ep
->br_blockcount
;
574 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
577 _("allocation of the realtime bitmap failed, error = %d\n"),
580 libxfs_trans_commit(tp
);
585 fill_rbmino(xfs_mount_t
*mp
)
596 struct xfs_trans_res tres
= {0};
601 tp
= libxfs_trans_alloc(mp
, 0);
603 error
= -libxfs_trans_reserve(tp
, &tres
, 10, 0);
607 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
610 _("couldn't iget realtime bitmap inode -- error - %d\n"),
615 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
617 * fill the file one block at a time
620 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
621 &first
, 1, &map
, &nmap
, NULL
);
622 if (error
|| nmap
!= 1) {
624 _("couldn't map realtime bitmap block %" PRIu64
", error = %d\n"),
628 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
630 error
= -libxfs_trans_read_buf(
632 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
633 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
637 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime bitmap inode %" PRIu64
"\n"),
638 bno
, map
.br_startblock
, mp
->m_sb
.sb_rbmino
);
642 memmove(XFS_BUF_PTR(bp
), bmp
, mp
->m_sb
.sb_blocksize
);
644 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
646 bmp
= (xfs_rtword_t
*)((intptr_t) bmp
+ mp
->m_sb
.sb_blocksize
);
650 libxfs_trans_commit(tp
);
656 fill_rsumino(xfs_mount_t
*mp
)
666 xfs_fileoff_t end_bno
;
668 struct xfs_trans_res tres
= {0};
672 end_bno
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
674 tp
= libxfs_trans_alloc(mp
, 0);
676 error
= -libxfs_trans_reserve(tp
, &tres
, 10, 0);
680 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
683 _("couldn't iget realtime summary inode -- error - %d\n"),
688 while (bno
< end_bno
) {
690 * fill the file one block at a time
693 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
694 &first
, 1, &map
, &nmap
, NULL
);
695 if (error
|| nmap
!= 1) {
697 _("couldn't map realtime summary inode block %" PRIu64
", error = %d\n"),
701 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
703 error
= -libxfs_trans_read_buf(
705 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
706 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
710 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime summary inode %" PRIu64
"\n"),
711 bno
, map
.br_startblock
, mp
->m_sb
.sb_rsumino
);
716 memmove(XFS_BUF_PTR(bp
), smp
, mp
->m_sb
.sb_blocksize
);
718 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
720 smp
= (xfs_suminfo_t
*)((intptr_t)smp
+ mp
->m_sb
.sb_blocksize
);
724 libxfs_trans_commit(tp
);
730 mk_rsumino(xfs_mount_t
*mp
)
740 xfs_bmap_free_t flist
;
742 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
745 struct xfs_trans_res tres
= {0};
750 tp
= libxfs_trans_alloc(mp
, 0);
752 i
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_ichange
, 10, 0);
756 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
759 _("couldn't iget realtime summary inode -- error - %d\n"),
763 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
764 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
766 VFS_I(ip
)->i_mode
= S_IFREG
;
767 ip
->i_d
.di_version
= vers
;
768 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
769 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
771 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
773 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
774 if (ip
->i_d
.di_version
== 3) {
775 VFS_I(ip
)->i_version
= 1;
776 ip
->i_d
.di_flags2
= 0;
777 times
|= XFS_ICHGTIME_CREATE
;
779 libxfs_trans_ichgtime(tp
, ip
, times
);
784 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
785 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
786 ip
->i_df
.if_u1
.if_extents
= NULL
;
788 ip
->i_d
.di_size
= mp
->m_rsumsize
;
793 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
794 libxfs_trans_commit(tp
);
797 * then allocate blocks for file and fill with zeroes (stolen
800 tp
= libxfs_trans_alloc(mp
, 0);
801 xfs_bmap_init(&flist
, &first
);
803 nsumblocks
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
804 tres
.tr_logres
= BBTOB(128);
805 tres
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
806 tres
.tr_logflags
= XFS_TRANS_PERM_LOG_RES
;
807 error
= -libxfs_trans_reserve(tp
, &tres
, mp
->m_sb
.sb_rbmblocks
+
808 (XFS_BM_MAXLEVELS(mp
, XFS_DATA_FORK
) - 1), 0);
812 libxfs_trans_ijoin(tp
, ip
, 0);
814 xfs_bmap_init(&flist
, &first
);
815 while (bno
< nsumblocks
) {
816 nmap
= XFS_BMAP_MAX_NMAP
;
817 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
818 (xfs_extlen_t
)(nsumblocks
- bno
),
819 0, &first
, nsumblocks
, map
, &nmap
, &flist
);
822 _("couldn't allocate realtime summary inode, error = %d\n"),
825 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
826 libxfs_device_zero(mp
->m_ddev_targp
,
827 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
828 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
829 bno
+= ep
->br_blockcount
;
832 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
835 _("allocation of the realtime summary ino failed, error = %d\n"),
838 libxfs_trans_commit(tp
);
843 * makes a new root directory.
846 mk_root_dir(xfs_mount_t
*mp
)
852 const mode_t mode
= 0755;
853 ino_tree_node_t
*irec
;
857 tp
= libxfs_trans_alloc(mp
, 0);
860 i
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_ichange
, 10, 0);
864 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rootino
, 0, 0, &ip
);
866 do_error(_("could not iget root inode -- error - %d\n"), error
);
870 * take care of the core -- initialization from xfs_ialloc()
872 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
873 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
875 VFS_I(ip
)->i_mode
= mode
|S_IFDIR
;
876 ip
->i_d
.di_version
= vers
;
877 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
878 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
880 set_nlink(VFS_I(ip
), 1); /* account for . */
882 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
883 if (ip
->i_d
.di_version
== 3) {
884 VFS_I(ip
)->i_version
= 1;
885 ip
->i_d
.di_flags2
= 0;
886 times
|= XFS_ICHGTIME_CREATE
;
888 libxfs_trans_ichgtime(tp
, ip
, times
);
890 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
895 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
896 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
897 ip
->i_df
.if_u1
.if_extents
= NULL
;
902 * initialize the directory
904 ip
->d_ops
= mp
->m_dir_inode_ops
;
905 libxfs_dir_init(tp
, ip
, ip
);
907 libxfs_trans_commit(tp
);
910 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
911 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
912 set_inode_isadir(irec
, XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
) -
917 * orphanage name == lost+found
920 mk_orphanage(xfs_mount_t
*mp
)
927 ino_tree_node_t
*irec
;
931 xfs_bmap_free_t flist
;
932 const int mode
= 0755;
934 struct xfs_name xname
;
937 * check for an existing lost+found first, if it exists, return
938 * its inode. Otherwise, we can create it. Bad lost+found inodes
939 * would have been cleared in phase3 and phase4.
942 if ((i
= -libxfs_iget(mp
, NULL
, mp
->m_sb
.sb_rootino
, 0, &pip
, 0)))
943 do_error(_("%d - couldn't iget root inode to obtain %s\n"),
946 xname
.name
= (unsigned char *)ORPHANAGE
;
947 xname
.len
= strlen(ORPHANAGE
);
948 xname
.type
= XFS_DIR3_FT_DIR
;
950 if (libxfs_dir_lookup(NULL
, pip
, &xname
, &ino
, NULL
) == 0)
954 * could not be found, create it
957 tp
= libxfs_trans_alloc(mp
, 0);
958 xfs_bmap_init(&flist
, &first
);
960 nres
= XFS_MKDIR_SPACE_RES(mp
, xname
.len
);
961 i
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_mkdir
, nres
, 0);
966 * use iget/ijoin instead of trans_iget because the ialloc
967 * wrapper can commit the transaction and start a new one
969 /* if ((i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip, 0)))
970 do_error(_("%d - couldn't iget root inode to make %s\n"),
973 error
= -libxfs_inode_alloc(&tp
, pip
, mode
|S_IFDIR
,
974 1, 0, &zerocr
, &zerofsx
, &ip
);
976 do_error(_("%s inode allocation failed %d\n"),
979 inc_nlink(VFS_I(ip
)); /* account for . */
982 irec
= find_inode_rec(mp
,
983 XFS_INO_TO_AGNO(mp
, ino
),
984 XFS_INO_TO_AGINO(mp
, ino
));
988 * This inode is allocated from a newly created inode
989 * chunk and therefore did not exist when inode chunks
990 * were processed in phase3. Add this group of inodes to
991 * the entry avl tree as if they were discovered in phase3.
993 irec
= set_inode_free_alloc(mp
, XFS_INO_TO_AGNO(mp
, ino
),
994 XFS_INO_TO_AGINO(mp
, ino
));
997 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++)
998 set_inode_free(irec
, i
);
1001 ino_offset
= get_inode_offset(mp
, ino
, irec
);
1004 * Mark the inode allocated to lost+found as used in the AVL tree
1005 * so it is not skipped in phase 7
1007 set_inode_used(irec
, ino_offset
);
1008 add_inode_ref(irec
, ino_offset
);
1011 * now that we know the transaction will stay around,
1012 * add the root inode to it
1014 libxfs_trans_ijoin(tp
, pip
, 0);
1017 * create the actual entry
1019 error
= -libxfs_dir_createname(tp
, pip
, &xname
, ip
->i_ino
, &first
,
1023 _("can't make %s, createname error %d\n"),
1027 * bump up the link count in the root directory to account
1028 * for .. in the new directory
1030 inc_nlink(VFS_I(pip
));
1031 add_inode_ref(find_inode_rec(mp
,
1032 XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
1033 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
)), 0);
1037 libxfs_trans_log_inode(tp
, pip
, XFS_ILOG_CORE
);
1038 libxfs_dir_init(tp
, ip
, pip
);
1039 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1041 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
1043 do_error(_("%s directory creation failed -- bmapf error %d\n"),
1048 libxfs_trans_commit(tp
);
1051 add_inode_reached(irec
,ino_offset
);
1057 * move a file to the orphange.
1062 xfs_ino_t ino
, /* inode # to be moved */
1063 int isa_dir
) /* 1 if inode is a directory */
1065 xfs_inode_t
*orphanage_ip
;
1066 xfs_ino_t entry_ino_num
;
1069 xfs_fsblock_t first
;
1070 xfs_bmap_free_t flist
;
1072 unsigned char fname
[MAXPATHLEN
+ 1];
1075 ino_tree_node_t
*irec
;
1077 struct xfs_name xname
;
1080 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu",
1081 (unsigned long long)ino
);
1083 err
= -libxfs_iget(mp
, NULL
, orphanage_ino
, 0, &orphanage_ip
, 0);
1085 do_error(_("%d - couldn't iget orphanage inode\n"), err
);
1087 * Make sure the filename is unique in the lost+found
1090 while (libxfs_dir_lookup(NULL
, orphanage_ip
, &xname
, &entry_ino_num
,
1092 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu.%d",
1093 (unsigned long long)ino
, ++incr
);
1095 tp
= libxfs_trans_alloc(mp
, 0);
1097 if ((err
= -libxfs_iget(mp
, NULL
, ino
, 0, &ino_p
, 0)))
1098 do_error(_("%d - couldn't iget disconnected inode\n"), err
);
1100 xname
.type
= xfs_mode_to_ftype
[(VFS_I(ino_p
)->i_mode
& S_IFMT
)>>S_SHIFT
];
1103 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, orphanage_ino
),
1104 XFS_INO_TO_AGINO(mp
, orphanage_ino
));
1106 ino_offset
= XFS_INO_TO_AGINO(mp
, orphanage_ino
) -
1108 nres
= XFS_DIRENTER_SPACE_RES(mp
, fnamelen
) +
1109 XFS_DIRENTER_SPACE_RES(mp
, 2);
1110 err
= -libxfs_dir_lookup(tp
, ino_p
, &xfs_name_dotdot
,
1111 &entry_ino_num
, NULL
);
1113 ASSERT(err
== ENOENT
);
1115 err
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_rename
,
1119 _("space reservation failed (%d), filesystem may be out of space\n"),
1122 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1123 libxfs_trans_ijoin(tp
, ino_p
, 0);
1125 xfs_bmap_init(&flist
, &first
);
1126 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1127 ino
, &first
, &flist
, nres
);
1130 _("name create failed in %s (%d), filesystem may be out of space\n"),
1134 add_inode_ref(irec
, ino_offset
);
1136 inc_nlink(VFS_I(orphanage_ip
));
1137 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1139 err
= -libxfs_dir_createname(tp
, ino_p
, &xfs_name_dotdot
,
1140 orphanage_ino
, &first
, &flist
, nres
);
1143 _("creation of .. entry failed (%d), filesystem may be out of space\n"),
1146 inc_nlink(VFS_I(ino_p
));
1147 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1149 err
= -libxfs_bmap_finish(&tp
, &flist
, ino_p
);
1152 _("bmap finish failed (err - %d), filesystem may be out of space\n"),
1155 libxfs_trans_commit(tp
);
1157 err
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_rename
,
1161 _("space reservation failed (%d), filesystem may be out of space\n"),
1164 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1165 libxfs_trans_ijoin(tp
, ino_p
, 0);
1167 xfs_bmap_init(&flist
, &first
);
1169 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1170 ino
, &first
, &flist
, nres
);
1173 _("name create failed in %s (%d), filesystem may be out of space\n"),
1177 add_inode_ref(irec
, ino_offset
);
1179 inc_nlink(VFS_I(orphanage_ip
));
1180 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1183 * don't replace .. value if it already points
1184 * to us. that'll pop a libxfs/kernel ASSERT.
1186 if (entry_ino_num
!= orphanage_ino
) {
1187 err
= -libxfs_dir_replace(tp
, ino_p
,
1188 &xfs_name_dotdot
, orphanage_ino
,
1189 &first
, &flist
, nres
);
1192 _("name replace op failed (%d), filesystem may be out of space\n"),
1196 err
= -libxfs_bmap_finish(&tp
, &flist
, ino_p
);
1199 _("bmap finish failed (%d), filesystem may be out of space\n"),
1202 libxfs_trans_commit(tp
);
1207 * use the remove log reservation as that's
1208 * more accurate. we're only creating the
1209 * links, we're not doing the inode allocation
1210 * also accounted for in the create
1212 nres
= XFS_DIRENTER_SPACE_RES(mp
, xname
.len
);
1213 err
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_remove
,
1217 _("space reservation failed (%d), filesystem may be out of space\n"),
1220 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1221 libxfs_trans_ijoin(tp
, ino_p
, 0);
1223 xfs_bmap_init(&flist
, &first
);
1224 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
, ino
,
1225 &first
, &flist
, nres
);
1228 _("name create failed in %s (%d), filesystem may be out of space\n"),
1232 set_nlink(VFS_I(ino_p
), 1);
1233 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1235 err
= -libxfs_bmap_finish(&tp
, &flist
, ino_p
);
1238 _("bmap finish failed (%d), filesystem may be out of space\n"),
1241 libxfs_trans_commit(tp
);
1244 IRELE(orphanage_ip
);
1254 do_warn(msg
, iname
, ino1
, ino2
);
1257 do_warn(_(", marking entry to be junked\n"));
1261 do_warn(_(", would junk entry\n"));
1266 * Unexpected failure during the rebuild will leave the entries in
1267 * lost+found on the next run
1271 longform_dir2_rebuild(
1275 ino_tree_node_t
*irec
,
1277 dir_hash_tab_t
*hashtab
)
1282 xfs_fileoff_t lastblock
;
1283 xfs_fsblock_t firstblock
;
1284 xfs_bmap_free_t flist
;
1290 * trash directory completely and rebuild from scratch using the
1291 * name/inode pairs in the hash table
1294 do_warn(_("rebuilding directory inode %" PRIu64
"\n"), ino
);
1297 * first attempt to locate the parent inode, if it can't be
1298 * found, set it to the root inode and it'll be moved to the
1299 * orphanage later (the inode number here needs to be valid
1300 * for the libxfs_dir_init() call).
1302 pip
.i_ino
= get_inode_parent(irec
, ino_offset
);
1303 if (pip
.i_ino
== NULLFSINO
||
1304 xfs_dir_ino_validate(mp
, pip
.i_ino
))
1305 pip
.i_ino
= mp
->m_sb
.sb_rootino
;
1307 xfs_bmap_init(&flist
, &firstblock
);
1309 tp
= libxfs_trans_alloc(mp
, 0);
1310 nres
= XFS_REMOVE_SPACE_RES(mp
);
1311 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_remove
, nres
, 0);
1314 libxfs_trans_ijoin(tp
, ip
, 0);
1316 if ((error
= -libxfs_bmap_last_offset(ip
, &lastblock
, XFS_DATA_FORK
)))
1317 do_error(_("xfs_bmap_last_offset failed -- error - %d\n"),
1320 /* free all data, leaf, node and freespace blocks */
1321 error
= -libxfs_bunmapi(tp
, ip
, 0, lastblock
, XFS_BMAPI_METADATA
, 0,
1322 &firstblock
, &flist
, &done
);
1324 do_warn(_("xfs_bunmapi failed -- error - %d\n"), error
);
1325 goto out_bmap_cancel
;
1330 error
= libxfs_dir_init(tp
, ip
, &pip
);
1332 do_warn(_("xfs_dir_init failed -- error - %d\n"), error
);
1333 goto out_bmap_cancel
;
1336 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
1338 libxfs_trans_commit(tp
);
1340 if (ino
== mp
->m_sb
.sb_rootino
)
1341 need_root_dotdot
= 0;
1343 /* go through the hash list and re-add the inodes */
1345 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
1347 if (p
->name
.name
[0] == '/' || (p
->name
.name
[0] == '.' &&
1348 (p
->name
.len
== 1 || (p
->name
.len
== 2 &&
1349 p
->name
.name
[1] == '.'))))
1352 tp
= libxfs_trans_alloc(mp
, 0);
1353 nres
= XFS_CREATE_SPACE_RES(mp
, p
->name
.len
);
1354 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_create
,
1359 libxfs_trans_ijoin(tp
, ip
, 0);
1361 xfs_bmap_init(&flist
, &firstblock
);
1362 error
= -libxfs_dir_createname(tp
, ip
, &p
->name
, p
->inum
,
1363 &firstblock
, &flist
, nres
);
1366 _("name create failed in ino %" PRIu64
" (%d), filesystem may be out of space\n"),
1368 goto out_bmap_cancel
;
1371 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
1374 _("bmap finish failed (%d), filesystem may be out of space\n"),
1376 goto out_bmap_cancel
;
1379 libxfs_trans_commit(tp
);
1385 libxfs_bmap_cancel(&flist
);
1386 libxfs_trans_cancel(tp
);
1392 * Kill a block in a version 2 inode.
1393 * Makes its own transaction.
1404 xfs_fsblock_t firstblock
;
1405 xfs_bmap_free_t flist
;
1409 tp
= libxfs_trans_alloc(mp
, 0);
1410 nres
= XFS_REMOVE_SPACE_RES(mp
);
1411 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_remove
, nres
, 0);
1414 libxfs_trans_ijoin(tp
, ip
, 0);
1415 libxfs_trans_bjoin(tp
, bp
);
1416 memset(&args
, 0, sizeof(args
));
1417 xfs_bmap_init(&flist
, &firstblock
);
1420 args
.firstblock
= &firstblock
;
1421 args
.flist
= &flist
;
1422 args
.whichfork
= XFS_DATA_FORK
;
1423 args
.geo
= mp
->m_dir_geo
;
1424 if (da_bno
>= mp
->m_dir_geo
->leafblk
&& da_bno
< mp
->m_dir_geo
->freeblk
)
1425 error
= -libxfs_da_shrink_inode(&args
, da_bno
, bp
);
1427 error
= -libxfs_dir2_shrink_inode(&args
,
1428 xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
), bp
);
1430 do_error(_("shrink_inode failed inode %" PRIu64
" block %u\n"),
1432 libxfs_bmap_finish(&tp
, &flist
, ip
);
1433 libxfs_trans_commit(tp
);
1437 * process a data block, also checks for .. entry
1438 * and corrects it to match what we think .. should be
1441 longform_dir2_entry_check_data(
1446 ino_tree_node_t
*current_irec
,
1447 int current_ino_offset
,
1448 struct xfs_buf
**bpp
,
1449 dir_hash_tab_t
*hashtab
,
1450 freetab_t
**freetabp
,
1454 xfs_dir2_dataptr_t addr
;
1455 xfs_dir2_leaf_entry_t
*blp
;
1457 xfs_dir2_block_tail_t
*btp
;
1458 struct xfs_dir2_data_hdr
*d
;
1460 xfs_dir2_data_entry_t
*dep
;
1461 xfs_dir2_data_unused_t
*dup
;
1462 struct xfs_dir2_data_free
*bf
;
1465 xfs_fsblock_t firstblock
;
1466 xfs_bmap_free_t flist
;
1467 char fname
[MAXNAMELEN
+ 1];
1472 ino_tree_node_t
*irec
;
1483 struct xfs_da_args da
= {
1485 .geo
= mp
->m_dir_geo
,
1491 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1493 needscan
= needlog
= 0;
1495 freetab
= *freetabp
;
1497 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, d
);
1498 blp
= xfs_dir2_block_leaf_p(btp
);
1499 endptr
= (char *)blp
;
1500 if (endptr
> (char *)btp
)
1501 endptr
= (char *)btp
;
1502 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1503 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1505 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1507 endptr
= (char *)d
+ mp
->m_dir_geo
->blksize
;
1508 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1509 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1511 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1513 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
1515 /* check for data block beyond expected end */
1516 if (freetab
->naents
<= db
) {
1517 struct freetab_ent e
;
1519 *freetabp
= freetab
= realloc(freetab
, FREETAB_SIZE(db
+ 1));
1521 do_error(_("realloc failed in %s (%zu bytes)\n"),
1522 __func__
, FREETAB_SIZE(db
+ 1));
1526 for (i
= freetab
->naents
; i
< db
; i
++)
1527 freetab
->ents
[i
] = e
;
1528 freetab
->naents
= db
+ 1;
1531 /* check the data block */
1532 while (ptr
< endptr
) {
1534 /* check for freespace */
1535 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1536 if (XFS_DIR2_DATA_FREE_TAG
== be16_to_cpu(dup
->freetag
)) {
1538 /* check for invalid freespace length */
1539 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1540 be16_to_cpu(dup
->length
) == 0 ||
1541 (be16_to_cpu(dup
->length
) &
1542 (XFS_DIR2_DATA_ALIGN
- 1)))
1545 /* check for invalid tag */
1546 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1547 (char *)dup
- (char *)d
)
1550 /* check for block with no data entries */
1551 if ((ptr
== (char *)M_DIROPS(mp
)->data_entry_p(d
)) &&
1552 (ptr
+ be16_to_cpu(dup
->length
) >= endptr
)) {
1558 /* continue at the end of the freespace */
1559 ptr
+= be16_to_cpu(dup
->length
);
1564 /* validate data entry size */
1565 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1566 if (ptr
+ M_DIROPS(mp
)->data_entsize(dep
->namelen
) > endptr
)
1568 if (be16_to_cpu(*M_DIROPS(mp
)->data_entry_tag_p(dep
)) !=
1569 (char *)dep
- (char *)d
)
1571 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1574 /* did we find an empty or corrupt block? */
1575 if (ptr
!= endptr
) {
1578 _("empty data block %u in directory inode %" PRIu64
": "),
1582 ("corrupt block %u in directory inode %" PRIu64
": "),
1586 do_warn(_("junking block\n"));
1587 dir2_kill_block(mp
, ip
, da_bno
, bp
);
1589 do_warn(_("would junk block\n"));
1592 freetab
->ents
[db
].v
= NULLDATAOFF
;
1597 /* update number of data blocks processed */
1598 if (freetab
->nents
< db
+ 1)
1599 freetab
->nents
= db
+ 1;
1601 tp
= libxfs_trans_alloc(mp
, 0);
1602 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_remove
, 0, 0);
1606 libxfs_trans_ijoin(tp
, ip
, 0);
1607 libxfs_trans_bjoin(tp
, bp
);
1608 libxfs_trans_bhold(tp
, bp
);
1609 xfs_bmap_init(&flist
, &firstblock
);
1610 if (be32_to_cpu(d
->magic
) != wantmagic
) {
1612 _("bad directory block magic # %#x for directory inode %" PRIu64
" block %d: "),
1613 be32_to_cpu(d
->magic
), ip
->i_ino
, da_bno
);
1615 do_warn(_("fixing magic # to %#x\n"), wantmagic
);
1616 d
->magic
= cpu_to_be32(wantmagic
);
1619 do_warn(_("would fix magic # to %#x\n"), wantmagic
);
1622 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1624 * look at each entry. reference inode pointed to by each
1625 * entry in the incore inode tree.
1626 * if not a directory, set reached flag, increment link count
1627 * if a directory and reached, mark entry as to be deleted.
1628 * if a directory, check to see if recorded parent
1629 * matches current inode #,
1630 * if so, then set reached flag, increment link count
1631 * of current and child dir inodes, push the child
1632 * directory inode onto the directory stack.
1633 * if current inode != parent, then mark entry to be deleted.
1635 while (ptr
< endptr
) {
1636 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1637 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1640 _("directory inode %" PRIu64
" block %u has consecutive free entries: "),
1644 do_warn(_("joining together\n"));
1645 len
= be16_to_cpu(dup
->length
);
1646 libxfs_dir2_data_use_free(&da
, bp
, dup
,
1647 ptr
- (char *)d
, len
, &needlog
,
1649 libxfs_dir2_data_make_free(&da
, bp
,
1650 ptr
- (char *)d
, len
, &needlog
,
1653 do_warn(_("would join together\n"));
1655 ptr
+= be16_to_cpu(dup
->length
);
1659 addr
= xfs_dir2_db_off_to_dataptr(mp
->m_dir_geo
, db
,
1661 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1662 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1663 inum
= be64_to_cpu(dep
->inumber
);
1666 * skip bogus entries (leading '/'). they'll be deleted
1667 * later. must still log it, else we leak references to
1670 if (dep
->name
[0] == '/') {
1673 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1677 memmove(fname
, dep
->name
, dep
->namelen
);
1678 fname
[dep
->namelen
] = '\0';
1679 ASSERT(inum
!= NULLFSINO
);
1681 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, inum
),
1682 XFS_INO_TO_AGINO(mp
, inum
));
1686 _("entry \"%s\" in directory inode %" PRIu64
" points to non-existent inode %" PRIu64
""),
1687 fname
, ip
->i_ino
, inum
)) {
1689 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1693 ino_offset
= XFS_INO_TO_AGINO(mp
, inum
) - irec
->ino_startnum
;
1696 * if it's a free inode, blow out the entry.
1697 * by now, any inode that we think is free
1700 if (is_inode_free(irec
, ino_offset
)) {
1703 _("entry \"%s\" in directory inode %" PRIu64
" points to free inode %" PRIu64
),
1704 fname
, ip
->i_ino
, inum
)) {
1706 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1712 * check if this inode is lost+found dir in the root
1714 if (inum
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
1716 * if it's not a directory, trash it
1718 if (!inode_isadir(irec
, ino_offset
)) {
1721 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
1722 ORPHANAGE
, inum
, ip
->i_ino
)) {
1724 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1729 * if this is a dup, it will be picked up below,
1730 * otherwise, mark it as the orphanage for later.
1733 orphanage_ino
= inum
;
1737 * check for duplicate names in directory.
1739 if (!dir_hash_add(mp
, hashtab
, addr
, inum
, dep
->namelen
,
1740 dep
->name
, M_DIROPS(mp
)->data_get_ftype(dep
))) {
1743 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
1744 fname
, inum
, ip
->i_ino
)) {
1746 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1748 if (inum
== orphanage_ino
)
1754 * if just scanning to rebuild a directory due to a ".."
1755 * update, just continue
1761 * skip the '..' entry since it's checked when the
1762 * directory is reached by something else. if it never
1763 * gets reached, it'll be moved to the orphanage and we'll
1764 * take care of it then. If it doesn't exist at all, the
1765 * directory needs to be rebuilt first before being added
1768 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
1769 dep
->name
[1] == '.') {
1771 /* ".." should be in the first block */
1774 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is not in the the first block"), fname
,
1777 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1782 ASSERT(no_modify
|| !verify_inum(mp
, inum
));
1784 * special case the . entry. we know there's only one
1785 * '.' and only '.' points to itself because bogus entries
1786 * got trashed in phase 3 if there were > 1.
1787 * bump up link count for '.' but don't set reached
1788 * until we're actually reached by another directory
1789 * '..' is already accounted for or will be taken care
1790 * of when directory is moved to orphanage.
1792 if (ip
->i_ino
== inum
) {
1793 ASSERT(dep
->name
[0] == '.' && dep
->namelen
== 1);
1794 add_inode_ref(current_irec
, current_ino_offset
);
1796 dep
!= M_DIROPS(mp
)->data_entry_p(d
)) {
1797 /* "." should be the first entry */
1800 _("entry \"%s\" in dir %" PRIu64
" is not the first entry"),
1801 fname
, inum
, ip
->i_ino
)) {
1803 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1810 * skip entries with bogus inumbers if we're in no modify mode
1812 if (no_modify
&& verify_inum(mp
, inum
))
1815 /* validate ftype field if supported */
1816 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
1817 __uint8_t dir_ftype
;
1818 __uint8_t ino_ftype
;
1820 dir_ftype
= M_DIROPS(mp
)->data_get_ftype(dep
);
1821 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
1823 if (dir_ftype
!= ino_ftype
) {
1826 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1827 dir_ftype
, ino_ftype
,
1831 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1832 dir_ftype
, ino_ftype
,
1834 M_DIROPS(mp
)->data_put_ftype(dep
,
1836 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1837 dir_hash_update_ftype(hashtab
, addr
,
1844 * check easy case first, regular inode, just bump
1845 * the link count and continue
1847 if (!inode_isadir(irec
, ino_offset
)) {
1848 add_inode_reached(irec
, ino_offset
);
1851 parent
= get_inode_parent(irec
, ino_offset
);
1852 ASSERT(parent
!= 0);
1855 * bump up the link counts in parent and child
1856 * directory but if the link doesn't agree with
1857 * the .. in the child, blow out the entry.
1858 * if the directory has already been reached,
1859 * blow away the entry also.
1861 if (is_inode_reached(irec
, ino_offset
)) {
1864 _("entry \"%s\" in dir %" PRIu64
" points to an already connected directory inode %" PRIu64
"\n"),
1865 fname
, ip
->i_ino
, inum
);
1866 } else if (parent
== ip
->i_ino
) {
1867 add_inode_reached(irec
, ino_offset
);
1868 add_inode_ref(current_irec
, current_ino_offset
);
1869 } else if (parent
== NULLFSINO
) {
1870 /* ".." was missing, but this entry refers to it,
1871 so, set it as the parent and mark for rebuild */
1873 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
1874 fname
, ip
->i_ino
, inum
);
1875 set_inode_parent(irec
, ino_offset
, ip
->i_ino
);
1876 add_inode_reached(irec
, ino_offset
);
1877 add_inode_ref(current_irec
, current_ino_offset
);
1878 add_dotdot_update(XFS_INO_TO_AGNO(mp
, inum
), irec
,
1883 _("entry \"%s\" in dir inode %" PRIu64
" inconsistent with .. value (%" PRIu64
") in ino %" PRIu64
"\n"),
1884 fname
, ip
->i_ino
, parent
, inum
);
1887 if (inum
== orphanage_ino
)
1892 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1895 _("\twill clear entry \"%s\"\n"),
1898 do_warn(_("\twould clear entry \"%s\"\n"),
1903 *num_illegal
+= nbad
;
1905 libxfs_dir2_data_freescan(mp
->m_dir_geo
, M_DIROPS(mp
), d
, &i
);
1907 libxfs_dir2_data_log_header(&da
, bp
);
1908 libxfs_bmap_finish(&tp
, &flist
, ip
);
1909 libxfs_trans_commit(tp
);
1911 /* record the largest free space in the freetab for later checking */
1912 bf
= M_DIROPS(mp
)->data_bestfree_p(d
);
1913 freetab
->ents
[db
].v
= be16_to_cpu(bf
[0].length
);
1914 freetab
->ents
[db
].s
= 0;
1917 /* check v5 metadata */
1919 __check_dir3_header(
1920 struct xfs_mount
*mp
,
1929 if (be64_to_cpu(owner
) != ino
) {
1931 _("expected owner inode %" PRIu64
", got %llu, directory block %" PRIu64
"\n"),
1932 ino
, be64_to_cpu(owner
), bp
->b_bn
);
1935 /* verify block number */
1936 if (be64_to_cpu(blkno
) != bp
->b_bn
) {
1938 _("expected block %" PRIu64
", got %llu, directory inode %" PRIu64
"\n"),
1939 bp
->b_bn
, be64_to_cpu(blkno
), ino
);
1943 if (platform_uuid_compare(uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
1945 _("wrong FS UUID, directory inode %" PRIu64
" block %" PRIu64
"\n"),
1955 struct xfs_mount
*mp
,
1959 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
1961 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
1967 struct xfs_mount
*mp
,
1971 struct xfs_dir3_blk_hdr
*info
= bp
->b_addr
;
1973 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
1978 * Check contents of leaf-form block.
1981 longform_dir2_check_leaf(
1984 dir_hash_tab_t
*hashtab
,
1992 xfs_dir2_leaf_t
*leaf
;
1993 xfs_dir2_leaf_tail_t
*ltp
;
1995 struct xfs_dir2_leaf_entry
*ents
;
1996 struct xfs_dir3_icleaf_hdr leafhdr
;
2000 da_bno
= mp
->m_dir_geo
->leafblk
;
2001 error
= dir_read_buf(ip
, da_bno
, -1, &bp
, &xfs_dir3_leaf1_buf_ops
,
2003 if (error
== EFSBADCRC
|| error
== EFSCORRUPTED
|| fixit
) {
2005 _("leaf block %u for directory inode %" PRIu64
" bad CRC\n"),
2010 _("can't read block %u for directory inode %" PRIu64
", error %d\n"),
2011 da_bno
, ip
->i_ino
, error
);
2016 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2017 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2018 ltp
= xfs_dir2_leaf_tail_p(mp
->m_dir_geo
, leaf
);
2019 bestsp
= xfs_dir2_leaf_bests_p(ltp
);
2020 if (!(leafhdr
.magic
== XFS_DIR2_LEAF1_MAGIC
||
2021 leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) ||
2022 leafhdr
.forw
|| leafhdr
.back
||
2023 leafhdr
.count
< leafhdr
.stale
||
2025 M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2026 (char *)&ents
[leafhdr
.count
] > (char *)bestsp
) {
2028 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2034 if (leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) {
2035 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2042 seeval
= dir_hash_see_all(hashtab
, ents
, leafhdr
.count
, leafhdr
.stale
);
2043 if (dir_hash_check(hashtab
, ip
, seeval
)) {
2047 badtail
= freetab
->nents
!= be32_to_cpu(ltp
->bestcount
);
2048 for (i
= 0; !badtail
&& i
< be32_to_cpu(ltp
->bestcount
); i
++) {
2049 freetab
->ents
[i
].s
= 1;
2050 badtail
= freetab
->ents
[i
].v
!= be16_to_cpu(bestsp
[i
]);
2054 _("leaf block %u for directory inode %" PRIu64
" bad tail\n"),
2064 * Check contents of the node blocks (leaves)
2065 * Looks for matching hash values for the data entries.
2068 longform_dir2_check_node(
2071 dir_hash_tab_t
*hashtab
,
2077 xfs_dir2_free_t
*free
;
2079 xfs_dir2_leaf_t
*leaf
;
2080 xfs_fileoff_t next_da_bno
;
2083 struct xfs_dir2_leaf_entry
*ents
;
2084 struct xfs_dir3_icleaf_hdr leafhdr
;
2085 struct xfs_dir3_icfree_hdr freehdr
;
2090 for (da_bno
= mp
->m_dir_geo
->leafblk
, next_da_bno
= 0;
2091 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->freeblk
;
2092 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2093 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2094 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2098 * we need to use the da3 node verifier here as it handles the
2099 * fact that reading the leaf hash tree blocks can return either
2100 * leaf or node blocks and calls the correct verifier. If we get
2101 * a node block, then we'll skip it below based on a magic
2104 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2105 &xfs_da3_node_buf_ops
, &fixit
);
2108 _("can't read leaf block %u for directory inode %" PRIu64
", error %d\n"),
2109 da_bno
, ip
->i_ino
, error
);
2113 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2114 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2115 if (!(leafhdr
.magic
== XFS_DIR2_LEAFN_MAGIC
||
2116 leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2117 leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2118 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
)) {
2120 _("unknown magic number %#x for block %u in directory inode %" PRIu64
"\n"),
2121 leafhdr
.magic
, da_bno
, ip
->i_ino
);
2126 /* check v5 metadata */
2127 if (leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2128 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2129 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2137 if (leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2138 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2144 * If there's a validator error, we need to ensure that we got
2145 * the right ops on the buffer for when we write it back out.
2147 bp
->b_ops
= &xfs_dir3_leafn_buf_ops
;
2148 if (leafhdr
.count
> M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2149 leafhdr
.count
< leafhdr
.stale
) {
2151 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2156 seeval
= dir_hash_see_all(hashtab
, ents
,
2157 leafhdr
.count
, leafhdr
.stale
);
2159 if (seeval
!= DIR_HASH_CK_OK
)
2162 if (dir_hash_check(hashtab
, ip
, seeval
))
2165 for (da_bno
= mp
->m_dir_geo
->freeblk
, next_da_bno
= 0;
2166 next_da_bno
!= NULLFILEOFF
;
2167 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2168 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2169 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2172 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2173 &xfs_dir3_free_buf_ops
, &fixit
);
2176 _("can't read freespace block %u for directory inode %" PRIu64
", error %d\n"),
2177 da_bno
, ip
->i_ino
, error
);
2181 M_DIROPS(mp
)->free_hdr_from_disk(&freehdr
, free
);
2182 bests
= M_DIROPS(mp
)->free_bests_p(free
);
2183 fdb
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2184 if (!(freehdr
.magic
== XFS_DIR2_FREE_MAGIC
||
2185 freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) ||
2187 (fdb
- xfs_dir2_byte_to_db(mp
->m_dir_geo
, XFS_DIR2_FREE_OFFSET
)) *
2188 M_DIROPS(mp
)->free_max_bests(mp
->m_dir_geo
) ||
2189 freehdr
.nvalid
< freehdr
.nused
) {
2191 _("free block %u for directory inode %" PRIu64
" bad header\n"),
2197 if (freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) {
2198 error
= check_dir3_header(mp
, bp
, ip
->i_ino
);
2204 for (i
= used
= 0; i
< freehdr
.nvalid
; i
++) {
2205 if (i
+ freehdr
.firstdb
>= freetab
->nents
||
2206 freetab
->ents
[i
+ freehdr
.firstdb
].v
!=
2207 be16_to_cpu(bests
[i
])) {
2209 _("free block %u entry %i for directory ino %" PRIu64
" bad\n"),
2210 da_bno
, i
, ip
->i_ino
);
2214 used
+= be16_to_cpu(bests
[i
]) != NULLDATAOFF
;
2215 freetab
->ents
[i
+ freehdr
.firstdb
].s
= 1;
2217 if (used
!= freehdr
.nused
) {
2219 _("free block %u for directory inode %" PRIu64
" bad nused\n"),
2226 for (i
= 0; i
< freetab
->nents
; i
++) {
2227 if ((freetab
->ents
[i
].s
== 0) &&
2228 (freetab
->ents
[i
].v
!= NULLDATAOFF
)) {
2230 _("missing freetab entry %u for directory inode %" PRIu64
"\n"),
2239 * If a directory is corrupt, we need to read in as many entries as possible,
2240 * destroy the entry and create a new one with recovered name/inode pairs.
2241 * (ie. get libxfs to do all the grunt work)
2244 longform_dir2_entry_check(xfs_mount_t
*mp
,
2249 ino_tree_node_t
*irec
,
2251 dir_hash_tab_t
*hashtab
)
2253 struct xfs_buf
**bplist
;
2260 xfs_fileoff_t next_da_bno
;
2264 struct xfs_da_args args
;
2267 freetab
= malloc(FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2269 do_error(_("malloc failed in %s (%" PRId64
" bytes)\n"),
2271 FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2274 freetab
->naents
= ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
;
2276 for (i
= 0; i
< freetab
->naents
; i
++) {
2277 freetab
->ents
[i
].v
= NULLDATAOFF
;
2278 freetab
->ents
[i
].s
= 0;
2280 num_bps
= freetab
->naents
;
2281 bplist
= calloc(num_bps
, sizeof(struct xfs_buf
*));
2283 do_error(_("calloc failed in %s (%zu bytes)\n"),
2284 __func__
, num_bps
* sizeof(struct xfs_buf
*));
2286 /* is this a block, leaf, or node directory? */
2288 args
.geo
= mp
->m_dir_geo
;
2289 libxfs_dir2_isblock(&args
, &isblock
);
2290 libxfs_dir2_isleaf(&args
, &isleaf
);
2292 /* check directory "data" blocks (ie. name/inode pairs) */
2293 for (da_bno
= 0, next_da_bno
= 0;
2294 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->leafblk
;
2295 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2296 const struct xfs_buf_ops
*ops
;
2298 struct xfs_dir2_data_hdr
*d
;
2300 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2301 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
)) {
2303 * if this is the first block, there isn't anything we
2304 * can recover so we just trash it.
2313 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2314 if (db
>= num_bps
) {
2315 /* more data blocks than expected */
2317 bplist
= realloc(bplist
, num_bps
* sizeof(struct xfs_buf
*));
2319 do_error(_("realloc failed in %s (%zu bytes)\n"),
2321 num_bps
* sizeof(struct xfs_buf
*));
2325 ops
= &xfs_dir3_block_buf_ops
;
2327 ops
= &xfs_dir3_data_buf_ops
;
2329 error
= dir_read_buf(ip
, da_bno
, -1, &bplist
[db
], ops
, &fixit
);
2332 _("can't read data block %u for directory inode %" PRIu64
" error %d\n"),
2333 da_bno
, ino
, error
);
2337 * we try to read all "data" blocks, but if we are in
2338 * block form and we fail, there isn't anything else to
2339 * read, and nothing we can do but trash it.
2348 /* check v5 metadata */
2349 d
= bplist
[db
]->b_addr
;
2350 if (be32_to_cpu(d
->magic
) == XFS_DIR3_BLOCK_MAGIC
||
2351 be32_to_cpu(d
->magic
) == XFS_DIR3_DATA_MAGIC
) {
2352 struct xfs_buf
*bp
= bplist
[db
];
2354 error
= check_dir3_header(mp
, bp
, ino
);
2361 longform_dir2_entry_check_data(mp
, ip
, num_illegal
, need_dot
,
2362 irec
, ino_offset
, &bplist
[db
], hashtab
,
2363 &freetab
, da_bno
, isblock
);
2365 fixit
|= (*num_illegal
!= 0) || dir2_is_badino(ino
) || *need_dot
;
2367 if (!dotdot_update
) {
2368 /* check btree and freespace */
2370 struct xfs_dir2_data_hdr
*block
;
2371 xfs_dir2_block_tail_t
*btp
;
2372 xfs_dir2_leaf_entry_t
*blp
;
2374 block
= bplist
[0]->b_addr
;
2375 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, block
);
2376 blp
= xfs_dir2_block_leaf_p(btp
);
2377 seeval
= dir_hash_see_all(hashtab
, blp
,
2378 be32_to_cpu(btp
->count
),
2379 be32_to_cpu(btp
->stale
));
2380 if (dir_hash_check(hashtab
, ip
, seeval
))
2382 } else if (isleaf
) {
2383 fixit
|= longform_dir2_check_leaf(mp
, ip
, hashtab
,
2386 fixit
|= longform_dir2_check_node(mp
, ip
, hashtab
,
2391 if (!no_modify
&& (fixit
|| dotdot_update
)) {
2392 dir_hash_dup_names(hashtab
);
2393 for (i
= 0; i
< num_bps
; i
++)
2395 libxfs_putbuf(bplist
[i
]);
2396 longform_dir2_rebuild(mp
, ino
, ip
, irec
, ino_offset
, hashtab
);
2400 for (i
= 0; i
< num_bps
; i
++)
2402 libxfs_putbuf(bplist
[i
]);
2410 * shortform directory v2 processing routines -- entry verification and
2411 * bad entry deletion (pruning).
2413 static struct xfs_dir2_sf_entry
*
2414 shortform_dir2_junk(
2415 struct xfs_mount
*mp
,
2416 struct xfs_dir2_sf_hdr
*sfp
,
2417 struct xfs_dir2_sf_entry
*sfep
,
2424 struct xfs_dir2_sf_entry
*next_sfep
;
2428 if (lino
== orphanage_ino
)
2431 next_elen
= M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
);
2432 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2435 * if we are just checking, simply return the pointer to the next entry
2436 * here so that the checking loop can continue.
2439 do_warn(_("would junk entry\n"));
2444 * now move all the remaining entries down over the junked entry and
2445 * clear the newly unused bytes at the tail of the directory region.
2447 next_len
= *max_size
- ((intptr_t)next_sfep
- (intptr_t)sfp
);
2448 *max_size
-= next_elen
;
2449 *bytes_deleted
+= next_elen
;
2451 memmove(sfep
, next_sfep
, next_len
);
2452 memset((void *)((intptr_t)sfep
+ next_len
), 0, next_elen
);
2457 * WARNING: drop the index i by one so it matches the decremented count
2458 * for accurate comparisons in the loop test
2463 do_warn(_("junking entry\n"));
2470 shortform_dir2_entry_check(xfs_mount_t
*mp
,
2474 ino_tree_node_t
*current_irec
,
2475 int current_ino_offset
,
2476 dir_hash_tab_t
*hashtab
)
2480 struct xfs_dir2_sf_hdr
*sfp
;
2481 struct xfs_dir2_sf_entry
*sfep
;
2482 struct xfs_dir2_sf_entry
*next_sfep
;
2483 struct xfs_ifork
*ifp
;
2484 struct ino_tree_node
*irec
;
2491 char fname
[MAXNAMELEN
+ 1];
2495 sfp
= (struct xfs_dir2_sf_hdr
*) ifp
->if_u1
.if_data
;
2499 max_size
= ifp
->if_bytes
;
2500 ASSERT(ip
->i_d
.di_size
<= ifp
->if_bytes
);
2503 * if just rebuild a directory due to a "..", update and return
2505 if (dotdot_update
) {
2506 parent
= get_inode_parent(current_irec
, current_ino_offset
);
2509 _("would set .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2513 _("setting .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2515 M_DIROPS(mp
)->sf_put_parent_ino(sfp
, parent
);
2522 * no '.' entry in shortform dirs, just bump up ref count by 1
2523 * '..' was already (or will be) accounted for and checked when
2524 * the directory is reached or will be taken care of when the
2525 * directory is moved to orphanage.
2527 add_inode_ref(current_irec
, current_ino_offset
);
2530 * Initialise i8 counter -- the parent inode number counts as well.
2532 i8
= M_DIROPS(mp
)->sf_get_parent_ino(sfp
) > XFS_DIR2_MAX_SHORT_INUM
;
2535 * now run through entries, stop at first bad entry, don't need
2536 * to skip over '..' since that's encoded in its own field and
2537 * no need to worry about '.' since it doesn't exist.
2539 sfep
= next_sfep
= xfs_dir2_sf_firstentry(sfp
);
2541 for (i
= 0; i
< sfp
->count
&& max_size
>
2542 (intptr_t)next_sfep
- (intptr_t)sfp
;
2543 sfep
= next_sfep
, i
++) {
2546 lino
= M_DIROPS(mp
)->sf_get_ino(sfp
, sfep
);
2548 namelen
= sfep
->namelen
;
2550 ASSERT(no_modify
|| namelen
> 0);
2552 if (no_modify
&& namelen
== 0) {
2554 * if we're really lucky, this is
2555 * the last entry in which case we
2556 * can use the dir size to set the
2557 * namelen value. otherwise, forget
2558 * it because we're not going to be
2559 * able to find the next entry.
2563 if (i
== sfp
->count
- 1) {
2564 namelen
= ip
->i_d
.di_size
-
2565 ((intptr_t) &sfep
->name
[0] -
2569 * don't process the rest of the directory,
2570 * break out of processing loop
2574 } else if (no_modify
&& (intptr_t) sfep
- (intptr_t) sfp
+
2575 + M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)
2576 > ip
->i_d
.di_size
) {
2579 if (i
== sfp
->count
- 1) {
2580 namelen
= ip
->i_d
.di_size
-
2581 ((intptr_t) &sfep
->name
[0] -
2585 * don't process the rest of the directory,
2586 * break out of processing loop
2592 memmove(fname
, sfep
->name
, sfep
->namelen
);
2593 fname
[sfep
->namelen
] = '\0';
2595 ASSERT(no_modify
|| (lino
!= NULLFSINO
&& lino
!= 0));
2596 ASSERT(no_modify
|| !verify_inum(mp
, lino
));
2599 * Also skip entries with bogus inode numbers if we're
2600 * in no modify mode.
2603 if (no_modify
&& verify_inum(mp
, lino
)) {
2604 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2608 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, lino
),
2609 XFS_INO_TO_AGINO(mp
, lino
));
2613 _("entry \"%s\" in shortform directory %" PRIu64
" references non-existent inode %" PRIu64
"\n"),
2615 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2616 &max_size
, &i
, &bytes_deleted
,
2621 ino_offset
= XFS_INO_TO_AGINO(mp
, lino
) - irec
->ino_startnum
;
2624 * if it's a free inode, blow out the entry.
2625 * by now, any inode that we think is free
2628 if (is_inode_free(irec
, ino_offset
)) {
2630 _("entry \"%s\" in shortform directory inode %" PRIu64
" points to free inode %" PRIu64
"\n"),
2632 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2633 &max_size
, &i
, &bytes_deleted
,
2638 * check if this inode is lost+found dir in the root
2640 if (ino
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
2642 * if it's not a directory, trash it
2644 if (!inode_isadir(irec
, ino_offset
)) {
2646 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
2647 ORPHANAGE
, lino
, ino
);
2648 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2649 lino
, &max_size
, &i
,
2650 &bytes_deleted
, ino_dirty
);
2654 * if this is a dup, it will be picked up below,
2655 * otherwise, mark it as the orphanage for later.
2658 orphanage_ino
= lino
;
2661 * check for duplicate names in directory.
2663 if (!dir_hash_add(mp
, hashtab
, (xfs_dir2_dataptr_t
)
2664 (sfep
- xfs_dir2_sf_firstentry(sfp
)),
2665 lino
, sfep
->namelen
, sfep
->name
,
2666 M_DIROPS(mp
)->sf_get_ftype(sfep
))) {
2668 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
2670 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2671 &max_size
, &i
, &bytes_deleted
,
2676 if (!inode_isadir(irec
, ino_offset
)) {
2678 * check easy case first, regular inode, just bump
2681 add_inode_reached(irec
, ino_offset
);
2683 parent
= get_inode_parent(irec
, ino_offset
);
2686 * bump up the link counts in parent and child.
2687 * directory but if the link doesn't agree with
2688 * the .. in the child, blow out the entry
2690 if (is_inode_reached(irec
, ino_offset
)) {
2692 _("entry \"%s\" in directory inode %" PRIu64
2693 " references already connected inode %" PRIu64
".\n"),
2695 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2696 lino
, &max_size
, &i
,
2697 &bytes_deleted
, ino_dirty
);
2699 } else if (parent
== ino
) {
2700 add_inode_reached(irec
, ino_offset
);
2701 add_inode_ref(current_irec
, current_ino_offset
);
2702 } else if (parent
== NULLFSINO
) {
2703 /* ".." was missing, but this entry refers to it,
2704 so, set it as the parent and mark for rebuild */
2706 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
2708 set_inode_parent(irec
, ino_offset
, ino
);
2709 add_inode_reached(irec
, ino_offset
);
2710 add_inode_ref(current_irec
, current_ino_offset
);
2711 add_dotdot_update(XFS_INO_TO_AGNO(mp
, lino
),
2715 _("entry \"%s\" in directory inode %" PRIu64
2716 " not consistent with .. value (%" PRIu64
2717 ") in inode %" PRIu64
",\n"),
2718 fname
, ino
, parent
, lino
);
2719 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2720 lino
, &max_size
, &i
,
2721 &bytes_deleted
, ino_dirty
);
2726 /* validate ftype field if supported */
2727 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
2728 __uint8_t dir_ftype
;
2729 __uint8_t ino_ftype
;
2731 dir_ftype
= M_DIROPS(mp
)->sf_get_ftype(sfep
);
2732 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
2734 if (dir_ftype
!= ino_ftype
) {
2737 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2738 dir_ftype
, ino_ftype
,
2742 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2743 dir_ftype
, ino_ftype
,
2745 M_DIROPS(mp
)->sf_put_ftype(sfep
,
2747 dir_hash_update_ftype(hashtab
,
2748 (xfs_dir2_dataptr_t
)(sfep
- xfs_dir2_sf_firstentry(sfp
)),
2755 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
2759 * go onto next entry - we have to take entries with bad namelen
2760 * into account in no modify mode since we calculate size based
2763 ASSERT(no_modify
|| bad_sfnamelen
== 0);
2764 next_sfep
= (struct xfs_dir2_sf_entry
*)((intptr_t)sfep
+
2766 ? M_DIROPS(mp
)->sf_entsize(sfp
, namelen
)
2767 : M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)));
2770 if (sfp
->i8count
!= i8
) {
2772 do_warn(_("would fix i8count in inode %" PRIu64
"\n"),
2776 struct xfs_dir2_sf_entry
*tmp_sfep
;
2778 tmp_sfep
= next_sfep
;
2779 process_sf_dir2_fixi8(mp
, sfp
, &tmp_sfep
);
2781 (intptr_t)next_sfep
-
2783 next_sfep
= tmp_sfep
;
2787 do_warn(_("fixing i8count in inode %" PRIu64
"\n"),
2793 * sync up sizes if required
2795 if (*ino_dirty
&& bytes_deleted
> 0) {
2797 libxfs_idata_realloc(ip
, -bytes_deleted
, XFS_DATA_FORK
);
2798 ip
->i_d
.di_size
-= bytes_deleted
;
2801 if (ip
->i_d
.di_size
!= ip
->i_df
.if_bytes
) {
2802 ASSERT(ip
->i_df
.if_bytes
== (xfs_fsize_t
)
2803 ((intptr_t) next_sfep
- (intptr_t) sfp
));
2804 ip
->i_d
.di_size
= (xfs_fsize_t
)
2805 ((intptr_t) next_sfep
- (intptr_t) sfp
);
2807 _("setting size to %" PRId64
" bytes to reflect junked entries\n"),
2814 * processes all reachable inodes in directories
2819 xfs_agnumber_t agno
,
2820 ino_tree_node_t
*irec
,
2824 xfs_bmap_free_t flist
;
2825 xfs_fsblock_t first
;
2828 dir_hash_tab_t
*hashtab
;
2830 int dirty
, num_illegal
, error
, nres
;
2832 ino
= XFS_AGINO_TO_INO(mp
, agno
, irec
->ino_startnum
+ ino_offset
);
2835 * open up directory inode, check all entries,
2836 * then call prune_dir_entries to remove all
2837 * remaining illegal directory entries.
2840 ASSERT(!is_inode_refchecked(irec
, ino_offset
) || dotdot_update
);
2842 error
= -libxfs_iget(mp
, NULL
, ino
, 0, &ip
, 0);
2846 _("couldn't map inode %" PRIu64
", err = %d\n"),
2850 _("couldn't map inode %" PRIu64
", err = %d\n"),
2853 * see below for what we're doing if this
2854 * is root. Why do we need to do this here?
2855 * to ensure that the root doesn't show up
2856 * as being disconnected in the no_modify case.
2858 if (mp
->m_sb
.sb_rootino
== ino
) {
2859 add_inode_reached(irec
, 0);
2860 add_inode_ref(irec
, 0);
2864 add_inode_refchecked(irec
, 0);
2868 need_dot
= dirty
= num_illegal
= 0;
2870 if (mp
->m_sb
.sb_rootino
== ino
) {
2872 * mark root inode reached and bump up
2873 * link count for root inode to account
2874 * for '..' entry since the root inode is
2875 * never reached by a parent. we know
2876 * that root's '..' is always good --
2877 * guaranteed by phase 3 and/or below.
2879 add_inode_reached(irec
, ino_offset
);
2882 add_inode_refchecked(irec
, ino_offset
);
2884 hashtab
= dir_hash_init(ip
->i_d
.di_size
);
2887 * look for bogus entries
2889 switch (ip
->i_d
.di_format
) {
2890 case XFS_DINODE_FMT_EXTENTS
:
2891 case XFS_DINODE_FMT_BTREE
:
2893 * also check for missing '.' in longform dirs.
2894 * missing .. entries are added if required when
2895 * the directory is connected to lost+found. but
2896 * we need to create '.' entries here.
2898 longform_dir2_entry_check(mp
, ino
, ip
,
2899 &num_illegal
, &need_dot
,
2904 case XFS_DINODE_FMT_LOCAL
:
2905 tp
= libxfs_trans_alloc(mp
, 0);
2907 * using the remove reservation is overkill
2908 * since at most we'll only need to log the
2909 * inode but it's easier than wedging a
2910 * new define in ourselves.
2912 nres
= no_modify
? 0 : XFS_REMOVE_SPACE_RES(mp
);
2913 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_remove
,
2918 libxfs_trans_ijoin(tp
, ip
, 0);
2920 shortform_dir2_entry_check(mp
, ino
, ip
, &dirty
,
2924 ASSERT(dirty
== 0 || (dirty
&& !no_modify
));
2926 libxfs_trans_log_inode(tp
, ip
,
2927 XFS_ILOG_CORE
| XFS_ILOG_DDATA
);
2928 libxfs_trans_commit(tp
);
2930 libxfs_trans_cancel(tp
);
2937 dir_hash_done(hashtab
);
2940 * if we have to create a .. for /, do it now *before*
2941 * we delete the bogus entries, otherwise the directory
2942 * could transform into a shortform dir which would
2943 * probably cause the simulation to choke. Even
2944 * if the illegal entries get shifted around, it's ok
2945 * because the entries are structurally intact and in
2946 * in hash-value order so the simulation won't get confused
2947 * if it has to move them around.
2949 if (!no_modify
&& need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2950 ASSERT(ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
);
2952 do_warn(_("recreating root directory .. entry\n"));
2954 tp
= libxfs_trans_alloc(mp
, 0);
2957 nres
= XFS_MKDIR_SPACE_RES(mp
, 2);
2958 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_mkdir
, nres
, 0);
2962 libxfs_trans_ijoin(tp
, ip
, 0);
2964 xfs_bmap_init(&flist
, &first
);
2966 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dotdot
,
2967 ip
->i_ino
, &first
, &flist
, nres
);
2970 _("can't make \"..\" entry in root inode %" PRIu64
", createname error %d\n"), ino
, error
);
2972 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2974 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
2976 libxfs_trans_commit(tp
);
2978 need_root_dotdot
= 0;
2979 } else if (need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2980 do_warn(_("would recreate root directory .. entry\n"));
2984 * if we need to create the '.' entry, do so only if
2985 * the directory is a longform dir. if it's been
2986 * turned into a shortform dir, then the inode is ok
2987 * since shortform dirs have no '.' entry and the inode
2988 * has already been committed by prune_lf_dir_entry().
2992 * bump up our link count but don't
2993 * bump up the inode link count. chances
2994 * are good that even though we lost '.'
2995 * the inode link counts reflect '.' so
2996 * leave the inode link count alone and if
2997 * it turns out to be wrong, we'll catch
3000 add_inode_ref(irec
, ino_offset
);
3004 _("would create missing \".\" entry in dir ino %" PRIu64
"\n"),
3006 } else if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
) {
3008 * need to create . entry in longform dir.
3011 _("creating missing \".\" entry in dir ino %" PRIu64
"\n"), ino
);
3013 tp
= libxfs_trans_alloc(mp
, 0);
3016 nres
= XFS_MKDIR_SPACE_RES(mp
, 1);
3017 error
= -libxfs_trans_reserve(tp
, &M_RES(mp
)->tr_mkdir
,
3022 libxfs_trans_ijoin(tp
, ip
, 0);
3024 xfs_bmap_init(&flist
, &first
);
3026 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dot
,
3027 ip
->i_ino
, &first
, &flist
, nres
);
3030 _("can't make \".\" entry in dir ino %" PRIu64
", createname error %d\n"),
3033 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3035 error
= -libxfs_bmap_finish(&tp
, &flist
, ip
);
3037 libxfs_trans_commit(tp
);
3044 * mark realtime bitmap and summary inodes as reached.
3045 * quota inode will be marked here as well
3048 mark_standalone_inodes(xfs_mount_t
*mp
)
3050 ino_tree_node_t
*irec
;
3053 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rbmino
),
3054 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
));
3056 ASSERT(irec
!= NULL
);
3058 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
) -
3061 add_inode_reached(irec
, offset
);
3063 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rsumino
),
3064 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
));
3066 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
) -
3069 ASSERT(irec
!= NULL
);
3071 add_inode_reached(irec
, offset
);
3074 if (mp
->m_sb
.sb_uquotino
3075 && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
3076 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3077 mp
->m_sb
.sb_uquotino
),
3078 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
));
3079 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
)
3080 - irec
->ino_startnum
;
3081 add_inode_reached(irec
, offset
);
3083 if (mp
->m_sb
.sb_gquotino
3084 && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
3085 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3086 mp
->m_sb
.sb_gquotino
),
3087 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
));
3088 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
)
3089 - irec
->ino_startnum
;
3090 add_inode_reached(irec
, offset
);
3092 if (mp
->m_sb
.sb_pquotino
3093 && mp
->m_sb
.sb_pquotino
!= NULLFSINO
) {
3094 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3095 mp
->m_sb
.sb_pquotino
),
3096 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
));
3097 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
)
3098 - irec
->ino_startnum
;
3099 add_inode_reached(irec
, offset
);
3105 check_for_orphaned_inodes(
3107 xfs_agnumber_t agno
,
3108 ino_tree_node_t
*irec
)
3113 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3114 ASSERT(is_inode_confirmed(irec
, i
));
3115 if (is_inode_free(irec
, i
))
3118 if (is_inode_reached(irec
, i
))
3121 ASSERT(inode_isadir(irec
, i
) ||
3122 num_inode_references(irec
, i
) == 0);
3124 ino
= XFS_AGINO_TO_INO(mp
, agno
, i
+ irec
->ino_startnum
);
3125 if (inode_isadir(irec
, i
))
3126 do_warn(_("disconnected dir inode %" PRIu64
", "), ino
);
3128 do_warn(_("disconnected inode %" PRIu64
", "), ino
);
3131 orphanage_ino
= mk_orphanage(mp
);
3132 do_warn(_("moving to %s\n"), ORPHANAGE
);
3133 mv_orphanage(mp
, ino
, inode_isadir(irec
, i
));
3135 do_warn(_("would move to %s\n"), ORPHANAGE
);
3138 * for read-only case, even though the inode isn't
3139 * really reachable, set the flag (and bump our link
3140 * count) anyway to fool phase 7
3142 add_inode_reached(irec
, i
);
3149 xfs_agnumber_t agno
,
3152 ino_tree_node_t
*irec
;
3154 prefetch_args_t
*pf_args
= arg
;
3156 wait_for_inode_prefetch(pf_args
);
3159 do_log(_(" - agno = %d\n"), agno
);
3161 for (irec
= findfirst_inode_rec(agno
); irec
; irec
= next_ino_rec(irec
)) {
3162 if (irec
->ino_isa_dir
== 0)
3166 sem_post(&pf_args
->ra_count
);
3168 sem_getvalue(&pf_args
->ra_count
, &i
);
3170 "processing inode chunk %p in AG %d (sem count = %d)",
3175 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3176 if (inode_isadir(irec
, i
))
3177 process_dir_inode(wq
->mp
, agno
, irec
, i
);
3180 cleanup_inode_prefetch(pf_args
);
3184 update_missing_dotdot_entries(
3187 dotdot_update_t
*dir
;
3190 * these entries parents were updated, rebuild them again
3191 * set dotdot_update flag so processing routines do not count links
3194 while (!list_empty(&dotdot_update_list
)) {
3195 dir
= list_entry(dotdot_update_list
.prev
, struct dotdot_update
,
3197 list_del(&dir
->list
);
3198 process_dir_inode(mp
, dir
->agno
, dir
->irec
, dir
->ino_offset
);
3205 struct xfs_mount
*mp
)
3207 do_inode_prefetch(mp
, 0, traverse_function
, false, true);
3211 phase6(xfs_mount_t
*mp
)
3213 ino_tree_node_t
*irec
;
3216 memset(&zerocr
, 0, sizeof(struct cred
));
3217 memset(&zerofsx
, 0, sizeof(struct fsxattr
));
3220 do_log(_("Phase 6 - check inode connectivity...\n"));
3222 incore_ext_teardown(mp
);
3224 add_ino_ex_data(mp
);
3227 * verify existence of root directory - if we have to
3228 * make one, it's ok for the incore data structs not to
3229 * know about it since everything about it (and the other
3230 * inodes in its chunk if a new chunk was created) are ok
3232 if (need_root_inode
) {
3234 do_warn(_("reinitializing root directory\n"));
3236 need_root_inode
= 0;
3237 need_root_dotdot
= 0;
3239 do_warn(_("would reinitialize root directory\n"));
3245 do_warn(_("reinitializing realtime bitmap inode\n"));
3249 do_warn(_("would reinitialize realtime bitmap inode\n"));
3255 do_warn(_("reinitializing realtime summary inode\n"));
3259 do_warn(_("would reinitialize realtime summary inode\n"));
3265 _(" - resetting contents of realtime bitmap and summary inodes\n"));
3266 if (fill_rbmino(mp
)) {
3268 _("Warning: realtime bitmap may be inconsistent\n"));
3271 if (fill_rsumino(mp
)) {
3273 _("Warning: realtime bitmap may be inconsistent\n"));
3277 mark_standalone_inodes(mp
);
3279 do_log(_(" - traversing filesystem ...\n"));
3281 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
3282 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
3285 * we always have a root inode, even if it's free...
3286 * if the root is free, forget it, lost+found is already gone
3288 if (is_inode_free(irec
, 0) || !inode_isadir(irec
, 0)) {
3289 need_root_inode
= 1;
3293 * then process all inodes by walking incore inode tree
3298 * any directories that had updated ".." entries, rebuild them now
3300 update_missing_dotdot_entries(mp
);
3302 do_log(_(" - traversal finished ...\n"));
3303 do_log(_(" - moving disconnected inodes to %s ...\n"),
3307 * move all disconnected inodes to the orphanage
3309 for (i
= 0; i
< glob_agcount
; i
++) {
3310 irec
= findfirst_inode_rec(i
);
3311 while (irec
!= NULL
) {
3312 check_for_orphaned_inodes(mp
, i
, irec
);
3313 irec
= next_ino_rec(irec
);