2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it would be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write the Free Software Foundation,
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25 #include "err_protos.h"
30 #include "attr_repair.h"
37 * gettext lookups for translations of strings use mutexes internally to
38 * the library. Hence when we come through here doing parallel scans in
39 * multiple AGs, then all do concurrent text conversions and serialise
40 * on the translation string lookups. Let's avoid doing repeated lookups
41 * by making them static variables and only assigning the translation
44 static char *forkname_data
;
45 static char *forkname_attr
;
46 static char *ftype_real_time
;
47 static char *ftype_regular
;
50 dinode_bmbt_translation_init(void)
52 forkname_data
= _("data");
53 forkname_attr
= _("attr");
54 ftype_real_time
= _("real-time");
55 ftype_regular
= _("regular");
59 get_forkname(int whichfork
)
62 if (whichfork
== XFS_DATA_FORK
)
68 * inode clearing routines
72 clear_dinode_attr(xfs_mount_t
*mp
, xfs_dinode_t
*dino
, xfs_ino_t ino_num
)
74 ASSERT(dino
->di_forkoff
!= 0);
78 _("clearing inode %" PRIu64
" attributes\n"), ino_num
);
81 _("would have cleared inode %" PRIu64
" attributes\n"), ino_num
);
83 if (be16_to_cpu(dino
->di_anextents
) != 0) {
86 dino
->di_anextents
= cpu_to_be16(0);
89 if (dino
->di_aformat
!= XFS_DINODE_FMT_EXTENTS
) {
92 dino
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
95 /* get rid of the fork by clearing forkoff */
97 /* Originally, when the attr repair code was added, the fork was cleared
98 * by turning it into shortform status. This meant clearing the
99 * hdr.totsize/count fields and also changing aformat to LOCAL
100 * (vs EXTENTS). Over various fixes, the aformat and forkoff have
101 * been updated to not show an attribute fork at all, however.
102 * It could be possible that resetting totsize/count are not needed,
103 * but just to be safe, leave it in for now.
107 xfs_attr_shortform_t
*asf
= (xfs_attr_shortform_t
*)
108 XFS_DFORK_APTR(dino
);
109 asf
->hdr
.totsize
= cpu_to_be16(sizeof(xfs_attr_sf_hdr_t
));
111 dino
->di_forkoff
= 0; /* got to do this after asf is set */
115 * always returns 1 since the fork gets zapped
121 clear_dinode_core(struct xfs_mount
*mp
, xfs_dinode_t
*dinoc
, xfs_ino_t ino_num
)
126 #define __dirty_no_modify_ret(dirty) \
127 ({ (dirty) = 1; if (no_modify) return 1; })
129 if (be16_to_cpu(dinoc
->di_magic
) != XFS_DINODE_MAGIC
) {
130 __dirty_no_modify_ret(dirty
);
131 dinoc
->di_magic
= cpu_to_be16(XFS_DINODE_MAGIC
);
134 if (!libxfs_dinode_good_version(mp
, dinoc
->di_version
)) {
135 __dirty_no_modify_ret(dirty
);
136 if (xfs_sb_version_hascrc(&mp
->m_sb
))
137 dinoc
->di_version
= 3;
139 dinoc
->di_version
= 2;
142 if (be16_to_cpu(dinoc
->di_mode
) != 0) {
143 __dirty_no_modify_ret(dirty
);
147 if (be16_to_cpu(dinoc
->di_flags
) != 0) {
148 __dirty_no_modify_ret(dirty
);
152 if (be32_to_cpu(dinoc
->di_dmevmask
) != 0) {
153 __dirty_no_modify_ret(dirty
);
154 dinoc
->di_dmevmask
= 0;
157 if (dinoc
->di_forkoff
!= 0) {
158 __dirty_no_modify_ret(dirty
);
159 dinoc
->di_forkoff
= 0;
162 if (dinoc
->di_format
!= XFS_DINODE_FMT_EXTENTS
) {
163 __dirty_no_modify_ret(dirty
);
164 dinoc
->di_format
= XFS_DINODE_FMT_EXTENTS
;
167 if (dinoc
->di_aformat
!= XFS_DINODE_FMT_EXTENTS
) {
168 __dirty_no_modify_ret(dirty
);
169 dinoc
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
172 if (be64_to_cpu(dinoc
->di_size
) != 0) {
173 __dirty_no_modify_ret(dirty
);
177 if (be64_to_cpu(dinoc
->di_nblocks
) != 0) {
178 __dirty_no_modify_ret(dirty
);
179 dinoc
->di_nblocks
= 0;
182 if (be16_to_cpu(dinoc
->di_onlink
) != 0) {
183 __dirty_no_modify_ret(dirty
);
184 dinoc
->di_onlink
= 0;
187 if (be32_to_cpu(dinoc
->di_nextents
) != 0) {
188 __dirty_no_modify_ret(dirty
);
189 dinoc
->di_nextents
= 0;
192 if (be16_to_cpu(dinoc
->di_anextents
) != 0) {
193 __dirty_no_modify_ret(dirty
);
194 dinoc
->di_anextents
= 0;
197 if (dinoc
->di_version
> 1 &&
198 be32_to_cpu(dinoc
->di_nlink
) != 0) {
199 __dirty_no_modify_ret(dirty
);
203 /* we are done for version 1/2 inodes */
204 if (dinoc
->di_version
< 3)
207 if (be64_to_cpu(dinoc
->di_ino
) != ino_num
) {
208 __dirty_no_modify_ret(dirty
);
209 dinoc
->di_ino
= cpu_to_be64(ino_num
);
212 if (platform_uuid_compare(&dinoc
->di_uuid
, &mp
->m_sb
.sb_meta_uuid
)) {
213 __dirty_no_modify_ret(dirty
);
214 platform_uuid_copy(&dinoc
->di_uuid
, &mp
->m_sb
.sb_meta_uuid
);
217 for (i
= 0; i
< sizeof(dinoc
->di_pad2
)/sizeof(dinoc
->di_pad2
[0]); i
++) {
218 if (dinoc
->di_pad2
[i
] != 0) {
219 __dirty_no_modify_ret(dirty
);
220 memset(dinoc
->di_pad2
, 0, sizeof(dinoc
->di_pad2
));
225 if (be64_to_cpu(dinoc
->di_flags2
) != 0) {
226 __dirty_no_modify_ret(dirty
);
227 dinoc
->di_flags2
= 0;
230 if (be64_to_cpu(dinoc
->di_lsn
) != 0) {
231 __dirty_no_modify_ret(dirty
);
235 if (be64_to_cpu(dinoc
->di_changecount
) != 0) {
236 __dirty_no_modify_ret(dirty
);
237 dinoc
->di_changecount
= 0;
244 clear_dinode_unlinked(xfs_mount_t
*mp
, xfs_dinode_t
*dino
)
247 if (be32_to_cpu(dino
->di_next_unlinked
) != NULLAGINO
) {
249 dino
->di_next_unlinked
= cpu_to_be32(NULLAGINO
);
257 * this clears the unlinked list too so it should not be called
258 * until after the agi unlinked lists are walked in phase 3.
259 * returns > zero if the inode has been altered while being cleared
262 clear_dinode(xfs_mount_t
*mp
, xfs_dinode_t
*dino
, xfs_ino_t ino_num
)
266 dirty
= clear_dinode_core(mp
, dino
, ino_num
);
267 dirty
+= clear_dinode_unlinked(mp
, dino
);
269 /* and clear the forks */
271 if (dirty
&& !no_modify
)
272 memset(XFS_DFORK_DPTR(dino
), 0,
273 XFS_LITINO(mp
, dino
->di_version
));
280 * misc. inode-related utility routines
284 * verify_ag_bno is heavily used. In the common case, it
285 * performs just two number of compares
286 * Returns 1 for bad ag/bno pair or 0 if it's valid.
289 verify_ag_bno(xfs_sb_t
*sbp
,
293 if (agno
< (sbp
->sb_agcount
- 1))
294 return (agbno
>= sbp
->sb_agblocks
);
295 if (agno
== (sbp
->sb_agcount
- 1))
296 return (agbno
>= (sbp
->sb_dblocks
-
297 ((xfs_rfsblock_t
)(sbp
->sb_agcount
- 1) *
303 * returns 0 if inode number is valid, 1 if bogus
306 verify_inum(xfs_mount_t
*mp
,
312 xfs_sb_t
*sbp
= &mp
->m_sb
;;
314 /* range check ag #, ag block. range-checking offset is pointless */
316 agno
= XFS_INO_TO_AGNO(mp
, ino
);
317 agino
= XFS_INO_TO_AGINO(mp
, ino
);
318 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
322 if (ino
== 0 || ino
== NULLFSINO
)
325 if (ino
!= XFS_AGINO_TO_INO(mp
, agno
, agino
))
328 return verify_ag_bno(sbp
, agno
, agbno
);
332 * have a separate routine to ensure that we don't accidentally
333 * lose illegally set bits in the agino by turning it into an FSINO
334 * to feed to the above routine
337 verify_aginum(xfs_mount_t
*mp
,
342 xfs_sb_t
*sbp
= &mp
->m_sb
;;
344 /* range check ag #, ag block. range-checking offset is pointless */
346 if (agino
== 0 || agino
== NULLAGINO
)
350 * agino's can't be too close to NULLAGINO because the min blocksize
351 * is 9 bits and at most 1 bit of that gets used for the inode offset
352 * so if the agino gets shifted by the # of offset bits and compared
353 * to the legal agbno values, a bogus agino will be too large. there
354 * will be extra bits set at the top that shouldn't be set.
356 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
360 return verify_ag_bno(sbp
, agno
, agbno
);
364 * return 1 if block number is good, 0 if out of range
367 verify_dfsbno(xfs_mount_t
*mp
,
372 xfs_sb_t
*sbp
= &mp
->m_sb
;;
374 /* range check ag #, ag block. range-checking offset is pointless */
376 agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
377 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
);
379 return verify_ag_bno(sbp
, agno
, agbno
) == 0;
382 #define XR_DFSBNORANGE_VALID 0
383 #define XR_DFSBNORANGE_BADSTART 1
384 #define XR_DFSBNORANGE_BADEND 2
385 #define XR_DFSBNORANGE_OVERFLOW 3
388 verify_dfsbno_range(xfs_mount_t
*mp
,
394 xfs_sb_t
*sbp
= &mp
->m_sb
;;
396 /* the start and end blocks better be in the same allocation group */
397 agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
398 if (agno
!= XFS_FSB_TO_AGNO(mp
, fsbno
+ count
- 1)) {
399 return XR_DFSBNORANGE_OVERFLOW
;
402 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
);
403 if (verify_ag_bno(sbp
, agno
, agbno
)) {
404 return XR_DFSBNORANGE_BADSTART
;
407 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
+ count
- 1);
408 if (verify_ag_bno(sbp
, agno
, agbno
)) {
409 return XR_DFSBNORANGE_BADEND
;
412 return (XR_DFSBNORANGE_VALID
);
416 verify_agbno(xfs_mount_t
*mp
,
420 xfs_sb_t
*sbp
= &mp
->m_sb
;;
422 /* range check ag #, ag block. range-checking offset is pointless */
423 return verify_ag_bno(sbp
, agno
, agbno
) == 0;
429 xfs_bmbt_irec_t
*irec
,
437 int pwe
; /* partially-written extent */
440 * check numeric validity of the extent
442 if (irec
->br_startblock
>= mp
->m_sb
.sb_rblocks
) {
444 _("inode %" PRIu64
" - bad rt extent start block number %" PRIu64
", offset %" PRIu64
"\n"),
450 if (irec
->br_startblock
+ irec
->br_blockcount
- 1 >= mp
->m_sb
.sb_rblocks
) {
452 _("inode %" PRIu64
" - bad rt extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
454 irec
->br_startblock
+ irec
->br_blockcount
- 1,
458 if (irec
->br_startblock
+ irec
->br_blockcount
- 1 < irec
->br_startblock
) {
460 _("inode %" PRIu64
" - bad rt extent overflows - start %" PRIu64
", "
461 "end %" PRIu64
", offset %" PRIu64
"\n"),
464 irec
->br_startblock
+ irec
->br_blockcount
- 1,
470 * verify that the blocks listed in the record
471 * are multiples of an extent
473 if (xfs_sb_version_hasextflgbit(&mp
->m_sb
) == 0 &&
474 (irec
->br_startblock
% mp
->m_sb
.sb_rextsize
!= 0 ||
475 irec
->br_blockcount
% mp
->m_sb
.sb_rextsize
!= 0)) {
477 _("malformed rt inode extent [%" PRIu64
" %" PRIu64
"] (fs rtext size = %u)\n"),
480 mp
->m_sb
.sb_rextsize
);
485 * set the appropriate number of extents
486 * this iterates block by block, this can be optimised using extents
488 for (b
= irec
->br_startblock
; b
< irec
->br_startblock
+
489 irec
->br_blockcount
; b
+= mp
->m_sb
.sb_rextsize
) {
490 ext
= (xfs_rtblock_t
) b
/ mp
->m_sb
.sb_rextsize
;
491 pwe
= xfs_sb_version_hasextflgbit(&mp
->m_sb
) &&
492 irec
->br_state
== XFS_EXT_UNWRITTEN
&&
493 (b
% mp
->m_sb
.sb_rextsize
!= 0);
495 if (check_dups
== 1) {
496 if (search_rt_dup_extent(mp
, ext
) && !pwe
) {
498 _("data fork in rt ino %" PRIu64
" claims dup rt extent,"
499 "off - %" PRIu64
", start - %" PRIu64
", count %" PRIu64
"\n"),
503 irec
->br_blockcount
);
509 state
= get_rtbmap(ext
);
513 set_rtbmap(ext
, XR_E_INUSE
);
517 _("bad state in rt block map %" PRIu64
"\n"),
523 _("data fork in rt inode %" PRIu64
" found metadata block %" PRIu64
" in rt bmap\n"),
530 set_rtbmap(ext
, XR_E_MULT
);
532 _("data fork in rt inode %" PRIu64
" claims used rt block %" PRIu64
"\n"),
538 _("illegal state %d in rt block map %" PRIu64
"\n"),
544 * bump up the block counter
546 *tot
+= irec
->br_blockcount
;
552 * return 1 if inode should be cleared, 0 otherwise
553 * if check_dups should be set to 1, that implies that
554 * the primary purpose of this call is to see if the
555 * file overlaps with any duplicate extents (in the
556 * duplicate extent list).
559 process_bmbt_reclist_int(
567 xfs_fileoff_t
*first_key
,
568 xfs_fileoff_t
*last_key
,
572 xfs_bmbt_irec_t irec
;
573 xfs_filblks_t cp
= 0; /* prev count */
574 xfs_fsblock_t sp
= 0; /* prev start */
575 xfs_fileoff_t op
= 0; /* prev offset */
578 char *forkname
= get_forkname(whichfork
);
585 xfs_agnumber_t locked_agno
= -1;
588 if (type
== XR_INO_RTDATA
)
589 ftype
= ftype_real_time
;
591 ftype
= ftype_regular
;
593 for (i
= 0; i
< *numrecs
; i
++) {
594 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
596 *last_key
= *first_key
= irec
.br_startoff
;
598 *last_key
= irec
.br_startoff
;
599 if (i
> 0 && op
+ cp
> irec
.br_startoff
) {
601 _("bmap rec out of order, inode %" PRIu64
" entry %d "
602 "[o s c] [%" PRIu64
" %" PRIu64
" %" PRIu64
"], "
603 "%d [%" PRIu64
" %" PRIu64
" %" PRIu64
"]\n"),
604 ino
, i
, irec
.br_startoff
, irec
.br_startblock
,
605 irec
.br_blockcount
, i
- 1, op
, sp
, cp
);
608 op
= irec
.br_startoff
;
609 cp
= irec
.br_blockcount
;
610 sp
= irec
.br_startblock
;
613 * check numeric validity of the extent
615 if (irec
.br_blockcount
== 0) {
617 _("zero length extent (off = %" PRIu64
", fsbno = %" PRIu64
") in ino %" PRIu64
"\n"),
624 if (type
== XR_INO_RTDATA
&& whichfork
== XFS_DATA_FORK
) {
626 * realtime bitmaps don't use AG locks, so returning
627 * immediately is fine for this code path.
629 if (process_rt_rec(mp
, &irec
, ino
, tot
, check_dups
))
632 * skip rest of loop processing since that'irec.br_startblock
633 * all for regular file forks and attr forks
639 * regular file data fork or attribute fork
641 switch (verify_dfsbno_range(mp
, irec
.br_startblock
,
642 irec
.br_blockcount
)) {
643 case XR_DFSBNORANGE_VALID
:
646 case XR_DFSBNORANGE_BADSTART
:
648 _("inode %" PRIu64
" - bad extent starting block number %" PRIu64
", offset %" PRIu64
"\n"),
654 case XR_DFSBNORANGE_BADEND
:
656 _("inode %" PRIu64
" - bad extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
658 irec
.br_startblock
+ irec
.br_blockcount
- 1,
662 case XR_DFSBNORANGE_OVERFLOW
:
664 _("inode %" PRIu64
" - bad extent overflows - start %" PRIu64
", "
665 "end %" PRIu64
", offset %" PRIu64
"\n"),
668 irec
.br_startblock
+ irec
.br_blockcount
- 1,
672 /* Ensure this extent does not extend beyond the max offset */
673 if (irec
.br_startoff
+ irec
.br_blockcount
- 1 >
674 fs_max_file_offset
) {
676 _("inode %" PRIu64
" - extent exceeds max offset - start %" PRIu64
", "
677 "count %" PRIu64
", physical block %" PRIu64
"\n"),
678 ino
, irec
.br_startoff
, irec
.br_blockcount
,
683 if (blkmapp
&& *blkmapp
) {
685 error2
= blkmap_set_ext(blkmapp
, irec
.br_startoff
,
686 irec
.br_startblock
, irec
.br_blockcount
);
689 * we don't want to clear the inode due to an
690 * internal bmap tracking error, but if we've
691 * run out of memory then we simply can't
692 * validate that the filesystem is consistent.
693 * Hence just abort at this point with an ENOMEM
697 _("Fatal error: inode %" PRIu64
" - blkmap_set_ext(): %s\n"
698 "\t%s fork, off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
699 ino
, strerror(error2
), forkname
,
700 irec
.br_startoff
, irec
.br_startblock
,
706 * Profiling shows that the following loop takes the
707 * most time in all of xfs_repair.
709 agno
= XFS_FSB_TO_AGNO(mp
, irec
.br_startblock
);
710 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
711 ebno
= agbno
+ irec
.br_blockcount
;
712 if (agno
!= locked_agno
) {
713 if (locked_agno
!= -1)
714 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
715 pthread_mutex_lock(&ag_locks
[agno
].lock
);
721 * if we're just checking the bmap for dups,
722 * return if we find one, otherwise, continue
723 * checking each entry without setting the
726 if (!(type
== XR_INO_DATA
&&
727 xfs_sb_version_hasreflink(&mp
->m_sb
)) &&
728 search_dup_extent(agno
, agbno
, ebno
)) {
730 _("%s fork in ino %" PRIu64
" claims dup extent, "
731 "off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
732 forkname
, ino
, irec
.br_startoff
,
737 *tot
+= irec
.br_blockcount
;
741 for (b
= irec
.br_startblock
;
743 b
+= blen
, agbno
+= blen
) {
744 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
749 _("%s fork in ino %" PRIu64
" claims free block %" PRIu64
"\n"),
750 forkname
, ino
, (uint64_t) b
);
751 /* fall through ... */
752 case XR_E_INUSE1
: /* seen by rmap */
757 do_error(_("bad state in block map %" PRIu64
"\n"), b
);
762 do_warn(_("rmap claims metadata use!\n"));
769 _("%s fork in inode %" PRIu64
" claims metadata block %" PRIu64
"\n"),
775 if (type
== XR_INO_DATA
&&
776 xfs_sb_version_hasreflink(&mp
->m_sb
))
779 _("%s fork in %s inode %" PRIu64
" claims used block %" PRIu64
"\n"),
780 forkname
, ftype
, ino
, b
);
785 _("%s fork in %s inode %" PRIu64
" claims CoW block %" PRIu64
"\n"),
786 forkname
, ftype
, ino
, b
);
791 _("illegal state %d in block map %" PRIu64
"\n"),
798 * Update the internal extent map only after we've checked
799 * every block in this extent. The first time we reject this
800 * data fork we'll try to rebuild the bmbt from rmap data.
801 * After a successful rebuild we'll try this scan again.
802 * (If the rebuild fails we won't come back here.)
804 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
805 ebno
= agbno
+ irec
.br_blockcount
;
806 for (; agbno
< ebno
; agbno
+= blen
) {
807 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
813 set_bmap_ext(agno
, agbno
, blen
, XR_E_INUSE
);
817 set_bmap_ext(agno
, agbno
, blen
, XR_E_MULT
);
823 if (collect_rmaps
) { /* && !check_dups */
824 error
= rmap_add_rec(mp
, ino
, whichfork
, &irec
);
827 _("couldn't add reverse mapping\n")
830 *tot
+= irec
.br_blockcount
;
834 if (locked_agno
!= -1)
835 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
838 ASSERT(i
< *numrecs
);
839 do_warn(_("correcting nextents for inode %" PRIu64
"\n"), ino
);
847 * return 1 if inode should be cleared, 0 otherwise, sets block bitmap
851 process_bmbt_reclist(
859 xfs_fileoff_t
*first_key
,
860 xfs_fileoff_t
*last_key
,
863 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
864 blkmapp
, first_key
, last_key
, 0, whichfork
);
868 * return 1 if inode should be cleared, 0 otherwise, does not set
881 xfs_fileoff_t first_key
= 0;
882 xfs_fileoff_t last_key
= 0;
884 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
885 NULL
, &first_key
, &last_key
, 1, whichfork
);
889 * Grab the buffer backing an inode. This is meant for routines that
890 * work with inodes one at a time in any order (like walking the
891 * unlinked lists to look for inodes). The caller is responsible for
892 * writing/releasing the buffer.
896 struct xfs_mount
*mp
,
899 struct xfs_dinode
**dipp
)
904 xfs_agino_t cluster_agino
;
905 xfs_daddr_t cluster_daddr
;
906 xfs_daddr_t cluster_blks
;
909 * Inode buffers have been read into memory in inode_cluster_size
910 * chunks (or one FSB). To find the correct buffer for an inode,
911 * we must find the buffer for its cluster, add the appropriate
912 * offset, and return that.
914 cluster_size
= MAX(mp
->m_inode_cluster_size
, mp
->m_sb
.sb_blocksize
);
915 ino_per_cluster
= cluster_size
/ mp
->m_sb
.sb_inodesize
;
916 cluster_agino
= agino
& ~(ino_per_cluster
- 1);
917 cluster_blks
= XFS_FSB_TO_DADDR(mp
, MAX(1,
918 mp
->m_inode_cluster_size
>> mp
->m_sb
.sb_blocklog
));
919 cluster_daddr
= XFS_AGB_TO_DADDR(mp
, agno
,
920 XFS_AGINO_TO_AGBNO(mp
, cluster_agino
));
922 #ifdef XR_INODE_TRACE
923 printf("cluster_size %d ipc %d clusagino %d daddr %lld sectors %lld\n",
924 cluster_size
, ino_per_cluster
, cluster_agino
, cluster_daddr
,
928 bp
= libxfs_readbuf(mp
->m_dev
, cluster_daddr
, cluster_blks
,
929 0, &xfs_inode_buf_ops
);
931 do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64
"\n"),
932 agno
, cluster_agino
, cluster_daddr
);
936 *dipp
= xfs_make_iptr(mp
, bp
, agino
- cluster_agino
);
937 ASSERT(!xfs_sb_version_hascrc(&mp
->m_sb
) ||
938 XFS_AGINO_TO_INO(mp
, agno
, agino
) ==
939 be64_to_cpu((*dipp
)->di_ino
));
944 * higher level inode processing stuff starts here:
945 * first, one utility routine for each type of inode
949 * return 1 if inode should be cleared, 0 otherwise
965 xfs_bmdr_block_t
*dib
;
966 xfs_fileoff_t last_key
;
967 xfs_fileoff_t first_key
= 0;
970 xfs_bmbt_key_t
*pkey
;
971 char *forkname
= get_forkname(whichfork
);
975 bmap_cursor_t cursor
;
978 dib
= (xfs_bmdr_block_t
*)XFS_DFORK_PTR(dip
, whichfork
);
979 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
983 magic
= xfs_sb_version_hascrc(&mp
->m_sb
) ? XFS_BMAP_CRC_MAGIC
986 level
= be16_to_cpu(dib
->bb_level
);
987 numrecs
= be16_to_cpu(dib
->bb_numrecs
);
989 if ((level
== 0) || (level
> XFS_BM_MAXLEVELS(mp
, whichfork
))) {
991 * XXX - if we were going to fix up the inode,
992 * we'd try to treat the fork as an interior
993 * node and see if we could get an accurate
994 * level value from one of the blocks pointed
995 * to by the pointers in the fork. For now
996 * though, we just bail (and blow out the inode).
999 _("bad level %d in inode %" PRIu64
" bmap btree root block\n"),
1000 level
, XFS_AGINO_TO_INO(mp
, agno
, ino
));
1005 _("bad numrecs 0 in inode %" PRIu64
" bmap btree root block\n"),
1006 XFS_AGINO_TO_INO(mp
, agno
, ino
));
1010 * use bmdr/dfork_dsize since the root block is in the data fork
1012 if (XFS_BMDR_SPACE_CALC(numrecs
) > XFS_DFORK_SIZE(dip
, mp
, whichfork
)) {
1014 _("indicated size of %s btree root (%d bytes) greater than space in "
1015 "inode %" PRIu64
" %s fork\n"),
1016 forkname
, XFS_BMDR_SPACE_CALC(numrecs
), lino
, forkname
);
1020 init_bm_cursor(&cursor
, level
+ 1);
1022 pp
= XFS_BMDR_PTR_ADDR(dib
, 1,
1023 libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip
, mp
, whichfork
), 0));
1024 pkey
= XFS_BMDR_KEY_ADDR(dib
, 1);
1025 last_key
= NULLFILEOFF
;
1027 for (i
= 0; i
< numrecs
; i
++) {
1029 * XXX - if we were going to do more to fix up the inode
1030 * btree, we'd do it right here. For now, if there's a
1031 * problem, we'll bail out and presumably clear the inode.
1033 if (!verify_dfsbno(mp
, get_unaligned_be64(&pp
[i
]))) {
1035 _("bad bmap btree ptr 0x%" PRIx64
" in ino %" PRIu64
"\n"),
1036 get_unaligned_be64(&pp
[i
]), lino
);
1040 if (scan_lbtree(get_unaligned_be64(&pp
[i
]), level
, scan_bmapbt
,
1041 type
, whichfork
, lino
, tot
, nex
, blkmapp
,
1042 &cursor
, 1, check_dups
, magic
,
1046 * fix key (offset) mismatches between the keys in root
1047 * block records and the first key of each child block.
1048 * fixes cases where entries have been shifted between
1049 * blocks but the parent hasn't been updated
1051 if (!check_dups
&& cursor
.level
[level
-1].first_key
!=
1052 get_unaligned_be64(&pkey
[i
].br_startoff
)) {
1055 _("correcting key in bmbt root (was %" PRIu64
", now %" PRIu64
") in inode "
1056 "%" PRIu64
" %s fork\n"),
1057 get_unaligned_be64(&pkey
[i
].br_startoff
),
1058 cursor
.level
[level
-1].first_key
,
1059 XFS_AGINO_TO_INO(mp
, agno
, ino
),
1063 cursor
.level
[level
-1].first_key
,
1064 &pkey
[i
].br_startoff
);
1067 _("bad key in bmbt root (is %" PRIu64
", would reset to %" PRIu64
") in inode "
1068 "%" PRIu64
" %s fork\n"),
1069 get_unaligned_be64(&pkey
[i
].br_startoff
),
1070 cursor
.level
[level
-1].first_key
,
1071 XFS_AGINO_TO_INO(mp
, agno
, ino
),
1076 * make sure that keys are in ascending order. blow out
1077 * inode if the ordering doesn't hold
1079 if (check_dups
== 0) {
1080 if (last_key
!= NULLFILEOFF
&& last_key
>=
1081 cursor
.level
[level
-1].first_key
) {
1083 _("out of order bmbt root key %" PRIu64
" in inode %" PRIu64
" %s fork\n"),
1085 XFS_AGINO_TO_INO(mp
, agno
, ino
),
1089 last_key
= cursor
.level
[level
-1].first_key
;
1093 * Ideally if all the extents are ok (perhaps after further
1094 * checks below?) we'd just move this back into extents format.
1095 * But for now clear it, as the kernel will choke on this
1097 if (*nex
<= XFS_DFORK_SIZE(dip
, mp
, whichfork
) /
1098 sizeof(xfs_bmbt_rec_t
)) {
1100 _("extent count for ino %" PRIu64
" %s fork too low (%" PRIu64
") for file format\n"),
1101 lino
, forkname
, *nex
);
1105 * Check that the last child block's forward sibling pointer
1108 if (check_dups
== 0 &&
1109 cursor
.level
[0].right_fsbno
!= NULLFSBLOCK
) {
1111 _("bad fwd (right) sibling pointer (saw %" PRIu64
" should be NULLFSBLOCK)\n"),
1112 cursor
.level
[0].right_fsbno
);
1114 _("\tin inode %" PRIu64
" (%s fork) bmap btree block %" PRIu64
"\n"),
1115 XFS_AGINO_TO_INO(mp
, agno
, ino
), forkname
,
1116 cursor
.level
[0].fsbno
);
1124 * return 1 if inode should be cleared, 0 otherwise
1129 xfs_agnumber_t agno
,
1134 xfs_rfsblock_t
*tot
,
1142 xfs_fileoff_t first_key
;
1143 xfs_fileoff_t last_key
;
1147 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1148 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_PTR(dip
, whichfork
);
1150 numrecs
= XFS_DFORK_NEXTENTS(dip
, whichfork
);
1153 * We've already decided on the maximum number of extents on the inode,
1154 * and numrecs may be corrupt. Hence make sure we only allow numrecs to
1155 * be in the range of valid on-disk numbers, which is:
1156 * 0 < numrecs < 2^31 - 1
1162 * XXX - if we were going to fix up the btree record,
1163 * we'd do it right here. For now, if there's a problem,
1164 * we'll bail out and presumably clear the inode.
1166 if (check_dups
== 0)
1167 ret
= process_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
,
1168 tot
, blkmapp
, &first_key
, &last_key
,
1171 ret
= scan_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
, tot
,
1179 * return 1 if inode should be cleared, 0 otherwise
1184 xfs_agnumber_t agno
,
1189 xfs_attr_shortform_t
*asf
;
1192 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1193 if (whichfork
== XFS_DATA_FORK
&& be64_to_cpu(dip
->di_size
) >
1194 XFS_DFORK_DSIZE(dip
, mp
)) {
1196 _("local inode %" PRIu64
" data fork is too large (size = %lld, max = %d)\n"),
1197 lino
, (unsigned long long) be64_to_cpu(dip
->di_size
),
1198 XFS_DFORK_DSIZE(dip
, mp
));
1200 } else if (whichfork
== XFS_ATTR_FORK
) {
1201 asf
= (xfs_attr_shortform_t
*)XFS_DFORK_APTR(dip
);
1202 if (be16_to_cpu(asf
->hdr
.totsize
) > XFS_DFORK_ASIZE(dip
, mp
)) {
1204 _("local inode %" PRIu64
" attr fork too large (size %d, max = %d)\n"),
1205 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1206 XFS_DFORK_ASIZE(dip
, mp
));
1209 if (be16_to_cpu(asf
->hdr
.totsize
) < sizeof(xfs_attr_sf_hdr_t
)) {
1211 _("local inode %" PRIu64
" attr too small (size = %d, min size = %zd)\n"),
1212 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1213 sizeof(xfs_attr_sf_hdr_t
));
1222 process_symlink_extlist(xfs_mount_t
*mp
, xfs_ino_t lino
, xfs_dinode_t
*dino
)
1224 xfs_fileoff_t expected_offset
;
1226 xfs_bmbt_irec_t irec
;
1231 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1232 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
)
1235 _("mismatch between format (%d) and size (%" PRId64
") in symlink ino %" PRIu64
"\n"),
1237 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1240 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
) {
1242 _("mismatch between format (%d) and size (%" PRId64
") in symlink inode %" PRIu64
"\n"),
1244 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1248 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_DPTR(dino
);
1249 numrecs
= be32_to_cpu(dino
->di_nextents
);
1252 * the max # of extents in a symlink inode is equal to the
1253 * number of max # of blocks required to store the symlink
1255 if (numrecs
> max_symlink_blocks
) {
1257 _("bad number of extents (%d) in symlink %" PRIu64
" data fork\n"),
1262 max_blocks
= max_symlink_blocks
;
1263 expected_offset
= 0;
1265 for (i
= 0; i
< numrecs
; i
++) {
1266 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
1267 if (irec
.br_startoff
!= expected_offset
) {
1269 _("bad extent #%d offset (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1270 i
, irec
.br_startoff
, lino
);
1273 if (irec
.br_blockcount
== 0 || irec
.br_blockcount
> max_blocks
) {
1275 _("bad extent #%d count (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1276 i
, irec
.br_blockcount
, lino
);
1280 max_blocks
-= irec
.br_blockcount
;
1281 expected_offset
+= irec
.br_blockcount
;
1288 * takes a name and length and returns 1 if the name contains
1289 * a \0, returns 0 otherwise
1292 null_check(char *name
, int length
)
1296 ASSERT(length
< XFS_SYMLINK_MAXLEN
);
1298 for (i
= 0; i
< length
; i
++, name
++) {
1307 process_symlink_remote(
1308 struct xfs_mount
*mp
,
1310 struct xfs_dinode
*dino
,
1311 struct blkmap
*blkmap
,
1314 xfs_fsblock_t fsbno
;
1322 pathlen
= be64_to_cpu(dino
->di_size
);
1325 while (pathlen
> 0) {
1330 fsbno
= blkmap_get(blkmap
, i
);
1331 if (fsbno
== NULLFSBLOCK
) {
1333 _("cannot read inode %" PRIu64
", file block %d, NULL disk block\n"),
1339 * There's a symlink header for each contiguous extent. If
1340 * there are contiguous blocks, read them in one go.
1342 while (blk_cnt
<= max_symlink_blocks
) {
1343 if (blkmap_get(blkmap
, i
+ 1) != fsbno
+ 1)
1349 byte_cnt
= XFS_FSB_TO_B(mp
, blk_cnt
);
1351 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1352 BTOBB(byte_cnt
), 0, &xfs_symlink_buf_ops
);
1355 _("cannot read inode %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1359 if (bp
->b_error
== -EFSCORRUPTED
) {
1361 _("Corrupt symlink remote block %" PRIu64
", inode %" PRIu64
".\n"),
1366 if (bp
->b_error
== -EFSBADCRC
) {
1368 _("Bad symlink buffer CRC, block %" PRIu64
", inode %" PRIu64
".\n"
1369 "Correcting CRC, but symlink may be bad.\n"), fsbno
, lino
);
1373 byte_cnt
= XFS_SYMLINK_BUF_SPACE(mp
, byte_cnt
);
1374 byte_cnt
= MIN(pathlen
, byte_cnt
);
1377 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1378 if (!libxfs_symlink_hdr_ok(lino
, offset
,
1381 _("bad symlink header ino %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1386 src
+= sizeof(struct xfs_dsymlink_hdr
);
1389 memmove(dst
+ offset
, src
, byte_cnt
);
1391 pathlen
-= byte_cnt
;
1395 if (badcrc
&& !no_modify
)
1396 libxfs_writebuf(bp
, 0);
1404 * like usual, returns 0 if everything's ok and 1 if something's
1415 char data
[XFS_SYMLINK_MAXLEN
];
1418 * check size against kernel symlink limits. we know
1419 * size is consistent with inode storage format -- e.g.
1420 * the inode is structurally ok so we don't have to check
1423 if (be64_to_cpu(dino
->di_size
) >= XFS_SYMLINK_MAXLEN
) {
1424 do_warn(_("symlink in inode %" PRIu64
" too long (%llu chars)\n"),
1425 lino
, (unsigned long long) be64_to_cpu(dino
->di_size
));
1429 if (be64_to_cpu(dino
->di_size
) == 0) {
1430 do_warn(_("zero size symlink in inode %" PRIu64
"\n"), lino
);
1435 * have to check symlink component by component.
1436 * get symlink contents into data area
1439 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1441 * local symlink, just copy the symlink out of the
1442 * inode into the data area
1444 memmove(symlink
, XFS_DFORK_DPTR(dino
),
1445 be64_to_cpu(dino
->di_size
));
1449 error
= process_symlink_remote(mp
, lino
, dino
, blkmap
, symlink
);
1454 data
[be64_to_cpu(dino
->di_size
)] = '\0';
1459 if (null_check(symlink
, be64_to_cpu(dino
->di_size
))) {
1461 _("found illegal null character in symlink inode %" PRIu64
"\n"),
1470 * called to process the set of misc inode special inode types
1471 * that have no associated data storage (fifos, pipes, devices, etc.).
1474 process_misc_ino_types(xfs_mount_t
*mp
,
1480 * disallow mountpoint inodes until such time as the
1481 * kernel actually allows them to be created (will
1482 * probably require a superblock version rev, sigh).
1484 if (type
== XR_INO_MOUNTPOINT
) {
1486 _("inode %" PRIu64
" has bad inode type (IFMNT)\n"), lino
);
1491 * must also have a zero size
1493 if (be64_to_cpu(dino
->di_size
) != 0) {
1497 _("size of character device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1498 (int64_t)be64_to_cpu(dino
->di_size
));
1502 _("size of block device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1503 (int64_t)be64_to_cpu(dino
->di_size
));
1507 _("size of socket inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1508 (int64_t)be64_to_cpu(dino
->di_size
));
1512 _("size of fifo inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1513 (int64_t)be64_to_cpu(dino
->di_size
));
1516 do_warn(_("Internal error - process_misc_ino_types, "
1517 "illegal type %d\n"), type
);
1528 process_misc_ino_types_blocks(xfs_rfsblock_t totblocks
, xfs_ino_t lino
, int type
)
1531 * you can not enforce all misc types have zero data fork blocks
1532 * by checking dino->di_nblocks because atotblocks (attribute
1533 * blocks) are part of nblocks. We must check this later when atotblocks
1534 * has been calculated or by doing a simple check that anExtents == 0.
1535 * We must also guarantee that totblocks is 0. Thus nblocks checking
1536 * will be done later in process_dinode_int for misc types.
1539 if (totblocks
!= 0) {
1543 _("size of character device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1548 _("size of block device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1553 _("size of socket inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1558 _("size of fifo inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1573 return be16_to_cpu(dino
->di_mode
) & S_IFMT
;
1581 int mode
= be16_to_cpu(dino
->di_mode
);
1583 ASSERT((new_fmt
& ~S_IFMT
) == 0);
1587 dino
->di_mode
= cpu_to_be16(mode
);
1591 check_dinode_mode_format(
1592 xfs_dinode_t
*dinoc
)
1594 if (dinoc
->di_format
>= XFS_DINODE_FMT_UUID
)
1595 return -1; /* FMT_UUID is not used */
1597 switch (dinode_fmt(dinoc
)) {
1602 return (dinoc
->di_format
!= XFS_DINODE_FMT_DEV
) ? -1 : 0;
1605 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1606 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1609 return (dinoc
->di_format
< XFS_DINODE_FMT_EXTENTS
||
1610 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1613 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1614 dinoc
->di_format
> XFS_DINODE_FMT_EXTENTS
) ? -1 : 0;
1618 return 0; /* invalid modes are checked elsewhere */
1622 * If inode is a superblock inode, does type check to make sure is it valid.
1623 * Returns 0 if it's valid, non-zero if it needs to be cleared.
1627 process_check_sb_inodes(
1629 xfs_dinode_t
*dinoc
,
1634 if (lino
== mp
->m_sb
.sb_rootino
) {
1635 if (*type
!= XR_INO_DIR
) {
1636 do_warn(_("root inode %" PRIu64
" has bad type 0x%x\n"),
1637 lino
, dinode_fmt(dinoc
));
1640 do_warn(_("resetting to directory\n"));
1641 change_dinode_fmt(dinoc
, S_IFDIR
);
1644 do_warn(_("would reset to directory\n"));
1648 if (lino
== mp
->m_sb
.sb_uquotino
) {
1649 if (*type
!= XR_INO_DATA
) {
1650 do_warn(_("user quota inode %" PRIu64
" has bad type 0x%x\n"),
1651 lino
, dinode_fmt(dinoc
));
1652 mp
->m_sb
.sb_uquotino
= NULLFSINO
;
1657 if (lino
== mp
->m_sb
.sb_gquotino
) {
1658 if (*type
!= XR_INO_DATA
) {
1659 do_warn(_("group quota inode %" PRIu64
" has bad type 0x%x\n"),
1660 lino
, dinode_fmt(dinoc
));
1661 mp
->m_sb
.sb_gquotino
= NULLFSINO
;
1666 if (lino
== mp
->m_sb
.sb_pquotino
) {
1667 if (*type
!= XR_INO_DATA
) {
1668 do_warn(_("project quota inode %" PRIu64
" has bad type 0x%x\n"),
1669 lino
, dinode_fmt(dinoc
));
1670 mp
->m_sb
.sb_pquotino
= NULLFSINO
;
1675 if (lino
== mp
->m_sb
.sb_rsumino
) {
1676 if (*type
!= XR_INO_RTSUM
) {
1678 _("realtime summary inode %" PRIu64
" has bad type 0x%x, "),
1679 lino
, dinode_fmt(dinoc
));
1681 do_warn(_("resetting to regular file\n"));
1682 change_dinode_fmt(dinoc
, S_IFREG
);
1685 do_warn(_("would reset to regular file\n"));
1688 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1690 _("bad # of extents (%u) for realtime summary inode %" PRIu64
"\n"),
1691 be32_to_cpu(dinoc
->di_nextents
), lino
);
1696 if (lino
== mp
->m_sb
.sb_rbmino
) {
1697 if (*type
!= XR_INO_RTBITMAP
) {
1699 _("realtime bitmap inode %" PRIu64
" has bad type 0x%x, "),
1700 lino
, dinode_fmt(dinoc
));
1702 do_warn(_("resetting to regular file\n"));
1703 change_dinode_fmt(dinoc
, S_IFREG
);
1706 do_warn(_("would reset to regular file\n"));
1709 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1711 _("bad # of extents (%u) for realtime bitmap inode %" PRIu64
"\n"),
1712 be32_to_cpu(dinoc
->di_nextents
), lino
);
1721 * general size/consistency checks:
1723 * if the size <= size of the data fork, directories must be
1724 * local inodes unlike regular files which would be extent inodes.
1725 * all the other mentioned types have to have a zero size value.
1727 * if the size and format don't match, get out now rather than
1728 * risk trying to process a non-existent extents or btree
1732 process_check_inode_sizes(
1738 xfs_fsize_t size
= be64_to_cpu(dino
->di_size
);
1743 if (size
<= XFS_DFORK_DSIZE(dino
, mp
) &&
1744 dino
->di_format
!= XFS_DINODE_FMT_LOCAL
) {
1746 _("mismatch between format (%d) and size (%" PRId64
") in directory ino %" PRIu64
"\n"),
1747 dino
->di_format
, size
, lino
);
1750 if (size
> XFS_DIR2_LEAF_OFFSET
) {
1752 _("directory inode %" PRIu64
" has bad size %" PRId64
"\n"),
1758 case XR_INO_SYMLINK
:
1759 if (process_symlink_extlist(mp
, lino
, dino
)) {
1760 do_warn(_("bad data fork in symlink %" PRIu64
"\n"), lino
);
1765 case XR_INO_CHRDEV
: /* fall through to FIFO case ... */
1766 case XR_INO_BLKDEV
: /* fall through to FIFO case ... */
1767 case XR_INO_SOCK
: /* fall through to FIFO case ... */
1768 case XR_INO_MOUNTPOINT
: /* fall through to FIFO case ... */
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 *dirty
+= 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 sii 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, clear
2426 * it just in case to ensure that format, etc. are
2430 *dirty
+= clear_dinode(mp
, dino
, lino
);
2435 * the inode looks free but the map says it's in use.
2436 * clear the inode just to be safe and mark the inode
2440 _("imap claims a free inode %" PRIu64
" is in use, "), lino
);
2442 do_warn(_("correcting imap and clearing inode\n"));
2443 *dirty
+= clear_dinode(mp
, dino
, lino
);
2446 do_warn(_("would correct imap and clear inode\n"));
2452 * because of the lack of any write ordering guarantee, it's
2453 * possible that the core got updated but the forks didn't.
2454 * so rather than be ambitious (and probably incorrect),
2455 * if there's an inconsistency, we get conservative and
2456 * just pitch the file. blow off checking formats of
2457 * free inodes since technically any format is legal
2458 * as we reset the inode when we re-use it.
2460 if (di_mode
!= 0 && check_dinode_mode_format(dino
) != 0) {
2463 _("bad inode format in inode %" PRIu64
"\n"), lino
);
2470 * check that we only have valid flags set, and those that are set make
2473 if (dino
->di_flags
) {
2474 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2476 if (flags
& ~XFS_DIFLAG_ANY
) {
2479 _("Bad flags set in inode %" PRIu64
"\n"),
2482 flags
&= XFS_DIFLAG_ANY
;
2485 if (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
)) {
2486 /* need an rt-dev! */
2490 _("inode %" PRIu64
" has RT flag set but there is no RT device\n"),
2493 flags
&= ~(XFS_DIFLAG_REALTIME
|
2494 XFS_DIFLAG_RTINHERIT
);
2497 if (flags
& XFS_DIFLAG_NEWRTBM
) {
2498 /* must be a rt bitmap inode */
2499 if (lino
!= mp
->m_sb
.sb_rbmino
) {
2502 _("inode %" PRIu64
" not rt bitmap\n"),
2505 flags
&= ~XFS_DIFLAG_NEWRTBM
;
2508 if (flags
& (XFS_DIFLAG_RTINHERIT
|
2509 XFS_DIFLAG_EXTSZINHERIT
|
2510 XFS_DIFLAG_PROJINHERIT
|
2511 XFS_DIFLAG_NOSYMLINKS
)) {
2512 /* must be a directory */
2513 if (di_mode
&& !S_ISDIR(di_mode
)) {
2516 _("directory flags set on non-directory inode %" PRIu64
"\n" ),
2519 flags
&= ~(XFS_DIFLAG_RTINHERIT
|
2520 XFS_DIFLAG_EXTSZINHERIT
|
2521 XFS_DIFLAG_PROJINHERIT
|
2522 XFS_DIFLAG_NOSYMLINKS
);
2525 if (flags
& (XFS_DIFLAG_REALTIME
| FS_XFLAG_EXTSIZE
)) {
2526 /* must be a file */
2527 if (di_mode
&& !S_ISREG(di_mode
)) {
2530 _("file flags set on non-file inode %" PRIu64
"\n"),
2533 flags
&= ~(XFS_DIFLAG_REALTIME
|
2537 if (!verify_mode
&& flags
!= be16_to_cpu(dino
->di_flags
)) {
2539 do_warn(_("fixing bad flags.\n"));
2540 dino
->di_flags
= cpu_to_be16(flags
);
2543 do_warn(_("would fix bad flags.\n"));
2548 * check that we only have valid flags2 set, and those that are set make
2551 if (dino
->di_version
>= 3) {
2552 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2553 uint64_t flags2
= be64_to_cpu(dino
->di_flags2
);
2555 if (flags2
& ~XFS_DIFLAG2_ANY
) {
2558 _("Bad flags2 set in inode %" PRIu64
"\n"),
2561 flags2
&= XFS_DIFLAG2_ANY
;
2564 if (flags2
& XFS_DIFLAG2_DAX
) {
2565 /* must be a file or dir */
2566 if (di_mode
&& !(S_ISREG(di_mode
) || S_ISDIR(di_mode
))) {
2569 _("DAX flag set on special inode %" PRIu64
"\n"),
2572 flags2
&= ~XFS_DIFLAG2_DAX
;
2576 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2577 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2580 _("inode %" PRIu64
" is marked reflinked but file system does not support reflink\n"),
2586 if (flags2
& XFS_DIFLAG2_REFLINK
) {
2587 /* must be a file */
2588 if (di_mode
&& !S_ISREG(di_mode
)) {
2591 _("reflink flag set on non-file inode %" PRIu64
"\n"),
2598 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2599 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2602 _("Cannot have a reflinked realtime inode %" PRIu64
"\n"),
2608 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2609 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2612 _("inode %" PRIu64
" has CoW extent size hint but file system does not support reflink\n"),
2615 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2618 if (flags2
& XFS_DIFLAG2_COWEXTSIZE
) {
2619 /* must be a directory or file */
2620 if (di_mode
&& !S_ISDIR(di_mode
) && !S_ISREG(di_mode
)) {
2623 _("CoW extent size flag set on non-file, non-directory inode %" PRIu64
"\n" ),
2626 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2630 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2631 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2634 _("Cannot have CoW extent size hint on a realtime inode %" PRIu64
"\n"),
2637 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2640 if (!verify_mode
&& flags2
!= be64_to_cpu(dino
->di_flags2
)) {
2642 do_warn(_("fixing bad flags2.\n"));
2643 dino
->di_flags2
= cpu_to_be64(flags2
);
2646 do_warn(_("would fix bad flags2.\n"));
2654 * clear the next unlinked field if necessary on a good
2655 * inode only during phase 4 -- when checking for inodes
2656 * referencing duplicate blocks. then it's safe because
2657 * we've done the inode discovery and have found all the inodes
2658 * we're going to find. check_dups is set to 1 only during
2661 if (check_dups
&& !no_modify
)
2662 *dirty
+= clear_dinode_unlinked(mp
, dino
);
2664 /* set type and map type info */
2666 switch (di_mode
& S_IFMT
) {
2672 if (be16_to_cpu(dino
->di_flags
) & XFS_DIFLAG_REALTIME
)
2673 type
= XR_INO_RTDATA
;
2674 else if (lino
== mp
->m_sb
.sb_rbmino
)
2675 type
= XR_INO_RTBITMAP
;
2676 else if (lino
== mp
->m_sb
.sb_rsumino
)
2677 type
= XR_INO_RTSUM
;
2682 type
= XR_INO_SYMLINK
;
2685 type
= XR_INO_CHRDEV
;
2688 type
= XR_INO_BLKDEV
;
2697 do_warn(_("bad inode type %#o inode %" PRIu64
"\n"),
2698 di_mode
& S_IFMT
, lino
);
2703 * type checks for superblock inodes
2705 if (process_check_sb_inodes(mp
, dino
, lino
, &type
, dirty
) != 0)
2709 * only regular files with REALTIME or EXTSIZE flags set can have
2710 * extsize set, or directories with EXTSZINHERIT.
2712 if (be32_to_cpu(dino
->di_extsize
) != 0) {
2713 if ((type
== XR_INO_RTDATA
) ||
2714 (type
== XR_INO_DIR
&& (be16_to_cpu(dino
->di_flags
) &
2715 XFS_DIFLAG_EXTSZINHERIT
)) ||
2716 (type
== XR_INO_DATA
&& (be16_to_cpu(dino
->di_flags
) &
2717 XFS_DIFLAG_EXTSIZE
))) {
2721 _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64
", "),
2722 be32_to_cpu(dino
->di_extsize
), lino
);
2724 do_warn(_("resetting to zero\n"));
2725 dino
->di_extsize
= 0;
2728 do_warn(_("would reset to zero\n"));
2733 * Only (regular files and directories) with COWEXTSIZE flags
2734 * set can have extsize set.
2736 if (dino
->di_version
>= 3 &&
2737 be32_to_cpu(dino
->di_cowextsize
) != 0) {
2738 if ((type
== XR_INO_DIR
|| type
== XR_INO_DATA
) &&
2739 (be64_to_cpu(dino
->di_flags2
) &
2740 XFS_DIFLAG2_COWEXTSIZE
)) {
2744 _("Cannot have non-zero CoW extent size %u on non-cowextsize inode %" PRIu64
", "),
2745 be32_to_cpu(dino
->di_cowextsize
), lino
);
2747 do_warn(_("resetting to zero\n"));
2748 dino
->di_flags2
&= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE
);
2749 dino
->di_cowextsize
= 0;
2752 do_warn(_("would reset to zero\n"));
2757 * Can't have the COWEXTSIZE flag set with no hint.
2759 if (dino
->di_version
>= 3 &&
2760 be32_to_cpu(dino
->di_cowextsize
) == 0 &&
2761 (be64_to_cpu(dino
->di_flags2
) & XFS_DIFLAG2_COWEXTSIZE
)) {
2763 _("Cannot have CoW extent size of zero on cowextsize inode %" PRIu64
", "),
2766 do_warn(_("clearing cowextsize flag\n"));
2767 dino
->di_flags2
&= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE
);
2770 do_warn(_("would clear cowextsize flag\n"));
2774 /* nsec fields cannot be larger than 1 billion */
2775 check_nsec("atime", lino
, &dino
->di_atime
, dirty
);
2776 check_nsec("mtime", lino
, &dino
->di_mtime
, dirty
);
2777 check_nsec("ctime", lino
, &dino
->di_ctime
, dirty
);
2778 if (dino
->di_version
>= 3)
2779 check_nsec("crtime", lino
, &dino
->di_crtime
, dirty
);
2782 * general size/consistency checks:
2784 if (process_check_inode_sizes(mp
, dino
, lino
, type
) != 0)
2788 * check for illegal values of forkoff
2790 if (process_check_inode_forkoff(mp
, dino
, lino
) != 0)
2794 * record the state of the reflink flag
2797 record_inode_reflink_flag(mp
, dino
, agno
, ino
, lino
);
2800 * check data fork -- if it's bad, clear the inode
2802 if (process_inode_data_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2803 &totblocks
, &nextents
, &dblkmap
, check_dups
) != 0)
2807 * check attribute fork if necessary. attributes are
2808 * always stored in the regular filesystem.
2810 if (process_inode_attr_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2811 &atotblocks
, &anextents
, check_dups
, extra_attr_check
,
2816 * enforce totblocks is 0 for misc types
2818 if (process_misc_ino_types_blocks(totblocks
, lino
, type
))
2822 * correct space counters if required
2824 if (process_inode_blocks_and_extents(dino
, totblocks
+ atotblocks
,
2825 nextents
, anextents
, lino
, dirty
) != 0)
2829 * do any semantic type-based checking here
2833 if (process_dir2(mp
, lino
, dino
, ino_discovery
,
2834 dirty
, "", parent
, dblkmap
)) {
2836 _("problem with directory contents in inode %" PRIu64
"\n"),
2841 case XR_INO_SYMLINK
:
2842 if (process_symlink(mp
, lino
, dino
, dblkmap
) != 0) {
2844 _("problem with symbolic link in inode %" PRIu64
"\n"),
2853 blkmap_free(dblkmap
);
2856 * check nlinks feature, if it's a version 1 inode,
2857 * just leave nlinks alone. even if it's set wrong,
2858 * it'll be reset when read in.
2860 *dirty
+= process_check_inode_nlink_version(dino
, lino
);
2866 *dirty
+= clear_dinode(mp
, dino
, lino
);
2872 blkmap_free(dblkmap
);
2877 * returns 1 if inode is used, 0 if free.
2878 * performs any necessary salvaging actions.
2879 * note that we leave the generation count alone
2880 * because nothing we could set it to would be
2881 * guaranteed to be correct so the best guess for
2882 * the correct value is just to leave it alone.
2884 * The trick is detecting empty files. For those,
2885 * the core and the forks should all be in the "empty"
2886 * or zero-length state -- a zero or possibly minimum length
2887 * (in the case of dirs) extent list -- although inline directories
2888 * and symlinks might be handled differently. So it should be
2889 * possible to sanity check them against each other.
2891 * If the forks are an empty extent list though, then forget it.
2892 * The file is toast anyway since we can't recover its storage.
2896 * mp -- mount structure
2897 * dino -- pointer to on-disk inode structure
2898 * agno/ino -- inode numbers
2899 * free -- whether the map thinks the inode is free (1 == free)
2900 * ino_discovery -- whether we should examine directory
2901 * contents to discover new inodes
2902 * check_dups -- whether we should check to see if the
2903 * inode references duplicate blocks
2904 * if so, we compare the inode's claimed
2905 * blocks against the contents of the
2906 * duplicate extent list but we don't
2907 * set the bitmap. If not, we set the
2908 * bitmap and try and detect multiply
2909 * claimed blocks using the bitmap.
2911 * dirty -- whether we changed the inode (1 == yes)
2912 * used -- 1 if the inode is used, 0 if free. In no modify
2913 * mode, whether the inode should be used or free
2914 * isa_dir -- 1 if the inode is a directory, 0 if not. In
2915 * no modify mode, if the inode would be a dir or not.
2917 * Return value -- 0 if the inode is good, 1 if it is/was corrupt
2924 xfs_agnumber_t agno
,
2931 int extra_attr_check
,
2935 const int verify_mode
= 0;
2936 const int uncertain
= 0;
2938 #ifdef XR_INODE_TRACE
2939 fprintf(stderr
, _("processing inode %d/%d\n"), agno
, ino
);
2941 return process_dinode_int(mp
, dino
, agno
, ino
, was_free
, dirty
, used
,
2942 verify_mode
, uncertain
, ino_discovery
,
2943 check_dups
, extra_attr_check
, isa_dir
, parent
);
2947 * a more cursory check, check inode core, *DON'T* check forks
2948 * this basically just verifies whether the inode is an inode
2949 * and whether or not it has been totally trashed. returns 0
2950 * if the inode passes the cursory sanity check, 1 otherwise.
2956 xfs_agnumber_t agno
,
2963 const int verify_mode
= 1;
2964 const int check_dups
= 0;
2965 const int ino_discovery
= 0;
2966 const int uncertain
= 0;
2968 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
2969 verify_mode
, uncertain
, ino_discovery
,
2970 check_dups
, 0, &isa_dir
, &parent
);
2974 * like above only for inode on the uncertain list. it sets
2975 * the uncertain flag which makes process_dinode_int quieter.
2976 * returns 0 if the inode passes the cursory sanity check, 1 otherwise.
2979 verify_uncertain_dinode(
2982 xfs_agnumber_t agno
,
2989 const int verify_mode
= 1;
2990 const int check_dups
= 0;
2991 const int ino_discovery
= 0;
2992 const int uncertain
= 1;
2994 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
2995 verify_mode
, uncertain
, ino_discovery
,
2996 check_dups
, 0, &isa_dir
, &parent
);