Blob Blame History Raw
commit ef1979d8cbfb8ad976de0af21a70f8c0f98fbbe9
Author: Tomas Bzatek <tbzatek@redhat.com>
Date:   Wed Mar 17 18:50:19 2021 +0100

    udiskslinuxfsinfo: Add dosfstools >= 4.2 quirks
    
    Reverting back the legacy behaviour with no protective (fake) MBR
    created while making new FAT filesystem on an unpartitioned block device.
    
    Added a label clear functionality as well.

diff --git a/src/udiskslinuxfsinfo.c b/src/udiskslinuxfsinfo.c
index 15af26c8..f18b9b80 100644
--- a/src/udiskslinuxfsinfo.c
+++ b/src/udiskslinuxfsinfo.c
@@ -21,6 +21,8 @@
 #include <string.h>
 #include <glib.h>
 
+#include <blockdev/exec.h>
+
 #include "config.h"
 #include "udiskslinuxfsinfo.h"
 #include "udisksconfigmanager.h"
@@ -236,6 +238,19 @@ const FSInfo _fs_info[] =
     },
   };
 
+/* workaround for dosfstools >= 4.2 */
+static const FSInfo vfat_dosfstools_42 =
+    {
+      FS_VFAT,
+      "fatlabel $DEVICE $LABEL",
+      "fatlabel --reset $DEVICE",
+      FALSE, /* supports_online_label_rename */
+      FALSE, /* supports_owners */
+      "mkfs.vfat -I -n $LABEL --mbr=n $DEVICE",
+      NULL,
+      NULL, /* option_no_discard */
+    };
+
 /**
  * get_fs_info:
  *
@@ -248,6 +263,7 @@ const FSInfo _fs_info[] =
 const FSInfo *
 get_fs_info (const gchar *fstype)
 {
+  const FSInfo *info = NULL;
   guint n;
 
   g_return_val_if_fail (fstype != NULL, NULL);
@@ -255,10 +271,20 @@ get_fs_info (const gchar *fstype)
   for (n = 0; n < sizeof(_fs_info)/sizeof(FSInfo); n++)
     {
       if (strcmp (_fs_info[n].fstype, fstype) == 0)
-        return &_fs_info[n];
+        {
+          info = &_fs_info[n];
+          break;
+        }
+    }
+
+  /* dosfstools >= 4.2 workaround */
+  if (g_str_equal (fstype, FS_VFAT) &&
+      bd_utils_check_util_version ("mkfs.vfat", "4.2", "--help", "mkfs.fat\\s+([\\d\\.]+).+", NULL))
+    {
+      info = &vfat_dosfstools_42;
     }
 
-  return NULL;
+  return info;
 }
 
 /**