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 error
; /* error return value */
438 xfs_bmbt_irec_t got
; /* current extent value */
439 xfs_ifork_t
*ifp
; /* inode fork pointer */
440 struct xfs_iext_cursor icur
;
442 if (XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_BTREE
&&
443 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_EXTENTS
&&
444 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_LOCAL
)
446 if (XFS_IFORK_FORMAT(ip
, whichfork
) == XFS_DINODE_FMT_LOCAL
) {
450 ifp
= XFS_IFORK_PTR(ip
, whichfork
);
451 if (!(ifp
->if_flags
& XFS_IFEXTENTS
) &&
452 (error
= -libxfs_iread_extents(tp
, ip
, whichfork
)))
455 if (!libxfs_iext_lookup_extent(ip
, ifp
, bno
, &icur
, &got
))
458 *bnop
= got
.br_startoff
< bno
? bno
: got
.br_startoff
;
468 do_error(_("ran out of disk space!\n"));
470 do_error(_("xfs_trans_reserve returned %d\n"), err
);
474 mk_rbmino(xfs_mount_t
*mp
)
483 struct xfs_defer_ops dfops
;
485 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
488 struct xfs_trans_res tres
= {0};
493 i
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
497 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
500 _("couldn't iget realtime bitmap inode -- error - %d\n"),
504 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
505 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
507 VFS_I(ip
)->i_mode
= S_IFREG
;
508 ip
->i_d
.di_version
= vers
;
509 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
510 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
512 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
514 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
515 if (ip
->i_d
.di_version
== 3) {
516 VFS_I(ip
)->i_version
= 1;
517 ip
->i_d
.di_flags2
= 0;
518 times
|= XFS_ICHGTIME_CREATE
;
520 libxfs_trans_ichgtime(tp
, ip
, times
);
525 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
526 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
527 ip
->i_df
.if_u1
.if_root
= NULL
;
529 ip
->i_d
.di_size
= mp
->m_sb
.sb_rbmblocks
* mp
->m_sb
.sb_blocksize
;
534 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
535 libxfs_trans_commit(tp
);
538 * then allocate blocks for file and fill with zeroes (stolen
541 error
= -libxfs_trans_alloc(mp
, &tres
,
542 mp
->m_sb
.sb_rbmblocks
+ (XFS_BM_MAXLEVELS(mp
,XFS_DATA_FORK
) - 1),
547 libxfs_trans_ijoin(tp
, ip
, 0);
549 libxfs_defer_init(&dfops
, &first
);
550 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
551 nmap
= XFS_BMAP_MAX_NMAP
;
552 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
553 (xfs_extlen_t
)(mp
->m_sb
.sb_rbmblocks
- bno
),
554 0, &first
, mp
->m_sb
.sb_rbmblocks
,
558 _("couldn't allocate realtime bitmap, error = %d\n"),
561 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
562 libxfs_device_zero(mp
->m_ddev_targp
,
563 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
564 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
565 bno
+= ep
->br_blockcount
;
568 libxfs_defer_ijoin(&dfops
, ip
);
569 error
= -libxfs_defer_finish(&tp
, &dfops
);
572 _("allocation of the realtime bitmap failed, error = %d\n"),
575 libxfs_trans_commit(tp
);
580 fill_rbmino(xfs_mount_t
*mp
)
591 struct xfs_trans_res tres
= {0};
596 error
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
600 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
603 _("couldn't iget realtime bitmap inode -- error - %d\n"),
608 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
610 * fill the file one block at a time
613 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
614 &first
, 1, &map
, &nmap
, NULL
);
615 if (error
|| nmap
!= 1) {
617 _("couldn't map realtime bitmap block %" PRIu64
", error = %d\n"),
621 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
623 error
= -libxfs_trans_read_buf(
625 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
626 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
630 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime bitmap inode %" PRIu64
"\n"),
631 bno
, map
.br_startblock
, mp
->m_sb
.sb_rbmino
);
635 memmove(XFS_BUF_PTR(bp
), bmp
, mp
->m_sb
.sb_blocksize
);
637 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
639 bmp
= (xfs_rtword_t
*)((intptr_t) bmp
+ mp
->m_sb
.sb_blocksize
);
643 libxfs_trans_commit(tp
);
649 fill_rsumino(xfs_mount_t
*mp
)
659 xfs_fileoff_t end_bno
;
661 struct xfs_trans_res tres
= {0};
665 end_bno
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
667 error
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
671 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
674 _("couldn't iget realtime summary inode -- error - %d\n"),
679 while (bno
< end_bno
) {
681 * fill the file one block at a time
684 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
685 &first
, 1, &map
, &nmap
, NULL
);
686 if (error
|| nmap
!= 1) {
688 _("couldn't map realtime summary inode block %" PRIu64
", error = %d\n"),
692 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
694 error
= -libxfs_trans_read_buf(
696 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
697 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
701 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime summary inode %" PRIu64
"\n"),
702 bno
, map
.br_startblock
, mp
->m_sb
.sb_rsumino
);
707 memmove(XFS_BUF_PTR(bp
), smp
, mp
->m_sb
.sb_blocksize
);
709 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
711 smp
= (xfs_suminfo_t
*)((intptr_t)smp
+ mp
->m_sb
.sb_blocksize
);
715 libxfs_trans_commit(tp
);
721 mk_rsumino(xfs_mount_t
*mp
)
731 struct xfs_defer_ops dfops
;
733 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
736 struct xfs_trans_res tres
= {0};
741 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
745 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
748 _("couldn't iget realtime summary inode -- error - %d\n"),
752 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
753 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
755 VFS_I(ip
)->i_mode
= S_IFREG
;
756 ip
->i_d
.di_version
= vers
;
757 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
758 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
760 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
762 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
763 if (ip
->i_d
.di_version
== 3) {
764 VFS_I(ip
)->i_version
= 1;
765 ip
->i_d
.di_flags2
= 0;
766 times
|= XFS_ICHGTIME_CREATE
;
768 libxfs_trans_ichgtime(tp
, ip
, times
);
773 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
774 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
775 ip
->i_df
.if_u1
.if_root
= NULL
;
777 ip
->i_d
.di_size
= mp
->m_rsumsize
;
782 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
783 libxfs_trans_commit(tp
);
786 * then allocate blocks for file and fill with zeroes (stolen
789 libxfs_defer_init(&dfops
, &first
);
791 nsumblocks
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
792 tres
.tr_logres
= BBTOB(128);
793 tres
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
794 tres
.tr_logflags
= XFS_TRANS_PERM_LOG_RES
;
795 error
= -libxfs_trans_alloc(mp
, &tres
,
796 mp
->m_sb
.sb_rbmblocks
+ (XFS_BM_MAXLEVELS(mp
,XFS_DATA_FORK
) - 1),
801 libxfs_trans_ijoin(tp
, ip
, 0);
803 libxfs_defer_init(&dfops
, &first
);
804 while (bno
< nsumblocks
) {
805 nmap
= XFS_BMAP_MAX_NMAP
;
806 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
807 (xfs_extlen_t
)(nsumblocks
- bno
),
808 0, &first
, nsumblocks
, map
, &nmap
, &dfops
);
811 _("couldn't allocate realtime summary inode, error = %d\n"),
814 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
815 libxfs_device_zero(mp
->m_ddev_targp
,
816 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
817 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
818 bno
+= ep
->br_blockcount
;
821 libxfs_defer_ijoin(&dfops
, ip
);
822 error
= -libxfs_defer_finish(&tp
, &dfops
);
825 _("allocation of the realtime summary ino failed, error = %d\n"),
828 libxfs_trans_commit(tp
);
833 * makes a new root directory.
836 mk_root_dir(xfs_mount_t
*mp
)
842 const mode_t mode
= 0755;
843 ino_tree_node_t
*irec
;
848 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
852 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rootino
, 0, 0, &ip
);
854 do_error(_("could not iget root inode -- error - %d\n"), error
);
858 * take care of the core -- initialization from xfs_ialloc()
860 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
861 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
863 VFS_I(ip
)->i_mode
= mode
|S_IFDIR
;
864 ip
->i_d
.di_version
= vers
;
865 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
866 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
868 set_nlink(VFS_I(ip
), 1); /* account for . */
870 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
871 if (ip
->i_d
.di_version
== 3) {
872 VFS_I(ip
)->i_version
= 1;
873 ip
->i_d
.di_flags2
= 0;
874 times
|= XFS_ICHGTIME_CREATE
;
876 libxfs_trans_ichgtime(tp
, ip
, times
);
878 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
883 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
884 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
885 ip
->i_df
.if_u1
.if_root
= NULL
;
890 * initialize the directory
892 ip
->d_ops
= mp
->m_dir_inode_ops
;
893 libxfs_dir_init(tp
, ip
, ip
);
895 libxfs_trans_commit(tp
);
898 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
899 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
900 set_inode_isadir(irec
, XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
) -
905 * orphanage name == lost+found
908 mk_orphanage(xfs_mount_t
*mp
)
915 ino_tree_node_t
*irec
;
919 struct xfs_defer_ops dfops
;
920 const int mode
= 0755;
922 struct xfs_name xname
;
925 * check for an existing lost+found first, if it exists, return
926 * its inode. Otherwise, we can create it. Bad lost+found inodes
927 * would have been cleared in phase3 and phase4.
930 if ((i
= -libxfs_iget(mp
, NULL
, mp
->m_sb
.sb_rootino
, 0, &pip
)))
931 do_error(_("%d - couldn't iget root inode to obtain %s\n"),
934 xname
.name
= (unsigned char *)ORPHANAGE
;
935 xname
.len
= strlen(ORPHANAGE
);
936 xname
.type
= XFS_DIR3_FT_DIR
;
938 if (libxfs_dir_lookup(NULL
, pip
, &xname
, &ino
, NULL
) == 0)
942 * could not be found, create it
944 libxfs_defer_init(&dfops
, &first
);
945 nres
= XFS_MKDIR_SPACE_RES(mp
, xname
.len
);
946 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
, nres
, 0, 0, &tp
);
951 * use iget/ijoin instead of trans_iget because the ialloc
952 * wrapper can commit the transaction and start a new one
954 /* if ((i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip)))
955 do_error(_("%d - couldn't iget root inode to make %s\n"),
958 error
= -libxfs_inode_alloc(&tp
, pip
, mode
|S_IFDIR
,
959 1, 0, &zerocr
, &zerofsx
, &ip
);
961 do_error(_("%s inode allocation failed %d\n"),
964 inc_nlink(VFS_I(ip
)); /* account for . */
967 irec
= find_inode_rec(mp
,
968 XFS_INO_TO_AGNO(mp
, ino
),
969 XFS_INO_TO_AGINO(mp
, ino
));
973 * This inode is allocated from a newly created inode
974 * chunk and therefore did not exist when inode chunks
975 * were processed in phase3. Add this group of inodes to
976 * the entry avl tree as if they were discovered in phase3.
978 irec
= set_inode_free_alloc(mp
, XFS_INO_TO_AGNO(mp
, ino
),
979 XFS_INO_TO_AGINO(mp
, ino
));
982 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++)
983 set_inode_free(irec
, i
);
986 ino_offset
= get_inode_offset(mp
, ino
, irec
);
989 * Mark the inode allocated to lost+found as used in the AVL tree
990 * so it is not skipped in phase 7
992 set_inode_used(irec
, ino_offset
);
993 add_inode_ref(irec
, ino_offset
);
996 * now that we know the transaction will stay around,
997 * add the root inode to it
999 libxfs_trans_ijoin(tp
, pip
, 0);
1002 * create the actual entry
1004 error
= -libxfs_dir_createname(tp
, pip
, &xname
, ip
->i_ino
, &first
,
1008 _("can't make %s, createname error %d\n"),
1012 * bump up the link count in the root directory to account
1013 * for .. in the new directory
1015 inc_nlink(VFS_I(pip
));
1016 add_inode_ref(find_inode_rec(mp
,
1017 XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
1018 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
)), 0);
1022 libxfs_trans_log_inode(tp
, pip
, XFS_ILOG_CORE
);
1023 libxfs_dir_init(tp
, ip
, pip
);
1024 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1026 libxfs_defer_ijoin(&dfops
, ip
);
1027 error
= -libxfs_defer_finish(&tp
, &dfops
);
1029 do_error(_("%s directory creation failed -- bmapf error %d\n"),
1034 libxfs_trans_commit(tp
);
1037 add_inode_reached(irec
,ino_offset
);
1043 * move a file to the orphange.
1048 xfs_ino_t ino
, /* inode # to be moved */
1049 int isa_dir
) /* 1 if inode is a directory */
1051 xfs_inode_t
*orphanage_ip
;
1052 xfs_ino_t entry_ino_num
;
1055 xfs_fsblock_t first
;
1056 struct xfs_defer_ops dfops
;
1058 unsigned char fname
[MAXPATHLEN
+ 1];
1061 ino_tree_node_t
*irec
;
1063 struct xfs_name xname
;
1066 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu",
1067 (unsigned long long)ino
);
1069 err
= -libxfs_iget(mp
, NULL
, orphanage_ino
, 0, &orphanage_ip
);
1071 do_error(_("%d - couldn't iget orphanage inode\n"), err
);
1073 * Make sure the filename is unique in the lost+found
1076 while (libxfs_dir_lookup(NULL
, orphanage_ip
, &xname
, &entry_ino_num
,
1078 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu.%d",
1079 (unsigned long long)ino
, ++incr
);
1081 if ((err
= -libxfs_iget(mp
, NULL
, ino
, 0, &ino_p
)))
1082 do_error(_("%d - couldn't iget disconnected inode\n"), err
);
1084 xname
.type
= xfs_mode_to_ftype(VFS_I(ino_p
)->i_mode
);
1087 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, orphanage_ino
),
1088 XFS_INO_TO_AGINO(mp
, orphanage_ino
));
1090 ino_offset
= XFS_INO_TO_AGINO(mp
, orphanage_ino
) -
1092 nres
= XFS_DIRENTER_SPACE_RES(mp
, fnamelen
) +
1093 XFS_DIRENTER_SPACE_RES(mp
, 2);
1094 err
= -libxfs_dir_lookup(NULL
, ino_p
, &xfs_name_dotdot
,
1095 &entry_ino_num
, NULL
);
1097 ASSERT(err
== ENOENT
);
1099 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1103 _("space reservation failed (%d), filesystem may be out of space\n"),
1106 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1107 libxfs_trans_ijoin(tp
, ino_p
, 0);
1109 libxfs_defer_init(&dfops
, &first
);
1110 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1111 ino
, &first
, &dfops
, nres
);
1114 _("name create failed in %s (%d), filesystem may be out of space\n"),
1118 add_inode_ref(irec
, ino_offset
);
1120 inc_nlink(VFS_I(orphanage_ip
));
1121 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1123 err
= -libxfs_dir_createname(tp
, ino_p
, &xfs_name_dotdot
,
1124 orphanage_ino
, &first
, &dfops
, nres
);
1127 _("creation of .. entry failed (%d), filesystem may be out of space\n"),
1130 inc_nlink(VFS_I(ino_p
));
1131 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1133 libxfs_defer_ijoin(&dfops
, ino_p
);
1134 err
= -libxfs_defer_finish(&tp
, &dfops
);
1137 _("bmap finish failed (err - %d), filesystem may be out of space\n"),
1140 libxfs_trans_commit(tp
);
1142 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1146 _("space reservation failed (%d), filesystem may be out of space\n"),
1149 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1150 libxfs_trans_ijoin(tp
, ino_p
, 0);
1152 libxfs_defer_init(&dfops
, &first
);
1154 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1155 ino
, &first
, &dfops
, nres
);
1158 _("name create failed in %s (%d), filesystem may be out of space\n"),
1162 add_inode_ref(irec
, ino_offset
);
1164 inc_nlink(VFS_I(orphanage_ip
));
1165 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1168 * don't replace .. value if it already points
1169 * to us. that'll pop a libxfs/kernel ASSERT.
1171 if (entry_ino_num
!= orphanage_ino
) {
1172 err
= -libxfs_dir_replace(tp
, ino_p
,
1173 &xfs_name_dotdot
, orphanage_ino
,
1174 &first
, &dfops
, nres
);
1177 _("name replace op failed (%d), filesystem may be out of space\n"),
1181 libxfs_defer_ijoin(&dfops
, ino_p
);
1182 err
= -libxfs_defer_finish(&tp
, &dfops
);
1185 _("bmap finish failed (%d), filesystem may be out of space\n"),
1188 libxfs_trans_commit(tp
);
1193 * use the remove log reservation as that's
1194 * more accurate. we're only creating the
1195 * links, we're not doing the inode allocation
1196 * also accounted for in the create
1198 nres
= XFS_DIRENTER_SPACE_RES(mp
, xname
.len
);
1199 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
1203 _("space reservation failed (%d), filesystem may be out of space\n"),
1206 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1207 libxfs_trans_ijoin(tp
, ino_p
, 0);
1209 libxfs_defer_init(&dfops
, &first
);
1210 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
, ino
,
1211 &first
, &dfops
, nres
);
1214 _("name create failed in %s (%d), filesystem may be out of space\n"),
1218 set_nlink(VFS_I(ino_p
), 1);
1219 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1221 libxfs_defer_ijoin(&dfops
, ino_p
);
1222 err
= -libxfs_defer_finish(&tp
, &dfops
);
1225 _("bmap finish failed (%d), filesystem may be out of space\n"),
1228 libxfs_trans_commit(tp
);
1231 IRELE(orphanage_ip
);
1241 do_warn(msg
, iname
, ino1
, ino2
);
1244 do_warn(_(", marking entry to be junked\n"));
1248 do_warn(_(", would junk entry\n"));
1253 * Unexpected failure during the rebuild will leave the entries in
1254 * lost+found on the next run
1258 longform_dir2_rebuild(
1262 ino_tree_node_t
*irec
,
1264 dir_hash_tab_t
*hashtab
)
1269 xfs_fileoff_t lastblock
;
1270 xfs_fsblock_t firstblock
;
1271 struct xfs_defer_ops dfops
;
1277 * trash directory completely and rebuild from scratch using the
1278 * name/inode pairs in the hash table
1281 do_warn(_("rebuilding directory inode %" PRIu64
"\n"), ino
);
1284 * first attempt to locate the parent inode, if it can't be
1285 * found, set it to the root inode and it'll be moved to the
1286 * orphanage later (the inode number here needs to be valid
1287 * for the libxfs_dir_init() call).
1289 pip
.i_ino
= get_inode_parent(irec
, ino_offset
);
1290 if (pip
.i_ino
== NULLFSINO
||
1291 libxfs_dir_ino_validate(mp
, pip
.i_ino
))
1292 pip
.i_ino
= mp
->m_sb
.sb_rootino
;
1294 libxfs_defer_init(&dfops
, &firstblock
);
1296 nres
= XFS_REMOVE_SPACE_RES(mp
);
1297 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1300 libxfs_trans_ijoin(tp
, ip
, 0);
1302 if ((error
= -libxfs_bmap_last_offset(ip
, &lastblock
, XFS_DATA_FORK
)))
1303 do_error(_("xfs_bmap_last_offset failed -- error - %d\n"),
1306 /* free all data, leaf, node and freespace blocks */
1307 error
= -libxfs_bunmapi(tp
, ip
, 0, lastblock
, XFS_BMAPI_METADATA
, 0,
1308 &firstblock
, &dfops
, &done
);
1310 do_warn(_("xfs_bunmapi failed -- error - %d\n"), error
);
1311 goto out_bmap_cancel
;
1316 error
= -libxfs_dir_init(tp
, ip
, &pip
);
1318 do_warn(_("xfs_dir_init failed -- error - %d\n"), error
);
1319 goto out_bmap_cancel
;
1322 libxfs_defer_ijoin(&dfops
, ip
);
1323 error
= -libxfs_defer_finish(&tp
, &dfops
);
1325 libxfs_trans_commit(tp
);
1327 if (ino
== mp
->m_sb
.sb_rootino
)
1328 need_root_dotdot
= 0;
1330 /* go through the hash list and re-add the inodes */
1332 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
1334 if (p
->name
.name
[0] == '/' || (p
->name
.name
[0] == '.' &&
1335 (p
->name
.len
== 1 || (p
->name
.len
== 2 &&
1336 p
->name
.name
[1] == '.'))))
1339 nres
= XFS_CREATE_SPACE_RES(mp
, p
->name
.len
);
1340 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_create
,
1345 libxfs_trans_ijoin(tp
, ip
, 0);
1347 libxfs_defer_init(&dfops
, &firstblock
);
1348 error
= -libxfs_dir_createname(tp
, ip
, &p
->name
, p
->inum
,
1349 &firstblock
, &dfops
, nres
);
1352 _("name create failed in ino %" PRIu64
" (%d), filesystem may be out of space\n"),
1354 goto out_bmap_cancel
;
1357 libxfs_defer_ijoin(&dfops
, ip
);
1358 error
= -libxfs_defer_finish(&tp
, &dfops
);
1361 _("bmap finish failed (%d), filesystem may be out of space\n"),
1363 goto out_bmap_cancel
;
1366 libxfs_trans_commit(tp
);
1372 libxfs_defer_cancel(&dfops
);
1373 libxfs_trans_cancel(tp
);
1379 * Kill a block in a version 2 inode.
1380 * Makes its own transaction.
1391 xfs_fsblock_t firstblock
;
1392 struct xfs_defer_ops dfops
;
1396 nres
= XFS_REMOVE_SPACE_RES(mp
);
1397 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1400 libxfs_trans_ijoin(tp
, ip
, 0);
1401 libxfs_trans_bjoin(tp
, bp
);
1402 memset(&args
, 0, sizeof(args
));
1403 libxfs_defer_init(&dfops
, &firstblock
);
1406 args
.firstblock
= &firstblock
;
1407 args
.dfops
= &dfops
;
1408 args
.whichfork
= XFS_DATA_FORK
;
1409 args
.geo
= mp
->m_dir_geo
;
1410 if (da_bno
>= mp
->m_dir_geo
->leafblk
&& da_bno
< mp
->m_dir_geo
->freeblk
)
1411 error
= -libxfs_da_shrink_inode(&args
, da_bno
, bp
);
1413 error
= -libxfs_dir2_shrink_inode(&args
,
1414 xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
), bp
);
1416 do_error(_("shrink_inode failed inode %" PRIu64
" block %u\n"),
1418 libxfs_defer_ijoin(&dfops
, ip
);
1419 libxfs_defer_finish(&tp
, &dfops
);
1420 libxfs_trans_commit(tp
);
1424 * process a data block, also checks for .. entry
1425 * and corrects it to match what we think .. should be
1428 longform_dir2_entry_check_data(
1433 ino_tree_node_t
*current_irec
,
1434 int current_ino_offset
,
1435 struct xfs_buf
**bpp
,
1436 dir_hash_tab_t
*hashtab
,
1437 freetab_t
**freetabp
,
1441 xfs_dir2_dataptr_t addr
;
1442 xfs_dir2_leaf_entry_t
*blp
;
1444 xfs_dir2_block_tail_t
*btp
;
1445 struct xfs_dir2_data_hdr
*d
;
1447 xfs_dir2_data_entry_t
*dep
;
1448 xfs_dir2_data_unused_t
*dup
;
1449 struct xfs_dir2_data_free
*bf
;
1452 xfs_fsblock_t firstblock
;
1453 struct xfs_defer_ops dfops
;
1454 char fname
[MAXNAMELEN
+ 1];
1459 ino_tree_node_t
*irec
;
1470 struct xfs_da_args da
= {
1472 .geo
= mp
->m_dir_geo
,
1478 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1480 needscan
= needlog
= 0;
1482 freetab
= *freetabp
;
1484 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, d
);
1485 blp
= xfs_dir2_block_leaf_p(btp
);
1486 endptr
= (char *)blp
;
1487 if (endptr
> (char *)btp
)
1488 endptr
= (char *)btp
;
1489 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1490 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1492 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1494 endptr
= (char *)d
+ mp
->m_dir_geo
->blksize
;
1495 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1496 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1498 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1500 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
1502 /* check for data block beyond expected end */
1503 if (freetab
->naents
<= db
) {
1504 struct freetab_ent e
;
1506 *freetabp
= freetab
= realloc(freetab
, FREETAB_SIZE(db
+ 1));
1508 do_error(_("realloc failed in %s (%zu bytes)\n"),
1509 __func__
, FREETAB_SIZE(db
+ 1));
1513 for (i
= freetab
->naents
; i
< db
; i
++)
1514 freetab
->ents
[i
] = e
;
1515 freetab
->naents
= db
+ 1;
1518 /* check the data block */
1519 while (ptr
< endptr
) {
1521 /* check for freespace */
1522 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1523 if (XFS_DIR2_DATA_FREE_TAG
== be16_to_cpu(dup
->freetag
)) {
1525 /* check for invalid freespace length */
1526 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1527 be16_to_cpu(dup
->length
) == 0 ||
1528 (be16_to_cpu(dup
->length
) &
1529 (XFS_DIR2_DATA_ALIGN
- 1)))
1532 /* check for invalid tag */
1533 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1534 (char *)dup
- (char *)d
)
1537 /* check for block with no data entries */
1538 if ((ptr
== (char *)M_DIROPS(mp
)->data_entry_p(d
)) &&
1539 (ptr
+ be16_to_cpu(dup
->length
) >= endptr
)) {
1545 /* continue at the end of the freespace */
1546 ptr
+= be16_to_cpu(dup
->length
);
1551 /* validate data entry size */
1552 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1553 if (ptr
+ M_DIROPS(mp
)->data_entsize(dep
->namelen
) > endptr
)
1555 if (be16_to_cpu(*M_DIROPS(mp
)->data_entry_tag_p(dep
)) !=
1556 (char *)dep
- (char *)d
)
1558 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1561 /* did we find an empty or corrupt block? */
1562 if (ptr
!= endptr
) {
1565 _("empty data block %u in directory inode %" PRIu64
": "),
1569 ("corrupt block %u in directory inode %" PRIu64
": "),
1573 do_warn(_("junking block\n"));
1574 dir2_kill_block(mp
, ip
, da_bno
, bp
);
1576 do_warn(_("would junk block\n"));
1579 freetab
->ents
[db
].v
= NULLDATAOFF
;
1584 /* update number of data blocks processed */
1585 if (freetab
->nents
< db
+ 1)
1586 freetab
->nents
= db
+ 1;
1588 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, 0, 0, 0, &tp
);
1592 libxfs_trans_ijoin(tp
, ip
, 0);
1593 libxfs_trans_bjoin(tp
, bp
);
1594 libxfs_trans_bhold(tp
, bp
);
1595 libxfs_defer_init(&dfops
, &firstblock
);
1596 if (be32_to_cpu(d
->magic
) != wantmagic
) {
1598 _("bad directory block magic # %#x for directory inode %" PRIu64
" block %d: "),
1599 be32_to_cpu(d
->magic
), ip
->i_ino
, da_bno
);
1601 do_warn(_("fixing magic # to %#x\n"), wantmagic
);
1602 d
->magic
= cpu_to_be32(wantmagic
);
1605 do_warn(_("would fix magic # to %#x\n"), wantmagic
);
1608 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1610 * look at each entry. reference inode pointed to by each
1611 * entry in the incore inode tree.
1612 * if not a directory, set reached flag, increment link count
1613 * if a directory and reached, mark entry as to be deleted.
1614 * if a directory, check to see if recorded parent
1615 * matches current inode #,
1616 * if so, then set reached flag, increment link count
1617 * of current and child dir inodes, push the child
1618 * directory inode onto the directory stack.
1619 * if current inode != parent, then mark entry to be deleted.
1621 while (ptr
< endptr
) {
1622 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1623 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1626 _("directory inode %" PRIu64
" block %u has consecutive free entries: "),
1630 do_warn(_("joining together\n"));
1631 len
= be16_to_cpu(dup
->length
);
1632 libxfs_dir2_data_use_free(&da
, bp
, dup
,
1633 ptr
- (char *)d
, len
, &needlog
,
1635 libxfs_dir2_data_make_free(&da
, bp
,
1636 ptr
- (char *)d
, len
, &needlog
,
1639 do_warn(_("would join together\n"));
1641 ptr
+= be16_to_cpu(dup
->length
);
1645 addr
= xfs_dir2_db_off_to_dataptr(mp
->m_dir_geo
, db
,
1647 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1648 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1649 inum
= be64_to_cpu(dep
->inumber
);
1652 * skip bogus entries (leading '/'). they'll be deleted
1653 * later. must still log it, else we leak references to
1656 if (dep
->name
[0] == '/') {
1659 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1663 memmove(fname
, dep
->name
, dep
->namelen
);
1664 fname
[dep
->namelen
] = '\0';
1665 ASSERT(inum
!= NULLFSINO
);
1667 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, inum
),
1668 XFS_INO_TO_AGINO(mp
, inum
));
1672 _("entry \"%s\" in directory inode %" PRIu64
" points to non-existent inode %" PRIu64
""),
1673 fname
, ip
->i_ino
, inum
)) {
1675 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1679 ino_offset
= XFS_INO_TO_AGINO(mp
, inum
) - irec
->ino_startnum
;
1682 * if it's a free inode, blow out the entry.
1683 * by now, any inode that we think is free
1686 if (is_inode_free(irec
, ino_offset
)) {
1689 _("entry \"%s\" in directory inode %" PRIu64
" points to free inode %" PRIu64
),
1690 fname
, ip
->i_ino
, inum
)) {
1692 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1698 * check if this inode is lost+found dir in the root
1700 if (inum
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
1702 * if it's not a directory, trash it
1704 if (!inode_isadir(irec
, ino_offset
)) {
1707 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
1708 ORPHANAGE
, inum
, ip
->i_ino
)) {
1710 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1715 * if this is a dup, it will be picked up below,
1716 * otherwise, mark it as the orphanage for later.
1719 orphanage_ino
= inum
;
1723 * check for duplicate names in directory.
1725 if (!dir_hash_add(mp
, hashtab
, addr
, inum
, dep
->namelen
,
1726 dep
->name
, M_DIROPS(mp
)->data_get_ftype(dep
))) {
1729 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
1730 fname
, inum
, ip
->i_ino
)) {
1732 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1734 if (inum
== orphanage_ino
)
1740 * if just scanning to rebuild a directory due to a ".."
1741 * update, just continue
1747 * skip the '..' entry since it's checked when the
1748 * directory is reached by something else. if it never
1749 * gets reached, it'll be moved to the orphanage and we'll
1750 * take care of it then. If it doesn't exist at all, the
1751 * directory needs to be rebuilt first before being added
1754 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
1755 dep
->name
[1] == '.') {
1757 /* ".." should be in the first block */
1760 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is not in the the first block"), fname
,
1763 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1768 ASSERT(no_modify
|| !verify_inum(mp
, inum
));
1770 * special case the . entry. we know there's only one
1771 * '.' and only '.' points to itself because bogus entries
1772 * got trashed in phase 3 if there were > 1.
1773 * bump up link count for '.' but don't set reached
1774 * until we're actually reached by another directory
1775 * '..' is already accounted for or will be taken care
1776 * of when directory is moved to orphanage.
1778 if (ip
->i_ino
== inum
) {
1779 ASSERT(dep
->name
[0] == '.' && dep
->namelen
== 1);
1780 add_inode_ref(current_irec
, current_ino_offset
);
1782 dep
!= M_DIROPS(mp
)->data_entry_p(d
)) {
1783 /* "." should be the first entry */
1786 _("entry \"%s\" in dir %" PRIu64
" is not the first entry"),
1787 fname
, inum
, ip
->i_ino
)) {
1789 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1796 * skip entries with bogus inumbers if we're in no modify mode
1798 if (no_modify
&& verify_inum(mp
, inum
))
1801 /* validate ftype field if supported */
1802 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
1806 dir_ftype
= M_DIROPS(mp
)->data_get_ftype(dep
);
1807 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
1809 if (dir_ftype
!= ino_ftype
) {
1812 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1813 dir_ftype
, ino_ftype
,
1817 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1818 dir_ftype
, ino_ftype
,
1820 M_DIROPS(mp
)->data_put_ftype(dep
,
1822 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1823 dir_hash_update_ftype(hashtab
, addr
,
1830 * check easy case first, regular inode, just bump
1831 * the link count and continue
1833 if (!inode_isadir(irec
, ino_offset
)) {
1834 add_inode_reached(irec
, ino_offset
);
1837 parent
= get_inode_parent(irec
, ino_offset
);
1838 ASSERT(parent
!= 0);
1841 * bump up the link counts in parent and child
1842 * directory but if the link doesn't agree with
1843 * the .. in the child, blow out the entry.
1844 * if the directory has already been reached,
1845 * blow away the entry also.
1847 if (is_inode_reached(irec
, ino_offset
)) {
1850 _("entry \"%s\" in dir %" PRIu64
" points to an already connected directory inode %" PRIu64
"\n"),
1851 fname
, ip
->i_ino
, inum
);
1852 } else if (parent
== ip
->i_ino
) {
1853 add_inode_reached(irec
, ino_offset
);
1854 add_inode_ref(current_irec
, current_ino_offset
);
1855 } else if (parent
== NULLFSINO
) {
1856 /* ".." was missing, but this entry refers to it,
1857 so, set it as the parent and mark for rebuild */
1859 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
1860 fname
, ip
->i_ino
, inum
);
1861 set_inode_parent(irec
, ino_offset
, ip
->i_ino
);
1862 add_inode_reached(irec
, ino_offset
);
1863 add_inode_ref(current_irec
, current_ino_offset
);
1864 add_dotdot_update(XFS_INO_TO_AGNO(mp
, inum
), irec
,
1869 _("entry \"%s\" in dir inode %" PRIu64
" inconsistent with .. value (%" PRIu64
") in ino %" PRIu64
"\n"),
1870 fname
, ip
->i_ino
, parent
, inum
);
1873 if (inum
== orphanage_ino
)
1878 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1881 _("\twill clear entry \"%s\"\n"),
1884 do_warn(_("\twould clear entry \"%s\"\n"),
1889 *num_illegal
+= nbad
;
1891 libxfs_dir2_data_freescan_int(mp
->m_dir_geo
, M_DIROPS(mp
),
1894 libxfs_dir2_data_log_header(&da
, bp
);
1895 libxfs_defer_ijoin(&dfops
, ip
);
1896 libxfs_defer_finish(&tp
, &dfops
);
1897 libxfs_trans_commit(tp
);
1899 /* record the largest free space in the freetab for later checking */
1900 bf
= M_DIROPS(mp
)->data_bestfree_p(d
);
1901 freetab
->ents
[db
].v
= be16_to_cpu(bf
[0].length
);
1902 freetab
->ents
[db
].s
= 0;
1905 /* check v5 metadata */
1907 __check_dir3_header(
1908 struct xfs_mount
*mp
,
1917 if (be64_to_cpu(owner
) != ino
) {
1919 _("expected owner inode %" PRIu64
", got %llu, directory block %" PRIu64
"\n"),
1920 ino
, (unsigned long long)be64_to_cpu(owner
), bp
->b_bn
);
1923 /* verify block number */
1924 if (be64_to_cpu(blkno
) != bp
->b_bn
) {
1926 _("expected block %" PRIu64
", got %llu, directory inode %" PRIu64
"\n"),
1927 bp
->b_bn
, (unsigned long long)be64_to_cpu(blkno
), ino
);
1931 if (platform_uuid_compare(uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
1933 _("wrong FS UUID, directory inode %" PRIu64
" block %" PRIu64
"\n"),
1943 struct xfs_mount
*mp
,
1947 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
1949 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
1955 struct xfs_mount
*mp
,
1959 struct xfs_dir3_blk_hdr
*info
= bp
->b_addr
;
1961 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
1966 * Check contents of leaf-form block.
1969 longform_dir2_check_leaf(
1972 dir_hash_tab_t
*hashtab
,
1980 xfs_dir2_leaf_t
*leaf
;
1981 xfs_dir2_leaf_tail_t
*ltp
;
1983 struct xfs_dir2_leaf_entry
*ents
;
1984 struct xfs_dir3_icleaf_hdr leafhdr
;
1988 da_bno
= mp
->m_dir_geo
->leafblk
;
1989 error
= dir_read_buf(ip
, da_bno
, -1, &bp
, &xfs_dir3_leaf1_buf_ops
,
1991 if (error
== EFSBADCRC
|| error
== EFSCORRUPTED
|| fixit
) {
1993 _("leaf block %u for directory inode %" PRIu64
" bad CRC\n"),
1998 _("can't read block %u for directory inode %" PRIu64
", error %d\n"),
1999 da_bno
, ip
->i_ino
, error
);
2004 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2005 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2006 ltp
= xfs_dir2_leaf_tail_p(mp
->m_dir_geo
, leaf
);
2007 bestsp
= xfs_dir2_leaf_bests_p(ltp
);
2008 if (!(leafhdr
.magic
== XFS_DIR2_LEAF1_MAGIC
||
2009 leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) ||
2010 leafhdr
.forw
|| leafhdr
.back
||
2011 leafhdr
.count
< leafhdr
.stale
||
2013 M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2014 (char *)&ents
[leafhdr
.count
] > (char *)bestsp
) {
2016 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2022 if (leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) {
2023 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2030 seeval
= dir_hash_see_all(hashtab
, ents
, leafhdr
.count
, leafhdr
.stale
);
2031 if (dir_hash_check(hashtab
, ip
, seeval
)) {
2035 badtail
= freetab
->nents
!= be32_to_cpu(ltp
->bestcount
);
2036 for (i
= 0; !badtail
&& i
< be32_to_cpu(ltp
->bestcount
); i
++) {
2037 freetab
->ents
[i
].s
= 1;
2038 badtail
= freetab
->ents
[i
].v
!= be16_to_cpu(bestsp
[i
]);
2042 _("leaf block %u for directory inode %" PRIu64
" bad tail\n"),
2052 * Check contents of the node blocks (leaves)
2053 * Looks for matching hash values for the data entries.
2056 longform_dir2_check_node(
2059 dir_hash_tab_t
*hashtab
,
2065 xfs_dir2_free_t
*free
;
2067 xfs_dir2_leaf_t
*leaf
;
2068 xfs_fileoff_t next_da_bno
;
2071 struct xfs_dir2_leaf_entry
*ents
;
2072 struct xfs_dir3_icleaf_hdr leafhdr
;
2073 struct xfs_dir3_icfree_hdr freehdr
;
2078 for (da_bno
= mp
->m_dir_geo
->leafblk
, next_da_bno
= 0;
2079 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->freeblk
;
2080 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2081 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2082 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2086 * we need to use the da3 node verifier here as it handles the
2087 * fact that reading the leaf hash tree blocks can return either
2088 * leaf or node blocks and calls the correct verifier. If we get
2089 * a node block, then we'll skip it below based on a magic
2092 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2093 &xfs_da3_node_buf_ops
, &fixit
);
2096 _("can't read leaf block %u for directory inode %" PRIu64
", error %d\n"),
2097 da_bno
, ip
->i_ino
, error
);
2101 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2102 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2103 if (!(leafhdr
.magic
== XFS_DIR2_LEAFN_MAGIC
||
2104 leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2105 leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2106 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
)) {
2108 _("unknown magic number %#x for block %u in directory inode %" PRIu64
"\n"),
2109 leafhdr
.magic
, da_bno
, ip
->i_ino
);
2114 /* check v5 metadata */
2115 if (leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2116 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2117 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2125 if (leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2126 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2132 * If there's a validator error, we need to ensure that we got
2133 * the right ops on the buffer for when we write it back out.
2135 bp
->b_ops
= &xfs_dir3_leafn_buf_ops
;
2136 if (leafhdr
.count
> M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2137 leafhdr
.count
< leafhdr
.stale
) {
2139 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2144 seeval
= dir_hash_see_all(hashtab
, ents
,
2145 leafhdr
.count
, leafhdr
.stale
);
2147 if (seeval
!= DIR_HASH_CK_OK
)
2150 if (dir_hash_check(hashtab
, ip
, seeval
))
2153 for (da_bno
= mp
->m_dir_geo
->freeblk
, next_da_bno
= 0;
2154 next_da_bno
!= NULLFILEOFF
;
2155 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2156 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2157 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2160 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2161 &xfs_dir3_free_buf_ops
, &fixit
);
2164 _("can't read freespace block %u for directory inode %" PRIu64
", error %d\n"),
2165 da_bno
, ip
->i_ino
, error
);
2169 M_DIROPS(mp
)->free_hdr_from_disk(&freehdr
, free
);
2170 bests
= M_DIROPS(mp
)->free_bests_p(free
);
2171 fdb
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2172 if (!(freehdr
.magic
== XFS_DIR2_FREE_MAGIC
||
2173 freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) ||
2175 (fdb
- xfs_dir2_byte_to_db(mp
->m_dir_geo
, XFS_DIR2_FREE_OFFSET
)) *
2176 M_DIROPS(mp
)->free_max_bests(mp
->m_dir_geo
) ||
2177 freehdr
.nvalid
< freehdr
.nused
) {
2179 _("free block %u for directory inode %" PRIu64
" bad header\n"),
2185 if (freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) {
2186 error
= check_dir3_header(mp
, bp
, ip
->i_ino
);
2192 for (i
= used
= 0; i
< freehdr
.nvalid
; i
++) {
2193 if (i
+ freehdr
.firstdb
>= freetab
->nents
||
2194 freetab
->ents
[i
+ freehdr
.firstdb
].v
!=
2195 be16_to_cpu(bests
[i
])) {
2197 _("free block %u entry %i for directory ino %" PRIu64
" bad\n"),
2198 da_bno
, i
, ip
->i_ino
);
2202 used
+= be16_to_cpu(bests
[i
]) != NULLDATAOFF
;
2203 freetab
->ents
[i
+ freehdr
.firstdb
].s
= 1;
2205 if (used
!= freehdr
.nused
) {
2207 _("free block %u for directory inode %" PRIu64
" bad nused\n"),
2214 for (i
= 0; i
< freetab
->nents
; i
++) {
2215 if ((freetab
->ents
[i
].s
== 0) &&
2216 (freetab
->ents
[i
].v
!= NULLDATAOFF
)) {
2218 _("missing freetab entry %u for directory inode %" PRIu64
"\n"),
2227 * If a directory is corrupt, we need to read in as many entries as possible,
2228 * destroy the entry and create a new one with recovered name/inode pairs.
2229 * (ie. get libxfs to do all the grunt work)
2232 longform_dir2_entry_check(xfs_mount_t
*mp
,
2237 ino_tree_node_t
*irec
,
2239 dir_hash_tab_t
*hashtab
)
2241 struct xfs_buf
**bplist
;
2248 xfs_fileoff_t next_da_bno
;
2252 struct xfs_da_args args
;
2255 freetab
= malloc(FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2257 do_error(_("malloc failed in %s (%" PRId64
" bytes)\n"),
2259 FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2262 freetab
->naents
= ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
;
2264 for (i
= 0; i
< freetab
->naents
; i
++) {
2265 freetab
->ents
[i
].v
= NULLDATAOFF
;
2266 freetab
->ents
[i
].s
= 0;
2268 num_bps
= freetab
->naents
;
2269 bplist
= calloc(num_bps
, sizeof(struct xfs_buf
*));
2271 do_error(_("calloc failed in %s (%zu bytes)\n"),
2272 __func__
, num_bps
* sizeof(struct xfs_buf
*));
2274 /* is this a block, leaf, or node directory? */
2276 args
.geo
= mp
->m_dir_geo
;
2277 libxfs_dir2_isblock(&args
, &isblock
);
2278 libxfs_dir2_isleaf(&args
, &isleaf
);
2280 /* check directory "data" blocks (ie. name/inode pairs) */
2281 for (da_bno
= 0, next_da_bno
= 0;
2282 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->leafblk
;
2283 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2284 const struct xfs_buf_ops
*ops
;
2286 struct xfs_dir2_data_hdr
*d
;
2288 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2289 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
)) {
2291 * if this is the first block, there isn't anything we
2292 * can recover so we just trash it.
2301 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2302 if (db
>= num_bps
) {
2303 /* more data blocks than expected */
2305 bplist
= realloc(bplist
, num_bps
* sizeof(struct xfs_buf
*));
2307 do_error(_("realloc failed in %s (%zu bytes)\n"),
2309 num_bps
* sizeof(struct xfs_buf
*));
2313 ops
= &xfs_dir3_block_buf_ops
;
2315 ops
= &xfs_dir3_data_buf_ops
;
2317 error
= dir_read_buf(ip
, da_bno
, -1, &bplist
[db
], ops
, &fixit
);
2320 _("can't read data block %u for directory inode %" PRIu64
" error %d\n"),
2321 da_bno
, ino
, error
);
2325 * we try to read all "data" blocks, but if we are in
2326 * block form and we fail, there isn't anything else to
2327 * read, and nothing we can do but trash it.
2336 /* check v5 metadata */
2337 d
= bplist
[db
]->b_addr
;
2338 if (be32_to_cpu(d
->magic
) == XFS_DIR3_BLOCK_MAGIC
||
2339 be32_to_cpu(d
->magic
) == XFS_DIR3_DATA_MAGIC
) {
2340 struct xfs_buf
*bp
= bplist
[db
];
2342 error
= check_dir3_header(mp
, bp
, ino
);
2349 longform_dir2_entry_check_data(mp
, ip
, num_illegal
, need_dot
,
2350 irec
, ino_offset
, &bplist
[db
], hashtab
,
2351 &freetab
, da_bno
, isblock
);
2353 fixit
|= (*num_illegal
!= 0) || dir2_is_badino(ino
) || *need_dot
;
2355 if (!dotdot_update
) {
2356 /* check btree and freespace */
2358 struct xfs_dir2_data_hdr
*block
;
2359 xfs_dir2_block_tail_t
*btp
;
2360 xfs_dir2_leaf_entry_t
*blp
;
2362 block
= bplist
[0]->b_addr
;
2363 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, block
);
2364 blp
= xfs_dir2_block_leaf_p(btp
);
2365 seeval
= dir_hash_see_all(hashtab
, blp
,
2366 be32_to_cpu(btp
->count
),
2367 be32_to_cpu(btp
->stale
));
2368 if (dir_hash_check(hashtab
, ip
, seeval
))
2370 } else if (isleaf
) {
2371 fixit
|= longform_dir2_check_leaf(mp
, ip
, hashtab
,
2374 fixit
|= longform_dir2_check_node(mp
, ip
, hashtab
,
2379 if (!no_modify
&& (fixit
|| dotdot_update
)) {
2380 dir_hash_dup_names(hashtab
);
2381 for (i
= 0; i
< num_bps
; i
++)
2383 libxfs_putbuf(bplist
[i
]);
2384 longform_dir2_rebuild(mp
, ino
, ip
, irec
, ino_offset
, hashtab
);
2388 for (i
= 0; i
< num_bps
; i
++)
2390 libxfs_putbuf(bplist
[i
]);
2398 * shortform directory v2 processing routines -- entry verification and
2399 * bad entry deletion (pruning).
2401 static struct xfs_dir2_sf_entry
*
2402 shortform_dir2_junk(
2403 struct xfs_mount
*mp
,
2404 struct xfs_dir2_sf_hdr
*sfp
,
2405 struct xfs_dir2_sf_entry
*sfep
,
2412 struct xfs_dir2_sf_entry
*next_sfep
;
2416 if (lino
== orphanage_ino
)
2419 next_elen
= M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
);
2420 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2423 * if we are just checking, simply return the pointer to the next entry
2424 * here so that the checking loop can continue.
2427 do_warn(_("would junk entry\n"));
2432 * now move all the remaining entries down over the junked entry and
2433 * clear the newly unused bytes at the tail of the directory region.
2435 next_len
= *max_size
- ((intptr_t)next_sfep
- (intptr_t)sfp
);
2436 *max_size
-= next_elen
;
2437 *bytes_deleted
+= next_elen
;
2439 memmove(sfep
, next_sfep
, next_len
);
2440 memset((void *)((intptr_t)sfep
+ next_len
), 0, next_elen
);
2445 * WARNING: drop the index i by one so it matches the decremented count
2446 * for accurate comparisons in the loop test
2451 do_warn(_("junking entry\n"));
2458 shortform_dir2_entry_check(xfs_mount_t
*mp
,
2462 ino_tree_node_t
*current_irec
,
2463 int current_ino_offset
,
2464 dir_hash_tab_t
*hashtab
)
2468 struct xfs_dir2_sf_hdr
*sfp
;
2469 struct xfs_dir2_sf_entry
*sfep
;
2470 struct xfs_dir2_sf_entry
*next_sfep
;
2471 struct xfs_ifork
*ifp
;
2472 struct ino_tree_node
*irec
;
2479 char fname
[MAXNAMELEN
+ 1];
2483 sfp
= (struct xfs_dir2_sf_hdr
*) ifp
->if_u1
.if_data
;
2487 max_size
= ifp
->if_bytes
;
2488 ASSERT(ip
->i_d
.di_size
<= ifp
->if_bytes
);
2491 * if just rebuild a directory due to a "..", update and return
2493 if (dotdot_update
) {
2494 parent
= get_inode_parent(current_irec
, current_ino_offset
);
2497 _("would set .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2501 _("setting .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2503 M_DIROPS(mp
)->sf_put_parent_ino(sfp
, parent
);
2510 * no '.' entry in shortform dirs, just bump up ref count by 1
2511 * '..' was already (or will be) accounted for and checked when
2512 * the directory is reached or will be taken care of when the
2513 * directory is moved to orphanage.
2515 add_inode_ref(current_irec
, current_ino_offset
);
2518 * Initialise i8 counter -- the parent inode number counts as well.
2520 i8
= M_DIROPS(mp
)->sf_get_parent_ino(sfp
) > XFS_DIR2_MAX_SHORT_INUM
;
2523 * now run through entries, stop at first bad entry, don't need
2524 * to skip over '..' since that's encoded in its own field and
2525 * no need to worry about '.' since it doesn't exist.
2527 sfep
= next_sfep
= xfs_dir2_sf_firstentry(sfp
);
2529 for (i
= 0; i
< sfp
->count
&& max_size
>
2530 (intptr_t)next_sfep
- (intptr_t)sfp
;
2531 sfep
= next_sfep
, i
++) {
2534 lino
= M_DIROPS(mp
)->sf_get_ino(sfp
, sfep
);
2536 namelen
= sfep
->namelen
;
2538 ASSERT(no_modify
|| namelen
> 0);
2540 if (no_modify
&& namelen
== 0) {
2542 * if we're really lucky, this is
2543 * the last entry in which case we
2544 * can use the dir size to set the
2545 * namelen value. otherwise, forget
2546 * it because we're not going to be
2547 * able to find the next entry.
2551 if (i
== sfp
->count
- 1) {
2552 namelen
= ip
->i_d
.di_size
-
2553 ((intptr_t) &sfep
->name
[0] -
2557 * don't process the rest of the directory,
2558 * break out of processing loop
2562 } else if (no_modify
&& (intptr_t) sfep
- (intptr_t) sfp
+
2563 + M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)
2564 > ip
->i_d
.di_size
) {
2567 if (i
== sfp
->count
- 1) {
2568 namelen
= ip
->i_d
.di_size
-
2569 ((intptr_t) &sfep
->name
[0] -
2573 * don't process the rest of the directory,
2574 * break out of processing loop
2580 memmove(fname
, sfep
->name
, sfep
->namelen
);
2581 fname
[sfep
->namelen
] = '\0';
2583 ASSERT(no_modify
|| (lino
!= NULLFSINO
&& lino
!= 0));
2584 ASSERT(no_modify
|| !verify_inum(mp
, lino
));
2587 * Also skip entries with bogus inode numbers if we're
2588 * in no modify mode.
2591 if (no_modify
&& verify_inum(mp
, lino
)) {
2592 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2596 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, lino
),
2597 XFS_INO_TO_AGINO(mp
, lino
));
2601 _("entry \"%s\" in shortform directory %" PRIu64
" references non-existent inode %" PRIu64
"\n"),
2603 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2604 &max_size
, &i
, &bytes_deleted
,
2609 ino_offset
= XFS_INO_TO_AGINO(mp
, lino
) - irec
->ino_startnum
;
2612 * if it's a free inode, blow out the entry.
2613 * by now, any inode that we think is free
2616 if (is_inode_free(irec
, ino_offset
)) {
2618 _("entry \"%s\" in shortform directory inode %" PRIu64
" points to free inode %" PRIu64
"\n"),
2620 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2621 &max_size
, &i
, &bytes_deleted
,
2626 * check if this inode is lost+found dir in the root
2628 if (ino
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
2630 * if it's not a directory, trash it
2632 if (!inode_isadir(irec
, ino_offset
)) {
2634 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
2635 ORPHANAGE
, lino
, ino
);
2636 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2637 lino
, &max_size
, &i
,
2638 &bytes_deleted
, ino_dirty
);
2642 * if this is a dup, it will be picked up below,
2643 * otherwise, mark it as the orphanage for later.
2646 orphanage_ino
= lino
;
2649 * check for duplicate names in directory.
2651 if (!dir_hash_add(mp
, hashtab
, (xfs_dir2_dataptr_t
)
2652 (sfep
- xfs_dir2_sf_firstentry(sfp
)),
2653 lino
, sfep
->namelen
, sfep
->name
,
2654 M_DIROPS(mp
)->sf_get_ftype(sfep
))) {
2656 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
2658 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2659 &max_size
, &i
, &bytes_deleted
,
2664 if (!inode_isadir(irec
, ino_offset
)) {
2666 * check easy case first, regular inode, just bump
2669 add_inode_reached(irec
, ino_offset
);
2671 parent
= get_inode_parent(irec
, ino_offset
);
2674 * bump up the link counts in parent and child.
2675 * directory but if the link doesn't agree with
2676 * the .. in the child, blow out the entry
2678 if (is_inode_reached(irec
, ino_offset
)) {
2680 _("entry \"%s\" in directory inode %" PRIu64
2681 " references already connected inode %" PRIu64
".\n"),
2683 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2684 lino
, &max_size
, &i
,
2685 &bytes_deleted
, ino_dirty
);
2687 } else if (parent
== ino
) {
2688 add_inode_reached(irec
, ino_offset
);
2689 add_inode_ref(current_irec
, current_ino_offset
);
2690 } else if (parent
== NULLFSINO
) {
2691 /* ".." was missing, but this entry refers to it,
2692 so, set it as the parent and mark for rebuild */
2694 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
2696 set_inode_parent(irec
, ino_offset
, ino
);
2697 add_inode_reached(irec
, ino_offset
);
2698 add_inode_ref(current_irec
, current_ino_offset
);
2699 add_dotdot_update(XFS_INO_TO_AGNO(mp
, lino
),
2703 _("entry \"%s\" in directory inode %" PRIu64
2704 " not consistent with .. value (%" PRIu64
2705 ") in inode %" PRIu64
",\n"),
2706 fname
, ino
, parent
, lino
);
2707 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2708 lino
, &max_size
, &i
,
2709 &bytes_deleted
, ino_dirty
);
2714 /* validate ftype field if supported */
2715 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
2719 dir_ftype
= M_DIROPS(mp
)->sf_get_ftype(sfep
);
2720 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
2722 if (dir_ftype
!= ino_ftype
) {
2725 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2726 dir_ftype
, ino_ftype
,
2730 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2731 dir_ftype
, ino_ftype
,
2733 M_DIROPS(mp
)->sf_put_ftype(sfep
,
2735 dir_hash_update_ftype(hashtab
,
2736 (xfs_dir2_dataptr_t
)(sfep
- xfs_dir2_sf_firstentry(sfp
)),
2743 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
2747 * go onto next entry - we have to take entries with bad namelen
2748 * into account in no modify mode since we calculate size based
2751 ASSERT(no_modify
|| bad_sfnamelen
== 0);
2752 next_sfep
= (struct xfs_dir2_sf_entry
*)((intptr_t)sfep
+
2754 ? M_DIROPS(mp
)->sf_entsize(sfp
, namelen
)
2755 : M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)));
2758 if (sfp
->i8count
!= i8
) {
2760 do_warn(_("would fix i8count in inode %" PRIu64
"\n"),
2764 struct xfs_dir2_sf_entry
*tmp_sfep
;
2766 tmp_sfep
= next_sfep
;
2767 process_sf_dir2_fixi8(mp
, sfp
, &tmp_sfep
);
2769 (intptr_t)next_sfep
-
2771 next_sfep
= tmp_sfep
;
2775 do_warn(_("fixing i8count in inode %" PRIu64
"\n"),
2781 * sync up sizes if required
2783 if (*ino_dirty
&& bytes_deleted
> 0) {
2785 libxfs_idata_realloc(ip
, -bytes_deleted
, XFS_DATA_FORK
);
2786 ip
->i_d
.di_size
-= bytes_deleted
;
2789 if (ip
->i_d
.di_size
!= ip
->i_df
.if_bytes
) {
2790 ASSERT(ip
->i_df
.if_bytes
== (xfs_fsize_t
)
2791 ((intptr_t) next_sfep
- (intptr_t) sfp
));
2792 ip
->i_d
.di_size
= (xfs_fsize_t
)
2793 ((intptr_t) next_sfep
- (intptr_t) sfp
);
2795 _("setting size to %" PRId64
" bytes to reflect junked entries\n"),
2802 * processes all reachable inodes in directories
2807 xfs_agnumber_t agno
,
2808 ino_tree_node_t
*irec
,
2812 struct xfs_defer_ops dfops
;
2813 xfs_fsblock_t first
;
2816 dir_hash_tab_t
*hashtab
;
2818 int dirty
, num_illegal
, error
, nres
;
2820 ino
= XFS_AGINO_TO_INO(mp
, agno
, irec
->ino_startnum
+ ino_offset
);
2823 * open up directory inode, check all entries,
2824 * then call prune_dir_entries to remove all
2825 * remaining illegal directory entries.
2828 ASSERT(!is_inode_refchecked(irec
, ino_offset
) || dotdot_update
);
2830 error
= -libxfs_iget(mp
, NULL
, ino
, 0, &ip
);
2834 _("couldn't map inode %" PRIu64
", err = %d\n"),
2838 _("couldn't map inode %" PRIu64
", err = %d\n"),
2841 * see below for what we're doing if this
2842 * is root. Why do we need to do this here?
2843 * to ensure that the root doesn't show up
2844 * as being disconnected in the no_modify case.
2846 if (mp
->m_sb
.sb_rootino
== ino
) {
2847 add_inode_reached(irec
, 0);
2848 add_inode_ref(irec
, 0);
2852 add_inode_refchecked(irec
, 0);
2856 need_dot
= dirty
= num_illegal
= 0;
2858 if (mp
->m_sb
.sb_rootino
== ino
) {
2860 * mark root inode reached and bump up
2861 * link count for root inode to account
2862 * for '..' entry since the root inode is
2863 * never reached by a parent. we know
2864 * that root's '..' is always good --
2865 * guaranteed by phase 3 and/or below.
2867 add_inode_reached(irec
, ino_offset
);
2870 add_inode_refchecked(irec
, ino_offset
);
2872 hashtab
= dir_hash_init(ip
->i_d
.di_size
);
2875 * look for bogus entries
2877 switch (ip
->i_d
.di_format
) {
2878 case XFS_DINODE_FMT_EXTENTS
:
2879 case XFS_DINODE_FMT_BTREE
:
2881 * also check for missing '.' in longform dirs.
2882 * missing .. entries are added if required when
2883 * the directory is connected to lost+found. but
2884 * we need to create '.' entries here.
2886 longform_dir2_entry_check(mp
, ino
, ip
,
2887 &num_illegal
, &need_dot
,
2892 case XFS_DINODE_FMT_LOCAL
:
2894 * using the remove reservation is overkill
2895 * since at most we'll only need to log the
2896 * inode but it's easier than wedging a
2897 * new define in ourselves.
2899 nres
= no_modify
? 0 : XFS_REMOVE_SPACE_RES(mp
);
2900 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
2905 libxfs_trans_ijoin(tp
, ip
, 0);
2907 shortform_dir2_entry_check(mp
, ino
, ip
, &dirty
,
2911 ASSERT(dirty
== 0 || (dirty
&& !no_modify
));
2913 libxfs_trans_log_inode(tp
, ip
,
2914 XFS_ILOG_CORE
| XFS_ILOG_DDATA
);
2915 libxfs_trans_commit(tp
);
2917 libxfs_trans_cancel(tp
);
2924 dir_hash_done(hashtab
);
2927 * if we have to create a .. for /, do it now *before*
2928 * we delete the bogus entries, otherwise the directory
2929 * could transform into a shortform dir which would
2930 * probably cause the simulation to choke. Even
2931 * if the illegal entries get shifted around, it's ok
2932 * because the entries are structurally intact and in
2933 * in hash-value order so the simulation won't get confused
2934 * if it has to move them around.
2936 if (!no_modify
&& need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2937 ASSERT(ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
);
2939 do_warn(_("recreating root directory .. entry\n"));
2941 nres
= XFS_MKDIR_SPACE_RES(mp
, 2);
2942 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
2947 libxfs_trans_ijoin(tp
, ip
, 0);
2949 libxfs_defer_init(&dfops
, &first
);
2951 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dotdot
,
2952 ip
->i_ino
, &first
, &dfops
, nres
);
2955 _("can't make \"..\" entry in root inode %" PRIu64
", createname error %d\n"), ino
, error
);
2957 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
2959 libxfs_defer_ijoin(&dfops
, ip
);
2960 error
= -libxfs_defer_finish(&tp
, &dfops
);
2962 libxfs_trans_commit(tp
);
2964 need_root_dotdot
= 0;
2965 } else if (need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
2966 do_warn(_("would recreate root directory .. entry\n"));
2970 * if we need to create the '.' entry, do so only if
2971 * the directory is a longform dir. if it's been
2972 * turned into a shortform dir, then the inode is ok
2973 * since shortform dirs have no '.' entry and the inode
2974 * has already been committed by prune_lf_dir_entry().
2978 * bump up our link count but don't
2979 * bump up the inode link count. chances
2980 * are good that even though we lost '.'
2981 * the inode link counts reflect '.' so
2982 * leave the inode link count alone and if
2983 * it turns out to be wrong, we'll catch
2986 add_inode_ref(irec
, ino_offset
);
2990 _("would create missing \".\" entry in dir ino %" PRIu64
"\n"),
2992 } else if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
) {
2994 * need to create . entry in longform dir.
2997 _("creating missing \".\" entry in dir ino %" PRIu64
"\n"), ino
);
2999 nres
= XFS_MKDIR_SPACE_RES(mp
, 1);
3000 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3005 libxfs_trans_ijoin(tp
, ip
, 0);
3007 libxfs_defer_init(&dfops
, &first
);
3009 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dot
,
3010 ip
->i_ino
, &first
, &dfops
, nres
);
3013 _("can't make \".\" entry in dir ino %" PRIu64
", createname error %d\n"),
3016 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3018 libxfs_defer_ijoin(&dfops
, ip
);
3019 error
= -libxfs_defer_finish(&tp
, &dfops
);
3021 libxfs_trans_commit(tp
);
3028 * mark realtime bitmap and summary inodes as reached.
3029 * quota inode will be marked here as well
3032 mark_standalone_inodes(xfs_mount_t
*mp
)
3034 ino_tree_node_t
*irec
;
3037 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rbmino
),
3038 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
));
3040 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
) -
3043 add_inode_reached(irec
, offset
);
3045 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rsumino
),
3046 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
));
3048 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
) -
3051 add_inode_reached(irec
, offset
);
3054 if (mp
->m_sb
.sb_uquotino
3055 && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
3056 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3057 mp
->m_sb
.sb_uquotino
),
3058 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
));
3059 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
)
3060 - irec
->ino_startnum
;
3061 add_inode_reached(irec
, offset
);
3063 if (mp
->m_sb
.sb_gquotino
3064 && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
3065 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3066 mp
->m_sb
.sb_gquotino
),
3067 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
));
3068 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
)
3069 - irec
->ino_startnum
;
3070 add_inode_reached(irec
, offset
);
3072 if (mp
->m_sb
.sb_pquotino
3073 && mp
->m_sb
.sb_pquotino
!= NULLFSINO
) {
3074 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3075 mp
->m_sb
.sb_pquotino
),
3076 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
));
3077 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
)
3078 - irec
->ino_startnum
;
3079 add_inode_reached(irec
, offset
);
3085 check_for_orphaned_inodes(
3087 xfs_agnumber_t agno
,
3088 ino_tree_node_t
*irec
)
3093 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3094 ASSERT(is_inode_confirmed(irec
, i
));
3095 if (is_inode_free(irec
, i
))
3098 if (is_inode_reached(irec
, i
))
3101 ASSERT(inode_isadir(irec
, i
) ||
3102 num_inode_references(irec
, i
) == 0);
3104 ino
= XFS_AGINO_TO_INO(mp
, agno
, i
+ irec
->ino_startnum
);
3105 if (inode_isadir(irec
, i
))
3106 do_warn(_("disconnected dir inode %" PRIu64
", "), ino
);
3108 do_warn(_("disconnected inode %" PRIu64
", "), ino
);
3111 orphanage_ino
= mk_orphanage(mp
);
3112 do_warn(_("moving to %s\n"), ORPHANAGE
);
3113 mv_orphanage(mp
, ino
, inode_isadir(irec
, i
));
3115 do_warn(_("would move to %s\n"), ORPHANAGE
);
3118 * for read-only case, even though the inode isn't
3119 * really reachable, set the flag (and bump our link
3120 * count) anyway to fool phase 7
3122 add_inode_reached(irec
, i
);
3128 struct workqueue
*wq
,
3129 xfs_agnumber_t agno
,
3132 ino_tree_node_t
*irec
;
3134 prefetch_args_t
*pf_args
= arg
;
3136 wait_for_inode_prefetch(pf_args
);
3139 do_log(_(" - agno = %d\n"), agno
);
3141 for (irec
= findfirst_inode_rec(agno
); irec
; irec
= next_ino_rec(irec
)) {
3142 if (irec
->ino_isa_dir
== 0)
3146 sem_post(&pf_args
->ra_count
);
3148 sem_getvalue(&pf_args
->ra_count
, &i
);
3150 "processing inode chunk %p in AG %d (sem count = %d)",
3155 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3156 if (inode_isadir(irec
, i
))
3157 process_dir_inode(wq
->wq_ctx
, agno
, irec
, i
);
3160 cleanup_inode_prefetch(pf_args
);
3164 update_missing_dotdot_entries(
3167 dotdot_update_t
*dir
;
3170 * these entries parents were updated, rebuild them again
3171 * set dotdot_update flag so processing routines do not count links
3174 while (!list_empty(&dotdot_update_list
)) {
3175 dir
= list_entry(dotdot_update_list
.prev
, struct dotdot_update
,
3177 list_del(&dir
->list
);
3178 process_dir_inode(mp
, dir
->agno
, dir
->irec
, dir
->ino_offset
);
3185 struct xfs_mount
*mp
)
3187 do_inode_prefetch(mp
, 0, traverse_function
, false, true);
3191 phase6(xfs_mount_t
*mp
)
3193 ino_tree_node_t
*irec
;
3196 memset(&zerocr
, 0, sizeof(struct cred
));
3197 memset(&zerofsx
, 0, sizeof(struct fsxattr
));
3200 do_log(_("Phase 6 - check inode connectivity...\n"));
3202 incore_ext_teardown(mp
);
3204 add_ino_ex_data(mp
);
3207 * verify existence of root directory - if we have to
3208 * make one, it's ok for the incore data structs not to
3209 * know about it since everything about it (and the other
3210 * inodes in its chunk if a new chunk was created) are ok
3212 if (need_root_inode
) {
3214 do_warn(_("reinitializing root directory\n"));
3216 need_root_inode
= 0;
3217 need_root_dotdot
= 0;
3219 do_warn(_("would reinitialize root directory\n"));
3225 do_warn(_("reinitializing realtime bitmap inode\n"));
3229 do_warn(_("would reinitialize realtime bitmap inode\n"));
3235 do_warn(_("reinitializing realtime summary inode\n"));
3239 do_warn(_("would reinitialize realtime summary inode\n"));
3245 _(" - resetting contents of realtime bitmap and summary inodes\n"));
3246 if (fill_rbmino(mp
)) {
3248 _("Warning: realtime bitmap may be inconsistent\n"));
3251 if (fill_rsumino(mp
)) {
3253 _("Warning: realtime bitmap may be inconsistent\n"));
3257 mark_standalone_inodes(mp
);
3259 do_log(_(" - traversing filesystem ...\n"));
3261 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
3262 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
3265 * we always have a root inode, even if it's free...
3266 * if the root is free, forget it, lost+found is already gone
3268 if (is_inode_free(irec
, 0) || !inode_isadir(irec
, 0)) {
3269 need_root_inode
= 1;
3273 * then process all inodes by walking incore inode tree
3278 * any directories that had updated ".." entries, rebuild them now
3280 update_missing_dotdot_entries(mp
);
3282 do_log(_(" - traversal finished ...\n"));
3283 do_log(_(" - moving disconnected inodes to %s ...\n"),
3287 * move all disconnected inodes to the orphanage
3289 for (i
= 0; i
< glob_agcount
; i
++) {
3290 irec
= findfirst_inode_rec(i
);
3291 while (irec
!= NULL
) {
3292 check_for_orphaned_inodes(mp
, i
, irec
);
3293 irec
= next_ino_rec(irec
);