Blame SOURCES/0004-Adapt-to-dosfstools-4.2-changes.patch

940a02
From cc522ec3717d909370af6181c7859c62fa0167df Mon Sep 17 00:00:00 2001
940a02
From: Vojtech Trefny <vtrefny@redhat.com>
940a02
Date: Mon, 22 Feb 2021 15:40:56 +0100
940a02
Subject: [PATCH 1/2] fs: Allow using empty label for vfat with newest
940a02
 dosfstools
940a02
940a02
---
940a02
 src/plugins/fs/vfat.c | 11 +++++++++++
940a02
 1 file changed, 11 insertions(+)
940a02
940a02
diff --git a/src/plugins/fs/vfat.c b/src/plugins/fs/vfat.c
940a02
index ff0c35a3..ce13f147 100644
940a02
--- a/src/plugins/fs/vfat.c
940a02
+++ b/src/plugins/fs/vfat.c
940a02
@@ -232,10 +232,21 @@ gboolean bd_fs_vfat_repair (const gchar *device, const BDExtraArg **extra, GErro
940a02
  */
940a02
 gboolean bd_fs_vfat_set_label (const gchar *device, const gchar *label, GError **error) {
940a02
     const gchar *args[4] = {"fatlabel", device, label, NULL};
940a02
+    UtilDep dep = {"fatlabel", "4.2", "--version", "fatlabel\\s+([\\d\\.]+).+"};
940a02
+    gboolean new_vfat = FALSE;
940a02
 
940a02
     if (!check_deps (&avail_deps, DEPS_FATLABEL_MASK, deps, DEPS_LAST, &deps_check_lock, error))
940a02
         return FALSE;
940a02
 
940a02
+    if (!label || g_strcmp0 (label, "") == 0) {
940a02
+        /* fatlabel >= 4.2 refuses to set empty label */
940a02
+        new_vfat = bd_utils_check_util_version (dep.name, dep.version,
940a02
+                                                dep.ver_arg, dep.ver_regexp,
940a02
+                                                NULL);
940a02
+        if (new_vfat)
940a02
+            args[2] = "--reset";
940a02
+    }
940a02
+
940a02
     return bd_utils_exec_and_report_error (args, NULL, error);
940a02
 }
940a02
 
940a02
940a02
From c3c3583409c8ed8f99a840e0c70cc92ca1dd3c93 Mon Sep 17 00:00:00 2001
940a02
From: Vojtech Trefny <vtrefny@redhat.com>
940a02
Date: Tue, 27 Apr 2021 14:06:59 +0200
940a02
Subject: [PATCH 2/2] tests: Call fs_vfat_mkfs with "--mbr=n" extra option in
940a02
 tests
940a02
940a02
Without the option the newest dosfstools 4.2 will create a valid
940a02
MBR partition table with a simgle partition on the disk, see
940a02
dosfstools/dosfstools#95 for details.
940a02
---
940a02
 src/plugins/fs/vfat.c |  5 ++-
940a02
 tests/fs_test.py      | 76 +++++++++++++++++++++++++++++++++----------
940a02
 2 files changed, 62 insertions(+), 19 deletions(-)
940a02
940a02
diff --git a/src/plugins/fs/vfat.c b/src/plugins/fs/vfat.c
940a02
index ce13f147..6cb82537 100644
940a02
--- a/src/plugins/fs/vfat.c
940a02
+++ b/src/plugins/fs/vfat.c
940a02
@@ -234,6 +234,7 @@ gboolean bd_fs_vfat_set_label (const gchar *device, const gchar *label, GError *
940a02
     const gchar *args[4] = {"fatlabel", device, label, NULL};
940a02
     UtilDep dep = {"fatlabel", "4.2", "--version", "fatlabel\\s+([\\d\\.]+).+"};
940a02
     gboolean new_vfat = FALSE;
940a02
+    GError *loc_error = NULL;
940a02
 
940a02
     if (!check_deps (&avail_deps, DEPS_FATLABEL_MASK, deps, DEPS_LAST, &deps_check_lock, error))
940a02
         return FALSE;
940a02
@@ -242,9 +243,11 @@ gboolean bd_fs_vfat_set_label (const gchar *device, const gchar *label, GError *
940a02
         /* fatlabel >= 4.2 refuses to set empty label */
940a02
         new_vfat = bd_utils_check_util_version (dep.name, dep.version,
940a02
                                                 dep.ver_arg, dep.ver_regexp,
940a02
-                                                NULL);
940a02
+                                                &loc_error);
940a02
         if (new_vfat)
940a02
             args[2] = "--reset";
940a02
+        else
940a02
+            g_clear_error (&loc_error);
940a02
     }
940a02
 
940a02
     return bd_utils_exec_and_report_error (args, NULL, error);
940a02
diff --git a/tests/fs_test.py b/tests/fs_test.py
940a02
index 239cb47c..2233db4f 100644
940a02
--- a/tests/fs_test.py
940a02
+++ b/tests/fs_test.py
940a02
@@ -5,10 +5,13 @@
940a02
 import tempfile
940a02
 from contextlib import contextmanager
940a02
 import utils
940a02
-from utils import run, create_sparse_tempfile, mount, umount, TestTags, tag_test
940a02
+from utils import run, create_sparse_tempfile, mount, umount, TestTags, tag_test, run_command
940a02
+import re
940a02
 import six
940a02
 import overrides_hack
940a02
 
940a02
+from distutils.version import LooseVersion
940a02
+
940a02
 from gi.repository import BlockDev, GLib
940a02
 
940a02
 
940a02
@@ -29,9 +32,20 @@ def mounted(device, where, ro=False):
940a02
     yield
940a02
     umount(where)
940a02
 
940a02
+
940a02
+def _get_dosfstools_version():
940a02
+    _ret, out, _err = run_command("mkfs.vfat --help")
940a02
+    # mkfs.fat 4.1 (2017-01-24)
940a02
+    m = re.search(r"mkfs\.fat ([\d\.]+)", out)
940a02
+    if not m or len(m.groups()) != 1:
940a02
+        raise RuntimeError("Failed to determine dosfstools version from: %s" % out)
940a02
+    return LooseVersion(m.groups()[0])
940a02
+
940a02
+
940a02
 class FSTestCase(unittest.TestCase):
940a02
 
940a02
     requested_plugins = BlockDev.plugin_specs_from_names(("fs", "loop"))
940a02
+    _vfat_version = _get_dosfstools_version()
940a02
 
940a02
     @classmethod
940a02
     def setUpClass(cls):
940a02
@@ -66,6 +80,11 @@ def setUp(self):
940a02
 
940a02
         self.mount_dir = tempfile.mkdtemp(prefix="libblockdev.", suffix="ext4_test")
940a02
 
940a02
+        if self._vfat_version <= LooseVersion("4.1"):
940a02
+            self._mkfs_options = None
940a02
+        else:
940a02
+            self._mkfs_options = [BlockDev.ExtraArg.new("--mbr=n", "")]
940a02
+
940a02
     def _clean_up(self):
940a02
         try:
940a02
             utils.delete_lio_device(self.loop_dev)
940a02
@@ -120,7 +139,10 @@ def test_generic_wipe(self):
940a02
 
940a02
         # vfat has multiple signatures on the device so it allows us to test the
940a02
         # 'all' argument of fs_wipe()
940a02
-        ret = run("mkfs.vfat -I %s >/dev/null 2>&1" % self.loop_dev)
940a02
+        if self._vfat_version >= LooseVersion("4.2"):
940a02
+            ret = utils.run("mkfs.vfat -I %s >/dev/null 2>&1 --mbr=n" % self.loop_dev)
940a02
+        else:
940a02
+            ret = utils.run("mkfs.vfat -I %s >/dev/null 2>&1" % self.loop_dev)
940a02
         self.assertEqual(ret, 0)
940a02
 
940a02
         time.sleep(0.5)
940a02
@@ -142,7 +164,10 @@ def test_generic_wipe(self):
940a02
         self.assertEqual(fs_type, b"")
940a02
 
940a02
         # now do the wipe all in a one step
940a02
-        ret = run("mkfs.vfat -I %s >/dev/null 2>&1" % self.loop_dev)
940a02
+        if self._vfat_version >= LooseVersion("4.2"):
940a02
+            ret = utils.run("mkfs.vfat -I %s >/dev/null 2>&1 --mbr=n" % self.loop_dev)
940a02
+        else:
940a02
+            ret = utils.run("mkfs.vfat -I %s >/dev/null 2>&1" % self.loop_dev)
940a02
         self.assertEqual(ret, 0)
940a02
 
940a02
         succ = BlockDev.fs_wipe(self.loop_dev, True)
940a02
@@ -197,7 +222,10 @@ def test_clean(self):
940a02
 
940a02
         # vfat has multiple signatures on the device so it allows us to test
940a02
         # that clean removes all signatures
940a02
-        ret = run("mkfs.vfat -I %s >/dev/null 2>&1" % self.loop_dev)
940a02
+        if self._vfat_version >= LooseVersion("4.2"):
940a02
+            ret = utils.run("mkfs.vfat -I %s >/dev/null 2>&1 --mbr=n" % self.loop_dev)
940a02
+        else:
940a02
+            ret = utils.run("mkfs.vfat -I %s >/dev/null 2>&1" % self.loop_dev)
940a02
         self.assertEqual(ret, 0)
940a02
 
940a02
         time.sleep(0.5)
940a02
@@ -744,9 +772,9 @@ def test_vfat_mkfs(self):
940a02
         """Verify that it is possible to create a new vfat file system"""
940a02
 
940a02
         with self.assertRaises(GLib.GError):
940a02
-            BlockDev.fs_vfat_mkfs("/non/existing/device", None)
940a02
+            BlockDev.fs_vfat_mkfs("/non/existing/device", self._mkfs_options)
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         # just try if we can mount the file system
940a02
@@ -764,7 +792,10 @@ def test_vfat_mkfs_with_label(self):
940a02
         """Verify that it is possible to create an vfat file system with label"""
940a02
 
940a02
         ea = BlockDev.ExtraArg.new("-n", "TEST_LABEL")
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, [ea])
940a02
+        if self._mkfs_options:
940a02
+            succ = BlockDev.fs_vfat_mkfs(self.loop_dev, [ea] + self._mkfs_options)
940a02
+        else:
940a02
+            succ = BlockDev.fs_vfat_mkfs(self.loop_dev, [ea])
940a02
         self.assertTrue(succ)
