2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 #include "err_protos.h"
33 static struct cred zerocr
;
34 static struct fsxattr zerofsx
;
35 static xfs_ino_t orphanage_ino
;
37 static struct xfs_name xfs_name_dot
= {(unsigned char *)".",
42 * When we're checking directory inodes, we're allowed to set a directory's
43 * dotdot entry to zero to signal that the parent needs to be reconnected
44 * during phase 6. If we're handling a shortform directory the ifork
45 * verifiers will fail, so temporarily patch out this canary so that we can
46 * verify the rest of the fork and move on to fixing the dir.
52 struct xfs_mount
*mp
= ip
->i_mount
;
53 const struct xfs_dir_ops
*dops
;
54 struct xfs_ifork
*ifp
;
55 struct xfs_dir2_sf_hdr
*sfp
;
58 bool parent_bypass
= false;
61 dops
= libxfs_dir_get_ops(mp
, NULL
);
63 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
64 sfp
= (struct xfs_dir2_sf_hdr
*)ifp
->if_u1
.if_data
;
68 * If this is a shortform directory, phase4 may have set the parent
69 * inode to zero to indicate that it must be fixed. Temporarily
70 * set a valid parent so that the directory verifier will pass.
72 if (size
> offsetof(struct xfs_dir2_sf_hdr
, parent
) &&
73 size
>= xfs_dir2_sf_hdr_size(sfp
->i8count
)) {
74 old_parent
= dops
->sf_get_parent_ino(sfp
);
75 if (old_parent
== 0) {
76 dops
->sf_put_parent_ino(sfp
, mp
->m_sb
.sb_rootino
);
81 fa
= libxfs_default_ifork_ops
.verify_dir(ip
);
85 dops
->sf_put_parent_ino(sfp
, old_parent
);
90 static struct xfs_ifork_ops phase6_ifork_ops
= {
91 .verify_attr
= xfs_attr_shortform_verify
,
92 .verify_dir
= phase6_verify_dir
,
93 .verify_symlink
= xfs_symlink_shortform_verify
,
97 * Data structures used to keep track of directories where the ".."
98 * entries are updated. These must be rebuilt after the initial pass
100 typedef struct dotdot_update
{
101 struct list_head list
;
102 ino_tree_node_t
*irec
;
107 static LIST_HEAD(dotdot_update_list
);
108 static int dotdot_update
;
113 ino_tree_node_t
*irec
,
116 dotdot_update_t
*dir
= malloc(sizeof(dotdot_update_t
));
119 do_error(_("malloc failed add_dotdot_update (%zu bytes)\n"),
120 sizeof(dotdot_update_t
));
122 INIT_LIST_HEAD(&dir
->list
);
125 dir
->ino_offset
= ino_offset
;
127 list_add(&dir
->list
, &dotdot_update_list
);
131 * Data structures and routines to keep track of directory entries
132 * and whether their leaf entry has been seen. Also used for name
133 * duplicate checking and rebuilding step if required.
135 typedef struct dir_hash_ent
{
136 struct dir_hash_ent
*nextbyaddr
; /* next in addr bucket */
137 struct dir_hash_ent
*nextbyhash
; /* next in name bucket */
138 struct dir_hash_ent
*nextbyorder
; /* next in order added */
139 xfs_dahash_t hashval
; /* hash value of name */
140 uint32_t address
; /* offset of data entry */
141 xfs_ino_t inum
; /* inode num of entry */
142 short junkit
; /* name starts with / */
143 short seen
; /* have seen leaf entry */
144 struct xfs_name name
;
147 typedef struct dir_hash_tab
{
148 int size
; /* size of hash tables */
149 int names_duped
; /* 1 = ent names malloced */
150 dir_hash_ent_t
*first
; /* ptr to first added entry */
151 dir_hash_ent_t
*last
; /* ptr to last added entry */
152 dir_hash_ent_t
**byhash
; /* ptr to name hash buckets */
153 dir_hash_ent_t
**byaddr
; /* ptr to addr hash buckets */
156 #define DIR_HASH_TAB_SIZE(n) \
157 (sizeof(dir_hash_tab_t) + (sizeof(dir_hash_ent_t *) * (n) * 2))
158 #define DIR_HASH_FUNC(t,a) ((a) % (t)->size)
161 * Track the contents of the freespace table in a directory.
163 typedef struct freetab
{
164 int naents
; /* expected number of data blocks */
165 int nents
; /* number of data blocks processed */
167 xfs_dir2_data_off_t v
;
171 #define FREETAB_SIZE(n) \
172 (offsetof(freetab_t, ents) + (sizeof(struct freetab_ent) * (n)))
174 #define DIR_HASH_CK_OK 0
175 #define DIR_HASH_CK_DUPLEAF 1
176 #define DIR_HASH_CK_BADHASH 2
177 #define DIR_HASH_CK_NODATA 3
178 #define DIR_HASH_CK_NOLEAF 4
179 #define DIR_HASH_CK_BADSTALE 5
180 #define DIR_HASH_CK_TOTAL 6
183 * Need to handle CRC and validation errors specially here. If there is a
184 * validator error, re-read without the verifier so that we get a buffer we can
185 * check and repair. Re-attach the ops to the buffer after the read so that when
186 * it is rewritten the CRC is recalculated.
188 * If the buffer was not read, we return an error. If the buffer was read but
189 * had a CRC or corruption error, we reread it without the verifier and if it is
190 * read successfully we increment *crc_error and return 0. Otherwise we
191 * return the read error.
195 struct xfs_inode
*ip
,
197 xfs_daddr_t mappedbno
,
198 struct xfs_buf
**bpp
,
199 const struct xfs_buf_ops
*ops
,
205 error
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
208 if (error
!= EFSBADCRC
&& error
!= EFSCORRUPTED
)
211 error2
= -libxfs_da_read_buf(NULL
, ip
, bno
, mappedbno
, bpp
,
212 XFS_DATA_FORK
, NULL
);
222 * Returns 0 if the name already exists (ie. a duplicate)
227 dir_hash_tab_t
*hashtab
,
234 xfs_dahash_t hash
= 0;
240 struct xfs_name xname
;
242 ASSERT(!hashtab
->names_duped
);
248 junk
= name
[0] == '/';
249 byaddr
= DIR_HASH_FUNC(hashtab
, addr
);
253 hash
= mp
->m_dirnameops
->hashname(&xname
);
254 byhash
= DIR_HASH_FUNC(hashtab
, hash
);
257 * search hash bucket for existing name.
259 for (p
= hashtab
->byhash
[byhash
]; p
; p
= p
->nextbyhash
) {
260 if (p
->hashval
== hash
&& p
->name
.len
== namelen
) {
261 if (memcmp(p
->name
.name
, name
, namelen
) == 0) {
270 if ((p
= malloc(sizeof(*p
))) == NULL
)
271 do_error(_("malloc failed in dir_hash_add (%zu bytes)\n"),
274 p
->nextbyaddr
= hashtab
->byaddr
[byaddr
];
275 hashtab
->byaddr
[byaddr
] = p
;
277 hashtab
->last
->nextbyorder
= p
;
280 p
->nextbyorder
= NULL
;
283 if (!(p
->junkit
= junk
)) {
285 p
->nextbyhash
= hashtab
->byhash
[byhash
];
286 hashtab
->byhash
[byhash
] = p
;
297 * checks to see if any data entries are not in the leaf blocks
301 dir_hash_tab_t
*hashtab
)
306 for (i
= 0; i
< hashtab
->size
; i
++) {
307 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
317 dir_hash_tab_t
*hashtab
,
321 static char *seevalstr
[DIR_HASH_CK_TOTAL
];
325 seevalstr
[DIR_HASH_CK_OK
] = _("ok");
326 seevalstr
[DIR_HASH_CK_DUPLEAF
] = _("duplicate leaf");
327 seevalstr
[DIR_HASH_CK_BADHASH
] = _("hash value mismatch");
328 seevalstr
[DIR_HASH_CK_NODATA
] = _("no data entry");
329 seevalstr
[DIR_HASH_CK_NOLEAF
] = _("no leaf entry");
330 seevalstr
[DIR_HASH_CK_BADSTALE
] = _("bad stale count");
334 if (seeval
== DIR_HASH_CK_OK
&& dir_hash_unseen(hashtab
))
335 seeval
= DIR_HASH_CK_NOLEAF
;
336 if (seeval
== DIR_HASH_CK_OK
)
338 do_warn(_("bad hash table for directory inode %" PRIu64
" (%s): "),
339 ip
->i_ino
, seevalstr
[seeval
]);
341 do_warn(_("rebuilding\n"));
343 do_warn(_("would rebuild\n"));
349 dir_hash_tab_t
*hashtab
)
355 for (i
= 0; i
< hashtab
->size
; i
++) {
356 for (p
= hashtab
->byaddr
[i
]; p
; p
= n
) {
358 if (hashtab
->names_duped
)
359 free((void *)p
->name
.name
);
366 static dir_hash_tab_t
*
370 dir_hash_tab_t
*hashtab
;
373 hsize
= size
/ (16 * 4);
378 if ((hashtab
= calloc(DIR_HASH_TAB_SIZE(hsize
), 1)) == NULL
)
379 do_error(_("calloc failed in dir_hash_init\n"));
380 hashtab
->size
= hsize
;
381 hashtab
->byhash
= (dir_hash_ent_t
**)((char *)hashtab
+
382 sizeof(dir_hash_tab_t
));
383 hashtab
->byaddr
= (dir_hash_ent_t
**)((char *)hashtab
+
384 sizeof(dir_hash_tab_t
) + sizeof(dir_hash_ent_t
*) * hsize
);
390 dir_hash_tab_t
*hashtab
,
392 xfs_dir2_dataptr_t addr
)
397 i
= DIR_HASH_FUNC(hashtab
, addr
);
398 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
399 if (p
->address
!= addr
)
402 return DIR_HASH_CK_DUPLEAF
;
403 if (p
->junkit
== 0 && p
->hashval
!= hash
)
404 return DIR_HASH_CK_BADHASH
;
406 return DIR_HASH_CK_OK
;
408 return DIR_HASH_CK_NODATA
;
412 dir_hash_update_ftype(
413 dir_hash_tab_t
*hashtab
,
414 xfs_dir2_dataptr_t addr
,
420 i
= DIR_HASH_FUNC(hashtab
, addr
);
421 for (p
= hashtab
->byaddr
[i
]; p
; p
= p
->nextbyaddr
) {
422 if (p
->address
!= addr
)
424 p
->name
.type
= ftype
;
429 * checks to make sure leafs match a data entry, and that the stale
434 dir_hash_tab_t
*hashtab
,
435 xfs_dir2_leaf_entry_t
*ents
,
443 for (i
= j
= 0; i
< count
; i
++) {
444 if (be32_to_cpu(ents
[i
].address
) == XFS_DIR2_NULL_DATAPTR
) {
448 rval
= dir_hash_see(hashtab
, be32_to_cpu(ents
[i
].hashval
),
449 be32_to_cpu(ents
[i
].address
));
450 if (rval
!= DIR_HASH_CK_OK
)
453 return j
== stale
? DIR_HASH_CK_OK
: DIR_HASH_CK_BADSTALE
;
457 * Convert name pointers into locally allocated memory.
458 * This must only be done after all the entries have been added.
461 dir_hash_dup_names(dir_hash_tab_t
*hashtab
)
466 if (hashtab
->names_duped
)
469 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
470 name
= malloc(p
->name
.len
);
471 memcpy(name
, p
->name
.name
, p
->name
.len
);
474 hashtab
->names_duped
= 1;
478 * Given a block number in a fork, return the next valid block number
480 * If this is the last block number then NULLFILEOFF is returned.
482 * This was originally in the kernel, but only used in xfs_repair.
486 xfs_trans_t
*tp
, /* transaction pointer */
487 xfs_inode_t
*ip
, /* incore inode */
488 xfs_fileoff_t
*bnop
, /* current block */
489 int whichfork
) /* data or attr fork */
491 xfs_fileoff_t bno
; /* current block */
492 int error
; /* error return value */
493 xfs_bmbt_irec_t got
; /* current extent value */
494 xfs_ifork_t
*ifp
; /* inode fork pointer */
495 struct xfs_iext_cursor icur
;
497 if (XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_BTREE
&&
498 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_EXTENTS
&&
499 XFS_IFORK_FORMAT(ip
, whichfork
) != XFS_DINODE_FMT_LOCAL
)
501 if (XFS_IFORK_FORMAT(ip
, whichfork
) == XFS_DINODE_FMT_LOCAL
) {
505 ifp
= XFS_IFORK_PTR(ip
, whichfork
);
506 if (!(ifp
->if_flags
& XFS_IFEXTENTS
) &&
507 (error
= -libxfs_iread_extents(tp
, ip
, whichfork
)))
510 if (!libxfs_iext_lookup_extent(ip
, ifp
, bno
, &icur
, &got
))
513 *bnop
= got
.br_startoff
< bno
? bno
: got
.br_startoff
;
523 do_error(_("ran out of disk space!\n"));
525 do_error(_("xfs_trans_reserve returned %d\n"), err
);
529 mk_rbmino(xfs_mount_t
*mp
)
538 struct xfs_defer_ops dfops
;
540 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
543 struct xfs_trans_res tres
= {0};
548 i
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
552 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
555 _("couldn't iget realtime bitmap inode -- error - %d\n"),
559 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
560 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
562 VFS_I(ip
)->i_mode
= S_IFREG
;
563 ip
->i_d
.di_version
= vers
;
564 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
565 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
567 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
569 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
570 if (ip
->i_d
.di_version
== 3) {
571 VFS_I(ip
)->i_version
= 1;
572 ip
->i_d
.di_flags2
= 0;
573 times
|= XFS_ICHGTIME_CREATE
;
575 libxfs_trans_ichgtime(tp
, ip
, times
);
580 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
581 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
582 ip
->i_df
.if_u1
.if_root
= NULL
;
584 ip
->i_d
.di_size
= mp
->m_sb
.sb_rbmblocks
* mp
->m_sb
.sb_blocksize
;
589 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
590 libxfs_trans_commit(tp
);
593 * then allocate blocks for file and fill with zeroes (stolen
596 error
= -libxfs_trans_alloc(mp
, &tres
,
597 mp
->m_sb
.sb_rbmblocks
+ (XFS_BM_MAXLEVELS(mp
,XFS_DATA_FORK
) - 1),
602 libxfs_trans_ijoin(tp
, ip
, 0);
604 libxfs_defer_init(&dfops
, &first
);
605 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
606 nmap
= XFS_BMAP_MAX_NMAP
;
607 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
608 (xfs_extlen_t
)(mp
->m_sb
.sb_rbmblocks
- bno
),
609 0, &first
, mp
->m_sb
.sb_rbmblocks
,
613 _("couldn't allocate realtime bitmap, error = %d\n"),
616 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
617 libxfs_device_zero(mp
->m_ddev_targp
,
618 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
619 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
620 bno
+= ep
->br_blockcount
;
623 libxfs_defer_ijoin(&dfops
, ip
);
624 error
= -libxfs_defer_finish(&tp
, &dfops
);
627 _("allocation of the realtime bitmap failed, error = %d\n"),
630 libxfs_trans_commit(tp
);
635 fill_rbmino(xfs_mount_t
*mp
)
646 struct xfs_trans_res tres
= {0};
651 error
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
655 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rbmino
, 0, 0, &ip
);
658 _("couldn't iget realtime bitmap inode -- error - %d\n"),
663 while (bno
< mp
->m_sb
.sb_rbmblocks
) {
665 * fill the file one block at a time
668 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
669 &first
, 1, &map
, &nmap
, NULL
);
670 if (error
|| nmap
!= 1) {
672 _("couldn't map realtime bitmap block %" PRIu64
", error = %d\n"),
676 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
678 error
= -libxfs_trans_read_buf(
680 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
681 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
685 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime bitmap inode %" PRIu64
"\n"),
686 bno
, map
.br_startblock
, mp
->m_sb
.sb_rbmino
);
690 memmove(XFS_BUF_PTR(bp
), bmp
, mp
->m_sb
.sb_blocksize
);
692 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
694 bmp
= (xfs_rtword_t
*)((intptr_t) bmp
+ mp
->m_sb
.sb_blocksize
);
698 libxfs_trans_commit(tp
);
704 fill_rsumino(xfs_mount_t
*mp
)
714 xfs_fileoff_t end_bno
;
716 struct xfs_trans_res tres
= {0};
720 end_bno
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
722 error
= -libxfs_trans_alloc(mp
, &tres
, 10, 0, 0, &tp
);
726 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
729 _("couldn't iget realtime summary inode -- error - %d\n"),
734 while (bno
< end_bno
) {
736 * fill the file one block at a time
739 error
= -libxfs_bmapi_write(tp
, ip
, bno
, 1, 0,
740 &first
, 1, &map
, &nmap
, NULL
);
741 if (error
|| nmap
!= 1) {
743 _("couldn't map realtime summary inode block %" PRIu64
", error = %d\n"),
747 ASSERT(map
.br_startblock
!= HOLESTARTBLOCK
);
749 error
= -libxfs_trans_read_buf(
751 XFS_FSB_TO_DADDR(mp
, map
.br_startblock
),
752 XFS_FSB_TO_BB(mp
, 1), 1, &bp
, NULL
);
756 _("can't access block %" PRIu64
" (fsbno %" PRIu64
") of realtime summary inode %" PRIu64
"\n"),
757 bno
, map
.br_startblock
, mp
->m_sb
.sb_rsumino
);
762 memmove(XFS_BUF_PTR(bp
), smp
, mp
->m_sb
.sb_blocksize
);
764 libxfs_trans_log_buf(tp
, bp
, 0, mp
->m_sb
.sb_blocksize
- 1);
766 smp
= (xfs_suminfo_t
*)((intptr_t)smp
+ mp
->m_sb
.sb_blocksize
);
770 libxfs_trans_commit(tp
);
776 mk_rsumino(xfs_mount_t
*mp
)
786 struct xfs_defer_ops dfops
;
788 xfs_bmbt_irec_t map
[XFS_BMAP_MAX_NMAP
];
791 struct xfs_trans_res tres
= {0};
796 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
800 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rsumino
, 0, 0, &ip
);
803 _("couldn't iget realtime summary inode -- error - %d\n"),
807 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
808 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
810 VFS_I(ip
)->i_mode
= S_IFREG
;
811 ip
->i_d
.di_version
= vers
;
812 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
813 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
815 set_nlink(VFS_I(ip
), 1); /* account for sb ptr */
817 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
818 if (ip
->i_d
.di_version
== 3) {
819 VFS_I(ip
)->i_version
= 1;
820 ip
->i_d
.di_flags2
= 0;
821 times
|= XFS_ICHGTIME_CREATE
;
823 libxfs_trans_ichgtime(tp
, ip
, times
);
828 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
829 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
830 ip
->i_df
.if_u1
.if_root
= NULL
;
832 ip
->i_d
.di_size
= mp
->m_rsumsize
;
837 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
838 libxfs_trans_commit(tp
);
841 * then allocate blocks for file and fill with zeroes (stolen
844 libxfs_defer_init(&dfops
, &first
);
846 nsumblocks
= mp
->m_rsumsize
>> mp
->m_sb
.sb_blocklog
;
847 tres
.tr_logres
= BBTOB(128);
848 tres
.tr_logcount
= XFS_DEFAULT_PERM_LOG_COUNT
;
849 tres
.tr_logflags
= XFS_TRANS_PERM_LOG_RES
;
850 error
= -libxfs_trans_alloc(mp
, &tres
,
851 mp
->m_sb
.sb_rbmblocks
+ (XFS_BM_MAXLEVELS(mp
,XFS_DATA_FORK
) - 1),
856 libxfs_trans_ijoin(tp
, ip
, 0);
858 libxfs_defer_init(&dfops
, &first
);
859 while (bno
< nsumblocks
) {
860 nmap
= XFS_BMAP_MAX_NMAP
;
861 error
= -libxfs_bmapi_write(tp
, ip
, bno
,
862 (xfs_extlen_t
)(nsumblocks
- bno
),
863 0, &first
, nsumblocks
, map
, &nmap
, &dfops
);
866 _("couldn't allocate realtime summary inode, error = %d\n"),
869 for (i
= 0, ep
= map
; i
< nmap
; i
++, ep
++) {
870 libxfs_device_zero(mp
->m_ddev_targp
,
871 XFS_FSB_TO_DADDR(mp
, ep
->br_startblock
),
872 XFS_FSB_TO_BB(mp
, ep
->br_blockcount
));
873 bno
+= ep
->br_blockcount
;
876 libxfs_defer_ijoin(&dfops
, ip
);
877 error
= -libxfs_defer_finish(&tp
, &dfops
);
880 _("allocation of the realtime summary ino failed, error = %d\n"),
883 libxfs_trans_commit(tp
);
888 * makes a new root directory.
891 mk_root_dir(xfs_mount_t
*mp
)
897 const mode_t mode
= 0755;
898 ino_tree_node_t
*irec
;
903 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_ichange
, 10, 0, 0, &tp
);
907 error
= -libxfs_trans_iget(mp
, tp
, mp
->m_sb
.sb_rootino
, 0, 0, &ip
);
909 do_error(_("could not iget root inode -- error - %d\n"), error
);
913 * take care of the core -- initialization from xfs_ialloc()
915 vers
= xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
916 memset(&ip
->i_d
, 0, sizeof(ip
->i_d
));
918 VFS_I(ip
)->i_mode
= mode
|S_IFDIR
;
919 ip
->i_d
.di_version
= vers
;
920 ip
->i_d
.di_format
= XFS_DINODE_FMT_EXTENTS
;
921 ip
->i_d
.di_aformat
= XFS_DINODE_FMT_EXTENTS
;
923 set_nlink(VFS_I(ip
), 1); /* account for . */
925 times
= XFS_ICHGTIME_CHG
| XFS_ICHGTIME_MOD
;
926 if (ip
->i_d
.di_version
== 3) {
927 VFS_I(ip
)->i_version
= 1;
928 ip
->i_d
.di_flags2
= 0;
929 times
|= XFS_ICHGTIME_CREATE
;
931 libxfs_trans_ichgtime(tp
, ip
, times
);
933 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
938 ip
->i_df
.if_flags
= XFS_IFEXTENTS
;
939 ip
->i_df
.if_bytes
= ip
->i_df
.if_real_bytes
= 0;
940 ip
->i_df
.if_u1
.if_root
= NULL
;
945 * initialize the directory
947 ip
->d_ops
= mp
->m_dir_inode_ops
;
948 libxfs_dir_init(tp
, ip
, ip
);
950 libxfs_trans_commit(tp
);
953 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
954 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
955 set_inode_isadir(irec
, XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
) -
960 * orphanage name == lost+found
963 mk_orphanage(xfs_mount_t
*mp
)
970 ino_tree_node_t
*irec
;
974 struct xfs_defer_ops dfops
;
975 const int mode
= 0755;
977 struct xfs_name xname
;
980 * check for an existing lost+found first, if it exists, return
981 * its inode. Otherwise, we can create it. Bad lost+found inodes
982 * would have been cleared in phase3 and phase4.
985 i
= -libxfs_iget(mp
, NULL
, mp
->m_sb
.sb_rootino
, 0, &pip
,
986 &xfs_default_ifork_ops
);
988 do_error(_("%d - couldn't iget root inode to obtain %s\n"),
991 xname
.name
= (unsigned char *)ORPHANAGE
;
992 xname
.len
= strlen(ORPHANAGE
);
993 xname
.type
= XFS_DIR3_FT_DIR
;
995 if (libxfs_dir_lookup(NULL
, pip
, &xname
, &ino
, NULL
) == 0)
999 * could not be found, create it
1001 libxfs_defer_init(&dfops
, &first
);
1002 nres
= XFS_MKDIR_SPACE_RES(mp
, xname
.len
);
1003 i
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
, nres
, 0, 0, &tp
);
1008 * use iget/ijoin instead of trans_iget because the ialloc
1009 * wrapper can commit the transaction and start a new one
1011 /* i = -libxfs_iget(mp, NULL, mp->m_sb.sb_rootino, 0, &pip,
1012 &xfs_default_ifork_ops);
1014 do_error(_("%d - couldn't iget root inode to make %s\n"),
1017 error
= -libxfs_inode_alloc(&tp
, pip
, mode
|S_IFDIR
,
1018 1, 0, &zerocr
, &zerofsx
, &ip
);
1020 do_error(_("%s inode allocation failed %d\n"),
1023 inc_nlink(VFS_I(ip
)); /* account for . */
1026 irec
= find_inode_rec(mp
,
1027 XFS_INO_TO_AGNO(mp
, ino
),
1028 XFS_INO_TO_AGINO(mp
, ino
));
1032 * This inode is allocated from a newly created inode
1033 * chunk and therefore did not exist when inode chunks
1034 * were processed in phase3. Add this group of inodes to
1035 * the entry avl tree as if they were discovered in phase3.
1037 irec
= set_inode_free_alloc(mp
, XFS_INO_TO_AGNO(mp
, ino
),
1038 XFS_INO_TO_AGINO(mp
, ino
));
1039 alloc_ex_data(irec
);
1041 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++)
1042 set_inode_free(irec
, i
);
1045 ino_offset
= get_inode_offset(mp
, ino
, irec
);
1048 * Mark the inode allocated to lost+found as used in the AVL tree
1049 * so it is not skipped in phase 7
1051 set_inode_used(irec
, ino_offset
);
1052 add_inode_ref(irec
, ino_offset
);
1055 * now that we know the transaction will stay around,
1056 * add the root inode to it
1058 libxfs_trans_ijoin(tp
, pip
, 0);
1061 * create the actual entry
1063 error
= -libxfs_dir_createname(tp
, pip
, &xname
, ip
->i_ino
, &first
,
1067 _("can't make %s, createname error %d\n"),
1071 * bump up the link count in the root directory to account
1072 * for .. in the new directory
1074 inc_nlink(VFS_I(pip
));
1075 add_inode_ref(find_inode_rec(mp
,
1076 XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
1077 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
)), 0);
1081 libxfs_trans_log_inode(tp
, pip
, XFS_ILOG_CORE
);
1082 libxfs_dir_init(tp
, ip
, pip
);
1083 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
1085 libxfs_defer_ijoin(&dfops
, ip
);
1086 error
= -libxfs_defer_finish(&tp
, &dfops
);
1088 do_error(_("%s directory creation failed -- bmapf error %d\n"),
1093 libxfs_trans_commit(tp
);
1096 add_inode_reached(irec
,ino_offset
);
1102 * move a file to the orphange.
1107 xfs_ino_t ino
, /* inode # to be moved */
1108 int isa_dir
) /* 1 if inode is a directory */
1110 xfs_inode_t
*orphanage_ip
;
1111 xfs_ino_t entry_ino_num
;
1114 xfs_fsblock_t first
;
1115 struct xfs_defer_ops dfops
;
1117 unsigned char fname
[MAXPATHLEN
+ 1];
1120 ino_tree_node_t
*irec
;
1122 struct xfs_name xname
;
1125 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu",
1126 (unsigned long long)ino
);
1128 err
= -libxfs_iget(mp
, NULL
, orphanage_ino
, 0, &orphanage_ip
,
1129 &xfs_default_ifork_ops
);
1131 do_error(_("%d - couldn't iget orphanage inode\n"), err
);
1133 * Make sure the filename is unique in the lost+found
1136 while (libxfs_dir_lookup(NULL
, orphanage_ip
, &xname
, &entry_ino_num
,
1138 xname
.len
= snprintf((char *)fname
, sizeof(fname
), "%llu.%d",
1139 (unsigned long long)ino
, ++incr
);
1141 /* Orphans may not have a proper parent, so use custom ops here */
1142 err
= -libxfs_iget(mp
, NULL
, ino
, 0, &ino_p
, &phase6_ifork_ops
);
1144 do_error(_("%d - couldn't iget disconnected inode\n"), err
);
1146 xname
.type
= libxfs_mode_to_ftype(VFS_I(ino_p
)->i_mode
);
1149 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, orphanage_ino
),
1150 XFS_INO_TO_AGINO(mp
, orphanage_ino
));
1152 ino_offset
= XFS_INO_TO_AGINO(mp
, orphanage_ino
) -
1154 nres
= XFS_DIRENTER_SPACE_RES(mp
, fnamelen
) +
1155 XFS_DIRENTER_SPACE_RES(mp
, 2);
1156 err
= -libxfs_dir_lookup(NULL
, ino_p
, &xfs_name_dotdot
,
1157 &entry_ino_num
, NULL
);
1159 ASSERT(err
== ENOENT
);
1161 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1165 _("space reservation failed (%d), filesystem may be out of space\n"),
1168 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1169 libxfs_trans_ijoin(tp
, ino_p
, 0);
1171 libxfs_defer_init(&dfops
, &first
);
1172 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1173 ino
, &first
, &dfops
, nres
);
1176 _("name create failed in %s (%d), filesystem may be out of space\n"),
1180 add_inode_ref(irec
, ino_offset
);
1182 inc_nlink(VFS_I(orphanage_ip
));
1183 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1185 err
= -libxfs_dir_createname(tp
, ino_p
, &xfs_name_dotdot
,
1186 orphanage_ino
, &first
, &dfops
, nres
);
1189 _("creation of .. entry failed (%d), filesystem may be out of space\n"),
1192 inc_nlink(VFS_I(ino_p
));
1193 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1195 libxfs_defer_ijoin(&dfops
, ino_p
);
1196 err
= -libxfs_defer_finish(&tp
, &dfops
);
1199 _("bmap finish failed (err - %d), filesystem may be out of space\n"),
1202 libxfs_trans_commit(tp
);
1204 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_rename
,
1208 _("space reservation failed (%d), filesystem may be out of space\n"),
1211 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1212 libxfs_trans_ijoin(tp
, ino_p
, 0);
1214 libxfs_defer_init(&dfops
, &first
);
1216 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
,
1217 ino
, &first
, &dfops
, nres
);
1220 _("name create failed in %s (%d), filesystem may be out of space\n"),
1224 add_inode_ref(irec
, ino_offset
);
1226 inc_nlink(VFS_I(orphanage_ip
));
1227 libxfs_trans_log_inode(tp
, orphanage_ip
, XFS_ILOG_CORE
);
1230 * don't replace .. value if it already points
1231 * to us. that'll pop a libxfs/kernel ASSERT.
1233 if (entry_ino_num
!= orphanage_ino
) {
1234 err
= -libxfs_dir_replace(tp
, ino_p
,
1235 &xfs_name_dotdot
, orphanage_ino
,
1236 &first
, &dfops
, nres
);
1239 _("name replace op failed (%d), filesystem may be out of space\n"),
1243 libxfs_defer_ijoin(&dfops
, ino_p
);
1244 err
= -libxfs_defer_finish(&tp
, &dfops
);
1247 _("bmap finish failed (%d), filesystem may be out of space\n"),
1250 libxfs_trans_commit(tp
);
1255 * use the remove log reservation as that's
1256 * more accurate. we're only creating the
1257 * links, we're not doing the inode allocation
1258 * also accounted for in the create
1260 nres
= XFS_DIRENTER_SPACE_RES(mp
, xname
.len
);
1261 err
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
1265 _("space reservation failed (%d), filesystem may be out of space\n"),
1268 libxfs_trans_ijoin(tp
, orphanage_ip
, 0);
1269 libxfs_trans_ijoin(tp
, ino_p
, 0);
1271 libxfs_defer_init(&dfops
, &first
);
1272 err
= -libxfs_dir_createname(tp
, orphanage_ip
, &xname
, ino
,
1273 &first
, &dfops
, nres
);
1276 _("name create failed in %s (%d), filesystem may be out of space\n"),
1280 set_nlink(VFS_I(ino_p
), 1);
1281 libxfs_trans_log_inode(tp
, ino_p
, XFS_ILOG_CORE
);
1283 libxfs_defer_ijoin(&dfops
, ino_p
);
1284 err
= -libxfs_defer_finish(&tp
, &dfops
);
1287 _("bmap finish failed (%d), filesystem may be out of space\n"),
1290 libxfs_trans_commit(tp
);
1293 IRELE(orphanage_ip
);
1303 do_warn(msg
, iname
, ino1
, ino2
);
1306 do_warn(_(", marking entry to be junked\n"));
1310 do_warn(_(", would junk entry\n"));
1314 /* Find and invalidate all the directory's buffers. */
1317 struct xfs_trans
*tp
,
1318 struct xfs_inode
*ip
,
1321 struct xfs_iext_cursor icur
;
1322 struct xfs_bmbt_irec rec
;
1323 struct xfs_ifork
*ifp
;
1324 struct xfs_da_geometry
*geo
;
1326 xfs_dablk_t dabno
, end_dabno
;
1329 if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_EXTENTS
&&
1330 ip
->i_d
.di_format
!= XFS_DINODE_FMT_BTREE
)
1333 geo
= tp
->t_mountp
->m_dir_geo
;
1334 ifp
= XFS_IFORK_PTR(ip
, XFS_DATA_FORK
);
1335 for_each_xfs_iext(ifp
, &icur
, &rec
) {
1336 dabno
= xfs_dir2_db_to_da(geo
, rec
.br_startoff
+
1338 end_dabno
= xfs_dir2_db_to_da(geo
, rec
.br_startoff
+
1340 for (; dabno
<= end_dabno
; dabno
+= geo
->fsbcount
) {
1342 error
= -libxfs_da_get_buf(tp
, ip
, dabno
, -2, &bp
,
1348 libxfs_trans_binval(tp
, bp
);
1349 libxfs_trans_brelse(tp
, bp
);
1357 * Unexpected failure during the rebuild will leave the entries in
1358 * lost+found on the next run
1362 longform_dir2_rebuild(
1366 ino_tree_node_t
*irec
,
1368 dir_hash_tab_t
*hashtab
)
1373 xfs_fileoff_t lastblock
;
1374 xfs_fsblock_t firstblock
;
1375 struct xfs_defer_ops dfops
;
1381 * trash directory completely and rebuild from scratch using the
1382 * name/inode pairs in the hash table
1385 do_warn(_("rebuilding directory inode %" PRIu64
"\n"), ino
);
1388 * first attempt to locate the parent inode, if it can't be
1389 * found, set it to the root inode and it'll be moved to the
1390 * orphanage later (the inode number here needs to be valid
1391 * for the libxfs_dir_init() call).
1393 pip
.i_ino
= get_inode_parent(irec
, ino_offset
);
1394 if (pip
.i_ino
== NULLFSINO
||
1395 libxfs_dir_ino_validate(mp
, pip
.i_ino
))
1396 pip
.i_ino
= mp
->m_sb
.sb_rootino
;
1398 libxfs_defer_init(&dfops
, &firstblock
);
1400 nres
= XFS_REMOVE_SPACE_RES(mp
);
1401 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1404 libxfs_trans_ijoin(tp
, ip
, 0);
1406 error
= dir_binval(tp
, ip
, XFS_DATA_FORK
);
1410 if ((error
= -libxfs_bmap_last_offset(ip
, &lastblock
, XFS_DATA_FORK
)))
1411 do_error(_("xfs_bmap_last_offset failed -- error - %d\n"),
1414 /* free all data, leaf, node and freespace blocks */
1415 error
= -libxfs_bunmapi(tp
, ip
, 0, lastblock
, XFS_BMAPI_METADATA
, 0,
1416 &firstblock
, &dfops
, &done
);
1418 do_warn(_("xfs_bunmapi failed -- error - %d\n"), error
);
1419 goto out_bmap_cancel
;
1424 error
= -libxfs_dir_init(tp
, ip
, &pip
);
1426 do_warn(_("xfs_dir_init failed -- error - %d\n"), error
);
1427 goto out_bmap_cancel
;
1430 libxfs_defer_ijoin(&dfops
, ip
);
1431 error
= -libxfs_defer_finish(&tp
, &dfops
);
1433 libxfs_trans_commit(tp
);
1435 if (ino
== mp
->m_sb
.sb_rootino
)
1436 need_root_dotdot
= 0;
1438 /* go through the hash list and re-add the inodes */
1440 for (p
= hashtab
->first
; p
; p
= p
->nextbyorder
) {
1442 if (p
->name
.name
[0] == '/' || (p
->name
.name
[0] == '.' &&
1443 (p
->name
.len
== 1 || (p
->name
.len
== 2 &&
1444 p
->name
.name
[1] == '.'))))
1447 nres
= XFS_CREATE_SPACE_RES(mp
, p
->name
.len
);
1448 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_create
,
1453 libxfs_trans_ijoin(tp
, ip
, 0);
1455 libxfs_defer_init(&dfops
, &firstblock
);
1456 error
= -libxfs_dir_createname(tp
, ip
, &p
->name
, p
->inum
,
1457 &firstblock
, &dfops
, nres
);
1460 _("name create failed in ino %" PRIu64
" (%d), filesystem may be out of space\n"),
1462 goto out_bmap_cancel
;
1465 libxfs_defer_ijoin(&dfops
, ip
);
1466 error
= -libxfs_defer_finish(&tp
, &dfops
);
1469 _("bmap finish failed (%d), filesystem may be out of space\n"),
1471 goto out_bmap_cancel
;
1474 libxfs_trans_commit(tp
);
1480 libxfs_defer_cancel(&dfops
);
1481 libxfs_trans_cancel(tp
);
1487 * Kill a block in a version 2 inode.
1488 * Makes its own transaction.
1499 xfs_fsblock_t firstblock
;
1500 struct xfs_defer_ops dfops
;
1504 nres
= XFS_REMOVE_SPACE_RES(mp
);
1505 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, nres
, 0, 0, &tp
);
1508 libxfs_trans_ijoin(tp
, ip
, 0);
1509 libxfs_trans_bjoin(tp
, bp
);
1510 memset(&args
, 0, sizeof(args
));
1511 libxfs_defer_init(&dfops
, &firstblock
);
1514 args
.firstblock
= &firstblock
;
1515 args
.dfops
= &dfops
;
1516 args
.whichfork
= XFS_DATA_FORK
;
1517 args
.geo
= mp
->m_dir_geo
;
1518 if (da_bno
>= mp
->m_dir_geo
->leafblk
&& da_bno
< mp
->m_dir_geo
->freeblk
)
1519 error
= -libxfs_da_shrink_inode(&args
, da_bno
, bp
);
1521 error
= -libxfs_dir2_shrink_inode(&args
,
1522 xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
), bp
);
1524 do_error(_("shrink_inode failed inode %" PRIu64
" block %u\n"),
1526 libxfs_defer_ijoin(&dfops
, ip
);
1527 libxfs_defer_finish(&tp
, &dfops
);
1528 libxfs_trans_commit(tp
);
1532 * process a data block, also checks for .. entry
1533 * and corrects it to match what we think .. should be
1536 longform_dir2_entry_check_data(
1541 ino_tree_node_t
*current_irec
,
1542 int current_ino_offset
,
1543 struct xfs_buf
**bpp
,
1544 dir_hash_tab_t
*hashtab
,
1545 freetab_t
**freetabp
,
1549 xfs_dir2_dataptr_t addr
;
1550 xfs_dir2_leaf_entry_t
*blp
;
1552 xfs_dir2_block_tail_t
*btp
;
1553 struct xfs_dir2_data_hdr
*d
;
1555 xfs_dir2_data_entry_t
*dep
;
1556 xfs_dir2_data_unused_t
*dup
;
1557 struct xfs_dir2_data_free
*bf
;
1560 xfs_fsblock_t firstblock
;
1561 struct xfs_defer_ops dfops
;
1562 char fname
[MAXNAMELEN
+ 1];
1567 ino_tree_node_t
*irec
;
1578 struct xfs_da_args da
= {
1580 .geo
= mp
->m_dir_geo
,
1586 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1588 needscan
= needlog
= 0;
1590 freetab
= *freetabp
;
1592 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, d
);
1593 blp
= xfs_dir2_block_leaf_p(btp
);
1594 endptr
= (char *)blp
;
1595 if (endptr
> (char *)btp
)
1596 endptr
= (char *)btp
;
1597 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1598 wantmagic
= XFS_DIR3_BLOCK_MAGIC
;
1600 wantmagic
= XFS_DIR2_BLOCK_MAGIC
;
1602 endptr
= (char *)d
+ mp
->m_dir_geo
->blksize
;
1603 if (xfs_sb_version_hascrc(&mp
->m_sb
))
1604 wantmagic
= XFS_DIR3_DATA_MAGIC
;
1606 wantmagic
= XFS_DIR2_DATA_MAGIC
;
1608 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
1610 /* check for data block beyond expected end */
1611 if (freetab
->naents
<= db
) {
1612 struct freetab_ent e
;
1614 *freetabp
= freetab
= realloc(freetab
, FREETAB_SIZE(db
+ 1));
1616 do_error(_("realloc failed in %s (%zu bytes)\n"),
1617 __func__
, FREETAB_SIZE(db
+ 1));
1621 for (i
= freetab
->naents
; i
< db
; i
++)
1622 freetab
->ents
[i
] = e
;
1623 freetab
->naents
= db
+ 1;
1626 /* check the data block */
1627 while (ptr
< endptr
) {
1629 /* check for freespace */
1630 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1631 if (XFS_DIR2_DATA_FREE_TAG
== be16_to_cpu(dup
->freetag
)) {
1633 /* check for invalid freespace length */
1634 if (ptr
+ be16_to_cpu(dup
->length
) > endptr
||
1635 be16_to_cpu(dup
->length
) == 0 ||
1636 (be16_to_cpu(dup
->length
) &
1637 (XFS_DIR2_DATA_ALIGN
- 1)))
1640 /* check for invalid tag */
1641 if (be16_to_cpu(*xfs_dir2_data_unused_tag_p(dup
)) !=
1642 (char *)dup
- (char *)d
)
1645 /* check for block with no data entries */
1646 if ((ptr
== (char *)M_DIROPS(mp
)->data_entry_p(d
)) &&
1647 (ptr
+ be16_to_cpu(dup
->length
) >= endptr
)) {
1653 /* continue at the end of the freespace */
1654 ptr
+= be16_to_cpu(dup
->length
);
1659 /* validate data entry size */
1660 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1661 if (ptr
+ M_DIROPS(mp
)->data_entsize(dep
->namelen
) > endptr
)
1663 if (be16_to_cpu(*M_DIROPS(mp
)->data_entry_tag_p(dep
)) !=
1664 (char *)dep
- (char *)d
)
1666 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1669 /* did we find an empty or corrupt block? */
1670 if (ptr
!= endptr
) {
1673 _("empty data block %u in directory inode %" PRIu64
": "),
1677 ("corrupt block %u in directory inode %" PRIu64
": "),
1681 do_warn(_("junking block\n"));
1682 dir2_kill_block(mp
, ip
, da_bno
, bp
);
1684 do_warn(_("would junk block\n"));
1687 freetab
->ents
[db
].v
= NULLDATAOFF
;
1692 /* update number of data blocks processed */
1693 if (freetab
->nents
< db
+ 1)
1694 freetab
->nents
= db
+ 1;
1696 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
, 0, 0, 0, &tp
);
1700 libxfs_trans_ijoin(tp
, ip
, 0);
1701 libxfs_trans_bjoin(tp
, bp
);
1702 libxfs_trans_bhold(tp
, bp
);
1703 libxfs_defer_init(&dfops
, &firstblock
);
1704 if (be32_to_cpu(d
->magic
) != wantmagic
) {
1706 _("bad directory block magic # %#x for directory inode %" PRIu64
" block %d: "),
1707 be32_to_cpu(d
->magic
), ip
->i_ino
, da_bno
);
1709 do_warn(_("fixing magic # to %#x\n"), wantmagic
);
1710 d
->magic
= cpu_to_be32(wantmagic
);
1713 do_warn(_("would fix magic # to %#x\n"), wantmagic
);
1716 ptr
= (char *)M_DIROPS(mp
)->data_entry_p(d
);
1718 * look at each entry. reference inode pointed to by each
1719 * entry in the incore inode tree.
1720 * if not a directory, set reached flag, increment link count
1721 * if a directory and reached, mark entry as to be deleted.
1722 * if a directory, check to see if recorded parent
1723 * matches current inode #,
1724 * if so, then set reached flag, increment link count
1725 * of current and child dir inodes, push the child
1726 * directory inode onto the directory stack.
1727 * if current inode != parent, then mark entry to be deleted.
1729 while (ptr
< endptr
) {
1730 dup
= (xfs_dir2_data_unused_t
*)ptr
;
1731 if (be16_to_cpu(dup
->freetag
) == XFS_DIR2_DATA_FREE_TAG
) {
1734 _("directory inode %" PRIu64
" block %u has consecutive free entries: "),
1738 do_warn(_("joining together\n"));
1739 len
= be16_to_cpu(dup
->length
);
1740 libxfs_dir2_data_use_free(&da
, bp
, dup
,
1741 ptr
- (char *)d
, len
, &needlog
,
1743 libxfs_dir2_data_make_free(&da
, bp
,
1744 ptr
- (char *)d
, len
, &needlog
,
1747 do_warn(_("would join together\n"));
1749 ptr
+= be16_to_cpu(dup
->length
);
1753 addr
= xfs_dir2_db_off_to_dataptr(mp
->m_dir_geo
, db
,
1755 dep
= (xfs_dir2_data_entry_t
*)ptr
;
1756 ptr
+= M_DIROPS(mp
)->data_entsize(dep
->namelen
);
1757 inum
= be64_to_cpu(dep
->inumber
);
1760 * skip bogus entries (leading '/'). they'll be deleted
1761 * later. must still log it, else we leak references to
1764 if (dep
->name
[0] == '/') {
1767 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1771 memmove(fname
, dep
->name
, dep
->namelen
);
1772 fname
[dep
->namelen
] = '\0';
1773 ASSERT(inum
!= NULLFSINO
);
1775 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, inum
),
1776 XFS_INO_TO_AGINO(mp
, inum
));
1780 _("entry \"%s\" in directory inode %" PRIu64
" points to non-existent inode %" PRIu64
""),
1781 fname
, ip
->i_ino
, inum
)) {
1783 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1787 ino_offset
= XFS_INO_TO_AGINO(mp
, inum
) - irec
->ino_startnum
;
1790 * if it's a free inode, blow out the entry.
1791 * by now, any inode that we think is free
1794 if (is_inode_free(irec
, ino_offset
)) {
1797 _("entry \"%s\" in directory inode %" PRIu64
" points to free inode %" PRIu64
),
1798 fname
, ip
->i_ino
, inum
)) {
1800 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1806 * check if this inode is lost+found dir in the root
1808 if (inum
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
1810 * if it's not a directory, trash it
1812 if (!inode_isadir(irec
, ino_offset
)) {
1815 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
1816 ORPHANAGE
, inum
, ip
->i_ino
)) {
1818 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1823 * if this is a dup, it will be picked up below,
1824 * otherwise, mark it as the orphanage for later.
1827 orphanage_ino
= inum
;
1831 * check for duplicate names in directory.
1833 if (!dir_hash_add(mp
, hashtab
, addr
, inum
, dep
->namelen
,
1834 dep
->name
, M_DIROPS(mp
)->data_get_ftype(dep
))) {
1837 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
1838 fname
, inum
, ip
->i_ino
)) {
1840 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1842 if (inum
== orphanage_ino
)
1848 * if just scanning to rebuild a directory due to a ".."
1849 * update, just continue
1855 * skip the '..' entry since it's checked when the
1856 * directory is reached by something else. if it never
1857 * gets reached, it'll be moved to the orphanage and we'll
1858 * take care of it then. If it doesn't exist at all, the
1859 * directory needs to be rebuilt first before being added
1862 if (dep
->namelen
== 2 && dep
->name
[0] == '.' &&
1863 dep
->name
[1] == '.') {
1865 /* ".." should be in the first block */
1868 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is not in the the first block"), fname
,
1871 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1876 ASSERT(no_modify
|| !verify_inum(mp
, inum
));
1878 * special case the . entry. we know there's only one
1879 * '.' and only '.' points to itself because bogus entries
1880 * got trashed in phase 3 if there were > 1.
1881 * bump up link count for '.' but don't set reached
1882 * until we're actually reached by another directory
1883 * '..' is already accounted for or will be taken care
1884 * of when directory is moved to orphanage.
1886 if (ip
->i_ino
== inum
) {
1887 ASSERT(dep
->name
[0] == '.' && dep
->namelen
== 1);
1888 add_inode_ref(current_irec
, current_ino_offset
);
1890 dep
!= M_DIROPS(mp
)->data_entry_p(d
)) {
1891 /* "." should be the first entry */
1894 _("entry \"%s\" in dir %" PRIu64
" is not the first entry"),
1895 fname
, inum
, ip
->i_ino
)) {
1897 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1904 * skip entries with bogus inumbers if we're in no modify mode
1906 if (no_modify
&& verify_inum(mp
, inum
))
1909 /* validate ftype field if supported */
1910 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
1914 dir_ftype
= M_DIROPS(mp
)->data_get_ftype(dep
);
1915 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
1917 if (dir_ftype
!= ino_ftype
) {
1920 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1921 dir_ftype
, ino_ftype
,
1925 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
1926 dir_ftype
, ino_ftype
,
1928 M_DIROPS(mp
)->data_put_ftype(dep
,
1930 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1931 dir_hash_update_ftype(hashtab
, addr
,
1938 * check easy case first, regular inode, just bump
1939 * the link count and continue
1941 if (!inode_isadir(irec
, ino_offset
)) {
1942 add_inode_reached(irec
, ino_offset
);
1945 parent
= get_inode_parent(irec
, ino_offset
);
1946 ASSERT(parent
!= 0);
1949 * bump up the link counts in parent and child
1950 * directory but if the link doesn't agree with
1951 * the .. in the child, blow out the entry.
1952 * if the directory has already been reached,
1953 * blow away the entry also.
1955 if (is_inode_reached(irec
, ino_offset
)) {
1958 _("entry \"%s\" in dir %" PRIu64
" points to an already connected directory inode %" PRIu64
"\n"),
1959 fname
, ip
->i_ino
, inum
);
1960 } else if (parent
== ip
->i_ino
) {
1961 add_inode_reached(irec
, ino_offset
);
1962 add_inode_ref(current_irec
, current_ino_offset
);
1963 } else if (parent
== NULLFSINO
) {
1964 /* ".." was missing, but this entry refers to it,
1965 so, set it as the parent and mark for rebuild */
1967 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
1968 fname
, ip
->i_ino
, inum
);
1969 set_inode_parent(irec
, ino_offset
, ip
->i_ino
);
1970 add_inode_reached(irec
, ino_offset
);
1971 add_inode_ref(current_irec
, current_ino_offset
);
1972 add_dotdot_update(XFS_INO_TO_AGNO(mp
, inum
), irec
,
1977 _("entry \"%s\" in dir inode %" PRIu64
" inconsistent with .. value (%" PRIu64
") in ino %" PRIu64
"\n"),
1978 fname
, ip
->i_ino
, parent
, inum
);
1981 if (inum
== orphanage_ino
)
1986 libxfs_dir2_data_log_entry(&da
, bp
, dep
);
1989 _("\twill clear entry \"%s\"\n"),
1992 do_warn(_("\twould clear entry \"%s\"\n"),
1997 *num_illegal
+= nbad
;
1999 libxfs_dir2_data_freescan_int(mp
->m_dir_geo
, M_DIROPS(mp
),
2002 libxfs_dir2_data_log_header(&da
, bp
);
2003 libxfs_defer_ijoin(&dfops
, ip
);
2004 libxfs_defer_finish(&tp
, &dfops
);
2005 libxfs_trans_commit(tp
);
2007 /* record the largest free space in the freetab for later checking */
2008 bf
= M_DIROPS(mp
)->data_bestfree_p(d
);
2009 freetab
->ents
[db
].v
= be16_to_cpu(bf
[0].length
);
2010 freetab
->ents
[db
].s
= 0;
2013 /* check v5 metadata */
2015 __check_dir3_header(
2016 struct xfs_mount
*mp
,
2025 if (be64_to_cpu(owner
) != ino
) {
2027 _("expected owner inode %" PRIu64
", got %llu, directory block %" PRIu64
"\n"),
2028 ino
, (unsigned long long)be64_to_cpu(owner
), bp
->b_bn
);
2031 /* verify block number */
2032 if (be64_to_cpu(blkno
) != bp
->b_bn
) {
2034 _("expected block %" PRIu64
", got %llu, directory inode %" PRIu64
"\n"),
2035 bp
->b_bn
, (unsigned long long)be64_to_cpu(blkno
), ino
);
2039 if (platform_uuid_compare(uuid
, &mp
->m_sb
.sb_meta_uuid
) != 0) {
2041 _("wrong FS UUID, directory inode %" PRIu64
" block %" PRIu64
"\n"),
2051 struct xfs_mount
*mp
,
2055 struct xfs_da3_blkinfo
*info
= bp
->b_addr
;
2057 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2063 struct xfs_mount
*mp
,
2067 struct xfs_dir3_blk_hdr
*info
= bp
->b_addr
;
2069 return __check_dir3_header(mp
, bp
, ino
, info
->owner
, info
->blkno
,
2074 * Check contents of leaf-form block.
2077 longform_dir2_check_leaf(
2080 dir_hash_tab_t
*hashtab
,
2088 xfs_dir2_leaf_t
*leaf
;
2089 xfs_dir2_leaf_tail_t
*ltp
;
2091 struct xfs_dir2_leaf_entry
*ents
;
2092 struct xfs_dir3_icleaf_hdr leafhdr
;
2096 da_bno
= mp
->m_dir_geo
->leafblk
;
2097 error
= dir_read_buf(ip
, da_bno
, -1, &bp
, &xfs_dir3_leaf1_buf_ops
,
2099 if (error
== EFSBADCRC
|| error
== EFSCORRUPTED
|| fixit
) {
2101 _("leaf block %u for directory inode %" PRIu64
" bad CRC\n"),
2106 _("can't read block %u for directory inode %" PRIu64
", error %d\n"),
2107 da_bno
, ip
->i_ino
, error
);
2112 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2113 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2114 ltp
= xfs_dir2_leaf_tail_p(mp
->m_dir_geo
, leaf
);
2115 bestsp
= xfs_dir2_leaf_bests_p(ltp
);
2116 if (!(leafhdr
.magic
== XFS_DIR2_LEAF1_MAGIC
||
2117 leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) ||
2118 leafhdr
.forw
|| leafhdr
.back
||
2119 leafhdr
.count
< leafhdr
.stale
||
2121 M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2122 (char *)&ents
[leafhdr
.count
] > (char *)bestsp
) {
2124 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2130 if (leafhdr
.magic
== XFS_DIR3_LEAF1_MAGIC
) {
2131 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2138 seeval
= dir_hash_see_all(hashtab
, ents
, leafhdr
.count
, leafhdr
.stale
);
2139 if (dir_hash_check(hashtab
, ip
, seeval
)) {
2143 badtail
= freetab
->nents
!= be32_to_cpu(ltp
->bestcount
);
2144 for (i
= 0; !badtail
&& i
< be32_to_cpu(ltp
->bestcount
); i
++) {
2145 freetab
->ents
[i
].s
= 1;
2146 badtail
= freetab
->ents
[i
].v
!= be16_to_cpu(bestsp
[i
]);
2150 _("leaf block %u for directory inode %" PRIu64
" bad tail\n"),
2160 * Check contents of the node blocks (leaves)
2161 * Looks for matching hash values for the data entries.
2164 longform_dir2_check_node(
2167 dir_hash_tab_t
*hashtab
,
2173 xfs_dir2_free_t
*free
;
2175 xfs_dir2_leaf_t
*leaf
;
2176 xfs_fileoff_t next_da_bno
;
2179 struct xfs_dir2_leaf_entry
*ents
;
2180 struct xfs_dir3_icleaf_hdr leafhdr
;
2181 struct xfs_dir3_icfree_hdr freehdr
;
2186 for (da_bno
= mp
->m_dir_geo
->leafblk
, next_da_bno
= 0;
2187 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->freeblk
;
2188 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2189 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2190 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2194 * we need to use the da3 node verifier here as it handles the
2195 * fact that reading the leaf hash tree blocks can return either
2196 * leaf or node blocks and calls the correct verifier. If we get
2197 * a node block, then we'll skip it below based on a magic
2200 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2201 &xfs_da3_node_buf_ops
, &fixit
);
2204 _("can't read leaf block %u for directory inode %" PRIu64
", error %d\n"),
2205 da_bno
, ip
->i_ino
, error
);
2209 M_DIROPS(mp
)->leaf_hdr_from_disk(&leafhdr
, leaf
);
2210 ents
= M_DIROPS(mp
)->leaf_ents_p(leaf
);
2211 if (!(leafhdr
.magic
== XFS_DIR2_LEAFN_MAGIC
||
2212 leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2213 leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2214 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
)) {
2216 _("unknown magic number %#x for block %u in directory inode %" PRIu64
"\n"),
2217 leafhdr
.magic
, da_bno
, ip
->i_ino
);
2222 /* check v5 metadata */
2223 if (leafhdr
.magic
== XFS_DIR3_LEAFN_MAGIC
||
2224 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2225 error
= check_da3_header(mp
, bp
, ip
->i_ino
);
2233 if (leafhdr
.magic
== XFS_DA_NODE_MAGIC
||
2234 leafhdr
.magic
== XFS_DA3_NODE_MAGIC
) {
2240 * If there's a validator error, we need to ensure that we got
2241 * the right ops on the buffer for when we write it back out.
2243 bp
->b_ops
= &xfs_dir3_leafn_buf_ops
;
2244 if (leafhdr
.count
> M_DIROPS(mp
)->leaf_max_ents(mp
->m_dir_geo
) ||
2245 leafhdr
.count
< leafhdr
.stale
) {
2247 _("leaf block %u for directory inode %" PRIu64
" bad header\n"),
2252 seeval
= dir_hash_see_all(hashtab
, ents
,
2253 leafhdr
.count
, leafhdr
.stale
);
2255 if (seeval
!= DIR_HASH_CK_OK
)
2258 if (dir_hash_check(hashtab
, ip
, seeval
))
2261 for (da_bno
= mp
->m_dir_geo
->freeblk
, next_da_bno
= 0;
2262 next_da_bno
!= NULLFILEOFF
;
2263 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2264 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2265 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
))
2268 error
= dir_read_buf(ip
, da_bno
, -1, &bp
,
2269 &xfs_dir3_free_buf_ops
, &fixit
);
2272 _("can't read freespace block %u for directory inode %" PRIu64
", error %d\n"),
2273 da_bno
, ip
->i_ino
, error
);
2277 M_DIROPS(mp
)->free_hdr_from_disk(&freehdr
, free
);
2278 bests
= M_DIROPS(mp
)->free_bests_p(free
);
2279 fdb
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2280 if (!(freehdr
.magic
== XFS_DIR2_FREE_MAGIC
||
2281 freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) ||
2283 (fdb
- xfs_dir2_byte_to_db(mp
->m_dir_geo
, XFS_DIR2_FREE_OFFSET
)) *
2284 M_DIROPS(mp
)->free_max_bests(mp
->m_dir_geo
) ||
2285 freehdr
.nvalid
< freehdr
.nused
) {
2287 _("free block %u for directory inode %" PRIu64
" bad header\n"),
2293 if (freehdr
.magic
== XFS_DIR3_FREE_MAGIC
) {
2294 error
= check_dir3_header(mp
, bp
, ip
->i_ino
);
2300 for (i
= used
= 0; i
< freehdr
.nvalid
; i
++) {
2301 if (i
+ freehdr
.firstdb
>= freetab
->nents
||
2302 freetab
->ents
[i
+ freehdr
.firstdb
].v
!=
2303 be16_to_cpu(bests
[i
])) {
2305 _("free block %u entry %i for directory ino %" PRIu64
" bad\n"),
2306 da_bno
, i
, ip
->i_ino
);
2310 used
+= be16_to_cpu(bests
[i
]) != NULLDATAOFF
;
2311 freetab
->ents
[i
+ freehdr
.firstdb
].s
= 1;
2313 if (used
!= freehdr
.nused
) {
2315 _("free block %u for directory inode %" PRIu64
" bad nused\n"),
2322 for (i
= 0; i
< freetab
->nents
; i
++) {
2323 if ((freetab
->ents
[i
].s
== 0) &&
2324 (freetab
->ents
[i
].v
!= NULLDATAOFF
)) {
2326 _("missing freetab entry %u for directory inode %" PRIu64
"\n"),
2335 * If a directory is corrupt, we need to read in as many entries as possible,
2336 * destroy the entry and create a new one with recovered name/inode pairs.
2337 * (ie. get libxfs to do all the grunt work)
2340 longform_dir2_entry_check(xfs_mount_t
*mp
,
2345 ino_tree_node_t
*irec
,
2347 dir_hash_tab_t
*hashtab
)
2349 struct xfs_buf
**bplist
;
2356 xfs_fileoff_t next_da_bno
;
2360 struct xfs_da_args args
;
2363 freetab
= malloc(FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2365 do_error(_("malloc failed in %s (%" PRId64
" bytes)\n"),
2367 FREETAB_SIZE(ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
));
2370 freetab
->naents
= ip
->i_d
.di_size
/ mp
->m_dir_geo
->blksize
;
2372 for (i
= 0; i
< freetab
->naents
; i
++) {
2373 freetab
->ents
[i
].v
= NULLDATAOFF
;
2374 freetab
->ents
[i
].s
= 0;
2376 num_bps
= freetab
->naents
;
2377 bplist
= calloc(num_bps
, sizeof(struct xfs_buf
*));
2379 do_error(_("calloc failed in %s (%zu bytes)\n"),
2380 __func__
, num_bps
* sizeof(struct xfs_buf
*));
2382 /* is this a block, leaf, or node directory? */
2384 args
.geo
= mp
->m_dir_geo
;
2385 libxfs_dir2_isblock(&args
, &isblock
);
2386 libxfs_dir2_isleaf(&args
, &isleaf
);
2388 /* check directory "data" blocks (ie. name/inode pairs) */
2389 for (da_bno
= 0, next_da_bno
= 0;
2390 next_da_bno
!= NULLFILEOFF
&& da_bno
< mp
->m_dir_geo
->leafblk
;
2391 da_bno
= (xfs_dablk_t
)next_da_bno
) {
2392 const struct xfs_buf_ops
*ops
;
2394 struct xfs_dir2_data_hdr
*d
;
2396 next_da_bno
= da_bno
+ mp
->m_dir_geo
->fsbcount
- 1;
2397 if (bmap_next_offset(NULL
, ip
, &next_da_bno
, XFS_DATA_FORK
)) {
2399 * if this is the first block, there isn't anything we
2400 * can recover so we just trash it.
2409 db
= xfs_dir2_da_to_db(mp
->m_dir_geo
, da_bno
);
2410 if (db
>= num_bps
) {
2411 /* more data blocks than expected */
2413 bplist
= realloc(bplist
, num_bps
* sizeof(struct xfs_buf
*));
2415 do_error(_("realloc failed in %s (%zu bytes)\n"),
2417 num_bps
* sizeof(struct xfs_buf
*));
2421 ops
= &xfs_dir3_block_buf_ops
;
2423 ops
= &xfs_dir3_data_buf_ops
;
2425 error
= dir_read_buf(ip
, da_bno
, -1, &bplist
[db
], ops
, &fixit
);
2428 _("can't read data block %u for directory inode %" PRIu64
" error %d\n"),
2429 da_bno
, ino
, error
);
2433 * we try to read all "data" blocks, but if we are in
2434 * block form and we fail, there isn't anything else to
2435 * read, and nothing we can do but trash it.
2444 /* check v5 metadata */
2445 d
= bplist
[db
]->b_addr
;
2446 if (be32_to_cpu(d
->magic
) == XFS_DIR3_BLOCK_MAGIC
||
2447 be32_to_cpu(d
->magic
) == XFS_DIR3_DATA_MAGIC
) {
2448 struct xfs_buf
*bp
= bplist
[db
];
2450 error
= check_dir3_header(mp
, bp
, ino
);
2457 longform_dir2_entry_check_data(mp
, ip
, num_illegal
, need_dot
,
2458 irec
, ino_offset
, &bplist
[db
], hashtab
,
2459 &freetab
, da_bno
, isblock
);
2461 fixit
|= (*num_illegal
!= 0) || dir2_is_badino(ino
) || *need_dot
;
2463 if (!dotdot_update
) {
2464 /* check btree and freespace */
2466 struct xfs_dir2_data_hdr
*block
;
2467 xfs_dir2_block_tail_t
*btp
;
2468 xfs_dir2_leaf_entry_t
*blp
;
2470 block
= bplist
[0]->b_addr
;
2471 btp
= xfs_dir2_block_tail_p(mp
->m_dir_geo
, block
);
2472 blp
= xfs_dir2_block_leaf_p(btp
);
2473 seeval
= dir_hash_see_all(hashtab
, blp
,
2474 be32_to_cpu(btp
->count
),
2475 be32_to_cpu(btp
->stale
));
2476 if (dir_hash_check(hashtab
, ip
, seeval
))
2478 } else if (isleaf
) {
2479 fixit
|= longform_dir2_check_leaf(mp
, ip
, hashtab
,
2482 fixit
|= longform_dir2_check_node(mp
, ip
, hashtab
,
2487 if (!no_modify
&& (fixit
|| dotdot_update
)) {
2488 dir_hash_dup_names(hashtab
);
2489 for (i
= 0; i
< num_bps
; i
++)
2491 libxfs_putbuf(bplist
[i
]);
2492 longform_dir2_rebuild(mp
, ino
, ip
, irec
, ino_offset
, hashtab
);
2496 for (i
= 0; i
< num_bps
; i
++)
2498 libxfs_putbuf(bplist
[i
]);
2506 * shortform directory v2 processing routines -- entry verification and
2507 * bad entry deletion (pruning).
2509 static struct xfs_dir2_sf_entry
*
2510 shortform_dir2_junk(
2511 struct xfs_mount
*mp
,
2512 struct xfs_dir2_sf_hdr
*sfp
,
2513 struct xfs_dir2_sf_entry
*sfep
,
2520 struct xfs_dir2_sf_entry
*next_sfep
;
2524 if (lino
== orphanage_ino
)
2527 next_elen
= M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
);
2528 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2531 * if we are just checking, simply return the pointer to the next entry
2532 * here so that the checking loop can continue.
2535 do_warn(_("would junk entry\n"));
2540 * now move all the remaining entries down over the junked entry and
2541 * clear the newly unused bytes at the tail of the directory region.
2543 next_len
= *max_size
- ((intptr_t)next_sfep
- (intptr_t)sfp
);
2544 *max_size
-= next_elen
;
2545 *bytes_deleted
+= next_elen
;
2547 memmove(sfep
, next_sfep
, next_len
);
2548 memset((void *)((intptr_t)sfep
+ next_len
), 0, next_elen
);
2553 * WARNING: drop the index i by one so it matches the decremented count
2554 * for accurate comparisons in the loop test
2559 do_warn(_("junking entry\n"));
2566 shortform_dir2_entry_check(xfs_mount_t
*mp
,
2570 ino_tree_node_t
*current_irec
,
2571 int current_ino_offset
,
2572 dir_hash_tab_t
*hashtab
)
2576 struct xfs_dir2_sf_hdr
*sfp
;
2577 struct xfs_dir2_sf_entry
*sfep
;
2578 struct xfs_dir2_sf_entry
*next_sfep
;
2579 struct xfs_ifork
*ifp
;
2580 struct ino_tree_node
*irec
;
2587 char fname
[MAXNAMELEN
+ 1];
2591 sfp
= (struct xfs_dir2_sf_hdr
*) ifp
->if_u1
.if_data
;
2595 max_size
= ifp
->if_bytes
;
2596 ASSERT(ip
->i_d
.di_size
<= ifp
->if_bytes
);
2599 * if just rebuild a directory due to a "..", update and return
2601 if (dotdot_update
) {
2602 parent
= get_inode_parent(current_irec
, current_ino_offset
);
2605 _("would set .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2609 _("setting .. in sf dir inode %" PRIu64
" to %" PRIu64
"\n"),
2611 M_DIROPS(mp
)->sf_put_parent_ino(sfp
, parent
);
2618 * no '.' entry in shortform dirs, just bump up ref count by 1
2619 * '..' was already (or will be) accounted for and checked when
2620 * the directory is reached or will be taken care of when the
2621 * directory is moved to orphanage.
2623 add_inode_ref(current_irec
, current_ino_offset
);
2626 * Initialise i8 counter -- the parent inode number counts as well.
2628 i8
= M_DIROPS(mp
)->sf_get_parent_ino(sfp
) > XFS_DIR2_MAX_SHORT_INUM
;
2631 * now run through entries, stop at first bad entry, don't need
2632 * to skip over '..' since that's encoded in its own field and
2633 * no need to worry about '.' since it doesn't exist.
2635 sfep
= next_sfep
= xfs_dir2_sf_firstentry(sfp
);
2637 for (i
= 0; i
< sfp
->count
&& max_size
>
2638 (intptr_t)next_sfep
- (intptr_t)sfp
;
2639 sfep
= next_sfep
, i
++) {
2642 lino
= M_DIROPS(mp
)->sf_get_ino(sfp
, sfep
);
2644 namelen
= sfep
->namelen
;
2646 ASSERT(no_modify
|| namelen
> 0);
2648 if (no_modify
&& namelen
== 0) {
2650 * if we're really lucky, this is
2651 * the last entry in which case we
2652 * can use the dir size to set the
2653 * namelen value. otherwise, forget
2654 * it because we're not going to be
2655 * able to find the next entry.
2659 if (i
== sfp
->count
- 1) {
2660 namelen
= ip
->i_d
.di_size
-
2661 ((intptr_t) &sfep
->name
[0] -
2665 * don't process the rest of the directory,
2666 * break out of processing loop
2670 } else if (no_modify
&& (intptr_t) sfep
- (intptr_t) sfp
+
2671 + M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)
2672 > ip
->i_d
.di_size
) {
2675 if (i
== sfp
->count
- 1) {
2676 namelen
= ip
->i_d
.di_size
-
2677 ((intptr_t) &sfep
->name
[0] -
2681 * don't process the rest of the directory,
2682 * break out of processing loop
2688 memmove(fname
, sfep
->name
, sfep
->namelen
);
2689 fname
[sfep
->namelen
] = '\0';
2691 ASSERT(no_modify
|| (lino
!= NULLFSINO
&& lino
!= 0));
2692 ASSERT(no_modify
|| !verify_inum(mp
, lino
));
2695 * Also skip entries with bogus inode numbers if we're
2696 * in no modify mode.
2699 if (no_modify
&& verify_inum(mp
, lino
)) {
2700 next_sfep
= M_DIROPS(mp
)->sf_nextentry(sfp
, sfep
);
2704 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, lino
),
2705 XFS_INO_TO_AGINO(mp
, lino
));
2709 _("entry \"%s\" in shortform directory %" PRIu64
" references non-existent inode %" PRIu64
"\n"),
2711 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2712 &max_size
, &i
, &bytes_deleted
,
2717 ino_offset
= XFS_INO_TO_AGINO(mp
, lino
) - irec
->ino_startnum
;
2720 * if it's a free inode, blow out the entry.
2721 * by now, any inode that we think is free
2724 if (is_inode_free(irec
, ino_offset
)) {
2726 _("entry \"%s\" in shortform directory inode %" PRIu64
" points to free inode %" PRIu64
"\n"),
2728 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2729 &max_size
, &i
, &bytes_deleted
,
2734 * check if this inode is lost+found dir in the root
2736 if (ino
== mp
->m_sb
.sb_rootino
&& strcmp(fname
, ORPHANAGE
) == 0) {
2738 * if it's not a directory, trash it
2740 if (!inode_isadir(irec
, ino_offset
)) {
2742 _("%s (ino %" PRIu64
") in root (%" PRIu64
") is not a directory"),
2743 ORPHANAGE
, lino
, ino
);
2744 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2745 lino
, &max_size
, &i
,
2746 &bytes_deleted
, ino_dirty
);
2750 * if this is a dup, it will be picked up below,
2751 * otherwise, mark it as the orphanage for later.
2754 orphanage_ino
= lino
;
2757 * check for duplicate names in directory.
2759 if (!dir_hash_add(mp
, hashtab
, (xfs_dir2_dataptr_t
)
2760 (sfep
- xfs_dir2_sf_firstentry(sfp
)),
2761 lino
, sfep
->namelen
, sfep
->name
,
2762 M_DIROPS(mp
)->sf_get_ftype(sfep
))) {
2764 _("entry \"%s\" (ino %" PRIu64
") in dir %" PRIu64
" is a duplicate name"),
2766 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
, lino
,
2767 &max_size
, &i
, &bytes_deleted
,
2772 if (!inode_isadir(irec
, ino_offset
)) {
2774 * check easy case first, regular inode, just bump
2777 add_inode_reached(irec
, ino_offset
);
2779 parent
= get_inode_parent(irec
, ino_offset
);
2782 * bump up the link counts in parent and child.
2783 * directory but if the link doesn't agree with
2784 * the .. in the child, blow out the entry
2786 if (is_inode_reached(irec
, ino_offset
)) {
2788 _("entry \"%s\" in directory inode %" PRIu64
2789 " references already connected inode %" PRIu64
".\n"),
2791 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2792 lino
, &max_size
, &i
,
2793 &bytes_deleted
, ino_dirty
);
2795 } else if (parent
== ino
) {
2796 add_inode_reached(irec
, ino_offset
);
2797 add_inode_ref(current_irec
, current_ino_offset
);
2798 } else if (parent
== NULLFSINO
) {
2799 /* ".." was missing, but this entry refers to it,
2800 so, set it as the parent and mark for rebuild */
2802 _("entry \"%s\" in dir ino %" PRIu64
" doesn't have a .. entry, will set it in ino %" PRIu64
".\n"),
2804 set_inode_parent(irec
, ino_offset
, ino
);
2805 add_inode_reached(irec
, ino_offset
);
2806 add_inode_ref(current_irec
, current_ino_offset
);
2807 add_dotdot_update(XFS_INO_TO_AGNO(mp
, lino
),
2811 _("entry \"%s\" in directory inode %" PRIu64
2812 " not consistent with .. value (%" PRIu64
2813 ") in inode %" PRIu64
",\n"),
2814 fname
, ino
, parent
, lino
);
2815 next_sfep
= shortform_dir2_junk(mp
, sfp
, sfep
,
2816 lino
, &max_size
, &i
,
2817 &bytes_deleted
, ino_dirty
);
2822 /* validate ftype field if supported */
2823 if (xfs_sb_version_hasftype(&mp
->m_sb
)) {
2827 dir_ftype
= M_DIROPS(mp
)->sf_get_ftype(sfep
);
2828 ino_ftype
= get_inode_ftype(irec
, ino_offset
);
2830 if (dir_ftype
!= ino_ftype
) {
2833 _("would fix ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2834 dir_ftype
, ino_ftype
,
2838 _("fixing ftype mismatch (%d/%d) in directory/child inode %" PRIu64
"/%" PRIu64
"\n"),
2839 dir_ftype
, ino_ftype
,
2841 M_DIROPS(mp
)->sf_put_ftype(sfep
,
2843 dir_hash_update_ftype(hashtab
,
2844 (xfs_dir2_dataptr_t
)(sfep
- xfs_dir2_sf_firstentry(sfp
)),
2851 if (lino
> XFS_DIR2_MAX_SHORT_INUM
)
2855 * go onto next entry - we have to take entries with bad namelen
2856 * into account in no modify mode since we calculate size based
2859 ASSERT(no_modify
|| bad_sfnamelen
== 0);
2860 next_sfep
= (struct xfs_dir2_sf_entry
*)((intptr_t)sfep
+
2862 ? M_DIROPS(mp
)->sf_entsize(sfp
, namelen
)
2863 : M_DIROPS(mp
)->sf_entsize(sfp
, sfep
->namelen
)));
2866 if (sfp
->i8count
!= i8
) {
2868 do_warn(_("would fix i8count in inode %" PRIu64
"\n"),
2872 struct xfs_dir2_sf_entry
*tmp_sfep
;
2874 tmp_sfep
= next_sfep
;
2875 process_sf_dir2_fixi8(mp
, sfp
, &tmp_sfep
);
2877 (intptr_t)next_sfep
-
2879 next_sfep
= tmp_sfep
;
2883 do_warn(_("fixing i8count in inode %" PRIu64
"\n"),
2889 * sync up sizes if required
2891 if (*ino_dirty
&& bytes_deleted
> 0) {
2893 libxfs_idata_realloc(ip
, -bytes_deleted
, XFS_DATA_FORK
);
2894 ip
->i_d
.di_size
-= bytes_deleted
;
2897 if (ip
->i_d
.di_size
!= ip
->i_df
.if_bytes
) {
2898 ASSERT(ip
->i_df
.if_bytes
== (xfs_fsize_t
)
2899 ((intptr_t) next_sfep
- (intptr_t) sfp
));
2900 ip
->i_d
.di_size
= (xfs_fsize_t
)
2901 ((intptr_t) next_sfep
- (intptr_t) sfp
);
2903 _("setting size to %" PRId64
" bytes to reflect junked entries\n"),
2910 * processes all reachable inodes in directories
2915 xfs_agnumber_t agno
,
2916 ino_tree_node_t
*irec
,
2920 struct xfs_defer_ops dfops
;
2921 xfs_fsblock_t first
;
2924 dir_hash_tab_t
*hashtab
;
2926 int dirty
, num_illegal
, error
, nres
;
2928 ino
= XFS_AGINO_TO_INO(mp
, agno
, irec
->ino_startnum
+ ino_offset
);
2931 * open up directory inode, check all entries,
2932 * then call prune_dir_entries to remove all
2933 * remaining illegal directory entries.
2936 ASSERT(!is_inode_refchecked(irec
, ino_offset
) || dotdot_update
);
2938 error
= -libxfs_iget(mp
, NULL
, ino
, 0, &ip
, &phase6_ifork_ops
);
2942 _("couldn't map inode %" PRIu64
", err = %d\n"),
2946 _("couldn't map inode %" PRIu64
", err = %d\n"),
2949 * see below for what we're doing if this
2950 * is root. Why do we need to do this here?
2951 * to ensure that the root doesn't show up
2952 * as being disconnected in the no_modify case.
2954 if (mp
->m_sb
.sb_rootino
== ino
) {
2955 add_inode_reached(irec
, 0);
2956 add_inode_ref(irec
, 0);
2960 add_inode_refchecked(irec
, 0);
2964 need_dot
= dirty
= num_illegal
= 0;
2966 if (mp
->m_sb
.sb_rootino
== ino
) {
2968 * mark root inode reached and bump up
2969 * link count for root inode to account
2970 * for '..' entry since the root inode is
2971 * never reached by a parent. we know
2972 * that root's '..' is always good --
2973 * guaranteed by phase 3 and/or below.
2975 add_inode_reached(irec
, ino_offset
);
2978 add_inode_refchecked(irec
, ino_offset
);
2980 hashtab
= dir_hash_init(ip
->i_d
.di_size
);
2983 * look for bogus entries
2985 switch (ip
->i_d
.di_format
) {
2986 case XFS_DINODE_FMT_EXTENTS
:
2987 case XFS_DINODE_FMT_BTREE
:
2989 * also check for missing '.' in longform dirs.
2990 * missing .. entries are added if required when
2991 * the directory is connected to lost+found. but
2992 * we need to create '.' entries here.
2994 longform_dir2_entry_check(mp
, ino
, ip
,
2995 &num_illegal
, &need_dot
,
3000 case XFS_DINODE_FMT_LOCAL
:
3002 * using the remove reservation is overkill
3003 * since at most we'll only need to log the
3004 * inode but it's easier than wedging a
3005 * new define in ourselves.
3007 nres
= no_modify
? 0 : XFS_REMOVE_SPACE_RES(mp
);
3008 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_remove
,
3013 libxfs_trans_ijoin(tp
, ip
, 0);
3015 shortform_dir2_entry_check(mp
, ino
, ip
, &dirty
,
3019 ASSERT(dirty
== 0 || (dirty
&& !no_modify
));
3021 libxfs_trans_log_inode(tp
, ip
,
3022 XFS_ILOG_CORE
| XFS_ILOG_DDATA
);
3023 libxfs_trans_commit(tp
);
3025 libxfs_trans_cancel(tp
);
3032 dir_hash_done(hashtab
);
3035 * if we have to create a .. for /, do it now *before*
3036 * we delete the bogus entries, otherwise the directory
3037 * could transform into a shortform dir which would
3038 * probably cause the simulation to choke. Even
3039 * if the illegal entries get shifted around, it's ok
3040 * because the entries are structurally intact and in
3041 * in hash-value order so the simulation won't get confused
3042 * if it has to move them around.
3044 if (!no_modify
&& need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
3045 ASSERT(ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
);
3047 do_warn(_("recreating root directory .. entry\n"));
3049 nres
= XFS_MKDIR_SPACE_RES(mp
, 2);
3050 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3055 libxfs_trans_ijoin(tp
, ip
, 0);
3057 libxfs_defer_init(&dfops
, &first
);
3059 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dotdot
,
3060 ip
->i_ino
, &first
, &dfops
, nres
);
3063 _("can't make \"..\" entry in root inode %" PRIu64
", createname error %d\n"), ino
, error
);
3065 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3067 libxfs_defer_ijoin(&dfops
, ip
);
3068 error
= -libxfs_defer_finish(&tp
, &dfops
);
3070 libxfs_trans_commit(tp
);
3072 need_root_dotdot
= 0;
3073 } else if (need_root_dotdot
&& ino
== mp
->m_sb
.sb_rootino
) {
3074 do_warn(_("would recreate root directory .. entry\n"));
3078 * if we need to create the '.' entry, do so only if
3079 * the directory is a longform dir. if it's been
3080 * turned into a shortform dir, then the inode is ok
3081 * since shortform dirs have no '.' entry and the inode
3082 * has already been committed by prune_lf_dir_entry().
3086 * bump up our link count but don't
3087 * bump up the inode link count. chances
3088 * are good that even though we lost '.'
3089 * the inode link counts reflect '.' so
3090 * leave the inode link count alone and if
3091 * it turns out to be wrong, we'll catch
3094 add_inode_ref(irec
, ino_offset
);
3098 _("would create missing \".\" entry in dir ino %" PRIu64
"\n"),
3100 } else if (ip
->i_d
.di_format
!= XFS_DINODE_FMT_LOCAL
) {
3102 * need to create . entry in longform dir.
3105 _("creating missing \".\" entry in dir ino %" PRIu64
"\n"), ino
);
3107 nres
= XFS_MKDIR_SPACE_RES(mp
, 1);
3108 error
= -libxfs_trans_alloc(mp
, &M_RES(mp
)->tr_mkdir
,
3113 libxfs_trans_ijoin(tp
, ip
, 0);
3115 libxfs_defer_init(&dfops
, &first
);
3117 error
= -libxfs_dir_createname(tp
, ip
, &xfs_name_dot
,
3118 ip
->i_ino
, &first
, &dfops
, nres
);
3121 _("can't make \".\" entry in dir ino %" PRIu64
", createname error %d\n"),
3124 libxfs_trans_log_inode(tp
, ip
, XFS_ILOG_CORE
);
3126 libxfs_defer_ijoin(&dfops
, ip
);
3127 error
= -libxfs_defer_finish(&tp
, &dfops
);
3129 libxfs_trans_commit(tp
);
3136 * mark realtime bitmap and summary inodes as reached.
3137 * quota inode will be marked here as well
3140 mark_standalone_inodes(xfs_mount_t
*mp
)
3142 ino_tree_node_t
*irec
;
3145 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rbmino
),
3146 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
));
3148 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rbmino
) -
3151 add_inode_reached(irec
, offset
);
3153 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rsumino
),
3154 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
));
3156 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rsumino
) -
3159 add_inode_reached(irec
, offset
);
3162 if (mp
->m_sb
.sb_uquotino
3163 && mp
->m_sb
.sb_uquotino
!= NULLFSINO
) {
3164 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3165 mp
->m_sb
.sb_uquotino
),
3166 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
));
3167 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_uquotino
)
3168 - irec
->ino_startnum
;
3169 add_inode_reached(irec
, offset
);
3171 if (mp
->m_sb
.sb_gquotino
3172 && mp
->m_sb
.sb_gquotino
!= NULLFSINO
) {
3173 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3174 mp
->m_sb
.sb_gquotino
),
3175 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
));
3176 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_gquotino
)
3177 - irec
->ino_startnum
;
3178 add_inode_reached(irec
, offset
);
3180 if (mp
->m_sb
.sb_pquotino
3181 && mp
->m_sb
.sb_pquotino
!= NULLFSINO
) {
3182 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
,
3183 mp
->m_sb
.sb_pquotino
),
3184 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
));
3185 offset
= XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_pquotino
)
3186 - irec
->ino_startnum
;
3187 add_inode_reached(irec
, offset
);
3193 check_for_orphaned_inodes(
3195 xfs_agnumber_t agno
,
3196 ino_tree_node_t
*irec
)
3201 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3202 ASSERT(is_inode_confirmed(irec
, i
));
3203 if (is_inode_free(irec
, i
))
3206 if (is_inode_reached(irec
, i
))
3209 ASSERT(inode_isadir(irec
, i
) ||
3210 num_inode_references(irec
, i
) == 0);
3212 ino
= XFS_AGINO_TO_INO(mp
, agno
, i
+ irec
->ino_startnum
);
3213 if (inode_isadir(irec
, i
))
3214 do_warn(_("disconnected dir inode %" PRIu64
", "), ino
);
3216 do_warn(_("disconnected inode %" PRIu64
", "), ino
);
3219 orphanage_ino
= mk_orphanage(mp
);
3220 do_warn(_("moving to %s\n"), ORPHANAGE
);
3221 mv_orphanage(mp
, ino
, inode_isadir(irec
, i
));
3223 do_warn(_("would move to %s\n"), ORPHANAGE
);
3226 * for read-only case, even though the inode isn't
3227 * really reachable, set the flag (and bump our link
3228 * count) anyway to fool phase 7
3230 add_inode_reached(irec
, i
);
3236 struct workqueue
*wq
,
3237 xfs_agnumber_t agno
,
3240 ino_tree_node_t
*irec
;
3242 prefetch_args_t
*pf_args
= arg
;
3244 wait_for_inode_prefetch(pf_args
);
3247 do_log(_(" - agno = %d\n"), agno
);
3249 for (irec
= findfirst_inode_rec(agno
); irec
; irec
= next_ino_rec(irec
)) {
3250 if (irec
->ino_isa_dir
== 0)
3254 sem_post(&pf_args
->ra_count
);
3256 sem_getvalue(&pf_args
->ra_count
, &i
);
3258 "processing inode chunk %p in AG %d (sem count = %d)",
3263 for (i
= 0; i
< XFS_INODES_PER_CHUNK
; i
++) {
3264 if (inode_isadir(irec
, i
))
3265 process_dir_inode(wq
->wq_ctx
, agno
, irec
, i
);
3268 cleanup_inode_prefetch(pf_args
);
3272 update_missing_dotdot_entries(
3275 dotdot_update_t
*dir
;
3278 * these entries parents were updated, rebuild them again
3279 * set dotdot_update flag so processing routines do not count links
3282 while (!list_empty(&dotdot_update_list
)) {
3283 dir
= list_entry(dotdot_update_list
.prev
, struct dotdot_update
,
3285 list_del(&dir
->list
);
3286 process_dir_inode(mp
, dir
->agno
, dir
->irec
, dir
->ino_offset
);
3293 struct xfs_mount
*mp
)
3295 do_inode_prefetch(mp
, 0, traverse_function
, false, true);
3299 phase6(xfs_mount_t
*mp
)
3301 ino_tree_node_t
*irec
;
3304 memset(&zerocr
, 0, sizeof(struct cred
));
3305 memset(&zerofsx
, 0, sizeof(struct fsxattr
));
3308 do_log(_("Phase 6 - check inode connectivity...\n"));
3310 incore_ext_teardown(mp
);
3312 add_ino_ex_data(mp
);
3315 * verify existence of root directory - if we have to
3316 * make one, it's ok for the incore data structs not to
3317 * know about it since everything about it (and the other
3318 * inodes in its chunk if a new chunk was created) are ok
3320 if (need_root_inode
) {
3322 do_warn(_("reinitializing root directory\n"));
3324 need_root_inode
= 0;
3325 need_root_dotdot
= 0;
3327 do_warn(_("would reinitialize root directory\n"));
3333 do_warn(_("reinitializing realtime bitmap inode\n"));
3337 do_warn(_("would reinitialize realtime bitmap inode\n"));
3343 do_warn(_("reinitializing realtime summary inode\n"));
3347 do_warn(_("would reinitialize realtime summary inode\n"));
3353 _(" - resetting contents of realtime bitmap and summary inodes\n"));
3354 if (fill_rbmino(mp
)) {
3356 _("Warning: realtime bitmap may be inconsistent\n"));
3359 if (fill_rsumino(mp
)) {
3361 _("Warning: realtime bitmap may be inconsistent\n"));
3365 mark_standalone_inodes(mp
);
3367 do_log(_(" - traversing filesystem ...\n"));
3369 irec
= find_inode_rec(mp
, XFS_INO_TO_AGNO(mp
, mp
->m_sb
.sb_rootino
),
3370 XFS_INO_TO_AGINO(mp
, mp
->m_sb
.sb_rootino
));
3373 * we always have a root inode, even if it's free...
3374 * if the root is free, forget it, lost+found is already gone
3376 if (is_inode_free(irec
, 0) || !inode_isadir(irec
, 0)) {
3377 need_root_inode
= 1;
3381 * then process all inodes by walking incore inode tree
3386 * any directories that had updated ".." entries, rebuild them now
3388 update_missing_dotdot_entries(mp
);
3390 do_log(_(" - traversal finished ...\n"));
3391 do_log(_(" - moving disconnected inodes to %s ...\n"),
3395 * move all disconnected inodes to the orphanage
3397 for (i
= 0; i
< glob_agcount
; i
++) {
3398 irec
= findfirst_inode_rec(i
);
3399 while (irec
!= NULL
) {
3400 check_for_orphaned_inodes(mp
, i
, irec
);
3401 irec
= next_ino_rec(irec
);