]> git.proxmox.com Git - grub2.git/blobdiff - grub-core/kern/emu/misc.c
merge with mainline
[grub2.git] / grub-core / kern / emu / misc.c
index 9437169e002bb05bf5eedc61d22b4007157b638c..03ceae8f9b3dacd46ead9567a86ce002703d69ec 100644 (file)
 #include <grub/time.h>
 #include <grub/emu/misc.h>
 
+#ifdef HAVE_DEVICE_MAPPER
+# include <libdevmapper.h>
+#endif
+
 int verbosity;
 
 void
@@ -136,18 +140,18 @@ asprintf (char **buf, const char *fmt, ...)
 
 char *
 xasprintf (const char *fmt, ...)
-{ 
+{
   va_list ap;
   char *result;
-  
+
   va_start (ap, fmt);
   if (vasprintf (&result, fmt, ap) < 0)
-    { 
+    {
       if (errno == ENOMEM)
         grub_util_error ("out of memory");
       return NULL;
     }
-  
+
   return result;
 }
 
@@ -311,3 +315,38 @@ grub_make_system_path_relative_to_its_root (const char *path)
 
   return buf3;
 }
+
+#ifdef HAVE_DEVICE_MAPPER
+static void device_mapper_null_log (int level __attribute__ ((unused)),
+                                   const char *file __attribute__ ((unused)),
+                                   int line __attribute__ ((unused)),
+                                   int dm_errno __attribute__ ((unused)),
+                                   const char *f __attribute__ ((unused)),
+                                   ...)
+{
+}
+
+int
+grub_device_mapper_supported (void)
+{
+  static int supported = -1;
+
+  if (supported == -1)
+    {
+      struct dm_task *dmt;
+
+      /* Suppress annoying log messages.  */
+      dm_log_with_errno_init (&device_mapper_null_log);
+
+      dmt = dm_task_create (DM_DEVICE_VERSION);
+      supported = (dmt != NULL);
+      if (dmt)
+       dm_task_destroy (dmt);
+
+      /* Restore the original logger.  */
+      dm_log_with_errno_init (NULL);
+    }
+
+  return supported;
+}
+#endif /* HAVE_DEVICE_MAPPER */