1 /* 2 * Copyright (C) 2018 Oracle. All Rights Reserved. 3 * 4 * Author: Darrick J. Wong <darrick.wong@oracle.com> 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * 11 * This program is distributed in the hope that it would be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. 19 */ 20 #include "xfs.h" 21 #include "xfs_fs.h" 22 #include "xfs_shared.h" 23 #include "xfs_format.h" 24 #include "xfs_trans_resv.h" 25 #include "xfs_mount.h" 26 #include "xfs_defer.h" 27 #include "xfs_btree.h" 28 #include "xfs_bit.h" 29 #include "xfs_log_format.h" 30 #include "xfs_trans.h" 31 #include "xfs_sb.h" 32 #include "xfs_inode.h" 33 #include "xfs_alloc.h" 34 #include "xfs_ialloc.h" 35 #include "xfs_rmap.h" 36 #include "scrub/xfs_scrub.h" 37 #include "scrub/scrub.h" 38 #include "scrub/common.h" 39 #include "scrub/trace.h" 40 41 /* Superblock */ 42 43 /* Repair the superblock. */ 44 int 45 xfs_repair_superblock( 46 struct xfs_scrub_context *sc) 47 { 48 struct xfs_mount *mp = sc->mp; 49 struct xfs_buf *bp; 50 xfs_agnumber_t agno; 51 int error; 52 53 /* Don't try to repair AG 0's sb; let xfs_repair deal with it. */ 54 agno = sc->sm->sm_agno; 55 if (agno == 0) 56 return -EOPNOTSUPP; 57 58 error = xfs_sb_get_secondary(mp, sc->tp, agno, &bp); 59 if (error) 60 return error; 61 62 /* Copy AG 0's superblock to this one. */ 63 xfs_buf_zero(bp, 0, BBTOB(bp->b_length)); 64 xfs_sb_to_disk(XFS_BUF_TO_SBP(bp), &mp->m_sb); 65 66 /* Write this to disk. */ 67 xfs_trans_buf_set_type(sc->tp, bp, XFS_BLFT_SB_BUF); 68 xfs_trans_log_buf(sc->tp, bp, 0, BBTOB(bp->b_length) - 1); 69 return error; 70 } 71