]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blobdiff - db/sb.c
mkfs: validate extent size hint parameters
[thirdparty/xfsprogs-dev.git] / db / sb.c
diff --git a/db/sb.c b/db/sb.c
index 9c585ca28f518de7d80e59e63b37fa56cb78c341..5059b261ceff7fd5297bbf3abae5fc029fed35f9 100644 (file)
--- a/db/sb.c
+++ b/db/sb.c
@@ -1,19 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
  * All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
 #include "libxfs.h"
@@ -229,7 +217,6 @@ int xlog_recover_do_trans(struct xlog *log, xlog_recover_t *t, int p)
 int
 sb_logcheck(void)
 {
-       struct xlog     log;
        int             dirty;
 
        if (mp->m_sb.sb_logstart) {
@@ -248,7 +235,7 @@ sb_logcheck(void)
 
        libxfs_buftarg_init(mp, x.ddev, x.logdev, x.rtdev);
 
-       dirty = xlog_is_dirty(mp, &log, &x, 0);
+       dirty = xlog_is_dirty(mp, mp->m_log, &x, 0);
        if (dirty == -1) {
                dbprintf(_("ERROR: cannot find log head/tail, run xfs_repair\n"));
                return 0;
@@ -269,20 +256,32 @@ sb_logcheck(void)
 static int
 sb_logzero(uuid_t *uuidp)
 {
+       int     cycle = XLOG_INIT_CYCLE;
+       int     error;
+
        if (!sb_logcheck())
                return 0;
 
+       /*
+        * The log must always move forward on v5 superblocks. Bump it to the
+        * next cycle.
+        */
+       if (xfs_sb_version_hascrc(&mp->m_sb))
+               cycle = mp->m_log->l_curr_cycle + 1;
+
        dbprintf(_("Clearing log and setting UUID\n"));
 
-       if (libxfs_log_clear(mp->m_logdev_targp,
+       error =  libxfs_log_clear(mp->m_logdev_targp, NULL,
                        XFS_FSB_TO_DADDR(mp, mp->m_sb.sb_logstart),
                        (xfs_extlen_t)XFS_FSB_TO_BB(mp, mp->m_sb.sb_logblocks),
                        uuidp,
                        xfs_sb_version_haslogv2(&mp->m_sb) ? 2 : 1,
-                       mp->m_sb.sb_logsunit, XLOG_FMT, XLOG_INIT_CYCLE)) {
+                       mp->m_sb.sb_logsunit, XLOG_FMT, cycle, true);
+       if (error) {
                dbprintf(_("ERROR: cannot clear the log\n"));
                return 0;
        }
+
        return 1;
 }
 
@@ -403,7 +402,7 @@ uuid_f(
                        /* Not set; nothing to do.  Success! */
                        if (!xfs_sb_version_hasmetauuid(&tsb))
                                return 0;
-               
+
                        memcpy(&uu, mp->m_sb.sb_meta_uuid, sizeof(uuid_t));
                } else {
                        if (platform_uuid_parse(argv[1], &uu)) {
@@ -595,7 +594,7 @@ version_help(void)
 }
 
 static int
-do_version(xfs_agnumber_t agno, __uint16_t version, __uint32_t features)
+do_version(xfs_agnumber_t agno, uint16_t version, uint32_t features)
 {
        xfs_sb_t        tsb;
 
@@ -659,7 +658,8 @@ version_string(
                strcat(s, ",DALIGN");
        if (xfs_sb_version_haslogv2(sbp))
                strcat(s, ",LOGV2");
-       if (xfs_sb_version_hasextflgbit(sbp))
+       /* This feature is required now as well */
+       if (sbp->sb_versionnum & XFS_SB_VERSION_EXTFLGBIT)
                strcat(s, ",EXTFLG");
        if (xfs_sb_version_hassector(sbp))
                strcat(s, ",SECTOR");
@@ -683,6 +683,10 @@ version_string(
                strcat(s, ",SPARSE_INODES");
        if (xfs_sb_version_hasmetauuid(sbp))
                strcat(s, ",META_UUID");
+       if (xfs_sb_version_hasrmapbt(sbp))
+               strcat(s, ",RMAPBT");
+       if (xfs_sb_version_hasreflink(sbp))
+               strcat(s, ",REFLINK");
        return s;
 }
 
@@ -697,8 +701,8 @@ version_f(
        int             argc,
        char            **argv)
 {
-       __uint16_t      version = 0;
-       __uint32_t      features = 0;
+       uint16_t        version = 0;
+       uint32_t        features = 0;
        xfs_agnumber_t  ag;
 
        if (argc == 2) {        /* WRITE VERSION */
@@ -722,7 +726,8 @@ version_f(
                                version = 0x0034 | XFS_SB_VERSION_EXTFLGBIT;
                                break;
                        case XFS_SB_VERSION_4:
-                               if (xfs_sb_version_hasextflgbit(&mp->m_sb))
+                               if (mp->m_sb.sb_versionnum &
+                                               XFS_SB_VERSION_EXTFLGBIT)
                                        dbprintf(
                _("unwritten extents flag is already enabled\n"));
                                else