]>
Commit | Line | Data |
---|---|---|
7bdf406d | 1 | dnl # |
0bd31011 TG |
2 | dnl # Check for ZFS support in libblkid. This test needs to check |
3 | dnl # more than if the library exists because we expect there are | |
4 | dnl # at least 3 flavors of the library out in the wild: | |
5 | dnl # | |
6 | dnl # 1) blkid which has no ZFS support | |
7 | dnl # 2) blkid with ZFS support and a flawed method of probing | |
8 | dnl # 3) blkid with ZFS support and a working method of probing | |
9 | dnl # | |
10 | dnl # To handle this the check first validates that there is a version | |
11 | dnl # of the library installed. If there is it creates a simulated | |
12 | dnl # ZFS filesystem and then links a small test app which attempts | |
13 | dnl # to detect the simualated filesystem type. If it correctly | |
14 | dnl # identifies the filesystem as ZFS we can safely assume case 3). | |
15 | dnl # Otherwise we disable blkid support and resort to manual probing. | |
7bdf406d TG |
16 | dnl # |
17 | AC_DEFUN([ZFS_AC_CONFIG_USER_LIBBLKID], [ | |
0bd31011 TG |
18 | AC_ARG_WITH([blkid], |
19 | [AS_HELP_STRING([--with-blkid], | |
20 | [support blkid caching @<:@default=check@:>@])], | |
21 | [], | |
22 | [with_blkid=check]) | |
23 | ||
7bdf406d | 24 | LIBBLKID= |
0bd31011 TG |
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], | |
33 | [ | |
34 | AC_CHECK_LIB([blkid], [blkid_get_cache], | |
35 | [ | |
36 | AC_MSG_CHECKING([for blkid zfs support]) | |
37 | ||
38 | ZFS_DEV=`mktemp` | |
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 \ | |
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 | |
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 | |
56 | ||
57 | saved_LIBS="$LIBS" | |
58 | LIBS="-lblkid" | |
59 | ||
60 | AC_RUN_IFELSE([AC_LANG_PROGRAM( | |
61 | [ | |
62 | #include <stdio.h> | |
63 | #include <stdlib.h> | |
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 | ||
80 | if (strcmp(value, "zfs_member")) { | |
81 | free(value); | |
82 | blkid_put_cache(cache); | |
83 | return 0; | |
84 | } | |
7bdf406d | 85 | |
0bd31011 TG |
86 | free(value); |
87 | blkid_put_cache(cache); | |
88 | ])], | |
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 | ]) | |
7bdf406d | 103 | |
0bd31011 TG |
104 | LIBS="$saved_LIBS" |
105 | ], | |
106 | [ | |
107 | AS_IF([test "x$with_blkid" != xcheck], | |
108 | [AC_MSG_FAILURE( | |
109 | [--with-blkid given but unavailable])]) | |
110 | ] | |
111 | []) | |
112 | ]) | |
7bdf406d | 113 | ]) |