/* * returns 0 if things are fine, 1 if we don't understand * this superblock version. Sets superblock geometry-dependent * global variables. */ int parse_sb_version(xfs_sb_t *sb) { int issue_warning; fs_attributes = 0; fs_attributes2 = 0; fs_inode_nlink = 0; fs_quotas = 0; fs_aligned_inodes = 0; fs_sb_feature_bits = 0; fs_ino_alignment = 0; fs_has_extflgbit = 0; have_uquotino = 0; have_gquotino = 0; have_pquotino = 0; issue_warning = 0; /* * ok, check to make sure that the sb isn't newer * than we are */ if (xfs_sb_version_hasextflgbit(sb)) { fs_has_extflgbit = 1; if (!fs_has_extflgbit_allowed) { issue_warning = 1; do_warn( _("This filesystem has uninitialized extent flags.\n")); } } if (xfs_sb_version_hasshared(sb)) { fs_shared = 1; if (!fs_shared_allowed) { issue_warning = 1; do_warn(_("This filesystem is marked shared.\n")); } } if (issue_warning) { do_warn( _("This filesystem uses feature(s) not yet supported in this release.\n" "Please run a more recent version of xfs_repair.\n")); return(1); } if (!xfs_sb_good_version(sb)) { do_warn(_("WARNING: unknown superblock version %d\n"), XFS_SB_VERSION_NUM(sb)); do_warn( _("This filesystem contains features not understood by this program.\n")); return(1); } if (XFS_SB_VERSION_NUM(sb) >= XFS_SB_VERSION_4) { if (!fs_sb_feature_bits_allowed) { if (!no_modify) { do_warn( _("WARNING: you have disallowed superblock-feature-bits-allowed\n" "\tbut this superblock has feature bits. The superblock\n" "\twill be downgraded. This may cause loss of filesystem meta-data\n")); } else { do_warn( _("WARNING: you have disallowed superblock-feature-bits-allowed\n" "\tbut this superblock has feature bits. The superblock\n" "\twould be downgraded. This might cause loss of filesystem\n" "\tmeta-data.\n")); } } else { fs_sb_feature_bits = 1; } } if (xfs_sb_version_hasattr(sb)) { if (!fs_attributes_allowed) { if (!no_modify) { do_warn( _("WARNING: you have disallowed attributes but this filesystem\n" "\thas attributes. The filesystem will be downgraded and\n" "\tall attributes will be removed.\n")); } else { do_warn( _("WARNING: you have disallowed attributes but this filesystem\n" "\thas attributes. The filesystem would be downgraded and\n" "\tall attributes would be removed.\n")); } } else { fs_attributes = 1; } } if (xfs_sb_version_hasattr2(sb)) { if (!fs_attributes2_allowed) { if (!no_modify) { do_warn( _("WARNING: you have disallowed attr2 attributes but this filesystem\n" "\thas attributes. The filesystem will be downgraded and\n" "\tall attr2 attributes will be removed.\n")); } else { do_warn( _("WARNING: you have disallowed attr2 attributes but this filesystem\n" "\thas attributes. The filesystem would be downgraded and\n" "\tall attr2 attributes would be removed.\n")); } } else { fs_attributes2 = 1; } } if (xfs_sb_version_hasnlink(sb)) { if (!fs_inode_nlink_allowed) { if (!no_modify) { do_warn( _("WARNING: you have disallowed version 2 inodes but this filesystem\n" "\thas version 2 inodes. The filesystem will be downgraded and\n" "\tall version 2 inodes will be converted to version 1 inodes.\n" "\tThis may cause some hard links to files to be destroyed\n")); } else { do_warn( _("WARNING: you have disallowed version 2 inodes but this filesystem\n" "\thas version 2 inodes. The filesystem would be downgraded and\n" "\tall version 2 inodes would be converted to version 1 inodes.\n" "\tThis might cause some hard links to files to be destroyed\n")); } } else { fs_inode_nlink = 1; } } if (xfs_sb_version_hasquota(sb)) { if (!fs_quotas_allowed) { if (!no_modify) { do_warn( _("WARNING: you have disallowed quotas but this filesystem\n" "\thas quotas. The filesystem will be downgraded and\n" "\tall quota information will be removed.\n")); } else { do_warn( _("WARNING: you have disallowed quotas but this filesystem\n" "\thas quotas. The filesystem would be downgraded and\n" "\tall quota information would be removed.\n")); } } else { fs_quotas = 1; if (sb->sb_uquotino != 0 && sb->sb_uquotino != NULLFSINO) have_uquotino = 1; if (sb->sb_gquotino != 0 && sb->sb_gquotino != NULLFSINO) have_gquotino = 1; if (sb->sb_pquotino != 0 && sb->sb_pquotino != NULLFSINO) have_pquotino = 1; } } if (xfs_sb_version_hasalign(sb)) { if (fs_aligned_inodes_allowed) { fs_aligned_inodes = 1; fs_ino_alignment = sb->sb_inoalignmt; } else { if (!no_modify) { do_warn( _("WARNING: you have disallowed aligned inodes but this filesystem\n" "\thas aligned inodes. The filesystem will be downgraded.\n" "\tThis will permanently degrade the performance of this filesystem.\n")); } else { do_warn( _("WARNING: you have disallowed aligned inodes but this filesystem\n" "\thas aligned inodes. The filesystem would be downgraded.\n" "\tThis would permanently degrade the performance of this filesystem.\n")); } } } /* * calculate maximum file offset for this geometry */ fs_max_file_offset = 0x7fffffffffffffffLL >> sb->sb_blocklog; return(0); }
int verify_sb(xfs_sb_t *sb, int is_primary_sb) { __uint32_t bsize; xfs_extlen_t align; int i; /* check magic number and version number */ if (sb->sb_magicnum != XFS_SB_MAGIC) return(XR_BAD_MAGIC); if (!xfs_sb_good_version(sb)) return(XR_BAD_VERSION); /* does sb think mkfs really finished ? */ if (is_primary_sb && sb->sb_inprogress == 1) return(XR_BAD_INPROGRESS); /* check to make sure blocksize is legal 2^N, 9 <= N <= 16 */ if (sb->sb_blocksize == 0) return(XR_BAD_BLOCKSIZE); bsize = 1; for (i = 0; bsize < sb->sb_blocksize && i < sizeof(sb->sb_blocksize) * NBBY; i++) bsize <<= 1; if (i < XFS_MIN_BLOCKSIZE_LOG || i > XFS_MAX_BLOCKSIZE_LOG) return(XR_BAD_BLOCKSIZE); /* check sb blocksize field against sb blocklog field */ if (i != sb->sb_blocklog) return(XR_BAD_BLOCKLOG); /* sanity check ag count, size fields against data size field */ if (sb->sb_dblocks == 0 || sb->sb_dblocks > ((__uint64_t)sb->sb_agcount * sb->sb_agblocks) || sb->sb_dblocks < ((__uint64_t)(sb->sb_agcount - 1) * sb->sb_agblocks + XFS_MIN_AG_BLOCKS)) return(XR_BAD_FS_SIZE_DATA); if (sb->sb_agblklog != (__uint8_t)libxfs_log2_roundup(sb->sb_agblocks)) return(XR_BAD_FS_SIZE_DATA); if (sb->sb_inodesize < XFS_DINODE_MIN_SIZE || sb->sb_inodesize > XFS_DINODE_MAX_SIZE || sb->sb_inopblock != howmany(sb->sb_blocksize,sb->sb_inodesize)) return(XR_BAD_INO_SIZE_DATA); /* check to make sure sectorsize is legal 2^N, 9 <= N <= 15 */ if (sb->sb_sectsize == 0) return(XR_BAD_SECT_SIZE_DATA); bsize = 1; for (i = 0; bsize < sb->sb_sectsize && i < sizeof(sb->sb_sectsize) * NBBY; i++) { bsize <<= 1; } if (i < XFS_MIN_SECTORSIZE_LOG || i > XFS_MAX_SECTORSIZE_LOG) return(XR_BAD_SECT_SIZE_DATA); /* check sb sectorsize field against sb sectlog field */ if (i != sb->sb_sectlog) return(XR_BAD_SECT_SIZE_DATA); if (xfs_sb_version_hassector(sb)) { /* check to make sure log sector is legal 2^N, 9 <= N <= 15 */ if (sb->sb_logsectsize == 0) return(XR_BAD_SECT_SIZE_DATA); bsize = 1; for (i = 0; bsize < sb->sb_logsectsize && i < sizeof(sb->sb_logsectsize) * NBBY; i++) { bsize <<= 1; } if (i < XFS_MIN_SECTORSIZE_LOG || i > XFS_MAX_SECTORSIZE_LOG) return(XR_BAD_SECT_SIZE_DATA); /* check sb log sectorsize field against sb log sectlog field */ if (i != sb->sb_logsectlog) return(XR_BAD_SECT_SIZE_DATA); } /* * real-time extent size is always set */ if (sb->sb_rextsize * sb->sb_blocksize > XFS_MAX_RTEXTSIZE) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rextsize * sb->sb_blocksize < XFS_MIN_RTEXTSIZE) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rblocks == 0) { if (sb->sb_rextents != 0) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rbmblocks != 0) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rextslog != 0) return(XR_BAD_RT_GEO_DATA); if (sb->sb_frextents != 0) return(XR_BAD_RT_GEO_DATA); } else { /* * if we have a real-time partition, sanity-check geometry */ if (sb->sb_rblocks / sb->sb_rextsize != sb->sb_rextents) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rextslog != libxfs_highbit32((unsigned int)sb->sb_rextents)) return(XR_BAD_RT_GEO_DATA); if (sb->sb_rbmblocks != (xfs_extlen_t) howmany(sb->sb_rextents, NBBY * sb->sb_blocksize)) return(XR_BAD_RT_GEO_DATA); } /* * verify correctness of inode alignment if it's there */ if (xfs_sb_version_hasalign(sb)) { align = calc_ino_align(sb); if (align != sb->sb_inoalignmt) return(XR_BAD_INO_ALIGN); } /* * verify max. % of inodes (sb_imax_pct) */ if (sb->sb_imax_pct > 100) return(XR_BAD_INO_MAX_PCT); /* * verify stripe alignment fields if present */ if (xfs_sb_version_hasdalign(sb)) { if ((!sb->sb_unit && sb->sb_width) || (sb->sb_unit && sb->sb_agblocks % sb->sb_unit)) return(XR_BAD_SB_UNIT); if ((sb->sb_unit && !sb->sb_width) || (sb->sb_width && sb->sb_unit && sb->sb_width % sb->sb_unit)) return(XR_BAD_SB_WIDTH); } /* * if shared bit is set, verify that the version number is sane */ if (xfs_sb_version_hasshared(sb)) { if (sb->sb_shared_vn > XFS_SB_MAX_SHARED_VN) return(XR_BAD_SVN); } /* * mkfs's that stamped a feature bit besides the ones in the * mask below could leave garbage in the secondary superblock * sectors. Anything stamping the shared fs bit or better into * the secondaries is ok and should generate clean secondary * superblock sectors. * * check primary and clean secondary superblocks more strictly */ if (is_primary_sb || sb->sb_versionnum & XR_PART_SECSB_VNMASK) { /* * return errors if shared vn or alignment fields * are set without their feature bits being set */ if ((!pre_65_beta && (sb->sb_versionnum & XR_PART_SECSB_VNMASK)) || (pre_65_beta && (sb->sb_versionnum & XR_ALPHA_SECSB_VNMASK))) { /* * shared version # and inode alignment fields * should be valid */ if (sb->sb_shared_vn && !xfs_sb_version_hasshared(sb)) return(XR_BAD_SVN); if (sb->sb_inoalignmt && !xfs_sb_version_hasalign(sb)) return(XR_BAD_INO_ALIGN); } if ((!pre_65_beta && (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK)) || (pre_65_beta && (sb->sb_versionnum & XFS_SB_VERSION_DALIGNBIT))) { /* * stripe alignment values should be valid */ if (sb->sb_unit && !xfs_sb_version_hasdalign(sb)) return(XR_BAD_SB_UNIT); if (sb->sb_width && !xfs_sb_version_hasdalign(sb)) return(XR_BAD_SB_WIDTH); } #if 0 /* * checks involving later superblock fields get added here... */ if (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK) { } #endif } return(XR_OK); }
void get_sb_geometry(fs_geometry_t *geo, xfs_sb_t *sbp) { memset(geo, 0, sizeof(fs_geometry_t)); /* * blindly set fields that we know are always good */ geo->sb_blocksize = sbp->sb_blocksize; geo->sb_dblocks = sbp->sb_dblocks; geo->sb_rblocks = sbp->sb_rblocks; geo->sb_rextents = sbp->sb_rextents; geo->sb_logstart = sbp->sb_logstart; geo->sb_rextsize = sbp->sb_rextsize; geo->sb_agblocks = sbp->sb_agblocks; geo->sb_agcount = sbp->sb_agcount; geo->sb_rbmblocks = sbp->sb_rbmblocks; geo->sb_logblocks = sbp->sb_logblocks; geo->sb_sectsize = sbp->sb_sectsize; geo->sb_inodesize = sbp->sb_inodesize; if (xfs_sb_version_hasalign(sbp)) geo->sb_ialignbit = 1; if (xfs_sb_version_hasshared(sbp) || sbp->sb_versionnum & XR_PART_SECSB_VNMASK) geo->sb_sharedbit = 1; if (xfs_sb_version_hasdalign(sbp)) geo->sb_salignbit = 1; if (xfs_sb_version_hasextflgbit(sbp)) geo->sb_extflgbit = 1; /* * protect against pre-6.5 mkfs-generated garbaged * fields in the secondary superblocks. pay attention * to those fields if and only if their corresponding * feature bits are set in the feature bits of the * version number or we can deduce from the version bits * that are set that our field was properly initialized * because a field after the field we care about was * properly initialized as well. */ /* * inode alignment field lives before the data alignment field */ if ((!pre_65_beta && (sbp->sb_versionnum & XR_PART_SECSB_VNMASK)) || (pre_65_beta && (sbp->sb_versionnum & XR_ALPHA_SECSB_VNMASK))) geo->sb_inoalignmt = sbp->sb_inoalignmt; if ((!pre_65_beta && (sbp->sb_versionnum & XR_GOOD_SECSB_VNMASK)) || (pre_65_beta && xfs_sb_version_hasdalign(sbp))) { geo->sb_unit = sbp->sb_unit; geo->sb_width = sbp->sb_width; } /* * shared vn always set if either ino or data alignment is on * since that field lives between the quota and inode alignment * fields */ if (sbp->sb_versionnum & XR_PART_SECSB_VNMASK) geo->sb_shared_vn = sbp->sb_shared_vn; /* * superblock fields located after sb_widthfields get set * into the geometry structure only if we can determine * from the features enabled in this superblock whether * or not the sector was zero'd at mkfs time. */ if ((!pre_65_beta && (sbp->sb_versionnum & XR_GOOD_SECSB_VNMASK)) || (pre_65_beta && (sbp->sb_versionnum & XR_ALPHA_SECSB_VNMASK))) { geo->sb_fully_zeroed = 1; } }
/* * Possible fields that may have been set at mkfs time, * sb_inoalignmt, sb_unit, sb_width and sb_dirblklog. * The quota inode fields in the secondaries should be zero. * Likewise, the sb_flags and sb_shared_vn should also be * zero and the shared version bit should be cleared for * current mkfs's. * * And everything else in the buffer beyond either sb_width, * sb_dirblklog (v2 dirs), or sb_logsectsize can be zeroed. * * Note: contrary to the name, this routine is called for all * superblocks, not just the secondary superblocks. */ static int secondary_sb_wack(xfs_mount_t *mp, xfs_buf_t *sbuf, xfs_sb_t *sb, xfs_agnumber_t i) { int do_bzero; int size; char *ip; int rval; rval = do_bzero = 0; /* * mkfs's that stamped a feature bit besides the ones in the mask * (e.g. were pre-6.5 beta) could leave garbage in the secondary * superblock sectors. Anything stamping the shared fs bit or better * into the secondaries is ok and should generate clean secondary * superblock sectors. so only run the zero check on the * potentially garbaged secondaries. */ if (pre_65_beta || (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK) == 0 || sb->sb_versionnum < XFS_SB_VERSION_4) { /* * Check for garbage beyond the last field. * Use field addresses instead so this code will still * work against older filesystems when the superblock * gets rev'ed again with new fields appended. */ if (xfs_sb_version_hasmorebits(sb)) size = (__psint_t)&sb->sb_features2 + sizeof(sb->sb_features2) - (__psint_t)sb; else if (xfs_sb_version_haslogv2(sb)) size = (__psint_t)&sb->sb_logsunit + sizeof(sb->sb_logsunit) - (__psint_t)sb; else if (xfs_sb_version_hassector(sb)) size = (__psint_t)&sb->sb_logsectsize + sizeof(sb->sb_logsectsize) - (__psint_t)sb; else if (xfs_sb_version_hasdirv2(sb)) size = (__psint_t)&sb->sb_dirblklog + sizeof(sb->sb_dirblklog) - (__psint_t)sb; else size = (__psint_t)&sb->sb_width + sizeof(sb->sb_width) - (__psint_t)sb; for (ip = (char *)((__psint_t)sb + size); ip < (char *)((__psint_t)sb + mp->m_sb.sb_sectsize); ip++) { if (*ip) { do_bzero = 1; break; } } if (do_bzero) { rval |= XR_AG_SB_SEC; if (!no_modify) { do_warn( _("zeroing unused portion of %s superblock (AG #%u)\n"), !i ? _("primary") : _("secondary"), i); memset((void *)((__psint_t)sb + size), 0, mp->m_sb.sb_sectsize - size); } else do_warn( _("would zero unused portion of %s superblock (AG #%u)\n"), !i ? _("primary") : _("secondary"), i); } } /* * now look for the fields we can manipulate directly. * if we did a zero and that zero could have included * the field in question, just silently reset it. otherwise, * complain. * * for now, just zero the flags field since only * the readonly flag is used */ if (sb->sb_flags) { if (!no_modify) sb->sb_flags = 0; if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn(_("bad flags field in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } /* * quota inodes and flags in secondary superblocks * are never set by mkfs. However, they could be set * in a secondary if a fs with quotas was growfs'ed since * growfs copies the new primary into the secondaries. */ if (sb->sb_inprogress == 1 && sb->sb_uquotino) { if (!no_modify) sb->sb_uquotino = 0; if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn( _("non-null user quota inode field in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } if (sb->sb_inprogress == 1 && sb->sb_gquotino) { if (!no_modify) sb->sb_gquotino = 0; if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn( _("non-null group quota inode field in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } if (sb->sb_inprogress == 1 && sb->sb_qflags) { if (!no_modify) sb->sb_qflags = 0; if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn(_("non-null quota flags in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } /* * if the secondaries agree on a stripe unit/width or inode * alignment, those fields ought to be valid since they are * written at mkfs time (and the corresponding sb version bits * are set). */ if (!xfs_sb_version_hasshared(sb) && sb->sb_shared_vn != 0) { if (!no_modify) sb->sb_shared_vn = 0; if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn( _("bad shared version number in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } if (!xfs_sb_version_hasalign(sb) && sb->sb_inoalignmt != 0) { if (!no_modify) sb->sb_inoalignmt = 0; if (sb->sb_versionnum & XR_PART_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn( _("bad inode alignment field in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } if (!xfs_sb_version_hasdalign(sb) && (sb->sb_unit != 0 || sb->sb_width != 0)) { if (!no_modify) sb->sb_unit = sb->sb_width = 0; if (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn( _("bad stripe unit/width fields in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } if (!xfs_sb_version_hassector(sb) && (sb->sb_sectsize != BBSIZE || sb->sb_sectlog != BBSHIFT || sb->sb_logsectsize != 0 || sb->sb_logsectlog != 0)) { if (!no_modify) { sb->sb_sectsize = BBSIZE; sb->sb_sectlog = BBSHIFT; sb->sb_logsectsize = 0; sb->sb_logsectlog = 0; } if (sb->sb_versionnum & XR_GOOD_SECSB_VNMASK || !do_bzero) { rval |= XR_AG_SB; do_warn( _("bad log/data device sector size fields in superblock %d\n"), i); } else rval |= XR_AG_SB_SEC; } return(rval); }