1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
13 #include "err_protos.h"
18 #include "attr_repair.h"
25 * gettext lookups for translations of strings use mutexes internally to
26 * the library. Hence when we come through here doing parallel scans in
27 * multiple AGs, then all do concurrent text conversions and serialise
28 * on the translation string lookups. Let's avoid doing repeated lookups
29 * by making them static variables and only assigning the translation
32 static char *forkname_data
;
33 static char *forkname_attr
;
34 static char *ftype_real_time
;
35 static char *ftype_regular
;
38 dinode_bmbt_translation_init(void)
40 forkname_data
= _("data");
41 forkname_attr
= _("attr");
42 ftype_real_time
= _("real-time");
43 ftype_regular
= _("regular");
47 get_forkname(int whichfork
)
50 if (whichfork
== XFS_DATA_FORK
)
56 * inode clearing routines
60 clear_dinode_attr(xfs_mount_t
*mp
, xfs_dinode_t
*dino
, xfs_ino_t ino_num
)
62 ASSERT(dino
->di_forkoff
!= 0);
66 _("clearing inode %" PRIu64
" attributes\n"), ino_num
);
69 _("would have cleared inode %" PRIu64
" attributes\n"), ino_num
);
71 if (be16_to_cpu(dino
->di_anextents
) != 0) {
74 dino
->di_anextents
= cpu_to_be16(0);
77 if (dino
->di_aformat
!= XFS_DINODE_FMT_EXTENTS
) {
80 dino
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
83 /* get rid of the fork by clearing forkoff */
85 /* Originally, when the attr repair code was added, the fork was cleared
86 * by turning it into shortform status. This meant clearing the
87 * hdr.totsize/count fields and also changing aformat to LOCAL
88 * (vs EXTENTS). Over various fixes, the aformat and forkoff have
89 * been updated to not show an attribute fork at all, however.
90 * It could be possible that resetting totsize/count are not needed,
91 * but just to be safe, leave it in for now.
95 xfs_attr_shortform_t
*asf
= (xfs_attr_shortform_t
*)
97 asf
->hdr
.totsize
= cpu_to_be16(sizeof(xfs_attr_sf_hdr_t
));
99 dino
->di_forkoff
= 0; /* got to do this after asf is set */
103 * always returns 1 since the fork gets zapped
109 clear_dinode_core(struct xfs_mount
*mp
, xfs_dinode_t
*dinoc
, xfs_ino_t ino_num
)
111 memset(dinoc
, 0, sizeof(*dinoc
));
112 dinoc
->di_magic
= cpu_to_be16(XFS_DINODE_MAGIC
);
113 if (xfs_sb_version_hascrc(&mp
->m_sb
))
114 dinoc
->di_version
= 3;
116 dinoc
->di_version
= 2;
117 dinoc
->di_gen
= cpu_to_be32(random());
118 dinoc
->di_format
= XFS_DINODE_FMT_EXTENTS
;
119 dinoc
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
120 /* we are done for version 1/2 inodes */
121 if (dinoc
->di_version
< 3)
123 dinoc
->di_ino
= cpu_to_be64(ino_num
);
124 platform_uuid_copy(&dinoc
->di_uuid
, &mp
->m_sb
.sb_meta_uuid
);
129 clear_dinode_unlinked(xfs_mount_t
*mp
, xfs_dinode_t
*dino
)
132 dino
->di_next_unlinked
= cpu_to_be32(NULLAGINO
);
136 * this clears the unlinked list too so it should not be called
137 * until after the agi unlinked lists are walked in phase 3.
140 clear_dinode(xfs_mount_t
*mp
, xfs_dinode_t
*dino
, xfs_ino_t ino_num
)
142 clear_dinode_core(mp
, dino
, ino_num
);
143 clear_dinode_unlinked(mp
, dino
);
145 /* and clear the forks */
146 memset(XFS_DFORK_DPTR(dino
), 0, XFS_LITINO(mp
, dino
->di_version
));
152 * misc. inode-related utility routines
156 * verify_ag_bno is heavily used. In the common case, it
157 * performs just two number of compares
158 * Returns 1 for bad ag/bno pair or 0 if it's valid.
161 verify_ag_bno(xfs_sb_t
*sbp
,
165 if (agno
< (sbp
->sb_agcount
- 1))
166 return (agbno
>= sbp
->sb_agblocks
);
167 if (agno
== (sbp
->sb_agcount
- 1))
168 return (agbno
>= (sbp
->sb_dblocks
-
169 ((xfs_rfsblock_t
)(sbp
->sb_agcount
- 1) *
175 * returns 0 if inode number is valid, 1 if bogus
178 verify_inum(xfs_mount_t
*mp
,
184 xfs_sb_t
*sbp
= &mp
->m_sb
;;
186 /* range check ag #, ag block. range-checking offset is pointless */
188 agno
= XFS_INO_TO_AGNO(mp
, ino
);
189 agino
= XFS_INO_TO_AGINO(mp
, ino
);
190 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
194 if (ino
== 0 || ino
== NULLFSINO
)
197 if (ino
!= XFS_AGINO_TO_INO(mp
, agno
, agino
))
200 return verify_ag_bno(sbp
, agno
, agbno
);
204 * have a separate routine to ensure that we don't accidentally
205 * lose illegally set bits in the agino by turning it into an FSINO
206 * to feed to the above routine
209 verify_aginum(xfs_mount_t
*mp
,
214 xfs_sb_t
*sbp
= &mp
->m_sb
;;
216 /* range check ag #, ag block. range-checking offset is pointless */
218 if (agino
== 0 || agino
== NULLAGINO
)
222 * agino's can't be too close to NULLAGINO because the min blocksize
223 * is 9 bits and at most 1 bit of that gets used for the inode offset
224 * so if the agino gets shifted by the # of offset bits and compared
225 * to the legal agbno values, a bogus agino will be too large. there
226 * will be extra bits set at the top that shouldn't be set.
228 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
232 return verify_ag_bno(sbp
, agno
, agbno
);
236 * return 1 if block number is good, 0 if out of range
239 verify_dfsbno(xfs_mount_t
*mp
,
244 xfs_sb_t
*sbp
= &mp
->m_sb
;;
246 /* range check ag #, ag block. range-checking offset is pointless */
248 agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
249 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
);
251 return verify_ag_bno(sbp
, agno
, agbno
) == 0;
254 #define XR_DFSBNORANGE_VALID 0
255 #define XR_DFSBNORANGE_BADSTART 1
256 #define XR_DFSBNORANGE_BADEND 2
257 #define XR_DFSBNORANGE_OVERFLOW 3
260 verify_dfsbno_range(xfs_mount_t
*mp
,
266 xfs_sb_t
*sbp
= &mp
->m_sb
;;
268 /* the start and end blocks better be in the same allocation group */
269 agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
270 if (agno
!= XFS_FSB_TO_AGNO(mp
, fsbno
+ count
- 1)) {
271 return XR_DFSBNORANGE_OVERFLOW
;
274 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
);
275 if (verify_ag_bno(sbp
, agno
, agbno
)) {
276 return XR_DFSBNORANGE_BADSTART
;
279 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
+ count
- 1);
280 if (verify_ag_bno(sbp
, agno
, agbno
)) {
281 return XR_DFSBNORANGE_BADEND
;
284 return (XR_DFSBNORANGE_VALID
);
288 verify_agbno(xfs_mount_t
*mp
,
292 xfs_sb_t
*sbp
= &mp
->m_sb
;;
294 /* range check ag #, ag block. range-checking offset is pointless */
295 return verify_ag_bno(sbp
, agno
, agbno
) == 0;
301 xfs_bmbt_irec_t
*irec
,
309 int pwe
; /* partially-written extent */
312 * check numeric validity of the extent
314 if (irec
->br_startblock
>= mp
->m_sb
.sb_rblocks
) {
316 _("inode %" PRIu64
" - bad rt extent start block number %" PRIu64
", offset %" PRIu64
"\n"),
322 if (irec
->br_startblock
+ irec
->br_blockcount
- 1 >= mp
->m_sb
.sb_rblocks
) {
324 _("inode %" PRIu64
" - bad rt extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
326 irec
->br_startblock
+ irec
->br_blockcount
- 1,
330 if (irec
->br_startblock
+ irec
->br_blockcount
- 1 < irec
->br_startblock
) {
332 _("inode %" PRIu64
" - bad rt extent overflows - start %" PRIu64
", "
333 "end %" PRIu64
", offset %" PRIu64
"\n"),
336 irec
->br_startblock
+ irec
->br_blockcount
- 1,
342 * verify that the blocks listed in the record
343 * are multiples of an extent
345 if (xfs_sb_version_hasextflgbit(&mp
->m_sb
) == 0 &&
346 (irec
->br_startblock
% mp
->m_sb
.sb_rextsize
!= 0 ||
347 irec
->br_blockcount
% mp
->m_sb
.sb_rextsize
!= 0)) {
349 _("malformed rt inode extent [%" PRIu64
" %" PRIu64
"] (fs rtext size = %u)\n"),
352 mp
->m_sb
.sb_rextsize
);
357 * set the appropriate number of extents
358 * this iterates block by block, this can be optimised using extents
360 for (b
= irec
->br_startblock
; b
< irec
->br_startblock
+
361 irec
->br_blockcount
; b
+= mp
->m_sb
.sb_rextsize
) {
362 ext
= (xfs_rtblock_t
) b
/ mp
->m_sb
.sb_rextsize
;
363 pwe
= xfs_sb_version_hasextflgbit(&mp
->m_sb
) &&
364 irec
->br_state
== XFS_EXT_UNWRITTEN
&&
365 (b
% mp
->m_sb
.sb_rextsize
!= 0);
367 if (check_dups
== 1) {
368 if (search_rt_dup_extent(mp
, ext
) && !pwe
) {
370 _("data fork in rt ino %" PRIu64
" claims dup rt extent,"
371 "off - %" PRIu64
", start - %" PRIu64
", count %" PRIu64
"\n"),
375 irec
->br_blockcount
);
381 state
= get_rtbmap(ext
);
385 set_rtbmap(ext
, XR_E_INUSE
);
389 _("bad state in rt block map %" PRIu64
"\n"),
395 _("data fork in rt inode %" PRIu64
" found metadata block %" PRIu64
" in rt bmap\n"),
402 set_rtbmap(ext
, XR_E_MULT
);
404 _("data fork in rt inode %" PRIu64
" claims used rt block %" PRIu64
"\n"),
410 _("illegal state %d in rt block map %" PRIu64
"\n"),
416 * bump up the block counter
418 *tot
+= irec
->br_blockcount
;
424 * return 1 if inode should be cleared, 0 otherwise
425 * if check_dups should be set to 1, that implies that
426 * the primary purpose of this call is to see if the
427 * file overlaps with any duplicate extents (in the
428 * duplicate extent list).
431 process_bmbt_reclist_int(
439 xfs_fileoff_t
*first_key
,
440 xfs_fileoff_t
*last_key
,
444 xfs_bmbt_irec_t irec
;
445 xfs_filblks_t cp
= 0; /* prev count */
446 xfs_fsblock_t sp
= 0; /* prev start */
447 xfs_fileoff_t op
= 0; /* prev offset */
450 char *forkname
= get_forkname(whichfork
);
457 xfs_agnumber_t locked_agno
= -1;
460 if (type
== XR_INO_RTDATA
)
461 ftype
= ftype_real_time
;
463 ftype
= ftype_regular
;
465 for (i
= 0; i
< *numrecs
; i
++) {
466 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
468 *last_key
= *first_key
= irec
.br_startoff
;
470 *last_key
= irec
.br_startoff
;
471 if (i
> 0 && op
+ cp
> irec
.br_startoff
) {
473 _("bmap rec out of order, inode %" PRIu64
" entry %d "
474 "[o s c] [%" PRIu64
" %" PRIu64
" %" PRIu64
"], "
475 "%d [%" PRIu64
" %" PRIu64
" %" PRIu64
"]\n"),
476 ino
, i
, irec
.br_startoff
, irec
.br_startblock
,
477 irec
.br_blockcount
, i
- 1, op
, sp
, cp
);
480 op
= irec
.br_startoff
;
481 cp
= irec
.br_blockcount
;
482 sp
= irec
.br_startblock
;
485 * check numeric validity of the extent
487 if (irec
.br_blockcount
== 0) {
489 _("zero length extent (off = %" PRIu64
", fsbno = %" PRIu64
") in ino %" PRIu64
"\n"),
496 if (type
== XR_INO_RTDATA
&& whichfork
== XFS_DATA_FORK
) {
498 * realtime bitmaps don't use AG locks, so returning
499 * immediately is fine for this code path.
501 if (process_rt_rec(mp
, &irec
, ino
, tot
, check_dups
))
504 * skip rest of loop processing since that'irec.br_startblock
505 * all for regular file forks and attr forks
511 * regular file data fork or attribute fork
513 switch (verify_dfsbno_range(mp
, irec
.br_startblock
,
514 irec
.br_blockcount
)) {
515 case XR_DFSBNORANGE_VALID
:
518 case XR_DFSBNORANGE_BADSTART
:
520 _("inode %" PRIu64
" - bad extent starting block number %" PRIu64
", offset %" PRIu64
"\n"),
526 case XR_DFSBNORANGE_BADEND
:
528 _("inode %" PRIu64
" - bad extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
530 irec
.br_startblock
+ irec
.br_blockcount
- 1,
534 case XR_DFSBNORANGE_OVERFLOW
:
536 _("inode %" PRIu64
" - bad extent overflows - start %" PRIu64
", "
537 "end %" PRIu64
", offset %" PRIu64
"\n"),
540 irec
.br_startblock
+ irec
.br_blockcount
- 1,
544 /* Ensure this extent does not extend beyond the max offset */
545 if (irec
.br_startoff
+ irec
.br_blockcount
- 1 >
546 fs_max_file_offset
) {
548 _("inode %" PRIu64
" - extent exceeds max offset - start %" PRIu64
", "
549 "count %" PRIu64
", physical block %" PRIu64
"\n"),
550 ino
, irec
.br_startoff
, irec
.br_blockcount
,
555 if (blkmapp
&& *blkmapp
) {
557 error2
= blkmap_set_ext(blkmapp
, irec
.br_startoff
,
558 irec
.br_startblock
, irec
.br_blockcount
);
561 * we don't want to clear the inode due to an
562 * internal bmap tracking error, but if we've
563 * run out of memory then we simply can't
564 * validate that the filesystem is consistent.
565 * Hence just abort at this point with an ENOMEM
569 _("Fatal error: inode %" PRIu64
" - blkmap_set_ext(): %s\n"
570 "\t%s fork, off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
571 ino
, strerror(error2
), forkname
,
572 irec
.br_startoff
, irec
.br_startblock
,
578 * Profiling shows that the following loop takes the
579 * most time in all of xfs_repair.
581 agno
= XFS_FSB_TO_AGNO(mp
, irec
.br_startblock
);
582 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
583 ebno
= agbno
+ irec
.br_blockcount
;
584 if (agno
!= locked_agno
) {
585 if (locked_agno
!= -1)
586 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
587 pthread_mutex_lock(&ag_locks
[agno
].lock
);
593 * if we're just checking the bmap for dups,
594 * return if we find one, otherwise, continue
595 * checking each entry without setting the
598 if (!(type
== XR_INO_DATA
&&
599 xfs_sb_version_hasreflink(&mp
->m_sb
)) &&
600 search_dup_extent(agno
, agbno
, ebno
)) {
602 _("%s fork in ino %" PRIu64
" claims dup extent, "
603 "off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
604 forkname
, ino
, irec
.br_startoff
,
609 *tot
+= irec
.br_blockcount
;
613 for (b
= irec
.br_startblock
;
615 b
+= blen
, agbno
+= blen
) {
616 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
621 _("%s fork in ino %" PRIu64
" claims free block %" PRIu64
"\n"),
622 forkname
, ino
, (uint64_t) b
);
623 /* fall through ... */
624 case XR_E_INUSE1
: /* seen by rmap */
629 do_error(_("bad state in block map %" PRIu64
"\n"), b
);
634 do_warn(_("rmap claims metadata use!\n"));
641 _("%s fork in inode %" PRIu64
" claims metadata block %" PRIu64
"\n"),
647 if (type
== XR_INO_DATA
&&
648 xfs_sb_version_hasreflink(&mp
->m_sb
))
651 _("%s fork in %s inode %" PRIu64
" claims used block %" PRIu64
"\n"),
652 forkname
, ftype
, ino
, b
);
657 _("%s fork in %s inode %" PRIu64
" claims CoW block %" PRIu64
"\n"),
658 forkname
, ftype
, ino
, b
);
663 _("illegal state %d in block map %" PRIu64
"\n"),
670 * Update the internal extent map only after we've checked
671 * every block in this extent. The first time we reject this
672 * data fork we'll try to rebuild the bmbt from rmap data.
673 * After a successful rebuild we'll try this scan again.
674 * (If the rebuild fails we won't come back here.)
676 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
677 ebno
= agbno
+ irec
.br_blockcount
;
678 for (; agbno
< ebno
; agbno
+= blen
) {
679 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
685 set_bmap_ext(agno
, agbno
, blen
, XR_E_INUSE
);
689 set_bmap_ext(agno
, agbno
, blen
, XR_E_MULT
);
695 if (collect_rmaps
) { /* && !check_dups */
696 error
= rmap_add_rec(mp
, ino
, whichfork
, &irec
);
699 _("couldn't add reverse mapping\n")
702 *tot
+= irec
.br_blockcount
;
706 if (locked_agno
!= -1)
707 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
710 ASSERT(i
< *numrecs
);
711 do_warn(_("correcting nextents for inode %" PRIu64
"\n"), ino
);
719 * return 1 if inode should be cleared, 0 otherwise, sets block bitmap
723 process_bmbt_reclist(
731 xfs_fileoff_t
*first_key
,
732 xfs_fileoff_t
*last_key
,
735 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
736 blkmapp
, first_key
, last_key
, 0, whichfork
);
740 * return 1 if inode should be cleared, 0 otherwise, does not set
753 xfs_fileoff_t first_key
= 0;
754 xfs_fileoff_t last_key
= 0;
756 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
757 NULL
, &first_key
, &last_key
, 1, whichfork
);
761 * Grab the buffer backing an inode. This is meant for routines that
762 * work with inodes one at a time in any order (like walking the
763 * unlinked lists to look for inodes). The caller is responsible for
764 * writing/releasing the buffer.
768 struct xfs_mount
*mp
,
771 struct xfs_dinode
**dipp
)
776 xfs_agino_t cluster_agino
;
777 xfs_daddr_t cluster_daddr
;
778 xfs_daddr_t cluster_blks
;
781 * Inode buffers have been read into memory in inode_cluster_size
782 * chunks (or one FSB). To find the correct buffer for an inode,
783 * we must find the buffer for its cluster, add the appropriate
784 * offset, and return that.
786 cluster_size
= max(mp
->m_inode_cluster_size
, mp
->m_sb
.sb_blocksize
);
787 ino_per_cluster
= cluster_size
/ mp
->m_sb
.sb_inodesize
;
788 cluster_agino
= agino
& ~(ino_per_cluster
- 1);
789 cluster_blks
= XFS_FSB_TO_DADDR(mp
, max(1,
790 mp
->m_inode_cluster_size
>> mp
->m_sb
.sb_blocklog
));
791 cluster_daddr
= XFS_AGB_TO_DADDR(mp
, agno
,
792 XFS_AGINO_TO_AGBNO(mp
, cluster_agino
));
794 #ifdef XR_INODE_TRACE
795 printf("cluster_size %d ipc %d clusagino %d daddr %lld sectors %lld\n",
796 cluster_size
, ino_per_cluster
, cluster_agino
, cluster_daddr
,
800 bp
= libxfs_readbuf(mp
->m_dev
, cluster_daddr
, cluster_blks
,
801 0, &xfs_inode_buf_ops
);
803 do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64
"\n"),
804 agno
, cluster_agino
, cluster_daddr
);
808 *dipp
= xfs_make_iptr(mp
, bp
, agino
- cluster_agino
);
809 ASSERT(!xfs_sb_version_hascrc(&mp
->m_sb
) ||
810 XFS_AGINO_TO_INO(mp
, agno
, agino
) ==
811 be64_to_cpu((*dipp
)->di_ino
));
816 * higher level inode processing stuff starts here:
817 * first, one utility routine for each type of inode
821 * return 1 if inode should be cleared, 0 otherwise
837 xfs_bmdr_block_t
*dib
;
838 xfs_fileoff_t last_key
;
839 xfs_fileoff_t first_key
= 0;
842 xfs_bmbt_key_t
*pkey
;
843 char *forkname
= get_forkname(whichfork
);
847 bmap_cursor_t cursor
;
850 dib
= (xfs_bmdr_block_t
*)XFS_DFORK_PTR(dip
, whichfork
);
851 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
855 magic
= xfs_sb_version_hascrc(&mp
->m_sb
) ? XFS_BMAP_CRC_MAGIC
858 level
= be16_to_cpu(dib
->bb_level
);
859 numrecs
= be16_to_cpu(dib
->bb_numrecs
);
861 if ((level
== 0) || (level
> XFS_BM_MAXLEVELS(mp
, whichfork
))) {
863 * XXX - if we were going to fix up the inode,
864 * we'd try to treat the fork as an interior
865 * node and see if we could get an accurate
866 * level value from one of the blocks pointed
867 * to by the pointers in the fork. For now
868 * though, we just bail (and blow out the inode).
871 _("bad level %d in inode %" PRIu64
" bmap btree root block\n"),
872 level
, XFS_AGINO_TO_INO(mp
, agno
, ino
));
877 _("bad numrecs 0 in inode %" PRIu64
" bmap btree root block\n"),
878 XFS_AGINO_TO_INO(mp
, agno
, ino
));
882 * use bmdr/dfork_dsize since the root block is in the data fork
884 if (XFS_BMDR_SPACE_CALC(numrecs
) > XFS_DFORK_SIZE(dip
, mp
, whichfork
)) {
886 _("indicated size of %s btree root (%d bytes) greater than space in "
887 "inode %" PRIu64
" %s fork\n"),
888 forkname
, XFS_BMDR_SPACE_CALC(numrecs
), lino
, forkname
);
892 init_bm_cursor(&cursor
, level
+ 1);
894 pp
= XFS_BMDR_PTR_ADDR(dib
, 1,
895 libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip
, mp
, whichfork
), 0));
896 pkey
= XFS_BMDR_KEY_ADDR(dib
, 1);
897 last_key
= NULLFILEOFF
;
899 for (i
= 0; i
< numrecs
; i
++) {
901 * XXX - if we were going to do more to fix up the inode
902 * btree, we'd do it right here. For now, if there's a
903 * problem, we'll bail out and presumably clear the inode.
905 if (!verify_dfsbno(mp
, get_unaligned_be64(&pp
[i
]))) {
907 _("bad bmap btree ptr 0x%" PRIx64
" in ino %" PRIu64
"\n"),
908 get_unaligned_be64(&pp
[i
]), lino
);
912 if (scan_lbtree(get_unaligned_be64(&pp
[i
]), level
, scan_bmapbt
,
913 type
, whichfork
, lino
, tot
, nex
, blkmapp
,
914 &cursor
, 1, check_dups
, magic
,
918 * fix key (offset) mismatches between the keys in root
919 * block records and the first key of each child block.
920 * fixes cases where entries have been shifted between
921 * blocks but the parent hasn't been updated
923 if (!check_dups
&& cursor
.level
[level
-1].first_key
!=
924 get_unaligned_be64(&pkey
[i
].br_startoff
)) {
927 _("correcting key in bmbt root (was %" PRIu64
", now %" PRIu64
") in inode "
928 "%" PRIu64
" %s fork\n"),
929 get_unaligned_be64(&pkey
[i
].br_startoff
),
930 cursor
.level
[level
-1].first_key
,
931 XFS_AGINO_TO_INO(mp
, agno
, ino
),
935 cursor
.level
[level
-1].first_key
,
936 &pkey
[i
].br_startoff
);
939 _("bad key in bmbt root (is %" PRIu64
", would reset to %" PRIu64
") in inode "
940 "%" PRIu64
" %s fork\n"),
941 get_unaligned_be64(&pkey
[i
].br_startoff
),
942 cursor
.level
[level
-1].first_key
,
943 XFS_AGINO_TO_INO(mp
, agno
, ino
),
948 * make sure that keys are in ascending order. blow out
949 * inode if the ordering doesn't hold
951 if (check_dups
== 0) {
952 if (last_key
!= NULLFILEOFF
&& last_key
>=
953 cursor
.level
[level
-1].first_key
) {
955 _("out of order bmbt root key %" PRIu64
" in inode %" PRIu64
" %s fork\n"),
957 XFS_AGINO_TO_INO(mp
, agno
, ino
),
961 last_key
= cursor
.level
[level
-1].first_key
;
965 * Ideally if all the extents are ok (perhaps after further
966 * checks below?) we'd just move this back into extents format.
967 * But for now clear it, as the kernel will choke on this
969 if (*nex
<= XFS_DFORK_SIZE(dip
, mp
, whichfork
) /
970 sizeof(xfs_bmbt_rec_t
)) {
972 _("extent count for ino %" PRIu64
" %s fork too low (%" PRIu64
") for file format\n"),
973 lino
, forkname
, *nex
);
977 * Check that the last child block's forward sibling pointer
980 if (check_dups
== 0 &&
981 cursor
.level
[0].right_fsbno
!= NULLFSBLOCK
) {
983 _("bad fwd (right) sibling pointer (saw %" PRIu64
" should be NULLFSBLOCK)\n"),
984 cursor
.level
[0].right_fsbno
);
986 _("\tin inode %" PRIu64
" (%s fork) bmap btree block %" PRIu64
"\n"),
987 XFS_AGINO_TO_INO(mp
, agno
, ino
), forkname
,
988 cursor
.level
[0].fsbno
);
996 * return 1 if inode should be cleared, 0 otherwise
1001 xfs_agnumber_t agno
,
1006 xfs_rfsblock_t
*tot
,
1014 xfs_fileoff_t first_key
;
1015 xfs_fileoff_t last_key
;
1019 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1020 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_PTR(dip
, whichfork
);
1022 numrecs
= XFS_DFORK_NEXTENTS(dip
, whichfork
);
1025 * We've already decided on the maximum number of extents on the inode,
1026 * and numrecs may be corrupt. Hence make sure we only allow numrecs to
1027 * be in the range of valid on-disk numbers, which is:
1028 * 0 < numrecs < 2^31 - 1
1034 * XXX - if we were going to fix up the btree record,
1035 * we'd do it right here. For now, if there's a problem,
1036 * we'll bail out and presumably clear the inode.
1038 if (check_dups
== 0)
1039 ret
= process_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
,
1040 tot
, blkmapp
, &first_key
, &last_key
,
1043 ret
= scan_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
, tot
,
1051 * return 1 if inode should be cleared, 0 otherwise
1056 xfs_agnumber_t agno
,
1061 xfs_attr_shortform_t
*asf
;
1064 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1065 if (whichfork
== XFS_DATA_FORK
&& be64_to_cpu(dip
->di_size
) >
1066 XFS_DFORK_DSIZE(dip
, mp
)) {
1068 _("local inode %" PRIu64
" data fork is too large (size = %lld, max = %d)\n"),
1069 lino
, (unsigned long long) be64_to_cpu(dip
->di_size
),
1070 XFS_DFORK_DSIZE(dip
, mp
));
1072 } else if (whichfork
== XFS_ATTR_FORK
) {
1073 asf
= (xfs_attr_shortform_t
*)XFS_DFORK_APTR(dip
);
1074 if (be16_to_cpu(asf
->hdr
.totsize
) > XFS_DFORK_ASIZE(dip
, mp
)) {
1076 _("local inode %" PRIu64
" attr fork too large (size %d, max = %d)\n"),
1077 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1078 XFS_DFORK_ASIZE(dip
, mp
));
1081 if (be16_to_cpu(asf
->hdr
.totsize
) < sizeof(xfs_attr_sf_hdr_t
)) {
1083 _("local inode %" PRIu64
" attr too small (size = %d, min size = %zd)\n"),
1084 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1085 sizeof(xfs_attr_sf_hdr_t
));
1094 process_symlink_extlist(xfs_mount_t
*mp
, xfs_ino_t lino
, xfs_dinode_t
*dino
)
1096 xfs_fileoff_t expected_offset
;
1098 xfs_bmbt_irec_t irec
;
1103 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1104 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
)
1107 _("mismatch between format (%d) and size (%" PRId64
") in symlink ino %" PRIu64
"\n"),
1109 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1112 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
) {
1114 _("mismatch between format (%d) and size (%" PRId64
") in symlink inode %" PRIu64
"\n"),
1116 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1120 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_DPTR(dino
);
1121 numrecs
= be32_to_cpu(dino
->di_nextents
);
1124 * the max # of extents in a symlink inode is equal to the
1125 * number of max # of blocks required to store the symlink
1127 if (numrecs
> max_symlink_blocks
) {
1129 _("bad number of extents (%d) in symlink %" PRIu64
" data fork\n"),
1134 max_blocks
= max_symlink_blocks
;
1135 expected_offset
= 0;
1137 for (i
= 0; i
< numrecs
; i
++) {
1138 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
1139 if (irec
.br_startoff
!= expected_offset
) {
1141 _("bad extent #%d offset (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1142 i
, irec
.br_startoff
, lino
);
1145 if (irec
.br_blockcount
== 0 || irec
.br_blockcount
> max_blocks
) {
1147 _("bad extent #%d count (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1148 i
, irec
.br_blockcount
, lino
);
1152 max_blocks
-= irec
.br_blockcount
;
1153 expected_offset
+= irec
.br_blockcount
;
1160 * takes a name and length and returns 1 if the name contains
1161 * a \0, returns 0 otherwise
1164 null_check(char *name
, int length
)
1168 ASSERT(length
< XFS_SYMLINK_MAXLEN
);
1170 for (i
= 0; i
< length
; i
++, name
++) {
1179 * This does /not/ do quotacheck, it validates the basic quota
1180 * inode metadata, checksums, etc.
1182 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
1184 process_quota_inode(
1185 struct xfs_mount
*mp
,
1187 struct xfs_dinode
*dino
,
1189 struct blkmap
*blkmap
)
1191 xfs_fsblock_t fsbno
;
1193 xfs_filblks_t dqchunklen
;
1204 quota_type
= XFS_DQ_USER
;
1205 quota_string
= _("User quota");
1208 quota_type
= XFS_DQ_GROUP
;
1209 quota_string
= _("Group quota");
1212 quota_type
= XFS_DQ_PROJ
;
1213 quota_string
= _("Project quota");
1219 dqchunklen
= XFS_FSB_TO_BB(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
);
1220 dqperchunk
= libxfs_calc_dquots_per_chunk(dqchunklen
);
1224 while ((qbno
= blkmap_next_off(blkmap
, qbno
, &t
)) != NULLFILEOFF
) {
1228 fsbno
= blkmap_get(blkmap
, qbno
);
1229 dqid
= (xfs_dqid_t
)qbno
* dqperchunk
;
1231 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1232 dqchunklen
, 0, &xfs_dquot_buf_ops
);
1235 _("cannot read inode %" PRIu64
", file block %" PRIu64
", disk block %" PRIu64
"\n"),
1241 for (i
= 0; i
< dqperchunk
; i
++, dqid
++, dqb
++) {
1244 /* We only print the first problem we find */
1245 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1246 if (!libxfs_verify_cksum((char *)dqb
,
1248 XFS_DQUOT_CRC_OFF
)) {
1249 do_warn(_("%s: bad CRC for id %u. "),
1250 quota_string
, dqid
);
1255 if (!uuid_equal(&dqb
->dd_uuid
,
1256 &mp
->m_sb
.sb_meta_uuid
)) {
1257 do_warn(_("%s: bad UUID for id %u. "),
1258 quota_string
, dqid
);
1263 if (libxfs_dquot_verify(mp
, &dqb
->dd_diskdq
, dqid
,
1264 quota_type
) != NULL
) {
1265 do_warn(_("%s: Corrupt quota for id %u. "),
1266 quota_string
, dqid
);
1273 do_warn(_("Would correct.\n"));
1275 do_warn(_("Corrected.\n"));
1276 libxfs_dqblk_repair(mp
, dqb
,
1283 if (writebuf
&& !no_modify
)
1284 libxfs_writebuf(bp
, 0);
1292 process_symlink_remote(
1293 struct xfs_mount
*mp
,
1295 struct xfs_dinode
*dino
,
1296 struct blkmap
*blkmap
,
1299 xfs_fsblock_t fsbno
;
1307 pathlen
= be64_to_cpu(dino
->di_size
);
1310 while (pathlen
> 0) {
1315 fsbno
= blkmap_get(blkmap
, i
);
1316 if (fsbno
== NULLFSBLOCK
) {
1318 _("cannot read inode %" PRIu64
", file block %d, NULL disk block\n"),
1324 * There's a symlink header for each contiguous extent. If
1325 * there are contiguous blocks, read them in one go.
1327 while (blk_cnt
<= max_symlink_blocks
) {
1328 if (blkmap_get(blkmap
, i
+ 1) != fsbno
+ 1)
1334 byte_cnt
= XFS_FSB_TO_B(mp
, blk_cnt
);
1336 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1337 BTOBB(byte_cnt
), 0, &xfs_symlink_buf_ops
);
1340 _("cannot read inode %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1344 if (bp
->b_error
== -EFSCORRUPTED
) {
1346 _("Corrupt symlink remote block %" PRIu64
", inode %" PRIu64
".\n"),
1351 if (bp
->b_error
== -EFSBADCRC
) {
1353 _("Bad symlink buffer CRC, block %" PRIu64
", inode %" PRIu64
".\n"
1354 "Correcting CRC, but symlink may be bad.\n"), fsbno
, lino
);
1358 byte_cnt
= XFS_SYMLINK_BUF_SPACE(mp
, byte_cnt
);
1359 byte_cnt
= min(pathlen
, byte_cnt
);
1362 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1363 if (!libxfs_symlink_hdr_ok(lino
, offset
,
1366 _("bad symlink header ino %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1371 src
+= sizeof(struct xfs_dsymlink_hdr
);
1374 memmove(dst
+ offset
, src
, byte_cnt
);
1376 pathlen
-= byte_cnt
;
1380 if (badcrc
&& !no_modify
)
1381 libxfs_writebuf(bp
, 0);
1389 * like usual, returns 0 if everything's ok and 1 if something's
1400 char data
[XFS_SYMLINK_MAXLEN
];
1403 * check size against kernel symlink limits. we know
1404 * size is consistent with inode storage format -- e.g.
1405 * the inode is structurally ok so we don't have to check
1408 if (be64_to_cpu(dino
->di_size
) >= XFS_SYMLINK_MAXLEN
) {
1409 do_warn(_("symlink in inode %" PRIu64
" too long (%llu chars)\n"),
1410 lino
, (unsigned long long) be64_to_cpu(dino
->di_size
));
1414 if (be64_to_cpu(dino
->di_size
) == 0) {
1415 do_warn(_("zero size symlink in inode %" PRIu64
"\n"), lino
);
1420 * have to check symlink component by component.
1421 * get symlink contents into data area
1424 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1426 * local symlink, just copy the symlink out of the
1427 * inode into the data area
1429 memmove(symlink
, XFS_DFORK_DPTR(dino
),
1430 be64_to_cpu(dino
->di_size
));
1434 error
= process_symlink_remote(mp
, lino
, dino
, blkmap
, symlink
);
1439 data
[be64_to_cpu(dino
->di_size
)] = '\0';
1444 if (null_check(symlink
, be64_to_cpu(dino
->di_size
))) {
1446 _("found illegal null character in symlink inode %" PRIu64
"\n"),
1455 * called to process the set of misc inode special inode types
1456 * that have no associated data storage (fifos, pipes, devices, etc.).
1459 process_misc_ino_types(xfs_mount_t
*mp
,
1465 * disallow mountpoint inodes until such time as the
1466 * kernel actually allows them to be created (will
1467 * probably require a superblock version rev, sigh).
1469 if (type
== XR_INO_MOUNTPOINT
) {
1471 _("inode %" PRIu64
" has bad inode type (IFMNT)\n"), lino
);
1476 * must also have a zero size
1478 if (be64_to_cpu(dino
->di_size
) != 0) {
1482 _("size of character device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1483 (int64_t)be64_to_cpu(dino
->di_size
));
1487 _("size of block device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1488 (int64_t)be64_to_cpu(dino
->di_size
));
1492 _("size of socket inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1493 (int64_t)be64_to_cpu(dino
->di_size
));
1497 _("size of fifo inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1498 (int64_t)be64_to_cpu(dino
->di_size
));
1504 _("size of quota inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1505 (int64_t)be64_to_cpu(dino
->di_size
));
1508 do_warn(_("Internal error - process_misc_ino_types, "
1509 "illegal type %d\n"), type
);
1520 process_misc_ino_types_blocks(xfs_rfsblock_t totblocks
, xfs_ino_t lino
, int type
)
1523 * you can not enforce all misc types have zero data fork blocks
1524 * by checking dino->di_nblocks because atotblocks (attribute
1525 * blocks) are part of nblocks. We must check this later when atotblocks
1526 * has been calculated or by doing a simple check that anExtents == 0.
1527 * We must also guarantee that totblocks is 0. Thus nblocks checking
1528 * will be done later in process_dinode_int for misc types.
1531 if (totblocks
!= 0) {
1535 _("size of character device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1540 _("size of block device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1545 _("size of socket inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1550 _("size of fifo inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1565 return be16_to_cpu(dino
->di_mode
) & S_IFMT
;
1573 int mode
= be16_to_cpu(dino
->di_mode
);
1575 ASSERT((new_fmt
& ~S_IFMT
) == 0);
1579 dino
->di_mode
= cpu_to_be16(mode
);
1583 check_dinode_mode_format(
1584 xfs_dinode_t
*dinoc
)
1586 if (dinoc
->di_format
>= XFS_DINODE_FMT_UUID
)
1587 return -1; /* FMT_UUID is not used */
1589 switch (dinode_fmt(dinoc
)) {
1594 return (dinoc
->di_format
!= XFS_DINODE_FMT_DEV
) ? -1 : 0;
1597 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1598 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1601 return (dinoc
->di_format
< XFS_DINODE_FMT_EXTENTS
||
1602 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1605 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1606 dinoc
->di_format
> XFS_DINODE_FMT_EXTENTS
) ? -1 : 0;
1610 return 0; /* invalid modes are checked elsewhere */
1614 * If inode is a superblock inode, does type check to make sure is it valid.
1615 * Returns 0 if it's valid, non-zero if it needs to be cleared.
1619 process_check_sb_inodes(
1621 xfs_dinode_t
*dinoc
,
1626 if (lino
== mp
->m_sb
.sb_rootino
) {
1627 if (*type
!= XR_INO_DIR
) {
1628 do_warn(_("root inode %" PRIu64
" has bad type 0x%x\n"),
1629 lino
, dinode_fmt(dinoc
));
1632 do_warn(_("resetting to directory\n"));
1633 change_dinode_fmt(dinoc
, S_IFDIR
);
1636 do_warn(_("would reset to directory\n"));
1640 if (lino
== mp
->m_sb
.sb_uquotino
) {
1641 if (*type
!= XR_INO_UQUOTA
) {
1642 do_warn(_("user quota inode %" PRIu64
" has bad type 0x%x\n"),
1643 lino
, dinode_fmt(dinoc
));
1644 mp
->m_sb
.sb_uquotino
= NULLFSINO
;
1649 if (lino
== mp
->m_sb
.sb_gquotino
) {
1650 if (*type
!= XR_INO_GQUOTA
) {
1651 do_warn(_("group quota inode %" PRIu64
" has bad type 0x%x\n"),
1652 lino
, dinode_fmt(dinoc
));
1653 mp
->m_sb
.sb_gquotino
= NULLFSINO
;
1658 if (lino
== mp
->m_sb
.sb_pquotino
) {
1659 if (*type
!= XR_INO_PQUOTA
) {
1660 do_warn(_("project quota inode %" PRIu64
" has bad type 0x%x\n"),
1661 lino
, dinode_fmt(dinoc
));
1662 mp
->m_sb
.sb_pquotino
= NULLFSINO
;
1667 if (lino
== mp
->m_sb
.sb_rsumino
) {
1668 if (*type
!= XR_INO_RTSUM
) {
1670 _("realtime summary inode %" PRIu64
" has bad type 0x%x, "),
1671 lino
, dinode_fmt(dinoc
));
1673 do_warn(_("resetting to regular file\n"));
1674 change_dinode_fmt(dinoc
, S_IFREG
);
1677 do_warn(_("would reset to regular file\n"));
1680 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1682 _("bad # of extents (%u) for realtime summary inode %" PRIu64
"\n"),
1683 be32_to_cpu(dinoc
->di_nextents
), lino
);
1688 if (lino
== mp
->m_sb
.sb_rbmino
) {
1689 if (*type
!= XR_INO_RTBITMAP
) {
1691 _("realtime bitmap inode %" PRIu64
" has bad type 0x%x, "),
1692 lino
, dinode_fmt(dinoc
));
1694 do_warn(_("resetting to regular file\n"));
1695 change_dinode_fmt(dinoc
, S_IFREG
);
1698 do_warn(_("would reset to regular file\n"));
1701 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1703 _("bad # of extents (%u) for realtime bitmap inode %" PRIu64
"\n"),
1704 be32_to_cpu(dinoc
->di_nextents
), lino
);
1713 * general size/consistency checks:
1715 * if the size <= size of the data fork, directories must be
1716 * local inodes unlike regular files which would be extent inodes.
1717 * all the other mentioned types have to have a zero size value.
1719 * if the size and format don't match, get out now rather than
1720 * risk trying to process a non-existent extents or btree
1724 process_check_inode_sizes(
1730 xfs_fsize_t size
= be64_to_cpu(dino
->di_size
);
1735 if (size
<= XFS_DFORK_DSIZE(dino
, mp
) &&
1736 dino
->di_format
!= XFS_DINODE_FMT_LOCAL
) {
1738 _("mismatch between format (%d) and size (%" PRId64
") in directory ino %" PRIu64
"\n"),
1739 dino
->di_format
, size
, lino
);
1742 if (size
> XFS_DIR2_LEAF_OFFSET
) {
1744 _("directory inode %" PRIu64
" has bad size %" PRId64
"\n"),
1750 case XR_INO_SYMLINK
:
1751 if (process_symlink_extlist(mp
, lino
, dino
)) {
1752 do_warn(_("bad data fork in symlink %" PRIu64
"\n"), lino
);
1757 case XR_INO_CHRDEV
: /* fall through to FIFO case ... */
1758 case XR_INO_BLKDEV
: /* fall through to FIFO case ... */
1759 case XR_INO_SOCK
: /* fall through to FIFO case ... */
1760 case XR_INO_MOUNTPOINT
: /* fall through to FIFO case ... */
1762 if (process_misc_ino_types(mp
, dino
, lino
, type
))
1769 /* Quota inodes have same restrictions as above types */
1770 if (process_misc_ino_types(mp
, dino
, lino
, type
))
1776 * if we have no realtime blocks, any inode claiming
1777 * to be a real-time file is bogus
1779 if (mp
->m_sb
.sb_rblocks
== 0) {
1781 _("found inode %" PRIu64
" claiming to be a real-time file\n"), lino
);
1786 case XR_INO_RTBITMAP
:
1787 if (size
!= (int64_t)mp
->m_sb
.sb_rbmblocks
*
1788 mp
->m_sb
.sb_blocksize
) {
1790 _("realtime bitmap inode %" PRIu64
" has bad size %" PRId64
" (should be %" PRIu64
")\n"),
1792 (int64_t) mp
->m_sb
.sb_rbmblocks
*
1793 mp
->m_sb
.sb_blocksize
);
1799 if (size
!= mp
->m_rsumsize
) {
1801 _("realtime summary inode %" PRIu64
" has bad size %" PRId64
" (should be %d)\n"),
1802 lino
, size
, mp
->m_rsumsize
);
1814 * check for illegal values of forkoff
1817 process_check_inode_forkoff(
1822 if (dino
->di_forkoff
== 0)
1825 switch (dino
->di_format
) {
1826 case XFS_DINODE_FMT_DEV
:
1827 if (dino
->di_forkoff
!= (roundup(sizeof(xfs_dev_t
), 8) >> 3)) {
1829 _("bad attr fork offset %d in dev inode %" PRIu64
", should be %d\n"),
1830 dino
->di_forkoff
, lino
,
1831 (int)(roundup(sizeof(xfs_dev_t
), 8) >> 3));
1835 case XFS_DINODE_FMT_LOCAL
: /* fall through ... */
1836 case XFS_DINODE_FMT_EXTENTS
: /* fall through ... */
1837 case XFS_DINODE_FMT_BTREE
:
1838 if (dino
->di_forkoff
>=
1839 (XFS_LITINO(mp
, dino
->di_version
) >> 3)) {
1841 _("bad attr fork offset %d in inode %" PRIu64
", max=%d\n"),
1842 dino
->di_forkoff
, lino
,
1843 XFS_LITINO(mp
, dino
->di_version
) >> 3);
1848 do_error(_("unexpected inode format %d\n"), dino
->di_format
);
1855 * Updates the inodes block and extent counts if they are wrong
1858 process_inode_blocks_and_extents(
1860 xfs_rfsblock_t nblocks
,
1866 if (nblocks
!= be64_to_cpu(dino
->di_nblocks
)) {
1869 _("correcting nblocks for inode %" PRIu64
", was %llu - counted %" PRIu64
"\n"), lino
,
1870 (unsigned long long) be64_to_cpu(dino
->di_nblocks
),
1872 dino
->di_nblocks
= cpu_to_be64(nblocks
);
1876 _("bad nblocks %llu for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
1877 (unsigned long long) be64_to_cpu(dino
->di_nblocks
),
1882 if (nextents
> MAXEXTNUM
) {
1884 _("too many data fork extents (%" PRIu64
") in inode %" PRIu64
"\n"),
1888 if (nextents
!= be32_to_cpu(dino
->di_nextents
)) {
1891 _("correcting nextents for inode %" PRIu64
", was %d - counted %" PRIu64
"\n"),
1893 be32_to_cpu(dino
->di_nextents
),
1895 dino
->di_nextents
= cpu_to_be32(nextents
);
1899 _("bad nextents %d for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
1900 be32_to_cpu(dino
->di_nextents
),
1905 if (anextents
> MAXAEXTNUM
) {
1907 _("too many attr fork extents (%" PRIu64
") in inode %" PRIu64
"\n"),
1911 if (anextents
!= be16_to_cpu(dino
->di_anextents
)) {
1914 _("correcting anextents for inode %" PRIu64
", was %d - counted %" PRIu64
"\n"),
1916 be16_to_cpu(dino
->di_anextents
), anextents
);
1917 dino
->di_anextents
= cpu_to_be16(anextents
);
1921 _("bad anextents %d for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
1922 be16_to_cpu(dino
->di_anextents
),
1928 * We are comparing different units here, but that's fine given that
1929 * an extent has to have at least a block in it.
1931 if (nblocks
< nextents
+ anextents
) {
1933 _("nblocks (%" PRIu64
") smaller than nextents for inode %" PRIu64
"\n"), nblocks
, lino
);
1941 * check data fork -- if it's bad, clear the inode
1944 process_inode_data_fork(
1946 xfs_agnumber_t agno
,
1951 xfs_rfsblock_t
*totblocks
,
1956 xfs_ino_t lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1961 * extent count on disk is only valid for positive values. The kernel
1962 * uses negative values in memory. hence if we see negative numbers
1965 nex
= be32_to_cpu(dino
->di_nextents
);
1971 if (*nextents
> be64_to_cpu(dino
->di_nblocks
))
1975 if (dino
->di_format
!= XFS_DINODE_FMT_LOCAL
&& type
!= XR_INO_RTDATA
)
1976 *dblkmap
= blkmap_alloc(*nextents
, XFS_DATA_FORK
);
1979 switch (dino
->di_format
) {
1980 case XFS_DINODE_FMT_LOCAL
:
1981 err
= process_lclinode(mp
, agno
, ino
, dino
, XFS_DATA_FORK
);
1984 case XFS_DINODE_FMT_EXTENTS
:
1985 err
= process_exinode(mp
, agno
, ino
, dino
, type
, dirty
,
1986 totblocks
, nextents
, dblkmap
, XFS_DATA_FORK
,
1989 case XFS_DINODE_FMT_BTREE
:
1990 err
= process_btinode(mp
, agno
, ino
, dino
, type
, dirty
,
1991 totblocks
, nextents
, dblkmap
, XFS_DATA_FORK
,
1994 case XFS_DINODE_FMT_DEV
: /* fall through */
1998 do_error(_("unknown format %d, ino %" PRIu64
" (mode = %d)\n"),
1999 dino
->di_format
, lino
, be16_to_cpu(dino
->di_mode
));
2003 do_warn(_("bad data fork in inode %" PRIu64
"\n"), lino
);
2005 clear_dinode(mp
, dino
, lino
);
2013 * if check_dups was non-zero, we have to
2014 * re-process data fork to set bitmap since the
2015 * bitmap wasn't set the first time through
2017 switch (dino
->di_format
) {
2018 case XFS_DINODE_FMT_LOCAL
:
2019 err
= process_lclinode(mp
, agno
, ino
, dino
,
2022 case XFS_DINODE_FMT_EXTENTS
:
2023 err
= process_exinode(mp
, agno
, ino
, dino
, type
,
2024 dirty
, totblocks
, nextents
, dblkmap
,
2027 case XFS_DINODE_FMT_BTREE
:
2028 err
= process_btinode(mp
, agno
, ino
, dino
, type
,
2029 dirty
, totblocks
, nextents
, dblkmap
,
2032 case XFS_DINODE_FMT_DEV
: /* fall through */
2036 do_error(_("unknown format %d, ino %" PRIu64
" (mode = %d)\n"),
2037 dino
->di_format
, lino
,
2038 be16_to_cpu(dino
->di_mode
));
2041 if (no_modify
&& err
!= 0)
2050 * Process extended attribute fork in inode
2053 process_inode_attr_fork(
2055 xfs_agnumber_t agno
,
2060 xfs_rfsblock_t
*atotblocks
,
2061 uint64_t *anextents
,
2063 int extra_attr_check
,
2066 xfs_ino_t lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2067 blkmap_t
*ablkmap
= NULL
;
2071 if (!XFS_DFORK_Q(dino
)) {
2073 if (dino
->di_aformat
!= XFS_DINODE_FMT_EXTENTS
) {
2074 do_warn(_("bad attribute format %d in inode %" PRIu64
", "),
2075 dino
->di_aformat
, lino
);
2077 do_warn(_("resetting value\n"));
2078 dino
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
2081 do_warn(_("would reset value\n"));
2086 *anextents
= be16_to_cpu(dino
->di_anextents
);
2087 if (*anextents
> be64_to_cpu(dino
->di_nblocks
))
2090 switch (dino
->di_aformat
) {
2091 case XFS_DINODE_FMT_LOCAL
:
2094 err
= process_lclinode(mp
, agno
, ino
, dino
, XFS_ATTR_FORK
);
2096 case XFS_DINODE_FMT_EXTENTS
:
2097 ablkmap
= blkmap_alloc(*anextents
, XFS_ATTR_FORK
);
2099 err
= process_exinode(mp
, agno
, ino
, dino
, type
, dirty
,
2100 atotblocks
, anextents
, &ablkmap
,
2101 XFS_ATTR_FORK
, check_dups
);
2103 case XFS_DINODE_FMT_BTREE
:
2104 ablkmap
= blkmap_alloc(*anextents
, XFS_ATTR_FORK
);
2106 err
= process_btinode(mp
, agno
, ino
, dino
, type
, dirty
,
2107 atotblocks
, anextents
, &ablkmap
,
2108 XFS_ATTR_FORK
, check_dups
);
2111 do_warn(_("illegal attribute format %d, ino %" PRIu64
"\n"),
2112 dino
->di_aformat
, lino
);
2119 * clear the attribute fork if necessary. we can't
2120 * clear the inode because we've already put the
2121 * inode space info into the blockmap.
2123 * XXX - put the inode onto the "move it" list and
2124 * log the the attribute scrubbing
2126 do_warn(_("bad attribute fork in inode %" PRIu64
), lino
);
2129 do_warn(_(", clearing attr fork\n"));
2130 *dirty
+= clear_dinode_attr(mp
, dino
, lino
);
2131 dino
->di_aformat
= XFS_DINODE_FMT_LOCAL
;
2134 do_warn(_(", would clear attr fork\n"));
2139 blkmap_free(ablkmap
);
2146 switch (dino
->di_aformat
) {
2147 case XFS_DINODE_FMT_LOCAL
:
2148 err
= process_lclinode(mp
, agno
, ino
, dino
,
2151 case XFS_DINODE_FMT_EXTENTS
:
2152 err
= process_exinode(mp
, agno
, ino
, dino
,
2153 type
, dirty
, atotblocks
, anextents
,
2154 &ablkmap
, XFS_ATTR_FORK
, 0);
2156 case XFS_DINODE_FMT_BTREE
:
2157 err
= process_btinode(mp
, agno
, ino
, dino
,
2158 type
, dirty
, atotblocks
, anextents
,
2159 &ablkmap
, XFS_ATTR_FORK
, 0);
2162 do_error(_("illegal attribute fmt %d, ino %" PRIu64
"\n"),
2163 dino
->di_aformat
, lino
);
2166 if (no_modify
&& err
!= 0) {
2167 blkmap_free(ablkmap
);
2175 * do attribute semantic-based consistency checks now
2178 /* get this only in phase 3, not in both phase 3 and 4 */
2179 if (extra_attr_check
&&
2180 process_attributes(mp
, lino
, dino
, ablkmap
, &repair
)) {
2182 _("problem with attribute contents in inode %" PRIu64
"\n"),
2185 /* clear attributes if not done already */
2187 *dirty
+= clear_dinode_attr(mp
, dino
, lino
);
2188 dino
->di_aformat
= XFS_DINODE_FMT_LOCAL
;
2190 do_warn(_("would clear attr fork\n"));
2196 *dirty
= 1; /* it's been repaired */
2199 blkmap_free(ablkmap
);
2204 * check nlinks feature, if it's a version 1 inode,
2205 * just leave nlinks alone. even if it's set wrong,
2206 * it'll be reset when read in.
2210 process_check_inode_nlink_version(
2217 * if it's a version 2 inode, it should have a zero
2218 * onlink field, so clear it.
2220 if (dino
->di_version
> 1 && dino
->di_onlink
!= 0) {
2223 _("clearing obsolete nlink field in version 2 inode %" PRIu64
", was %d, now 0\n"),
2224 lino
, be16_to_cpu(dino
->di_onlink
));
2225 dino
->di_onlink
= 0;
2229 _("would clear obsolete nlink field in version 2 inode %" PRIu64
", currently %d\n"),
2230 lino
, be16_to_cpu(dino
->di_onlink
));
2236 /* Check nanoseconds of a timestamp don't exceed 1 second. */
2241 struct xfs_timestamp
*t
,
2244 if (be32_to_cpu(t
->t_nsec
) < 1000000000)
2248 _("Bad %s nsec %u on inode %" PRIu64
", "), name
, be32_to_cpu(t
->t_nsec
), lino
);
2250 do_warn(_("would reset to zero\n"));
2252 do_warn(_("resetting to zero\n"));
2259 * returns 0 if the inode is ok, 1 if the inode is corrupt
2260 * check_dups can be set to 1 *only* when called by the
2261 * first pass of the duplicate block checking of phase 4.
2262 * *dirty is set > 0 if the dinode has been altered and
2263 * needs to be written out.
2265 * for detailed, info, look at process_dinode() comments.
2268 process_dinode_int(xfs_mount_t
*mp
,
2270 xfs_agnumber_t agno
,
2272 int was_free
, /* 1 if inode is currently free */
2273 int *dirty
, /* out == > 0 if inode is now dirty */
2274 int *used
, /* out == 1 if inode is in use */
2275 int verify_mode
, /* 1 == verify but don't modify inode */
2276 int uncertain
, /* 1 == inode is uncertain */
2277 int ino_discovery
, /* 1 == check dirs for unknown inodes */
2278 int check_dups
, /* 1 == check if inode claims
2279 * duplicate blocks */
2280 int extra_attr_check
, /* 1 == do attribute format and value checks */
2281 int *isa_dir
, /* out == 1 if inode is a directory */
2282 xfs_ino_t
*parent
) /* out -- parent if ino is a dir */
2284 xfs_rfsblock_t totblocks
= 0;
2285 xfs_rfsblock_t atotblocks
= 0;
2292 const int is_free
= 0;
2293 const int is_used
= 1;
2294 blkmap_t
*dblkmap
= NULL
;
2296 *dirty
= *isa_dir
= 0;
2298 type
= XR_INO_UNKNOWN
;
2300 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2301 di_mode
= be16_to_cpu(dino
->di_mode
);
2304 * if in verify mode, don't modify the inode.
2306 * if correcting, reset stuff that has known values
2308 * if in uncertain mode, be silent on errors since we're
2309 * trying to find out if these are inodes as opposed
2310 * to assuming that they are. Just return the appropriate
2311 * return code in that case.
2313 * If uncertain is set, verify_mode MUST be set.
2315 ASSERT(uncertain
== 0 || verify_mode
!= 0);
2318 * This is the only valid point to check the CRC; after this we may have
2319 * made changes which invalidate it, and the CRC is only updated again
2320 * when it gets written out.
2322 * Of course if we make any modifications after this, the inode gets
2323 * rewritten, and the CRC is updated automagically.
2325 if (xfs_sb_version_hascrc(&mp
->m_sb
) &&
2326 !libxfs_verify_cksum((char *)dino
, mp
->m_sb
.sb_inodesize
,
2327 XFS_DINODE_CRC_OFF
)) {
2330 do_warn(_("bad CRC for inode %" PRIu64
"%c"),
2331 lino
, verify_mode
? '\n' : ',');
2334 do_warn(_(" will rewrite\n"));
2337 do_warn(_(" would rewrite\n"));
2341 if (be16_to_cpu(dino
->di_magic
) != XFS_DINODE_MAGIC
) {
2344 do_warn(_("bad magic number 0x%x on inode %" PRIu64
"%c"),
2345 be16_to_cpu(dino
->di_magic
), lino
,
2346 verify_mode
? '\n' : ',');
2349 do_warn(_(" resetting magic number\n"));
2350 dino
->di_magic
= cpu_to_be16(XFS_DINODE_MAGIC
);
2353 do_warn(_(" would reset magic number\n"));
2357 if (!libxfs_dinode_good_version(mp
, dino
->di_version
)) {
2360 do_warn(_("bad version number 0x%x on inode %" PRIu64
"%c"),
2361 (__s8
)dino
->di_version
, lino
,
2362 verify_mode
? '\n' : ',');
2365 do_warn(_(" resetting version number\n"));
2367 xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
2370 do_warn(_(" would reset version number\n"));
2375 * We don't bother checking the CRC here - we cannot guarantee that when
2376 * we are called here that the inode has not already been modified in
2377 * memory and hence invalidated the CRC.
2379 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
2380 if (be64_to_cpu(dino
->di_ino
) != lino
) {
2383 _("inode identifier %llu mismatch on inode %" PRIu64
"\n"),
2384 (unsigned long long)be64_to_cpu(dino
->di_ino
),
2390 if (platform_uuid_compare(&dino
->di_uuid
,
2391 &mp
->m_sb
.sb_meta_uuid
)) {
2394 _("UUID mismatch on inode %" PRIu64
"\n"), lino
);
2402 * blow out of here if the inode size is < 0
2404 if ((xfs_fsize_t
)be64_to_cpu(dino
->di_size
) < 0) {
2407 _("bad (negative) size %" PRId64
" on inode %" PRIu64
"\n"),
2408 (int64_t)be64_to_cpu(dino
->di_size
),
2416 * if not in verify mode, check to see if the inode and imap
2417 * agree that the inode is free
2419 if (!verify_mode
&& di_mode
== 0) {
2421 * was_free value is not meaningful if we're in verify mode
2425 * easy case, inode free -- inode and map agree, check
2426 * it just in case to ensure that format, etc. are
2429 if (libxfs_dinode_verify(mp
, lino
, dino
) != NULL
) {
2431 _("free inode %" PRIu64
" contains errors, "), lino
);
2433 clear_dinode(mp
, dino
, lino
);
2434 do_warn(_("corrected\n"));
2437 do_warn(_("would correct\n"));
2444 * the inode looks free but the map says it's in use.
2445 * clear the inode just to be safe and mark the inode
2449 _("imap claims a free inode %" PRIu64
" is in use, "), lino
);
2451 do_warn(_("correcting imap and clearing inode\n"));
2452 clear_dinode(mp
, dino
, lino
);
2456 do_warn(_("would correct imap and clear inode\n"));
2462 * because of the lack of any write ordering guarantee, it's
2463 * possible that the core got updated but the forks didn't.
2464 * so rather than be ambitious (and probably incorrect),
2465 * if there's an inconsistency, we get conservative and
2466 * just pitch the file. blow off checking formats of
2467 * free inodes since technically any format is legal
2468 * as we reset the inode when we re-use it.
2470 if (di_mode
!= 0 && check_dinode_mode_format(dino
) != 0) {
2473 _("bad inode format in inode %" PRIu64
"\n"), lino
);
2480 * check that we only have valid flags set, and those that are set make
2483 if (dino
->di_flags
) {
2484 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2486 if (flags
& ~XFS_DIFLAG_ANY
) {
2489 _("Bad flags set in inode %" PRIu64
"\n"),
2492 flags
&= XFS_DIFLAG_ANY
;
2495 if (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
)) {
2496 /* need an rt-dev! */
2500 _("inode %" PRIu64
" has RT flag set but there is no RT device\n"),
2503 flags
&= ~(XFS_DIFLAG_REALTIME
|
2504 XFS_DIFLAG_RTINHERIT
);
2507 if (flags
& XFS_DIFLAG_NEWRTBM
) {
2508 /* must be a rt bitmap inode */
2509 if (lino
!= mp
->m_sb
.sb_rbmino
) {
2512 _("inode %" PRIu64
" not rt bitmap\n"),
2515 flags
&= ~XFS_DIFLAG_NEWRTBM
;
2518 if (flags
& (XFS_DIFLAG_RTINHERIT
|
2519 XFS_DIFLAG_EXTSZINHERIT
|
2520 XFS_DIFLAG_PROJINHERIT
|
2521 XFS_DIFLAG_NOSYMLINKS
)) {
2522 /* must be a directory */
2523 if (di_mode
&& !S_ISDIR(di_mode
)) {
2526 _("directory flags set on non-directory inode %" PRIu64
"\n" ),
2529 flags
&= ~(XFS_DIFLAG_RTINHERIT
|
2530 XFS_DIFLAG_EXTSZINHERIT
|
2531 XFS_DIFLAG_PROJINHERIT
|
2532 XFS_DIFLAG_NOSYMLINKS
);
2535 if (flags
& (XFS_DIFLAG_REALTIME
| FS_XFLAG_EXTSIZE
)) {
2536 /* must be a file */
2537 if (di_mode
&& !S_ISREG(di_mode
)) {
2540 _("file flags set on non-file inode %" PRIu64
"\n"),
2543 flags
&= ~(XFS_DIFLAG_REALTIME
|
2547 if (!verify_mode
&& flags
!= be16_to_cpu(dino
->di_flags
)) {
2549 do_warn(_("fixing bad flags.\n"));
2550 dino
->di_flags
= cpu_to_be16(flags
);
2553 do_warn(_("would fix bad flags.\n"));
2558 * check that we only have valid flags2 set, and those that are set make
2561 if (dino
->di_version
>= 3) {
2562 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2563 uint64_t flags2
= be64_to_cpu(dino
->di_flags2
);
2565 if (flags2
& ~XFS_DIFLAG2_ANY
) {
2568 _("Bad flags2 set in inode %" PRIu64
"\n"),
2571 flags2
&= XFS_DIFLAG2_ANY
;
2574 if (flags2
& XFS_DIFLAG2_DAX
) {
2575 /* must be a file or dir */
2576 if (di_mode
&& !(S_ISREG(di_mode
) || S_ISDIR(di_mode
))) {
2579 _("DAX flag set on special inode %" PRIu64
"\n"),
2582 flags2
&= ~XFS_DIFLAG2_DAX
;
2586 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2587 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2590 _("inode %" PRIu64
" is marked reflinked but file system does not support reflink\n"),
2596 if (flags2
& XFS_DIFLAG2_REFLINK
) {
2597 /* must be a file */
2598 if (di_mode
&& !S_ISREG(di_mode
)) {
2601 _("reflink flag set on non-file inode %" PRIu64
"\n"),
2608 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2609 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2612 _("Cannot have a reflinked realtime inode %" PRIu64
"\n"),
2618 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2619 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2622 _("inode %" PRIu64
" has CoW extent size hint but file system does not support reflink\n"),
2625 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2628 if (flags2
& XFS_DIFLAG2_COWEXTSIZE
) {
2629 /* must be a directory or file */
2630 if (di_mode
&& !S_ISDIR(di_mode
) && !S_ISREG(di_mode
)) {
2633 _("CoW extent size flag set on non-file, non-directory inode %" PRIu64
"\n" ),
2636 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2640 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2641 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2644 _("Cannot have CoW extent size hint on a realtime inode %" PRIu64
"\n"),
2647 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2650 if (!verify_mode
&& flags2
!= be64_to_cpu(dino
->di_flags2
)) {
2652 do_warn(_("fixing bad flags2.\n"));
2653 dino
->di_flags2
= cpu_to_be64(flags2
);
2656 do_warn(_("would fix bad flags2.\n"));
2664 * clear the next unlinked field if necessary on a good
2665 * inode only during phase 4 -- when checking for inodes
2666 * referencing duplicate blocks. then it's safe because
2667 * we've done the inode discovery and have found all the inodes
2668 * we're going to find. check_dups is set to 1 only during
2671 if (check_dups
&& be32_to_cpu(dino
->di_next_unlinked
) != NULLAGINO
) {
2674 _("Would clear next_unlinked in inode %" PRIu64
"\n"), lino
);
2676 clear_dinode_unlinked(mp
, dino
);
2678 _("Cleared next_unlinked in inode %" PRIu64
"\n"), lino
);
2683 /* set type and map type info */
2685 switch (di_mode
& S_IFMT
) {
2691 if (be16_to_cpu(dino
->di_flags
) & XFS_DIFLAG_REALTIME
)
2692 type
= XR_INO_RTDATA
;
2693 else if (lino
== mp
->m_sb
.sb_rbmino
)
2694 type
= XR_INO_RTBITMAP
;
2695 else if (lino
== mp
->m_sb
.sb_rsumino
)
2696 type
= XR_INO_RTSUM
;
2697 else if (lino
== mp
->m_sb
.sb_uquotino
)
2698 type
= XR_INO_UQUOTA
;
2699 else if (lino
== mp
->m_sb
.sb_gquotino
)
2700 type
= XR_INO_GQUOTA
;
2701 else if (lino
== mp
->m_sb
.sb_pquotino
)
2702 type
= XR_INO_PQUOTA
;
2707 type
= XR_INO_SYMLINK
;
2710 type
= XR_INO_CHRDEV
;
2713 type
= XR_INO_BLKDEV
;
2722 do_warn(_("bad inode type %#o inode %" PRIu64
"\n"),
2723 di_mode
& S_IFMT
, lino
);
2728 * type checks for superblock inodes
2730 if (process_check_sb_inodes(mp
, dino
, lino
, &type
, dirty
) != 0)
2734 * only regular files with REALTIME or EXTSIZE flags set can have
2735 * extsize set, or directories with EXTSZINHERIT.
2737 if (libxfs_inode_validate_extsize(mp
,
2738 be32_to_cpu(dino
->di_extsize
),
2739 be16_to_cpu(dino
->di_mode
),
2740 be16_to_cpu(dino
->di_flags
)) != NULL
) {
2742 _("Bad extent size %u on inode %" PRIu64
", "),
2743 be32_to_cpu(dino
->di_extsize
), lino
);
2745 do_warn(_("resetting to zero\n"));
2746 dino
->di_extsize
= 0;
2747 dino
->di_flags
&= ~cpu_to_be16(XFS_DIFLAG_EXTSIZE
|
2748 XFS_DIFLAG_EXTSZINHERIT
);
2751 do_warn(_("would reset to zero\n"));
2755 * Only (regular files and directories) with COWEXTSIZE flags
2756 * set can have extsize set.
2758 if (dino
->di_version
>= 3 &&
2759 libxfs_inode_validate_cowextsize(mp
,
2760 be32_to_cpu(dino
->di_cowextsize
),
2761 be16_to_cpu(dino
->di_mode
),
2762 be16_to_cpu(dino
->di_flags
),
2763 be64_to_cpu(dino
->di_flags2
)) != NULL
) {
2765 _("Bad CoW extent size %u on inode %" PRIu64
", "),
2766 be32_to_cpu(dino
->di_cowextsize
), lino
);
2768 do_warn(_("resetting to zero\n"));
2769 dino
->di_flags2
&= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE
);
2770 dino
->di_cowextsize
= 0;
2773 do_warn(_("would reset to zero\n"));
2776 /* nsec fields cannot be larger than 1 billion */
2777 check_nsec("atime", lino
, &dino
->di_atime
, dirty
);
2778 check_nsec("mtime", lino
, &dino
->di_mtime
, dirty
);
2779 check_nsec("ctime", lino
, &dino
->di_ctime
, dirty
);
2780 if (dino
->di_version
>= 3)
2781 check_nsec("crtime", lino
, &dino
->di_crtime
, dirty
);
2784 * general size/consistency checks:
2786 if (process_check_inode_sizes(mp
, dino
, lino
, type
) != 0)
2790 * check for illegal values of forkoff
2792 if (process_check_inode_forkoff(mp
, dino
, lino
) != 0)
2796 * record the state of the reflink flag
2799 record_inode_reflink_flag(mp
, dino
, agno
, ino
, lino
);
2802 * check data fork -- if it's bad, clear the inode
2804 if (process_inode_data_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2805 &totblocks
, &nextents
, &dblkmap
, check_dups
) != 0)
2809 * check attribute fork if necessary. attributes are
2810 * always stored in the regular filesystem.
2812 if (process_inode_attr_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2813 &atotblocks
, &anextents
, check_dups
, extra_attr_check
,
2818 * enforce totblocks is 0 for misc types
2820 if (process_misc_ino_types_blocks(totblocks
, lino
, type
))
2824 * correct space counters if required
2826 if (process_inode_blocks_and_extents(dino
, totblocks
+ atotblocks
,
2827 nextents
, anextents
, lino
, dirty
) != 0)
2831 * do any semantic type-based checking here
2835 if (process_dir2(mp
, lino
, dino
, ino_discovery
,
2836 dirty
, "", parent
, dblkmap
)) {
2838 _("problem with directory contents in inode %" PRIu64
"\n"),
2843 case XR_INO_SYMLINK
:
2844 if (process_symlink(mp
, lino
, dino
, dblkmap
) != 0) {
2846 _("problem with symbolic link in inode %" PRIu64
"\n"),
2854 if (process_quota_inode(mp
, lino
, dino
, type
, dblkmap
) != 0) {
2856 _("problem with quota inode %" PRIu64
"\n"), lino
);
2864 blkmap_free(dblkmap
);
2867 * check nlinks feature, if it's a version 1 inode,
2868 * just leave nlinks alone. even if it's set wrong,
2869 * it'll be reset when read in.
2871 *dirty
+= process_check_inode_nlink_version(dino
, lino
);
2877 clear_dinode(mp
, dino
, lino
);
2883 blkmap_free(dblkmap
);
2888 * returns 1 if inode is used, 0 if free.
2889 * performs any necessary salvaging actions.
2890 * note that we leave the generation count alone
2891 * because nothing we could set it to would be
2892 * guaranteed to be correct so the best guess for
2893 * the correct value is just to leave it alone.
2895 * The trick is detecting empty files. For those,
2896 * the core and the forks should all be in the "empty"
2897 * or zero-length state -- a zero or possibly minimum length
2898 * (in the case of dirs) extent list -- although inline directories
2899 * and symlinks might be handled differently. So it should be
2900 * possible to sanity check them against each other.
2902 * If the forks are an empty extent list though, then forget it.
2903 * The file is toast anyway since we can't recover its storage.
2907 * mp -- mount structure
2908 * dino -- pointer to on-disk inode structure
2909 * agno/ino -- inode numbers
2910 * free -- whether the map thinks the inode is free (1 == free)
2911 * ino_discovery -- whether we should examine directory
2912 * contents to discover new inodes
2913 * check_dups -- whether we should check to see if the
2914 * inode references duplicate blocks
2915 * if so, we compare the inode's claimed
2916 * blocks against the contents of the
2917 * duplicate extent list but we don't
2918 * set the bitmap. If not, we set the
2919 * bitmap and try and detect multiply
2920 * claimed blocks using the bitmap.
2922 * dirty -- whether we changed the inode (1 == yes)
2923 * used -- 1 if the inode is used, 0 if free. In no modify
2924 * mode, whether the inode should be used or free
2925 * isa_dir -- 1 if the inode is a directory, 0 if not. In
2926 * no modify mode, if the inode would be a dir or not.
2928 * Return value -- 0 if the inode is good, 1 if it is/was corrupt
2935 xfs_agnumber_t agno
,
2942 int extra_attr_check
,
2946 const int verify_mode
= 0;
2947 const int uncertain
= 0;
2949 #ifdef XR_INODE_TRACE
2950 fprintf(stderr
, _("processing inode %d/%d\n"), agno
, ino
);
2952 return process_dinode_int(mp
, dino
, agno
, ino
, was_free
, dirty
, used
,
2953 verify_mode
, uncertain
, ino_discovery
,
2954 check_dups
, extra_attr_check
, isa_dir
, parent
);
2958 * a more cursory check, check inode core, *DON'T* check forks
2959 * this basically just verifies whether the inode is an inode
2960 * and whether or not it has been totally trashed. returns 0
2961 * if the inode passes the cursory sanity check, 1 otherwise.
2967 xfs_agnumber_t agno
,
2974 const int verify_mode
= 1;
2975 const int check_dups
= 0;
2976 const int ino_discovery
= 0;
2977 const int uncertain
= 0;
2979 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
2980 verify_mode
, uncertain
, ino_discovery
,
2981 check_dups
, 0, &isa_dir
, &parent
);
2985 * like above only for inode on the uncertain list. it sets
2986 * the uncertain flag which makes process_dinode_int quieter.
2987 * returns 0 if the inode passes the cursory sanity check, 1 otherwise.
2990 verify_uncertain_dinode(
2993 xfs_agnumber_t agno
,
3000 const int verify_mode
= 1;
3001 const int check_dups
= 0;
3002 const int ino_discovery
= 0;
3003 const int uncertain
= 1;
3005 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
3006 verify_mode
, uncertain
, ino_discovery
,
3007 check_dups
, 0, &isa_dir
, &parent
);