]> git.proxmox.com Git - mirror_zfs-debian.git/blame - config/user-libblkid.m4
New upstream version 0.6.5.10
[mirror_zfs-debian.git] / config / user-libblkid.m4
CommitLineData
c9c0d073
BB
1dnl #
2dnl # Check for ZFS support in libblkid. This test needs to check
3dnl # more than if the library exists because we expect there are
4dnl # at least 3 flavors of the library out in the wild:
5dnl #
6dnl # 1) blkid which has no ZFS support
7dnl # 2) blkid with ZFS support and a flawed method of probing
8dnl # 3) blkid with ZFS support and a working method of probing
9dnl #
10dnl # To handle this the check first validates that there is a version
11dnl # of the library installed. If there is it creates a simulated
12dnl # ZFS filesystem and then links a small test app which attempts
13dnl # to detect the simualated filesystem type. If it correctly
14dnl # identifies the filesystem as ZFS we can safely assume case 3).
15dnl # Otherwise we disable blkid support and resort to manual probing.
16dnl #
17AC_DEFUN([ZFS_AC_CONFIG_USER_LIBBLKID], [
18 AC_ARG_WITH([blkid],
19 [AS_HELP_STRING([--with-blkid],
20 [support blkid caching @<:@default=check@:>@])],
21 [],
22 [with_blkid=check])
23
24 LIBBLKID=
a08ee875
LG
25 AS_IF([test "x$with_blkid" = xyes],
26 [
27 AC_SUBST([LIBBLKID], ["-lblkid"])
28 AC_DEFINE([HAVE_LIBBLKID], 1,
29 [Define if you have libblkid])
30 ])
31
32 AS_IF([test "x$with_blkid" = xcheck],
c9c0d073
BB
33 [
34 AC_CHECK_LIB([blkid], [blkid_get_cache],
35 [
36 AC_MSG_CHECKING([for blkid zfs support])
37
38 ZFS_DEV=`mktemp`
a08ee875
LG
39 truncate -s 64M $ZFS_DEV
40 echo -en "\x0c\xb1\xba\0\0\0\0\0" | \
41 dd of=$ZFS_DEV bs=1k count=8 \
42 seek=128 conv=notrunc &>/dev/null \
c9c0d073
BB
43 >/dev/null 2>/dev/null
44 echo -en "\x0c\xb1\xba\0\0\0\0\0" | \
45 dd of=$ZFS_DEV bs=1k count=8 \
46 seek=132 conv=notrunc &>/dev/null \
47 >/dev/null 2>/dev/null
a08ee875
LG
48 echo -en "\x0c\xb1\xba\0\0\0\0\0" | \
49 dd of=$ZFS_DEV bs=1k count=8 \
50 seek=136 conv=notrunc &>/dev/null \
51 >/dev/null 2>/dev/null
52 echo -en "\x0c\xb1\xba\0\0\0\0\0" | \
53 dd of=$ZFS_DEV bs=1k count=8 \
54 seek=140 conv=notrunc &>/dev/null \
55 >/dev/null 2>/dev/null
c9c0d073 56
a08ee875
LG
57 saved_LIBS="$LIBS"
58 LIBS="-lblkid"
c9c0d073 59
e89236fd 60 AC_RUN_IFELSE([AC_LANG_PROGRAM(
c9c0d073
BB
61 [
62 #include <stdio.h>
a08ee875 63 #include <stdlib.h>
c9c0d073
BB
64 #include <blkid/blkid.h>
65 ],
66 [
67 blkid_cache cache;
68 char *value;
69
70 if (blkid_get_cache(&cache, NULL) < 0)
71 return 1;
72
73 value = blkid_get_tag_value(cache, "TYPE",
74 "$ZFS_DEV");
75 if (!value) {
76 blkid_put_cache(cache);
77 return 2;
78 }
79
a08ee875 80 if (strcmp(value, "zfs_member")) {
c9c0d073
BB
81 free(value);
82 blkid_put_cache(cache);
a08ee875 83 return 0;
c9c0d073
BB
84 }
85
86 free(value);
87 blkid_put_cache(cache);
e89236fd 88 ])],
c9c0d073
BB
89 [
90 rm -f $ZFS_DEV
91 AC_MSG_RESULT([yes])
92 AC_SUBST([LIBBLKID], ["-lblkid"])
93 AC_DEFINE([HAVE_LIBBLKID], 1,
94 [Define if you have libblkid])
95 ],
96 [
97 rm -f $ZFS_DEV
98 AC_MSG_RESULT([no])
99 AS_IF([test "x$with_blkid" != xcheck],
100 [AC_MSG_FAILURE(
101 [--with-blkid given but unavailable])])
102 ])
103
a08ee875 104 LIBS="$saved_LIBS"
c9c0d073
BB
105 ],
106 [
107 AS_IF([test "x$with_blkid" != xcheck],
108 [AC_MSG_FAILURE(
109 [--with-blkid given but unavailable])])
110 ]
111 [])
112 ])
113])