+static bool
+__kernel_supports_unionfs(void)
+{
+ static int8_t kernel_supports_unionfs = -1;
+ if (kernel_supports_unionfs == -1) {
+ int value = 0;
+ size_t len = sizeof(value);
+ sysctlbyname("kern.secure_kernel", &value, &len, NULL, 0);
+ kernel_supports_unionfs = !value;
+ }
+ return kernel_supports_unionfs;
+}
+
+static int
+__fd_is_on_union_mount(int fd)
+{
+ struct statfs stbuf;
+ int rc;
+
+ rc = fstatfs(fd, &stbuf);
+ if (rc < 0) {
+ return rc;
+ }
+ return (stbuf.f_flags & MNT_UNION) != 0;
+}
+