xref: /freebsd/sys/contrib/openzfs/include/os/freebsd/zfs/sys/zfs_ioctl_compat.h (revision dbd5678dca91abcefe8d046aa2f9b66497a95ffb)
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 https://opensource.org/licenses/CDDL-1.0.
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 /*
22  * Copyright 2014 Xin Li <delphij@FreeBSD.org>.  All rights reserved.
23  * Copyright 2013 Martin Matuska <mm@FreeBSD.org>.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_ZFS_IOCTL_COMPAT_H
28 #define	_SYS_ZFS_IOCTL_COMPAT_H
29 
30 #include <sys/cred.h>
31 #include <sys/dmu.h>
32 #include <sys/zio.h>
33 #include <sys/dsl_deleg.h>
34 #include <sys/zfs_ioctl.h>
35 
36 #ifdef _KERNEL
37 #include <sys/nvpair.h>
38 #endif  /* _KERNEL */
39 
40 /*
41  * Legacy ioctl support allows compatibility with pre-OpenZFS tools on
42  * FreeBSD.  The need for it will eventually pass (perhaps after FreeBSD
43  * 12 is well out of support), at which point this code can be removed.
44  * For now, downstream consumers may choose to disable this code by
45  * removing the following define.
46  */
47 #define	ZFS_LEGACY_SUPPORT
48 
49 #ifdef	__cplusplus
50 extern "C" {
51 #endif
52 
53 /*
54  * Backwards ioctl compatibility
55  */
56 
57 /* ioctl versions for vfs.zfs.version.ioctl */
58 #define	ZFS_IOCVER_UNDEF	-1
59 #define	ZFS_IOCVER_NONE		0
60 #define	ZFS_IOCVER_DEADMAN	1
61 #define	ZFS_IOCVER_LZC		2
62 #define	ZFS_IOCVER_ZCMD		3
63 #define	ZFS_IOCVER_EDBP		4
64 #define	ZFS_IOCVER_RESUME	5
65 #define	ZFS_IOCVER_INLANES	6
66 #define	ZFS_IOCVER_PAD		7
67 #define	ZFS_IOCVER_LEGACY	ZFS_IOCVER_PAD
68 #define	ZFS_IOCVER_OZFS		15
69 
70 /* compatibility conversion flag */
71 #define	ZFS_CMD_COMPAT_NONE	0
72 #define	ZFS_CMD_COMPAT_V15	1
73 #define	ZFS_CMD_COMPAT_V28	2
74 #define	ZFS_CMD_COMPAT_DEADMAN	3
75 #define	ZFS_CMD_COMPAT_LZC	4
76 #define	ZFS_CMD_COMPAT_ZCMD	5
77 #define	ZFS_CMD_COMPAT_EDBP	6
78 #define	ZFS_CMD_COMPAT_RESUME	7
79 #define	ZFS_CMD_COMPAT_INLANES	8
80 #define	ZFS_CMD_COMPAT_LEGACY	9
81 
82 #define	ZFS_IOC_COMPAT_PASS	254
83 #define	ZFS_IOC_COMPAT_FAIL	255
84 
85 #define	ZFS_IOCREQ(ioreq)	((ioreq) & 0xff)
86 
87 typedef struct zfs_iocparm {
88 	uint32_t	zfs_ioctl_version;
89 	uint64_t	zfs_cmd;
90 	uint64_t	zfs_cmd_size;
91 } zfs_iocparm_t;
92 
93 
94 #ifdef ZFS_LEGACY_SUPPORT
95 #define	LEGACY_MAXPATHLEN 1024
96 #define	LEGACY_MAXNAMELEN 256
97 
98 /*
99  * Note: this struct must have the same layout in 32-bit and 64-bit, so
100  * that 32-bit processes (like /sbin/zfs) can pass it to the 64-bit
101  * kernel.  Therefore, we add padding to it so that no "hidden" padding
102  * is automatically added on 64-bit (but not on 32-bit).
103  */
104 typedef struct zfs_cmd_legacy {
105 	char		zc_name[LEGACY_MAXPATHLEN];	/* pool|dataset name */
106 	uint64_t	zc_nvlist_src;		/* really (char *) */
107 	uint64_t	zc_nvlist_src_size;
108 	uint64_t	zc_nvlist_dst;		/* really (char *) */
109 	uint64_t	zc_nvlist_dst_size;
110 	boolean_t	zc_nvlist_dst_filled;	/* put an nvlist in dst? */
111 	int		zc_pad2;
112 
113 	/*
114 	 * The following members are for legacy ioctls which haven't been
115 	 * converted to the new method.
116 	 */
117 	uint64_t	zc_history;		/* really (char *) */
118 	char		zc_value[LEGACY_MAXPATHLEN * 2];
119 	char		zc_string[LEGACY_MAXNAMELEN];
120 	uint64_t	zc_guid;
121 	uint64_t	zc_nvlist_conf;		/* really (char *) */
122 	uint64_t	zc_nvlist_conf_size;
123 	uint64_t	zc_cookie;
124 	uint64_t	zc_objset_type;
125 	uint64_t	zc_perm_action;
126 	uint64_t	zc_history_len;
127 	uint64_t	zc_history_offset;
128 	uint64_t	zc_obj;
129 	uint64_t	zc_iflags;		/* internal to zfs(7fs) */
130 	zfs_share_t	zc_share;
131 	uint64_t	zc_jailid;
132 	dmu_objset_stats_t zc_objset_stats;
133 	dmu_replay_record_t zc_begin_record;
134 	zinject_record_t zc_inject_record;
135 	uint32_t	zc_defer_destroy;
136 	uint32_t	zc_flags;
137 	uint64_t	zc_action_handle;
138 	int		zc_cleanup_fd;
139 	uint8_t		zc_simple;
140 	uint8_t		zc_pad3[3];
141 	boolean_t	zc_resumable;
142 	uint32_t	zc_pad4;
143 	uint64_t	zc_sendobj;
144 	uint64_t	zc_fromobj;
145 	uint64_t	zc_createtxg;
146 	zfs_stat_t	zc_stat;
147 } zfs_cmd_legacy_t;
148 #endif
149 
150 
151 #ifdef _KERNEL
152 int zfs_ioctl_compat_pre(zfs_cmd_t *, int *, const int);
153 void zfs_ioctl_compat_post(zfs_cmd_t *, const int, const int);
154 nvlist_t *zfs_ioctl_compat_innvl(zfs_cmd_t *, nvlist_t *, const int,
155     const int);
156 nvlist_t *zfs_ioctl_compat_outnvl(zfs_cmd_t *, nvlist_t *, const int,
157     const int);
158 #endif	/* _KERNEL */
159 #ifdef ZFS_LEGACY_SUPPORT
160 int zfs_ioctl_legacy_to_ozfs(int request);
161 int zfs_ioctl_ozfs_to_legacy(int request);
162 void zfs_cmd_legacy_to_ozfs(zfs_cmd_legacy_t *src, zfs_cmd_t *dst);
163 void zfs_cmd_ozfs_to_legacy(zfs_cmd_t *src, zfs_cmd_legacy_t *dst);
164 #endif
165 
166 void zfs_cmd_compat_put(zfs_cmd_t *, caddr_t, const int, const int);
167 
168 #ifdef	__cplusplus
169 }
170 #endif
171 
172 #endif	/* _SYS_ZFS_IOCTL_COMPAT_H */
173