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