inode.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2017 Oracle. All Rights Reserved.
  4. * Author: Darrick J. Wong <[email protected]>
  5. */
  6. #include "xfs.h"
  7. #include "xfs_fs.h"
  8. #include "xfs_shared.h"
  9. #include "xfs_format.h"
  10. #include "xfs_trans_resv.h"
  11. #include "xfs_mount.h"
  12. #include "xfs_btree.h"
  13. #include "xfs_log_format.h"
  14. #include "xfs_inode.h"
  15. #include "xfs_ialloc.h"
  16. #include "xfs_da_format.h"
  17. #include "xfs_reflink.h"
  18. #include "xfs_rmap.h"
  19. #include "xfs_bmap_util.h"
  20. #include "scrub/scrub.h"
  21. #include "scrub/common.h"
  22. #include "scrub/btree.h"
  23. /*
  24. * Grab total control of the inode metadata. It doesn't matter here if
  25. * the file data is still changing; exclusive access to the metadata is
  26. * the goal.
  27. */
  28. int
  29. xchk_setup_inode(
  30. struct xfs_scrub *sc)
  31. {
  32. int error;
  33. /*
  34. * Try to get the inode. If the verifiers fail, we try again
  35. * in raw mode.
  36. */
  37. error = xchk_get_inode(sc);
  38. switch (error) {
  39. case 0:
  40. break;
  41. case -EFSCORRUPTED:
  42. case -EFSBADCRC:
  43. return xchk_trans_alloc(sc, 0);
  44. default:
  45. return error;
  46. }
  47. /* Got the inode, lock it and we're ready to go. */
  48. sc->ilock_flags = XFS_IOLOCK_EXCL | XFS_MMAPLOCK_EXCL;
  49. xfs_ilock(sc->ip, sc->ilock_flags);
  50. error = xchk_trans_alloc(sc, 0);
  51. if (error)
  52. goto out;
  53. sc->ilock_flags |= XFS_ILOCK_EXCL;
  54. xfs_ilock(sc->ip, XFS_ILOCK_EXCL);
  55. out:
  56. /* scrub teardown will unlock and release the inode for us */
  57. return error;
  58. }
  59. /* Inode core */
  60. /* Validate di_extsize hint. */
  61. STATIC void
  62. xchk_inode_extsize(
  63. struct xfs_scrub *sc,
  64. struct xfs_dinode *dip,
  65. xfs_ino_t ino,
  66. uint16_t mode,
  67. uint16_t flags)
  68. {
  69. xfs_failaddr_t fa;
  70. uint32_t value = be32_to_cpu(dip->di_extsize);
  71. fa = xfs_inode_validate_extsize(sc->mp, value, mode, flags);
  72. if (fa)
  73. xchk_ino_set_corrupt(sc, ino);
  74. /*
  75. * XFS allows a sysadmin to change the rt extent size when adding a rt
  76. * section to a filesystem after formatting. If there are any
  77. * directories with extszinherit and rtinherit set, the hint could
  78. * become misaligned with the new rextsize. The verifier doesn't check
  79. * this, because we allow rtinherit directories even without an rt
  80. * device. Flag this as an administrative warning since we will clean
  81. * this up eventually.
  82. */
  83. if ((flags & XFS_DIFLAG_RTINHERIT) &&
  84. (flags & XFS_DIFLAG_EXTSZINHERIT) &&
  85. value % sc->mp->m_sb.sb_rextsize > 0)
  86. xchk_ino_set_warning(sc, ino);
  87. }
  88. /*
  89. * Validate di_cowextsize hint.
  90. *
  91. * The rules are documented at xfs_ioctl_setattr_check_cowextsize().
  92. * These functions must be kept in sync with each other.
  93. */
  94. STATIC void
  95. xchk_inode_cowextsize(
  96. struct xfs_scrub *sc,
  97. struct xfs_dinode *dip,
  98. xfs_ino_t ino,
  99. uint16_t mode,
  100. uint16_t flags,
  101. uint64_t flags2)
  102. {
  103. xfs_failaddr_t fa;
  104. fa = xfs_inode_validate_cowextsize(sc->mp,
  105. be32_to_cpu(dip->di_cowextsize), mode, flags,
  106. flags2);
  107. if (fa)
  108. xchk_ino_set_corrupt(sc, ino);
  109. }
  110. /* Make sure the di_flags make sense for the inode. */
  111. STATIC void
  112. xchk_inode_flags(
  113. struct xfs_scrub *sc,
  114. struct xfs_dinode *dip,
  115. xfs_ino_t ino,
  116. uint16_t mode,
  117. uint16_t flags)
  118. {
  119. struct xfs_mount *mp = sc->mp;
  120. /* di_flags are all taken, last bit cannot be used */
  121. if (flags & ~XFS_DIFLAG_ANY)
  122. goto bad;
  123. /* rt flags require rt device */
  124. if ((flags & XFS_DIFLAG_REALTIME) && !mp->m_rtdev_targp)
  125. goto bad;
  126. /* new rt bitmap flag only valid for rbmino */
  127. if ((flags & XFS_DIFLAG_NEWRTBM) && ino != mp->m_sb.sb_rbmino)
  128. goto bad;
  129. /* directory-only flags */
  130. if ((flags & (XFS_DIFLAG_RTINHERIT |
  131. XFS_DIFLAG_EXTSZINHERIT |
  132. XFS_DIFLAG_PROJINHERIT |
  133. XFS_DIFLAG_NOSYMLINKS)) &&
  134. !S_ISDIR(mode))
  135. goto bad;
  136. /* file-only flags */
  137. if ((flags & (XFS_DIFLAG_REALTIME | FS_XFLAG_EXTSIZE)) &&
  138. !S_ISREG(mode))
  139. goto bad;
  140. /* filestreams and rt make no sense */
  141. if ((flags & XFS_DIFLAG_FILESTREAM) && (flags & XFS_DIFLAG_REALTIME))
  142. goto bad;
  143. return;
  144. bad:
  145. xchk_ino_set_corrupt(sc, ino);
  146. }
  147. /* Make sure the di_flags2 make sense for the inode. */
  148. STATIC void
  149. xchk_inode_flags2(
  150. struct xfs_scrub *sc,
  151. struct xfs_dinode *dip,
  152. xfs_ino_t ino,
  153. uint16_t mode,
  154. uint16_t flags,
  155. uint64_t flags2)
  156. {
  157. struct xfs_mount *mp = sc->mp;
  158. /* Unknown di_flags2 could be from a future kernel */
  159. if (flags2 & ~XFS_DIFLAG2_ANY)
  160. xchk_ino_set_warning(sc, ino);
  161. /* reflink flag requires reflink feature */
  162. if ((flags2 & XFS_DIFLAG2_REFLINK) &&
  163. !xfs_has_reflink(mp))
  164. goto bad;
  165. /* cowextsize flag is checked w.r.t. mode separately */
  166. /* file/dir-only flags */
  167. if ((flags2 & XFS_DIFLAG2_DAX) && !(S_ISREG(mode) || S_ISDIR(mode)))
  168. goto bad;
  169. /* file-only flags */
  170. if ((flags2 & XFS_DIFLAG2_REFLINK) && !S_ISREG(mode))
  171. goto bad;
  172. /* realtime and reflink make no sense, currently */
  173. if ((flags & XFS_DIFLAG_REALTIME) && (flags2 & XFS_DIFLAG2_REFLINK))
  174. goto bad;
  175. /* no bigtime iflag without the bigtime feature */
  176. if (xfs_dinode_has_bigtime(dip) && !xfs_has_bigtime(mp))
  177. goto bad;
  178. return;
  179. bad:
  180. xchk_ino_set_corrupt(sc, ino);
  181. }
  182. static inline void
  183. xchk_dinode_nsec(
  184. struct xfs_scrub *sc,
  185. xfs_ino_t ino,
  186. struct xfs_dinode *dip,
  187. const xfs_timestamp_t ts)
  188. {
  189. struct timespec64 tv;
  190. tv = xfs_inode_from_disk_ts(dip, ts);
  191. if (tv.tv_nsec < 0 || tv.tv_nsec >= NSEC_PER_SEC)
  192. xchk_ino_set_corrupt(sc, ino);
  193. }
  194. /* Scrub all the ondisk inode fields. */
  195. STATIC void
  196. xchk_dinode(
  197. struct xfs_scrub *sc,
  198. struct xfs_dinode *dip,
  199. xfs_ino_t ino)
  200. {
  201. struct xfs_mount *mp = sc->mp;
  202. size_t fork_recs;
  203. unsigned long long isize;
  204. uint64_t flags2;
  205. xfs_extnum_t nextents;
  206. xfs_extnum_t naextents;
  207. prid_t prid;
  208. uint16_t flags;
  209. uint16_t mode;
  210. flags = be16_to_cpu(dip->di_flags);
  211. if (dip->di_version >= 3)
  212. flags2 = be64_to_cpu(dip->di_flags2);
  213. else
  214. flags2 = 0;
  215. /* di_mode */
  216. mode = be16_to_cpu(dip->di_mode);
  217. switch (mode & S_IFMT) {
  218. case S_IFLNK:
  219. case S_IFREG:
  220. case S_IFDIR:
  221. case S_IFCHR:
  222. case S_IFBLK:
  223. case S_IFIFO:
  224. case S_IFSOCK:
  225. /* mode is recognized */
  226. break;
  227. default:
  228. xchk_ino_set_corrupt(sc, ino);
  229. break;
  230. }
  231. /* v1/v2 fields */
  232. switch (dip->di_version) {
  233. case 1:
  234. /*
  235. * We autoconvert v1 inodes into v2 inodes on writeout,
  236. * so just mark this inode for preening.
  237. */
  238. xchk_ino_set_preen(sc, ino);
  239. prid = 0;
  240. break;
  241. case 2:
  242. case 3:
  243. if (dip->di_onlink != 0)
  244. xchk_ino_set_corrupt(sc, ino);
  245. if (dip->di_mode == 0 && sc->ip)
  246. xchk_ino_set_corrupt(sc, ino);
  247. if (dip->di_projid_hi != 0 &&
  248. !xfs_has_projid32(mp))
  249. xchk_ino_set_corrupt(sc, ino);
  250. prid = be16_to_cpu(dip->di_projid_lo);
  251. break;
  252. default:
  253. xchk_ino_set_corrupt(sc, ino);
  254. return;
  255. }
  256. if (xfs_has_projid32(mp))
  257. prid |= (prid_t)be16_to_cpu(dip->di_projid_hi) << 16;
  258. /*
  259. * di_uid/di_gid -- -1 isn't invalid, but there's no way that
  260. * userspace could have created that.
  261. */
  262. if (dip->di_uid == cpu_to_be32(-1U) ||
  263. dip->di_gid == cpu_to_be32(-1U))
  264. xchk_ino_set_warning(sc, ino);
  265. /*
  266. * project id of -1 isn't supposed to be valid, but the kernel didn't
  267. * always validate that.
  268. */
  269. if (prid == -1U)
  270. xchk_ino_set_warning(sc, ino);
  271. /* di_format */
  272. switch (dip->di_format) {
  273. case XFS_DINODE_FMT_DEV:
  274. if (!S_ISCHR(mode) && !S_ISBLK(mode) &&
  275. !S_ISFIFO(mode) && !S_ISSOCK(mode))
  276. xchk_ino_set_corrupt(sc, ino);
  277. break;
  278. case XFS_DINODE_FMT_LOCAL:
  279. if (!S_ISDIR(mode) && !S_ISLNK(mode))
  280. xchk_ino_set_corrupt(sc, ino);
  281. break;
  282. case XFS_DINODE_FMT_EXTENTS:
  283. if (!S_ISREG(mode) && !S_ISDIR(mode) && !S_ISLNK(mode))
  284. xchk_ino_set_corrupt(sc, ino);
  285. break;
  286. case XFS_DINODE_FMT_BTREE:
  287. if (!S_ISREG(mode) && !S_ISDIR(mode))
  288. xchk_ino_set_corrupt(sc, ino);
  289. break;
  290. case XFS_DINODE_FMT_UUID:
  291. default:
  292. xchk_ino_set_corrupt(sc, ino);
  293. break;
  294. }
  295. /* di_[amc]time.nsec */
  296. xchk_dinode_nsec(sc, ino, dip, dip->di_atime);
  297. xchk_dinode_nsec(sc, ino, dip, dip->di_mtime);
  298. xchk_dinode_nsec(sc, ino, dip, dip->di_ctime);
  299. /*
  300. * di_size. xfs_dinode_verify checks for things that screw up
  301. * the VFS such as the upper bit being set and zero-length
  302. * symlinks/directories, but we can do more here.
  303. */
  304. isize = be64_to_cpu(dip->di_size);
  305. if (isize & (1ULL << 63))
  306. xchk_ino_set_corrupt(sc, ino);
  307. /* Devices, fifos, and sockets must have zero size */
  308. if (!S_ISDIR(mode) && !S_ISREG(mode) && !S_ISLNK(mode) && isize != 0)
  309. xchk_ino_set_corrupt(sc, ino);
  310. /* Directories can't be larger than the data section size (32G) */
  311. if (S_ISDIR(mode) && (isize == 0 || isize >= XFS_DIR2_SPACE_SIZE))
  312. xchk_ino_set_corrupt(sc, ino);
  313. /* Symlinks can't be larger than SYMLINK_MAXLEN */
  314. if (S_ISLNK(mode) && (isize == 0 || isize >= XFS_SYMLINK_MAXLEN))
  315. xchk_ino_set_corrupt(sc, ino);
  316. /*
  317. * Warn if the running kernel can't handle the kinds of offsets
  318. * needed to deal with the file size. In other words, if the
  319. * pagecache can't cache all the blocks in this file due to
  320. * overly large offsets, flag the inode for admin review.
  321. */
  322. if (isize >= mp->m_super->s_maxbytes)
  323. xchk_ino_set_warning(sc, ino);
  324. /* di_nblocks */
  325. if (flags2 & XFS_DIFLAG2_REFLINK) {
  326. ; /* nblocks can exceed dblocks */
  327. } else if (flags & XFS_DIFLAG_REALTIME) {
  328. /*
  329. * nblocks is the sum of data extents (in the rtdev),
  330. * attr extents (in the datadev), and both forks' bmbt
  331. * blocks (in the datadev). This clumsy check is the
  332. * best we can do without cross-referencing with the
  333. * inode forks.
  334. */
  335. if (be64_to_cpu(dip->di_nblocks) >=
  336. mp->m_sb.sb_dblocks + mp->m_sb.sb_rblocks)
  337. xchk_ino_set_corrupt(sc, ino);
  338. } else {
  339. if (be64_to_cpu(dip->di_nblocks) >= mp->m_sb.sb_dblocks)
  340. xchk_ino_set_corrupt(sc, ino);
  341. }
  342. xchk_inode_flags(sc, dip, ino, mode, flags);
  343. xchk_inode_extsize(sc, dip, ino, mode, flags);
  344. nextents = xfs_dfork_data_extents(dip);
  345. naextents = xfs_dfork_attr_extents(dip);
  346. /* di_nextents */
  347. fork_recs = XFS_DFORK_DSIZE(dip, mp) / sizeof(struct xfs_bmbt_rec);
  348. switch (dip->di_format) {
  349. case XFS_DINODE_FMT_EXTENTS:
  350. if (nextents > fork_recs)
  351. xchk_ino_set_corrupt(sc, ino);
  352. break;
  353. case XFS_DINODE_FMT_BTREE:
  354. if (nextents <= fork_recs)
  355. xchk_ino_set_corrupt(sc, ino);
  356. break;
  357. default:
  358. if (nextents != 0)
  359. xchk_ino_set_corrupt(sc, ino);
  360. break;
  361. }
  362. /* di_forkoff */
  363. if (XFS_DFORK_APTR(dip) >= (char *)dip + mp->m_sb.sb_inodesize)
  364. xchk_ino_set_corrupt(sc, ino);
  365. if (naextents != 0 && dip->di_forkoff == 0)
  366. xchk_ino_set_corrupt(sc, ino);
  367. if (dip->di_forkoff == 0 && dip->di_aformat != XFS_DINODE_FMT_EXTENTS)
  368. xchk_ino_set_corrupt(sc, ino);
  369. /* di_aformat */
  370. if (dip->di_aformat != XFS_DINODE_FMT_LOCAL &&
  371. dip->di_aformat != XFS_DINODE_FMT_EXTENTS &&
  372. dip->di_aformat != XFS_DINODE_FMT_BTREE)
  373. xchk_ino_set_corrupt(sc, ino);
  374. /* di_anextents */
  375. fork_recs = XFS_DFORK_ASIZE(dip, mp) / sizeof(struct xfs_bmbt_rec);
  376. switch (dip->di_aformat) {
  377. case XFS_DINODE_FMT_EXTENTS:
  378. if (naextents > fork_recs)
  379. xchk_ino_set_corrupt(sc, ino);
  380. break;
  381. case XFS_DINODE_FMT_BTREE:
  382. if (naextents <= fork_recs)
  383. xchk_ino_set_corrupt(sc, ino);
  384. break;
  385. default:
  386. if (naextents != 0)
  387. xchk_ino_set_corrupt(sc, ino);
  388. }
  389. if (dip->di_version >= 3) {
  390. xchk_dinode_nsec(sc, ino, dip, dip->di_crtime);
  391. xchk_inode_flags2(sc, dip, ino, mode, flags, flags2);
  392. xchk_inode_cowextsize(sc, dip, ino, mode, flags,
  393. flags2);
  394. }
  395. }
  396. /*
  397. * Make sure the finobt doesn't think this inode is free.
  398. * We don't have to check the inobt ourselves because we got the inode via
  399. * IGET_UNTRUSTED, which checks the inobt for us.
  400. */
  401. static void
  402. xchk_inode_xref_finobt(
  403. struct xfs_scrub *sc,
  404. xfs_ino_t ino)
  405. {
  406. struct xfs_inobt_rec_incore rec;
  407. xfs_agino_t agino;
  408. int has_record;
  409. int error;
  410. if (!sc->sa.fino_cur || xchk_skip_xref(sc->sm))
  411. return;
  412. agino = XFS_INO_TO_AGINO(sc->mp, ino);
  413. /*
  414. * Try to get the finobt record. If we can't get it, then we're
  415. * in good shape.
  416. */
  417. error = xfs_inobt_lookup(sc->sa.fino_cur, agino, XFS_LOOKUP_LE,
  418. &has_record);
  419. if (!xchk_should_check_xref(sc, &error, &sc->sa.fino_cur) ||
  420. !has_record)
  421. return;
  422. error = xfs_inobt_get_rec(sc->sa.fino_cur, &rec, &has_record);
  423. if (!xchk_should_check_xref(sc, &error, &sc->sa.fino_cur) ||
  424. !has_record)
  425. return;
  426. /*
  427. * Otherwise, make sure this record either doesn't cover this inode,
  428. * or that it does but it's marked present.
  429. */
  430. if (rec.ir_startino > agino ||
  431. rec.ir_startino + XFS_INODES_PER_CHUNK <= agino)
  432. return;
  433. if (rec.ir_free & XFS_INOBT_MASK(agino - rec.ir_startino))
  434. xchk_btree_xref_set_corrupt(sc, sc->sa.fino_cur, 0);
  435. }
  436. /* Cross reference the inode fields with the forks. */
  437. STATIC void
  438. xchk_inode_xref_bmap(
  439. struct xfs_scrub *sc,
  440. struct xfs_dinode *dip)
  441. {
  442. xfs_extnum_t nextents;
  443. xfs_filblks_t count;
  444. xfs_filblks_t acount;
  445. int error;
  446. if (xchk_skip_xref(sc->sm))
  447. return;
  448. /* Walk all the extents to check nextents/naextents/nblocks. */
  449. error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_DATA_FORK,
  450. &nextents, &count);
  451. if (!xchk_should_check_xref(sc, &error, NULL))
  452. return;
  453. if (nextents < xfs_dfork_data_extents(dip))
  454. xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino);
  455. error = xfs_bmap_count_blocks(sc->tp, sc->ip, XFS_ATTR_FORK,
  456. &nextents, &acount);
  457. if (!xchk_should_check_xref(sc, &error, NULL))
  458. return;
  459. if (nextents != xfs_dfork_attr_extents(dip))
  460. xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino);
  461. /* Check nblocks against the inode. */
  462. if (count + acount != be64_to_cpu(dip->di_nblocks))
  463. xchk_ino_xref_set_corrupt(sc, sc->ip->i_ino);
  464. }
  465. /* Cross-reference with the other btrees. */
  466. STATIC void
  467. xchk_inode_xref(
  468. struct xfs_scrub *sc,
  469. xfs_ino_t ino,
  470. struct xfs_dinode *dip)
  471. {
  472. xfs_agnumber_t agno;
  473. xfs_agblock_t agbno;
  474. int error;
  475. if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
  476. return;
  477. agno = XFS_INO_TO_AGNO(sc->mp, ino);
  478. agbno = XFS_INO_TO_AGBNO(sc->mp, ino);
  479. error = xchk_ag_init_existing(sc, agno, &sc->sa);
  480. if (!xchk_xref_process_error(sc, agno, agbno, &error))
  481. goto out_free;
  482. xchk_xref_is_used_space(sc, agbno, 1);
  483. xchk_inode_xref_finobt(sc, ino);
  484. xchk_xref_is_owned_by(sc, agbno, 1, &XFS_RMAP_OINFO_INODES);
  485. xchk_xref_is_not_shared(sc, agbno, 1);
  486. xchk_inode_xref_bmap(sc, dip);
  487. out_free:
  488. xchk_ag_free(sc, &sc->sa);
  489. }
  490. /*
  491. * If the reflink iflag disagrees with a scan for shared data fork extents,
  492. * either flag an error (shared extents w/ no flag) or a preen (flag set w/o
  493. * any shared extents). We already checked for reflink iflag set on a non
  494. * reflink filesystem.
  495. */
  496. static void
  497. xchk_inode_check_reflink_iflag(
  498. struct xfs_scrub *sc,
  499. xfs_ino_t ino)
  500. {
  501. struct xfs_mount *mp = sc->mp;
  502. bool has_shared;
  503. int error;
  504. if (!xfs_has_reflink(mp))
  505. return;
  506. error = xfs_reflink_inode_has_shared_extents(sc->tp, sc->ip,
  507. &has_shared);
  508. if (!xchk_xref_process_error(sc, XFS_INO_TO_AGNO(mp, ino),
  509. XFS_INO_TO_AGBNO(mp, ino), &error))
  510. return;
  511. if (xfs_is_reflink_inode(sc->ip) && !has_shared)
  512. xchk_ino_set_preen(sc, ino);
  513. else if (!xfs_is_reflink_inode(sc->ip) && has_shared)
  514. xchk_ino_set_corrupt(sc, ino);
  515. }
  516. /* Scrub an inode. */
  517. int
  518. xchk_inode(
  519. struct xfs_scrub *sc)
  520. {
  521. struct xfs_dinode di;
  522. int error = 0;
  523. /*
  524. * If sc->ip is NULL, that means that the setup function called
  525. * xfs_iget to look up the inode. xfs_iget returned a EFSCORRUPTED
  526. * and a NULL inode, so flag the corruption error and return.
  527. */
  528. if (!sc->ip) {
  529. xchk_ino_set_corrupt(sc, sc->sm->sm_ino);
  530. return 0;
  531. }
  532. /* Scrub the inode core. */
  533. xfs_inode_to_disk(sc->ip, &di, 0);
  534. xchk_dinode(sc, &di, sc->ip->i_ino);
  535. if (sc->sm->sm_flags & XFS_SCRUB_OFLAG_CORRUPT)
  536. goto out;
  537. /*
  538. * Look for discrepancies between file's data blocks and the reflink
  539. * iflag. We already checked the iflag against the file mode when
  540. * we scrubbed the dinode.
  541. */
  542. if (S_ISREG(VFS_I(sc->ip)->i_mode))
  543. xchk_inode_check_reflink_iflag(sc, sc->ip->i_ino);
  544. xchk_inode_xref(sc, sc->ip->i_ino, &di);
  545. out:
  546. return error;
  547. }