summaryrefslogtreecommitdiffstats
path: root/config/user-libblkid.m4
blob: 276587fd358926d19a166ed917fbb4d60cb5e4ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
dnl #
dnl # Check for ZFS support in libblkid.  This test needs to check
dnl # more than if the library exists because we expect there are
dnl # at least 3 flavors of the library out in the wild:
dnl #
dnl #   1) blkid which has no ZFS support
dnl #   2) blkid with ZFS support and a flawed method of probing
dnl #   3) blkid with ZFS support and a working method of probing
dnl #
dnl # To handle this the check first validates that there is a version
dnl # of the library installed.  If there is it creates a simulated
dnl # ZFS filesystem and then links a small test app which attempts
dnl # to detect the simualated filesystem type.  If it correctly
dnl # identifies the filesystem as ZFS we can safely assume case 3).
dnl # Otherwise we disable blkid support and resort to manual probing.
dnl #
AC_DEFUN([ZFS_AC_CONFIG_USER_LIBBLKID], [
	AC_ARG_WITH([blkid],
		[AS_HELP_STRING([--with-blkid],
		[support blkid caching @<:@default=check@:>@])],
		[],
		[with_blkid=check])

	LIBBLKID=
	AS_IF([test "x$with_blkid" != xno],
	[
		AC_CHECK_LIB([blkid], [blkid_get_cache],
		[
			AC_MSG_CHECKING([for blkid zfs support])

			ZFS_DEV=`mktemp`
			dd if=/dev/zero of=$ZFS_DEV bs=1024k count=8 \
				>/dev/null 2>/dev/null
			echo -en "\x0c\xb1\xba\0\0\0\0\0" | \
				dd of=$ZFS_DEV bs=1k count=8 \
				seek=132 conv=notrunc &>/dev/null \
				>/dev/null 2>/dev/null

			saved_LDFLAGS="$LDFLAGS"
			LDFLAGS="-lblkid"

			AC_RUN_IFELSE([AC_LANG_PROGRAM(
			[
				#include <stdio.h>
				#include <blkid/blkid.h>
			],
			[
				blkid_cache cache;
				char *value;

			        if (blkid_get_cache(&cache, NULL) < 0)
					return 1;

				value = blkid_get_tag_value(cache, "TYPE",
				                            "$ZFS_DEV");
				if (!value) {
					blkid_put_cache(cache);
					return 2;
				}

				if (strcmp(value, "zfs")) {
					free(value);
					blkid_put_cache(cache);
					return 3;
				}

				free(value);
				blkid_put_cache(cache);
			])],
			[
				rm -f $ZFS_DEV
				AC_MSG_RESULT([yes])
				AC_SUBST([LIBBLKID], ["-lblkid"])
				AC_DEFINE([HAVE_LIBBLKID], 1,
					[Define if you have libblkid])
			],
			[
				rm -f $ZFS_DEV
				AC_MSG_RESULT([no])
				AS_IF([test "x$with_blkid" != xcheck],
					[AC_MSG_FAILURE(
					[--with-blkid given but unavailable])])
			])

			LDFLAGS="$saved_LDFLAGS"
		],
		[
			AS_IF([test "x$with_blkid" != xcheck],
				[AC_MSG_FAILURE(
				[--with-blkid given but unavailable])])
		]
		[])
	])
])