]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - repair/dinode.c
xfs_repair: fix naming problems in repair/rmap.c
[thirdparty/xfsprogs-dev.git] / repair / dinode.c
1 /*
2 * Copyright (c) 2000-2005 Silicon Graphics, Inc.
3 * All Rights Reserved.
4 *
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.
8 *
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.
13 *
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
17 */
18
19 #include "libxfs.h"
20 #include "avl.h"
21 #include "globals.h"
22 #include "agheader.h"
23 #include "incore.h"
24 #include "protos.h"
25 #include "err_protos.h"
26 #include "dir2.h"
27 #include "dinode.h"
28 #include "scan.h"
29 #include "versions.h"
30 #include "attr_repair.h"
31 #include "bmap.h"
32 #include "threads.h"
33 #include "slab.h"
34 #include "rmap.h"
35
36 /*
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
42 * once.
43 */
44 static char *forkname_data;
45 static char *forkname_attr;
46 static char *ftype_real_time;
47 static char *ftype_regular;
48
49 void
50 dinode_bmbt_translation_init(void)
51 {
52 forkname_data = _("data");
53 forkname_attr = _("attr");
54 ftype_real_time = _("real-time");
55 ftype_regular = _("regular");
56 }
57
58 char *
59 get_forkname(int whichfork)
60 {
61
62 if (whichfork == XFS_DATA_FORK)
63 return forkname_data;
64 return forkname_attr;
65 }
66
67 /*
68 * inode clearing routines
69 */
70
71 static int
72 clear_dinode_attr(xfs_mount_t *mp, xfs_dinode_t *dino, xfs_ino_t ino_num)
73 {
74 ASSERT(dino->di_forkoff != 0);
75
76 if (!no_modify)
77 fprintf(stderr,
78 _("clearing inode %" PRIu64 " attributes\n"), ino_num);
79 else
80 fprintf(stderr,
81 _("would have cleared inode %" PRIu64 " attributes\n"), ino_num);
82
83 if (be16_to_cpu(dino->di_anextents) != 0) {
84 if (no_modify)
85 return(1);
86 dino->di_anextents = cpu_to_be16(0);
87 }
88
89 if (dino->di_aformat != XFS_DINODE_FMT_EXTENTS) {
90 if (no_modify)
91 return(1);
92 dino->di_aformat = XFS_DINODE_FMT_EXTENTS;
93 }
94
95 /* get rid of the fork by clearing forkoff */
96
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.
104 */
105
106 if (!no_modify) {
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));
110 asf->hdr.count = 0;
111 dino->di_forkoff = 0; /* got to do this after asf is set */
112 }
113
114 /*
115 * always returns 1 since the fork gets zapped
116 */
117 return(1);
118 }
119
120 static int
121 clear_dinode_core(struct xfs_mount *mp, xfs_dinode_t *dinoc, xfs_ino_t ino_num)
122 {
123 int dirty = 0;
124 int i;
125
126 #define __dirty_no_modify_ret(dirty) \
127 ({ (dirty) = 1; if (no_modify) return 1; })
128
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);
132 }
133
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;
138 else
139 dinoc->di_version = 2;
140 }
141
142 if (be16_to_cpu(dinoc->di_mode) != 0) {
143 __dirty_no_modify_ret(dirty);
144 dinoc->di_mode = 0;
145 }
146
147 if (be16_to_cpu(dinoc->di_flags) != 0) {
148 __dirty_no_modify_ret(dirty);
149 dinoc->di_flags = 0;
150 }
151
152 if (be32_to_cpu(dinoc->di_dmevmask) != 0) {
153 __dirty_no_modify_ret(dirty);
154 dinoc->di_dmevmask = 0;
155 }
156
157 if (dinoc->di_forkoff != 0) {
158 __dirty_no_modify_ret(dirty);
159 dinoc->di_forkoff = 0;
160 }
161
162 if (dinoc->di_format != XFS_DINODE_FMT_EXTENTS) {
163 __dirty_no_modify_ret(dirty);
164 dinoc->di_format = XFS_DINODE_FMT_EXTENTS;
165 }
166
167 if (dinoc->di_aformat != XFS_DINODE_FMT_EXTENTS) {
168 __dirty_no_modify_ret(dirty);
169 dinoc->di_aformat = XFS_DINODE_FMT_EXTENTS;
170 }
171
172 if (be64_to_cpu(dinoc->di_size) != 0) {
173 __dirty_no_modify_ret(dirty);
174 dinoc->di_size = 0;
175 }
176
177 if (be64_to_cpu(dinoc->di_nblocks) != 0) {
178 __dirty_no_modify_ret(dirty);
179 dinoc->di_nblocks = 0;
180 }
181
182 if (be16_to_cpu(dinoc->di_onlink) != 0) {
183 __dirty_no_modify_ret(dirty);
184 dinoc->di_onlink = 0;
185 }
186
187 if (be32_to_cpu(dinoc->di_nextents) != 0) {
188 __dirty_no_modify_ret(dirty);
189 dinoc->di_nextents = 0;
190 }
191
192 if (be16_to_cpu(dinoc->di_anextents) != 0) {
193 __dirty_no_modify_ret(dirty);
194 dinoc->di_anextents = 0;
195 }
196
197 if (dinoc->di_version > 1 &&
198 be32_to_cpu(dinoc->di_nlink) != 0) {
199 __dirty_no_modify_ret(dirty);
200 dinoc->di_nlink = 0;
201 }
202
203 /* we are done for version 1/2 inodes */
204 if (dinoc->di_version < 3)
205 return dirty;
206
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);
210 }
211
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);
215 }
216
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));
221 break;
222 }
223 }
224
225 if (be64_to_cpu(dinoc->di_flags2) != 0) {
226 __dirty_no_modify_ret(dirty);
227 dinoc->di_flags2 = 0;
228 }
229
230 if (be64_to_cpu(dinoc->di_lsn) != 0) {
231 __dirty_no_modify_ret(dirty);
232 dinoc->di_lsn = 0;
233 }
234
235 if (be64_to_cpu(dinoc->di_changecount) != 0) {
236 __dirty_no_modify_ret(dirty);
237 dinoc->di_changecount = 0;
238 }
239
240 return dirty;
241 }
242
243 static int
244 clear_dinode_unlinked(xfs_mount_t *mp, xfs_dinode_t *dino)
245 {
246
247 if (be32_to_cpu(dino->di_next_unlinked) != NULLAGINO) {
248 if (!no_modify)
249 dino->di_next_unlinked = cpu_to_be32(NULLAGINO);
250 return(1);
251 }
252
253 return(0);
254 }
255
256 /*
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
260 */
261 static int
262 clear_dinode(xfs_mount_t *mp, xfs_dinode_t *dino, xfs_ino_t ino_num)
263 {
264 int dirty;
265
266 dirty = clear_dinode_core(mp, dino, ino_num);
267 dirty += clear_dinode_unlinked(mp, dino);
268
269 /* and clear the forks */
270
271 if (dirty && !no_modify)
272 memset(XFS_DFORK_DPTR(dino), 0,
273 XFS_LITINO(mp, dino->di_version));
274
275 return(dirty);
276 }
277
278
279 /*
280 * misc. inode-related utility routines
281 */
282
283 /*
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.
287 */
288 static __inline int
289 verify_ag_bno(xfs_sb_t *sbp,
290 xfs_agnumber_t agno,
291 xfs_agblock_t agbno)
292 {
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) *
298 sbp->sb_agblocks)));
299 return 1;
300 }
301
302 /*
303 * returns 0 if inode number is valid, 1 if bogus
304 */
305 int
306 verify_inum(xfs_mount_t *mp,
307 xfs_ino_t ino)
308 {
309 xfs_agnumber_t agno;
310 xfs_agino_t agino;
311 xfs_agblock_t agbno;
312 xfs_sb_t *sbp = &mp->m_sb;;
313
314 /* range check ag #, ag block. range-checking offset is pointless */
315
316 agno = XFS_INO_TO_AGNO(mp, ino);
317 agino = XFS_INO_TO_AGINO(mp, ino);
318 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
319 if (agbno == 0)
320 return 1;
321
322 if (ino == 0 || ino == NULLFSINO)
323 return(1);
324
325 if (ino != XFS_AGINO_TO_INO(mp, agno, agino))
326 return(1);
327
328 return verify_ag_bno(sbp, agno, agbno);
329 }
330
331 /*
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
335 */
336 int
337 verify_aginum(xfs_mount_t *mp,
338 xfs_agnumber_t agno,
339 xfs_agino_t agino)
340 {
341 xfs_agblock_t agbno;
342 xfs_sb_t *sbp = &mp->m_sb;;
343
344 /* range check ag #, ag block. range-checking offset is pointless */
345
346 if (agino == 0 || agino == NULLAGINO)
347 return(1);
348
349 /*
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.
355 */
356 agbno = XFS_AGINO_TO_AGBNO(mp, agino);
357 if (agbno == 0)
358 return 1;
359
360 return verify_ag_bno(sbp, agno, agbno);
361 }
362
363 /*
364 * return 1 if block number is good, 0 if out of range
365 */
366 int
367 verify_dfsbno(xfs_mount_t *mp,
368 xfs_fsblock_t fsbno)
369 {
370 xfs_agnumber_t agno;
371 xfs_agblock_t agbno;
372 xfs_sb_t *sbp = &mp->m_sb;;
373
374 /* range check ag #, ag block. range-checking offset is pointless */
375
376 agno = XFS_FSB_TO_AGNO(mp, fsbno);
377 agbno = XFS_FSB_TO_AGBNO(mp, fsbno);
378
379 return verify_ag_bno(sbp, agno, agbno) == 0;
380 }
381
382 #define XR_DFSBNORANGE_VALID 0
383 #define XR_DFSBNORANGE_BADSTART 1
384 #define XR_DFSBNORANGE_BADEND 2
385 #define XR_DFSBNORANGE_OVERFLOW 3
386
387 static __inline int
388 verify_dfsbno_range(xfs_mount_t *mp,
389 xfs_fsblock_t fsbno,
390 xfs_filblks_t count)
391 {
392 xfs_agnumber_t agno;
393 xfs_agblock_t agbno;
394 xfs_sb_t *sbp = &mp->m_sb;;
395
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;
400 }
401
402 agbno = XFS_FSB_TO_AGBNO(mp, fsbno);
403 if (verify_ag_bno(sbp, agno, agbno)) {
404 return XR_DFSBNORANGE_BADSTART;
405 }
406
407 agbno = XFS_FSB_TO_AGBNO(mp, fsbno + count - 1);
408 if (verify_ag_bno(sbp, agno, agbno)) {
409 return XR_DFSBNORANGE_BADEND;
410 }
411
412 return (XR_DFSBNORANGE_VALID);
413 }
414
415 int
416 verify_agbno(xfs_mount_t *mp,
417 xfs_agnumber_t agno,
418 xfs_agblock_t agbno)
419 {
420 xfs_sb_t *sbp = &mp->m_sb;;
421
422 /* range check ag #, ag block. range-checking offset is pointless */
423 return verify_ag_bno(sbp, agno, agbno) == 0;
424 }
425
426 static int
427 process_rt_rec(
428 xfs_mount_t *mp,
429 xfs_bmbt_irec_t *irec,
430 xfs_ino_t ino,
431 xfs_rfsblock_t *tot,
432 int check_dups)
433 {
434 xfs_fsblock_t b;
435 xfs_rtblock_t ext;
436 int state;
437 int pwe; /* partially-written extent */
438
439 /*
440 * check numeric validity of the extent
441 */
442 if (irec->br_startblock >= mp->m_sb.sb_rblocks) {
443 do_warn(
444 _("inode %" PRIu64 " - bad rt extent start block number %" PRIu64 ", offset %" PRIu64 "\n"),
445 ino,
446 irec->br_startblock,
447 irec->br_startoff);
448 return 1;
449 }
450 if (irec->br_startblock + irec->br_blockcount - 1 >= mp->m_sb.sb_rblocks) {
451 do_warn(
452 _("inode %" PRIu64 " - bad rt extent last block number %" PRIu64 ", offset %" PRIu64 "\n"),
453 ino,
454 irec->br_startblock + irec->br_blockcount - 1,
455 irec->br_startoff);
456 return 1;
457 }
458 if (irec->br_startblock + irec->br_blockcount - 1 < irec->br_startblock) {
459 do_warn(
460 _("inode %" PRIu64 " - bad rt extent overflows - start %" PRIu64 ", "
461 "end %" PRIu64 ", offset %" PRIu64 "\n"),
462 ino,
463 irec->br_startblock,
464 irec->br_startblock + irec->br_blockcount - 1,
465 irec->br_startoff);
466 return 1;
467 }
468
469 /*
470 * verify that the blocks listed in the record
471 * are multiples of an extent
472 */
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)) {
476 do_warn(
477 _("malformed rt inode extent [%" PRIu64 " %" PRIu64 "] (fs rtext size = %u)\n"),
478 irec->br_startblock,
479 irec->br_blockcount,
480 mp->m_sb.sb_rextsize);
481 return 1;
482 }
483
484 /*
485 * set the appropriate number of extents
486 * this iterates block by block, this can be optimised using extents
487 */
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);
494
495 if (check_dups == 1) {
496 if (search_rt_dup_extent(mp, ext) && !pwe) {
497 do_warn(
498 _("data fork in rt ino %" PRIu64 " claims dup rt extent,"
499 "off - %" PRIu64 ", start - %" PRIu64 ", count %" PRIu64 "\n"),
500 ino,
501 irec->br_startoff,
502 irec->br_startblock,
503 irec->br_blockcount);
504 return 1;
505 }
506 continue;
507 }
508
509 state = get_rtbmap(ext);
510 switch (state) {
511 case XR_E_FREE:
512 case XR_E_UNKNOWN:
513 set_rtbmap(ext, XR_E_INUSE);
514 break;
515 case XR_E_BAD_STATE:
516 do_error(
517 _("bad state in rt block map %" PRIu64 "\n"),
518 ext);
519 case XR_E_FS_MAP:
520 case XR_E_INO:
521 case XR_E_INUSE_FS:
522 do_error(
523 _("data fork in rt inode %" PRIu64 " found metadata block %" PRIu64 " in rt bmap\n"),
524 ino, ext);
525 case XR_E_INUSE:
526 if (pwe)
527 break;
528 case XR_E_MULT:
529 set_rtbmap(ext, XR_E_MULT);
530 do_warn(
531 _("data fork in rt inode %" PRIu64 " claims used rt block %" PRIu64 "\n"),
532 ino, ext);
533 return 1;
534 case XR_E_FREE1:
535 default:
536 do_error(
537 _("illegal state %d in rt block map %" PRIu64 "\n"),
538 state, b);
539 }
540 }
541
542 /*
543 * bump up the block counter
544 */
545 *tot += irec->br_blockcount;
546
547 return 0;
548 }
549
550 /*
551 * return 1 if inode should be cleared, 0 otherwise
552 * if check_dups should be set to 1, that implies that
553 * the primary purpose of this call is to see if the
554 * file overlaps with any duplicate extents (in the
555 * duplicate extent list).
556 */
557 static int
558 process_bmbt_reclist_int(
559 xfs_mount_t *mp,
560 xfs_bmbt_rec_t *rp,
561 int *numrecs,
562 int type,
563 xfs_ino_t ino,
564 xfs_rfsblock_t *tot,
565 blkmap_t **blkmapp,
566 xfs_fileoff_t *first_key,
567 xfs_fileoff_t *last_key,
568 int check_dups,
569 int whichfork)
570 {
571 xfs_bmbt_irec_t irec;
572 xfs_filblks_t cp = 0; /* prev count */
573 xfs_fsblock_t sp = 0; /* prev start */
574 xfs_fileoff_t op = 0; /* prev offset */
575 xfs_fsblock_t b;
576 char *ftype;
577 char *forkname = get_forkname(whichfork);
578 int i;
579 int state;
580 xfs_agnumber_t agno;
581 xfs_agblock_t agbno;
582 xfs_agblock_t ebno;
583 xfs_extlen_t blen;
584 xfs_agnumber_t locked_agno = -1;
585 int error = 1;
586
587 if (type == XR_INO_RTDATA)
588 ftype = ftype_real_time;
589 else
590 ftype = ftype_regular;
591
592 for (i = 0; i < *numrecs; i++) {
593 libxfs_bmbt_disk_get_all((rp +i), &irec);
594 if (i == 0)
595 *last_key = *first_key = irec.br_startoff;
596 else
597 *last_key = irec.br_startoff;
598 if (i > 0 && op + cp > irec.br_startoff) {
599 do_warn(
600 _("bmap rec out of order, inode %" PRIu64" entry %d "
601 "[o s c] [%" PRIu64 " %" PRIu64 " %" PRIu64 "], "
602 "%d [%" PRIu64 " %" PRIu64 " %" PRIu64 "]\n"),
603 ino, i, irec.br_startoff, irec.br_startblock,
604 irec.br_blockcount, i - 1, op, sp, cp);
605 goto done;
606 }
607 op = irec.br_startoff;
608 cp = irec.br_blockcount;
609 sp = irec.br_startblock;
610
611 /*
612 * check numeric validity of the extent
613 */
614 if (irec.br_blockcount == 0) {
615 do_warn(
616 _("zero length extent (off = %" PRIu64 ", fsbno = %" PRIu64 ") in ino %" PRIu64 "\n"),
617 irec.br_startoff,
618 irec.br_startblock,
619 ino);
620 goto done;
621 }
622
623 if (type == XR_INO_RTDATA && whichfork == XFS_DATA_FORK) {
624 /*
625 * realtime bitmaps don't use AG locks, so returning
626 * immediately is fine for this code path.
627 */
628 if (process_rt_rec(mp, &irec, ino, tot, check_dups))
629 return 1;
630 /*
631 * skip rest of loop processing since that'irec.br_startblock
632 * all for regular file forks and attr forks
633 */
634 continue;
635 }
636
637 /*
638 * regular file data fork or attribute fork
639 */
640 switch (verify_dfsbno_range(mp, irec.br_startblock,
641 irec.br_blockcount)) {
642 case XR_DFSBNORANGE_VALID:
643 break;
644
645 case XR_DFSBNORANGE_BADSTART:
646 do_warn(
647 _("inode %" PRIu64 " - bad extent starting block number %" PRIu64 ", offset %" PRIu64 "\n"),
648 ino,
649 irec.br_startblock,
650 irec.br_startoff);
651 goto done;
652
653 case XR_DFSBNORANGE_BADEND:
654 do_warn(
655 _("inode %" PRIu64 " - bad extent last block number %" PRIu64 ", offset %" PRIu64 "\n"),
656 ino,
657 irec.br_startblock + irec.br_blockcount - 1,
658 irec.br_startoff);
659 goto done;
660
661 case XR_DFSBNORANGE_OVERFLOW:
662 do_warn(
663 _("inode %" PRIu64 " - bad extent overflows - start %" PRIu64 ", "
664 "end %" PRIu64 ", offset %" PRIu64 "\n"),
665 ino,
666 irec.br_startblock,
667 irec.br_startblock + irec.br_blockcount - 1,
668 irec.br_startoff);
669 goto done;
670 }
671 /* Ensure this extent does not extend beyond the max offset */
672 if (irec.br_startoff + irec.br_blockcount - 1 >
673 fs_max_file_offset) {
674 do_warn(
675 _("inode %" PRIu64 " - extent exceeds max offset - start %" PRIu64 ", "
676 "count %" PRIu64 ", physical block %" PRIu64 "\n"),
677 ino, irec.br_startoff, irec.br_blockcount,
678 irec.br_startblock);
679 goto done;
680 }
681
682 if (blkmapp && *blkmapp) {
683 int error2;
684 error2 = blkmap_set_ext(blkmapp, irec.br_startoff,
685 irec.br_startblock, irec.br_blockcount);
686 if (error2) {
687 /*
688 * we don't want to clear the inode due to an
689 * internal bmap tracking error, but if we've
690 * run out of memory then we simply can't
691 * validate that the filesystem is consistent.
692 * Hence just abort at this point with an ENOMEM
693 * error.
694 */
695 do_abort(
696 _("Fatal error: inode %" PRIu64 " - blkmap_set_ext(): %s\n"
697 "\t%s fork, off - %" PRIu64 ", start - %" PRIu64 ", cnt %" PRIu64 "\n"),
698 ino, strerror(error2), forkname,
699 irec.br_startoff, irec.br_startblock,
700 irec.br_blockcount);
701 }
702 }
703
704 /*
705 * Profiling shows that the following loop takes the
706 * most time in all of xfs_repair.
707 */
708 agno = XFS_FSB_TO_AGNO(mp, irec.br_startblock);
709 agbno = XFS_FSB_TO_AGBNO(mp, irec.br_startblock);
710 ebno = agbno + irec.br_blockcount;
711 if (agno != locked_agno) {
712 if (locked_agno != -1)
713 pthread_mutex_unlock(&ag_locks[locked_agno].lock);
714 pthread_mutex_lock(&ag_locks[agno].lock);
715 locked_agno = agno;
716 }
717
718 if (check_dups) {
719 /*
720 * if we're just checking the bmap for dups,
721 * return if we find one, otherwise, continue
722 * checking each entry without setting the
723 * block bitmap
724 */
725 if (search_dup_extent(agno, agbno, ebno)) {
726 do_warn(
727 _("%s fork in ino %" PRIu64 " claims dup extent, "
728 "off - %" PRIu64 ", start - %" PRIu64 ", cnt %" PRIu64 "\n"),
729 forkname, ino, irec.br_startoff,
730 irec.br_startblock,
731 irec.br_blockcount);
732 goto done;
733 }
734 *tot += irec.br_blockcount;
735 continue;
736 }
737
738 for (b = irec.br_startblock;
739 agbno < ebno;
740 b += blen, agbno += blen) {
741 state = get_bmap_ext(agno, agbno, ebno, &blen);
742 switch (state) {
743 case XR_E_FREE:
744 case XR_E_FREE1:
745 do_warn(
746 _("%s fork in ino %" PRIu64 " claims free block %" PRIu64 "\n"),
747 forkname, ino, (__uint64_t) b);
748 /* fall through ... */
749 case XR_E_INUSE1: /* seen by rmap */
750 case XR_E_UNKNOWN:
751 set_bmap_ext(agno, agbno, blen, XR_E_INUSE);
752 break;
753
754 case XR_E_BAD_STATE:
755 do_error(_("bad state in block map %" PRIu64 "\n"), b);
756
757 case XR_E_FS_MAP1:
758 case XR_E_INO1:
759 case XR_E_INUSE_FS1:
760 do_warn(_("rmap claims metadata use!\n"));
761 /* fall through */
762 case XR_E_FS_MAP:
763 case XR_E_INO:
764 case XR_E_INUSE_FS:
765 do_warn(
766 _("%s fork in inode %" PRIu64 " claims metadata block %" PRIu64 "\n"),
767 forkname, ino, b);
768 goto done;
769
770 case XR_E_INUSE:
771 case XR_E_MULT:
772 set_bmap_ext(agno, agbno, blen, XR_E_MULT);
773 do_warn(
774 _("%s fork in %s inode %" PRIu64 " claims used block %" PRIu64 "\n"),
775 forkname, ftype, ino, b);
776 goto done;
777
778 default:
779 do_error(
780 _("illegal state %d in block map %" PRIu64 "\n"),
781 state, b);
782 }
783 }
784 if (collect_rmaps) { /* && !check_dups */
785 error = rmap_add_rec(mp, ino, whichfork, &irec);
786 if (error)
787 do_error(
788 _("couldn't add reverse mapping\n")
789 );
790 }
791 *tot += irec.br_blockcount;
792 }
793 error = 0;
794 done:
795 if (locked_agno != -1)
796 pthread_mutex_unlock(&ag_locks[locked_agno].lock);
797
798 if (i != *numrecs) {
799 ASSERT(i < *numrecs);
800 do_warn(_("correcting nextents for inode %" PRIu64 "\n"), ino);
801 *numrecs = i;
802 }
803
804 return error;
805 }
806
807 /*
808 * return 1 if inode should be cleared, 0 otherwise, sets block bitmap
809 * as a side-effect
810 */
811 int
812 process_bmbt_reclist(
813 xfs_mount_t *mp,
814 xfs_bmbt_rec_t *rp,
815 int *numrecs,
816 int type,
817 xfs_ino_t ino,
818 xfs_rfsblock_t *tot,
819 blkmap_t **blkmapp,
820 xfs_fileoff_t *first_key,
821 xfs_fileoff_t *last_key,
822 int whichfork)
823 {
824 return process_bmbt_reclist_int(mp, rp, numrecs, type, ino, tot,
825 blkmapp, first_key, last_key, 0, whichfork);
826 }
827
828 /*
829 * return 1 if inode should be cleared, 0 otherwise, does not set
830 * block bitmap
831 */
832 int
833 scan_bmbt_reclist(
834 xfs_mount_t *mp,
835 xfs_bmbt_rec_t *rp,
836 int *numrecs,
837 int type,
838 xfs_ino_t ino,
839 xfs_rfsblock_t *tot,
840 int whichfork)
841 {
842 xfs_fileoff_t first_key = 0;
843 xfs_fileoff_t last_key = 0;
844
845 return process_bmbt_reclist_int(mp, rp, numrecs, type, ino, tot,
846 NULL, &first_key, &last_key, 1, whichfork);
847 }
848
849 /*
850 * these two are meant for routines that read and work with inodes
851 * one at a time where the inodes may be in any order (like walking
852 * the unlinked lists to look for inodes). the caller is responsible
853 * for writing/releasing the buffer.
854 */
855 xfs_buf_t *
856 get_agino_buf(xfs_mount_t *mp,
857 xfs_agnumber_t agno,
858 xfs_agino_t agino,
859 xfs_dinode_t **dipp)
860 {
861 ino_tree_node_t *irec;
862 xfs_buf_t *bp;
863 int size;
864
865 if ((irec = find_inode_rec(mp, agno, agino)) == NULL)
866 return(NULL);
867
868 size = MAX(1, XFS_FSB_TO_BB(mp,
869 mp->m_inode_cluster_size >> mp->m_sb.sb_blocklog));
870 bp = libxfs_readbuf(mp->m_dev, XFS_AGB_TO_DADDR(mp, agno,
871 XFS_AGINO_TO_AGBNO(mp, irec->ino_startnum)), size, 0,
872 &xfs_inode_buf_ops);
873 if (!bp) {
874 do_warn(_("cannot read inode (%u/%u), disk block %" PRIu64 "\n"),
875 agno, irec->ino_startnum,
876 XFS_AGB_TO_DADDR(mp, agno,
877 XFS_AGINO_TO_AGBNO(mp, irec->ino_startnum)));
878 return(NULL);
879 }
880
881 *dipp = xfs_make_iptr(mp, bp, agino -
882 XFS_OFFBNO_TO_AGINO(mp, XFS_AGINO_TO_AGBNO(mp,
883 irec->ino_startnum),
884 0));
885
886 return(bp);
887 }
888
889 /*
890 * higher level inode processing stuff starts here:
891 * first, one utility routine for each type of inode
892 */
893
894 /*
895 * return 1 if inode should be cleared, 0 otherwise
896 */
897 static int
898 process_btinode(
899 xfs_mount_t *mp,
900 xfs_agnumber_t agno,
901 xfs_agino_t ino,
902 xfs_dinode_t *dip,
903 int type,
904 int *dirty,
905 xfs_rfsblock_t *tot,
906 __uint64_t *nex,
907 blkmap_t **blkmapp,
908 int whichfork,
909 int check_dups)
910 {
911 xfs_bmdr_block_t *dib;
912 xfs_fileoff_t last_key;
913 xfs_fileoff_t first_key = 0;
914 xfs_ino_t lino;
915 xfs_bmbt_ptr_t *pp;
916 xfs_bmbt_key_t *pkey;
917 char *forkname = get_forkname(whichfork);
918 int i;
919 int level;
920 int numrecs;
921 bmap_cursor_t cursor;
922 __uint64_t magic;
923
924 dib = (xfs_bmdr_block_t *)XFS_DFORK_PTR(dip, whichfork);
925 lino = XFS_AGINO_TO_INO(mp, agno, ino);
926 *tot = 0;
927 *nex = 0;
928
929 magic = xfs_sb_version_hascrc(&mp->m_sb) ? XFS_BMAP_CRC_MAGIC
930 : XFS_BMAP_MAGIC;
931
932 level = be16_to_cpu(dib->bb_level);
933 numrecs = be16_to_cpu(dib->bb_numrecs);
934
935 if ((level == 0) || (level > XFS_BM_MAXLEVELS(mp, whichfork))) {
936 /*
937 * XXX - if we were going to fix up the inode,
938 * we'd try to treat the fork as an interior
939 * node and see if we could get an accurate
940 * level value from one of the blocks pointed
941 * to by the pointers in the fork. For now
942 * though, we just bail (and blow out the inode).
943 */
944 do_warn(
945 _("bad level %d in inode %" PRIu64 " bmap btree root block\n"),
946 level, XFS_AGINO_TO_INO(mp, agno, ino));
947 return(1);
948 }
949 if (numrecs == 0) {
950 do_warn(
951 _("bad numrecs 0 in inode %" PRIu64 " bmap btree root block\n"),
952 XFS_AGINO_TO_INO(mp, agno, ino));
953 return(1);
954 }
955 /*
956 * use bmdr/dfork_dsize since the root block is in the data fork
957 */
958 if (XFS_BMDR_SPACE_CALC(numrecs) > XFS_DFORK_SIZE(dip, mp, whichfork)) {
959 do_warn(
960 _("indicated size of %s btree root (%d bytes) greater than space in "
961 "inode %" PRIu64 " %s fork\n"),
962 forkname, XFS_BMDR_SPACE_CALC(numrecs), lino, forkname);
963 return(1);
964 }
965
966 init_bm_cursor(&cursor, level + 1);
967
968 pp = XFS_BMDR_PTR_ADDR(dib, 1,
969 libxfs_bmdr_maxrecs(XFS_DFORK_SIZE(dip, mp, whichfork), 0));
970 pkey = XFS_BMDR_KEY_ADDR(dib, 1);
971 last_key = NULLFILEOFF;
972
973 for (i = 0; i < numrecs; i++) {
974 /*
975 * XXX - if we were going to do more to fix up the inode
976 * btree, we'd do it right here. For now, if there's a
977 * problem, we'll bail out and presumably clear the inode.
978 */
979 if (!verify_dfsbno(mp, get_unaligned_be64(&pp[i]))) {
980 do_warn(
981 _("bad bmap btree ptr 0x%" PRIx64 " in ino %" PRIu64 "\n"),
982 get_unaligned_be64(&pp[i]), lino);
983 return(1);
984 }
985
986 if (scan_lbtree(get_unaligned_be64(&pp[i]), level, scan_bmapbt,
987 type, whichfork, lino, tot, nex, blkmapp,
988 &cursor, 1, check_dups, magic,
989 &xfs_bmbt_buf_ops))
990 return(1);
991 /*
992 * fix key (offset) mismatches between the keys in root
993 * block records and the first key of each child block.
994 * fixes cases where entries have been shifted between
995 * blocks but the parent hasn't been updated
996 */
997 if (!check_dups && cursor.level[level-1].first_key !=
998 get_unaligned_be64(&pkey[i].br_startoff)) {
999 if (!no_modify) {
1000 do_warn(
1001 _("correcting key in bmbt root (was %" PRIu64 ", now %" PRIu64") in inode "
1002 "%" PRIu64" %s fork\n"),
1003 get_unaligned_be64(&pkey[i].br_startoff),
1004 cursor.level[level-1].first_key,
1005 XFS_AGINO_TO_INO(mp, agno, ino),
1006 forkname);
1007 *dirty = 1;
1008 put_unaligned_be64(
1009 cursor.level[level-1].first_key,
1010 &pkey[i].br_startoff);
1011 } else {
1012 do_warn(
1013 _("bad key in bmbt root (is %" PRIu64 ", would reset to %" PRIu64 ") in inode "
1014 "%" PRIu64 " %s fork\n"),
1015 get_unaligned_be64(&pkey[i].br_startoff),
1016 cursor.level[level-1].first_key,
1017 XFS_AGINO_TO_INO(mp, agno, ino),
1018 forkname);
1019 }
1020 }
1021 /*
1022 * make sure that keys are in ascending order. blow out
1023 * inode if the ordering doesn't hold
1024 */
1025 if (check_dups == 0) {
1026 if (last_key != NULLFILEOFF && last_key >=
1027 cursor.level[level-1].first_key) {
1028 do_warn(
1029 _("out of order bmbt root key %" PRIu64 " in inode %" PRIu64 " %s fork\n"),
1030 first_key,
1031 XFS_AGINO_TO_INO(mp, agno, ino),
1032 forkname);
1033 return(1);
1034 }
1035 last_key = cursor.level[level-1].first_key;
1036 }
1037 }
1038 /*
1039 * Ideally if all the extents are ok (perhaps after further
1040 * checks below?) we'd just move this back into extents format.
1041 * But for now clear it, as the kernel will choke on this
1042 */
1043 if (*nex <= XFS_DFORK_SIZE(dip, mp, whichfork) /
1044 sizeof(xfs_bmbt_rec_t)) {
1045 do_warn(
1046 _("extent count for ino %" PRIu64 " %s fork too low (%" PRIu64 ") for file format\n"),
1047 lino, forkname, *nex);
1048 return(1);
1049 }
1050 /*
1051 * Check that the last child block's forward sibling pointer
1052 * is NULL.
1053 */
1054 if (check_dups == 0 &&
1055 cursor.level[0].right_fsbno != NULLFSBLOCK) {
1056 do_warn(
1057 _("bad fwd (right) sibling pointer (saw %" PRIu64 " should be NULLFSBLOCK)\n"),
1058 cursor.level[0].right_fsbno);
1059 do_warn(
1060 _("\tin inode %" PRIu64 " (%s fork) bmap btree block %" PRIu64 "\n"),
1061 XFS_AGINO_TO_INO(mp, agno, ino), forkname,
1062 cursor.level[0].fsbno);
1063 return(1);
1064 }
1065
1066 return(0);
1067 }
1068
1069 /*
1070 * return 1 if inode should be cleared, 0 otherwise
1071 */
1072 static int
1073 process_exinode(
1074 xfs_mount_t *mp,
1075 xfs_agnumber_t agno,
1076 xfs_agino_t ino,
1077 xfs_dinode_t *dip,
1078 int type,
1079 int *dirty,
1080 xfs_rfsblock_t *tot,
1081 __uint64_t *nex,
1082 blkmap_t **blkmapp,
1083 int whichfork,
1084 int check_dups)
1085 {
1086 xfs_ino_t lino;
1087 xfs_bmbt_rec_t *rp;
1088 xfs_fileoff_t first_key;
1089 xfs_fileoff_t last_key;
1090 int32_t numrecs;
1091 int ret;
1092
1093 lino = XFS_AGINO_TO_INO(mp, agno, ino);
1094 rp = (xfs_bmbt_rec_t *)XFS_DFORK_PTR(dip, whichfork);
1095 *tot = 0;
1096 numrecs = XFS_DFORK_NEXTENTS(dip, whichfork);
1097
1098 /*
1099 * We've already decided on the maximum number of extents on the inode,
1100 * and numrecs may be corrupt. Hence make sure we only allow numrecs to
1101 * be in the range of valid on-disk numbers, which is:
1102 * 0 < numrecs < 2^31 - 1
1103 */
1104 if (numrecs < 0)
1105 numrecs = *nex;
1106
1107 /*
1108 * XXX - if we were going to fix up the btree record,
1109 * we'd do it right here. For now, if there's a problem,
1110 * we'll bail out and presumably clear the inode.
1111 */
1112 if (check_dups == 0)
1113 ret = process_bmbt_reclist(mp, rp, &numrecs, type, lino,
1114 tot, blkmapp, &first_key, &last_key,
1115 whichfork);
1116 else
1117 ret = scan_bmbt_reclist(mp, rp, &numrecs, type, lino, tot,
1118 whichfork);
1119
1120 *nex = numrecs;
1121 return ret;
1122 }
1123
1124 /*
1125 * return 1 if inode should be cleared, 0 otherwise
1126 */
1127 static int
1128 process_lclinode(
1129 xfs_mount_t *mp,
1130 xfs_agnumber_t agno,
1131 xfs_agino_t ino,
1132 xfs_dinode_t *dip,
1133 int whichfork)
1134 {
1135 xfs_attr_shortform_t *asf;
1136 xfs_ino_t lino;
1137
1138 lino = XFS_AGINO_TO_INO(mp, agno, ino);
1139 if (whichfork == XFS_DATA_FORK && be64_to_cpu(dip->di_size) >
1140 XFS_DFORK_DSIZE(dip, mp)) {
1141 do_warn(
1142 _("local inode %" PRIu64 " data fork is too large (size = %lld, max = %d)\n"),
1143 lino, (unsigned long long) be64_to_cpu(dip->di_size),
1144 XFS_DFORK_DSIZE(dip, mp));
1145 return(1);
1146 } else if (whichfork == XFS_ATTR_FORK) {
1147 asf = (xfs_attr_shortform_t *)XFS_DFORK_APTR(dip);
1148 if (be16_to_cpu(asf->hdr.totsize) > XFS_DFORK_ASIZE(dip, mp)) {
1149 do_warn(
1150 _("local inode %" PRIu64 " attr fork too large (size %d, max = %d)\n"),
1151 lino, be16_to_cpu(asf->hdr.totsize),
1152 XFS_DFORK_ASIZE(dip, mp));
1153 return(1);
1154 }
1155 if (be16_to_cpu(asf->hdr.totsize) < sizeof(xfs_attr_sf_hdr_t)) {
1156 do_warn(
1157 _("local inode %" PRIu64 " attr too small (size = %d, min size = %zd)\n"),
1158 lino, be16_to_cpu(asf->hdr.totsize),
1159 sizeof(xfs_attr_sf_hdr_t));
1160 return(1);
1161 }
1162 }
1163
1164 return(0);
1165 }
1166
1167 static int
1168 process_symlink_extlist(xfs_mount_t *mp, xfs_ino_t lino, xfs_dinode_t *dino)
1169 {
1170 xfs_fileoff_t expected_offset;
1171 xfs_bmbt_rec_t *rp;
1172 xfs_bmbt_irec_t irec;
1173 int numrecs;
1174 int i;
1175 int max_blocks;
1176
1177 if (be64_to_cpu(dino->di_size) <= XFS_DFORK_DSIZE(dino, mp)) {
1178 if (dino->di_format == XFS_DINODE_FMT_LOCAL)
1179 return 0;
1180 do_warn(
1181 _("mismatch between format (%d) and size (%" PRId64 ") in symlink ino %" PRIu64 "\n"),
1182 dino->di_format,
1183 (__int64_t)be64_to_cpu(dino->di_size), lino);
1184 return 1;
1185 }
1186 if (dino->di_format == XFS_DINODE_FMT_LOCAL) {
1187 do_warn(
1188 _("mismatch between format (%d) and size (%" PRId64 ") in symlink inode %" PRIu64 "\n"),
1189 dino->di_format,
1190 (__int64_t)be64_to_cpu(dino->di_size), lino);
1191 return 1;
1192 }
1193
1194 rp = (xfs_bmbt_rec_t *)XFS_DFORK_DPTR(dino);
1195 numrecs = be32_to_cpu(dino->di_nextents);
1196
1197 /*
1198 * the max # of extents in a symlink inode is equal to the
1199 * number of max # of blocks required to store the symlink
1200 */
1201 if (numrecs > max_symlink_blocks) {
1202 do_warn(
1203 _("bad number of extents (%d) in symlink %" PRIu64 " data fork\n"),
1204 numrecs, lino);
1205 return(1);
1206 }
1207
1208 max_blocks = max_symlink_blocks;
1209 expected_offset = 0;
1210
1211 for (i = 0; i < numrecs; i++) {
1212 libxfs_bmbt_disk_get_all((rp +i), &irec);
1213 if (irec.br_startoff != expected_offset) {
1214 do_warn(
1215 _("bad extent #%d offset (%" PRIu64 ") in symlink %" PRIu64 " data fork\n"),
1216 i, irec.br_startoff, lino);
1217 return(1);
1218 }
1219 if (irec.br_blockcount == 0 || irec.br_blockcount > max_blocks) {
1220 do_warn(
1221 _("bad extent #%d count (%" PRIu64 ") in symlink %" PRIu64 " data fork\n"),
1222 i, irec.br_blockcount, lino);
1223 return(1);
1224 }
1225
1226 max_blocks -= irec.br_blockcount;
1227 expected_offset += irec.br_blockcount;
1228 }
1229
1230 return(0);
1231 }
1232
1233 /*
1234 * takes a name and length and returns 1 if the name contains
1235 * a \0, returns 0 otherwise
1236 */
1237 static int
1238 null_check(char *name, int length)
1239 {
1240 int i;
1241
1242 ASSERT(length < MAXPATHLEN);
1243
1244 for (i = 0; i < length; i++, name++) {
1245 if (*name == '\0')
1246 return(1);
1247 }
1248
1249 return(0);
1250 }
1251
1252 static int
1253 process_symlink_remote(
1254 struct xfs_mount *mp,
1255 xfs_ino_t lino,
1256 struct xfs_dinode *dino,
1257 struct blkmap *blkmap,
1258 char *dst)
1259 {
1260 xfs_fsblock_t fsbno;
1261 struct xfs_buf *bp;
1262 char *src;
1263 int pathlen;
1264 int offset;
1265 int i;
1266
1267 offset = 0;
1268 pathlen = be64_to_cpu(dino->di_size);
1269 i = 0;
1270
1271 while (pathlen > 0) {
1272 int blk_cnt = 1;
1273 int byte_cnt;
1274 int badcrc = 0;
1275
1276 fsbno = blkmap_get(blkmap, i);
1277 if (fsbno == NULLFSBLOCK) {
1278 do_warn(
1279 _("cannot read inode %" PRIu64 ", file block %d, NULL disk block\n"),
1280 lino, i);
1281 return 1;
1282 }
1283
1284 /*
1285 * There's a symlink header for each contiguous extent. If
1286 * there are contiguous blocks, read them in one go.
1287 */
1288 while (blk_cnt <= max_symlink_blocks) {
1289 if (blkmap_get(blkmap, i + 1) != fsbno + 1)
1290 break;
1291 blk_cnt++;
1292 i++;
1293 }
1294
1295 byte_cnt = XFS_FSB_TO_B(mp, blk_cnt);
1296
1297 bp = libxfs_readbuf(mp->m_dev, XFS_FSB_TO_DADDR(mp, fsbno),
1298 BTOBB(byte_cnt), 0, &xfs_symlink_buf_ops);
1299 if (!bp) {
1300 do_warn(
1301 _("cannot read inode %" PRIu64 ", file block %d, disk block %" PRIu64 "\n"),
1302 lino, i, fsbno);
1303 return 1;
1304 }
1305 if (bp->b_error == -EFSBADCRC) {
1306 do_warn(
1307 _("Bad symlink buffer CRC, block %" PRIu64 ", inode %" PRIu64 ".\n"
1308 "Correcting CRC, but symlink may be bad.\n"), fsbno, lino);
1309 badcrc = 1;
1310 }
1311
1312 byte_cnt = XFS_SYMLINK_BUF_SPACE(mp, byte_cnt);
1313 byte_cnt = MIN(pathlen, byte_cnt);
1314
1315 src = bp->b_addr;
1316 if (xfs_sb_version_hascrc(&mp->m_sb)) {
1317 if (!libxfs_symlink_hdr_ok(lino, offset,
1318 byte_cnt, bp)) {
1319 do_warn(
1320 _("bad symlink header ino %" PRIu64 ", file block %d, disk block %" PRIu64 "\n"),
1321 lino, i, fsbno);
1322 libxfs_putbuf(bp);
1323 return 1;
1324 }
1325 src += sizeof(struct xfs_dsymlink_hdr);
1326 }
1327
1328 memmove(dst + offset, src, byte_cnt);
1329
1330 pathlen -= byte_cnt;
1331 offset += byte_cnt;
1332 i++;
1333
1334 if (badcrc && !no_modify)
1335 libxfs_writebuf(bp, 0);
1336 else
1337 libxfs_putbuf(bp);
1338 }
1339 return 0;
1340 }
1341
1342 /*
1343 * like usual, returns 0 if everything's ok and 1 if something's
1344 * bogus
1345 */
1346 static int
1347 process_symlink(
1348 xfs_mount_t *mp,
1349 xfs_ino_t lino,
1350 xfs_dinode_t *dino,
1351 blkmap_t *blkmap)
1352 {
1353 char *symlink;
1354 char data[MAXPATHLEN];
1355
1356 /*
1357 * check size against kernel symlink limits. we know
1358 * size is consistent with inode storage format -- e.g.
1359 * the inode is structurally ok so we don't have to check
1360 * for that
1361 */
1362 if (be64_to_cpu(dino->di_size) >= MAXPATHLEN) {
1363 do_warn(_("symlink in inode %" PRIu64 " too long (%llu chars)\n"),
1364 lino, (unsigned long long) be64_to_cpu(dino->di_size));
1365 return(1);
1366 }
1367
1368 /*
1369 * have to check symlink component by component.
1370 * get symlink contents into data area
1371 */
1372 symlink = &data[0];
1373 if (be64_to_cpu(dino->di_size) <= XFS_DFORK_DSIZE(dino, mp)) {
1374 /*
1375 * local symlink, just copy the symlink out of the
1376 * inode into the data area
1377 */
1378 memmove(symlink, XFS_DFORK_DPTR(dino),
1379 be64_to_cpu(dino->di_size));
1380 } else {
1381 int error;
1382
1383 error = process_symlink_remote(mp, lino, dino, blkmap, symlink);
1384 if (error)
1385 return error;
1386 }
1387
1388 data[be64_to_cpu(dino->di_size)] = '\0';
1389
1390 /*
1391 * check for nulls
1392 */
1393 if (null_check(symlink, be64_to_cpu(dino->di_size))) {
1394 do_warn(
1395 _("found illegal null character in symlink inode %" PRIu64 "\n"),
1396 lino);
1397 return(1);
1398 }
1399
1400 return(0);
1401 }
1402
1403 /*
1404 * called to process the set of misc inode special inode types
1405 * that have no associated data storage (fifos, pipes, devices, etc.).
1406 */
1407 static int
1408 process_misc_ino_types(xfs_mount_t *mp,
1409 xfs_dinode_t *dino,
1410 xfs_ino_t lino,
1411 int type)
1412 {
1413 /*
1414 * disallow mountpoint inodes until such time as the
1415 * kernel actually allows them to be created (will
1416 * probably require a superblock version rev, sigh).
1417 */
1418 if (type == XR_INO_MOUNTPOINT) {
1419 do_warn(
1420 _("inode %" PRIu64 " has bad inode type (IFMNT)\n"), lino);
1421 return(1);
1422 }
1423
1424 /*
1425 * must also have a zero size
1426 */
1427 if (be64_to_cpu(dino->di_size) != 0) {
1428 switch (type) {
1429 case XR_INO_CHRDEV:
1430 do_warn(
1431 _("size of character device inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1432 (__int64_t)be64_to_cpu(dino->di_size));
1433 break;
1434 case XR_INO_BLKDEV:
1435 do_warn(
1436 _("size of block device inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1437 (__int64_t)be64_to_cpu(dino->di_size));
1438 break;
1439 case XR_INO_SOCK:
1440 do_warn(
1441 _("size of socket inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1442 (__int64_t)be64_to_cpu(dino->di_size));
1443 break;
1444 case XR_INO_FIFO:
1445 do_warn(
1446 _("size of fifo inode %" PRIu64 " != 0 (%" PRId64 " bytes)\n"), lino,
1447 (__int64_t)be64_to_cpu(dino->di_size));
1448 break;
1449 default:
1450 do_warn(_("Internal error - process_misc_ino_types, "
1451 "illegal type %d\n"), type);
1452 abort();
1453 }
1454
1455 return(1);
1456 }
1457
1458 return(0);
1459 }
1460
1461 static int
1462 process_misc_ino_types_blocks(xfs_rfsblock_t totblocks, xfs_ino_t lino, int type)
1463 {
1464 /*
1465 * you can not enforce all misc types have zero data fork blocks
1466 * by checking dino->di_nblocks because atotblocks (attribute
1467 * blocks) are part of nblocks. We must check this later when atotblocks
1468 * has been calculated or by doing a simple check that anExtents == 0.
1469 * We must also guarantee that totblocks is 0. Thus nblocks checking
1470 * will be done later in process_dinode_int for misc types.
1471 */
1472
1473 if (totblocks != 0) {
1474 switch (type) {
1475 case XR_INO_CHRDEV:
1476 do_warn(
1477 _("size of character device inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1478 lino, totblocks);
1479 break;
1480 case XR_INO_BLKDEV:
1481 do_warn(
1482 _("size of block device inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1483 lino, totblocks);
1484 break;
1485 case XR_INO_SOCK:
1486 do_warn(
1487 _("size of socket inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1488 lino, totblocks);
1489 break;
1490 case XR_INO_FIFO:
1491 do_warn(
1492 _("size of fifo inode %" PRIu64 " != 0 (%" PRIu64 " blocks)\n"),
1493 lino, totblocks);
1494 break;
1495 default:
1496 return(0);
1497 }
1498 return(1);
1499 }
1500 return (0);
1501 }
1502
1503 static inline int
1504 dinode_fmt(
1505 xfs_dinode_t *dino)
1506 {
1507 return be16_to_cpu(dino->di_mode) & S_IFMT;
1508 }
1509
1510 static inline void
1511 change_dinode_fmt(
1512 xfs_dinode_t *dino,
1513 int new_fmt)
1514 {
1515 int mode = be16_to_cpu(dino->di_mode);
1516
1517 ASSERT((new_fmt & ~S_IFMT) == 0);
1518
1519 mode &= ~S_IFMT;
1520 mode |= new_fmt;
1521 dino->di_mode = cpu_to_be16(mode);
1522 }
1523
1524 static int
1525 check_dinode_mode_format(
1526 xfs_dinode_t *dinoc)
1527 {
1528 if (dinoc->di_format >= XFS_DINODE_FMT_UUID)
1529 return -1; /* FMT_UUID is not used */
1530
1531 switch (dinode_fmt(dinoc)) {
1532 case S_IFIFO:
1533 case S_IFCHR:
1534 case S_IFBLK:
1535 case S_IFSOCK:
1536 return (dinoc->di_format != XFS_DINODE_FMT_DEV) ? -1 : 0;
1537
1538 case S_IFDIR:
1539 return (dinoc->di_format < XFS_DINODE_FMT_LOCAL ||
1540 dinoc->di_format > XFS_DINODE_FMT_BTREE) ? -1 : 0;
1541
1542 case S_IFREG:
1543 return (dinoc->di_format < XFS_DINODE_FMT_EXTENTS ||
1544 dinoc->di_format > XFS_DINODE_FMT_BTREE) ? -1 : 0;
1545
1546 case S_IFLNK:
1547 return (dinoc->di_format < XFS_DINODE_FMT_LOCAL ||
1548 dinoc->di_format > XFS_DINODE_FMT_EXTENTS) ? -1 : 0;
1549
1550 default: ;
1551 }
1552 return 0; /* invalid modes are checked elsewhere */
1553 }
1554
1555 /*
1556 * If inode is a superblock inode, does type check to make sure is it valid.
1557 * Returns 0 if it's valid, non-zero if it needs to be cleared.
1558 */
1559
1560 static int
1561 process_check_sb_inodes(
1562 xfs_mount_t *mp,
1563 xfs_dinode_t *dinoc,
1564 xfs_ino_t lino,
1565 int *type,
1566 int *dirty)
1567 {
1568 if (lino == mp->m_sb.sb_rootino) {
1569 if (*type != XR_INO_DIR) {
1570 do_warn(_("root inode %" PRIu64 " has bad type 0x%x\n"),
1571 lino, dinode_fmt(dinoc));
1572 *type = XR_INO_DIR;
1573 if (!no_modify) {
1574 do_warn(_("resetting to directory\n"));
1575 change_dinode_fmt(dinoc, S_IFDIR);
1576 *dirty = 1;
1577 } else
1578 do_warn(_("would reset to directory\n"));
1579 }
1580 return 0;
1581 }
1582 if (lino == mp->m_sb.sb_uquotino) {
1583 if (*type != XR_INO_DATA) {
1584 do_warn(_("user quota inode %" PRIu64 " has bad type 0x%x\n"),
1585 lino, dinode_fmt(dinoc));
1586 mp->m_sb.sb_uquotino = NULLFSINO;
1587 return 1;
1588 }
1589 return 0;
1590 }
1591 if (lino == mp->m_sb.sb_gquotino) {
1592 if (*type != XR_INO_DATA) {
1593 do_warn(_("group quota inode %" PRIu64 " has bad type 0x%x\n"),
1594 lino, dinode_fmt(dinoc));
1595 mp->m_sb.sb_gquotino = NULLFSINO;
1596 return 1;
1597 }
1598 return 0;
1599 }
1600 if (lino == mp->m_sb.sb_pquotino) {
1601 if (*type != XR_INO_DATA) {
1602 do_warn(_("project quota inode %" PRIu64 " has bad type 0x%x\n"),
1603 lino, dinode_fmt(dinoc));
1604 mp->m_sb.sb_pquotino = NULLFSINO;
1605 return 1;
1606 }
1607 return 0;
1608 }
1609 if (lino == mp->m_sb.sb_rsumino) {
1610 if (*type != XR_INO_RTSUM) {
1611 do_warn(
1612 _("realtime summary inode %" PRIu64 " has bad type 0x%x, "),
1613 lino, dinode_fmt(dinoc));
1614 if (!no_modify) {
1615 do_warn(_("resetting to regular file\n"));
1616 change_dinode_fmt(dinoc, S_IFREG);
1617 *dirty = 1;
1618 } else {
1619 do_warn(_("would reset to regular file\n"));
1620 }
1621 }
1622 if (mp->m_sb.sb_rblocks == 0 && dinoc->di_nextents != 0) {
1623 do_warn(
1624 _("bad # of extents (%u) for realtime summary inode %" PRIu64 "\n"),
1625 be32_to_cpu(dinoc->di_nextents), lino);
1626 return 1;
1627 }
1628 return 0;
1629 }
1630 if (lino == mp->m_sb.sb_rbmino) {
1631 if (*type != XR_INO_RTBITMAP) {
1632 do_warn(
1633 _("realtime bitmap inode %" PRIu64 " has bad type 0x%x, "),
1634 lino, dinode_fmt(dinoc));
1635 if (!no_modify) {
1636 do_warn(_("resetting to regular file\n"));
1637 change_dinode_fmt(dinoc, S_IFREG);
1638 *dirty = 1;
1639 } else {
1640 do_warn(_("would reset to regular file\n"));
1641 }
1642 }
1643 if (mp->m_sb.sb_rblocks == 0 && dinoc->di_nextents != 0) {
1644 do_warn(
1645 _("bad # of extents (%u) for realtime bitmap inode %" PRIu64 "\n"),
1646 be32_to_cpu(dinoc->di_nextents), lino);
1647 return 1;
1648 }
1649 return 0;
1650 }
1651 return 0;
1652 }
1653
1654 /*
1655 * general size/consistency checks:
1656 *
1657 * if the size <= size of the data fork, directories must be
1658 * local inodes unlike regular files which would be extent inodes.
1659 * all the other mentioned types have to have a zero size value.
1660 *
1661 * if the size and format don't match, get out now rather than
1662 * risk trying to process a non-existent extents or btree
1663 * type data fork.
1664 */
1665 static int
1666 process_check_inode_sizes(
1667 xfs_mount_t *mp,
1668 xfs_dinode_t *dino,
1669 xfs_ino_t lino,
1670 int type)
1671 {
1672 xfs_fsize_t size = be64_to_cpu(dino->di_size);
1673
1674 switch (type) {
1675
1676 case XR_INO_DIR:
1677 if (size <= XFS_DFORK_DSIZE(dino, mp) &&
1678 dino->di_format != XFS_DINODE_FMT_LOCAL) {
1679 do_warn(
1680 _("mismatch between format (%d) and size (%" PRId64 ") in directory ino %" PRIu64 "\n"),
1681 dino->di_format, size, lino);
1682 return 1;
1683 }
1684 if (size > XFS_DIR2_LEAF_OFFSET) {
1685 do_warn(
1686 _("directory inode %" PRIu64 " has bad size %" PRId64 "\n"),
1687 lino, size);
1688 return 1;
1689 }
1690 break;
1691
1692 case XR_INO_SYMLINK:
1693 if (process_symlink_extlist(mp, lino, dino)) {
1694 do_warn(_("bad data fork in symlink %" PRIu64 "\n"), lino);
1695 return 1;
1696 }
1697 break;
1698
1699 case XR_INO_CHRDEV: /* fall through to FIFO case ... */
1700 case XR_INO_BLKDEV: /* fall through to FIFO case ... */
1701 case XR_INO_SOCK: /* fall through to FIFO case ... */
1702 case XR_INO_MOUNTPOINT: /* fall through to FIFO case ... */
1703 case XR_INO_FIFO:
1704 if (process_misc_ino_types(mp, dino, lino, type))
1705 return 1;
1706 break;
1707
1708 case XR_INO_RTDATA:
1709 /*
1710 * if we have no realtime blocks, any inode claiming
1711 * to be a real-time file is bogus
1712 */
1713 if (mp->m_sb.sb_rblocks == 0) {
1714 do_warn(
1715 _("found inode %" PRIu64 " claiming to be a real-time file\n"), lino);
1716 return 1;
1717 }
1718 break;
1719
1720 case XR_INO_RTBITMAP:
1721 if (size != (__int64_t)mp->m_sb.sb_rbmblocks *
1722 mp->m_sb.sb_blocksize) {
1723 do_warn(
1724 _("realtime bitmap inode %" PRIu64 " has bad size %" PRId64 " (should be %" PRIu64 ")\n"),
1725 lino, size,
1726 (__int64_t) mp->m_sb.sb_rbmblocks *
1727 mp->m_sb.sb_blocksize);
1728 return 1;
1729 }
1730 break;
1731
1732 case XR_INO_RTSUM:
1733 if (size != mp->m_rsumsize) {
1734 do_warn(
1735 _("realtime summary inode %" PRIu64 " has bad size %" PRId64 " (should be %d)\n"),
1736 lino, size, mp->m_rsumsize);
1737 return 1;
1738 }
1739 break;
1740
1741 default:
1742 break;
1743 }
1744 return 0;
1745 }
1746
1747 /*
1748 * check for illegal values of forkoff
1749 */
1750 static int
1751 process_check_inode_forkoff(
1752 xfs_mount_t *mp,
1753 xfs_dinode_t *dino,
1754 xfs_ino_t lino)
1755 {
1756 if (dino->di_forkoff == 0)
1757 return 0;
1758
1759 switch (dino->di_format) {
1760 case XFS_DINODE_FMT_DEV:
1761 if (dino->di_forkoff != (roundup(sizeof(xfs_dev_t), 8) >> 3)) {
1762 do_warn(
1763 _("bad attr fork offset %d in dev inode %" PRIu64 ", should be %d\n"),
1764 dino->di_forkoff, lino,
1765 (int)(roundup(sizeof(xfs_dev_t), 8) >> 3));
1766 return 1;
1767 }
1768 break;
1769 case XFS_DINODE_FMT_LOCAL: /* fall through ... */
1770 case XFS_DINODE_FMT_EXTENTS: /* fall through ... */
1771 case XFS_DINODE_FMT_BTREE:
1772 if (dino->di_forkoff >=
1773 (XFS_LITINO(mp, dino->di_version) >> 3)) {
1774 do_warn(
1775 _("bad attr fork offset %d in inode %" PRIu64 ", max=%d\n"),
1776 dino->di_forkoff, lino,
1777 XFS_LITINO(mp, dino->di_version) >> 3);
1778 return 1;
1779 }
1780 break;
1781 default:
1782 do_error(_("unexpected inode format %d\n"), dino->di_format);
1783 break;
1784 }
1785 return 0;
1786 }
1787
1788 /*
1789 * Updates the inodes block and extent counts if they are wrong
1790 */
1791 static int
1792 process_inode_blocks_and_extents(
1793 xfs_dinode_t *dino,
1794 xfs_rfsblock_t nblocks,
1795 __uint64_t nextents,
1796 __uint64_t anextents,
1797 xfs_ino_t lino,
1798 int *dirty)
1799 {
1800 if (nblocks != be64_to_cpu(dino->di_nblocks)) {
1801 if (!no_modify) {
1802 do_warn(
1803 _("correcting nblocks for inode %" PRIu64 ", was %llu - counted %" PRIu64 "\n"), lino,
1804 (unsigned long long) be64_to_cpu(dino->di_nblocks),
1805 nblocks);
1806 dino->di_nblocks = cpu_to_be64(nblocks);
1807 *dirty = 1;
1808 } else {
1809 do_warn(
1810 _("bad nblocks %llu for inode %" PRIu64 ", would reset to %" PRIu64 "\n"),
1811 (unsigned long long) be64_to_cpu(dino->di_nblocks),
1812 lino, nblocks);
1813 }
1814 }
1815
1816 if (nextents > MAXEXTNUM) {
1817 do_warn(
1818 _("too many data fork extents (%" PRIu64 ") in inode %" PRIu64 "\n"),
1819 nextents, lino);
1820 return 1;
1821 }
1822 if (nextents != be32_to_cpu(dino->di_nextents)) {
1823 if (!no_modify) {
1824 do_warn(
1825 _("correcting nextents for inode %" PRIu64 ", was %d - counted %" PRIu64 "\n"),
1826 lino,
1827 be32_to_cpu(dino->di_nextents),
1828 nextents);
1829 dino->di_nextents = cpu_to_be32(nextents);
1830 *dirty = 1;
1831 } else {
1832 do_warn(
1833 _("bad nextents %d for inode %" PRIu64 ", would reset to %" PRIu64 "\n"),
1834 be32_to_cpu(dino->di_nextents),
1835 lino, nextents);
1836 }
1837 }
1838
1839 if (anextents > MAXAEXTNUM) {
1840 do_warn(
1841 _("too many attr fork extents (%" PRIu64 ") in inode %" PRIu64 "\n"),
1842 anextents, lino);
1843 return 1;
1844 }
1845 if (anextents != be16_to_cpu(dino->di_anextents)) {
1846 if (!no_modify) {
1847 do_warn(
1848 _("correcting anextents for inode %" PRIu64 ", was %d - counted %" PRIu64 "\n"),
1849 lino,
1850 be16_to_cpu(dino->di_anextents), anextents);
1851 dino->di_anextents = cpu_to_be16(anextents);
1852 *dirty = 1;
1853 } else {
1854 do_warn(
1855 _("bad anextents %d for inode %" PRIu64 ", would reset to %" PRIu64 "\n"),
1856 be16_to_cpu(dino->di_anextents),
1857 lino, anextents);
1858 }
1859 }
1860
1861 /*
1862 * We are comparing different units here, but that's fine given that
1863 * an extent has to have at least a block in it.
1864 */
1865 if (nblocks < nextents + anextents) {
1866 do_warn(
1867 _("nblocks (%" PRIu64 ") smaller than nextents for inode %" PRIu64 "\n"), nblocks, lino);
1868 return 1;
1869 }
1870
1871 return 0;
1872 }
1873
1874 /*
1875 * check data fork -- if it's bad, clear the inode
1876 */
1877 static int
1878 process_inode_data_fork(
1879 xfs_mount_t *mp,
1880 xfs_agnumber_t agno,
1881 xfs_agino_t ino,
1882 xfs_dinode_t *dino,
1883 int type,
1884 int *dirty,
1885 xfs_rfsblock_t *totblocks,
1886 __uint64_t *nextents,
1887 blkmap_t **dblkmap,
1888 int check_dups)
1889 {
1890 xfs_ino_t lino = XFS_AGINO_TO_INO(mp, agno, ino);
1891 int err = 0;
1892 int nex;
1893
1894 /*
1895 * extent count on disk is only valid for positive values. The kernel
1896 * uses negative values in memory. hence if we see negative numbers
1897 * here, trash it!
1898 */
1899 nex = be32_to_cpu(dino->di_nextents);
1900 if (nex < 0)
1901 *nextents = 1;
1902 else
1903 *nextents = nex;
1904
1905 if (*nextents > be64_to_cpu(dino->di_nblocks))
1906 *nextents = 1;
1907
1908
1909 if (dino->di_format != XFS_DINODE_FMT_LOCAL && type != XR_INO_RTDATA)
1910 *dblkmap = blkmap_alloc(*nextents, XFS_DATA_FORK);
1911 *nextents = 0;
1912
1913 switch (dino->di_format) {
1914 case XFS_DINODE_FMT_LOCAL:
1915 err = process_lclinode(mp, agno, ino, dino, XFS_DATA_FORK);
1916 *totblocks = 0;
1917 break;
1918 case XFS_DINODE_FMT_EXTENTS:
1919 err = process_exinode(mp, agno, ino, dino, type, dirty,
1920 totblocks, nextents, dblkmap, XFS_DATA_FORK,
1921 check_dups);
1922 break;
1923 case XFS_DINODE_FMT_BTREE:
1924 err = process_btinode(mp, agno, ino, dino, type, dirty,
1925 totblocks, nextents, dblkmap, XFS_DATA_FORK,
1926 check_dups);
1927 break;
1928 case XFS_DINODE_FMT_DEV: /* fall through */
1929 err = 0;
1930 break;
1931 default:
1932 do_error(_("unknown format %d, ino %" PRIu64 " (mode = %d)\n"),
1933 dino->di_format, lino, be16_to_cpu(dino->di_mode));
1934 }
1935
1936 if (err) {
1937 do_warn(_("bad data fork in inode %" PRIu64 "\n"), lino);
1938 if (!no_modify) {
1939 *dirty += clear_dinode(mp, dino, lino);
1940 ASSERT(*dirty > 0);
1941 }
1942 return 1;
1943 }
1944
1945 if (check_dups) {
1946 /*
1947 * if check_dups was non-zero, we have to
1948 * re-process data fork to set bitmap since the
1949 * bitmap wasn't set the first time through
1950 */
1951 switch (dino->di_format) {
1952 case XFS_DINODE_FMT_LOCAL:
1953 err = process_lclinode(mp, agno, ino, dino,
1954 XFS_DATA_FORK);
1955 break;
1956 case XFS_DINODE_FMT_EXTENTS:
1957 err = process_exinode(mp, agno, ino, dino, type,
1958 dirty, totblocks, nextents, dblkmap,
1959 XFS_DATA_FORK, 0);
1960 break;
1961 case XFS_DINODE_FMT_BTREE:
1962 err = process_btinode(mp, agno, ino, dino, type,
1963 dirty, totblocks, nextents, dblkmap,
1964 XFS_DATA_FORK, 0);
1965 break;
1966 case XFS_DINODE_FMT_DEV: /* fall through */
1967 err = 0;
1968 break;
1969 default:
1970 do_error(_("unknown format %d, ino %" PRIu64 " (mode = %d)\n"),
1971 dino->di_format, lino,
1972 be16_to_cpu(dino->di_mode));
1973 }
1974
1975 if (no_modify && err != 0)
1976 return 1;
1977
1978 ASSERT(err == 0);
1979 }
1980 return 0;
1981 }
1982
1983 /*
1984 * Process extended attribute fork in inode
1985 */
1986 static int
1987 process_inode_attr_fork(
1988 xfs_mount_t *mp,
1989 xfs_agnumber_t agno,
1990 xfs_agino_t ino,
1991 xfs_dinode_t *dino,
1992 int type,
1993 int *dirty,
1994 xfs_rfsblock_t *atotblocks,
1995 __uint64_t *anextents,
1996 int check_dups,
1997 int extra_attr_check,
1998 int *retval)
1999 {
2000 xfs_ino_t lino = XFS_AGINO_TO_INO(mp, agno, ino);
2001 blkmap_t *ablkmap = NULL;
2002 int repair = 0;
2003 int err;
2004
2005 if (!XFS_DFORK_Q(dino)) {
2006 *anextents = 0;
2007 if (dino->di_aformat != XFS_DINODE_FMT_EXTENTS) {
2008 do_warn(_("bad attribute format %d in inode %" PRIu64 ", "),
2009 dino->di_aformat, lino);
2010 if (!no_modify) {
2011 do_warn(_("resetting value\n"));
2012 dino->di_aformat = XFS_DINODE_FMT_EXTENTS;
2013 *dirty = 1;
2014 } else
2015 do_warn(_("would reset value\n"));
2016 }
2017 return 0;
2018 }
2019
2020 *anextents = be16_to_cpu(dino->di_anextents);
2021 if (*anextents > be64_to_cpu(dino->di_nblocks))
2022 *anextents = 1;
2023
2024 switch (dino->di_aformat) {
2025 case XFS_DINODE_FMT_LOCAL:
2026 *anextents = 0;
2027 *atotblocks = 0;
2028 err = process_lclinode(mp, agno, ino, dino, XFS_ATTR_FORK);
2029 break;
2030 case XFS_DINODE_FMT_EXTENTS:
2031 ablkmap = blkmap_alloc(*anextents, XFS_ATTR_FORK);
2032 *anextents = 0;
2033 err = process_exinode(mp, agno, ino, dino, type, dirty,
2034 atotblocks, anextents, &ablkmap,
2035 XFS_ATTR_FORK, check_dups);
2036 break;
2037 case XFS_DINODE_FMT_BTREE:
2038 ablkmap = blkmap_alloc(*anextents, XFS_ATTR_FORK);
2039 *anextents = 0;
2040 err = process_btinode(mp, agno, ino, dino, type, dirty,
2041 atotblocks, anextents, &ablkmap,
2042 XFS_ATTR_FORK, check_dups);
2043 break;
2044 default:
2045 do_warn(_("illegal attribute format %d, ino %" PRIu64 "\n"),
2046 dino->di_aformat, lino);
2047 err = 1;
2048 break;
2049 }
2050
2051 if (err) {
2052 /*
2053 * clear the attribute fork if necessary. we can't
2054 * clear the inode because we've already put the
2055 * inode space info into the blockmap.
2056 *
2057 * XXX - put the inode onto the "move it" list and
2058 * log the the attribute scrubbing
2059 */
2060 do_warn(_("bad attribute fork in inode %" PRIu64), lino);
2061
2062 if (!no_modify) {
2063 if (delete_attr_ok) {
2064 do_warn(_(", clearing attr fork\n"));
2065 *dirty += clear_dinode_attr(mp, dino, lino);
2066 dino->di_aformat = XFS_DINODE_FMT_LOCAL;
2067 } else {
2068 do_warn("\n");
2069 *dirty += clear_dinode(mp, dino, lino);
2070 }
2071 ASSERT(*dirty > 0);
2072 } else {
2073 do_warn(_(", would clear attr fork\n"));
2074 }
2075
2076 *atotblocks = 0;
2077 *anextents = 0;
2078 blkmap_free(ablkmap);
2079 *retval = 1;
2080
2081 return delete_attr_ok ? 0 : 1;
2082 }
2083
2084 if (check_dups) {
2085 switch (dino->di_aformat) {
2086 case XFS_DINODE_FMT_LOCAL:
2087 err = process_lclinode(mp, agno, ino, dino,
2088 XFS_ATTR_FORK);
2089 break;
2090 case XFS_DINODE_FMT_EXTENTS:
2091 err = process_exinode(mp, agno, ino, dino,
2092 type, dirty, atotblocks, anextents,
2093 &ablkmap, XFS_ATTR_FORK, 0);
2094 break;
2095 case XFS_DINODE_FMT_BTREE:
2096 err = process_btinode(mp, agno, ino, dino,
2097 type, dirty, atotblocks, anextents,
2098 &ablkmap, XFS_ATTR_FORK, 0);
2099 break;
2100 default:
2101 do_error(_("illegal attribute fmt %d, ino %" PRIu64 "\n"),
2102 dino->di_aformat, lino);
2103 }
2104
2105 if (no_modify && err != 0) {
2106 blkmap_free(ablkmap);
2107 return 1;
2108 }
2109
2110 ASSERT(err == 0);
2111 }
2112
2113 /*
2114 * do attribute semantic-based consistency checks now
2115 */
2116
2117 /* get this only in phase 3, not in both phase 3 and 4 */
2118 if (extra_attr_check &&
2119 process_attributes(mp, lino, dino, ablkmap, &repair)) {
2120 do_warn(
2121 _("problem with attribute contents in inode %" PRIu64 "\n"),
2122 lino);
2123 if (!repair) {
2124 /* clear attributes if not done already */
2125 if (!no_modify) {
2126 *dirty += clear_dinode_attr(mp, dino, lino);
2127 dino->di_aformat = XFS_DINODE_FMT_LOCAL;
2128 } else {
2129 do_warn(_("would clear attr fork\n"));
2130 }
2131 *atotblocks = 0;
2132 *anextents = 0;
2133 }
2134 else {
2135 *dirty = 1; /* it's been repaired */
2136 }
2137 }
2138 blkmap_free(ablkmap);
2139 return 0;
2140 }
2141
2142 /*
2143 * check nlinks feature, if it's a version 1 inode,
2144 * just leave nlinks alone. even if it's set wrong,
2145 * it'll be reset when read in.
2146 */
2147
2148 static int
2149 process_check_inode_nlink_version(
2150 xfs_dinode_t *dino,
2151 xfs_ino_t lino)
2152 {
2153 int dirty = 0;
2154
2155 /*
2156 * if it's a version 2 inode, it should have a zero
2157 * onlink field, so clear it.
2158 */
2159 if (dino->di_version > 1 && dino->di_onlink != 0) {
2160 if (!no_modify) {
2161 do_warn(
2162 _("clearing obsolete nlink field in version 2 inode %" PRIu64 ", was %d, now 0\n"),
2163 lino, be16_to_cpu(dino->di_onlink));
2164 dino->di_onlink = 0;
2165 dirty = 1;
2166 } else {
2167 do_warn(
2168 _("would clear obsolete nlink field in version 2 inode %" PRIu64 ", currently %d\n"),
2169 lino, be16_to_cpu(dino->di_onlink));
2170 }
2171 }
2172 return dirty;
2173 }
2174
2175 /*
2176 * returns 0 if the inode is ok, 1 if the inode is corrupt
2177 * check_dups can be set to 1 *only* when called by the
2178 * first pass of the duplicate block checking of phase 4.
2179 * *dirty is set > 0 if the dinode has been altered and
2180 * needs to be written out.
2181 *
2182 * for detailed, info, look at process_dinode() comments.
2183 */
2184 static int
2185 process_dinode_int(xfs_mount_t *mp,
2186 xfs_dinode_t *dino,
2187 xfs_agnumber_t agno,
2188 xfs_agino_t ino,
2189 int was_free, /* 1 if inode is currently free */
2190 int *dirty, /* out == > 0 if inode is now dirty */
2191 int *used, /* out == 1 if inode is in use */
2192 int verify_mode, /* 1 == verify but don't modify inode */
2193 int uncertain, /* 1 == inode is uncertain */
2194 int ino_discovery, /* 1 == check dirs for unknown inodes */
2195 int check_dups, /* 1 == check if inode claims
2196 * duplicate blocks */
2197 int extra_attr_check, /* 1 == do attribute format and value checks */
2198 int *isa_dir, /* out == 1 if inode is a directory */
2199 xfs_ino_t *parent) /* out -- parent if ino is a dir */
2200 {
2201 xfs_rfsblock_t totblocks = 0;
2202 xfs_rfsblock_t atotblocks = 0;
2203 int di_mode;
2204 int type;
2205 int retval = 0;
2206 __uint64_t nextents;
2207 __uint64_t anextents;
2208 xfs_ino_t lino;
2209 const int is_free = 0;
2210 const int is_used = 1;
2211 blkmap_t *dblkmap = NULL;
2212
2213 *dirty = *isa_dir = 0;
2214 *used = is_used;
2215 type = XR_INO_UNKNOWN;
2216
2217 lino = XFS_AGINO_TO_INO(mp, agno, ino);
2218 di_mode = be16_to_cpu(dino->di_mode);
2219
2220 /*
2221 * if in verify mode, don't modify the inode.
2222 *
2223 * if correcting, reset stuff that has known values
2224 *
2225 * if in uncertain mode, be silent on errors since we're
2226 * trying to find out if these are inodes as opposed
2227 * to assuming that they are. Just return the appropriate
2228 * return code in that case.
2229 *
2230 * If uncertain is set, verify_mode MUST be set.
2231 */
2232 ASSERT(uncertain == 0 || verify_mode != 0);
2233
2234 /*
2235 * This is the only valid point to check the CRC; after this we may have
2236 * made changes which invalidate it, and the CRC is only updated again
2237 * when it gets written out.
2238 *
2239 * Of course if we make any modifications after this, the inode gets
2240 * rewritten, and the CRC is updated automagically.
2241 */
2242 if (xfs_sb_version_hascrc(&mp->m_sb) &&
2243 !libxfs_verify_cksum((char *)dino, mp->m_sb.sb_inodesize,
2244 XFS_DINODE_CRC_OFF)) {
2245 retval = 1;
2246 if (!uncertain)
2247 do_warn(_("bad CRC for inode %" PRIu64 "%c"),
2248 lino, verify_mode ? '\n' : ',');
2249 if (!verify_mode) {
2250 if (!no_modify) {
2251 do_warn(_(" will rewrite\n"));
2252 *dirty = 1;
2253 } else
2254 do_warn(_(" would rewrite\n"));
2255 }
2256 }
2257
2258 if (be16_to_cpu(dino->di_magic) != XFS_DINODE_MAGIC) {
2259 retval = 1;
2260 if (!uncertain)
2261 do_warn(_("bad magic number 0x%x on inode %" PRIu64 "%c"),
2262 be16_to_cpu(dino->di_magic), lino,
2263 verify_mode ? '\n' : ',');
2264 if (!verify_mode) {
2265 if (!no_modify) {
2266 do_warn(_(" resetting magic number\n"));
2267 dino->di_magic = cpu_to_be16(XFS_DINODE_MAGIC);
2268 *dirty = 1;
2269 } else
2270 do_warn(_(" would reset magic number\n"));
2271 }
2272 }
2273
2274 if (!libxfs_dinode_good_version(mp, dino->di_version)) {
2275 retval = 1;
2276 if (!uncertain)
2277 do_warn(_("bad version number 0x%x on inode %" PRIu64 "%c"),
2278 (__s8)dino->di_version, lino,
2279 verify_mode ? '\n' : ',');
2280 if (!verify_mode) {
2281 if (!no_modify) {
2282 do_warn(_(" resetting version number\n"));
2283 dino->di_version =
2284 xfs_sb_version_hascrc(&mp->m_sb) ? 3 : 2;
2285 *dirty = 1;
2286 } else
2287 do_warn(_(" would reset version number\n"));
2288 }
2289 }
2290
2291 /*
2292 * We don't bother checking the CRC here - we cannot guarantee that when
2293 * we are called here that the inode has not already been modified in
2294 * memory and hence invalidated the CRC.
2295 */
2296 if (xfs_sb_version_hascrc(&mp->m_sb)) {
2297 if (be64_to_cpu(dino->di_ino) != lino) {
2298 if (!uncertain)
2299 do_warn(
2300 _("inode identifier %llu mismatch on inode %" PRIu64 "\n"),
2301 be64_to_cpu(dino->di_ino), lino);
2302 if (verify_mode)
2303 return 1;
2304 goto clear_bad_out;
2305 }
2306 if (platform_uuid_compare(&dino->di_uuid,
2307 &mp->m_sb.sb_meta_uuid)) {
2308 if (!uncertain)
2309 do_warn(
2310 _("UUID mismatch on inode %" PRIu64 "\n"), lino);
2311 if (verify_mode)
2312 return 1;
2313 goto clear_bad_out;
2314 }
2315 }
2316
2317 /*
2318 * blow out of here if the inode size is < 0
2319 */
2320 if ((xfs_fsize_t)be64_to_cpu(dino->di_size) < 0) {
2321 if (!uncertain)
2322 do_warn(
2323 _("bad (negative) size %" PRId64 " on inode %" PRIu64 "\n"),
2324 (__int64_t)be64_to_cpu(dino->di_size),
2325 lino);
2326 if (verify_mode)
2327 return 1;
2328 goto clear_bad_out;
2329 }
2330
2331 /*
2332 * if not in verify mode, check to sii if the inode and imap
2333 * agree that the inode is free
2334 */
2335 if (!verify_mode && di_mode == 0) {
2336 /*
2337 * was_free value is not meaningful if we're in verify mode
2338 */
2339 if (was_free) {
2340 /*
2341 * easy case, inode free -- inode and map agree, clear
2342 * it just in case to ensure that format, etc. are
2343 * set correctly
2344 */
2345 if (!no_modify)
2346 *dirty += clear_dinode(mp, dino, lino);
2347 *used = is_free;
2348 return 0;
2349 }
2350 /*
2351 * the inode looks free but the map says it's in use.
2352 * clear the inode just to be safe and mark the inode
2353 * free.
2354 */
2355 do_warn(
2356 _("imap claims a free inode %" PRIu64 " is in use, "), lino);
2357 if (!no_modify) {
2358 do_warn(_("correcting imap and clearing inode\n"));
2359 *dirty += clear_dinode(mp, dino, lino);
2360 retval = 1;
2361 } else
2362 do_warn(_("would correct imap and clear inode\n"));
2363 *used = is_free;
2364 return retval;
2365 }
2366
2367 /*
2368 * because of the lack of any write ordering guarantee, it's
2369 * possible that the core got updated but the forks didn't.
2370 * so rather than be ambitious (and probably incorrect),
2371 * if there's an inconsistency, we get conservative and
2372 * just pitch the file. blow off checking formats of
2373 * free inodes since technically any format is legal
2374 * as we reset the inode when we re-use it.
2375 */
2376 if (di_mode != 0 && check_dinode_mode_format(dino) != 0) {
2377 if (!uncertain)
2378 do_warn(
2379 _("bad inode format in inode %" PRIu64 "\n"), lino);
2380 if (verify_mode)
2381 return 1;
2382 goto clear_bad_out;
2383 }
2384
2385 /*
2386 * check that we only have valid flags set, and those that are set make
2387 * sense.
2388 */
2389 if (dino->di_flags) {
2390 uint16_t flags = be16_to_cpu(dino->di_flags);
2391
2392 if (flags & ~XFS_DIFLAG_ANY) {
2393 if (!uncertain) {
2394 do_warn(
2395 _("Bad flags set in inode %" PRIu64 "\n"),
2396 lino);
2397 }
2398 flags &= XFS_DIFLAG_ANY;
2399 }
2400
2401 if (flags & (XFS_DIFLAG_REALTIME | XFS_DIFLAG_RTINHERIT)) {
2402 /* need an rt-dev! */
2403 if (!rt_name) {
2404 if (!uncertain) {
2405 do_warn(
2406 _("inode %" PRIu64 " has RT flag set but there is no RT device\n"),
2407 lino);
2408 }
2409 flags &= ~(XFS_DIFLAG_REALTIME |
2410 XFS_DIFLAG_RTINHERIT);
2411 }
2412 }
2413 if (flags & XFS_DIFLAG_NEWRTBM) {
2414 /* must be a rt bitmap inode */
2415 if (lino != mp->m_sb.sb_rbmino) {
2416 if (!uncertain) {
2417 do_warn(
2418 _("inode %" PRIu64 " not rt bitmap\n"),
2419 lino);
2420 }
2421 flags &= ~XFS_DIFLAG_NEWRTBM;
2422 }
2423 }
2424 if (flags & (XFS_DIFLAG_RTINHERIT |
2425 XFS_DIFLAG_EXTSZINHERIT |
2426 XFS_DIFLAG_PROJINHERIT |
2427 XFS_DIFLAG_NOSYMLINKS)) {
2428 /* must be a directory */
2429 if (di_mode && !S_ISDIR(di_mode)) {
2430 if (!uncertain) {
2431 do_warn(
2432 _("directory flags set on non-directory inode %" PRIu64 "\n" ),
2433 lino);
2434 }
2435 flags &= ~(XFS_DIFLAG_RTINHERIT |
2436 XFS_DIFLAG_EXTSZINHERIT |
2437 XFS_DIFLAG_PROJINHERIT |
2438 XFS_DIFLAG_NOSYMLINKS);
2439 }
2440 }
2441 if (flags & (XFS_DIFLAG_REALTIME | FS_XFLAG_EXTSIZE)) {
2442 /* must be a file */
2443 if (di_mode && !S_ISREG(di_mode)) {
2444 if (!uncertain) {
2445 do_warn(
2446 _("file flags set on non-file inode %" PRIu64 "\n"),
2447 lino);
2448 }
2449 flags &= ~(XFS_DIFLAG_REALTIME |
2450 FS_XFLAG_EXTSIZE);
2451 }
2452 }
2453 if (!verify_mode && flags != be16_to_cpu(dino->di_flags)) {
2454 if (!no_modify) {
2455 do_warn(_("fixing bad flags.\n"));
2456 dino->di_flags = cpu_to_be16(flags);
2457 *dirty = 1;
2458 } else
2459 do_warn(_("would fix bad flags.\n"));
2460 }
2461 }
2462
2463 if (verify_mode)
2464 return retval;
2465
2466 /*
2467 * clear the next unlinked field if necessary on a good
2468 * inode only during phase 4 -- when checking for inodes
2469 * referencing duplicate blocks. then it's safe because
2470 * we've done the inode discovery and have found all the inodes
2471 * we're going to find. check_dups is set to 1 only during
2472 * phase 4. Ugly.
2473 */
2474 if (check_dups && !no_modify)
2475 *dirty += clear_dinode_unlinked(mp, dino);
2476
2477 /* set type and map type info */
2478
2479 switch (di_mode & S_IFMT) {
2480 case S_IFDIR:
2481 type = XR_INO_DIR;
2482 *isa_dir = 1;
2483 break;
2484 case S_IFREG:
2485 if (be16_to_cpu(dino->di_flags) & XFS_DIFLAG_REALTIME)
2486 type = XR_INO_RTDATA;
2487 else if (lino == mp->m_sb.sb_rbmino)
2488 type = XR_INO_RTBITMAP;
2489 else if (lino == mp->m_sb.sb_rsumino)
2490 type = XR_INO_RTSUM;
2491 else
2492 type = XR_INO_DATA;
2493 break;
2494 case S_IFLNK:
2495 type = XR_INO_SYMLINK;
2496 break;
2497 case S_IFCHR:
2498 type = XR_INO_CHRDEV;
2499 break;
2500 case S_IFBLK:
2501 type = XR_INO_BLKDEV;
2502 break;
2503 case S_IFSOCK:
2504 type = XR_INO_SOCK;
2505 break;
2506 case S_IFIFO:
2507 type = XR_INO_FIFO;
2508 break;
2509 default:
2510 do_warn(_("bad inode type %#o inode %" PRIu64 "\n"),
2511 di_mode & S_IFMT, lino);
2512 goto clear_bad_out;
2513 }
2514
2515 /*
2516 * type checks for superblock inodes
2517 */
2518 if (process_check_sb_inodes(mp, dino, lino, &type, dirty) != 0)
2519 goto clear_bad_out;
2520
2521 /*
2522 * only regular files with REALTIME or EXTSIZE flags set can have
2523 * extsize set, or directories with EXTSZINHERIT.
2524 */
2525 if (be32_to_cpu(dino->di_extsize) != 0) {
2526 if ((type == XR_INO_RTDATA) ||
2527 (type == XR_INO_DIR && (be16_to_cpu(dino->di_flags) &
2528 XFS_DIFLAG_EXTSZINHERIT)) ||
2529 (type == XR_INO_DATA && (be16_to_cpu(dino->di_flags) &
2530 XFS_DIFLAG_EXTSIZE))) {
2531 /* s'okay */ ;
2532 } else {
2533 do_warn(
2534 _("bad non-zero extent size %u for non-realtime/extsize inode %" PRIu64 ", "),
2535 be32_to_cpu(dino->di_extsize), lino);
2536 if (!no_modify) {
2537 do_warn(_("resetting to zero\n"));
2538 dino->di_extsize = 0;
2539 *dirty = 1;
2540 } else
2541 do_warn(_("would reset to zero\n"));
2542 }
2543 }
2544
2545 /*
2546 * general size/consistency checks:
2547 */
2548 if (process_check_inode_sizes(mp, dino, lino, type) != 0)
2549 goto clear_bad_out;
2550
2551 /*
2552 * check for illegal values of forkoff
2553 */
2554 if (process_check_inode_forkoff(mp, dino, lino) != 0)
2555 goto clear_bad_out;
2556
2557 /*
2558 * check data fork -- if it's bad, clear the inode
2559 */
2560 if (process_inode_data_fork(mp, agno, ino, dino, type, dirty,
2561 &totblocks, &nextents, &dblkmap, check_dups) != 0)
2562 goto bad_out;
2563
2564 /*
2565 * check attribute fork if necessary. attributes are
2566 * always stored in the regular filesystem.
2567 */
2568 if (process_inode_attr_fork(mp, agno, ino, dino, type, dirty,
2569 &atotblocks, &anextents, check_dups, extra_attr_check,
2570 &retval))
2571 goto bad_out;
2572
2573 /*
2574 * enforce totblocks is 0 for misc types
2575 */
2576 if (process_misc_ino_types_blocks(totblocks, lino, type))
2577 goto clear_bad_out;
2578
2579 /*
2580 * correct space counters if required
2581 */
2582 if (process_inode_blocks_and_extents(dino, totblocks + atotblocks,
2583 nextents, anextents, lino, dirty) != 0)
2584 goto clear_bad_out;
2585
2586 /*
2587 * do any semantic type-based checking here
2588 */
2589 switch (type) {
2590 case XR_INO_DIR:
2591 if (process_dir2(mp, lino, dino, ino_discovery,
2592 dirty, "", parent, dblkmap)) {
2593 do_warn(
2594 _("problem with directory contents in inode %" PRIu64 "\n"),
2595 lino);
2596 goto clear_bad_out;
2597 }
2598 break;
2599 case XR_INO_SYMLINK:
2600 if (process_symlink(mp, lino, dino, dblkmap) != 0) {
2601 do_warn(
2602 _("problem with symbolic link in inode %" PRIu64 "\n"),
2603 lino);
2604 goto clear_bad_out;
2605 }
2606 break;
2607 default:
2608 break;
2609 }
2610
2611 blkmap_free(dblkmap);
2612
2613 /*
2614 * check nlinks feature, if it's a version 1 inode,
2615 * just leave nlinks alone. even if it's set wrong,
2616 * it'll be reset when read in.
2617 */
2618 *dirty += process_check_inode_nlink_version(dino, lino);
2619
2620 return retval;
2621
2622 clear_bad_out:
2623 if (!no_modify) {
2624 *dirty += clear_dinode(mp, dino, lino);
2625 ASSERT(*dirty > 0);
2626 }
2627 bad_out:
2628 *used = is_free;
2629 *isa_dir = 0;
2630 blkmap_free(dblkmap);
2631 return 1;
2632 }
2633
2634 /*
2635 * returns 1 if inode is used, 0 if free.
2636 * performs any necessary salvaging actions.
2637 * note that we leave the generation count alone
2638 * because nothing we could set it to would be
2639 * guaranteed to be correct so the best guess for
2640 * the correct value is just to leave it alone.
2641 *
2642 * The trick is detecting empty files. For those,
2643 * the core and the forks should all be in the "empty"
2644 * or zero-length state -- a zero or possibly minimum length
2645 * (in the case of dirs) extent list -- although inline directories
2646 * and symlinks might be handled differently. So it should be
2647 * possible to sanity check them against each other.
2648 *
2649 * If the forks are an empty extent list though, then forget it.
2650 * The file is toast anyway since we can't recover its storage.
2651 *
2652 * Parameters:
2653 * Ins:
2654 * mp -- mount structure
2655 * dino -- pointer to on-disk inode structure
2656 * agno/ino -- inode numbers
2657 * free -- whether the map thinks the inode is free (1 == free)
2658 * ino_discovery -- whether we should examine directory
2659 * contents to discover new inodes
2660 * check_dups -- whether we should check to see if the
2661 * inode references duplicate blocks
2662 * if so, we compare the inode's claimed
2663 * blocks against the contents of the
2664 * duplicate extent list but we don't
2665 * set the bitmap. If not, we set the
2666 * bitmap and try and detect multiply
2667 * claimed blocks using the bitmap.
2668 * Outs:
2669 * dirty -- whether we changed the inode (1 == yes)
2670 * used -- 1 if the inode is used, 0 if free. In no modify
2671 * mode, whether the inode should be used or free
2672 * isa_dir -- 1 if the inode is a directory, 0 if not. In
2673 * no modify mode, if the inode would be a dir or not.
2674 *
2675 * Return value -- 0 if the inode is good, 1 if it is/was corrupt
2676 */
2677
2678 int
2679 process_dinode(
2680 xfs_mount_t *mp,
2681 xfs_dinode_t *dino,
2682 xfs_agnumber_t agno,
2683 xfs_agino_t ino,
2684 int was_free,
2685 int *dirty,
2686 int *used,
2687 int ino_discovery,
2688 int check_dups,
2689 int extra_attr_check,
2690 int *isa_dir,
2691 xfs_ino_t *parent)
2692 {
2693 const int verify_mode = 0;
2694 const int uncertain = 0;
2695
2696 #ifdef XR_INODE_TRACE
2697 fprintf(stderr, _("processing inode %d/%d\n"), agno, ino);
2698 #endif
2699 return process_dinode_int(mp, dino, agno, ino, was_free, dirty, used,
2700 verify_mode, uncertain, ino_discovery,
2701 check_dups, extra_attr_check, isa_dir, parent);
2702 }
2703
2704 /*
2705 * a more cursory check, check inode core, *DON'T* check forks
2706 * this basically just verifies whether the inode is an inode
2707 * and whether or not it has been totally trashed. returns 0
2708 * if the inode passes the cursory sanity check, 1 otherwise.
2709 */
2710 int
2711 verify_dinode(
2712 xfs_mount_t *mp,
2713 xfs_dinode_t *dino,
2714 xfs_agnumber_t agno,
2715 xfs_agino_t ino)
2716 {
2717 xfs_ino_t parent;
2718 int used = 0;
2719 int dirty = 0;
2720 int isa_dir = 0;
2721 const int verify_mode = 1;
2722 const int check_dups = 0;
2723 const int ino_discovery = 0;
2724 const int uncertain = 0;
2725
2726 return process_dinode_int(mp, dino, agno, ino, 0, &dirty, &used,
2727 verify_mode, uncertain, ino_discovery,
2728 check_dups, 0, &isa_dir, &parent);
2729 }
2730
2731 /*
2732 * like above only for inode on the uncertain list. it sets
2733 * the uncertain flag which makes process_dinode_int quieter.
2734 * returns 0 if the inode passes the cursory sanity check, 1 otherwise.
2735 */
2736 int
2737 verify_uncertain_dinode(
2738 xfs_mount_t *mp,
2739 xfs_dinode_t *dino,
2740 xfs_agnumber_t agno,
2741 xfs_agino_t ino)
2742 {
2743 xfs_ino_t parent;
2744 int used = 0;
2745 int dirty = 0;
2746 int isa_dir = 0;
2747 const int verify_mode = 1;
2748 const int check_dups = 0;
2749 const int ino_discovery = 0;
2750 const int uncertain = 1;
2751
2752 return process_dinode_int(mp, dino, agno, ino, 0, &dirty, &used,
2753 verify_mode, uncertain, ino_discovery,
2754 check_dups, 0, &isa_dir, &parent);
2755 }