[Midnightbsd-cvs] src: opensolaris/rpc: Add compatibility files from opensolaris (cddl)

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Mon Nov 10 21:11:36 EST 2008


Log Message:
-----------
Add compatibility files from opensolaris (cddl)

Added Files:
-----------
    src/sys/cddl/compat/opensolaris/kern:
        opensolaris_atomic.c (r1.1)
        opensolaris_kmem.c (r1.1)
        opensolaris_kobj.c (r1.1)
        opensolaris_kstat.c (r1.1)
        opensolaris_misc.c (r1.1)
        opensolaris_policy.c (r1.1)
        opensolaris_string.c (r1.1)
        opensolaris_vfs.c (r1.1)
        opensolaris_zone.c (r1.1)
    src/sys/cddl/compat/opensolaris/machine:
        endian.h (r1.1)
    src/sys/cddl/compat/opensolaris/rpc:
        xdr.h (r1.1)
    src/sys/cddl/compat/opensolaris/sys:
        acl.h (r1.1)
        atomic.h (r1.1)
        byteorder.h (r1.1)
        callb.h (r1.1)
        cmn_err.h (r1.1)
        cred.h (r1.1)
        debug.h (r1.1)
        dirent.h (r1.1)
        dkio.h (r1.1)
        dnlc.h (r1.1)
        kcondvar.h (r1.1)
        kmem.h (r1.1)
        kobj.h (r1.1)
        kstat.h (r1.1)
        lock.h (r1.1)
        misc.h (r1.1)
        mntent.h (r1.1)
        mnttab.h (r1.1)
        mount.h (r1.1)
        mutex.h (r1.1)
        policy.h (r1.1)
        proc.h (r1.1)
        random.h (r1.1)
        rwlock.h (r1.1)
        sdt.h (r1.1)
        string.h (r1.1)
        sunddi.h (r1.1)
        sysmacros.h (r1.1)
        systm.h (r1.1)
        taskq.h (r1.1)
        taskq_impl.h (r1.1)
        time.h (r1.1)
        types.h (r1.1)
        uio.h (r1.1)
        varargs.h (r1.1)
        vfs.h (r1.1)
        vnode.h (r1.1)
        zone.h (r1.1)

