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