4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
21 #include <sys/types.h>
22 #include <sys/param.h>
23 #include <sys/sysctl.h>
24 #include <sys/zfs_ioctl.h>
25 #include <os/freebsd/zfs/sys/zfs_ioctl_compat.h>
30 int zfs_ioctl_version = ZFS_IOCVER_UNDEF;
33 * Get zfs_ioctl_version
36 get_zfs_ioctl_version(void)
39 int ver = ZFS_IOCVER_NONE;
41 ver_size = sizeof (ver);
42 sysctlbyname("vfs.zfs.version.ioctl", &ver, &ver_size, NULL, 0);
48 zcmd_ioctl_compat(int fd, int request, zfs_cmd_t *zc, const int cflag)
56 case ZFS_CMD_COMPAT_NONE:
57 ncmd = _IOWR('Z', request, zfs_iocparm_t);
58 zp.zfs_cmd = (uint64_t)zc;
59 zp.zfs_cmd_size = sizeof (zfs_cmd_t);
60 zp.zfs_ioctl_version = ZFS_IOCVER_OZFS;
62 case ZFS_CMD_COMPAT_LEGACY:
63 newrequest = zfs_ioctl_ozfs_to_legacy(request);
64 ncmd = _IOWR('Z', newrequest, zfs_iocparm_t);
65 zc_c = malloc(sizeof (zfs_cmd_legacy_t));
66 zfs_cmd_ozfs_to_legacy(zc, zc_c);
67 zp.zfs_cmd = (uint64_t)zc_c;
68 zp.zfs_cmd_size = sizeof (zfs_cmd_legacy_t);
69 zp.zfs_ioctl_version = ZFS_IOCVER_LEGACY;
76 ret = ioctl(fd, ncmd, &zp);
83 zfs_cmd_legacy_to_ozfs(zc_c, zc);
90 * This is FreeBSD version of ioctl, because Solaris' ioctl() updates
91 * zc_nvlist_dst_size even if an error is returned, on FreeBSD if an
92 * error is returned zc_nvlist_dst_size won't be updated.
95 zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc)
98 int ret, cflag = ZFS_CMD_COMPAT_NONE;
100 if (zfs_ioctl_version == ZFS_IOCVER_UNDEF)
101 zfs_ioctl_version = get_zfs_ioctl_version();
103 switch (zfs_ioctl_version) {
104 case ZFS_IOCVER_LEGACY:
105 cflag = ZFS_CMD_COMPAT_LEGACY;
107 case ZFS_IOCVER_OZFS:
108 cflag = ZFS_CMD_COMPAT_NONE;
111 errx(1, "unrecognized zfs ioctl version %d",
115 oldsize = zc->zc_nvlist_dst_size;
116 ret = zcmd_ioctl_compat(fd, request, zc, cflag);
118 if (ret == 0 && oldsize < zc->zc_nvlist_dst_size) {