-------------- next part --------------
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_kstat.c
@@ -0,0 +1,131 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_kstat.c,v 1.2 2007/06/04 18:25:03 dwmalone Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/sysctl.h>
+#include <sys/kstat.h>
+
+static MALLOC_DEFINE(M_KSTAT, "kstat_data", "Kernel statistics");
+
+SYSCTL_NODE(, OID_AUTO, kstat, CTLFLAG_RW, 0, "Kernel statistics");
+
+kstat_t *
+kstat_create(char *module, int instance, char *name, char *class, uchar_t type,
+    ulong_t ndata, uchar_t flags)
+{
+	struct sysctl_oid *root;
+	kstat_t *ksp;
+
+	KASSERT(instance == 0, ("instance=%d", instance));
+	KASSERT(type == KSTAT_TYPE_NAMED, ("type=%hhu", type));
+	KASSERT(flags == KSTAT_FLAG_VIRTUAL, ("flags=%02hhx", flags));
+
+	/*
+	 * Allocate the main structure. We don't need to copy module/class/name
+	 * stuff in here, because it is only used for sysctl node creation
+	 * done in this function.
+	 */
+	ksp = malloc(sizeof(*ksp), M_KSTAT, M_WAITOK);
+	ksp->ks_ndata = ndata;
+
+	/*
+	 * Create sysctl tree for those statistics:
+	 *
+	 *	kstat.<module>.<class>.<name>.
+	 */
+	sysctl_ctx_init(&ksp->ks_sysctl_ctx);
+	root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx,
+	    SYSCTL_STATIC_CHILDREN(_kstat), OID_AUTO, module, CTLFLAG_RW, 0,
+	    "");
+	if (root == NULL) {
+		printf("%s: Cannot create kstat.%s tree!\n", __func__, module);
+		sysctl_ctx_free(&ksp->ks_sysctl_ctx);
+		free(ksp, M_KSTAT);
+		return (NULL);
+	}
+	root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx, SYSCTL_CHILDREN(root),
+	    OID_AUTO, class, CTLFLAG_RW, 0, "");
+	if (root == NULL) {
+		printf("%s: Cannot create kstat.%s.%s tree!\n", __func__,
+		    module, class);
+		sysctl_ctx_free(&ksp->ks_sysctl_ctx);
+		free(ksp, M_KSTAT);
+		return (NULL);
+	}
+	root = SYSCTL_ADD_NODE(&ksp->ks_sysctl_ctx, SYSCTL_CHILDREN(root),
+	    OID_AUTO, name, CTLFLAG_RW, 0, "");
+	if (root == NULL) {
+		printf("%s: Cannot create kstat.%s.%s.%s tree!\n", __func__,
+		    module, class, name);
+		sysctl_ctx_free(&ksp->ks_sysctl_ctx);
+		free(ksp, M_KSTAT);
+		return (NULL);
+	}
+	ksp->ks_sysctl_root = root;
+
+	return (ksp);
+}
+
+static int
+kstat_sysctl(SYSCTL_HANDLER_ARGS)
+{
+	kstat_named_t *ksent = arg1;
+	uint64_t val;
+
+	val = ksent->value.ui64;
+	return sysctl_handle_quad(oidp, &val, 0, req);
+}
+
+void
+kstat_install(kstat_t *ksp)
+{
+	kstat_named_t *ksent;
+	u_int i;
+
+	ksent = ksp->ks_data;
+	for (i = 0; i < ksp->ks_ndata; i++, ksent++) {
+		KASSERT(ksent->data_type == KSTAT_DATA_UINT64,
+		    ("data_type=%d", ksent->data_type));
+		SYSCTL_ADD_PROC(&ksp->ks_sysctl_ctx,
+		    SYSCTL_CHILDREN(ksp->ks_sysctl_root), OID_AUTO, ksent->name,
+		    CTLTYPE_QUAD | CTLFLAG_RD, ksent, sizeof(*ksent),
+		    kstat_sysctl, "QU", "");
+	}
+}
+
+void
+kstat_delete(kstat_t *ksp)
+{
+
+	sysctl_ctx_free(&ksp->ks_sysctl_ctx);
+	free(ksp, M_KSTAT);
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_kmem.c
@@ -0,0 +1,260 @@
+/*-
+ * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_kmem.c,v 1.2 2007/04/10 02:35:56 pjd Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/malloc.h>
+#include <sys/kmem.h>
+#include <sys/debug.h>
+#include <sys/mutex.h>
+
+#include <vm/vm_page.h>
+#include <vm/vm_object.h>
+#include <vm/vm_kern.h>
+#include <vm/vm_map.h>
+
+#ifdef KMEM_DEBUG
+#include <sys/queue.h>
+#include <sys/stack.h>
+#endif
+
+#ifdef _KERNEL
+static MALLOC_DEFINE(M_SOLARIS, "solaris", "Solaris");
+#else
+#define	malloc(size, type, flags)	malloc(size)
+#define	free(addr, type)		free(addr)
+#endif
+
+#ifdef KMEM_DEBUG
+struct kmem_item {
+	struct stack	stack;
+	LIST_ENTRY(kmem_item) next;
+};
+static LIST_HEAD(, kmem_item) kmem_items;
+static struct mtx kmem_items_mtx;
+MTX_SYSINIT(kmem_items_mtx, &kmem_items_mtx, "kmem_items", MTX_DEF);
+#endif	/* KMEM_DEBUG */
+
+void *
+zfs_kmem_alloc(size_t size, int kmflags)
+{
+	void *p;
+#ifdef KMEM_DEBUG
+	struct kmem_item *i;
+
+	size += sizeof(struct kmem_item);
+#endif
+	p = malloc(size, M_SOLARIS, kmflags);
+#ifndef _KERNEL
+	if (kmflags & KM_SLEEP)
+		assert(p != NULL);
+#endif
+#ifdef KMEM_DEBUG
+	if (p != NULL) {
+		i = p;
+		p = (u_char *)p + sizeof(struct kmem_item);
+		stack_save(&i->stack);
+		mtx_lock(&kmem_items_mtx);
+		LIST_INSERT_HEAD(&kmem_items, i, next);
+		mtx_unlock(&kmem_items_mtx);
+	}
+#endif
+	return (p);
+}
+
+void
+zfs_kmem_free(void *buf, size_t size __unused)
+{
+#ifdef KMEM_DEBUG
+	struct kmem_item *i;
+
+	buf = (u_char *)buf - sizeof(struct kmem_item);
+	mtx_lock(&kmem_items_mtx);
+	LIST_FOREACH(i, &kmem_items, next) {
+		if (i == buf)
+			break;
+	}
+	ASSERT(i != NULL);
+	LIST_REMOVE(i, next);
+	mtx_unlock(&kmem_items_mtx);
+#endif
+	free(buf, M_SOLARIS);
+}
+
+u_long
+kmem_size(void)
+{
+
+	return ((u_long)vm_kmem_size);
+}
+
+u_long
+kmem_used(void)
+{
+
+	return ((u_long)kmem_map->size);
+}
+
+static int
+kmem_std_constructor(void *mem, int size __unused, void *private, int flags)
+{
+	struct kmem_cache *cache = private;
+
+	return (cache->kc_constructor(mem, cache->kc_private, flags));
+}
+
+static void
+kmem_std_destructor(void *mem, int size __unused, void *private)
+{
+	struct kmem_cache *cache = private;
+
+	cache->kc_destructor(mem, cache->kc_private);
+}
+
+kmem_cache_t *
+kmem_cache_create(char *name, size_t bufsize, size_t align,
+    int (*constructor)(void *, void *, int), void (*destructor)(void *, void *),
+    void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags)
+{
+	kmem_cache_t *cache;
+
+	ASSERT(vmp == NULL);
+
+	cache = kmem_alloc(sizeof(*cache), KM_SLEEP);
+	strlcpy(cache->kc_name, name, sizeof(cache->kc_name));
+	cache->kc_constructor = constructor;
+	cache->kc_destructor = destructor;
+	cache->kc_private = private;
+#ifdef _KERNEL
+	cache->kc_zone = uma_zcreate(cache->kc_name, bufsize,
+	    constructor != NULL ? kmem_std_constructor : NULL,
+	    destructor != NULL ? kmem_std_destructor : NULL,
+	    NULL, NULL, align > 0 ? align - 1 : 0, cflags);
+#else
+	cache->kc_size = bufsize;
+#endif
+
+	return (cache);
+}
+
+void
+kmem_cache_destroy(kmem_cache_t *cache)
+{
+	uma_zdestroy(cache->kc_zone);
+	kmem_free(cache, sizeof(*cache));
+}
+
+void *
+kmem_cache_alloc(kmem_cache_t *cache, int flags)
+{
+#ifdef _KERNEL
+	return (uma_zalloc_arg(cache->kc_zone, cache, flags));
+#else
+	void *p;
+
+	p = kmem_alloc(cache->kc_size, flags);
+	if (p != NULL) {
+		kmem_std_constructor(p, cache->kc_size, cache->kc_private,
+		    flags);
+	}
+	return (p);
+#endif
+}
+
+void
+kmem_cache_free(kmem_cache_t *cache, void *buf)
+{
+#ifdef _KERNEL
+	uma_zfree_arg(cache->kc_zone, buf, cache);
+#else
+	kmem_std_destructor(buf, cache->kc_size, cache->kc_private);
+	kmem_free(buf, cache->kc_size);
+#endif
+}
+
+#ifdef _KERNEL
+extern void zone_drain(uma_zone_t zone);
+void
+kmem_cache_reap_now(kmem_cache_t *cache)
+{
+	zone_drain(cache->kc_zone);
+}
+
+void
+kmem_reap(void)
+{
+	uma_reclaim();
+}
+#else
+void
+kmem_cache_reap_now(kmem_cache_t *cache __unused)
+{
+}
+
+void
+kmem_reap(void)
+{
+}
+#endif
+
+int
+kmem_debugging(void)
+{
+	return (0);
+}
+
+void *
+calloc(size_t n, size_t s)
+{
+	return (kmem_zalloc(n * s, KM_NOSLEEP));
+}
+
+#ifdef KMEM_DEBUG
+static void
+kmem_show(void *dummy __unused)
+{
+	struct kmem_item *i;
+
+	mtx_lock(&kmem_items_mtx);
+	if (LIST_EMPTY(&kmem_items))
+		printf("KMEM_DEBUG: No leaked elements.\n");
+	else {
+		printf("KMEM_DEBUG: Leaked elements:\n\n");
+		LIST_FOREACH(i, &kmem_items, next) {
+			printf("address=%p\n", i);
+			stack_print(&i->stack);
+			printf("\n");
+		}
+	}
+	mtx_unlock(&kmem_items_mtx);
+}
+
+SYSUNINIT(sol_kmem, SI_SUB_DRIVERS, SI_ORDER_FIRST, kmem_show, NULL);
+#endif	/* KMEM_DEBUG */
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_string.c
@@ -0,0 +1,71 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#include <sys/param.h>
+#include <sys/string.h>
+
+#define	IS_DIGIT(c)	((c) >= '0' && (c) <= '9')
+
+#define	IS_ALPHA(c)	\
+	(((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
+
+char *
+strpbrk(const char *s, const char *b)
+{
+	const char *p;
+
+	do {
+		for (p = b; *p != '\0' && *p != *s; ++p)
+			;
+		if (*p != '\0')
+			return ((char *)s);
+	} while (*s++);
+
+	return (NULL);
+}
+
+/*
+ * Convert a string into a valid C identifier by replacing invalid
+ * characters with '_'.  Also makes sure the string is nul-terminated
+ * and takes up at most n bytes.
+ */
+void
+strident_canon(char *s, size_t n)
+{
+	char c;
+	char *end = s + n - 1;
+
+	if ((c = *s) == 0)
+		return;
+
+	if (!IS_ALPHA(c) && c != '_')
+		*s = '_';
+
+	while (s < end && ((c = *(++s)) != 0)) {
+		if (!IS_ALPHA(c) && !IS_DIGIT(c) && c != '_')
+			*s = '_';
+	}
+	*s = 0;
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_zone.c
@@ -0,0 +1,237 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_zone.c,v 1.1 2007/04/06 01:09:06 pjd Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/sx.h>
+#include <sys/malloc.h>
+#include <sys/queue.h>
+#include <sys/jail.h>
+#include <sys/priv.h>
+#include <sys/zone.h>
+
+static MALLOC_DEFINE(M_ZONES, "zones_data", "Zones data");
+
+/*
+ * Structure to record list of ZFS datasets exported to a zone.
+ */
+typedef struct zone_dataset {
+	LIST_ENTRY(zone_dataset) zd_next;
+	char	zd_dataset[0];
+} zone_dataset_t;
+
+LIST_HEAD(zone_dataset_head, zone_dataset);
+
+static struct prison_service *zone_prison_service = NULL;
+
+int
+zone_dataset_attach(struct ucred *cred, const char *dataset, int jailid)
+{
+	struct zone_dataset_head *head;
+	zone_dataset_t *zd, *zd2;
+	struct prison *pr;
+	int error;
+
+	if ((error = priv_check_cred(cred, PRIV_ZFS_JAIL, 0)) != 0)
+		return (error);
+
+	/* Allocate memory before we grab prison's mutex. */
+	zd = malloc(sizeof(*zd) + strlen(dataset) + 1, M_ZONES, M_WAITOK);
+
+	sx_slock(&allprison_lock);
+	pr = prison_find(jailid);	/* Locks &pr->pr_mtx. */
+	sx_sunlock(&allprison_lock);
+	if (pr == NULL) {
+		free(zd, M_ZONES);
+		return (ENOENT);
+	}
+
+	head = prison_service_data_get(zone_prison_service, pr);
+	LIST_FOREACH(zd2, head, zd_next) {
+		if (strcmp(dataset, zd2->zd_dataset) == 0) {
+			free(zd, M_ZONES);
+			error = EEXIST;
+			goto failure;
+		}
+	}
+	strcpy(zd->zd_dataset, dataset);
+	LIST_INSERT_HEAD(head, zd, zd_next);
+failure:
+	mtx_unlock(&pr->pr_mtx);
+	return (error);
+}
+
+int
+zone_dataset_detach(struct ucred *cred, const char *dataset, int jailid)
+{
+	struct zone_dataset_head *head;
+	zone_dataset_t *zd;
+	struct prison *pr;
+	int error;
+
+	if ((error = priv_check_cred(cred, PRIV_ZFS_JAIL, 0)) != 0)
+		return (error);
+
+	sx_slock(&allprison_lock);
+	pr = prison_find(jailid);
+	sx_sunlock(&allprison_lock);
+	if (pr == NULL)
+		return (ENOENT);
+	head = prison_service_data_get(zone_prison_service, pr);
+	LIST_FOREACH(zd, head, zd_next) {
+		if (strcmp(dataset, zd->zd_dataset) == 0) {
+			LIST_REMOVE(zd, zd_next);
+			free(zd, M_ZONES);
+			goto success;
+		}
+	}
+	error = ENOENT;
+success:
+	mtx_unlock(&pr->pr_mtx);
+	return (error);
+}
+
+/*
+ * Returns true if the named dataset is visible in the current zone.
+ * The 'write' parameter is set to 1 if the dataset is also writable.
+ */
+int
+zone_dataset_visible(const char *dataset, int *write)
+{
+	struct zone_dataset_head *head;
+	zone_dataset_t *zd;
+	struct prison *pr;
+	size_t len;
+	int ret = 0;
+
+	if (dataset[0] == '\0')
+		return (0);
+	if (INGLOBALZONE(curproc)) {
+		if (write != NULL)
+			*write = 1;
+		return (1);
+	}
+	pr = curthread->td_ucred->cr_prison;
+	mtx_lock(&pr->pr_mtx);
+	head = prison_service_data_get(zone_prison_service, pr);
+
+	/*
+	 * Walk the list once, looking for datasets which match exactly, or
+	 * specify a dataset underneath an exported dataset.  If found, return
+	 * true and note that it is writable.
+	 */
+	LIST_FOREACH(zd, head, zd_next) {
+		len = strlen(zd->zd_dataset);
+		if (strlen(dataset) >= len &&
+		    bcmp(dataset, zd->zd_dataset, len) == 0 &&
+		    (dataset[len] == '\0' || dataset[len] == '/' ||
+		    dataset[len] == '@')) {
+			if (write)
+				*write = 1;
+			ret = 1;
+			goto end;
+		}
+	}
+
+	/*
+	 * Walk the list a second time, searching for datasets which are parents
+	 * of exported datasets.  These should be visible, but read-only.
+	 *
+	 * Note that we also have to support forms such as 'pool/dataset/', with
+	 * a trailing slash.
+	 */
+	LIST_FOREACH(zd, head, zd_next) {
+		len = strlen(dataset);
+		if (dataset[len - 1] == '/')
+			len--;	/* Ignore trailing slash */
+		if (len < strlen(zd->zd_dataset) &&
+		    bcmp(dataset, zd->zd_dataset, len) == 0 &&
+		    zd->zd_dataset[len] == '/') {
+			if (write)
+				*write = 0;
+			ret = 1;
+			goto end;
+		}
+	}
+end:
+	mtx_unlock(&pr->pr_mtx);
+	return (ret);
+}
+
+static int
+zone_create(struct prison_service *psrv, struct prison *pr)
+{
+	struct zone_dataset_head *head;
+
+	head = malloc(sizeof(*head), M_ZONES, M_WAITOK);
+	LIST_INIT(head);
+	mtx_lock(&pr->pr_mtx);
+	prison_service_data_set(psrv, pr, head);
+	mtx_unlock(&pr->pr_mtx);
+	return (0);
+}
+
+static int
+zone_destroy(struct prison_service *psrv, struct prison *pr)
+{
+	struct zone_dataset_head *head;
+	zone_dataset_t *zd;
+
+	mtx_lock(&pr->pr_mtx);
+	head = prison_service_data_del(psrv, pr);
+	mtx_unlock(&pr->pr_mtx);
+	while ((zd = LIST_FIRST(head)) != NULL) {
+		LIST_REMOVE(zd, zd_next);
+		free(zd, M_ZONES);
+	}
+	free(head, M_ZONES);
+	return (0);
+}
+
+static void
+zone_sysinit(void *arg __unused)
+{
+
+	zone_prison_service = prison_service_register("zfs", zone_create,
+	    zone_destroy);
+}
+
+static void
+zone_sysuninit(void *arg __unused)
+{
+
+	prison_service_deregister(zone_prison_service);
+}
+
+SYSINIT(zone_sysinit, SI_SUB_DRIVERS, SI_ORDER_ANY, zone_sysinit, NULL);
+SYSUNINIT(zone_sysuninit, SI_SUB_DRIVERS, SI_ORDER_ANY, zone_sysuninit, NULL);
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_kobj.c
@@ -0,0 +1,220 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_kobj.c,v 1.4 2007/05/31 11:51:49 kib Exp $");
+
+#include <sys/types.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/kthread.h>
+#include <sys/namei.h>
+#include <sys/proc.h>
+#include <sys/filedesc.h>
+#include <sys/fcntl.h>
+#include <sys/linker.h>
+#include <sys/kobj.h>
+
+void
+kobj_free(void *address, size_t size)
+{
+
+	kmem_free(address, size);
+}
+
+void *
+kobj_alloc(size_t size, int flag)
+{
+
+	return (kmem_alloc(size, (flag & KM_NOWAIT) ? KM_NOSLEEP : KM_SLEEP));
+}
+
+void *
+kobj_zalloc(size_t size, int flag)
+{
+	void *p;
+
+	if ((p = kobj_alloc(size, flag)) != NULL)
+		bzero(p, size);
+	return (p);
+}
+
+static void *
+kobj_open_file_vnode(const char *file)
+{
+	struct thread *td = curthread;
+	struct nameidata nd;
+	int error, flags;
+
+	if (td->td_proc->p_fd->fd_rdir == NULL)
+		td->td_proc->p_fd->fd_rdir = rootvnode;
+	if (td->td_proc->p_fd->fd_cdir == NULL)
+		td->td_proc->p_fd->fd_cdir = rootvnode;
+
+	flags = FREAD;
+	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, file, td);
+	error = vn_open_cred(&nd, &flags, 0, td->td_ucred, NULL);
+	NDFREE(&nd, NDF_ONLY_PNBUF);
+	if (error != 0)
+		return (NULL);
+	/* We just unlock so we hold a reference. */
+	VOP_UNLOCK(nd.ni_vp, 0, td);
+	return (nd.ni_vp);
+}
+
+static void *
+kobj_open_file_loader(const char *file)
+{
+
+	return (preload_search_by_name(file));
+}
+
+struct _buf *
+kobj_open_file(const char *file)
+{
+	struct _buf *out;
+
+	out = kmem_alloc(sizeof(*out), KM_SLEEP);
+	out->mounted = root_mounted();
+	/*
+	 * If root is already mounted we read file using file system,
+	 * if not, we use loader.
+	 */
+	if (out->mounted)
+		out->ptr = kobj_open_file_vnode(file);
+	else
+		out->ptr = kobj_open_file_loader(file);
+	if (out->ptr == NULL) {
+		kmem_free(out, sizeof(*out));
+		return ((struct _buf *)-1);
+	}
+	return (out);
+}
+
+static int
+kobj_get_filesize_vnode(struct _buf *file, uint64_t *size)
+{
+	struct vnode *vp = file->ptr;
+	struct thread *td = curthread;
+	struct vattr va;
+	int error;
+
+	vn_lock(vp, LK_SHARED | LK_RETRY, td);
+	error = VOP_GETATTR(vp, &va, td->td_ucred, td);
+	VOP_UNLOCK(vp, 0, td);
+	if (error == 0)
+		*size = (uint64_t)va.va_size;
+	return (error);
+}
+
+static int
+kobj_get_filesize_loader(struct _buf *file, uint64_t *size)
+{
+	void *ptr;
+
+	ptr = preload_search_info(file->ptr, MODINFO_SIZE);
+	if (ptr == NULL)
+		return (ENOENT);
+	*size = (uint64_t)*(size_t *)ptr;
+	return (0);
+}
+
+int
+kobj_get_filesize(struct _buf *file, uint64_t *size)
+{
+
+	if (file->mounted)
+		return (kobj_get_filesize_vnode(file, size));
+	else
+		return (kobj_get_filesize_loader(file, size));
+}
+
+int
+kobj_read_file_vnode(struct _buf *file, char *buf, unsigned size, unsigned off)
+{
+	struct vnode *vp = file->ptr;
+	struct thread *td = curthread;
+	struct uio auio;
+	struct iovec aiov;
+	int error;
+
+	bzero(&aiov, sizeof(aiov));
+	bzero(&auio, sizeof(auio));
+
+	aiov.iov_base = buf;
+	aiov.iov_len = size;
+
+	auio.uio_iov = &aiov;
+	auio.uio_offset = (off_t)off;
+	auio.uio_segflg = UIO_SYSSPACE;
+	auio.uio_rw = UIO_READ;
+	auio.uio_iovcnt = 1;
+	auio.uio_resid = size;
+	auio.uio_td = td;
+
+	vn_lock(vp, LK_SHARED | LK_RETRY, td);
+	error = VOP_READ(vp, &auio, IO_UNIT | IO_SYNC, td->td_ucred);
+	VOP_UNLOCK(vp, 0, td);
+	return (error != 0 ? -1 : size - auio.uio_resid);
+}
+
+int
+kobj_read_file_loader(struct _buf *file, char *buf, unsigned size, unsigned off)
+{
+	char *ptr;
+
+	ptr = preload_search_info(file->ptr, MODINFO_ADDR);
+	if (ptr == NULL)
+		return (ENOENT);
+	ptr = *(void **)ptr;
+	bcopy(ptr + off, buf, size);
+	return (0);
+}
+
+int
+kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off)
+{
+
+	if (file->mounted)
+		return (kobj_read_file_vnode(file, buf, size, off));
+	else
+		return (kobj_read_file_loader(file, buf, size, off));
+}
+
+void
+kobj_close_file(struct _buf *file)
+{
+
+	if (file->mounted) {
+		struct vnode *vp = file->ptr;
+		struct thread *td = curthread;
+		int flags = FREAD;
+
+		vn_close(vp, flags, td->td_ucred, td);
+	}
+	kmem_free(file, sizeof(*file));
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_vfs.c
@@ -0,0 +1,276 @@
+/*-
+ * Copyright (c) 2006-2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_vfs.c,v 1.6 2007/06/04 11:31:45 pjd Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/systm.h>
+#include <sys/mount.h>
+#include <sys/cred.h>
+#include <sys/vfs.h>
+#include <sys/priv.h>
+#include <sys/libkern.h>
+
+MALLOC_DECLARE(M_MOUNT);
+
+TAILQ_HEAD(vfsoptlist, vfsopt);
+struct vfsopt {
+	TAILQ_ENTRY(vfsopt) link;
+	char	*name;
+	void	*value;
+	int	len;
+};
+
+void
+vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
+    int flags __unused)
+{
+	struct vfsopt *opt;
+	size_t namesize;
+
+	if (vfsp->mnt_opt == NULL) {
+		vfsp->mnt_opt = malloc(sizeof(*vfsp->mnt_opt), M_MOUNT, M_WAITOK);
+		TAILQ_INIT(vfsp->mnt_opt);
+	}
+
+	opt = malloc(sizeof(*opt), M_MOUNT, M_WAITOK);
+
+	namesize = strlen(name) + 1;
+	opt->name = malloc(namesize, M_MOUNT, M_WAITOK);
+	strlcpy(opt->name, name, namesize);
+
+	if (arg == NULL) {
+		opt->value = NULL;
+		opt->len = 0;
+	} else {
+		opt->len = strlen(arg) + 1;
+		opt->value = malloc(opt->len, M_MOUNT, M_WAITOK);
+		bcopy(arg, opt->value, opt->len);
+	}
+	/* TODO: Locking. */
+	TAILQ_INSERT_TAIL(vfsp->mnt_opt, opt, link);
+}
+
+void
+vfs_clearmntopt(vfs_t *vfsp, const char *name)
+{
+	struct vfsopt *opt;
+
+	if (vfsp->mnt_opt == NULL)
+		return;
+	/* TODO: Locking. */
+	TAILQ_FOREACH(opt, vfsp->mnt_opt, link) {
+		if (strcmp(opt->name, name) == 0)
+			break;
+	}
+	if (opt != NULL) {
+		TAILQ_REMOVE(vfsp->mnt_opt, opt, link);
+		free(opt->name, M_MOUNT);
+		if (opt->value != NULL)
+			free(opt->value, M_MOUNT);
+		free(opt, M_MOUNT);
+	}
+}
+
+int
+vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp)
+{
+	struct vfsoptlist *opts = vfsp->mnt_opt;
+	int error;
+
+	if (opts == NULL)
+		return (0);
+	error = vfs_getopt(opts, opt, (void **)argp, NULL);
+	return (error != 0 ? 0 : 1);
+}
+
+int
+traverse(vnode_t **cvpp, int lktype)
+{
+	kthread_t *td = curthread;
+	vnode_t *cvp;
+	vnode_t *tvp;
+	vfs_t *vfsp;
+	int error;
+
+	cvp = *cvpp;
+	tvp = NULL;
+
+	/*
+	 * If this vnode is mounted on, then we transparently indirect
+	 * to the vnode which is the root of the mounted file system.
+	 * Before we do this we must check that an unmount is not in
+	 * progress on this vnode.
+	 */
+
+	for (;;) {
+		/*
+		 * Reached the end of the mount chain?
+		 */
+		vfsp = vn_mountedvfs(cvp);
+		if (vfsp == NULL)
+			break;
+		/*
+		 * tvp is NULL for *cvpp vnode, which we can't unlock.
+		 */
+		if (tvp != NULL)
+			vput(cvp);
+		else
+			vrele(cvp);
+
+		/*
+		 * The read lock must be held across the call to VFS_ROOT() to
+		 * prevent a concurrent unmount from destroying the vfs.
+		 */
+		error = VFS_ROOT(vfsp, lktype, &tvp, td);
+		if (error != 0)
+			return (error);
+		cvp = tvp;
+	}
+
+	*cvpp = cvp;
+	return (0);
+}
+
+int
+domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
+    char *fspec, int fsflags)
+{
+	struct mount *mp;
+	struct vfsconf *vfsp;
+	int error;
+
+	/*
+	 * Be ultra-paranoid about making sure the type and fspath
+	 * variables will fit in our mp buffers, including the
+	 * terminating NUL.
+	 */
+	if (strlen(fstype) >= MFSNAMELEN || strlen(fspath) >= MNAMELEN)
+		return (ENAMETOOLONG);
+
+	vfsp = vfs_byname_kld(fstype, td, &error);
+	if (vfsp == NULL)
+		return (ENODEV);
+
+	if (vp->v_type != VDIR)
+		return (ENOTDIR);
+	VI_LOCK(vp);
+	if ((vp->v_iflag & VI_MOUNT) != 0 ||
+	    vp->v_mountedhere != NULL) {
+		VI_UNLOCK(vp);
+		return (EBUSY);
+	}
+	vp->v_iflag |= VI_MOUNT;
+	VI_UNLOCK(vp);
+
+	/*
+	 * Allocate and initialize the filesystem.
+	 */
+	vn_lock(vp, LK_SHARED | LK_RETRY, td);
+	mp = vfs_mount_alloc(vp, vfsp, fspath, td);
+	VOP_UNLOCK(vp, 0, td);
+
+	mp->mnt_optnew = NULL;
+	vfs_setmntopt(mp, "from", fspec, 0);
+	mp->mnt_optnew = mp->mnt_opt;
+	mp->mnt_opt = NULL;
+
+	/*
+	 * Set the mount level flags.
+	 */
+	MNT_ILOCK(mp);
+	if (fsflags & MNT_RDONLY)
+		mp->mnt_flag |= MNT_RDONLY;
+	mp->mnt_flag &=~ MNT_UPDATEMASK;
+	mp->mnt_flag |= fsflags & (MNT_UPDATEMASK | MNT_FORCE | MNT_ROOTFS);
+	/*
+	 * Unprivileged user can trigger mounting a snapshot, but we don't want
+	 * him to unmount it, so we switch to privileged credentials.
+	 */
+	crfree(mp->mnt_cred);
+	mp->mnt_cred = crdup(kcred);
+	mp->mnt_stat.f_owner = mp->mnt_cred->cr_uid;
+	MNT_IUNLOCK(mp);
+	/*
+	 * Mount the filesystem.
+	 * XXX The final recipients of VFS_MOUNT just overwrite the ndp they
+	 * get.  No freeing of cn_pnbuf.
+	 */
+	error = VFS_MOUNT(mp, td);
+
+	if (!error) {
+		if (mp->mnt_opt != NULL)
+			vfs_freeopts(mp->mnt_opt);
+		mp->mnt_opt = mp->mnt_optnew;
+		(void)VFS_STATFS(mp, &mp->mnt_stat, td);
+	}
+	/*
+	 * Prevent external consumers of mount options from reading
+	 * mnt_optnew.
+	*/
+	mp->mnt_optnew = NULL;
+	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
+	/*
+	 * Put the new filesystem on the mount list after root.
+	 */
+#ifdef FREEBSD_NAMECACHE
+	cache_purge(vp);
+#endif
+	if (!error) {
+		vnode_t *mvp;
+
+		VI_LOCK(vp);
+		vp->v_iflag &= ~VI_MOUNT;
+		VI_UNLOCK(vp);
+		vp->v_mountedhere = mp;
+		mtx_lock(&mountlist_mtx);
+		TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
+		mtx_unlock(&mountlist_mtx);
+		vfs_event_signal(NULL, VQ_MOUNT, 0);
+		if (VFS_ROOT(mp, LK_EXCLUSIVE, &mvp, td))
+			panic("mount: lost mount");
+		mountcheckdirs(vp, mvp);
+		vput(mvp);
+		VOP_UNLOCK(vp, 0, td);
+		if ((mp->mnt_flag & MNT_RDONLY) == 0)
+			error = vfs_allocate_syncvnode(mp);
+		vfs_unbusy(mp, td);
+		if (error)
+			vrele(vp);
+		else
+			vfs_mountedfrom(mp, fspec);
+	} else {
+		VI_LOCK(vp);
+		vp->v_iflag &= ~VI_MOUNT;
+		VI_UNLOCK(vp);
+		VOP_UNLOCK(vp, 0, td);
+		vfs_unbusy(mp, td);
+		vfs_mount_destroy(mp);
+	}
+	return (error);
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_misc.c
@@ -0,0 +1,56 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_misc.c,v 1.2 2007/04/23 00:52:06 pjd Exp $");
+
+#include <sys/param.h>
+#include <sys/kernel.h>
+#include <sys/libkern.h>
+#include <sys/misc.h>
+#include <sys/sunddi.h>
+
+char hw_serial[11] = "0";
+
+struct opensolaris_utsname utsname = {
+	.nodename = hostname
+};
+
+int
+ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result)
+{
+	char *end;
+
+	if (str == hw_serial) {
+		*result = hostid;
+		return (0);
+	}
+
+	*result = strtoul(str, &end, base);
+	if (*result == 0)
+		return (EINVAL);
+	return (0);
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_atomic.c
@@ -0,0 +1,133 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_atomic.c,v 1.1 2007/06/08 12:35:45 pjd Exp $");
+
+#include <sys/param.h>
+#include <sys/lock.h>
+#include <sys/mutex.h>
+#include <sys/atomic.h>
+
+#ifdef _KERNEL
+#include <sys/kernel.h>
+
+struct mtx atomic_mtx;
+MTX_SYSINIT(atomic, &atomic_mtx, "atomic", MTX_DEF);
+#else
+#include <pthread.h>
+
+#define	mtx_lock(lock)		pthread_mutex_lock(lock)
+#define	mtx_unlock(lock)	pthread_mutex_unlock(lock)
+
+static pthread_mutex_t atomic_mtx;
+
+static __attribute__((constructor)) void
+atomic_init(void)
+{
+	pthread_mutex_init(&atomic_mtx, NULL);
+}
+#endif
+
+#ifndef __LP64__
+void
+atomic_add_64(volatile uint64_t *target, int64_t delta)
+{
+
+	mtx_lock(&atomic_mtx);
+	*target += delta;
+	mtx_unlock(&atomic_mtx);
+}
+#endif
+
+uint64_t
+atomic_add_64_nv(volatile uint64_t *target, int64_t delta)
+{
+	uint64_t newval;
+
+	mtx_lock(&atomic_mtx);
+	newval = (*target += delta);
+	mtx_unlock(&atomic_mtx);
+	return (newval);
+}
+
+#if defined(__sparc64__) || defined(__powerpc__) || defined(__arm__)
+void
+atomic_or_8(volatile uint8_t *target, uint8_t value)
+{
+	mtx_lock(&atomic_mtx);
+	*target |= value;
+	mtx_unlock(&atomic_mtx);
+}
+#endif
+
+uint8_t
+atomic_or_8_nv(volatile uint8_t *target, uint8_t value)
+{
+	uint8_t newval;
+
+	mtx_lock(&atomic_mtx);
+	newval = (*target |= value);
+	mtx_unlock(&atomic_mtx);
+	return (newval);
+}
+
+#ifndef __LP64__
+void *
+atomic_cas_ptr(volatile void *target, void *cmp,  void *newval)
+{
+	void *oldval, **trg;
+
+	mtx_lock(&atomic_mtx);
+	trg = __DEVOLATILE(void **, target);
+	oldval = *trg;
+	if (oldval == cmp)
+		*trg = newval;
+	mtx_unlock(&atomic_mtx);
+	return (oldval);
+}
+#endif
+
+#ifndef __sparc64__
+uint64_t
+atomic_cas_64(volatile uint64_t *target, uint64_t cmp, uint64_t newval)
+{
+	uint64_t oldval;
+
+	mtx_lock(&atomic_mtx);
+	oldval = *target;
+	if (oldval == cmp)
+		*target = newval;
+	mtx_unlock(&atomic_mtx);
+	return (oldval);
+}
+#endif
+
+void
+membar_producer(void)
+{
+	/* nothing */
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/kern/opensolaris_policy.c
@@ -0,0 +1,261 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD: src/sys/compat/opensolaris/kern/opensolaris_policy.c,v 1.2 2007/06/12 00:11:57 rwatson Exp $");
+
+#include <sys/param.h>
+#include <sys/priv.h>
+#include <sys/vnode.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/policy.h>
+
+int
+secpolicy_zfs(struct ucred *cred)
+{
+
+	return (priv_check_cred(cred, PRIV_VFS_MOUNT, 0));
+}
+
+int
+secpolicy_sys_config(struct ucred *cred, int checkonly __unused)
+{
+
+	return (priv_check_cred(cred, PRIV_ZFS_POOL_CONFIG, 0));
+}
+
+int
+secpolicy_zinject(struct ucred *cred)
+{
+
+	return (priv_check_cred(cred, PRIV_ZFS_INJECT, 0));
+}
+
+int
+secpolicy_fs_unmount(struct ucred *cred, struct mount *vfsp __unused)
+{
+
+	return (priv_check_cred(cred, PRIV_VFS_UNMOUNT, 0));
+}
+
+/*
+ * This check is done in kern_link(), so we could just return 0 here.
+ */
+extern int hardlink_check_uid;
+int
+secpolicy_basic_link(struct ucred *cred)
+{
+
+	if (!hardlink_check_uid)
+		return (0);
+	return (priv_check_cred(cred, PRIV_VFS_LINK, 0));
+}
+
+int
+secpolicy_vnode_stky_modify(struct ucred *cred)
+{
+
+	return (EPERM);
+}
+
+int
+secpolicy_vnode_remove(struct ucred *cred)
+{
+
+	return (priv_check_cred(cred, PRIV_VFS_ADMIN, 0));
+}
+
+int
+secpolicy_vnode_access(struct ucred *cred, struct vnode *vp, uint64_t owner,
+    int mode)
+{
+
+	if ((mode & VREAD) && priv_check_cred(cred, PRIV_VFS_READ, 0) != 0) {
+		return (EACCES);
+	}
+	if ((mode & VWRITE) &&
+	    priv_check_cred(cred, PRIV_VFS_WRITE, 0) != 0) {
+		return (EACCES);
+	}
+	if (mode & VEXEC) {
+		if (vp->v_type == VDIR) {
+			if (priv_check_cred(cred, PRIV_VFS_LOOKUP, 0) != 0) {
+				return (EACCES);
+			}
+		} else {
+			if (priv_check_cred(cred, PRIV_VFS_EXEC, 0) != 0) {
+				return (EACCES);
+			}
+		}
+	}
+	return (0);
+}
+
+int
+secpolicy_vnode_setdac(struct ucred *cred, uid_t owner)
+{
+
+	if (owner == cred->cr_uid)
+		return (0);
+	return (priv_check_cred(cred, PRIV_VFS_ADMIN, 0));
+}
+
+int
+secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp, struct vattr *vap,
+    const struct vattr *ovap, int flags,
+    int unlocked_access(void *, int, struct ucred *), void *node)
+{
+	int mask = vap->va_mask;
+	int error;
+
+	if (mask & AT_SIZE) {
+		if (vp->v_type == VDIR)
+			return (EISDIR);
+		error = unlocked_access(node, VWRITE, cred);
+		if (error)
+			return (error);
+	}
+	if (mask & AT_MODE) {
+		/*
+		 * If not the owner of the file then check privilege
+		 * for two things: the privilege to set the mode at all
+		 * and, if we're setting setuid, we also need permissions
+		 * to add the set-uid bit, if we're not the owner.
+		 * In the specific case of creating a set-uid root
+		 * file, we need even more permissions.
+		 */
+		error = secpolicy_vnode_setdac(cred, ovap->va_uid);
+		if (error)
+			return (error);
+		error = secpolicy_setid_setsticky_clear(vp, vap, ovap, cred);
+		if (error)
+			return (error);
+	} else {
+		vap->va_mode = ovap->va_mode;
+	}
+	if (mask & (AT_UID | AT_GID)) {
+		error = secpolicy_vnode_setdac(cred, ovap->va_uid);
+		if (error)
+			return (error);
+
+		/*
+		 * To change the owner of a file, or change the group of a file to a
+		 * group of which we are not a member, the caller must have
+		 * privilege.
+		 */
+		if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
+		    ((mask & AT_GID) && vap->va_gid != ovap->va_gid &&
+		     !groupmember(vap->va_gid, cred))) {
+			error = priv_check_cred(cred, PRIV_VFS_CHOWN, 0);
+			if (error)
+				return (error);
+		}
+
+		if (((mask & AT_UID) && vap->va_uid != ovap->va_uid) ||
+		    ((mask & AT_GID) && vap->va_gid != ovap->va_gid)) {
+			secpolicy_setid_clear(vap, cred);
+		}
+	}
+	if (mask & (AT_ATIME | AT_MTIME)) {
+		/*
+		 * From utimes(2):
+		 * If times is NULL, ... The caller must be the owner of
+		 * the file, have permission to write the file, or be the
+		 * super-user.
+		 * If times is non-NULL, ... The caller must be the owner of
+		 * the file or be the super-user.
+		 */
+		error = secpolicy_vnode_setdac(cred, ovap->va_uid);
+		if (error && (vap->va_vaflags & VA_UTIMES_NULL))
+			error = unlocked_access(node, VWRITE, cred);
+		if (error)
+			return (error);
+	}
+	return (0);
+}
+
+int
+secpolicy_vnode_create_gid(struct ucred *cred)
+{
+
+	return (EPERM);
+}
+
+int
+secpolicy_vnode_setids_setgids(struct ucred *cred, gid_t gid)
+{
+
+	if (!groupmember(gid, cred))
+		return (priv_check_cred(cred, PRIV_VFS_SETGID, 0));
+	return (0);
+}
+
+int
+secpolicy_vnode_setid_retain(struct ucred *cred, boolean_t issuidroot __unused)
+{
+
+	return (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0));
+}
+
+void
+secpolicy_setid_clear(struct vattr *vap, struct ucred *cred)
+{
+
+	if ((vap->va_mode & (S_ISUID | S_ISGID)) != 0) {
+		if (priv_check_cred(cred, PRIV_VFS_RETAINSUGID, 0)) {
+			vap->va_mask |= AT_MODE;
+			vap->va_mode &= ~(S_ISUID|S_ISGID);
+		}
+	}
+}
+
+int
+secpolicy_setid_setsticky_clear(struct vnode *vp, struct vattr *vap,
+    const struct vattr *ovap, struct ucred *cred)
+{
+        int error;
+
+	/*
+	 * Privileged processes may set the sticky bit on non-directories,
+	 * as well as set the setgid bit on a file with a group that the process
+	 * is not a member of. Both of these are allowed in jail(8).
+	 */
+	if (vp->v_type != VDIR && (vap->va_mode & S_ISTXT)) {
+		if (priv_check_cred(cred, PRIV_VFS_STICKYFILE, 0))
+			return (EFTYPE);
+	}
+	/*
+	 * Check for privilege if attempting to set the
+	 * group-id bit.
+	 */
+	if ((vap->va_mode & S_ISGID) != 0) {
+		error = secpolicy_vnode_setids_setgids(cred, ovap->va_gid);
+		if (error)
+			return (error);
+	}
+	return (0);
+}
--- /dev/null
+++ sys/cddl/compat/opensolaris/machine/endian.h
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/machine/endian.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef	_OPENSOLARIS_MACHINE_ENDIAN_H_
+#define	_OPENSOLARIS_MACHINE_ENDIAN_H_
+
+#include_next <machine/endian.h>
+
+/*
+ * Solaris defines _LITTLE_ENDIAN or _BIG_ENDIAN, but never both and decides
+ * which architecture it is based on which thing is defined.
+ */
+#if _BYTE_ORDER == _LITTLE_ENDIAN
+#undef	_BIG_ENDIAN
+#else
+#undef	_LITTLE_ENDIAN
+#endif
+
+#endif	/* !_OPENSOLARIS_MACHINE_ENDIAN_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/rpc/xdr.h
@@ -0,0 +1,123 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
+/*	  All Rights Reserved  	*/
+
+/*
+ * Portions of this source code were derived from Berkeley 4.3 BSD
+ * under license from the Regents of the University of California.
+ */
+
+#ifndef	_OPENSOLARIS_RPC_XDR_H_
+#define	_OPENSOLARIS_RPC_XDR_H_
+
+#include_next <rpc/xdr.h>
+
+#ifndef _KERNEL
+#include_next <rpc/xdr.h>
+
+/*
+ * Strangely, my glibc version (2.3.6) doesn't have xdr_control(), so
+ * we have to hack it in here (source taken from OpenSolaris).
+ * By the way, it is assumed the xdrmem implementation is used.
+ */
+
+#undef xdr_control
+#define xdr_control(a,b,c) xdrmem_control(a,b,c)
+
+/*
+ * These are XDR control operators
+ */
+
+#define	XDR_GET_BYTES_AVAIL 1
+
+struct xdr_bytesrec {
+	bool_t xc_is_last_record;
+	size_t xc_num_avail;
+};
+
+typedef struct xdr_bytesrec xdr_bytesrec;
+
+/*
+ * These are the request arguments to XDR_CONTROL.
+ *
+ * XDR_PEEK - returns the contents of the next XDR unit on the XDR stream.
+ * XDR_SKIPBYTES - skips the next N bytes in the XDR stream.
+ * XDR_RDMAGET - for xdr implementation over RDMA, gets private flags from
+ *		 the XDR stream being moved over RDMA
+ * XDR_RDMANOCHUNK - for xdr implementaion over RDMA, sets private flags in
+ *                   the XDR stream moving over RDMA.
+ */
+#define XDR_PEEK      2
+#define XDR_SKIPBYTES 3
+#define XDR_RDMAGET   4
+#define XDR_RDMASET   5
+
+/* FIXME: probably doesn't work */
+static __inline bool_t
+xdrmem_control(XDR *xdrs, int request, void *info)
+{
+	xdr_bytesrec *xptr;
+	int32_t *int32p;
+	int len;
+
+	switch (request) {
+
+	case XDR_GET_BYTES_AVAIL:
+		xptr = (xdr_bytesrec *)info;
+		xptr->xc_is_last_record = TRUE;
+		xptr->xc_num_avail = xdrs->x_handy;
+		return (TRUE);
+
+	case XDR_PEEK:
+		/*
+		 * Return the next 4 byte unit in the XDR stream.
+		 */
+		if (xdrs->x_handy < sizeof (int32_t))
+			return (FALSE);
+		int32p = (int32_t *)info;
+		*int32p = (int32_t)ntohl((uint32_t)
+		    (*((int32_t *)(xdrs->x_private))));
+		return (TRUE);
+
+	case XDR_SKIPBYTES:
+		/*
+		 * Skip the next N bytes in the XDR stream.
+		 */
+		int32p = (int32_t *)info;
+		len = RNDUP((int)(*int32p));
+		if ((xdrs->x_handy -= len) < 0)
+			return (FALSE);
+		xdrs->x_private += len;
+		return (TRUE);
+
+	}
+	return (FALSE);
+}
+#endif	/* !_KERNEL */
+
+#endif	/* !_OPENSOLARIS_RPC_XDR_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/vfs.h
@@ -0,0 +1,116 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/vfs.h,v 1.2 2007/06/04 11:31:45 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_VFS_H_
+#define	_OPENSOLARIS_SYS_VFS_H_
+
+#include <sys/param.h>
+
+#ifdef _KERNEL
+
+#include <sys/mount.h>
+#include <sys/vnode.h>
+
+#define	rootdir	rootvnode
+
+typedef	struct mount	vfs_t;
+
+#define	vfs_flag	mnt_flag
+#define	vfs_data	mnt_data
+#define	vfs_count	mnt_ref
+#define	vfs_fsid	mnt_stat.f_fsid
+#define	vfs_bsize	mnt_stat.f_bsize
+
+#define	v_flag		v_vflag
+#define	v_vfsp		v_mount
+
+#define	VFS_RDONLY	MNT_RDONLY
+#define	VFS_NOSETUID	MNT_NOSUID
+#define	VFS_NOEXEC	MNT_NOEXEC
+
+#define	VFS_HOLD(vfsp)	do {						\
+	MNT_ILOCK(vfsp);						\
+	MNT_REF(vfsp);							\
+	MNT_IUNLOCK(vfsp);						\
+} while (0)
+#define	VFS_RELE(vfsp)	do {						\
+	MNT_ILOCK(vfsp);						\
+	MNT_REL(vfsp);							\
+	MNT_IUNLOCK(vfsp);						\
+} while (0)
+
+#define	VROOT		VV_ROOT
+
+/*
+ * Structure defining a mount option for a filesystem.
+ * option names are found in mntent.h
+ */
+typedef struct mntopt {
+	char	*mo_name;	/* option name */
+	char	**mo_cancel;	/* list of options cancelled by this one */
+	char	*mo_arg;	/* argument string for this option */
+	int	mo_flags;	/* flags for this mount option */
+	void	*mo_data;	/* filesystem specific data */
+} mntopt_t;
+
+/*
+ * Flags that apply to mount options
+ */
+
+#define	MO_SET		0x01		/* option is set */
+#define	MO_NODISPLAY	0x02		/* option not listed in mnttab */
+#define	MO_HASVALUE	0x04		/* option takes a value */
+#define	MO_IGNORE	0x08		/* option ignored by parser */
+#define	MO_DEFAULT	MO_SET		/* option is on by default */
+#define	MO_TAG		0x10		/* flags a tag set by user program */
+#define	MO_EMPTY	0x20		/* empty space in option table */
+
+#define	VFS_NOFORCEOPT	0x01		/* honor MO_IGNORE (don't set option) */
+#define	VFS_DISPLAY	0x02		/* Turn off MO_NODISPLAY bit for opt */
+#define	VFS_NODISPLAY	0x04		/* Turn on MO_NODISPLAY bit for opt */
+#define	VFS_CREATEOPT	0x08		/* Create the opt if it's not there */
+
+/*
+ * Structure holding mount option strings for the mounted file system.
+ */
+typedef struct mntopts {
+	uint_t		mo_count;		/* number of entries in table */
+	mntopt_t	*mo_list;		/* list of mount options */
+} mntopts_t;
+
+void vfs_setmntopt(vfs_t *vfsp, const char *name, const char *arg,
+    int flags __unused);
+void vfs_clearmntopt(vfs_t *vfsp, const char *name);
+int vfs_optionisset(const vfs_t *vfsp, const char *opt, char **argp);
+int traverse(vnode_t **cvpp, int lktype);
+int domount(kthread_t *td, vnode_t *vp, const char *fstype, char *fspath,
+    char *fspec, int fsflags);
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_VFS_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/rwlock.h
@@ -0,0 +1,88 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/rwlock.h,v 1.3 2007/05/26 21:37:14 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_RWLOCK_H_
+#define	_OPENSOLARIS_SYS_RWLOCK_H_
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
+#include <sys/sx.h>
+
+#ifdef _KERNEL
+
+typedef enum {
+	RW_DRIVER = 2,		/* driver (DDI) rwlock */
+	RW_DEFAULT = 4		/* kernel default rwlock */
+} krw_type_t;
+
+typedef enum {
+	RW_WRITER,
+	RW_READER
+} krw_t;
+
+typedef	struct sx	krwlock_t;
+
+#ifndef DEBUG
+#define	RW_FLAGS	(SX_DUPOK | SX_NOWITNESS)
+#else
+#define	RW_FLAGS	(SX_DUPOK)
+#endif
+
+#define	RW_READ_HELD(x)		(rw_read_held((x)))
+#define	RW_WRITE_HELD(x)	(rw_write_held((x)))
+#define	RW_LOCK_HELD(x)		(rw_lock_held((x)))
+#define	RW_ISWRITER(x)		(rw_iswriter(x))
+
+#define	rw_init(lock, desc, type, arg)	do {				\
+	KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) !=		\
+	    LO_EXPECTED, ("lock %s already initialized", #lock));	\
+	bzero((lock), sizeof(struct sx));				\
+	sx_init_flags((lock), "zfs:" #lock, RW_FLAGS);			\
+} while (0)
+#define	rw_destroy(lock)	sx_destroy(lock)
+#define	rw_enter(lock, how)	do {					\
+	if ((how) == RW_READER)						\
+		sx_slock(lock);						\
+	else /* if ((how) == RW_WRITER) */				\
+		sx_xlock(lock);						\
+} while (0)
+#define	rw_tryenter(lock, how)	((how) == RW_READER ? sx_try_slock(lock) : sx_try_xlock(lock))
+#define	rw_exit(lock)		sx_unlock(lock)
+#define	rw_downgrade(lock)	sx_downgrade(lock)
+#define	rw_tryupgrade(lock)	sx_try_upgrade(lock)
+#define	rw_read_held(lock)	((lock)->sx_lock != SX_LOCK_UNLOCKED && ((lock)->sx_lock & SX_LOCK_SHARED))
+#define	rw_write_held(lock)	sx_xlocked(lock)
+#define	rw_lock_held(lock)	(rw_read_held(lock) || rw_write_held(lock))
+#define	rw_iswriter(lock)	sx_xlocked(lock)
+/* TODO: Change to sx_xholder() once it is moved from kern_sx.c to sx.h. */
+#define	rw_owner(lock)		((lock)->sx_lock & SX_LOCK_SHARED ? NULL : (struct thread *)SX_OWNER((lock)->sx_lock))
+
+#endif	/* defined(_KERNEL) */
+
+#endif	/* _OPENSOLARIS_SYS_RWLOCK_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/sunddi.h
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/sunddi.h,v 1.1 2007/04/23 00:52:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_SUNDDI_H_
+#define	_OPENSOLARIS_SYS_SUNDDI_H_
+
+#define	ddi_copyin(from, to, size, flag)	(bcopy((from), (to), (size)), 0)
+#define	ddi_copyout(from, to, size, flag)	(bcopy((from), (to), (size)), 0)
+int ddi_strtoul(const char *str, char **nptr, int base, unsigned long *result);
+
+#endif	/* _OPENSOLARIS_SYS_SUNDDI_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/proc.h
@@ -0,0 +1,89 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/proc.h,v 1.2 2007/08/16 20:33:20 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_PROC_H_
+#define	_OPENSOLARIS_SYS_PROC_H_
+
+#include <sys/param.h>
+#include <sys/kthread.h>
+#include_next <sys/proc.h>
+#include <sys/stdint.h>
+#include <sys/smp.h>
+#include <sys/debug.h>
+
+#ifdef _KERNEL
+
+#define	CPU		curcpu
+#define	minclsyspri	0
+#define	maxclsyspri	0
+#define	max_ncpus	mp_ncpus
+#define	boot_max_ncpus	mp_ncpus
+
+extern int hz;	/* system clock's frequency */
+
+#define	TS_RUN	0
+
+#define	p0	proc0
+
+typedef	short		pri_t;
+typedef	struct thread	_kthread;
+typedef	struct thread	kthread_t;
+typedef struct thread	*kthread_id_t;
+typedef struct proc	proc_t;
+
+#if (KSTACK_PAGES * PAGE_SIZE) < 16384
+#define	ZFS_KSTACK_PAGES	(16384 / PAGE_SIZE)
+#else
+#define	ZFS_KSTACK_PAGES	0
+#endif
+
+static __inline kthread_t *
+thread_create(caddr_t stk, size_t stksize, void (*proc)(void *), void *arg,
+    size_t len, proc_t *pp, int state, pri_t pri)
+{
+	proc_t *p;
+	int error;
+
+	/*
+	 * Be sure there are no surprises.
+	 */
+	ASSERT(stk == NULL);
+	ASSERT(stksize == 0);
+	ASSERT(len == 0);
+	ASSERT(state == TS_RUN);
+
+	error = kthread_create(proc, arg, &p, 0, ZFS_KSTACK_PAGES,
+	    "solthread %p", proc);
+	return (error == 0 ? FIRST_THREAD_IN_PROC(p) : NULL);
+}
+
+#define	thread_exit()	kthread_exit(0)
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_PROC_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/policy.h
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ $ $FreeBSD: src/sys/compat/opensolaris/sys/policy.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_POLICY_H_
+#define	_OPENSOLARIS_SYS_POLICY_H_
+
+#include <sys/param.h>
+
+#ifdef _KERNEL
+
+struct mount;
+struct ucred;
+struct vattr;
+struct vnode;
+
+int	secpolicy_zfs(struct ucred  *cred);
+int	secpolicy_sys_config(struct ucred  *cred, int checkonly);
+int	secpolicy_zinject(struct ucred  *cred);
+int	secpolicy_fs_unmount(struct ucred  *cred, struct mount *vfsp);
+int	secpolicy_basic_link(struct ucred  *cred);
+int	secpolicy_vnode_stky_modify(struct ucred *cred);
+int	secpolicy_vnode_remove(struct ucred *cred);
+int	secpolicy_vnode_access(struct ucred *cred, struct vnode *vp,
+	    uint64_t owner, int mode);
+int	secpolicy_vnode_setdac(struct ucred *cred, uid_t owner);
+int	secpolicy_vnode_setattr(struct ucred *cred, struct vnode *vp,
+	    struct vattr *vap, const struct vattr *ovap, int flags,
+	    int unlocked_access(void *, int, struct ucred *), void *node);
+int	secpolicy_vnode_create_gid(struct ucred *cred);
+int	secpolicy_vnode_setids_setgids(struct ucred *cred, gid_t gid);
+int	secpolicy_vnode_setid_retain(struct ucred *cred, boolean_t issuidroot);
+void	secpolicy_setid_clear(struct vattr *vap, struct ucred *cred);
+int	secpolicy_setid_setsticky_clear(struct vnode *vp, struct vattr *vap,
+	    const struct vattr *ovap, struct ucred *cred);
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_POLICY_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/dirent.h
@@ -0,0 +1,44 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/dirent.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_DIRENT_H_
+#define	_OPENSOLARIS_SYS_DIRENT_H_
+
+#include_next <sys/dirent.h>
+
+typedef	struct dirent	dirent64_t;
+#define	dirent64	dirent
+#define	ino64_t		ino_t
+
+#define	d_ino	d_fileno
+
+#define	DIRENT64_RECLEN(len)	((sizeof(struct dirent) -		\
+				 sizeof(((struct dirent *)NULL)->d_name) + \
+				 (len) + 1 + 3) & ~3)
+
+#endif	/* !_OPENSOLARIS_SYS_DIRENT_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/kmem.h
@@ -0,0 +1,77 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/kmem.h,v 1.2 2007/04/10 02:35:56 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_KMEM_H_
+#define	_OPENSOLARIS_SYS_KMEM_H_
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/malloc.h>
+
+#include <vm/uma.h>
+#include <vm/vm.h>
+#include <vm/vm_extern.h>
+
+#define	KM_SLEEP		M_WAITOK
+#define	KM_NOSLEEP		M_NOWAIT
+#define	KMC_NODEBUG		0
+
+typedef	void	vmem_t;
+
+typedef struct kmem_cache {
+	char		kc_name[32];
+#ifdef _KERNEL
+	uma_zone_t	kc_zone;
+#else
+	size_t		size;
+#endif
+	int		(*kc_constructor)(void *, void *, int);
+	void		(*kc_destructor)(void *, void *);
+	void		*kc_private;
+} kmem_cache_t;
+
+void *zfs_kmem_alloc(size_t size, int kmflags);
+void zfs_kmem_free(void *buf, size_t size);
+u_long kmem_size(void);
+u_long kmem_used(void);
+kmem_cache_t *kmem_cache_create(char *name, size_t bufsize, size_t align,
+    int (*constructor)(void *, void *, int), void (*destructor)(void *, void *),
+    void (*reclaim)(void *) __unused, void *private, vmem_t *vmp, int cflags);
+void kmem_cache_destroy(kmem_cache_t *cache);
+void *kmem_cache_alloc(kmem_cache_t *cache, int flags);
+void kmem_cache_free(kmem_cache_t *cache, void *buf);
+void kmem_cache_reap_now(kmem_cache_t *cache);
+void kmem_reap(void);
+int kmem_debugging(void);
+void *calloc(size_t n, size_t s);
+
+#define	kmem_alloc(size, kmflags)	zfs_kmem_alloc((size), (kmflags))
+#define	kmem_zalloc(size, kmflags)	zfs_kmem_alloc((size), (kmflags) | M_ZERO)
+#define	kmem_free(buf, size)		zfs_kmem_free((buf), (size))
+
+#endif	/* _OPENSOLARIS_SYS_KMEM_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/kcondvar.h
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/kcondvar.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_CONDVAR_H_
+#define	_OPENSOLARIS_SYS_CONDVAR_H_
+
+#include <sys/param.h>
+#include <sys/proc.h>
+
+#ifdef _KERNEL
+
+#include <sys/mutex.h>
+#include <sys/condvar.h>
+
+typedef struct cv	kcondvar_t;
+
+typedef enum {
+	CV_DEFAULT,
+	CV_DRIVER
+} kcv_type_t;
+
+#define	zfs_cv_init(cv, name, type, arg)	do {			\
+	ASSERT((type) == CV_DEFAULT);					\
+	cv_init((cv), "zfs:" #cv);					\
+} while (0)
+#define	cv_init(cv, name, type, arg)	zfs_cv_init((cv), (name), (type), (arg))
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_CONDVAR_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/zone.h
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/zone.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_ZONE_H_
+#define	_OPENSOLARIS_SYS_ZONE_H_
+
+#ifdef _KERNEL
+
+#include <sys/jail.h>
+
+/*
+ * Macros to help with zone visibility restrictions.
+ */
+
+/*
+ * Is process in the global zone?
+ */
+#define	INGLOBALZONE(p)	(!jailed((p)->p_ucred))
+
+/*
+ * Attach the given dataset to the given jail.
+ */
+extern int zone_dataset_attach(struct ucred *, const char *, int);
+
+/*
+ * Detach the given dataset to the given jail.
+ */
+extern int zone_dataset_detach(struct ucred *, const char *, int);
+
+/*
+ * Returns true if the named pool/dataset is visible in the current zone.
+ */
+extern int zone_dataset_visible(const char *, int *);
+
+#else	/* !_KERNEL */
+
+#define	GLOBAL_ZONEID	0
+
+extern int getzoneid(void);
+
+#endif	/* _KERNEL */
+
+#endif	/* !_OPENSOLARIS_SYS_ZONE_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/systm.h
@@ -0,0 +1,49 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/systm.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_SYSTM_H_
+#define	_OPENSOLARIS_SYS_SYSTM_H_
+
+#include <sys/param.h>
+#include_next <sys/systm.h>
+
+#ifdef _KERNEL
+#include <sys/string.h>
+
+#define	PAGESIZE	PAGE_SIZE
+#define	PAGEOFFSET	(PAGESIZE - 1)
+#define	PAGEMASK	(~PAGEOFFSET)
+
+#define	delay(x)	pause("soldelay", (x))
+
+#define	xcopyin(u, k, s)	copyin(u, k, s)
+#define	xcopyout(k, u, s)	copyout(k, u, s)
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_SYSTM_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/acl.h
@@ -0,0 +1,241 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _OPENSOLARIS_SYS_ACL_H_
+#define	_OPENSOLARIS_SYS_ACL_H_
+
+#include_next <sys/acl.h>
+
+#define	MAX_ACL_ENTRIES		(1024)	/* max entries of each type */
+
+typedef struct acl_entry	aclent_t;
+#define	a_type	ae_tag
+#define	a_id	ae_id
+#define	a_perm	ae_perm
+
+typedef struct ace {
+	uid_t		a_who;		/* uid or gid */
+	uint32_t	a_access_mask;	/* read,write,... */
+	uint16_t	a_flags;	/* see below */
+	uint16_t	a_type;		/* allow or deny */
+} ace_t;
+
+#if 0
+/*
+ * The following are Defined types for an aclent_t.
+ */
+#define	USER_OBJ	(0x01)		/* object owner */
+#define	USER		(0x02)		/* additional users */
+#define	GROUP_OBJ	(0x04)		/* owning group of the object */
+#define	GROUP		(0x08)		/* additional groups */
+#define	CLASS_OBJ	(0x10)		/* file group class and mask entry */
+#define	OTHER_OBJ	(0x20)		/* other entry for the object */
+#define	ACL_DEFAULT	(0x1000)	/* default flag */
+/* default object owner */
+#define	DEF_USER_OBJ	(ACL_DEFAULT | USER_OBJ)
+/* defalut additional users */
+#define	DEF_USER	(ACL_DEFAULT | USER)
+/* default owning group */
+#define	DEF_GROUP_OBJ	(ACL_DEFAULT | GROUP_OBJ)
+/* default additional groups */
+#define	DEF_GROUP	(ACL_DEFAULT | GROUP)
+/* default mask entry */
+#define	DEF_CLASS_OBJ	(ACL_DEFAULT | CLASS_OBJ)
+/* default other entry */
+#define	DEF_OTHER_OBJ	(ACL_DEFAULT | OTHER_OBJ)
+#endif
+
+/*
+ * The following are defined for ace_t.
+ */
+#define	ACE_READ_DATA		0x00000001
+#define	ACE_LIST_DIRECTORY	0x00000001
+#define	ACE_WRITE_DATA		0x00000002
+#define	ACE_ADD_FILE		0x00000002
+#define	ACE_APPEND_DATA		0x00000004
+#define	ACE_ADD_SUBDIRECTORY	0x00000004
+#define	ACE_READ_NAMED_ATTRS	0x00000008
+#define	ACE_WRITE_NAMED_ATTRS	0x00000010
+#define	ACE_EXECUTE		0x00000020
+#define	ACE_DELETE_CHILD	0x00000040
+#define	ACE_READ_ATTRIBUTES	0x00000080
+#define	ACE_WRITE_ATTRIBUTES	0x00000100
+#define	ACE_DELETE		0x00010000
+#define	ACE_READ_ACL		0x00020000
+#define	ACE_WRITE_ACL		0x00040000
+#define	ACE_WRITE_OWNER		0x00080000
+#define	ACE_SYNCHRONIZE		0x00100000
+
+#define	ACE_FILE_INHERIT_ACE		0x0001
+#define	ACE_DIRECTORY_INHERIT_ACE	0x0002
+#define	ACE_NO_PROPAGATE_INHERIT_ACE	0x0004
+#define	ACE_INHERIT_ONLY_ACE		0x0008
+#define	ACE_SUCCESSFUL_ACCESS_ACE_FLAG	0x0010
+#define	ACE_FAILED_ACCESS_ACE_FLAG	0x0020
+#define	ACE_IDENTIFIER_GROUP		0x0040
+#define	ACE_OWNER			0x1000
+#define	ACE_GROUP			0x2000
+#define	ACE_EVERYONE			0x4000
+
+#define	ACE_ACCESS_ALLOWED_ACE_TYPE	0x0000
+#define	ACE_ACCESS_DENIED_ACE_TYPE	0x0001
+#define	ACE_SYSTEM_AUDIT_ACE_TYPE	0x0002
+#define	ACE_SYSTEM_ALARM_ACE_TYPE	0x0003
+
+#define	ACE_ALL_PERMS	(ACE_READ_DATA|ACE_LIST_DIRECTORY|ACE_WRITE_DATA| \
+    ACE_ADD_FILE|ACE_APPEND_DATA|ACE_ADD_SUBDIRECTORY|ACE_READ_NAMED_ATTRS| \
+    ACE_WRITE_NAMED_ATTRS|ACE_EXECUTE|ACE_DELETE_CHILD|ACE_READ_ATTRIBUTES| \
+    ACE_WRITE_ATTRIBUTES|ACE_DELETE|ACE_READ_ACL|ACE_WRITE_ACL| \
+    ACE_WRITE_OWNER|ACE_SYNCHRONIZE)
+
+/*
+ * The following flags are supported by both NFSv4 ACLs and ace_t.
+ */
+#define	ACE_NFSV4_SUP_FLAGS (ACE_FILE_INHERIT_ACE | \
+    ACE_DIRECTORY_INHERIT_ACE | \
+    ACE_NO_PROPAGATE_INHERIT_ACE | \
+    ACE_INHERIT_ONLY_ACE | \
+    ACE_IDENTIFIER_GROUP)
+
+#define	ACE_TYPE_FLAGS	(ACE_OWNER|ACE_GROUP|ACE_EVERYONE|ACE_IDENTIFIER_GROUP)
+
+#if 0
+/* cmd args to acl(2) for aclent_t  */
+#define	GETACL			1
+#define	SETACL			2
+#define	GETACLCNT		3
+#endif
+
+/* cmd's to manipulate ace acls. */
+#define	ACE_GETACL		4
+#define	ACE_SETACL		5
+#define	ACE_GETACLCNT		6
+
+#if 0
+/* minimal acl entries from GETACLCNT */
+#define	MIN_ACL_ENTRIES		4
+
+#if !defined(_KERNEL)
+
+/* acl check errors */
+#define	GRP_ERROR		1
+#define	USER_ERROR		2
+#define	OTHER_ERROR		3
+#define	CLASS_ERROR		4
+#define	DUPLICATE_ERROR		5
+#define	MISS_ERROR		6
+#define	MEM_ERROR		7
+#define	ENTRY_ERROR		8
+
+
+/*
+ * similar to ufs_acl.h: changed to char type for user commands (tar, cpio)
+ * Attribute types
+ */
+#define	UFSD_FREE	('0')	/* Free entry */
+#define	UFSD_ACL	('1')	/* Access Control Lists */
+#define	UFSD_DFACL	('2')	/* reserved for future use */
+#define	ACE_ACL		('3')	/* ace_t style acls */
+
+/*
+ * flag to [f]acl_get()
+ * controls whether a trivial acl should be returned.
+ */
+#define	ACL_NO_TRIVIAL	0x2
+
+
+/*
+ * Flags to control acl_totext()
+ */
+
+#define	ACL_APPEND_ID	0x1 	/* append uid/gid to user/group entries */
+#define	ACL_COMPACT_FMT	0x2 	/* build ACL in ls -V format */
+#define	ACL_NORESOLVE	0x4	/* don't do name service lookups */
+
+/*
+ * Legacy aclcheck errors for aclent_t ACLs
+ */
+#define	EACL_GRP_ERROR		GRP_ERROR
+#define	EACL_USER_ERROR		USER_ERROR
+#define	EACL_OTHER_ERROR	OTHER_ERROR
+#define	EACL_CLASS_ERROR	CLASS_ERROR
+#define	EACL_DUPLICATE_ERROR	DUPLICATE_ERROR
+#define	EACL_MISS_ERROR		MISS_ERROR
+#define	EACL_MEM_ERROR		MEM_ERROR
+#define	EACL_ENTRY_ERROR	ENTRY_ERROR
+
+#define	EACL_INHERIT_ERROR	9		/* invalid inherit flags */
+#define	EACL_FLAGS_ERROR	10		/* unknown flag value */
+#define	EACL_PERM_MASK_ERROR	11		/* unknown permission */
+#define	EACL_COUNT_ERROR	12		/* invalid acl count */
+
+#define	EACL_INVALID_SLOT	13		/* invalid acl slot */
+#define	EACL_NO_ACL_ENTRY	14		/* Entry doesn't exist */
+#define	EACL_DIFF_TYPE		15		/* acls aren't same type */
+
+#define	EACL_INVALID_USER_GROUP	16		/* need user/group name */
+#define	EACL_INVALID_STR	17		/* invalid acl string */
+#define	EACL_FIELD_NOT_BLANK	18		/* can't have blank field */
+#define	EACL_INVALID_ACCESS_TYPE 19		/* invalid access type */
+#define	EACL_UNKNOWN_DATA	20		/* Unrecognized data in ACL */
+#define	EACL_MISSING_FIELDS	21		/* missing fields in acl */
+
+#define	EACL_INHERIT_NOTDIR	22		/* Need dir for inheritance */
+
+extern int aclcheck(aclent_t *, int, int *);
+extern int acltomode(aclent_t *, int, mode_t *);
+extern int aclfrommode(aclent_t *, int, mode_t *);
+extern int aclsort(int, int, aclent_t *);
+extern char *acltotext(aclent_t *, int);
+extern aclent_t *aclfromtext(char *, int *);
+extern void acl_free(acl_t *);
+extern int acl_get(const char *, int, acl_t **);
+extern int facl_get(int, int, acl_t **);
+extern int acl_set(const char *, acl_t *acl);
+extern int facl_set(int, acl_t *acl);
+extern int acl_strip(const char *, uid_t, gid_t, mode_t);
+extern int acl_trivial(const char *);
+extern char *acl_totext(acl_t *, int);
+extern int acl_fromtext(const char *, acl_t **);
+extern int acl_check(acl_t *, int);
+
+#else	/* !defined(_KERNEL) */
+
+extern void ksort(caddr_t, int, int, int (*)(void *, void *));
+extern int cmp2acls(void *, void *);
+
+#endif	/* !defined(_KERNEL) */
+
+#if defined(__STDC__)
+extern int acl(const char *path, int cmd, int cnt, void *buf);
+extern int facl(int fd, int cmd, int cnt, void *buf);
+#else	/* !__STDC__ */
+extern int acl();
+extern int facl();
+#endif	/* defined(__STDC__) */
+
+#endif
+
+#endif /* _OPENSOLARIS_SYS_ACL_H */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/lock.h
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/lock.h,v 1.1 2007/04/09 01:05:31 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_LOCK_H_
+#define	_OPENSOLARIS_SYS_LOCK_H_
+
+#include_next <sys/lock.h>
+
+#ifdef _KERNEL
+
+#define	LO_ALLMASK	(LO_INITIALIZED | LO_WITNESS | LO_QUIET |	\
+			 LO_RECURSABLE | LO_SLEEPABLE | LO_UPGRADABLE |	\
+			 LO_DUPOK | LO_ENROLLPEND | LO_CLASSMASK |	\
+			 LO_NOPROFILE)
+#define	LO_EXPECTED	(LO_INITIALIZED | LO_WITNESS | LO_RECURSABLE |	\
+			 LO_SLEEPABLE | LO_UPGRADABLE | LO_DUPOK |	\
+			 /* sx lock class */(2 << LO_CLASSSHIFT))
+
+#endif	/* defined(_KERNEL) */
+
+#endif	/* _OPENSOLARIS_SYS_LOCK_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/kobj.h
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/kobj.h,v 1.2 2007/04/08 23:57:08 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_KOBJ_H_
+#define	_OPENSOLARIS_SYS_KOBJ_H_
+
+#include <sys/types.h>
+#include <sys/kmem.h>
+#include_next <sys/kobj.h>
+#ifdef AT_UID
+#undef AT_UID
+#endif
+#ifdef AT_GID
+#undef AT_GID
+#endif
+#include <sys/vnode.h>
+
+#define	KM_NOWAIT	0x01
+#define	KM_TMP		0x02
+
+void kobj_free(void *address, size_t size);
+void *kobj_alloc(size_t size, int flag);
+void *kobj_zalloc(size_t size, int flag);
+
+struct _buf {
+	void *ptr;
+	int mounted;
+};
+
+struct _buf *kobj_open_file(const char *path);
+int kobj_get_filesize(struct _buf *file, uint64_t *size);
+int kobj_read_file(struct _buf *file, char *buf, unsigned size, unsigned off);
+void kobj_close_file(struct _buf *file);
+
+#endif	/* _OPENSOLARIS_SYS_KOBJ_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/vnode.h
@@ -0,0 +1,268 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/vnode.h,v 1.3 2007/05/31 11:51:49 kib Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_VNODE_H_
+#define	_OPENSOLARIS_SYS_VNODE_H_
+
+#include_next <sys/vnode.h>
+#include <sys/mount.h>
+#include <sys/cred.h>
+#include <sys/fcntl.h>
+#include <sys/namei.h>
+#include <sys/proc.h>
+#include <sys/filedesc.h>
+#include <sys/syscallsubr.h>
+
+typedef	struct vnode	vnode_t;
+typedef	struct vattr	vattr_t;
+typedef	void		caller_context_t;
+
+typedef	struct vop_vector	vnodeops_t;
+#define	vop_fid		vop_vptofh
+#define	vop_fid_args	vop_vptofh_args
+#define	a_fid		a_fhp
+
+#define	v_count	v_usecount
+
+static __inline int
+vn_is_readonly(vnode_t *vp)
+{
+	return (vp->v_mount->mnt_flag & MNT_RDONLY);
+}
+#define	vn_vfswlock(vp)		(0)
+#define	vn_vfsunlock(vp)	do { } while (0)
+#define	vn_ismntpt(vp)		((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
+#define	vn_mountedvfs(vp)	((vp)->v_mountedhere)
+#define	vn_has_cached_data(vp)	((vp)->v_object != NULL && (vp)->v_object->resident_page_count > 0)
+
+#define	VN_HOLD(v)	vref(v)
+#define	VN_RELE(v)	vrele(v)
+#define	VN_URELE(v)	vput(v)
+
+#define	VOP_REALVP(vp, vpp)	(*(vpp) = (vp), 0)
+
+#define	vnevent_remove(vp)	do { } while (0)
+#define	vnevent_rmdir(vp)	do { } while (0)
+#define	vnevent_rename_src(vp)	do { } while (0)
+#define	vnevent_rename_dest(vp)	do { } while (0)
+
+
+#define	IS_DEVVP(vp)	\
+	((vp)->v_type == VCHR || (vp)->v_type == VBLK || (vp)->v_type == VFIFO)
+
+#define	MODEMASK	ALLPERMS
+
+#define	specvp(vp, rdev, type, cr)	(VN_HOLD(vp), (vp))
+#define	MANDMODE(mode)	(0)
+#define	chklock(vp, op, offset, size, mode, ct)	(0)
+#define	cleanlocks(vp, pid, foo)	do { } while (0)
+#define	cleanshares(vp, pid)		do { } while (0)
+
+/*
+ * We will use va_spare is place of Solaris' va_mask.
+ * This field is initialized in zfs_setattr().
+ */
+#define	va_mask		va_spare
+/* TODO: va_fileid is shorter than va_nodeid !!! */
+#define	va_nodeid	va_fileid
+/* TODO: This field needs conversion! */
+#define	va_nblocks	va_bytes
+#define	va_blksize	va_blocksize
+#define	va_seq		va_gen
+
+#define	MAXOFFSET_T	OFF_MAX
+#define	EXCL		0
+
+#define	AT_TYPE		0x0001
+#define	AT_MODE		0x0002
+#define	AT_UID		0x0004
+#define	AT_GID		0x0008
+#define	AT_FSID		0x0010
+#define	AT_NODEID	0x0020
+#define	AT_NLINK	0x0040
+#define	AT_SIZE		0x0080
+#define	AT_ATIME	0x0100
+#define	AT_MTIME	0x0200
+#define	AT_CTIME	0x0400
+#define	AT_RDEV		0x0800
+#define	AT_BLKSIZE	0x1000
+#define	AT_NBLOCKS	0x2000
+#define	AT_SEQ		0x4000
+#define	AT_NOSET	(AT_NLINK|AT_RDEV|AT_FSID|AT_NODEID|AT_TYPE|\
+			 AT_BLKSIZE|AT_NBLOCKS|AT_SEQ)
+
+#define	ACCESSED		(AT_ATIME)
+#define	STATE_CHANGED		(AT_CTIME)
+#define	CONTENT_MODIFIED	(AT_MTIME | AT_CTIME)
+
+static __inline void
+vattr_init_mask(vattr_t *vap)
+{
+
+	vap->va_mask = 0;
+
+	if (vap->va_type != VNON)
+		vap->va_mask |= AT_TYPE;
+	if (vap->va_uid != (uid_t)VNOVAL)
+		vap->va_mask |= AT_UID;
+	if (vap->va_gid != (gid_t)VNOVAL)
+		vap->va_mask |= AT_GID;
+	if (vap->va_size != (u_quad_t)VNOVAL)
+		vap->va_mask |= AT_SIZE;
+	if (vap->va_atime.tv_sec != VNOVAL)
+		vap->va_mask |= AT_ATIME;
+	if (vap->va_mtime.tv_sec != VNOVAL)
+		vap->va_mask |= AT_MTIME;
+	if (vap->va_mode != (u_short)VNOVAL)
+		vap->va_mask |= AT_MODE;
+}
+
+#define	FCREAT	O_CREAT
+#define	FTRUNC	O_TRUNC
+#define	FDSYNC	FFSYNC
+#define	FRSYNC	FFSYNC
+#define	FSYNC	FFSYNC
+#define	FOFFMAX	0x00
+
+enum create	{ CRCREAT };
+
+static __inline int
+zfs_vn_open(char *pnamep, enum uio_seg seg, int filemode, int createmode,
+    vnode_t **vpp, enum create crwhy, mode_t umask)
+{
+	struct thread *td = curthread;
+	struct nameidata nd;
+	int error;
+
+	ASSERT(seg == UIO_SYSSPACE);
+	ASSERT(filemode == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
+	ASSERT(crwhy == CRCREAT);
+	ASSERT(umask == 0);
+
+	if (td->td_proc->p_fd->fd_rdir == NULL)
+		td->td_proc->p_fd->fd_rdir = rootvnode;
+	if (td->td_proc->p_fd->fd_cdir == NULL)
+		td->td_proc->p_fd->fd_cdir = rootvnode;
+
+	NDINIT(&nd, LOOKUP, NOFOLLOW, UIO_SYSSPACE, pnamep, td);
+	error = vn_open_cred(&nd, &filemode, createmode, td->td_ucred, NULL);
+	NDFREE(&nd, NDF_ONLY_PNBUF);
+	if (error == 0) {
+		/* We just unlock so we hold a reference. */
+		VN_HOLD(nd.ni_vp);
+		VOP_UNLOCK(nd.ni_vp, 0, td);
+		*vpp = nd.ni_vp;
+	}
+	return (error);
+}
+#define	vn_open(pnamep, seg, filemode, createmode, vpp, crwhy, umask)	\
+	zfs_vn_open((pnamep), (seg), (filemode), (createmode), (vpp), (crwhy), (umask))
+
+#define	RLIM64_INFINITY	0
+static __inline int
+zfs_vn_rdwr(enum uio_rw rw, vnode_t *vp, caddr_t base, ssize_t len,
+    offset_t offset, enum uio_seg seg, int ioflag, int ulimit, cred_t *cr,
+    ssize_t *residp)
+{
+	struct thread *td = curthread;
+	int error, vfslocked, resid;
+
+	ASSERT(rw == UIO_WRITE);
+	ASSERT(ioflag == 0);
+	ASSERT(ulimit == RLIM64_INFINITY);
+
+	ioflag = IO_APPEND | IO_UNIT;
+
+	vfslocked = VFS_LOCK_GIANT(vp->v_mount);
+	VOP_LEASE(vp, td, td->td_ucred, LEASE_WRITE);
+	error = vn_rdwr(rw, vp, base, len, offset, seg, ioflag, cr, NOCRED,
+	    &resid, td);
+	VFS_UNLOCK_GIANT(vfslocked);
+	if (residp != NULL)
+		*residp = (ssize_t)resid;
+	return (error);
+}
+#define	vn_rdwr(rw, vp, base, len, offset, seg, ioflag, ulimit, cr, residp) \
+	zfs_vn_rdwr((rw), (vp), (base), (len), (offset), (seg), (ioflag), (ulimit), (cr), (residp))
+
+static __inline int
+zfs_vop_fsync(vnode_t *vp, int flag, cred_t *cr)
+{
+	struct thread *td = curthread;
+	struct mount *mp;
+	int error, vfslocked;
+
+	ASSERT(flag == FSYNC);
+
+	vfslocked = VFS_LOCK_GIANT(vp->v_mount);
+	if ((error = vn_start_write(vp, &mp, V_WAIT | PCATCH)) != 0)
+		goto drop;
+	vn_lock(vp, LK_EXCLUSIVE | LK_RETRY, td);
+	error = VOP_FSYNC(vp, MNT_WAIT, td);
+	VOP_UNLOCK(vp, 0, td);
+	vn_finished_write(mp);
+drop:
+	VFS_UNLOCK_GIANT(vfslocked);
+	return (error);
+}
+#define	VOP_FSYNC(vp, flag, cr)	zfs_vop_fsync((vp), (flag), (cr))
+
+static __inline int
+zfs_vop_close(vnode_t *vp, int flag, int count, offset_t offset, cred_t *cr)
+{
+
+	ASSERT(flag == (FWRITE | FCREAT | FTRUNC | FOFFMAX));
+	ASSERT(count == 1);
+	ASSERT(offset == 0);
+
+	return (vn_close(vp, flag, cr, curthread));
+}
+#define	VOP_CLOSE(vp, oflags, count, offset, cr)			\
+	zfs_vop_close((vp), (oflags), (count), (offset), (cr))
+
+static __inline int
+vn_rename(char *from, char *to, enum uio_seg seg)
+{
+
+	ASSERT(seg == UIO_SYSSPACE);
+
+	return (kern_rename(curthread, from, to, seg));
+}
+
+enum rm	{ RMFILE };
+static __inline int
+vn_remove(char *fnamep, enum uio_seg seg, enum rm dirflag)
+{
+
+	ASSERT(seg == UIO_SYSSPACE);
+	ASSERT(dirflag == RMFILE);
+
+	return (kern_unlink(curthread, fnamep, seg));
+}
+
+#endif	/* _OPENSOLARIS_SYS_VNODE_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/taskq.h
@@ -0,0 +1,84 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef	_SYS_TASKQ_H
+#define	_SYS_TASKQ_H
+
+#pragma ident	"@(#)taskq.h	1.5	05/06/08 SMI"
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/kcondvar.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#define	TASKQ_NAMELEN	31
+
+typedef struct taskq taskq_t;
+typedef uintptr_t taskqid_t;
+typedef void (task_func_t)(void *);
+
+/*
+ * Public flags for taskq_create(): bit range 0-15
+ */
+#define	TASKQ_PREPOPULATE	0x0001	/* Prepopulate with threads and data */
+#define	TASKQ_CPR_SAFE		0x0002	/* Use CPR safe protocol */
+#define	TASKQ_DYNAMIC		0x0004	/* Use dynamic thread scheduling */
+
+/*
+ * Flags for taskq_dispatch. TQ_SLEEP/TQ_NOSLEEP should be same as
+ * KM_SLEEP/KM_NOSLEEP.
+ */
+#define	TQ_SLEEP	0x00	/* Can block for memory */
+#define	TQ_NOSLEEP	0x01	/* cannot block for memory; may fail */
+#define	TQ_NOQUEUE	0x02	/* Do not enqueue if can't dispatch */
+#define	TQ_NOALLOC	0x04	/* cannot allocate memory; may fail */
+
+#ifdef _KERNEL
+
+extern taskq_t *system_taskq;
+
+extern taskq_t	*taskq_create(const char *, int, pri_t, int, int, uint_t);
+extern taskq_t	*taskq_create_instance(const char *, int, int, pri_t, int,
+    int, uint_t);
+extern taskqid_t taskq_dispatch(taskq_t *, task_func_t, void *, uint_t);
+extern void	nulltask(void *);
+extern void	taskq_destroy(taskq_t *);
+extern void	taskq_wait(taskq_t *);
+extern void	taskq_suspend(taskq_t *);
+extern int	taskq_suspended(taskq_t *);
+extern void	taskq_resume(taskq_t *);
+extern int	taskq_member(taskq_t *, kthread_t *);
+
+#endif	/* _KERNEL */
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _SYS_TASKQ_H */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/time.h
@@ -0,0 +1,58 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/time.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_TIME_H_
+#define	_OPENSOLARIS_SYS_TIME_H_
+
+#include_next <sys/time.h>
+
+#ifdef _KERNEL
+#define	lbolt	((gethrtime() * hz) / NANOSEC)
+#define	lbolt64	(int64_t)(lbolt)
+
+static __inline hrtime_t
+gethrtime(void) {
+
+	struct timespec ts;
+	hrtime_t nsec;
+
+#if 1
+	getnanouptime(&ts);
+#else
+	nanouptime(&ts);
+#endif
+	nsec = (hrtime_t)ts.tv_sec * NANOSEC + ts.tv_nsec;
+	return (nsec);
+}
+
+#define	gethrestime_sec()	(time_second)
+#define	gethrestime(ts)		getnanotime(ts)
+
+#endif	/* _KERNEL */
+
+#endif	/* !_OPENSOLARIS_SYS_TIME_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/string.h
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/string.h,v 1.2 2007/04/10 21:42:12 wkoszek Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_STRING_H_
+#define	_OPENSOLARIS_SYS_STRING_H_
+
+#include <sys/libkern.h>
+
+char	*strpbrk(const char *, const char *);
+void	 strident_canon(char *s, size_t n);
+
+#endif	/* _OPENSOLARIS_SYS_STRING_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/dkio.h
@@ -0,0 +1,85 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _OPENSOLARIS_SYS_DKIO_H_
+#define	_OPENSOLARIS_SYS_DKIO_H_
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+/*
+ * Disk io control commands
+ * Warning: some other ioctls with the DIOC prefix exist elsewhere.
+ * The Generic DKIOC numbers are from	0   -  50.
+ *	The Floppy Driver uses		51  - 100.
+ *	The Hard Disk (except SCSI)	101 - 106.	(these are obsolete)
+ *	The CDROM Driver		151 - 200.
+ *	The USCSI ioctl			201 - 250.
+ */
+#define	DKIOC		(0x04 << 8)
+
+/*
+ * The following ioctls are generic in nature and need to be
+ * suported as appropriate by all disk drivers
+ */
+#define	DKIOCGGEOM	(DKIOC|1)		/* Get geometry */
+#define	DKIOCINFO	(DKIOC|3)		/* Get info */
+#define	DKIOCEJECT	(DKIOC|6)		/* Generic 'eject' */
+#define	DKIOCGVTOC	(DKIOC|11)		/* Get VTOC */
+#define	DKIOCSVTOC	(DKIOC|12)		/* Set VTOC & Write to Disk */
+
+/*
+ * Disk Cache Controls.  These ioctls should be supported by
+ * all disk drivers.
+ *
+ * DKIOCFLUSHWRITECACHE when used from user-mode ignores the ioctl
+ * argument, but it should be passed as NULL to allow for future
+ * reinterpretation.  From user-mode, this ioctl request is synchronous.
+ *
+ * When invoked from within the kernel, the arg can be NULL to indicate
+ * a synchronous request or can be the address of a struct dk_callback
+ * to request an asynchronous callback when the flush request is complete.
+ * In this case, the flag to the ioctl must include FKIOCTL and the
+ * dkc_callback field of the pointed to struct must be non-null or the
+ * request is made synchronously.
+ *
+ * In the callback case: if the ioctl returns 0, a callback WILL be performed.
+ * If the ioctl returns non-zero, a callback will NOT be performed.
+ * NOTE: In some cases, the callback may be done BEFORE the ioctl call
+ * returns.  The caller's locking strategy should be prepared for this case.
+ */
+#define	DKIOCFLUSHWRITECACHE	(DKIOC|34)	/* flush cache to phys medium */
+
+struct dk_callback {
+	void (*dkc_callback)(void *dkc_cookie, int error);
+	void *dkc_cookie;
+};
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif /* _OPENSOLARIS_SYS_DKIO_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/mntent.h
@@ -0,0 +1,56 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ *
+ *	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
+ *		All Rights Reserved
+ */
+
+#ifndef	_OPENSOLARIS_SYS_MNTENT_H_
+#define	_OPENSOLARIS_SYS_MNTENT_H_
+
+#include <sys/param.h>
+#include_next <sys/mount.h>
+
+#define	MNTMAXSTR	128
+
+#define	MNTTYPE_ZFS	"zfs"		/* ZFS file system */
+
+#define	MNTOPT_RO	"ro"		/* Read only */
+#define	MNTOPT_RW	"rw"		/* Read/write */
+#define	MNTOPT_NOSUID	"nosuid"	/* Neither setuid nor devices allowed */
+#define	MNTOPT_DEVICES	"devices"	/* Device-special allowed */
+#define	MNTOPT_NODEVICES	"nodevices"	/* Device-special disallowed */
+#define	MNTOPT_SETUID	"setuid"	/* Set uid allowed */
+#define	MNTOPT_NOSETUID	"nosetuid"	/* Set uid not allowed */
+#define	MNTOPT_REMOUNT	"remount"	/* Change mount options */
+#define	MNTOPT_ATIME	"atime"		/* update atime for files */
+#define	MNTOPT_NOATIME  "noatime"	/* do not update atime for files */
+#define	MNTOPT_XATTR	"xattr"		/* enable extended attributes */
+#define	MNTOPT_NOXATTR	"noxattr"	/* disable extended attributes */
+#define	MNTOPT_EXEC	"exec"		/* enable executables */
+#define	MNTOPT_NOEXEC	"noexec"	/* disable executables */
+#define	MNTOPT_RESTRICT	"restrict"	/* restricted autofs mount */
+
+#endif	/* !_OPENSOLARIS_MNTENT_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/debug.h
@@ -0,0 +1,48 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/debug.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_DEBUG_H_
+#define	_OPENSOLARIS_SYS_DEBUG_H_
+
+#ifdef _KERNEL
+#include <sys/types.h>
+#include <sys/systm.h>
+
+#include_next <sys/debug.h>
+
+#define	assfail(a, f, l)						\
+	(panic("solaris assert: %s, file: %s, line: %d", (a), (f), (l)), 0)
+
+#define	assfail3(a, lv, op, rv, f, l)					\
+	panic("solaris assert: %s (0x%jx %s 0x%jx), file: %s, line: %d", \
+	    (a), (uintmax_t)(lv), (op), (uintmax_t)(rv), (f), (l))
+#else	/* !_KERNEL */
+#include_next <sys/debug.h>
+#endif
+
+#endif	/* _OPENSOLARIS_SYS_DEBUG_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/misc.h
@@ -0,0 +1,45 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/misc.h,v 1.2 2007/04/23 00:52:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_MISC_H_
+#define	_OPENSOLARIS_SYS_MISC_H_
+
+#define	_FIOFFS		(INT_MIN)
+#define	_FIOGDIO	(INT_MIN+1)
+#define	_FIOSDIO	(INT_MIN+2)
+
+#define	_FIO_SEEK_DATA	FIOSEEKDATA
+#define	_FIO_SEEK_HOLE	FIOSEEKHOLE
+
+struct opensolaris_utsname {
+	char *nodename;
+};
+
+extern char hw_serial[11];
+extern struct opensolaris_utsname utsname;
+#endif	/* _OPENSOLARIS_SYS_MISC_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/random.h
@@ -0,0 +1,37 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/random.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_RANDOM_H_
+#define	_OPENSOLARIS_SYS_RANDOM_H_
+
+#include_next <sys/random.h>
+
+#define	random_get_bytes(p, s)		read_random((p), (int)(s))
+#define	random_get_pseudo_bytes(p, s)	read_random((p), (int)(s))
+
+#endif	/* !_OPENSOLARIS_SYS_RANDOM_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/uio.h
@@ -0,0 +1,63 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/uio.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_UIO_H_
+#define	_OPENSOLARIS_SYS_UIO_H_
+
+#include_next <sys/uio.h>
+#include <sys/debug.h>
+
+#ifndef _KERNEL
+#define	FOF_OFFSET	1	/* Use the offset in uio argument */
+
+struct uio {
+	struct	iovec *uio_iov;
+	int	uio_iovcnt;
+	off_t	uio_offset;
+	int	uio_resid;
+	enum	uio_seg uio_segflg;
+	enum	uio_rw uio_rw;
+	void	*uio_td;
+};
+#endif
+
+typedef	struct uio	uio_t;
+typedef	struct iovec	iovec_t;
+
+#define	uio_loffset	uio_offset
+
+static __inline int
+zfs_uiomove(void *cp, size_t n, enum uio_rw dir, uio_t *uio)
+{
+
+	ASSERT(uio->uio_rw == dir);
+	return (uiomove(cp, (int)n, uio));
+}
+#define	uiomove(cp, n, dir, uio)	zfs_uiomove((cp), (n), (dir), (uio))
+
+#endif	/* !_OPENSOLARIS_SYS_UIO_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/kstat.h
@@ -0,0 +1,66 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/kstat.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_KSTAT_H_
+#define	_OPENSOLARIS_SYS_KSTAT_H_
+
+#include <sys/sysctl.h>
+
+#define	KSTAT_TYPE_NAMED	1
+
+#define	KSTAT_FLAG_VIRTUAL	0x01
+
+typedef struct kstat {
+	void	*ks_data;
+	u_int	 ks_ndata;
+#ifdef _KERNEL
+	struct sysctl_ctx_list ks_sysctl_ctx;
+	struct sysctl_oid *ks_sysctl_root;
+#endif
+} kstat_t;
+
+typedef struct kstat_named {
+#define	KSTAT_STRLEN	31
+	char	name[KSTAT_STRLEN];
+#define	KSTAT_DATA_CHAR		0
+#define	KSTAT_DATA_INT32	1
+#define	KSTAT_DATA_UINT32	2
+#define	KSTAT_DATA_INT64	3
+#define	KSTAT_DATA_UINT64	4
+	uchar_t	data_type;
+	union {
+		uint64_t	ui64;
+	} value;
+} kstat_named_t;
+
+kstat_t *kstat_create(char *module, int instance, char *name, char *class,
+    uchar_t type, ulong_t ndata, uchar_t flags);
+void kstat_install(kstat_t *ksp);
+void kstat_delete(kstat_t *ksp);
+
+#endif	/* _OPENSOLARIS_SYS_KSTAT_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/sdt.h
@@ -0,0 +1,46 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/sdt.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_SDT_H_
+#define	_OPENSOLARIS_SYS_SDT_H_
+
+#include_next <sys/sdt.h>
+
+#undef	DTRACE_PROBE
+#undef	DTRACE_PROBE1
+#undef	DTRACE_PROBE2
+#undef	DTRACE_PROBE3
+#undef	DTRACE_PROBE4
+
+#define	DTRACE_PROBE(name)
+#define	DTRACE_PROBE1(name, type1, arg1)
+#define	DTRACE_PROBE2(name, type1, arg1, type2, arg2)
+#define	DTRACE_PROBE3(name, type1, arg1, type2, arg2, type3, arg3)
+#define	DTRACE_PROBE4(name, type1, arg1, type2, arg2, type3, arg3, type4, arg4) 
+
+#endif	/* _OPENSOLARIS_SYS_SDT_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/sysmacros.h
@@ -0,0 +1,137 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
+/*	  All Rights Reserved  	*/
+
+
+/*
+ * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef _OPENSOLARIS_SYS_SYSMACROS_H_
+#define	_OPENSOLARIS_SYS_SYSMACROS_H_
+
+#include <sys/param.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+/*
+ * Macro for checking power of 2 address alignment.
+ */
+#define	IS_P2ALIGNED(v, a) ((((uintptr_t)(v)) & ((uintptr_t)(a) - 1)) == 0)
+
+/*
+ * Macro to determine if value is a power of 2
+ */
+#define	ISP2(x)		(((x) & ((x) - 1)) == 0)
+
+/*
+ * Macros for various sorts of alignment and rounding when the alignment
+ * is known to be a power of 2.
+ */
+#define	P2ALIGN(x, align)		((x) & -(align))
+#define	P2PHASE(x, align)		((x) & ((align) - 1))
+#define	P2NPHASE(x, align)		(-(x) & ((align) - 1))
+#define	P2ROUNDUP(x, align)		(-(-(x) & -(align)))
+#define	P2END(x, align)			(-(~(x) & -(align)))
+#define	P2PHASEUP(x, align, phase)	((phase) - (((phase) - (x)) & -(align)))
+#define	P2CROSS(x, y, align)		(((x) ^ (y)) > (align) - 1)
+/*
+ * Determine whether two numbers have the same high-order bit.
+ */
+#define	P2SAMEHIGHBIT(x, y)		(((x) ^ (y)) < ((x) & (y)))
+
+/*
+ * Typed version of the P2* macros.  These macros should be used to ensure
+ * that the result is correctly calculated based on the data type of (x),
+ * which is passed in as the last argument, regardless of the data
+ * type of the alignment.  For example, if (x) is of type uint64_t,
+ * and we want to round it up to a page boundary using "PAGESIZE" as
+ * the alignment, we can do either
+ *	P2ROUNDUP(x, (uint64_t)PAGESIZE)
+ * or
+ *	P2ROUNDUP_TYPED(x, PAGESIZE, uint64_t)
+ */
+#define	P2ALIGN_TYPED(x, align, type)	\
+	((type)(x) & -(type)(align))
+#define	P2PHASE_TYPED(x, align, type)	\
+	((type)(x) & ((type)(align) - 1))
+#define	P2NPHASE_TYPED(x, align, type)	\
+	(-(type)(x) & ((type)(align) - 1))
+#define	P2ROUNDUP_TYPED(x, align, type)	\
+	(-(-(type)(x) & -(type)(align)))
+#define	P2END_TYPED(x, align, type)	\
+	(-(~(type)(x) & -(type)(align)))
+#define	P2PHASEUP_TYPED(x, align, phase, type)	\
+	((type)(phase) - (((type)(phase) - (type)(x)) & -(type)(align)))
+#define	P2CROSS_TYPED(x, y, align, type)	\
+	(((type)(x) ^ (type)(y)) > (type)(align) - 1)
+#define	P2SAMEHIGHBIT_TYPED(x, y, type) \
+	(((type)(x) ^ (type)(y)) < ((type)(x) & (type)(y)))
+
+#ifdef _KERNEL
+#define	memmove(dst, src, size)	bcopy((src), (dst), (size))
+#endif
+
+/*
+ * Find highest one bit set.
+ *      Returns bit number + 1 of highest bit that is set, otherwise returns 0.
+ * High order bit is 31 (or 63 in _LP64 kernel).
+ */
+static __inline int
+highbit(ulong_t i)
+{
+	register int h = 1;
+
+	if (i == 0)
+		return (0);
+#ifdef _LP64
+	if (i & 0xffffffff00000000ul) {
+		h += 32; i >>= 32;
+	}
+#endif
+	if (i & 0xffff0000) {
+		h += 16; i >>= 16;
+	}
+	if (i & 0xff00) {
+		h += 8; i >>= 8;
+	}
+	if (i & 0xf0) {
+		h += 4; i >>= 4;
+	}
+	if (i & 0xc) {
+		h += 2; i >>= 2;
+	}
+	if (i & 0x2) {
+		h += 1;
+	}
+	return (h);
+}
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _OPENSOLARIS_SYS_SYSMACROS_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/taskq_impl.h
@@ -0,0 +1,135 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef	_SYS_TASKQ_IMPL_H
+#define	_SYS_TASKQ_IMPL_H
+
+#pragma ident	"@(#)taskq_impl.h	1.6	05/06/08 SMI"
+
+#include <sys/mutex.h>
+#include <sys/rwlock.h>
+#include <sys/condvar.h>
+#include <sys/taskq.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+typedef struct taskq_bucket taskq_bucket_t;
+
+typedef struct taskq_ent {
+	struct taskq_ent	*tqent_next;
+	struct taskq_ent	*tqent_prev;
+	task_func_t		*tqent_func;
+	void			*tqent_arg;
+	taskq_bucket_t		*tqent_bucket;
+	kthread_t		*tqent_thread;
+	kcondvar_t		tqent_cv;
+} taskq_ent_t;
+
+/*
+ * Taskq Statistics fields are not protected by any locks.
+ */
+typedef struct tqstat {
+	uint_t		tqs_hits;
+	uint_t		tqs_misses;
+	uint_t		tqs_overflow;	/* no threads to allocate   */
+	uint_t		tqs_tcreates;	/* threads created 	*/
+	uint_t		tqs_tdeaths;	/* threads died		*/
+	uint_t		tqs_maxthreads;	/* max # of alive threads */
+	uint_t		tqs_nomem;	/* # of times there were no memory */
+	uint_t		tqs_disptcreates;
+} tqstat_t;
+
+/*
+ * Per-CPU hash bucket manages taskq_bent_t structures using freelist.
+ */
+struct taskq_bucket {
+	kmutex_t	tqbucket_lock;
+	taskq_t		*tqbucket_taskq;	/* Enclosing taskq */
+	taskq_ent_t	tqbucket_freelist;
+	uint_t		tqbucket_nalloc;	/* # of allocated entries */
+	uint_t		tqbucket_nfree;		/* # of free entries */
+	kcondvar_t	tqbucket_cv;
+	ushort_t	tqbucket_flags;
+	hrtime_t	tqbucket_totaltime;
+	tqstat_t	tqbucket_stat;
+};
+
+/*
+ * Bucket flags.
+ */
+#define	TQBUCKET_CLOSE		0x01
+#define	TQBUCKET_SUSPEND	0x02
+
+/*
+ * taskq implementation flags: bit range 16-31
+ */
+#define	TASKQ_ACTIVE		0x00010000
+#define	TASKQ_SUSPENDED		0x00020000
+#define	TASKQ_NOINSTANCE	0x00040000
+
+struct taskq {
+	char		tq_name[TASKQ_NAMELEN + 1];
+	kmutex_t	tq_lock;
+	krwlock_t	tq_threadlock;
+	kcondvar_t	tq_dispatch_cv;
+	kcondvar_t	tq_wait_cv;
+	uint_t		tq_flags;
+	int		tq_active;
+	int		tq_nthreads;
+	int		tq_nalloc;
+	int		tq_minalloc;
+	int		tq_maxalloc;
+	taskq_ent_t	*tq_freelist;
+	taskq_ent_t	tq_task;
+	int		tq_maxsize;
+	pri_t		tq_pri;		/* Scheduling priority	    */
+	taskq_bucket_t	*tq_buckets;	/* Per-cpu array of buckets */
+	uint_t		tq_nbuckets;	/* # of buckets	(2^n)	    */
+	union {
+		kthread_t *_tq_thread;
+		kthread_t **_tq_threadlist;
+	}		tq_thr;
+	/*
+	 * Statistics.
+	 */
+	hrtime_t	tq_totaltime;	/* Time spent processing tasks */
+	int		tq_tasks;	/* Total # of tasks posted */
+	int		tq_executed;	/* Total # of tasks executed */
+	int		tq_maxtasks;	/* Max number of tasks in the queue */
+	int		tq_tcreates;
+	int		tq_tdeaths;
+};
+
+#define	tq_thread tq_thr._tq_thread
+#define	tq_threadlist tq_thr._tq_threadlist
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _SYS_TASKQ_IMPL_H */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/callb.h
@@ -0,0 +1,217 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+#ifndef	_SYS_CALLB_H
+#define	_SYS_CALLB_H
+
+#pragma ident	"@(#)callb.h	1.29	05/06/23 SMI"
+
+#include <sys/kcondvar.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+/*
+ * definitions of callback classes (c_class)
+ *
+ * Callbacks belong in the same class if (1) their callback routines
+ * do the same kind of processing (ideally, using the same callback function)
+ * and (2) they can/should be executed at the same time in a cpr
+ * suspend/resume operation.
+ *
+ * Note: The DAEMON class, in particular, is for stopping kernel threads
+ * and nothing else.  The CALLB_* macros below should be used to deal
+ * with kernel threads, and the callback function should be callb_generic_cpr.
+ * Another idiosyncrasy of the DAEMON class is that if a suspend operation
+ * fails, some of the callback functions may be called with the RESUME
+ * code which were never called with SUSPEND.  Not a problem currently,
+ * but see bug 4201851.
+ */
+#define	CB_CL_CPR_DAEMON	0
+#define	CB_CL_CPR_VM		1
+#define	CB_CL_CPR_CALLOUT	2
+#define	CB_CL_CPR_OBP		3
+#define	CB_CL_CPR_FB		4
+#define	CB_CL_PANIC		5
+#define	CB_CL_CPR_RPC		6
+#define	CB_CL_CPR_PROMPRINTF	7
+#define	CB_CL_UADMIN		8
+#define	CB_CL_CPR_PM		9
+#define	CB_CL_HALT		10
+#define	CB_CL_CPR_DMA		11
+#define	CB_CL_CPR_POST_USER	12
+#define	CB_CL_UADMIN_PRE_VFS    13
+#define	CB_CL_MDBOOT		CB_CL_UADMIN
+#define	CB_CL_ENTER_DEBUGGER	14
+#define	CB_CL_CPR_POST_KERNEL	15
+#define	NCBCLASS		16 /* CHANGE ME if classes are added/removed */
+
+/*
+ * CB_CL_CPR_DAEMON class specific definitions are given below:
+ */
+
+/*
+ * code for CPR callb_execute_class
+ */
+#define	CB_CODE_CPR_CHKPT	0
+#define	CB_CODE_CPR_RESUME	1
+
+typedef	void *		callb_id_t;
+/*
+ * Per kernel thread structure for CPR daemon callbacks.
+ * Must be protected by either a existing lock in the daemon or
+ * a new lock created for such a purpose.
+ */
+typedef struct callb_cpr {
+	kmutex_t	*cc_lockp;	/* lock to protect this struct */
+	char		cc_events;	/* various events for CPR */
+	callb_id_t	cc_id;		/* callb id address */
+	kcondvar_t	cc_callb_cv;	/* cv for callback waiting */
+	kcondvar_t	cc_stop_cv;	/* cv to checkpoint block */
+} callb_cpr_t;
+
+/*
+ * cc_events definitions
+ */
+#define	CALLB_CPR_START		1	/* a checkpoint request's started */
+#define	CALLB_CPR_SAFE		2	/* thread is safe for CPR */
+#define	CALLB_CPR_ALWAYS_SAFE	4	/* thread is ALWAYS safe for CPR */
+
+/*
+ * Used when checking that all kernel threads are stopped.
+ */
+#define	CALLB_MAX_RETRY		3	/* when waiting for kthread to sleep */
+#define	CALLB_THREAD_DELAY	10	/* ticks allowed to reach sleep */
+#define	CPR_KTHREAD_TIMEOUT_SEC	90	/* secs before callback times out -- */
+					/* due to pwr mgmt of disks, make -- */
+					/* big enough for worst spinup time */
+
+#ifdef  _KERNEL
+/*
+ *
+ * CALLB_CPR_INIT macro is used by kernel threads to add their entry to
+ * the callback table and perform other initialization.  It automatically
+ * adds the thread as being in the callback class CB_CL_CPR_DAEMON.
+ *
+ *	cp    - ptr to the callb_cpr_t structure for this kernel thread
+ *
+ *	lockp - pointer to mutex protecting the callb_cpr_t stuct
+ *
+ *	func  - pointer to the callback function for this kernel thread.
+ *		It has the prototype boolean_t <func>(void *arg, int code)
+ *		where: arg	- ptr to the callb_cpr_t structure
+ *		       code	- not used for this type of callback
+ *		returns: B_TRUE if successful; B_FALSE if unsuccessful.
+ *
+ *	name  - a string giving the name of the kernel thread
+ *
+ * Note: lockp is the lock to protect the callb_cpr_t (cp) structure
+ * later on.  No lock held is needed for this initialization.
+ */
+#define	CALLB_CPR_INIT(cp, lockp, func, name)	{			\
+		strlcpy(curthread->td_name, (name),			\
+		    sizeof(curthread->td_name));			\
+		strlcpy(curthread->td_proc->p_comm, (name),		\
+		    sizeof(curthread->td_proc->p_comm));		\
+		bzero((caddr_t)(cp), sizeof (callb_cpr_t));		\
+		(cp)->cc_lockp = lockp;					\
+		(cp)->cc_id = callb_add(func, (void *)(cp),		\
+			CB_CL_CPR_DAEMON, name);			\
+	}
+
+#ifndef __lock_lint
+#define	CALLB_CPR_ASSERT(cp)	ASSERT(MUTEX_HELD((cp)->cc_lockp));
+#else
+#define	CALLB_CPR_ASSERT(cp)
+#endif
+/*
+ * Some threads (like the idle threads) do not adhere to the callback
+ * protocol and are always considered safe.  Such threads must never exit.
+ * They register their presence by calling this macro during their
+ * initialization.
+ *
+ * Args:
+ *	t	- thread pointer of the client kernel thread
+ *	name	- a string giving the name of the kernel thread
+ */
+#define	CALLB_CPR_INIT_SAFE(t, name) {					\
+		(void) callb_add_thread(callb_generic_cpr_safe,		\
+		(void *) &callb_cprinfo_safe, CB_CL_CPR_DAEMON,		\
+		    name, t);						\
+	}
+/*
+ * The lock to protect cp's content must be held before
+ * calling the following two macros.
+ *
+ * Any code region between CALLB_CPR_SAFE_BEGIN and CALLB_CPR_SAFE_END
+ * is safe for checkpoint/resume.
+ */
+#define	CALLB_CPR_SAFE_BEGIN(cp) { 			\
+		CALLB_CPR_ASSERT(cp)			\
+		(cp)->cc_events |= CALLB_CPR_SAFE;	\
+		if ((cp)->cc_events & CALLB_CPR_START)	\
+			cv_signal(&(cp)->cc_callb_cv);	\
+	}
+#define	CALLB_CPR_SAFE_END(cp, lockp) {				\
+		CALLB_CPR_ASSERT(cp)				\
+		while ((cp)->cc_events & CALLB_CPR_START)	\
+			cv_wait(&(cp)->cc_stop_cv, lockp);	\
+		(cp)->cc_events &= ~CALLB_CPR_SAFE;		\
+	}
+/*
+ * cv_destroy is nop right now but may be needed in the future.
+ */
+#define	CALLB_CPR_EXIT(cp) {				\
+		CALLB_CPR_ASSERT(cp)			\
+		(cp)->cc_events |= CALLB_CPR_SAFE;	\
+		if ((cp)->cc_events & CALLB_CPR_START)	\
+			cv_signal(&(cp)->cc_callb_cv);	\
+		mutex_exit((cp)->cc_lockp);		\
+		(void) callb_delete((cp)->cc_id);	\
+		cv_destroy(&(cp)->cc_callb_cv);		\
+		cv_destroy(&(cp)->cc_stop_cv);		\
+	}
+
+extern callb_cpr_t callb_cprinfo_safe;
+extern callb_id_t callb_add(boolean_t  (*)(void *, int), void *, int, char *);
+extern callb_id_t callb_add_thread(boolean_t (*)(void *, int),
+    void *, int, char *, kthread_id_t);
+extern int	callb_delete(callb_id_t);
+extern void	callb_execute(callb_id_t, int);
+extern void	*callb_execute_class(int, int);
+extern boolean_t callb_generic_cpr(void *, int);
+extern boolean_t callb_generic_cpr_safe(void *, int);
+extern boolean_t callb_is_stopped(kthread_id_t, caddr_t *);
+extern void	callb_lock_table(void);
+extern void	callb_unlock_table(void);
+#endif
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _SYS_CALLB_H */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/byteorder.h
@@ -0,0 +1,65 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+
+/*
+ * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*	Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T	*/
+/*	  All Rights Reserved  	*/
+
+/*
+ * University Copyright- Copyright (c) 1982, 1986, 1988
+ * The Regents of the University of California
+ * All Rights Reserved
+ *
+ * University Acknowledgment- Portions of this document are derived from
+ * software developed by the University of California, Berkeley, and its
+ * contributors.
+ */
+
+#ifndef _OPENSOLARIS_SYS_BYTEORDER_H_
+#define	_OPENSOLARIS_SYS_BYTEORDER_H_
+
+/*
+ * Macros to reverse byte order
+ */
+#define	BSWAP_8(x)	((x) & 0xff)
+#define	BSWAP_16(x)	((BSWAP_8(x) << 8) | BSWAP_8((x) >> 8))
+#define	BSWAP_32(x)	((BSWAP_16(x) << 16) | BSWAP_16((x) >> 16))
+#define	BSWAP_64(x)	((BSWAP_32(x) << 32) | BSWAP_32((x) >> 32))
+
+#define	BMASK_8(x)	((x) & 0xff)
+#define	BMASK_16(x)	((x) & 0xffff)
+#define	BMASK_32(x)	((x) & 0xffffffff)
+#define	BMASK_64(x)	(x)
+
+/*
+ * Macros to convert from a specific byte order to/from native byte order
+ */
+#if _BYTE_ORDER == _BIG_ENDIAN
+#define	LE_64(x)	BSWAP_64(x)
+#else
+#define	LE_64(x)	BMASK_64(x)
+#endif
+
+#endif /* _OPENSOLARIS_SYS_BYTEORDER_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/dnlc.h
@@ -0,0 +1,40 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/dnlc.h,v 1.2 2007/05/24 13:44:45 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_DNLC_H_
+#define	_OPENSOLARIS_SYS_DNLC_H_
+
+#define	DNLC_NO_VNODE	((void *)(intptr_t)0xdeadc0de)
+
+#define	dnlc_lookup(dvp, name)	(NULL)
+#define	dnlc_update(dvp, name, vp)	do { } while (0)
+#define	dnlc_remove(dvp, name)		do { } while (0)
+#define	dnlc_purge_vfsp(vfsp, count)	(0)
+#define	dnlc_reduce_cache(percent)	do { } while (0)
+
+#endif	/* !_OPENSOLARIS_SYS_DNLC_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/varargs.h
@@ -0,0 +1,38 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/varargs.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_VARARGS_H_
+#define	_OPENSOLARIS_SYS_VARARGS_H_
+
+#ifdef	_KERNEL
+#include <machine/stdarg.h>
+#else
+#include <stdarg.h>
+#endif
+
+#endif	/* !_OPENSOLARIS_SYS_VARARGS_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/atomic.h
@@ -0,0 +1,114 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/atomic.h,v 1.1 2007/06/08 12:35:46 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_ATOMIC_H_
+#define	_OPENSOLARIS_SYS_ATOMIC_H_
+
+#include <sys/types.h>
+#include <machine/atomic.h>
+
+#ifndef __LP64__
+extern void atomic_add_64(volatile uint64_t *target, int64_t delta);
+extern void *atomic_cas_ptr(volatile void *target, void *cmp,  void *newval);
+#endif
+#ifndef __sparc64__
+extern uint64_t atomic_cas_64(volatile uint64_t *target, uint64_t cmp,
+    uint64_t newval);
+#endif
+extern uint64_t atomic_add_64_nv(volatile uint64_t *target, int64_t delta);
+extern uint8_t atomic_or_8_nv(volatile uint8_t *target, uint8_t value);
+extern void membar_producer(void);
+
+#if defined(__sparc64__) || defined(__powerpc__) || defined(__arm__)
+extern void atomic_or_8(volatile uint8_t *target, uint8_t value);
+#else
+static __inline void
+atomic_or_8(volatile uint8_t *target, uint8_t value)
+{
+	atomic_set_8(target, value);
+}
+#endif
+
+static __inline uint32_t
+atomic_add_32_nv(volatile uint32_t *target, int32_t delta)
+{
+	return (atomic_fetchadd_32(target, delta) + delta);
+}
+
+static __inline u_int
+atomic_add_int_nv(volatile u_int *target, int delta)
+{
+	return (atomic_add_32_nv(target, delta));
+}
+
+static __inline void
+atomic_dec_32(volatile uint32_t *target)
+{
+	atomic_subtract_32(target, 1);
+}
+
+static __inline uint32_t
+atomic_dec_32_nv(volatile uint32_t *target)
+{
+	return (atomic_fetchadd_32(target, -1) - 1);
+}
+
+static __inline void
+atomic_inc_32(volatile uint32_t *target)
+{
+	atomic_add_32(target, 1);
+}
+
+static __inline uint32_t
+atomic_inc_32_nv(volatile uint32_t *target)
+{
+	return (atomic_add_32_nv(target, 1));
+}
+
+static __inline void
+atomic_inc_64(volatile uint64_t *target)
+{
+	atomic_add_64(target, 1);
+}
+
+static __inline uint64_t
+atomic_inc_64_nv(volatile uint64_t *target)
+{
+	return (atomic_add_64_nv(target, 1));
+}
+
+#ifdef __LP64__
+static __inline void *
+atomic_cas_ptr(volatile void *target, void *cmp,  void *newval)
+{
+	return ((void *)atomic_cas_64((uint64_t *)target, (uint64_t)cmp,
+	    (uint64_t)newval));
+}
+#endif
+
+#endif	/* !_OPENSOLARIS_SYS_ATOMIC_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/mutex.h
@@ -0,0 +1,72 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/mutex.h,v 1.3 2007/05/26 21:37:14 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_MUTEX_H_
+#define	_OPENSOLARIS_SYS_MUTEX_H_
+
+#ifdef _KERNEL
+
+#include <sys/param.h>
+#include <sys/proc.h>
+#include <sys/lock.h>
+#include_next <sys/mutex.h>
+#include <sys/sx.h>
+
+typedef enum {
+	MUTEX_DEFAULT = 6	/* kernel default mutex */
+} kmutex_type_t;
+
+#define	MUTEX_HELD(x)		(mutex_owned(x))
+#define	MUTEX_NOT_HELD(x)	(!mutex_owned(x) || panicstr)
+
+typedef struct sx	kmutex_t;
+
+#ifndef DEBUG
+#define	MUTEX_FLAGS	(SX_DUPOK | SX_NOWITNESS)
+#else
+#define	MUTEX_FLAGS	(SX_DUPOK)
+#endif
+
+#define	mutex_init(lock, desc, type, arg)	do {			\
+	ASSERT((type) == MUTEX_DEFAULT);				\
+	KASSERT(((lock)->lock_object.lo_flags & LO_ALLMASK) !=		\
+	    LO_EXPECTED, ("lock %s already initialized", #lock));	\
+	bzero((lock), sizeof(struct sx));				\
+	sx_init_flags((lock), "zfs:" #lock, MUTEX_FLAGS);		\
+} while (0)
+#define	mutex_destroy(lock)	sx_destroy(lock)
+#define	mutex_enter(lock)	sx_xlock(lock)
+#define	mutex_tryenter(lock)	sx_try_xlock(lock)
+#define	mutex_exit(lock)	sx_xunlock(lock)
+#define	mutex_owned(lock)	sx_xlocked(lock)
+/* TODO: Change to sx_xholder() once it is moved from kern_sx.c to sx.h. */
+#define	mutex_owner(lock)	((lock)->sx_lock & SX_LOCK_SHARED ? NULL : (struct thread *)SX_OWNER((lock)->sx_lock))
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_MUTEX_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/mount.h
@@ -0,0 +1,39 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/mount.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_MOUNT_H_
+#define	_OPENSOLARIS_SYS_MOUNT_H_
+
+#include_next <sys/mount.h>
+
+#define	MS_FORCE	MNT_FORCE
+#define	MS_REMOUNT	MNT_UPDATE
+
+typedef	struct fid		fid_t;
+
+#endif	/* !_OPENSOLARIS_SYS_MOUNT_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/mnttab.h
@@ -0,0 +1,36 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/mnttab.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_MNTTAB_H_
+#define	_OPENSOLARIS_SYS_MNTTAB_H_
+
+#ifndef	_KERNEL
+#include <mnttab.h>
+#endif
+
+#endif	/* !_OPENSOLARIS_MNTTAB_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/cmn_err.h
@@ -0,0 +1,90 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/cmn_err.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_CMN_ERR_H_
+#define	_OPENSOLARIS_SYS_CMN_ERR_H_
+
+#include <sys/systm.h>
+#include <machine/stdarg.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+/* Common error handling severity levels */
+
+#define	CE_CONT		0	/* continuation		*/
+#define	CE_NOTE		1	/* notice		*/
+#define	CE_WARN		2	/* warning		*/
+#define	CE_PANIC	3	/* panic		*/
+#define	CE_IGNORE	4	/* print nothing	*/
+
+static __inline void
+vcmn_err(int ce, const char *fmt, va_list adx)
+{
+	char buf[256];
+
+	switch (ce) {
+	case CE_CONT:
+		snprintf(buf, sizeof(buf), "ZFS(cont): %s\n", fmt);
+		break;
+	case CE_NOTE:
+		snprintf(buf, sizeof(buf), "ZFS: NOTICE: %s\n", fmt);
+		break;
+	case CE_WARN:
+		snprintf(buf, sizeof(buf), "ZFS: WARNING: %s\n", fmt);
+		break;
+	case CE_PANIC:
+		snprintf(buf, sizeof(buf), "ZFS(panic): %s\n", fmt);
+		break;
+	case CE_IGNORE:
+		break;
+	default:
+		panic("unknown severity level");
+	}
+	if (ce != CE_IGNORE)
+		vprintf(buf, adx);
+	if (ce == CE_PANIC)
+		panic("ZFS");
+}
+
+static __inline void
+cmn_err(int ce, const char *fmt, ...)
+{
+	va_list adx;
+
+	va_start(adx, fmt);
+	vcmn_err(ce, fmt, adx);
+	va_end(adx);
+}
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* _OPENSOLARIS_SYS_CMN_ERR_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/types.h
@@ -0,0 +1,68 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/types.h,v 1.2 2007/04/23 00:52:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_TYPES_H_
+#define	_OPENSOLARIS_SYS_TYPES_H_
+
+/*
+ * This is a bag of dirty hacks to keep things compiling.
+ */
+
+#include <sys/stdint.h>
+#include_next <sys/types.h>
+
+#define	MAXNAMELEN	256
+
+typedef	struct timespec	timestruc_t;
+
+#ifdef _KERNEL
+
+#define	B_FALSE	0
+#define	B_TRUE	1
+
+typedef	short		index_t;
+typedef	off_t		offset_t;
+typedef	long		ptrdiff_t;	/* pointer difference */
+typedef	void		pathname_t;
+typedef	int64_t		rlim64_t;
+
+#else
+
+typedef	longlong_t	offset_t;
+typedef	u_longlong_t	u_offset_t;
+typedef	uint64_t	upad64_t;
+typedef	struct timespec	timespec_t;
+typedef	short		pri_t;
+typedef	int32_t		daddr32_t;
+typedef	int32_t		time32_t;
+typedef	u_longlong_t	diskaddr_t;
+typedef	ushort_t	o_mode_t;	/* old file attribute type */
+
+#endif	/* !_KERNEL */
+
+#endif	/* !_OPENSOLARIS_SYS_TYPES_H_ */
--- /dev/null
+++ sys/cddl/compat/opensolaris/sys/cred.h
@@ -0,0 +1,51 @@
+/*-
+ * Copyright (c) 2007 Pawel Jakub Dawidek <pjd at FreeBSD.org>
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: src/sys/compat/opensolaris/sys/cred.h,v 1.1 2007/04/06 01:09:06 pjd Exp $
+ */
+
+#ifndef _OPENSOLARIS_SYS_CRED_H_
+#define	_OPENSOLARIS_SYS_CRED_H_
+
+#include <sys/param.h>
+#include_next <sys/ucred.h>
+
+#ifdef _KERNEL
+
+typedef struct ucred cred_t;
+
+#define	CRED()		(curthread->td_ucred)
+
+/*
+ * kcred is used when you need all privileges.
+ */
+#define	kcred	(thread0.td_ucred)
+
+#define	crgetuid(cred)	((cred)->cr_uid)
+#define	crgetgid(cred)	((cred)->cr_gid)
+
+#endif	/* _KERNEL */
+
+#endif	/* _OPENSOLARIS_SYS_CRED_H_ */


More information about the Midnightbsd-cvs mailing list