#include <grub/time.h>
#include <grub/emu/misc.h>
+#ifdef HAVE_DEVICE_MAPPER
+# include <libdevmapper.h>
+#endif
+
int verbosity;
void
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;
}
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 */