940a02
 
940a02
         fi = BlockDev.fs_vfat_get_info(self.loop_dev)
940a02
@@ -775,7 +806,7 @@ class VfatTestWipe(FSTestCase):
940a02
     def test_vfat_wipe(self):
940a02
         """Verify that it is possible to wipe an vfat file system"""
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         succ = BlockDev.fs_vfat_wipe(self.loop_dev)
940a02
@@ -805,7 +836,7 @@ class VfatTestCheck(FSTestCase):
940a02
     def test_vfat_check(self):
940a02
         """Verify that it is possible to check an vfat file system"""
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         succ = BlockDev.fs_vfat_check(self.loop_dev, None)
940a02
@@ -818,7 +849,7 @@ class VfatTestRepair(FSTestCase):
940a02
     def test_vfat_repair(self):
940a02
         """Verify that it is possible to repair an vfat file system"""
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         succ = BlockDev.fs_vfat_repair(self.loop_dev, None)
940a02
@@ -828,7 +859,7 @@ class VfatGetInfo(FSTestCase):
940a02
     def test_vfat_get_info(self):
940a02
         """Verify that it is possible to get info about an vfat file system"""
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         fi = BlockDev.fs_vfat_get_info(self.loop_dev)
940a02
@@ -841,7 +872,7 @@ class VfatSetLabel(FSTestCase):
940a02
     def test_vfat_set_label(self):
