1 // SPDX-License-Identifier: GPL-2.0+ 2 /* 3 * Copyright (C) 2018 Oracle. All Rights Reserved. 4 * Author: Darrick J. Wong <darrick.wong@oracle.com> 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_defer.h" 13 #include "xfs_btree.h" 14 #include "xfs_bit.h" 15 #include "xfs_log_format.h" 16 #include "xfs_trans.h" 17 #include "xfs_sb.h" 18 #include "xfs_inode.h" 19 #include "xfs_alloc.h" 20 #include "xfs_ialloc.h" 21 #include "xfs_rmap.h" 22 #include "scrub/xfs_scrub.h" 23 #include "scrub/scrub.h" 24 #include "scrub/common.h" 25 #include "scrub/trace.h" 26 27 /* Superblock */ 28 29 /* Repair the superblock. */ 30 int 31 xfs_repair_superblock( 32 struct xfs_scrub_context *sc) 33 { 34 struct xfs_mount *mp = sc->mp; 35 struct xfs_buf *bp; 36 xfs_agnumber_t agno; 37 int error; 38 39 /* Don't try to repair AG 0's sb; let xfs_repair deal with it. */ 40 agno = sc->sm->sm_agno; 41 if (agno == 0) 42 return -EOPNOTSUPP; 43 44 error = xfs_sb_get_secondary(mp, sc->tp, agno, &bp); 45 if (error) 46 return error; 47 48 /* Copy AG 0's superblock to this one. */ 49 xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); 50 xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb); 51 52 /* Write this to disk. */ 53 xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_SB_BUF); 54 xfs_trans_log_buf(sc->tp, bp, 0, BBTOB(bp->b_length) - 1); 55 return error; 56 } 57