]> git.proxmox.com Git - mirror_zfs.git/blob - lib/libzutil/os/freebsd/zutil_compat.c
5b0fe85485dbde2425397e13a440e8b345f053fd
[mirror_zfs.git] / lib / libzutil / os / freebsd / zutil_compat.c
1 /*
2 * CDDL HEADER START
3 *
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.
7 *
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.
12 *
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]
18 *
19 * CDDL HEADER END
20 */
21 #include <sys/types.h>
22 #include <sys/param.h>
23 #include <sys/zfs_ioctl.h>
24 #include <os/freebsd/zfs/sys/zfs_ioctl_compat.h>
25 #include <libzutil.h>
26
27 static int
28 zcmd_ioctl_compat(int fd, int request, zfs_cmd_t *zc, const int cflag)
29 {
30 int ret;
31 void *zc_c;
32 unsigned long ncmd;
33 zfs_iocparm_t zp;
34
35 switch (cflag) {
36 case ZFS_CMD_COMPAT_NONE:
37 ncmd = _IOWR('Z', request, zfs_iocparm_t);
38 zp.zfs_cmd = (uint64_t)zc;
39 zp.zfs_cmd_size = sizeof (zfs_cmd_t);
40 zp.zfs_ioctl_version = ZFS_IOCVER_ZOF;
41 return (ioctl(fd, ncmd, &zp));
42 default:
43 abort();
44 return (EINVAL);
45 }
46
47 ret = ioctl(fd, ncmd, zc_c);
48 zfs_cmd_compat_get(zc, (caddr_t)zc_c, cflag);
49 free(zc_c);
50
51 return (ret);
52 }
53
54 /*
55 * This is FreeBSD version of ioctl, because Solaris' ioctl() updates
56 * zc_nvlist_dst_size even if an error is returned, on FreeBSD if an
57 * error is returned zc_nvlist_dst_size won't be updated.
58 */
59 int
60 zfs_ioctl_fd(int fd, unsigned long request, zfs_cmd_t *zc)
61 {
62 size_t oldsize;
63 int ret, cflag = ZFS_CMD_COMPAT_NONE;
64
65 oldsize = zc->zc_nvlist_dst_size;
66 ret = zcmd_ioctl_compat(fd, request, zc, cflag);
67
68 if (ret == 0 && oldsize < zc->zc_nvlist_dst_size) {
69 ret = -1;
70 errno = ENOMEM;
71 }
72
73 return (ret);
74 }