940a02
         """Verify that it is possible to set label of an vfat file system"""
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         fi = BlockDev.fs_vfat_get_info(self.loop_dev)
940a02
@@ -870,7 +901,7 @@ class VfatResize(FSTestCase):
940a02
     def test_vfat_resize(self):
940a02
         """Verify that it is possible to resize an vfat file system"""
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         # shrink
940a02
@@ -999,7 +1030,7 @@ def _remove_user(self):
940a02
     def test_mount(self):
940a02
         """ Test basic mounting and unmounting """
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         tmp = tempfile.mkdtemp(prefix="libblockdev.", suffix="mount_test")
940a02
@@ -1104,7 +1135,7 @@ def test_mount_fstab(self):
940a02
         fstab = utils.read_file("/etc/fstab")
940a02
         self.addCleanup(utils.write_file, "/etc/fstab", fstab)
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         tmp = tempfile.mkdtemp(prefix="libblockdev.", suffix="mount_fstab_test")
940a02
@@ -1139,7 +1170,7 @@ def test_mount_fstab_user(self):
940a02
         fstab = utils.read_file("/etc/fstab")
940a02
         self.addCleanup(utils.write_file, "/etc/fstab", fstab)
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         tmp = tempfile.mkdtemp(prefix="libblockdev.", suffix="mount_fstab_user_test")
940a02
@@ -1423,7 +1454,16 @@ def expected_size(fi):
940a02
     @tag_test(TestTags.UNSTABLE)
940a02
     def test_vfat_generic_resize(self):
940a02
         """Test generic resize function with a vfat file system"""
940a02
-        self._test_generic_resize(mkfs_function=BlockDev.fs_vfat_mkfs)
940a02
+        def mkfs_vfat(device, options=None):
940a02
+            if self._vfat_version >= LooseVersion("4.2"):
940a02
+                if options:
940a02
+                    return BlockDev.fs_vfat_mkfs(device, options + [BlockDev.ExtraArg.new("--mbr=n", "")])
940a02
+                else:
940a02
+                    return BlockDev.fs_vfat_mkfs(device, [BlockDev.ExtraArg.new("--mbr=n", "")])
940a02
+            else:
940a02
+                return BlockDev.fs_vfat_mkfs(device, options)
940a02
+
940a02
+        self._test_generic_resize(mkfs_function=mkfs_vfat)
940a02
 
940a02
     def _destroy_lvm(self):
940a02
         run("vgremove --yes libbd_fs_tests >/dev/null 2>&1")
940a02
@@ -1539,7 +1579,7 @@ def test_freeze_xfs(self):
940a02
     def test_freeze_vfat(self):
940a02
         """ Test basic freezing and un-freezing with FAT """
940a02
 
940a02
-        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, None)
940a02
+        succ = BlockDev.fs_vfat_mkfs(self.loop_dev, self._mkfs_options)
940a02
         self.assertTrue(succ)
940a02
 
940a02
         tmp = tempfile.mkdtemp(prefix="libblockdev.", suffix="freeze_test")