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 (be32_to_cpu(dinoc
->di_extsize
) != 0) {
198 __dirty_no_modify_ret(dirty
);
199 dinoc
->di_extsize
= 0;
202 if (dinoc
->di_version
> 1 &&
203 be32_to_cpu(dinoc
->di_nlink
) != 0) {
204 __dirty_no_modify_ret(dirty
);
208 /* we are done for version 1/2 inodes */
209 if (dinoc
->di_version
< 3)
212 if (be64_to_cpu(dinoc
->di_ino
) != ino_num
) {
213 __dirty_no_modify_ret(dirty
);
214 dinoc
->di_ino
= cpu_to_be64(ino_num
);
217 if (platform_uuid_compare(&dinoc
->di_uuid
, &mp
->m_sb
.sb_meta_uuid
)) {
218 __dirty_no_modify_ret(dirty
);
219 platform_uuid_copy(&dinoc
->di_uuid
, &mp
->m_sb
.sb_meta_uuid
);
222 for (i
= 0; i
< sizeof(dinoc
->di_pad2
)/sizeof(dinoc
->di_pad2
[0]); i
++) {
223 if (dinoc
->di_pad2
[i
] != 0) {
224 __dirty_no_modify_ret(dirty
);
225 memset(dinoc
->di_pad2
, 0, sizeof(dinoc
->di_pad2
));
230 if (be64_to_cpu(dinoc
->di_flags2
) != 0) {
231 __dirty_no_modify_ret(dirty
);
232 dinoc
->di_flags2
= 0;
235 if (be64_to_cpu(dinoc
->di_lsn
) != 0) {
236 __dirty_no_modify_ret(dirty
);
240 if (be64_to_cpu(dinoc
->di_changecount
) != 0) {
241 __dirty_no_modify_ret(dirty
);
242 dinoc
->di_changecount
= 0;
245 if (be32_to_cpu(dinoc
->di_cowextsize
) != 0) {
246 __dirty_no_modify_ret(dirty
);
247 dinoc
->di_cowextsize
= 0;
254 clear_dinode_unlinked(xfs_mount_t
*mp
, xfs_dinode_t
*dino
)
257 if (be32_to_cpu(dino
->di_next_unlinked
) != NULLAGINO
) {
259 dino
->di_next_unlinked
= cpu_to_be32(NULLAGINO
);
267 * this clears the unlinked list too so it should not be called
268 * until after the agi unlinked lists are walked in phase 3.
269 * returns > zero if the inode has been altered while being cleared
272 clear_dinode(xfs_mount_t
*mp
, xfs_dinode_t
*dino
, xfs_ino_t ino_num
)
276 dirty
= clear_dinode_core(mp
, dino
, ino_num
);
277 dirty
+= clear_dinode_unlinked(mp
, dino
);
279 /* and clear the forks */
281 if (dirty
&& !no_modify
)
282 memset(XFS_DFORK_DPTR(dino
), 0,
283 XFS_LITINO(mp
, dino
->di_version
));
290 * misc. inode-related utility routines
294 * verify_ag_bno is heavily used. In the common case, it
295 * performs just two number of compares
296 * Returns 1 for bad ag/bno pair or 0 if it's valid.
299 verify_ag_bno(xfs_sb_t
*sbp
,
303 if (agno
< (sbp
->sb_agcount
- 1))
304 return (agbno
>= sbp
->sb_agblocks
);
305 if (agno
== (sbp
->sb_agcount
- 1))
306 return (agbno
>= (sbp
->sb_dblocks
-
307 ((xfs_rfsblock_t
)(sbp
->sb_agcount
- 1) *
313 * returns 0 if inode number is valid, 1 if bogus
316 verify_inum(xfs_mount_t
*mp
,
322 xfs_sb_t
*sbp
= &mp
->m_sb
;;
324 /* range check ag #, ag block. range-checking offset is pointless */
326 agno
= XFS_INO_TO_AGNO(mp
, ino
);
327 agino
= XFS_INO_TO_AGINO(mp
, ino
);
328 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
332 if (ino
== 0 || ino
== NULLFSINO
)
335 if (ino
!= XFS_AGINO_TO_INO(mp
, agno
, agino
))
338 return verify_ag_bno(sbp
, agno
, agbno
);
342 * have a separate routine to ensure that we don't accidentally
343 * lose illegally set bits in the agino by turning it into an FSINO
344 * to feed to the above routine
347 verify_aginum(xfs_mount_t
*mp
,
352 xfs_sb_t
*sbp
= &mp
->m_sb
;;
354 /* range check ag #, ag block. range-checking offset is pointless */
356 if (agino
== 0 || agino
== NULLAGINO
)
360 * agino's can't be too close to NULLAGINO because the min blocksize
361 * is 9 bits and at most 1 bit of that gets used for the inode offset
362 * so if the agino gets shifted by the # of offset bits and compared
363 * to the legal agbno values, a bogus agino will be too large. there
364 * will be extra bits set at the top that shouldn't be set.
366 agbno
= XFS_AGINO_TO_AGBNO(mp
, agino
);
370 return verify_ag_bno(sbp
, agno
, agbno
);
374 * return 1 if block number is good, 0 if out of range
377 verify_dfsbno(xfs_mount_t
*mp
,
382 xfs_sb_t
*sbp
= &mp
->m_sb
;;
384 /* range check ag #, ag block. range-checking offset is pointless */
386 agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
387 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
);
389 return verify_ag_bno(sbp
, agno
, agbno
) == 0;
392 #define XR_DFSBNORANGE_VALID 0
393 #define XR_DFSBNORANGE_BADSTART 1
394 #define XR_DFSBNORANGE_BADEND 2
395 #define XR_DFSBNORANGE_OVERFLOW 3
398 verify_dfsbno_range(xfs_mount_t
*mp
,
404 xfs_sb_t
*sbp
= &mp
->m_sb
;;
406 /* the start and end blocks better be in the same allocation group */
407 agno
= XFS_FSB_TO_AGNO(mp
, fsbno
);
408 if (agno
!= XFS_FSB_TO_AGNO(mp
, fsbno
+ count
- 1)) {
409 return XR_DFSBNORANGE_OVERFLOW
;
412 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
);
413 if (verify_ag_bno(sbp
, agno
, agbno
)) {
414 return XR_DFSBNORANGE_BADSTART
;
417 agbno
= XFS_FSB_TO_AGBNO(mp
, fsbno
+ count
- 1);
418 if (verify_ag_bno(sbp
, agno
, agbno
)) {
419 return XR_DFSBNORANGE_BADEND
;
422 return (XR_DFSBNORANGE_VALID
);
426 verify_agbno(xfs_mount_t
*mp
,
430 xfs_sb_t
*sbp
= &mp
->m_sb
;;
432 /* range check ag #, ag block. range-checking offset is pointless */
433 return verify_ag_bno(sbp
, agno
, agbno
) == 0;
439 xfs_bmbt_irec_t
*irec
,
447 int pwe
; /* partially-written extent */
450 * check numeric validity of the extent
452 if (irec
->br_startblock
>= mp
->m_sb
.sb_rblocks
) {
454 _("inode %" PRIu64
" - bad rt extent start block number %" PRIu64
", offset %" PRIu64
"\n"),
460 if (irec
->br_startblock
+ irec
->br_blockcount
- 1 >= mp
->m_sb
.sb_rblocks
) {
462 _("inode %" PRIu64
" - bad rt extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
464 irec
->br_startblock
+ irec
->br_blockcount
- 1,
468 if (irec
->br_startblock
+ irec
->br_blockcount
- 1 < irec
->br_startblock
) {
470 _("inode %" PRIu64
" - bad rt extent overflows - start %" PRIu64
", "
471 "end %" PRIu64
", offset %" PRIu64
"\n"),
474 irec
->br_startblock
+ irec
->br_blockcount
- 1,
480 * verify that the blocks listed in the record
481 * are multiples of an extent
483 if (xfs_sb_version_hasextflgbit(&mp
->m_sb
) == 0 &&
484 (irec
->br_startblock
% mp
->m_sb
.sb_rextsize
!= 0 ||
485 irec
->br_blockcount
% mp
->m_sb
.sb_rextsize
!= 0)) {
487 _("malformed rt inode extent [%" PRIu64
" %" PRIu64
"] (fs rtext size = %u)\n"),
490 mp
->m_sb
.sb_rextsize
);
495 * set the appropriate number of extents
496 * this iterates block by block, this can be optimised using extents
498 for (b
= irec
->br_startblock
; b
< irec
->br_startblock
+
499 irec
->br_blockcount
; b
+= mp
->m_sb
.sb_rextsize
) {
500 ext
= (xfs_rtblock_t
) b
/ mp
->m_sb
.sb_rextsize
;
501 pwe
= xfs_sb_version_hasextflgbit(&mp
->m_sb
) &&
502 irec
->br_state
== XFS_EXT_UNWRITTEN
&&
503 (b
% mp
->m_sb
.sb_rextsize
!= 0);
505 if (check_dups
== 1) {
506 if (search_rt_dup_extent(mp
, ext
) && !pwe
) {
508 _("data fork in rt ino %" PRIu64
" claims dup rt extent,"
509 "off - %" PRIu64
", start - %" PRIu64
", count %" PRIu64
"\n"),
513 irec
->br_blockcount
);
519 state
= get_rtbmap(ext
);
523 set_rtbmap(ext
, XR_E_INUSE
);
527 _("bad state in rt block map %" PRIu64
"\n"),
533 _("data fork in rt inode %" PRIu64
" found metadata block %" PRIu64
" in rt bmap\n"),
540 set_rtbmap(ext
, XR_E_MULT
);
542 _("data fork in rt inode %" PRIu64
" claims used rt block %" PRIu64
"\n"),
548 _("illegal state %d in rt block map %" PRIu64
"\n"),
554 * bump up the block counter
556 *tot
+= irec
->br_blockcount
;
562 * return 1 if inode should be cleared, 0 otherwise
563 * if check_dups should be set to 1, that implies that
564 * the primary purpose of this call is to see if the
565 * file overlaps with any duplicate extents (in the
566 * duplicate extent list).
569 process_bmbt_reclist_int(
577 xfs_fileoff_t
*first_key
,
578 xfs_fileoff_t
*last_key
,
582 xfs_bmbt_irec_t irec
;
583 xfs_filblks_t cp
= 0; /* prev count */
584 xfs_fsblock_t sp
= 0; /* prev start */
585 xfs_fileoff_t op
= 0; /* prev offset */
588 char *forkname
= get_forkname(whichfork
);
595 xfs_agnumber_t locked_agno
= -1;
598 if (type
== XR_INO_RTDATA
)
599 ftype
= ftype_real_time
;
601 ftype
= ftype_regular
;
603 for (i
= 0; i
< *numrecs
; i
++) {
604 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
606 *last_key
= *first_key
= irec
.br_startoff
;
608 *last_key
= irec
.br_startoff
;
609 if (i
> 0 && op
+ cp
> irec
.br_startoff
) {
611 _("bmap rec out of order, inode %" PRIu64
" entry %d "
612 "[o s c] [%" PRIu64
" %" PRIu64
" %" PRIu64
"], "
613 "%d [%" PRIu64
" %" PRIu64
" %" PRIu64
"]\n"),
614 ino
, i
, irec
.br_startoff
, irec
.br_startblock
,
615 irec
.br_blockcount
, i
- 1, op
, sp
, cp
);
618 op
= irec
.br_startoff
;
619 cp
= irec
.br_blockcount
;
620 sp
= irec
.br_startblock
;
623 * check numeric validity of the extent
625 if (irec
.br_blockcount
== 0) {
627 _("zero length extent (off = %" PRIu64
", fsbno = %" PRIu64
") in ino %" PRIu64
"\n"),
634 if (type
== XR_INO_RTDATA
&& whichfork
== XFS_DATA_FORK
) {
636 * realtime bitmaps don't use AG locks, so returning
637 * immediately is fine for this code path.
639 if (process_rt_rec(mp
, &irec
, ino
, tot
, check_dups
))
642 * skip rest of loop processing since that'irec.br_startblock
643 * all for regular file forks and attr forks
649 * regular file data fork or attribute fork
651 switch (verify_dfsbno_range(mp
, irec
.br_startblock
,
652 irec
.br_blockcount
)) {
653 case XR_DFSBNORANGE_VALID
:
656 case XR_DFSBNORANGE_BADSTART
:
658 _("inode %" PRIu64
" - bad extent starting block number %" PRIu64
", offset %" PRIu64
"\n"),
664 case XR_DFSBNORANGE_BADEND
:
666 _("inode %" PRIu64
" - bad extent last block number %" PRIu64
", offset %" PRIu64
"\n"),
668 irec
.br_startblock
+ irec
.br_blockcount
- 1,
672 case XR_DFSBNORANGE_OVERFLOW
:
674 _("inode %" PRIu64
" - bad extent overflows - start %" PRIu64
", "
675 "end %" PRIu64
", offset %" PRIu64
"\n"),
678 irec
.br_startblock
+ irec
.br_blockcount
- 1,
682 /* Ensure this extent does not extend beyond the max offset */
683 if (irec
.br_startoff
+ irec
.br_blockcount
- 1 >
684 fs_max_file_offset
) {
686 _("inode %" PRIu64
" - extent exceeds max offset - start %" PRIu64
", "
687 "count %" PRIu64
", physical block %" PRIu64
"\n"),
688 ino
, irec
.br_startoff
, irec
.br_blockcount
,
693 if (blkmapp
&& *blkmapp
) {
695 error2
= blkmap_set_ext(blkmapp
, irec
.br_startoff
,
696 irec
.br_startblock
, irec
.br_blockcount
);
699 * we don't want to clear the inode due to an
700 * internal bmap tracking error, but if we've
701 * run out of memory then we simply can't
702 * validate that the filesystem is consistent.
703 * Hence just abort at this point with an ENOMEM
707 _("Fatal error: inode %" PRIu64
" - blkmap_set_ext(): %s\n"
708 "\t%s fork, off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
709 ino
, strerror(error2
), forkname
,
710 irec
.br_startoff
, irec
.br_startblock
,
716 * Profiling shows that the following loop takes the
717 * most time in all of xfs_repair.
719 agno
= XFS_FSB_TO_AGNO(mp
, irec
.br_startblock
);
720 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
721 ebno
= agbno
+ irec
.br_blockcount
;
722 if (agno
!= locked_agno
) {
723 if (locked_agno
!= -1)
724 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
725 pthread_mutex_lock(&ag_locks
[agno
].lock
);
731 * if we're just checking the bmap for dups,
732 * return if we find one, otherwise, continue
733 * checking each entry without setting the
736 if (!(type
== XR_INO_DATA
&&
737 xfs_sb_version_hasreflink(&mp
->m_sb
)) &&
738 search_dup_extent(agno
, agbno
, ebno
)) {
740 _("%s fork in ino %" PRIu64
" claims dup extent, "
741 "off - %" PRIu64
", start - %" PRIu64
", cnt %" PRIu64
"\n"),
742 forkname
, ino
, irec
.br_startoff
,
747 *tot
+= irec
.br_blockcount
;
751 for (b
= irec
.br_startblock
;
753 b
+= blen
, agbno
+= blen
) {
754 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
759 _("%s fork in ino %" PRIu64
" claims free block %" PRIu64
"\n"),
760 forkname
, ino
, (uint64_t) b
);
761 /* fall through ... */
762 case XR_E_INUSE1
: /* seen by rmap */
767 do_error(_("bad state in block map %" PRIu64
"\n"), b
);
772 do_warn(_("rmap claims metadata use!\n"));
779 _("%s fork in inode %" PRIu64
" claims metadata block %" PRIu64
"\n"),
785 if (type
== XR_INO_DATA
&&
786 xfs_sb_version_hasreflink(&mp
->m_sb
))
789 _("%s fork in %s inode %" PRIu64
" claims used block %" PRIu64
"\n"),
790 forkname
, ftype
, ino
, b
);
795 _("%s fork in %s inode %" PRIu64
" claims CoW block %" PRIu64
"\n"),
796 forkname
, ftype
, ino
, b
);
801 _("illegal state %d in block map %" PRIu64
"\n"),
808 * Update the internal extent map only after we've checked
809 * every block in this extent. The first time we reject this
810 * data fork we'll try to rebuild the bmbt from rmap data.
811 * After a successful rebuild we'll try this scan again.
812 * (If the rebuild fails we won't come back here.)
814 agbno
= XFS_FSB_TO_AGBNO(mp
, irec
.br_startblock
);
815 ebno
= agbno
+ irec
.br_blockcount
;
816 for (; agbno
< ebno
; agbno
+= blen
) {
817 state
= get_bmap_ext(agno
, agbno
, ebno
, &blen
);
823 set_bmap_ext(agno
, agbno
, blen
, XR_E_INUSE
);
827 set_bmap_ext(agno
, agbno
, blen
, XR_E_MULT
);
833 if (collect_rmaps
) { /* && !check_dups */
834 error
= rmap_add_rec(mp
, ino
, whichfork
, &irec
);
837 _("couldn't add reverse mapping\n")
840 *tot
+= irec
.br_blockcount
;
844 if (locked_agno
!= -1)
845 pthread_mutex_unlock(&ag_locks
[locked_agno
].lock
);
848 ASSERT(i
< *numrecs
);
849 do_warn(_("correcting nextents for inode %" PRIu64
"\n"), ino
);
857 * return 1 if inode should be cleared, 0 otherwise, sets block bitmap
861 process_bmbt_reclist(
869 xfs_fileoff_t
*first_key
,
870 xfs_fileoff_t
*last_key
,
873 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
874 blkmapp
, first_key
, last_key
, 0, whichfork
);
878 * return 1 if inode should be cleared, 0 otherwise, does not set
891 xfs_fileoff_t first_key
= 0;
892 xfs_fileoff_t last_key
= 0;
894 return process_bmbt_reclist_int(mp
, rp
, numrecs
, type
, ino
, tot
,
895 NULL
, &first_key
, &last_key
, 1, whichfork
);
899 * Grab the buffer backing an inode. This is meant for routines that
900 * work with inodes one at a time in any order (like walking the
901 * unlinked lists to look for inodes). The caller is responsible for
902 * writing/releasing the buffer.
906 struct xfs_mount
*mp
,
909 struct xfs_dinode
**dipp
)
914 xfs_agino_t cluster_agino
;
915 xfs_daddr_t cluster_daddr
;
916 xfs_daddr_t cluster_blks
;
919 * Inode buffers have been read into memory in inode_cluster_size
920 * chunks (or one FSB). To find the correct buffer for an inode,
921 * we must find the buffer for its cluster, add the appropriate
922 * offset, and return that.
924 cluster_size
= MAX(mp
->m_inode_cluster_size
, mp
->m_sb
.sb_blocksize
);
925 ino_per_cluster
= cluster_size
/ mp
->m_sb
.sb_inodesize
;
926 cluster_agino
= agino
& ~(ino_per_cluster
- 1);
927 cluster_blks
= XFS_FSB_TO_DADDR(mp
, MAX(1,
928 mp
->m_inode_cluster_size
>> mp
->m_sb
.sb_blocklog
));
929 cluster_daddr
= XFS_AGB_TO_DADDR(mp
, agno
,
930 XFS_AGINO_TO_AGBNO(mp
, cluster_agino
));
932 #ifdef XR_INODE_TRACE
933 printf("cluster_size %d ipc %d clusagino %d daddr %lld sectors %lld\n",
934 cluster_size
, ino_per_cluster
, cluster_agino
, cluster_daddr
,
938 bp
= libxfs_readbuf(mp
->m_dev
, cluster_daddr
, cluster_blks
,
939 0, &xfs_inode_buf_ops
);
941 do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64
"\n"),
942 agno
, cluster_agino
, cluster_daddr
);
946 *dipp
= xfs_make_iptr(mp
, bp
, agino
- cluster_agino
);
947 ASSERT(!xfs_sb_version_hascrc(&mp
->m_sb
) ||
948 XFS_AGINO_TO_INO(mp
, agno
, agino
) ==
949 be64_to_cpu((*dipp
)->di_ino
));
954 * higher level inode processing stuff starts here:
955 * first, one utility routine for each type of inode
959 * return 1 if inode should be cleared, 0 otherwise
975 xfs_bmdr_block_t
*dib
;
976 xfs_fileoff_t last_key
;
977 xfs_fileoff_t first_key
= 0;
980 xfs_bmbt_key_t
*pkey
;
981 char *forkname
= get_forkname(whichfork
);
985 bmap_cursor_t cursor
;
988 dib
= (xfs_bmdr_block_t
*)XFS_DFORK_PTR(dip
, whichfork
);
989 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
993 magic
= xfs_sb_version_hascrc(&mp
->m_sb
) ? XFS_BMAP_CRC_MAGIC
996 level
= be16_to_cpu(dib
->bb_level
);
997 numrecs
= be16_to_cpu(dib
->bb_numrecs
);
999 if ((level
== 0) || (level
> XFS_BM_MAXLEVELS(mp
, whichfork
))) {
1001 * XXX - if we were going to fix up the inode,
1002 * we'd try to treat the fork as an interior
1003 * node and see if we could get an accurate
1004 * level value from one of the blocks pointed
1005 * to by the pointers in the fork. For now
1006 * though, we just bail (and blow out the inode).
1009 _("bad level %d in inode %" PRIu64
" bmap btree root block\n"),
1010 level
, XFS_AGINO_TO_INO(mp
, agno
, ino
));
1015 _("bad numrecs 0 in inode %" PRIu64
" bmap btree root block\n"),
1016 XFS_AGINO_TO_INO(mp
, agno
, ino
));
1020 * use bmdr/dfork_dsize since the root block is in the data fork
1022 if (XFS_BMDR_SPACE_CALC(numrecs
) > XFS_DFORK_SIZE(dip
, mp
, whichfork
)) {
1024 _("indicated size of %s btree root (%d bytes) greater than space in "
1025 "inode %" PRIu64
" %s fork\n"),
1026 forkname
, XFS_BMDR_SPACE_CALC(numrecs
), lino
, forkname
);
1030 init_bm_cursor(&cursor
, level
+ 1);
1032 pp
= XFS_BMDR_PTR_ADDR(dib
, 1,
1033 libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip
, mp
, whichfork
), 0));
1034 pkey
= XFS_BMDR_KEY_ADDR(dib
, 1);
1035 last_key
= NULLFILEOFF
;
1037 for (i
= 0; i
< numrecs
; i
++) {
1039 * XXX - if we were going to do more to fix up the inode
1040 * btree, we'd do it right here. For now, if there's a
1041 * problem, we'll bail out and presumably clear the inode.
1043 if (!verify_dfsbno(mp
, get_unaligned_be64(&pp
[i
]))) {
1045 _("bad bmap btree ptr 0x%" PRIx64
" in ino %" PRIu64
"\n"),
1046 get_unaligned_be64(&pp
[i
]), lino
);
1050 if (scan_lbtree(get_unaligned_be64(&pp
[i
]), level
, scan_bmapbt
,
1051 type
, whichfork
, lino
, tot
, nex
, blkmapp
,
1052 &cursor
, 1, check_dups
, magic
,
1056 * fix key (offset) mismatches between the keys in root
1057 * block records and the first key of each child block.
1058 * fixes cases where entries have been shifted between
1059 * blocks but the parent hasn't been updated
1061 if (!check_dups
&& cursor
.level
[level
-1].first_key
!=
1062 get_unaligned_be64(&pkey
[i
].br_startoff
)) {
1065 _("correcting key in bmbt root (was %" PRIu64
", now %" PRIu64
") in inode "
1066 "%" PRIu64
" %s fork\n"),
1067 get_unaligned_be64(&pkey
[i
].br_startoff
),
1068 cursor
.level
[level
-1].first_key
,
1069 XFS_AGINO_TO_INO(mp
, agno
, ino
),
1073 cursor
.level
[level
-1].first_key
,
1074 &pkey
[i
].br_startoff
);
1077 _("bad key in bmbt root (is %" PRIu64
", would reset to %" PRIu64
") in inode "
1078 "%" PRIu64
" %s fork\n"),
1079 get_unaligned_be64(&pkey
[i
].br_startoff
),
1080 cursor
.level
[level
-1].first_key
,
1081 XFS_AGINO_TO_INO(mp
, agno
, ino
),
1086 * make sure that keys are in ascending order. blow out
1087 * inode if the ordering doesn't hold
1089 if (check_dups
== 0) {
1090 if (last_key
!= NULLFILEOFF
&& last_key
>=
1091 cursor
.level
[level
-1].first_key
) {
1093 _("out of order bmbt root key %" PRIu64
" in inode %" PRIu64
" %s fork\n"),
1095 XFS_AGINO_TO_INO(mp
, agno
, ino
),
1099 last_key
= cursor
.level
[level
-1].first_key
;
1103 * Ideally if all the extents are ok (perhaps after further
1104 * checks below?) we'd just move this back into extents format.
1105 * But for now clear it, as the kernel will choke on this
1107 if (*nex
<= XFS_DFORK_SIZE(dip
, mp
, whichfork
) /
1108 sizeof(xfs_bmbt_rec_t
)) {
1110 _("extent count for ino %" PRIu64
" %s fork too low (%" PRIu64
") for file format\n"),
1111 lino
, forkname
, *nex
);
1115 * Check that the last child block's forward sibling pointer
1118 if (check_dups
== 0 &&
1119 cursor
.level
[0].right_fsbno
!= NULLFSBLOCK
) {
1121 _("bad fwd (right) sibling pointer (saw %" PRIu64
" should be NULLFSBLOCK)\n"),
1122 cursor
.level
[0].right_fsbno
);
1124 _("\tin inode %" PRIu64
" (%s fork) bmap btree block %" PRIu64
"\n"),
1125 XFS_AGINO_TO_INO(mp
, agno
, ino
), forkname
,
1126 cursor
.level
[0].fsbno
);
1134 * return 1 if inode should be cleared, 0 otherwise
1139 xfs_agnumber_t agno
,
1144 xfs_rfsblock_t
*tot
,
1152 xfs_fileoff_t first_key
;
1153 xfs_fileoff_t last_key
;
1157 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1158 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_PTR(dip
, whichfork
);
1160 numrecs
= XFS_DFORK_NEXTENTS(dip
, whichfork
);
1163 * We've already decided on the maximum number of extents on the inode,
1164 * and numrecs may be corrupt. Hence make sure we only allow numrecs to
1165 * be in the range of valid on-disk numbers, which is:
1166 * 0 < numrecs < 2^31 - 1
1172 * XXX - if we were going to fix up the btree record,
1173 * we'd do it right here. For now, if there's a problem,
1174 * we'll bail out and presumably clear the inode.
1176 if (check_dups
== 0)
1177 ret
= process_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
,
1178 tot
, blkmapp
, &first_key
, &last_key
,
1181 ret
= scan_bmbt_reclist(mp
, rp
, &numrecs
, type
, lino
, tot
,
1189 * return 1 if inode should be cleared, 0 otherwise
1194 xfs_agnumber_t agno
,
1199 xfs_attr_shortform_t
*asf
;
1202 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
1203 if (whichfork
== XFS_DATA_FORK
&& be64_to_cpu(dip
->di_size
) >
1204 XFS_DFORK_DSIZE(dip
, mp
)) {
1206 _("local inode %" PRIu64
" data fork is too large (size = %lld, max = %d)\n"),
1207 lino
, (unsigned long long) be64_to_cpu(dip
->di_size
),
1208 XFS_DFORK_DSIZE(dip
, mp
));
1210 } else if (whichfork
== XFS_ATTR_FORK
) {
1211 asf
= (xfs_attr_shortform_t
*)XFS_DFORK_APTR(dip
);
1212 if (be16_to_cpu(asf
->hdr
.totsize
) > XFS_DFORK_ASIZE(dip
, mp
)) {
1214 _("local inode %" PRIu64
" attr fork too large (size %d, max = %d)\n"),
1215 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1216 XFS_DFORK_ASIZE(dip
, mp
));
1219 if (be16_to_cpu(asf
->hdr
.totsize
) < sizeof(xfs_attr_sf_hdr_t
)) {
1221 _("local inode %" PRIu64
" attr too small (size = %d, min size = %zd)\n"),
1222 lino
, be16_to_cpu(asf
->hdr
.totsize
),
1223 sizeof(xfs_attr_sf_hdr_t
));
1232 process_symlink_extlist(xfs_mount_t
*mp
, xfs_ino_t lino
, xfs_dinode_t
*dino
)
1234 xfs_fileoff_t expected_offset
;
1236 xfs_bmbt_irec_t irec
;
1241 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1242 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
)
1245 _("mismatch between format (%d) and size (%" PRId64
") in symlink ino %" PRIu64
"\n"),
1247 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1250 if (dino
->di_format
== XFS_DINODE_FMT_LOCAL
) {
1252 _("mismatch between format (%d) and size (%" PRId64
") in symlink inode %" PRIu64
"\n"),
1254 (int64_t)be64_to_cpu(dino
->di_size
), lino
);
1258 rp
= (xfs_bmbt_rec_t
*)XFS_DFORK_DPTR(dino
);
1259 numrecs
= be32_to_cpu(dino
->di_nextents
);
1262 * the max # of extents in a symlink inode is equal to the
1263 * number of max # of blocks required to store the symlink
1265 if (numrecs
> max_symlink_blocks
) {
1267 _("bad number of extents (%d) in symlink %" PRIu64
" data fork\n"),
1272 max_blocks
= max_symlink_blocks
;
1273 expected_offset
= 0;
1275 for (i
= 0; i
< numrecs
; i
++) {
1276 libxfs_bmbt_disk_get_all((rp
+i
), &irec
);
1277 if (irec
.br_startoff
!= expected_offset
) {
1279 _("bad extent #%d offset (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1280 i
, irec
.br_startoff
, lino
);
1283 if (irec
.br_blockcount
== 0 || irec
.br_blockcount
> max_blocks
) {
1285 _("bad extent #%d count (%" PRIu64
") in symlink %" PRIu64
" data fork\n"),
1286 i
, irec
.br_blockcount
, lino
);
1290 max_blocks
-= irec
.br_blockcount
;
1291 expected_offset
+= irec
.br_blockcount
;
1298 * takes a name and length and returns 1 if the name contains
1299 * a \0, returns 0 otherwise
1302 null_check(char *name
, int length
)
1306 ASSERT(length
< XFS_SYMLINK_MAXLEN
);
1308 for (i
= 0; i
< length
; i
++, name
++) {
1317 * This does /not/ do quotacheck, it validates the basic quota
1318 * inode metadata, checksums, etc.
1320 #define uuid_equal(s,d) (platform_uuid_compare((s),(d)) == 0)
1322 process_quota_inode(
1323 struct xfs_mount
*mp
,
1325 struct xfs_dinode
*dino
,
1327 struct blkmap
*blkmap
)
1329 xfs_fsblock_t fsbno
;
1331 xfs_filblks_t dqchunklen
;
1342 quota_type
= XFS_DQ_USER
;
1343 quota_string
= _("User quota");
1346 quota_type
= XFS_DQ_GROUP
;
1347 quota_string
= _("Group quota");
1350 quota_type
= XFS_DQ_PROJ
;
1351 quota_string
= _("Project quota");
1357 dqchunklen
= XFS_FSB_TO_BB(mp
, XFS_DQUOT_CLUSTER_SIZE_FSB
);
1358 dqperchunk
= libxfs_calc_dquots_per_chunk(dqchunklen
);
1362 while ((qbno
= blkmap_next_off(blkmap
, qbno
, &t
)) != NULLFILEOFF
) {
1366 fsbno
= blkmap_get(blkmap
, qbno
);
1367 dqid
= (xfs_dqid_t
)qbno
* dqperchunk
;
1369 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1370 dqchunklen
, 0, &xfs_dquot_buf_ops
);
1373 _("cannot read inode %" PRIu64
", file block %" PRIu64
", disk block %" PRIu64
"\n"),
1379 for (i
= 0; i
< dqperchunk
; i
++, dqid
++, dqb
++) {
1382 /* We only print the first problem we find */
1383 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1384 if (!libxfs_verify_cksum((char *)dqb
,
1386 XFS_DQUOT_CRC_OFF
)) {
1387 do_warn(_("%s: bad CRC for id %u. "),
1388 quota_string
, dqid
);
1393 if (!uuid_equal(&dqb
->dd_uuid
,
1394 &mp
->m_sb
.sb_meta_uuid
)) {
1395 do_warn(_("%s: bad UUID for id %u. "),
1396 quota_string
, dqid
);
1401 if (libxfs_dquot_verify(mp
, &dqb
->dd_diskdq
, dqid
,
1402 quota_type
) != NULL
) {
1403 do_warn(_("%s: Corrupt quota for id %u. "),
1404 quota_string
, dqid
);
1411 do_warn(_("Would correct.\n"));
1413 do_warn(_("Corrected.\n"));
1414 libxfs_dquot_repair(mp
, &dqb
->dd_diskdq
,
1421 if (writebuf
&& !no_modify
)
1422 libxfs_writebuf(bp
, 0);
1430 process_symlink_remote(
1431 struct xfs_mount
*mp
,
1433 struct xfs_dinode
*dino
,
1434 struct blkmap
*blkmap
,
1437 xfs_fsblock_t fsbno
;
1445 pathlen
= be64_to_cpu(dino
->di_size
);
1448 while (pathlen
> 0) {
1453 fsbno
= blkmap_get(blkmap
, i
);
1454 if (fsbno
== NULLFSBLOCK
) {
1456 _("cannot read inode %" PRIu64
", file block %d, NULL disk block\n"),
1462 * There's a symlink header for each contiguous extent. If
1463 * there are contiguous blocks, read them in one go.
1465 while (blk_cnt
<= max_symlink_blocks
) {
1466 if (blkmap_get(blkmap
, i
+ 1) != fsbno
+ 1)
1472 byte_cnt
= XFS_FSB_TO_B(mp
, blk_cnt
);
1474 bp
= libxfs_readbuf(mp
->m_dev
, XFS_FSB_TO_DADDR(mp
, fsbno
),
1475 BTOBB(byte_cnt
), 0, &xfs_symlink_buf_ops
);
1478 _("cannot read inode %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1482 if (bp
->b_error
== -EFSCORRUPTED
) {
1484 _("Corrupt symlink remote block %" PRIu64
", inode %" PRIu64
".\n"),
1489 if (bp
->b_error
== -EFSBADCRC
) {
1491 _("Bad symlink buffer CRC, block %" PRIu64
", inode %" PRIu64
".\n"
1492 "Correcting CRC, but symlink may be bad.\n"), fsbno
, lino
);
1496 byte_cnt
= XFS_SYMLINK_BUF_SPACE(mp
, byte_cnt
);
1497 byte_cnt
= MIN(pathlen
, byte_cnt
);
1500 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
1501 if (!libxfs_symlink_hdr_ok(lino
, offset
,
1504 _("bad symlink header ino %" PRIu64
", file block %d, disk block %" PRIu64
"\n"),
1509 src
+= sizeof(struct xfs_dsymlink_hdr
);
1512 memmove(dst
+ offset
, src
, byte_cnt
);
1514 pathlen
-= byte_cnt
;
1518 if (badcrc
&& !no_modify
)
1519 libxfs_writebuf(bp
, 0);
1527 * like usual, returns 0 if everything's ok and 1 if something's
1538 char data
[XFS_SYMLINK_MAXLEN
];
1541 * check size against kernel symlink limits. we know
1542 * size is consistent with inode storage format -- e.g.
1543 * the inode is structurally ok so we don't have to check
1546 if (be64_to_cpu(dino
->di_size
) >= XFS_SYMLINK_MAXLEN
) {
1547 do_warn(_("symlink in inode %" PRIu64
" too long (%llu chars)\n"),
1548 lino
, (unsigned long long) be64_to_cpu(dino
->di_size
));
1552 if (be64_to_cpu(dino
->di_size
) == 0) {
1553 do_warn(_("zero size symlink in inode %" PRIu64
"\n"), lino
);
1558 * have to check symlink component by component.
1559 * get symlink contents into data area
1562 if (be64_to_cpu(dino
->di_size
) <= XFS_DFORK_DSIZE(dino
, mp
)) {
1564 * local symlink, just copy the symlink out of the
1565 * inode into the data area
1567 memmove(symlink
, XFS_DFORK_DPTR(dino
),
1568 be64_to_cpu(dino
->di_size
));
1572 error
= process_symlink_remote(mp
, lino
, dino
, blkmap
, symlink
);
1577 data
[be64_to_cpu(dino
->di_size
)] = '\0';
1582 if (null_check(symlink
, be64_to_cpu(dino
->di_size
))) {
1584 _("found illegal null character in symlink inode %" PRIu64
"\n"),
1593 * called to process the set of misc inode special inode types
1594 * that have no associated data storage (fifos, pipes, devices, etc.).
1597 process_misc_ino_types(xfs_mount_t
*mp
,
1603 * disallow mountpoint inodes until such time as the
1604 * kernel actually allows them to be created (will
1605 * probably require a superblock version rev, sigh).
1607 if (type
== XR_INO_MOUNTPOINT
) {
1609 _("inode %" PRIu64
" has bad inode type (IFMNT)\n"), lino
);
1614 * must also have a zero size
1616 if (be64_to_cpu(dino
->di_size
) != 0) {
1620 _("size of character device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1621 (int64_t)be64_to_cpu(dino
->di_size
));
1625 _("size of block device inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1626 (int64_t)be64_to_cpu(dino
->di_size
));
1630 _("size of socket inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1631 (int64_t)be64_to_cpu(dino
->di_size
));
1635 _("size of fifo inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1636 (int64_t)be64_to_cpu(dino
->di_size
));
1642 _("size of quota inode %" PRIu64
" != 0 (%" PRId64
" bytes)\n"), lino
,
1643 (int64_t)be64_to_cpu(dino
->di_size
));
1646 do_warn(_("Internal error - process_misc_ino_types, "
1647 "illegal type %d\n"), type
);
1658 process_misc_ino_types_blocks(xfs_rfsblock_t totblocks
, xfs_ino_t lino
, int type
)
1661 * you can not enforce all misc types have zero data fork blocks
1662 * by checking dino->di_nblocks because atotblocks (attribute
1663 * blocks) are part of nblocks. We must check this later when atotblocks
1664 * has been calculated or by doing a simple check that anExtents == 0.
1665 * We must also guarantee that totblocks is 0. Thus nblocks checking
1666 * will be done later in process_dinode_int for misc types.
1669 if (totblocks
!= 0) {
1673 _("size of character device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1678 _("size of block device inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1683 _("size of socket inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1688 _("size of fifo inode %" PRIu64
" != 0 (%" PRIu64
" blocks)\n"),
1703 return be16_to_cpu(dino
->di_mode
) & S_IFMT
;
1711 int mode
= be16_to_cpu(dino
->di_mode
);
1713 ASSERT((new_fmt
& ~S_IFMT
) == 0);
1717 dino
->di_mode
= cpu_to_be16(mode
);
1721 check_dinode_mode_format(
1722 xfs_dinode_t
*dinoc
)
1724 if (dinoc
->di_format
>= XFS_DINODE_FMT_UUID
)
1725 return -1; /* FMT_UUID is not used */
1727 switch (dinode_fmt(dinoc
)) {
1732 return (dinoc
->di_format
!= XFS_DINODE_FMT_DEV
) ? -1 : 0;
1735 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1736 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1739 return (dinoc
->di_format
< XFS_DINODE_FMT_EXTENTS
||
1740 dinoc
->di_format
> XFS_DINODE_FMT_BTREE
) ? -1 : 0;
1743 return (dinoc
->di_format
< XFS_DINODE_FMT_LOCAL
||
1744 dinoc
->di_format
> XFS_DINODE_FMT_EXTENTS
) ? -1 : 0;
1748 return 0; /* invalid modes are checked elsewhere */
1752 * If inode is a superblock inode, does type check to make sure is it valid.
1753 * Returns 0 if it's valid, non-zero if it needs to be cleared.
1757 process_check_sb_inodes(
1759 xfs_dinode_t
*dinoc
,
1764 if (lino
== mp
->m_sb
.sb_rootino
) {
1765 if (*type
!= XR_INO_DIR
) {
1766 do_warn(_("root inode %" PRIu64
" has bad type 0x%x\n"),
1767 lino
, dinode_fmt(dinoc
));
1770 do_warn(_("resetting to directory\n"));
1771 change_dinode_fmt(dinoc
, S_IFDIR
);
1774 do_warn(_("would reset to directory\n"));
1778 if (lino
== mp
->m_sb
.sb_uquotino
) {
1779 if (*type
!= XR_INO_UQUOTA
) {
1780 do_warn(_("user quota inode %" PRIu64
" has bad type 0x%x\n"),
1781 lino
, dinode_fmt(dinoc
));
1782 mp
->m_sb
.sb_uquotino
= NULLFSINO
;
1787 if (lino
== mp
->m_sb
.sb_gquotino
) {
1788 if (*type
!= XR_INO_GQUOTA
) {
1789 do_warn(_("group quota inode %" PRIu64
" has bad type 0x%x\n"),
1790 lino
, dinode_fmt(dinoc
));
1791 mp
->m_sb
.sb_gquotino
= NULLFSINO
;
1796 if (lino
== mp
->m_sb
.sb_pquotino
) {
1797 if (*type
!= XR_INO_PQUOTA
) {
1798 do_warn(_("project quota inode %" PRIu64
" has bad type 0x%x\n"),
1799 lino
, dinode_fmt(dinoc
));
1800 mp
->m_sb
.sb_pquotino
= NULLFSINO
;
1805 if (lino
== mp
->m_sb
.sb_rsumino
) {
1806 if (*type
!= XR_INO_RTSUM
) {
1808 _("realtime summary inode %" PRIu64
" has bad type 0x%x, "),
1809 lino
, dinode_fmt(dinoc
));
1811 do_warn(_("resetting to regular file\n"));
1812 change_dinode_fmt(dinoc
, S_IFREG
);
1815 do_warn(_("would reset to regular file\n"));
1818 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1820 _("bad # of extents (%u) for realtime summary inode %" PRIu64
"\n"),
1821 be32_to_cpu(dinoc
->di_nextents
), lino
);
1826 if (lino
== mp
->m_sb
.sb_rbmino
) {
1827 if (*type
!= XR_INO_RTBITMAP
) {
1829 _("realtime bitmap inode %" PRIu64
" has bad type 0x%x, "),
1830 lino
, dinode_fmt(dinoc
));
1832 do_warn(_("resetting to regular file\n"));
1833 change_dinode_fmt(dinoc
, S_IFREG
);
1836 do_warn(_("would reset to regular file\n"));
1839 if (mp
->m_sb
.sb_rblocks
== 0 && dinoc
->di_nextents
!= 0) {
1841 _("bad # of extents (%u) for realtime bitmap inode %" PRIu64
"\n"),
1842 be32_to_cpu(dinoc
->di_nextents
), lino
);
1851 * general size/consistency checks:
1853 * if the size <= size of the data fork, directories must be
1854 * local inodes unlike regular files which would be extent inodes.
1855 * all the other mentioned types have to have a zero size value.
1857 * if the size and format don't match, get out now rather than
1858 * risk trying to process a non-existent extents or btree
1862 process_check_inode_sizes(
1868 xfs_fsize_t size
= be64_to_cpu(dino
->di_size
);
1873 if (size
<= XFS_DFORK_DSIZE(dino
, mp
) &&
1874 dino
->di_format
!= XFS_DINODE_FMT_LOCAL
) {
1876 _("mismatch between format (%d) and size (%" PRId64
") in directory ino %" PRIu64
"\n"),
1877 dino
->di_format
, size
, lino
);
1880 if (size
> XFS_DIR2_LEAF_OFFSET
) {
1882 _("directory inode %" PRIu64
" has bad size %" PRId64
"\n"),
1888 case XR_INO_SYMLINK
:
1889 if (process_symlink_extlist(mp
, lino
, dino
)) {
1890 do_warn(_("bad data fork in symlink %" PRIu64
"\n"), lino
);
1895 case XR_INO_CHRDEV
: /* fall through to FIFO case ... */
1896 case XR_INO_BLKDEV
: /* fall through to FIFO case ... */
1897 case XR_INO_SOCK
: /* fall through to FIFO case ... */
1898 case XR_INO_MOUNTPOINT
: /* fall through to FIFO case ... */
1900 if (process_misc_ino_types(mp
, dino
, lino
, type
))
1907 /* Quota inodes have same restrictions as above types */
1908 if (process_misc_ino_types(mp
, dino
, lino
, type
))
1914 * if we have no realtime blocks, any inode claiming
1915 * to be a real-time file is bogus
1917 if (mp
->m_sb
.sb_rblocks
== 0) {
1919 _("found inode %" PRIu64
" claiming to be a real-time file\n"), lino
);
1924 case XR_INO_RTBITMAP
:
1925 if (size
!= (int64_t)mp
->m_sb
.sb_rbmblocks
*
1926 mp
->m_sb
.sb_blocksize
) {
1928 _("realtime bitmap inode %" PRIu64
" has bad size %" PRId64
" (should be %" PRIu64
")\n"),
1930 (int64_t) mp
->m_sb
.sb_rbmblocks
*
1931 mp
->m_sb
.sb_blocksize
);
1937 if (size
!= mp
->m_rsumsize
) {
1939 _("realtime summary inode %" PRIu64
" has bad size %" PRId64
" (should be %d)\n"),
1940 lino
, size
, mp
->m_rsumsize
);
1952 * check for illegal values of forkoff
1955 process_check_inode_forkoff(
1960 if (dino
->di_forkoff
== 0)
1963 switch (dino
->di_format
) {
1964 case XFS_DINODE_FMT_DEV
:
1965 if (dino
->di_forkoff
!= (roundup(sizeof(xfs_dev_t
), 8) >> 3)) {
1967 _("bad attr fork offset %d in dev inode %" PRIu64
", should be %d\n"),
1968 dino
->di_forkoff
, lino
,
1969 (int)(roundup(sizeof(xfs_dev_t
), 8) >> 3));
1973 case XFS_DINODE_FMT_LOCAL
: /* fall through ... */
1974 case XFS_DINODE_FMT_EXTENTS
: /* fall through ... */
1975 case XFS_DINODE_FMT_BTREE
:
1976 if (dino
->di_forkoff
>=
1977 (XFS_LITINO(mp
, dino
->di_version
) >> 3)) {
1979 _("bad attr fork offset %d in inode %" PRIu64
", max=%d\n"),
1980 dino
->di_forkoff
, lino
,
1981 XFS_LITINO(mp
, dino
->di_version
) >> 3);
1986 do_error(_("unexpected inode format %d\n"), dino
->di_format
);
1993 * Updates the inodes block and extent counts if they are wrong
1996 process_inode_blocks_and_extents(
1998 xfs_rfsblock_t nblocks
,
2004 if (nblocks
!= be64_to_cpu(dino
->di_nblocks
)) {
2007 _("correcting nblocks for inode %" PRIu64
", was %llu - counted %" PRIu64
"\n"), lino
,
2008 (unsigned long long) be64_to_cpu(dino
->di_nblocks
),
2010 dino
->di_nblocks
= cpu_to_be64(nblocks
);
2014 _("bad nblocks %llu for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
2015 (unsigned long long) be64_to_cpu(dino
->di_nblocks
),
2020 if (nextents
> MAXEXTNUM
) {
2022 _("too many data fork extents (%" PRIu64
") in inode %" PRIu64
"\n"),
2026 if (nextents
!= be32_to_cpu(dino
->di_nextents
)) {
2029 _("correcting nextents for inode %" PRIu64
", was %d - counted %" PRIu64
"\n"),
2031 be32_to_cpu(dino
->di_nextents
),
2033 dino
->di_nextents
= cpu_to_be32(nextents
);
2037 _("bad nextents %d for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
2038 be32_to_cpu(dino
->di_nextents
),
2043 if (anextents
> MAXAEXTNUM
) {
2045 _("too many attr fork extents (%" PRIu64
") in inode %" PRIu64
"\n"),
2049 if (anextents
!= be16_to_cpu(dino
->di_anextents
)) {
2052 _("correcting anextents for inode %" PRIu64
", was %d - counted %" PRIu64
"\n"),
2054 be16_to_cpu(dino
->di_anextents
), anextents
);
2055 dino
->di_anextents
= cpu_to_be16(anextents
);
2059 _("bad anextents %d for inode %" PRIu64
", would reset to %" PRIu64
"\n"),
2060 be16_to_cpu(dino
->di_anextents
),
2066 * We are comparing different units here, but that's fine given that
2067 * an extent has to have at least a block in it.
2069 if (nblocks
< nextents
+ anextents
) {
2071 _("nblocks (%" PRIu64
") smaller than nextents for inode %" PRIu64
"\n"), nblocks
, lino
);
2079 * check data fork -- if it's bad, clear the inode
2082 process_inode_data_fork(
2084 xfs_agnumber_t agno
,
2089 xfs_rfsblock_t
*totblocks
,
2094 xfs_ino_t lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2099 * extent count on disk is only valid for positive values. The kernel
2100 * uses negative values in memory. hence if we see negative numbers
2103 nex
= be32_to_cpu(dino
->di_nextents
);
2109 if (*nextents
> be64_to_cpu(dino
->di_nblocks
))
2113 if (dino
->di_format
!= XFS_DINODE_FMT_LOCAL
&& type
!= XR_INO_RTDATA
)
2114 *dblkmap
= blkmap_alloc(*nextents
, XFS_DATA_FORK
);
2117 switch (dino
->di_format
) {
2118 case XFS_DINODE_FMT_LOCAL
:
2119 err
= process_lclinode(mp
, agno
, ino
, dino
, XFS_DATA_FORK
);
2122 case XFS_DINODE_FMT_EXTENTS
:
2123 err
= process_exinode(mp
, agno
, ino
, dino
, type
, dirty
,
2124 totblocks
, nextents
, dblkmap
, XFS_DATA_FORK
,
2127 case XFS_DINODE_FMT_BTREE
:
2128 err
= process_btinode(mp
, agno
, ino
, dino
, type
, dirty
,
2129 totblocks
, nextents
, dblkmap
, XFS_DATA_FORK
,
2132 case XFS_DINODE_FMT_DEV
: /* fall through */
2136 do_error(_("unknown format %d, ino %" PRIu64
" (mode = %d)\n"),
2137 dino
->di_format
, lino
, be16_to_cpu(dino
->di_mode
));
2141 do_warn(_("bad data fork in inode %" PRIu64
"\n"), lino
);
2143 *dirty
+= clear_dinode(mp
, dino
, lino
);
2151 * if check_dups was non-zero, we have to
2152 * re-process data fork to set bitmap since the
2153 * bitmap wasn't set the first time through
2155 switch (dino
->di_format
) {
2156 case XFS_DINODE_FMT_LOCAL
:
2157 err
= process_lclinode(mp
, agno
, ino
, dino
,
2160 case XFS_DINODE_FMT_EXTENTS
:
2161 err
= process_exinode(mp
, agno
, ino
, dino
, type
,
2162 dirty
, totblocks
, nextents
, dblkmap
,
2165 case XFS_DINODE_FMT_BTREE
:
2166 err
= process_btinode(mp
, agno
, ino
, dino
, type
,
2167 dirty
, totblocks
, nextents
, dblkmap
,
2170 case XFS_DINODE_FMT_DEV
: /* fall through */
2174 do_error(_("unknown format %d, ino %" PRIu64
" (mode = %d)\n"),
2175 dino
->di_format
, lino
,
2176 be16_to_cpu(dino
->di_mode
));
2179 if (no_modify
&& err
!= 0)
2188 * Process extended attribute fork in inode
2191 process_inode_attr_fork(
2193 xfs_agnumber_t agno
,
2198 xfs_rfsblock_t
*atotblocks
,
2199 uint64_t *anextents
,
2201 int extra_attr_check
,
2204 xfs_ino_t lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2205 blkmap_t
*ablkmap
= NULL
;
2209 if (!XFS_DFORK_Q(dino
)) {
2211 if (dino
->di_aformat
!= XFS_DINODE_FMT_EXTENTS
) {
2212 do_warn(_("bad attribute format %d in inode %" PRIu64
", "),
2213 dino
->di_aformat
, lino
);
2215 do_warn(_("resetting value\n"));
2216 dino
->di_aformat
= XFS_DINODE_FMT_EXTENTS
;
2219 do_warn(_("would reset value\n"));
2224 *anextents
= be16_to_cpu(dino
->di_anextents
);
2225 if (*anextents
> be64_to_cpu(dino
->di_nblocks
))
2228 switch (dino
->di_aformat
) {
2229 case XFS_DINODE_FMT_LOCAL
:
2232 err
= process_lclinode(mp
, agno
, ino
, dino
, XFS_ATTR_FORK
);
2234 case XFS_DINODE_FMT_EXTENTS
:
2235 ablkmap
= blkmap_alloc(*anextents
, XFS_ATTR_FORK
);
2237 err
= process_exinode(mp
, agno
, ino
, dino
, type
, dirty
,
2238 atotblocks
, anextents
, &ablkmap
,
2239 XFS_ATTR_FORK
, check_dups
);
2241 case XFS_DINODE_FMT_BTREE
:
2242 ablkmap
= blkmap_alloc(*anextents
, XFS_ATTR_FORK
);
2244 err
= process_btinode(mp
, agno
, ino
, dino
, type
, dirty
,
2245 atotblocks
, anextents
, &ablkmap
,
2246 XFS_ATTR_FORK
, check_dups
);
2249 do_warn(_("illegal attribute format %d, ino %" PRIu64
"\n"),
2250 dino
->di_aformat
, lino
);
2257 * clear the attribute fork if necessary. we can't
2258 * clear the inode because we've already put the
2259 * inode space info into the blockmap.
2261 * XXX - put the inode onto the "move it" list and
2262 * log the the attribute scrubbing
2264 do_warn(_("bad attribute fork in inode %" PRIu64
), lino
);
2267 do_warn(_(", clearing attr fork\n"));
2268 *dirty
+= clear_dinode_attr(mp
, dino
, lino
);
2269 dino
->di_aformat
= XFS_DINODE_FMT_LOCAL
;
2272 do_warn(_(", would clear attr fork\n"));
2277 blkmap_free(ablkmap
);
2284 switch (dino
->di_aformat
) {
2285 case XFS_DINODE_FMT_LOCAL
:
2286 err
= process_lclinode(mp
, agno
, ino
, dino
,
2289 case XFS_DINODE_FMT_EXTENTS
:
2290 err
= process_exinode(mp
, agno
, ino
, dino
,
2291 type
, dirty
, atotblocks
, anextents
,
2292 &ablkmap
, XFS_ATTR_FORK
, 0);
2294 case XFS_DINODE_FMT_BTREE
:
2295 err
= process_btinode(mp
, agno
, ino
, dino
,
2296 type
, dirty
, atotblocks
, anextents
,
2297 &ablkmap
, XFS_ATTR_FORK
, 0);
2300 do_error(_("illegal attribute fmt %d, ino %" PRIu64
"\n"),
2301 dino
->di_aformat
, lino
);
2304 if (no_modify
&& err
!= 0) {
2305 blkmap_free(ablkmap
);
2313 * do attribute semantic-based consistency checks now
2316 /* get this only in phase 3, not in both phase 3 and 4 */
2317 if (extra_attr_check
&&
2318 process_attributes(mp
, lino
, dino
, ablkmap
, &repair
)) {
2320 _("problem with attribute contents in inode %" PRIu64
"\n"),
2323 /* clear attributes if not done already */
2325 *dirty
+= clear_dinode_attr(mp
, dino
, lino
);
2326 dino
->di_aformat
= XFS_DINODE_FMT_LOCAL
;
2328 do_warn(_("would clear attr fork\n"));
2334 *dirty
= 1; /* it's been repaired */
2337 blkmap_free(ablkmap
);
2342 * check nlinks feature, if it's a version 1 inode,
2343 * just leave nlinks alone. even if it's set wrong,
2344 * it'll be reset when read in.
2348 process_check_inode_nlink_version(
2355 * if it's a version 2 inode, it should have a zero
2356 * onlink field, so clear it.
2358 if (dino
->di_version
> 1 && dino
->di_onlink
!= 0) {
2361 _("clearing obsolete nlink field in version 2 inode %" PRIu64
", was %d, now 0\n"),
2362 lino
, be16_to_cpu(dino
->di_onlink
));
2363 dino
->di_onlink
= 0;
2367 _("would clear obsolete nlink field in version 2 inode %" PRIu64
", currently %d\n"),
2368 lino
, be16_to_cpu(dino
->di_onlink
));
2374 /* Check nanoseconds of a timestamp don't exceed 1 second. */
2379 struct xfs_timestamp
*t
,
2382 if (be32_to_cpu(t
->t_nsec
) < 1000000000)
2386 _("Bad %s nsec %u on inode %" PRIu64
", "), name
, be32_to_cpu(t
->t_nsec
), lino
);
2388 do_warn(_("would reset to zero\n"));
2390 do_warn(_("resetting to zero\n"));
2397 * returns 0 if the inode is ok, 1 if the inode is corrupt
2398 * check_dups can be set to 1 *only* when called by the
2399 * first pass of the duplicate block checking of phase 4.
2400 * *dirty is set > 0 if the dinode has been altered and
2401 * needs to be written out.
2403 * for detailed, info, look at process_dinode() comments.
2406 process_dinode_int(xfs_mount_t
*mp
,
2408 xfs_agnumber_t agno
,
2410 int was_free
, /* 1 if inode is currently free */
2411 int *dirty
, /* out == > 0 if inode is now dirty */
2412 int *used
, /* out == 1 if inode is in use */
2413 int verify_mode
, /* 1 == verify but don't modify inode */
2414 int uncertain
, /* 1 == inode is uncertain */
2415 int ino_discovery
, /* 1 == check dirs for unknown inodes */
2416 int check_dups
, /* 1 == check if inode claims
2417 * duplicate blocks */
2418 int extra_attr_check
, /* 1 == do attribute format and value checks */
2419 int *isa_dir
, /* out == 1 if inode is a directory */
2420 xfs_ino_t
*parent
) /* out -- parent if ino is a dir */
2422 xfs_rfsblock_t totblocks
= 0;
2423 xfs_rfsblock_t atotblocks
= 0;
2430 const int is_free
= 0;
2431 const int is_used
= 1;
2432 blkmap_t
*dblkmap
= NULL
;
2434 *dirty
= *isa_dir
= 0;
2436 type
= XR_INO_UNKNOWN
;
2438 lino
= XFS_AGINO_TO_INO(mp
, agno
, ino
);
2439 di_mode
= be16_to_cpu(dino
->di_mode
);
2442 * if in verify mode, don't modify the inode.
2444 * if correcting, reset stuff that has known values
2446 * if in uncertain mode, be silent on errors since we're
2447 * trying to find out if these are inodes as opposed
2448 * to assuming that they are. Just return the appropriate
2449 * return code in that case.
2451 * If uncertain is set, verify_mode MUST be set.
2453 ASSERT(uncertain
== 0 || verify_mode
!= 0);
2456 * This is the only valid point to check the CRC; after this we may have
2457 * made changes which invalidate it, and the CRC is only updated again
2458 * when it gets written out.
2460 * Of course if we make any modifications after this, the inode gets
2461 * rewritten, and the CRC is updated automagically.
2463 if (xfs_sb_version_hascrc(&mp
->m_sb
) &&
2464 !libxfs_verify_cksum((char *)dino
, mp
->m_sb
.sb_inodesize
,
2465 XFS_DINODE_CRC_OFF
)) {
2468 do_warn(_("bad CRC for inode %" PRIu64
"%c"),
2469 lino
, verify_mode
? '\n' : ',');
2472 do_warn(_(" will rewrite\n"));
2475 do_warn(_(" would rewrite\n"));
2479 if (be16_to_cpu(dino
->di_magic
) != XFS_DINODE_MAGIC
) {
2482 do_warn(_("bad magic number 0x%x on inode %" PRIu64
"%c"),
2483 be16_to_cpu(dino
->di_magic
), lino
,
2484 verify_mode
? '\n' : ',');
2487 do_warn(_(" resetting magic number\n"));
2488 dino
->di_magic
= cpu_to_be16(XFS_DINODE_MAGIC
);
2491 do_warn(_(" would reset magic number\n"));
2495 if (!libxfs_dinode_good_version(mp
, dino
->di_version
)) {
2498 do_warn(_("bad version number 0x%x on inode %" PRIu64
"%c"),
2499 (__s8
)dino
->di_version
, lino
,
2500 verify_mode
? '\n' : ',');
2503 do_warn(_(" resetting version number\n"));
2505 xfs_sb_version_hascrc(&mp
->m_sb
) ? 3 : 2;
2508 do_warn(_(" would reset version number\n"));
2513 * We don't bother checking the CRC here - we cannot guarantee that when
2514 * we are called here that the inode has not already been modified in
2515 * memory and hence invalidated the CRC.
2517 if (xfs_sb_version_hascrc(&mp
->m_sb
)) {
2518 if (be64_to_cpu(dino
->di_ino
) != lino
) {
2521 _("inode identifier %llu mismatch on inode %" PRIu64
"\n"),
2522 (unsigned long long)be64_to_cpu(dino
->di_ino
),
2528 if (platform_uuid_compare(&dino
->di_uuid
,
2529 &mp
->m_sb
.sb_meta_uuid
)) {
2532 _("UUID mismatch on inode %" PRIu64
"\n"), lino
);
2540 * blow out of here if the inode size is < 0
2542 if ((xfs_fsize_t
)be64_to_cpu(dino
->di_size
) < 0) {
2545 _("bad (negative) size %" PRId64
" on inode %" PRIu64
"\n"),
2546 (int64_t)be64_to_cpu(dino
->di_size
),
2554 * if not in verify mode, check to sii if the inode and imap
2555 * agree that the inode is free
2557 if (!verify_mode
&& di_mode
== 0) {
2559 * was_free value is not meaningful if we're in verify mode
2563 * easy case, inode free -- inode and map agree, clear
2564 * it just in case to ensure that format, etc. are
2568 *dirty
+= clear_dinode(mp
, dino
, lino
);
2573 * the inode looks free but the map says it's in use.
2574 * clear the inode just to be safe and mark the inode
2578 _("imap claims a free inode %" PRIu64
" is in use, "), lino
);
2580 do_warn(_("correcting imap and clearing inode\n"));
2581 *dirty
+= clear_dinode(mp
, dino
, lino
);
2584 do_warn(_("would correct imap and clear inode\n"));
2590 * because of the lack of any write ordering guarantee, it's
2591 * possible that the core got updated but the forks didn't.
2592 * so rather than be ambitious (and probably incorrect),
2593 * if there's an inconsistency, we get conservative and
2594 * just pitch the file. blow off checking formats of
2595 * free inodes since technically any format is legal
2596 * as we reset the inode when we re-use it.
2598 if (di_mode
!= 0 && check_dinode_mode_format(dino
) != 0) {
2601 _("bad inode format in inode %" PRIu64
"\n"), lino
);
2608 * check that we only have valid flags set, and those that are set make
2611 if (dino
->di_flags
) {
2612 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2614 if (flags
& ~XFS_DIFLAG_ANY
) {
2617 _("Bad flags set in inode %" PRIu64
"\n"),
2620 flags
&= XFS_DIFLAG_ANY
;
2623 if (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
)) {
2624 /* need an rt-dev! */
2628 _("inode %" PRIu64
" has RT flag set but there is no RT device\n"),
2631 flags
&= ~(XFS_DIFLAG_REALTIME
|
2632 XFS_DIFLAG_RTINHERIT
);
2635 if (flags
& XFS_DIFLAG_NEWRTBM
) {
2636 /* must be a rt bitmap inode */
2637 if (lino
!= mp
->m_sb
.sb_rbmino
) {
2640 _("inode %" PRIu64
" not rt bitmap\n"),
2643 flags
&= ~XFS_DIFLAG_NEWRTBM
;
2646 if (flags
& (XFS_DIFLAG_RTINHERIT
|
2647 XFS_DIFLAG_EXTSZINHERIT
|
2648 XFS_DIFLAG_PROJINHERIT
|
2649 XFS_DIFLAG_NOSYMLINKS
)) {
2650 /* must be a directory */
2651 if (di_mode
&& !S_ISDIR(di_mode
)) {
2654 _("directory flags set on non-directory inode %" PRIu64
"\n" ),
2657 flags
&= ~(XFS_DIFLAG_RTINHERIT
|
2658 XFS_DIFLAG_EXTSZINHERIT
|
2659 XFS_DIFLAG_PROJINHERIT
|
2660 XFS_DIFLAG_NOSYMLINKS
);
2663 if (flags
& (XFS_DIFLAG_REALTIME
| FS_XFLAG_EXTSIZE
)) {
2664 /* must be a file */
2665 if (di_mode
&& !S_ISREG(di_mode
)) {
2668 _("file flags set on non-file inode %" PRIu64
"\n"),
2671 flags
&= ~(XFS_DIFLAG_REALTIME
|
2675 if (!verify_mode
&& flags
!= be16_to_cpu(dino
->di_flags
)) {
2677 do_warn(_("fixing bad flags.\n"));
2678 dino
->di_flags
= cpu_to_be16(flags
);
2681 do_warn(_("would fix bad flags.\n"));
2686 * check that we only have valid flags2 set, and those that are set make
2689 if (dino
->di_version
>= 3) {
2690 uint16_t flags
= be16_to_cpu(dino
->di_flags
);
2691 uint64_t flags2
= be64_to_cpu(dino
->di_flags2
);
2693 if (flags2
& ~XFS_DIFLAG2_ANY
) {
2696 _("Bad flags2 set in inode %" PRIu64
"\n"),
2699 flags2
&= XFS_DIFLAG2_ANY
;
2702 if (flags2
& XFS_DIFLAG2_DAX
) {
2703 /* must be a file or dir */
2704 if (di_mode
&& !(S_ISREG(di_mode
) || S_ISDIR(di_mode
))) {
2707 _("DAX flag set on special inode %" PRIu64
"\n"),
2710 flags2
&= ~XFS_DIFLAG2_DAX
;
2714 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2715 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2718 _("inode %" PRIu64
" is marked reflinked but file system does not support reflink\n"),
2724 if (flags2
& XFS_DIFLAG2_REFLINK
) {
2725 /* must be a file */
2726 if (di_mode
&& !S_ISREG(di_mode
)) {
2729 _("reflink flag set on non-file inode %" PRIu64
"\n"),
2736 if ((flags2
& XFS_DIFLAG2_REFLINK
) &&
2737 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2740 _("Cannot have a reflinked realtime inode %" PRIu64
"\n"),
2746 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2747 !xfs_sb_version_hasreflink(&mp
->m_sb
)) {
2750 _("inode %" PRIu64
" has CoW extent size hint but file system does not support reflink\n"),
2753 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2756 if (flags2
& XFS_DIFLAG2_COWEXTSIZE
) {
2757 /* must be a directory or file */
2758 if (di_mode
&& !S_ISDIR(di_mode
) && !S_ISREG(di_mode
)) {
2761 _("CoW extent size flag set on non-file, non-directory inode %" PRIu64
"\n" ),
2764 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2768 if ((flags2
& XFS_DIFLAG2_COWEXTSIZE
) &&
2769 (flags
& (XFS_DIFLAG_REALTIME
| XFS_DIFLAG_RTINHERIT
))) {
2772 _("Cannot have CoW extent size hint on a realtime inode %" PRIu64
"\n"),
2775 flags2
&= ~XFS_DIFLAG2_COWEXTSIZE
;
2778 if (!verify_mode
&& flags2
!= be64_to_cpu(dino
->di_flags2
)) {
2780 do_warn(_("fixing bad flags2.\n"));
2781 dino
->di_flags2
= cpu_to_be64(flags2
);
2784 do_warn(_("would fix bad flags2.\n"));
2792 * clear the next unlinked field if necessary on a good
2793 * inode only during phase 4 -- when checking for inodes
2794 * referencing duplicate blocks. then it's safe because
2795 * we've done the inode discovery and have found all the inodes
2796 * we're going to find. check_dups is set to 1 only during
2799 if (check_dups
&& !no_modify
)
2800 *dirty
+= clear_dinode_unlinked(mp
, dino
);
2802 /* set type and map type info */
2804 switch (di_mode
& S_IFMT
) {
2810 if (be16_to_cpu(dino
->di_flags
) & XFS_DIFLAG_REALTIME
)
2811 type
= XR_INO_RTDATA
;
2812 else if (lino
== mp
->m_sb
.sb_rbmino
)
2813 type
= XR_INO_RTBITMAP
;
2814 else if (lino
== mp
->m_sb
.sb_rsumino
)
2815 type
= XR_INO_RTSUM
;
2816 else if (lino
== mp
->m_sb
.sb_uquotino
)
2817 type
= XR_INO_UQUOTA
;
2818 else if (lino
== mp
->m_sb
.sb_gquotino
)
2819 type
= XR_INO_GQUOTA
;
2820 else if (lino
== mp
->m_sb
.sb_pquotino
)
2821 type
= XR_INO_PQUOTA
;
2826 type
= XR_INO_SYMLINK
;
2829 type
= XR_INO_CHRDEV
;
2832 type
= XR_INO_BLKDEV
;
2841 do_warn(_("bad inode type %#o inode %" PRIu64
"\n"),
2842 di_mode
& S_IFMT
, lino
);
2847 * type checks for superblock inodes
2849 if (process_check_sb_inodes(mp
, dino
, lino
, &type
, dirty
) != 0)
2853 * only regular files with REALTIME or EXTSIZE flags set can have
2854 * extsize set, or directories with EXTSZINHERIT.
2856 if (be32_to_cpu(dino
->di_extsize
) != 0) {
2857 if ((type
== XR_INO_RTDATA
) ||
2858 (type
== XR_INO_DIR
&& (be16_to_cpu(dino
->di_flags
) &
2859 XFS_DIFLAG_EXTSZINHERIT
)) ||
2860 (type
== XR_INO_DATA
&& (be16_to_cpu(dino
->di_flags
) &
2861 XFS_DIFLAG_EXTSIZE
))) {
2865 _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64
", "),
2866 be32_to_cpu(dino
->di_extsize
), lino
);
2868 do_warn(_("resetting to zero\n"));
2869 dino
->di_extsize
= 0;
2872 do_warn(_("would reset to zero\n"));
2877 * Only (regular files and directories) with COWEXTSIZE flags
2878 * set can have extsize set.
2880 if (dino
->di_version
>= 3 &&
2881 be32_to_cpu(dino
->di_cowextsize
) != 0) {
2882 if ((type
== XR_INO_DIR
|| type
== XR_INO_DATA
) &&
2883 (be64_to_cpu(dino
->di_flags2
) &
2884 XFS_DIFLAG2_COWEXTSIZE
)) {
2888 _("Cannot have non-zero CoW extent size %u on non-cowextsize inode %" PRIu64
", "),
2889 be32_to_cpu(dino
->di_cowextsize
), lino
);
2891 do_warn(_("resetting to zero\n"));
2892 dino
->di_flags2
&= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE
);
2893 dino
->di_cowextsize
= 0;
2896 do_warn(_("would reset to zero\n"));
2901 * Can't have the COWEXTSIZE flag set with no hint.
2903 if (dino
->di_version
>= 3 &&
2904 be32_to_cpu(dino
->di_cowextsize
) == 0 &&
2905 (be64_to_cpu(dino
->di_flags2
) & XFS_DIFLAG2_COWEXTSIZE
)) {
2907 _("Cannot have CoW extent size of zero on cowextsize inode %" PRIu64
", "),
2910 do_warn(_("clearing cowextsize flag\n"));
2911 dino
->di_flags2
&= ~cpu_to_be64(XFS_DIFLAG2_COWEXTSIZE
);
2914 do_warn(_("would clear cowextsize flag\n"));
2918 /* nsec fields cannot be larger than 1 billion */
2919 check_nsec("atime", lino
, &dino
->di_atime
, dirty
);
2920 check_nsec("mtime", lino
, &dino
->di_mtime
, dirty
);
2921 check_nsec("ctime", lino
, &dino
->di_ctime
, dirty
);
2922 if (dino
->di_version
>= 3)
2923 check_nsec("crtime", lino
, &dino
->di_crtime
, dirty
);
2926 * general size/consistency checks:
2928 if (process_check_inode_sizes(mp
, dino
, lino
, type
) != 0)
2932 * check for illegal values of forkoff
2934 if (process_check_inode_forkoff(mp
, dino
, lino
) != 0)
2938 * record the state of the reflink flag
2941 record_inode_reflink_flag(mp
, dino
, agno
, ino
, lino
);
2944 * check data fork -- if it's bad, clear the inode
2946 if (process_inode_data_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2947 &totblocks
, &nextents
, &dblkmap
, check_dups
) != 0)
2951 * check attribute fork if necessary. attributes are
2952 * always stored in the regular filesystem.
2954 if (process_inode_attr_fork(mp
, agno
, ino
, dino
, type
, dirty
,
2955 &atotblocks
, &anextents
, check_dups
, extra_attr_check
,
2960 * enforce totblocks is 0 for misc types
2962 if (process_misc_ino_types_blocks(totblocks
, lino
, type
))
2966 * correct space counters if required
2968 if (process_inode_blocks_and_extents(dino
, totblocks
+ atotblocks
,
2969 nextents
, anextents
, lino
, dirty
) != 0)
2973 * do any semantic type-based checking here
2977 if (process_dir2(mp
, lino
, dino
, ino_discovery
,
2978 dirty
, "", parent
, dblkmap
)) {
2980 _("problem with directory contents in inode %" PRIu64
"\n"),
2985 case XR_INO_SYMLINK
:
2986 if (process_symlink(mp
, lino
, dino
, dblkmap
) != 0) {
2988 _("problem with symbolic link in inode %" PRIu64
"\n"),
2996 if (process_quota_inode(mp
, lino
, dino
, type
, dblkmap
) != 0) {
2998 _("problem with quota inode %" PRIu64
"\n"), lino
);
3006 blkmap_free(dblkmap
);
3009 * check nlinks feature, if it's a version 1 inode,
3010 * just leave nlinks alone. even if it's set wrong,
3011 * it'll be reset when read in.
3013 *dirty
+= process_check_inode_nlink_version(dino
, lino
);
3019 *dirty
+= clear_dinode(mp
, dino
, lino
);
3025 blkmap_free(dblkmap
);
3030 * returns 1 if inode is used, 0 if free.
3031 * performs any necessary salvaging actions.
3032 * note that we leave the generation count alone
3033 * because nothing we could set it to would be
3034 * guaranteed to be correct so the best guess for
3035 * the correct value is just to leave it alone.
3037 * The trick is detecting empty files. For those,
3038 * the core and the forks should all be in the "empty"
3039 * or zero-length state -- a zero or possibly minimum length
3040 * (in the case of dirs) extent list -- although inline directories
3041 * and symlinks might be handled differently. So it should be
3042 * possible to sanity check them against each other.
3044 * If the forks are an empty extent list though, then forget it.
3045 * The file is toast anyway since we can't recover its storage.
3049 * mp -- mount structure
3050 * dino -- pointer to on-disk inode structure
3051 * agno/ino -- inode numbers
3052 * free -- whether the map thinks the inode is free (1 == free)
3053 * ino_discovery -- whether we should examine directory
3054 * contents to discover new inodes
3055 * check_dups -- whether we should check to see if the
3056 * inode references duplicate blocks
3057 * if so, we compare the inode's claimed
3058 * blocks against the contents of the
3059 * duplicate extent list but we don't
3060 * set the bitmap. If not, we set the
3061 * bitmap and try and detect multiply
3062 * claimed blocks using the bitmap.
3064 * dirty -- whether we changed the inode (1 == yes)
3065 * used -- 1 if the inode is used, 0 if free. In no modify
3066 * mode, whether the inode should be used or free
3067 * isa_dir -- 1 if the inode is a directory, 0 if not. In
3068 * no modify mode, if the inode would be a dir or not.
3070 * Return value -- 0 if the inode is good, 1 if it is/was corrupt
3077 xfs_agnumber_t agno
,
3084 int extra_attr_check
,
3088 const int verify_mode
= 0;
3089 const int uncertain
= 0;
3091 #ifdef XR_INODE_TRACE
3092 fprintf(stderr
, _("processing inode %d/%d\n"), agno
, ino
);
3094 return process_dinode_int(mp
, dino
, agno
, ino
, was_free
, dirty
, used
,
3095 verify_mode
, uncertain
, ino_discovery
,
3096 check_dups
, extra_attr_check
, isa_dir
, parent
);
3100 * a more cursory check, check inode core, *DON'T* check forks
3101 * this basically just verifies whether the inode is an inode
3102 * and whether or not it has been totally trashed. returns 0
3103 * if the inode passes the cursory sanity check, 1 otherwise.
3109 xfs_agnumber_t agno
,
3116 const int verify_mode
= 1;
3117 const int check_dups
= 0;
3118 const int ino_discovery
= 0;
3119 const int uncertain
= 0;
3121 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
3122 verify_mode
, uncertain
, ino_discovery
,
3123 check_dups
, 0, &isa_dir
, &parent
);
3127 * like above only for inode on the uncertain list. it sets
3128 * the uncertain flag which makes process_dinode_int quieter.
3129 * returns 0 if the inode passes the cursory sanity check, 1 otherwise.
3132 verify_uncertain_dinode(
3135 xfs_agnumber_t agno
,
3142 const int verify_mode
= 1;
3143 const int check_dups
= 0;
3144 const int ino_discovery
= 0;
3145 const int uncertain
= 1;
3147 return process_dinode_int(mp
, dino
, agno
, ino
, 0, &dirty
, &used
,
3148 verify_mode
, uncertain
, ino_discovery
,
3149 check_dups
, 0, &isa_dir
, &parent
);