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 * set the appropriate number of extents
343 * this iterates block by block, this can be optimised using extents
345 for (b
= irec
->br_startblock
; b
< irec
->br_startblock
+
346 irec
->br_blockcount
; b
+= mp
->m_sb
.sb_rextsize
) {
347 ext
= (xfs_rtblock_t
) b
/ mp
->m_sb
.sb_rextsize
;
348 pwe
= irec
->br_state
== XFS_EXT_UNWRITTEN
&&
349 (b
% mp
->m_sb
.sb_rextsize
!= 0);
351 if (check_dups
== 1) {
352 if (search_rt_dup_extent(mp
, ext
) && !pwe
) {
354 _("data fork in rt ino %" PRIu64
" claims dup rt extent,"
355 "off - %" PRIu64
", start - %" PRIu64
", count %" PRIu64
"\n"),
359 irec
->br_blockcount
);
365 state
= get_rtbmap(ext
);
369 set_rtbmap(ext
, XR_E_INUSE
);
373 _("bad state in rt block map %" PRIu64
"\n"),
379 _("data fork in rt inode %" PRIu64
" found metadata block %" PRIu64
" in rt bmap\n"),
386 set_rtbmap(ext
, XR_E_MULT
);
388 _("data fork in rt inode %" PRIu64
" claims used rt block %" PRIu64
"\n"),
394 _("illegal state %d in rt block map %" PRIu64
"\n"),
400 * bump up the block counter
402 *tot
+= irec
->br_blockcount
;
408 * return 1 if inode should be cleared, 0 otherwise
409 * if check_dups should be set to 1, that implies that
410 * the primary purpose of this call is to see if the
411 * file overlaps with any duplicate extents (in the
412 * duplicate extent list).
415 process_bmbt_reclist_int(
423 xfs_fileoff_t
*first_key
,
424 xfs_fileoff_t
*last_key
,
428 xfs_bmbt_irec_t irec
;
429 xfs_filblks_t cp
= 0; /* prev count */
430 xfs_fsblock_t sp
= 0; /* prev start */
431 xfs_fileoff_t op
= 0; /* prev offset */
434 char *forkname
= get_forkname(whichfork
);
441 xfs_agnumber_t locked_agno
= -1;
444 if (type
== XR_INO_RTDATA
)
445 ftype
= ftype_real_time
;
447 ftype
= ftype_regular
;
449 for (i
= 0; i
< *numrecs
; i
++) {
450 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
452 *last_key
= *first_key
= irec
.br_startoff
;
454 *last_key
= irec
.br_startoff
;
455 if (i
> 0 && op
+ cp
> irec
.br_startoff
) {
457 _("bmap rec out of order, inode %" PRIu64
" entry %d "
458 "[o s c] [%" PRIu64
" %" PRIu64
" %" PRIu64
"], "
459 "%d [%" PRIu64
" %" PRIu64
" %" PRIu64
"]\n"),
460 ino
, i
, irec
.br_startoff
, irec
.br_startblock
,
461 irec
.br_blockcount
, i
- 1, op
, sp
, cp
);
464 op
= irec
.br_startoff
;
465 cp
= irec
.br_blockcount
;
466 sp
= irec
.br_startblock
;
469 * check numeric validity of the extent
471 if (irec
.br_blockcount
== 0) {
473 _("zero length extent (off = %" PRIu64
", fsbno = %" PRIu64
") in ino %" PRIu64
"\n"),
480 if (type
== XR_INO_RTDATA
&& whichfork
== XFS_DATA_FORK
) {
482 * realtime bitmaps don't use AG locks, so returning
483 * immediately is fine for this code path.
485 if (process_rt_rec(mp
, &irec
, ino
, tot
, check_dups
))
488 * skip rest of loop processing since that'irec.br_startblock
489 * all for regular file forks and attr forks
495 * regular file data fork or attribute fork
497 switch (verify_dfsbno_range(mp
, irec
.br_startblock
,
498 irec
.br_blockcount
)) {
499 case XR_DFSBNORANGE_VALID
:
502 case XR_DFSBNORANGE_BADSTART
:
504 _("inode %" PRIu64
" - bad extent starting block number %" PRIu64
", offset %" PRIu64
"\n"),
510 case XR_DFSBNORANGE_BADEND
:
512 _("inode %" PRIu64
" - bad extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
514 irec
.br_startblock
+ irec
.br_blockcount
- 1,
518 case XR_DFSBNORANGE_OVERFLOW
:
520 _("inode %" PRIu64
" - bad extent overflows - start %" PRIu64
", "
521 "end %" PRIu64
", offset %" PRIu64
"\n"),
524 irec
.br_startblock
+ irec
.br_blockcount
- 1,
528 /* Ensure this extent does not extend beyond the max offset */
529 if (irec
.br_startoff
+ irec
.br_blockcount
- 1 >
530 fs_max_file_offset
) {
532 _("inode %" PRIu64
" - extent exceeds max offset - start %" PRIu64
", "
533 "count %" PRIu64
", physical block %" PRIu64
"\n"),
534 ino
, irec
.br_startoff
, irec
.br_blockcount
,
539 if (blkmapp
&& *blkmapp
) {
541 error2
= blkmap_set_ext(blkmapp
, irec
.br_startoff
,
542 irec
.br_startblock
, irec
.br_blockcount
);
545 * we don't want to clear the inode due to an
546 * internal bmap tracking error, but if we've
547 * run out of memory then we simply can't
548 * validate that the filesystem is consistent.
549 * Hence just abort at this point with an ENOMEM
553 _("Fatal error: inode %" PRIu64
" - blkmap_set_ext(): %s\n"
554 "\t%s fork, off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
555 ino
, strerror(error2
), forkname
,
556 irec
.br_startoff
, irec
.br_startblock
,
562 * Profiling shows that the following loop takes the
563 * most time in all of xfs_repair.
565 agno
= XFS_FSB_TO_AGNO(mp
, irec
.br_startblock
);
566 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
567 ebno
= agbno
+ irec
.br_blockcount
;
568 if (agno
!= locked_agno
) {
569 if (locked_agno
!= -1)
570 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
571 pthread_mutex_lock(&ag_locks
[agno
].lock
);
577 * if we're just checking the bmap for dups,
578 * return if we find one, otherwise, continue
579 * checking each entry without setting the
582 if (!(type
== XR_INO_DATA
&&
583 xfs_sb_version_hasreflink(&mp
->m_sb
)) &&
584 search_dup_extent(agno
, agbno
, ebno
)) {
586 _("%s fork in ino %" PRIu64
" claims dup extent, "
587 "off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
588 forkname
, ino
, irec
.br_startoff
,
593 *tot
+= irec
.br_blockcount
;
597 for (b
= irec
.br_startblock
;
599 b
+= blen
, agbno
+= blen
) {
600 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
605 _("%s fork in ino %" PRIu64
" claims free block %" PRIu64
"\n"),
606 forkname
, ino
, (uint64_t) b
);
607 /* fall through ... */
608 case XR_E_INUSE1
: /* seen by rmap */
613 do_error(_("bad state in block map %" PRIu64
"\n"), b
);
618 do_warn(_("rmap claims metadata use!\n"));
625 _("%s fork in inode %" PRIu64
" claims metadata block %" PRIu64
"\n"),
631 if (type
== XR_INO_DATA
&&
632 xfs_sb_version_hasreflink(&mp
->m_sb
))
635 _("%s fork in %s inode %" PRIu64
" claims used block %" PRIu64
"\n"),
636 forkname
, ftype
, ino
, b
);
641 _("%s fork in %s inode %" PRIu64
" claims CoW block %" PRIu64
"\n"),
642 forkname
, ftype
, ino
, b
);
647 _("illegal state %d in block map %" PRIu64
"\n"),
654 * Update the internal extent map only after we've checked
655 * every block in this extent. The first time we reject this
656 * data fork we'll try to rebuild the bmbt from rmap data.
657 * After a successful rebuild we'll try this scan again.
658 * (If the rebuild fails we won't come back here.)
660 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
661 ebno
= agbno
+ irec
.br_blockcount
;
662 for (; agbno
< ebno
; agbno
+= blen
) {
663 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
669 set_bmap_ext(agno
, agbno
, blen
, XR_E_INUSE
);
673 set_bmap_ext(agno
, agbno
, blen
, XR_E_MULT
);
679 if (collect_rmaps
) { /* && !check_dups */
680 error
= rmap_add_rec(mp
, ino
, whichfork
, &irec
);
683 _("couldn't add reverse mapping\n")
686 *tot
+= irec
.br_blockcount
;
690 if (locked_agno
!= -1)
691 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
694 ASSERT(i
< *numrecs
);
695 do_warn(_("correcting nextents for inode %" PRIu64
"\n"), ino
);
703 * return 1 if inode should be cleared, 0 otherwise, sets block bitmap
707 process_bmbt_reclist(
715 xfs_fileoff_t
*first_key
,
716 xfs_fileoff_t
*last_key
,
719 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
720 blkmapp
, first_key
, last_key
, 0, whichfork
);
724 * return 1 if inode should be cleared, 0 otherwise, does not set
737 xfs_fileoff_t first_key
= 0;
738 xfs_fileoff_t last_key
= 0;
740 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
741 NULL
, &first_key
, &last_key
, 1, whichfork
);
745 * Grab the buffer backing an inode. This is meant for routines that
746 * work with inodes one at a time in any order (like walking the
747 * unlinked lists to look for inodes). The caller is responsible for
748 * writing/releasing the buffer.
752 struct xfs_mount
*mp
,
755 struct xfs_dinode
**dipp
)
758 xfs_agino_t cluster_agino
;
759 xfs_daddr_t cluster_daddr
;
760 xfs_daddr_t cluster_blks
;
761 struct xfs_ino_geometry
*igeo
= M_IGEO(mp
);
764 * Inode buffers have been read into memory in inode_cluster_size
765 * chunks (or one FSB). To find the correct buffer for an inode,
766 * we must find the buffer for its cluster, add the appropriate
767 * offset, and return that.
769 cluster_agino
= agino
& ~(igeo
->inodes_per_cluster
- 1);
770 cluster_blks
= XFS_FSB_TO_DADDR(mp
, igeo
->blocks_per_cluster
);
771 cluster_daddr
= XFS_AGB_TO_DADDR(mp
, agno
,
772 XFS_AGINO_TO_AGBNO(mp
, cluster_agino
));
774 #ifdef XR_INODE_TRACE
775 printf("cluster_size %d ipc %d clusagino %d daddr %lld sectors %lld\n",
776 M_IGEO(mp
)->inode_cluster_size
, M_IGEO(mp
)->inodes_per_cluster
,
777 cluster_agino
, cluster_daddr
, cluster_blks
);
780 bp
= libxfs_readbuf(mp
->m_dev
, cluster_daddr
, cluster_blks
,
781 0, &xfs_inode_buf_ops
);
783 do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64
"\n"),
784 agno
, cluster_agino
, cluster_daddr
);
788 *dipp
= xfs_make_iptr(mp
, bp
, agino
- cluster_agino
);
789 ASSERT(!xfs_sb_version_hascrc(&mp
->m_sb
) ||
790 XFS_AGINO_TO_INO(mp
, agno
, agino
) ==
791 be64_to_cpu((*dipp
)->di_ino
));
796 * higher level inode processing stuff starts here:
797 * first, one utility routine for each type of inode
801 * return 1 if inode should be cleared, 0 otherwise
817 xfs_bmdr_block_t
*dib
;
818 xfs_fileoff_t last_key
;
819 xfs_fileoff_t first_key
= 0;
822 xfs_bmbt_key_t
*pkey
;
823 char *forkname
= get_forkname(whichfork
);
827 bmap_cursor_t cursor
;
830 dib
= (xfs_bmdr_block_t
*)XFS_DFORK_PTR(dip
, whichfork
);
831 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
835 magic
= xfs_sb_version_hascrc(&mp
->m_sb
) ? XFS_BMAP_CRC_MAGIC
838 level
= be16_to_cpu(dib
->bb_level
);
839 numrecs
= be16_to_cpu(dib
->bb_numrecs
);
841 if ((level
== 0) || (level
> XFS_BM_MAXLEVELS(mp
, whichfork
))) {
843 * XXX - if we were going to fix up the inode,
844 * we'd try to treat the fork as an interior
845 * node and see if we could get an accurate
846 * level value from one of the blocks pointed
847 * to by the pointers in the fork. For now
848 * though, we just bail (and blow out the inode).
851 _("bad level %d in inode %" PRIu64
" bmap btree root block\n"),
852 level
, XFS_AGINO_TO_INO(mp
, agno
, ino
));
857 _("bad numrecs 0 in inode %" PRIu64
" bmap btree root block\n"),
858 XFS_AGINO_TO_INO(mp
, agno
, ino
));
862 * use bmdr/dfork_dsize since the root block is in the data fork
864 if (XFS_BMDR_SPACE_CALC(numrecs
) > XFS_DFORK_SIZE(dip
, mp
, whichfork
)) {
866 _("indicated size of %s btree root (%d bytes) greater than space in "
867 "inode %" PRIu64
" %s fork\n"),
868 forkname
, XFS_BMDR_SPACE_CALC(numrecs
), lino
, forkname
);
872 init_bm_cursor(&cursor
, level
+ 1);
874 pp
= XFS_BMDR_PTR_ADDR(dib
, 1,
875 libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip
, mp
, whichfork
), 0));
876 pkey
= XFS_BMDR_KEY_ADDR(dib
, 1);
877 last_key
= NULLFILEOFF
;
879 for (i
= 0; i
< numrecs
; i
++) {
881 * XXX - if we were going to do more to fix up the inode
882 * btree, we'd do it right here. For now, if there's a
883 * problem, we'll bail out and presumably clear the inode.
885 if (!verify_dfsbno(mp
, get_unaligned_be64(&pp
[i
]))) {
887 _("bad bmap btree ptr 0x%" PRIx64
" in ino %" PRIu64
"\n"),
888 get_unaligned_be64(&pp
[i
]), lino
);
892 if (scan_lbtree(get_unaligned_be64(&pp
[i
]), level
, scan_bmapbt
,
893 type
, whichfork
, lino
, tot
, nex
, blkmapp
,
894 &cursor
, 1, check_dups
, magic
,
898 * fix key (offset) mismatches between the keys in root
899 * block records and the first key of each child block.
900 * fixes cases where entries have been shifted between
901 * blocks but the parent hasn't been updated
903 if (!check_dups
&& cursor
.level
[level
-1].first_key
!=
904 get_unaligned_be64(&pkey
[i
].br_startoff
)) {
907 _("correcting key in bmbt root (was %" PRIu64
", now %" PRIu64
") in inode "
908 "%" PRIu64
" %s fork\n"),
909 get_unaligned_be64(&pkey
[i
].br_startoff
),
910 cursor
.level
[level
-1].first_key
,
911 XFS_AGINO_TO_INO(mp
, agno
, ino
),
915 cursor
.level
[level
-1].first_key
,
916 &pkey
[i
].br_startoff
);
919 _("bad key in bmbt root (is %" PRIu64
", would reset to %" PRIu64
") in inode "
920 "%" PRIu64
" %s fork\n"),
921 get_unaligned_be64(&pkey
[i
].br_startoff
),
922 cursor
.level
[level
-1].first_key
,
923 XFS_AGINO_TO_INO(mp
, agno
, ino
),
928 * make sure that keys are in ascending order. blow out
929 * inode if the ordering doesn't hold
931 if (check_dups
== 0) {
932 if (last_key
!= NULLFILEOFF
&& last_key
>=
933 cursor
.level
[level
-1].first_key
) {
935 _("out of order bmbt root key %" PRIu64
" in inode %" PRIu64
" %s fork\n"),
937 XFS_AGINO_TO_INO(mp
, agno
, ino
),
941 last_key
= cursor
.level
[level
-1].first_key
;
945 * Ideally if all the extents are ok (perhaps after further
946 * checks below?) we'd just move this back into extents format.
947 * But for now clear it, as the kernel will choke on this
949 if (*nex
<= XFS_DFORK_SIZE(dip
, mp
, whichfork
) /
950 sizeof(xfs_bmbt_rec_t
)) {
952 _("extent count for ino %" PRIu64
" %s fork too low (%" PRIu64
") for file format\n"),
953 lino
, forkname
, *nex
);
957 * Check that the last child block's forward sibling pointer
960 if (check_dups
== 0 &&
961 cursor
.level
[0].right_fsbno
!= NULLFSBLOCK
) {
963 _("bad fwd (right) sibling pointer (saw %" PRIu64
" should be NULLFSBLOCK)\n"),
964 cursor
.level
[0].right_fsbno
);
966 _("\tin inode %" PRIu64
" (%s fork) bmap btree block %" PRIu64
"\n"),
967 XFS_AGINO_TO_INO(mp
, agno
, ino
), forkname
,
968 cursor
.level
[0].fsbno
);
976 * return 1 if inode should be cleared, 0 otherwise
994 xfs_fileoff_t first_key
;
995 xfs_fileoff_t last_key
;
999 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1000 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_PTR(dip
, whichfork
);
1002 numrecs
= XFS_DFORK_NEXTENTS(dip
, whichfork
);
1005 * We've already decided on the maximum number of extents on the inode,
1006 * and numrecs may be corrupt. Hence make sure we only allow numrecs to
1007 * be in the range of valid on-disk numbers, which is:
1008 * 0 < numrecs < 2^31 - 1
1014 * XXX - if we were going to fix up the btree record,
1015 * we'd do it right here. For now, if there's a problem,
1016 * we'll bail out and presumably clear the inode.
1018 if (check_dups
== 0)
1019 ret
= process_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
,
1020 tot
, blkmapp
, &first_key
, &last_key
,
1023 ret
= scan_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
, tot
,
1031 * return 1 if inode should be cleared, 0 otherwise
1036 xfs_agnumber_t agno
,
1041 xfs_attr_shortform_t
*asf
;
1044 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1045 if (whichfork
== XFS_DATA_FORK
&& be64_to_cpu(dip
->di_size
) >
1046 XFS_DFORK_DSIZE(dip
, mp
)) {
1048 _("local inode %" PRIu64
" data fork is too large (size = %lld, max = %d)\n"),
1049 lino
, (unsigned long long) be64_to_cpu(dip
->di_size
),
1050 XFS_DFORK_DSIZE(dip
, mp
));
1052 } else if (whichfork
== XFS_ATTR_FORK
) {
1053 asf
= (xfs_attr_shortform_t
*)XFS_DFORK_APTR(dip
);
1054 if (be16_to_cpu(asf
->hdr
.totsize
) > XFS_DFORK_ASIZE(dip
, mp
)) {
1056 _("local inode %" PRIu64
" attr fork too large (size %d, max = %d)\n"),
1057 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1058 XFS_DFORK_ASIZE(dip
, mp
));
1061 if (be16_to_cpu(asf
->hdr
.totsize
) < sizeof(xfs_attr_sf_hdr_t
)) {
1063 _("local inode %" PRIu64
" attr too small (size = %d, min size = %zd)\n"),
1064 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1065 sizeof(xfs_attr_sf_hdr_t
));
1074 process_symlink_extlist(xfs_mount_t
*mp
, xfs_ino_t lino
, xfs_dinode_t
*dino
)
1076 xfs_fileoff_t expected_offset
;
1078 xfs_bmbt_irec_t irec
;
1083 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1084 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
)
1087 _("mismatch between format (%d) and size (%" PRId64
") in symlink ino %" PRIu64
"\n"),
1089 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1092 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
) {
1094 _("mismatch between format (%d) and size (%" PRId64
") in symlink inode %" PRIu64
"\n"),
1096 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1100 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_DPTR(dino
);
1101 numrecs
= be32_to_cpu(dino
->di_nextents
);
1104 * the max # of extents in a symlink inode is equal to the
1105 * number of max # of blocks required to store the symlink
1107 if (numrecs
> max_symlink_blocks
) {
1109 _("bad number of extents (%d) in symlink %" PRIu64
" data fork\n"),
1114 max_blocks
= max_symlink_blocks
;
1115 expected_offset
= 0;
1117 for (i
= 0; i
< numrecs
; i
++) {
1118 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
1119 if (irec
.br_startoff
!= expected_offset
) {
1121 _("bad extent #%d offset (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1122 i
, irec
.br_startoff
, lino
);
1125 if (irec
.br_blockcount
== 0 || irec
.br_blockcount
> max_blocks
) {
1127 _("bad extent #%d count (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1128 i
, irec
.br_blockcount
, lino
);
1132 max_blocks
-= irec
.br_blockcount
;
1133 expected_offset
+= irec
.br_blockcount
;
1140 * takes a name and length and returns 1 if the name contains
1141 * a \0, returns 0 otherwise
1144 null_check(char *name
, int length
)
1148 ASSERT(length
< XFS_SYMLINK_MAXLEN
);
1150 for (i
= 0; i
< length
; i
++, name
++) {
1159 * This does /not/ do quotacheck, it validates the basic quota
1160 * inode metadata, checksums, etc.
1162 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
1164 process_quota_inode(
1165 struct xfs_mount
*mp
,
1167 struct xfs_dinode
*dino
,
1169 struct blkmap
*blkmap
)
1171 xfs_fsblock_t fsbno
;
1173 xfs_filblks_t dqchunklen
;
1176 char *quota_string
= NULL
;
1184 quota_type
= XFS_DQ_USER
;
1185 quota_string
= _("User quota");
1188 quota_type
= XFS_DQ_GROUP
;
1189 quota_string
= _("Group quota");
1192 quota_type
= XFS_DQ_PROJ
;
1193 quota_string
= _("Project quota");
1199 dqchunklen
= XFS_FSB_TO_BB(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
);
1200 dqperchunk
= libxfs_calc_dquots_per_chunk(dqchunklen
);
1204 while ((qbno
= blkmap_next_off(blkmap
, qbno
, &t
)) != NULLFILEOFF
) {
1208 fsbno
= blkmap_get(blkmap
, qbno
);
1209 dqid
= (xfs_dqid_t
)qbno
* dqperchunk
;
1211 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1212 dqchunklen
, 0, &xfs_dquot_buf_ops
);
1215 _("cannot read inode %" PRIu64
", file block %" PRIu64
", disk block %" PRIu64
"\n"),
1221 for (i
= 0; i
< dqperchunk
; i
++, dqid
++, dqb
++) {
1224 /* We only print the first problem we find */
1225 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1226 if (!libxfs_verify_cksum((char *)dqb
,
1228 XFS_DQUOT_CRC_OFF
)) {
1229 do_warn(_("%s: bad CRC for id %u. "),
1230 quota_string
, dqid
);
1235 if (!uuid_equal(&dqb
->dd_uuid
,
1236 &mp
->m_sb
.sb_meta_uuid
)) {
1237 do_warn(_("%s: bad UUID for id %u. "),
1238 quota_string
, dqid
);
1243 if (libxfs_dquot_verify(mp
, &dqb
->dd_diskdq
, dqid
,
1244 quota_type
) != NULL
) {
1245 do_warn(_("%s: Corrupt quota for id %u. "),
1246 quota_string
, dqid
);
1253 do_warn(_("Would correct.\n"));
1255 do_warn(_("Corrected.\n"));
1256 libxfs_dqblk_repair(mp
, dqb
,
1263 if (writebuf
&& !no_modify
)
1264 libxfs_writebuf(bp
, 0);
1272 process_symlink_remote(
1273 struct xfs_mount
*mp
,
1275 struct xfs_dinode
*dino
,
1276 struct blkmap
*blkmap
,
1279 xfs_fsblock_t fsbno
;
1287 pathlen
= be64_to_cpu(dino
->di_size
);
1290 while (pathlen
> 0) {
1295 fsbno
= blkmap_get(blkmap
, i
);
1296 if (fsbno
== NULLFSBLOCK
) {
1298 _("cannot read inode %" PRIu64
", file block %d, NULL disk block\n"),
1304 * There's a symlink header for each contiguous extent. If
1305 * there are contiguous blocks, read them in one go.
1307 while (blk_cnt
<= max_symlink_blocks
) {
1308 if (blkmap_get(blkmap
, i
+ 1) != fsbno
+ 1)
1314 byte_cnt
= XFS_FSB_TO_B(mp
, blk_cnt
);
1316 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1317 BTOBB(byte_cnt
), 0, &xfs_symlink_buf_ops
);
1320 _("cannot read inode %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1324 if (bp
->b_error
== -EFSCORRUPTED
) {
1326 _("Corrupt symlink remote block %" PRIu64
", inode %" PRIu64
".\n"),
1331 if (bp
->b_error
== -EFSBADCRC
) {
1333 _("Bad symlink buffer CRC, block %" PRIu64
", inode %" PRIu64
".\n"
1334 "Correcting CRC, but symlink may be bad.\n"), fsbno
, lino
);
1338 byte_cnt
= XFS_SYMLINK_BUF_SPACE(mp
, byte_cnt
);
1339 byte_cnt
= min(pathlen
, byte_cnt
);
1342 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1343 if (!libxfs_symlink_hdr_ok(lino
, offset
,
1346 _("bad symlink header ino %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1351 src
+= sizeof(struct xfs_dsymlink_hdr
);
1354 memmove(dst
+ offset
, src
, byte_cnt
);
1356 pathlen
-= byte_cnt
;
1360 if (badcrc
&& !no_modify
)
1361 libxfs_writebuf(bp
, 0);
1369 * like usual, returns 0 if everything's ok and 1 if something's
1380 char data
[XFS_SYMLINK_MAXLEN
];
1383 * check size against kernel symlink limits. we know
1384 * size is consistent with inode storage format -- e.g.
1385 * the inode is structurally ok so we don't have to check
1388 if (be64_to_cpu(dino
->di_size
) >= XFS_SYMLINK_MAXLEN
) {
1389 do_warn(_("symlink in inode %" PRIu64
" too long (%llu chars)\n"),
1390 lino
, (unsigned long long) be64_to_cpu(dino
->di_size
));
1394 if (be64_to_cpu(dino
->di_size
) == 0) {
1395 do_warn(_("zero size symlink in inode %" PRIu64
"\n"), lino
);
1400 * have to check symlink component by component.
1401 * get symlink contents into data area
1404 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1406 * local symlink, just copy the symlink out of the
1407 * inode into the data area
1409 memmove(symlink
, XFS_DFORK_DPTR(dino
),
1410 be64_to_cpu(dino
->di_size
));
1414 error
= process_symlink_remote(mp
, lino
, dino
, blkmap
, symlink
);
1419 data
[be64_to_cpu(dino
->di_size
)] = '\0';
1424 if (null_check(symlink
, be64_to_cpu(dino
->di_size
))) {
1426 _("found illegal null character in symlink inode %" PRIu64
"\n"),
1435 * called to process the set of misc inode special inode types
1436 * that have no associated data storage (fifos, pipes, devices, etc.).
1439 process_misc_ino_types(xfs_mount_t
*mp
,
1445 * disallow mountpoint inodes until such time as the
1446 * kernel actually allows them to be created (will
1447 * probably require a superblock version rev, sigh).
1449 if (type
== XR_INO_MOUNTPOINT
) {
1451 _("inode %" PRIu64
" has bad inode type (IFMNT)\n"), lino
);
1456 * must also have a zero size
1458 if (be64_to_cpu(dino
->di_size
) != 0) {
1462 _("size of character device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1463 (int64_t)be64_to_cpu(dino
->di_size
));
1467 _("size of block device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1468 (int64_t)be64_to_cpu(dino
->di_size
));
1472 _("size of socket inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1473 (int64_t)be64_to_cpu(dino
->di_size
));
1477 _("size of fifo inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1478 (int64_t)be64_to_cpu(dino
->di_size
));
1484 _("size of quota inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1485 (int64_t)be64_to_cpu(dino
->di_size
));
1488 do_warn(_("Internal error - process_misc_ino_types, "
1489 "illegal type %d\n"), type
);
1500 process_misc_ino_types_blocks(xfs_rfsblock_t totblocks
, xfs_ino_t lino
, int type
)
1503 * you can not enforce all misc types have zero data fork blocks
1504 * by checking dino->di_nblocks because atotblocks (attribute
1505 * blocks) are part of nblocks. We must check this later when atotblocks
1506 * has been calculated or by doing a simple check that anExtents == 0.
1507 * We must also guarantee that totblocks is 0. Thus nblocks checking
1508 * will be done later in process_dinode_int for misc types.
1511 if (totblocks
!= 0) {
1515 _("size of character device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1520 _("size of block device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1525 _("size of socket inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1530 _("size of fifo inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1545 return be16_to_cpu(dino
->di_mode
) & S_IFMT
;
1553 int mode
= be16_to_cpu(dino
->di_mode
);
1555 ASSERT((new_fmt
& ~S_IFMT
) == 0);
1559 dino
->di_mode
= cpu_to_be16(mode
);
1563 check_dinode_mode_format(
1564 xfs_dinode_t
*dinoc
)
1566 if (dinoc
->di_format
>= XFS_DINODE_FMT_UUID
)
1567 return -1; /* FMT_UUID is not used */
1569 switch (dinode_fmt(dinoc
)) {
1574 return (dinoc
->di_format
!= XFS_DINODE_FMT_DEV
) ? -1 : 0;
1577 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1578 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1581 return (dinoc
->di_format
< XFS_DINODE_FMT_EXTENTS
||
1582 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1585 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1586 dinoc
->di_format
> XFS_DINODE_FMT_EXTENTS
) ? -1 : 0;
1590 return 0; /* invalid modes are checked elsewhere */
1594 * If inode is a superblock inode, does type check to make sure is it valid.
1595 * Returns 0 if it's valid, non-zero if it needs to be cleared.
1599 process_check_sb_inodes(
1601 xfs_dinode_t
*dinoc
,
1606 if (lino
== mp
->m_sb
.sb_rootino
) {
1607 if (*type
!= XR_INO_DIR
) {
1608 do_warn(_("root inode %" PRIu64
" has bad type 0x%x\n"),
1609 lino
, dinode_fmt(dinoc
));
1612 do_warn(_("resetting to directory\n"));
1613 change_dinode_fmt(dinoc
, S_IFDIR
);
1616 do_warn(_("would reset to directory\n"));
1620 if (lino
== mp
->m_sb
.sb_uquotino
) {
1621 if (*type
!= XR_INO_UQUOTA
) {
1622 do_warn(_("user quota inode %" PRIu64
" has bad type 0x%x\n"),
1623 lino
, dinode_fmt(dinoc
));
1624 mp
->m_sb
.sb_uquotino
= NULLFSINO
;
1629 if (lino
== mp
->m_sb
.sb_gquotino
) {
1630 if (*type
!= XR_INO_GQUOTA
) {
1631 do_warn(_("group quota inode %" PRIu64
" has bad type 0x%x\n"),
1632 lino
, dinode_fmt(dinoc
));
1633 mp
->m_sb
.sb_gquotino
= NULLFSINO
;
1638 if (lino
== mp
->m_sb
.sb_pquotino
) {
1639 if (*type
!= XR_INO_PQUOTA
) {
1640 do_warn(_("project quota inode %" PRIu64
" has bad type 0x%x\n"),
1641 lino
, dinode_fmt(dinoc
));
1642 mp
->m_sb
.sb_pquotino
= NULLFSINO
;
1647 if (lino
== mp
->m_sb
.sb_rsumino
) {
1648 if (*type
!= XR_INO_RTSUM
) {
1650 _("realtime summary inode %" PRIu64
" has bad type 0x%x, "),
1651 lino
, dinode_fmt(dinoc
));
1653 do_warn(_("resetting to regular file\n"));
1654 change_dinode_fmt(dinoc
, S_IFREG
);
1657 do_warn(_("would reset to regular file\n"));
1660 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1662 _("bad # of extents (%u) for realtime summary inode %" PRIu64
"\n"),
1663 be32_to_cpu(dinoc
->di_nextents
), lino
);
1668 if (lino
== mp
->m_sb
.sb_rbmino
) {
1669 if (*type
!= XR_INO_RTBITMAP
) {
1671 _("realtime bitmap inode %" PRIu64
" has bad type 0x%x, "),
1672 lino
, dinode_fmt(dinoc
));
1674 do_warn(_("resetting to regular file\n"));
1675 change_dinode_fmt(dinoc
, S_IFREG
);
1678 do_warn(_("would reset to regular file\n"));
1681 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1683 _("bad # of extents (%u) for realtime bitmap inode %" PRIu64
"\n"),
1684 be32_to_cpu(dinoc
->di_nextents
), lino
);
1693 * general size/consistency checks:
1695 * if the size <= size of the data fork, directories must be
1696 * local inodes unlike regular files which would be extent inodes.
1697 * all the other mentioned types have to have a zero size value.
1699 * if the size and format don't match, get out now rather than
1700 * risk trying to process a non-existent extents or btree
1704 process_check_inode_sizes(
1710 xfs_fsize_t size
= be64_to_cpu(dino
->di_size
);
1715 if (size
<= XFS_DFORK_DSIZE(dino
, mp
) &&
1716 dino
->di_format
!= XFS_DINODE_FMT_LOCAL
) {
1718 _("mismatch between format (%d) and size (%" PRId64
") in directory ino %" PRIu64
"\n"),
1719 dino
->di_format
, size
, lino
);
1722 if (size
> XFS_DIR2_LEAF_OFFSET
) {
1724 _("directory inode %" PRIu64
" has bad size %" PRId64
"\n"),
1730 case XR_INO_SYMLINK
:
1731 if (process_symlink_extlist(mp
, lino
, dino
)) {
1732 do_warn(_("bad data fork in symlink %" PRIu64
"\n"), lino
);
1737 case XR_INO_CHRDEV
: /* fall through to FIFO case ... */
1738 case XR_INO_BLKDEV
: /* fall through to FIFO case ... */
1739 case XR_INO_SOCK
: /* fall through to FIFO case ... */
1740 case XR_INO_MOUNTPOINT
: /* fall through to FIFO case ... */
1742 if (process_misc_ino_types(mp
, dino
, lino
, type
))
1749 /* Quota inodes have same restrictions as above types */
1750 if (process_misc_ino_types(mp
, dino
, lino
, type
))
1756 * if we have no realtime blocks, any inode claiming
1757 * to be a real-time file is bogus
1759 if (mp
->m_sb
.sb_rblocks
== 0) {
1761 _("found inode %" PRIu64
" claiming to be a real-time file\n"), lino
);
1766 case XR_INO_RTBITMAP
:
1767 if (size
!= (int64_t)mp
->m_sb
.sb_rbmblocks
*
1768 mp
->m_sb
.sb_blocksize
) {
1770 _("realtime bitmap inode %" PRIu64
" has bad size %" PRId64
" (should be %" PRIu64
")\n"),
1772 (int64_t) mp
->m_sb
.sb_rbmblocks
*
1773 mp
->m_sb
.sb_blocksize
);
1779 if (size
!= mp
->m_rsumsize
) {
1781 _("realtime summary inode %" PRIu64
" has bad size %" PRId64
" (should be %d)\n"),
1782 lino
, size
, mp
->m_rsumsize
);
1794 * check for illegal values of forkoff
1797 process_check_inode_forkoff(
1802 if (dino
->di_forkoff
== 0)
1805 switch (dino
->di_format
) {
1806 case XFS_DINODE_FMT_DEV
:
1807 if (dino
->di_forkoff
!= (roundup(sizeof(xfs_dev_t
), 8) >> 3)) {
1809 _("bad attr fork offset %d in dev inode %" PRIu64
", should be %d\n"),
1810 dino
->di_forkoff
, lino
,
1811 (int)(roundup(sizeof(xfs_dev_t
), 8) >> 3));
1815 case XFS_DINODE_FMT_LOCAL
: /* fall through ... */
1816 case XFS_DINODE_FMT_EXTENTS
: /* fall through ... */
1817 case XFS_DINODE_FMT_BTREE
:
1818 if (dino
->di_forkoff
>=
1819 (XFS_LITINO(mp
, dino
->di_version
) >> 3)) {
1821 _("bad attr fork offset %d in inode %" PRIu64
", max=%d\n"),
1822 dino
->di_forkoff
, lino
,
1823 XFS_LITINO(mp
, dino
->di_version
) >> 3);
1828 do_error(_("unexpected inode format %d\n"), dino
->di_format
);
1835 * Updates the inodes block and extent counts if they are wrong
1838 process_inode_blocks_and_extents(
1840 xfs_rfsblock_t nblocks
,
1846 if (nblocks
!= be64_to_cpu(dino
->di_nblocks
)) {
1849 _("correcting nblocks for inode %" PRIu64
", was %llu - counted %" PRIu64
"\n"), lino
,
1850 (unsigned long long) be64_to_cpu(dino
->di_nblocks
),
1852 dino
->di_nblocks
= cpu_to_be64(nblocks
);
1856 _("bad nblocks %llu for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
1857 (unsigned long long) be64_to_cpu(dino
->di_nblocks
),
1862 if (nextents
> MAXEXTNUM
) {
1864 _("too many data fork extents (%" PRIu64
") in inode %" PRIu64
"\n"),
1868 if (nextents
!= be32_to_cpu(dino
->di_nextents
)) {
1871 _("correcting nextents for inode %" PRIu64
", was %d - counted %" PRIu64
"\n"),
1873 be32_to_cpu(dino
->di_nextents
),
1875 dino
->di_nextents
= cpu_to_be32(nextents
);
1879 _("bad nextents %d for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
1880 be32_to_cpu(dino
->di_nextents
),
1885 if (anextents
> MAXAEXTNUM
) {
1887 _("too many attr fork extents (%" PRIu64
") in inode %" PRIu64
"\n"),
1891 if (anextents
!= be16_to_cpu(dino
->di_anextents
)) {
1894 _("correcting anextents for inode %" PRIu64
", was %d - counted %" PRIu64
"\n"),
1896 be16_to_cpu(dino
->di_anextents
), anextents
);
1897 dino
->di_anextents
= cpu_to_be16(anextents
);
1901 _("bad anextents %d for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
1902 be16_to_cpu(dino
->di_anextents
),
1908 * We are comparing different units here, but that's fine given that
1909 * an extent has to have at least a block in it.
1911 if (nblocks
< nextents
+ anextents
) {
1913 _("nblocks (%" PRIu64
") smaller than nextents for inode %" PRIu64
"\n"), nblocks
, lino
);
1921 * check data fork -- if it's bad, clear the inode
1924 process_inode_data_fork(
1926 xfs_agnumber_t agno
,
1931 xfs_rfsblock_t
*totblocks
,
1936 xfs_ino_t lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1941 * extent count on disk is only valid for positive values. The kernel
1942 * uses negative values in memory. hence if we see negative numbers
1945 nex
= be32_to_cpu(dino
->di_nextents
);
1951 if (*nextents
> be64_to_cpu(dino
->di_nblocks
))
1955 if (dino
->di_format
!= XFS_DINODE_FMT_LOCAL
&& type
!= XR_INO_RTDATA
)
1956 *dblkmap
= blkmap_alloc(*nextents
, XFS_DATA_FORK
);
1959 switch (dino
->di_format
) {
1960 case XFS_DINODE_FMT_LOCAL
:
1961 err
= process_lclinode(mp
, agno
, ino
, dino
, XFS_DATA_FORK
);
1964 case XFS_DINODE_FMT_EXTENTS
:
1965 err
= process_exinode(mp
, agno
, ino
, dino
, type
, dirty
,
1966 totblocks
, nextents
, dblkmap
, XFS_DATA_FORK
,
1969 case XFS_DINODE_FMT_BTREE
:
1970 err
= process_btinode(mp
, agno
, ino
, dino
, type
, dirty
,
1971 totblocks
, nextents
, dblkmap
, XFS_DATA_FORK
,
1974 case XFS_DINODE_FMT_DEV
: /* fall through */
1978 do_error(_("unknown format %d, ino %" PRIu64
" (mode = %d)\n"),
1979 dino
->di_format
, lino
, be16_to_cpu(dino
->di_mode
));
1983 do_warn(_("bad data fork in inode %" PRIu64
"\n"), lino
);
1985 clear_dinode(mp
, dino
, lino
);
1993 * if check_dups was non-zero, we have to
1994 * re-process data fork to set bitmap since the
1995 * bitmap wasn't set the first time through
1997 switch (dino
->di_format
) {
1998 case XFS_DINODE_FMT_LOCAL
:
1999 err
= process_lclinode(mp
, agno
, ino
, dino
,
2002 case XFS_DINODE_FMT_EXTENTS
:
2003 err
= process_exinode(mp
, agno
, ino
, dino
, type
,
2004 dirty
, totblocks
, nextents
, dblkmap
,
2007 case XFS_DINODE_FMT_BTREE
:
2008 err
= process_btinode(mp
, agno
, ino
, dino
, type
,
2009 dirty
, totblocks
, nextents
, dblkmap
,
2012 case XFS_DINODE_FMT_DEV
: /* fall through */
2016 do_error(_("unknown format %d, ino %" PRIu64
" (mode = %d)\n"),
2017 dino
->di_format
, lino
,
2018 be16_to_cpu(dino
->di_mode
));
2021 if (no_modify
&& err
!= 0)
2030 * Process extended attribute fork in inode
2033 process_inode_attr_fork(
2035 xfs_agnumber_t agno
,
2040 xfs_rfsblock_t
*atotblocks
,
2041 uint64_t *anextents
,
2043 int extra_attr_check
,
2046 xfs_ino_t lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2047 blkmap_t
*ablkmap
= NULL
;
2051 if (!XFS_DFORK_Q(dino
)) {
2053 if (dino
->di_aformat
!= XFS_DINODE_FMT_EXTENTS
) {
2054 do_warn(_("bad attribute format %d in inode %" PRIu64
", "),
2055 dino
->di_aformat
, lino
);
2057 do_warn(_("resetting value\n"));
2058 dino
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
2061 do_warn(_("would reset value\n"));
2066 *anextents
= be16_to_cpu(dino
->di_anextents
);
2067 if (*anextents
> be64_to_cpu(dino
->di_nblocks
))
2070 switch (dino
->di_aformat
) {
2071 case XFS_DINODE_FMT_LOCAL
:
2074 err
= process_lclinode(mp
, agno
, ino
, dino
, XFS_ATTR_FORK
);
2076 case XFS_DINODE_FMT_EXTENTS
:
2077 ablkmap
= blkmap_alloc(*anextents
, XFS_ATTR_FORK
);
2079 err
= process_exinode(mp
, agno
, ino
, dino
, type
, dirty
,
2080 atotblocks
, anextents
, &ablkmap
,
2081 XFS_ATTR_FORK
, check_dups
);
2083 case XFS_DINODE_FMT_BTREE
:
2084 ablkmap
= blkmap_alloc(*anextents
, XFS_ATTR_FORK
);
2086 err
= process_btinode(mp
, agno
, ino
, dino
, type
, dirty
,
2087 atotblocks
, anextents
, &ablkmap
,
2088 XFS_ATTR_FORK
, check_dups
);
2091 do_warn(_("illegal attribute format %d, ino %" PRIu64
"\n"),
2092 dino
->di_aformat
, lino
);
2099 * clear the attribute fork if necessary. we can't
2100 * clear the inode because we've already put the
2101 * inode space info into the blockmap.
2103 * XXX - put the inode onto the "move it" list and
2104 * log the the attribute scrubbing
2106 do_warn(_("bad attribute fork in inode %" PRIu64
), lino
);
2109 do_warn(_(", clearing attr fork\n"));
2110 *dirty
+= clear_dinode_attr(mp
, dino
, lino
);
2111 dino
->di_aformat
= XFS_DINODE_FMT_LOCAL
;
2114 do_warn(_(", would clear attr fork\n"));
2119 blkmap_free(ablkmap
);
2126 switch (dino
->di_aformat
) {
2127 case XFS_DINODE_FMT_LOCAL
:
2128 err
= process_lclinode(mp
, agno
, ino
, dino
,
2131 case XFS_DINODE_FMT_EXTENTS
:
2132 err
= process_exinode(mp
, agno
, ino
, dino
,
2133 type
, dirty
, atotblocks
, anextents
,
2134 &ablkmap
, XFS_ATTR_FORK
, 0);
2136 case XFS_DINODE_FMT_BTREE
:
2137 err
= process_btinode(mp
, agno
, ino
, dino
,
2138 type
, dirty
, atotblocks
, anextents
,
2139 &ablkmap
, XFS_ATTR_FORK
, 0);
2142 do_error(_("illegal attribute fmt %d, ino %" PRIu64
"\n"),
2143 dino
->di_aformat
, lino
);
2146 if (no_modify
&& err
!= 0) {
2147 blkmap_free(ablkmap
);
2155 * do attribute semantic-based consistency checks now
2158 /* get this only in phase 3, not in both phase 3 and 4 */
2159 if (extra_attr_check
&&
2160 process_attributes(mp
, lino
, dino
, ablkmap
, &repair
)) {
2162 _("problem with attribute contents in inode %" PRIu64
"\n"),
2165 /* clear attributes if not done already */
2167 *dirty
+= clear_dinode_attr(mp
, dino
, lino
);
2168 dino
->di_aformat
= XFS_DINODE_FMT_LOCAL
;
2170 do_warn(_("would clear attr fork\n"));
2176 *dirty
= 1; /* it's been repaired */
2179 blkmap_free(ablkmap
);
2184 * check nlinks feature, if it's a version 1 inode,
2185 * just leave nlinks alone. even if it's set wrong,
2186 * it'll be reset when read in.
2190 process_check_inode_nlink_version(
2197 * if it's a version 2 inode, it should have a zero
2198 * onlink field, so clear it.
2200 if (dino
->di_version
> 1 && dino
->di_onlink
!= 0) {
2203 _("clearing obsolete nlink field in version 2 inode %" PRIu64
", was %d, now 0\n"),
2204 lino
, be16_to_cpu(dino
->di_onlink
));
2205 dino
->di_onlink
= 0;
2209 _("would clear obsolete nlink field in version 2 inode %" PRIu64
", currently %d\n"),
2210 lino
, be16_to_cpu(dino
->di_onlink
));
2216 /* Check nanoseconds of a timestamp don't exceed 1 second. */
2221 struct xfs_timestamp
*t
,
2224 if (be32_to_cpu(t
->t_nsec
) < 1000000000)
2228 _("Bad %s nsec %u on inode %" PRIu64
", "), name
, be32_to_cpu(t
->t_nsec
), lino
);
2230 do_warn(_("would reset to zero\n"));
2232 do_warn(_("resetting to zero\n"));
2239 * returns 0 if the inode is ok, 1 if the inode is corrupt
2240 * check_dups can be set to 1 *only* when called by the
2241 * first pass of the duplicate block checking of phase 4.
2242 * *dirty is set > 0 if the dinode has been altered and
2243 * needs to be written out.
2245 * for detailed, info, look at process_dinode() comments.
2248 process_dinode_int(xfs_mount_t
*mp
,
2250 xfs_agnumber_t agno
,
2252 int was_free
, /* 1 if inode is currently free */
2253 int *dirty
, /* out == > 0 if inode is now dirty */
2254 int *used
, /* out == 1 if inode is in use */
2255 int verify_mode
, /* 1 == verify but don't modify inode */
2256 int uncertain
, /* 1 == inode is uncertain */
2257 int ino_discovery
, /* 1 == check dirs for unknown inodes */
2258 int check_dups
, /* 1 == check if inode claims
2259 * duplicate blocks */
2260 int extra_attr_check
, /* 1 == do attribute format and value checks */
2261 int *isa_dir
, /* out == 1 if inode is a directory */
2262 xfs_ino_t
*parent
) /* out -- parent if ino is a dir */
2264 xfs_rfsblock_t totblocks
= 0;
2265 xfs_rfsblock_t atotblocks
= 0;
2272 const int is_free
= 0;
2273 const int is_used
= 1;
2274 blkmap_t
*dblkmap
= NULL
;
2276 *dirty
= *isa_dir
= 0;
2278 type
= XR_INO_UNKNOWN
;
2280 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2281 di_mode
= be16_to_cpu(dino
->di_mode
);
2284 * if in verify mode, don't modify the inode.
2286 * if correcting, reset stuff that has known values
2288 * if in uncertain mode, be silent on errors since we're
2289 * trying to find out if these are inodes as opposed
2290 * to assuming that they are. Just return the appropriate
2291 * return code in that case.
2293 * If uncertain is set, verify_mode MUST be set.
2295 ASSERT(uncertain
== 0 || verify_mode
!= 0);
2298 * This is the only valid point to check the CRC; after this we may have
2299 * made changes which invalidate it, and the CRC is only updated again
2300 * when it gets written out.
2302 * Of course if we make any modifications after this, the inode gets
2303 * rewritten, and the CRC is updated automagically.
2305 if (xfs_sb_version_hascrc(&mp
->m_sb
) &&
2306 !libxfs_verify_cksum((char *)dino
, mp
->m_sb
.sb_inodesize
,
2307 XFS_DINODE_CRC_OFF
)) {
2310 do_warn(_("bad CRC for inode %" PRIu64
"%c"),
2311 lino
, verify_mode
? '\n' : ',');
2314 do_warn(_(" will rewrite\n"));
2317 do_warn(_(" would rewrite\n"));
2321 if (be16_to_cpu(dino
->di_magic
) != XFS_DINODE_MAGIC
) {
2324 do_warn(_("bad magic number 0x%x on inode %" PRIu64
"%c"),
2325 be16_to_cpu(dino
->di_magic
), lino
,
2326 verify_mode
? '\n' : ',');
2329 do_warn(_(" resetting magic number\n"));
2330 dino
->di_magic
= cpu_to_be16(XFS_DINODE_MAGIC
);
2333 do_warn(_(" would reset magic number\n"));
2337 if (!libxfs_dinode_good_version(mp
, dino
->di_version
)) {
2340 do_warn(_("bad version number 0x%x on inode %" PRIu64
"%c"),
2341 (__s8
)dino
->di_version
, lino
,
2342 verify_mode
? '\n' : ',');
2345 do_warn(_(" resetting version number\n"));
2347 xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
2350 do_warn(_(" would reset version number\n"));
2355 * We don't bother checking the CRC here - we cannot guarantee that when
2356 * we are called here that the inode has not already been modified in
2357 * memory and hence invalidated the CRC.
2359 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
2360 if (be64_to_cpu(dino
->di_ino
) != lino
) {
2363 _("inode identifier %llu mismatch on inode %" PRIu64
"\n"),
2364 (unsigned long long)be64_to_cpu(dino
->di_ino
),
2370 if (platform_uuid_compare(&dino
->di_uuid
,
2371 &mp
->m_sb
.sb_meta_uuid
)) {
2374 _("UUID mismatch on inode %" PRIu64
"\n"), lino
);
2382 * blow out of here if the inode size is < 0
2384 if ((xfs_fsize_t
)be64_to_cpu(dino
->di_size
) < 0) {
2387 _("bad (negative) size %" PRId64
" on inode %" PRIu64
"\n"),
2388 (int64_t)be64_to_cpu(dino
->di_size
),
2396 * if not in verify mode, check to see if the inode and imap
2397 * agree that the inode is free
2399 if (!verify_mode
&& di_mode
== 0) {
2401 * was_free value is not meaningful if we're in verify mode
2405 * easy case, inode free -- inode and map agree, check
2406 * it just in case to ensure that format, etc. are
2409 if (libxfs_dinode_verify(mp
, lino
, dino
) != NULL
) {
2411 _("free inode %" PRIu64
" contains errors, "), lino
);
2413 clear_dinode(mp
, dino
, lino
);
2414 do_warn(_("corrected\n"));
2417 do_warn(_("would correct\n"));
2424 * the inode looks free but the map says it's in use.
2425 * clear the inode just to be safe and mark the inode
2429 _("imap claims a free inode %" PRIu64
" is in use, "), lino
);
2431 do_warn(_("correcting imap and clearing inode\n"));
2432 clear_dinode(mp
, dino
, lino
);
2436 do_warn(_("would correct imap and clear inode\n"));
2442 * because of the lack of any write ordering guarantee, it's
2443 * possible that the core got updated but the forks didn't.
2444 * so rather than be ambitious (and probably incorrect),
2445 * if there's an inconsistency, we get conservative and
2446 * just pitch the file. blow off checking formats of
2447 * free inodes since technically any format is legal
2448 * as we reset the inode when we re-use it.
2450 if (di_mode
!= 0 && check_dinode_mode_format(dino
) != 0) {
2453 _("bad inode format in inode %" PRIu64
"\n"), lino
);
2460 * check that we only have valid flags set, and those that are set make
2463 if (dino
->di_flags
) {
2464 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2466 if (flags
& ~XFS_DIFLAG_ANY
) {
2469 _("Bad flags set in inode %" PRIu64
"\n"),
2472 flags
&= XFS_DIFLAG_ANY
;
2475 if (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
)) {
2476 /* need an rt-dev! */
2480 _("inode %" PRIu64
" has RT flag set but there is no RT device\n"),
2483 flags
&= ~(XFS_DIFLAG_REALTIME
|
2484 XFS_DIFLAG_RTINHERIT
);
2487 if (flags
& XFS_DIFLAG_NEWRTBM
) {
2488 /* must be a rt bitmap inode */
2489 if (lino
!= mp
->m_sb
.sb_rbmino
) {
2492 _("inode %" PRIu64
" not rt bitmap\n"),
2495 flags
&= ~XFS_DIFLAG_NEWRTBM
;
2498 if (flags
& (XFS_DIFLAG_RTINHERIT
|
2499 XFS_DIFLAG_EXTSZINHERIT
|
2500 XFS_DIFLAG_PROJINHERIT
|
2501 XFS_DIFLAG_NOSYMLINKS
)) {
2502 /* must be a directory */
2503 if (di_mode
&& !S_ISDIR(di_mode
)) {
2506 _("directory flags set on non-directory inode %" PRIu64
"\n" ),
2509 flags
&= ~(XFS_DIFLAG_RTINHERIT
|
2510 XFS_DIFLAG_EXTSZINHERIT
|
2511 XFS_DIFLAG_PROJINHERIT
|
2512 XFS_DIFLAG_NOSYMLINKS
);
2515 if (flags
& (XFS_DIFLAG_REALTIME
| FS_XFLAG_EXTSIZE
)) {
2516 /* must be a file */
2517 if (di_mode
&& !S_ISREG(di_mode
)) {
2520 _("file flags set on non-file inode %" PRIu64
"\n"),
2523 flags
&= ~(XFS_DIFLAG_REALTIME
|
2527 if (!verify_mode
&& flags
!= be16_to_cpu(dino
->di_flags
)) {
2529 do_warn(_("fixing bad flags.\n"));
2530 dino
->di_flags
= cpu_to_be16(flags
);
2533 do_warn(_("would fix bad flags.\n"));
2538 * check that we only have valid flags2 set, and those that are set make
2541 if (dino
->di_version
>= 3) {
2542 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2543 uint64_t flags2
= be64_to_cpu(dino
->di_flags2
);
2545 if (flags2
& ~XFS_DIFLAG2_ANY
) {
2548 _("Bad flags2 set in inode %" PRIu64
"\n"),
2551 flags2
&= XFS_DIFLAG2_ANY
;
2554 if (flags2
& XFS_DIFLAG2_DAX
) {
2555 /* must be a file or dir */
2556 if (di_mode
&& !(S_ISREG(di_mode
) || S_ISDIR(di_mode
))) {
2559 _("DAX flag set on special inode %" PRIu64
"\n"),
2562 flags2
&= ~XFS_DIFLAG2_DAX
;
2566 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2567 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2570 _("inode %" PRIu64
" is marked reflinked but file system does not support reflink\n"),
2576 if (flags2
& XFS_DIFLAG2_REFLINK
) {
2577 /* must be a file */
2578 if (di_mode
&& !S_ISREG(di_mode
)) {
2581 _("reflink flag set on non-file inode %" PRIu64
"\n"),
2588 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2589 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2592 _("Cannot have a reflinked realtime inode %" PRIu64
"\n"),
2598 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2599 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2602 _("inode %" PRIu64
" has CoW extent size hint but file system does not support reflink\n"),
2605 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2608 if (flags2
& XFS_DIFLAG2_COWEXTSIZE
) {
2609 /* must be a directory or file */
2610 if (di_mode
&& !S_ISDIR(di_mode
) && !S_ISREG(di_mode
)) {
2613 _("CoW extent size flag set on non-file, non-directory inode %" PRIu64
"\n" ),
2616 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2620 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2621 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2624 _("Cannot have CoW extent size hint on a realtime inode %" PRIu64
"\n"),
2627 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2630 if (!verify_mode
&& flags2
!= be64_to_cpu(dino
->di_flags2
)) {
2632 do_warn(_("fixing bad flags2.\n"));
2633 dino
->di_flags2
= cpu_to_be64(flags2
);
2636 do_warn(_("would fix bad flags2.\n"));
2644 * clear the next unlinked field if necessary on a good
2645 * inode only during phase 4 -- when checking for inodes
2646 * referencing duplicate blocks. then it's safe because
2647 * we've done the inode discovery and have found all the inodes
2648 * we're going to find. check_dups is set to 1 only during
2651 if (check_dups
&& be32_to_cpu(dino
->di_next_unlinked
) != NULLAGINO
) {
2654 _("Would clear next_unlinked in inode %" PRIu64
"\n"), lino
);
2656 clear_dinode_unlinked(mp
, dino
);
2658 _("Cleared next_unlinked in inode %" PRIu64
"\n"), lino
);
2663 /* set type and map type info */
2665 switch (di_mode
& S_IFMT
) {
2671 if (be16_to_cpu(dino
->di_flags
) & XFS_DIFLAG_REALTIME
)
2672 type
= XR_INO_RTDATA
;
2673 else if (lino
== mp
->m_sb
.sb_rbmino
)
2674 type
= XR_INO_RTBITMAP
;
2675 else if (lino
== mp
->m_sb
.sb_rsumino
)
2676 type
= XR_INO_RTSUM
;
2677 else if (lino
== mp
->m_sb
.sb_uquotino
)
2678 type
= XR_INO_UQUOTA
;
2679 else if (lino
== mp
->m_sb
.sb_gquotino
)
2680 type
= XR_INO_GQUOTA
;
2681 else if (lino
== mp
->m_sb
.sb_pquotino
)
2682 type
= XR_INO_PQUOTA
;
2687 type
= XR_INO_SYMLINK
;
2690 type
= XR_INO_CHRDEV
;
2693 type
= XR_INO_BLKDEV
;
2702 do_warn(_("bad inode type %#o inode %" PRIu64
"\n"),
2703 di_mode
& S_IFMT
, lino
);
2708 * type checks for superblock inodes
2710 if (process_check_sb_inodes(mp
, dino
, lino
, &type
, dirty
) != 0)
2714 * only regular files with REALTIME or EXTSIZE flags set can have
2715 * extsize set, or directories with EXTSZINHERIT.
2717 if (libxfs_inode_validate_extsize(mp
,
2718 be32_to_cpu(dino
->di_extsize
),
2719 be16_to_cpu(dino
->di_mode
),
2720 be16_to_cpu(dino
->di_flags
)) != NULL
) {
2722 _("Bad extent size %u on inode %" PRIu64
", "),
2723 be32_to_cpu(dino
->di_extsize
), lino
);
2725 do_warn(_("resetting to zero\n"));
2726 dino
->di_extsize
= 0;
2727 dino
->di_flags
&= ~cpu_to_be16(XFS_DIFLAG_EXTSIZE
|
2728 XFS_DIFLAG_EXTSZINHERIT
);
2731 do_warn(_("would reset to zero\n"));
2735 * Only (regular files and directories) with COWEXTSIZE flags
2736 * set can have extsize set.
2738 if (dino
->di_version
>= 3 &&
2739 libxfs_inode_validate_cowextsize(mp
,
2740 be32_to_cpu(dino
->di_cowextsize
),
2741 be16_to_cpu(dino
->di_mode
),
2742 be16_to_cpu(dino
->di_flags
),
2743 be64_to_cpu(dino
->di_flags2
)) != NULL
) {
2745 _("Bad CoW extent size %u on inode %" PRIu64
", "),
2746 be32_to_cpu(dino
->di_cowextsize
), lino
);
2748 do_warn(_("resetting to zero\n"));
2749 dino
->di_flags2
&= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE
);
2750 dino
->di_cowextsize
= 0;
2753 do_warn(_("would reset to zero\n"));
2756 /* nsec fields cannot be larger than 1 billion */
2757 check_nsec("atime", lino
, &dino
->di_atime
, dirty
);
2758 check_nsec("mtime", lino
, &dino
->di_mtime
, dirty
);
2759 check_nsec("ctime", lino
, &dino
->di_ctime
, dirty
);
2760 if (dino
->di_version
>= 3)
2761 check_nsec("crtime", lino
, &dino
->di_crtime
, dirty
);
2764 * general size/consistency checks:
2766 if (process_check_inode_sizes(mp
, dino
, lino
, type
) != 0)
2770 * check for illegal values of forkoff
2772 if (process_check_inode_forkoff(mp
, dino
, lino
) != 0)
2776 * record the state of the reflink flag
2779 record_inode_reflink_flag(mp
, dino
, agno
, ino
, lino
);
2782 * check data fork -- if it's bad, clear the inode
2784 if (process_inode_data_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2785 &totblocks
, &nextents
, &dblkmap
, check_dups
) != 0)
2789 * check attribute fork if necessary. attributes are
2790 * always stored in the regular filesystem.
2792 if (process_inode_attr_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2793 &atotblocks
, &anextents
, check_dups
, extra_attr_check
,
2798 * enforce totblocks is 0 for misc types
2800 if (process_misc_ino_types_blocks(totblocks
, lino
, type
))
2804 * correct space counters if required
2806 if (process_inode_blocks_and_extents(dino
, totblocks
+ atotblocks
,
2807 nextents
, anextents
, lino
, dirty
) != 0)
2811 * do any semantic type-based checking here
2815 if (process_dir2(mp
, lino
, dino
, ino_discovery
,
2816 dirty
, "", parent
, dblkmap
)) {
2818 _("problem with directory contents in inode %" PRIu64
"\n"),
2823 case XR_INO_SYMLINK
:
2824 if (process_symlink(mp
, lino
, dino
, dblkmap
) != 0) {
2826 _("problem with symbolic link in inode %" PRIu64
"\n"),
2834 if (process_quota_inode(mp
, lino
, dino
, type
, dblkmap
) != 0) {
2836 _("problem with quota inode %" PRIu64
"\n"), lino
);
2844 blkmap_free(dblkmap
);
2847 * check nlinks feature, if it's a version 1 inode,
2848 * just leave nlinks alone. even if it's set wrong,
2849 * it'll be reset when read in.
2851 *dirty
+= process_check_inode_nlink_version(dino
, lino
);
2857 clear_dinode(mp
, dino
, lino
);
2863 blkmap_free(dblkmap
);
2868 * returns 1 if inode is used, 0 if free.
2869 * performs any necessary salvaging actions.
2870 * note that we leave the generation count alone
2871 * because nothing we could set it to would be
2872 * guaranteed to be correct so the best guess for
2873 * the correct value is just to leave it alone.
2875 * The trick is detecting empty files. For those,
2876 * the core and the forks should all be in the "empty"
2877 * or zero-length state -- a zero or possibly minimum length
2878 * (in the case of dirs) extent list -- although inline directories
2879 * and symlinks might be handled differently. So it should be
2880 * possible to sanity check them against each other.
2882 * If the forks are an empty extent list though, then forget it.
2883 * The file is toast anyway since we can't recover its storage.
2887 * mp -- mount structure
2888 * dino -- pointer to on-disk inode structure
2889 * agno/ino -- inode numbers
2890 * free -- whether the map thinks the inode is free (1 == free)
2891 * ino_discovery -- whether we should examine directory
2892 * contents to discover new inodes
2893 * check_dups -- whether we should check to see if the
2894 * inode references duplicate blocks
2895 * if so, we compare the inode's claimed
2896 * blocks against the contents of the
2897 * duplicate extent list but we don't
2898 * set the bitmap. If not, we set the
2899 * bitmap and try and detect multiply
2900 * claimed blocks using the bitmap.
2902 * dirty -- whether we changed the inode (1 == yes)
2903 * used -- 1 if the inode is used, 0 if free. In no modify
2904 * mode, whether the inode should be used or free
2905 * isa_dir -- 1 if the inode is a directory, 0 if not. In
2906 * no modify mode, if the inode would be a dir or not.
2908 * Return value -- 0 if the inode is good, 1 if it is/was corrupt
2915 xfs_agnumber_t agno
,
2922 int extra_attr_check
,
2926 const int verify_mode
= 0;
2927 const int uncertain
= 0;
2929 #ifdef XR_INODE_TRACE
2930 fprintf(stderr
, _("processing inode %d/%d\n"), agno
, ino
);
2932 return process_dinode_int(mp
, dino
, agno
, ino
, was_free
, dirty
, used
,
2933 verify_mode
, uncertain
, ino_discovery
,
2934 check_dups
, extra_attr_check
, isa_dir
, parent
);
2938 * a more cursory check, check inode core, *DON'T* check forks
2939 * this basically just verifies whether the inode is an inode
2940 * and whether or not it has been totally trashed. returns 0
2941 * if the inode passes the cursory sanity check, 1 otherwise.
2947 xfs_agnumber_t agno
,
2954 const int verify_mode
= 1;
2955 const int check_dups
= 0;
2956 const int ino_discovery
= 0;
2957 const int uncertain
= 0;
2959 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
2960 verify_mode
, uncertain
, ino_discovery
,
2961 check_dups
, 0, &isa_dir
, &parent
);
2965 * like above only for inode on the uncertain list. it sets
2966 * the uncertain flag which makes process_dinode_int quieter.
2967 * returns 0 if the inode passes the cursory sanity check, 1 otherwise.
2970 verify_uncertain_dinode(
2973 xfs_agnumber_t agno
,
2980 const int verify_mode
= 1;
2981 const int check_dups
= 0;
2982 const int ino_discovery
= 0;
2983 const int uncertain
= 1;
2985 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
2986 verify_mode
, uncertain
, ino_discovery
,
2987 check_dups
, 0, &isa_dir
, &parent
);