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 /*
  22  * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
  23  * Copyright (c) 2012 by Delphix. All rights reserved.
  24  * Copyright 2012, Nexenta Systems Inc. All rights reserved.
  25  */
  26 
  27 #ifndef _SYS_ZFS_IOCTL_H
  28 #define _SYS_ZFS_IOCTL_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/spa.h>
  35 #include <sys/zfs_stat.h>
  36 
  37 #ifdef _KERNEL
  38 #include <sys/nvpair.h>
  39 #endif  /* _KERNEL */
  40 
  41 #ifdef  __cplusplus
  42 extern "C" {
  43 #endif
  44 
  45 /*
  46  * The structures in this file are passed between userland and the
  47  * kernel.  Userland may be running a 32-bit process, while the kernel
  48  * is 64-bit.  Therefore, these structures need to compile the same in
  49  * 32-bit and 64-bit.  This means not using type "long", and adding
  50  * explicit padding so that the 32-bit structure will not be packed more
  51  * tightly than the 64-bit structure (which requires 64-bit alignment).
  52  */
  53 
  54 /*
  55  * Property values for snapdir
  56  */
  57 #define ZFS_SNAPDIR_HIDDEN              0
  58 #define ZFS_SNAPDIR_VISIBLE             1
  59 
  60 /*
  61  * Field manipulation macros for the drr_versioninfo field of the
  62  * send stream header.
  63  */
  64 
  65 /*
  66  * Header types for zfs send streams.
  67  */
  68 typedef enum drr_headertype {
  69         DMU_SUBSTREAM = 0x1,
  70         DMU_COMPOUNDSTREAM = 0x2
  71 } drr_headertype_t;
  72 
  73 #define DMU_GET_STREAM_HDRTYPE(vi)      BF64_GET((vi), 0, 2)
  74 #define DMU_SET_STREAM_HDRTYPE(vi, x)   BF64_SET((vi), 0, 2, x)
  75 
  76 #define DMU_GET_FEATUREFLAGS(vi)        BF64_GET((vi), 2, 30)
  77 #define DMU_SET_FEATUREFLAGS(vi, x)     BF64_SET((vi), 2, 30, x)
  78 
  79 /*
  80  * Feature flags for zfs send streams (flags in drr_versioninfo)
  81  */
  82 
  83 #define DMU_BACKUP_FEATURE_DEDUP        (0x1)
  84 #define DMU_BACKUP_FEATURE_DEDUPPROPS   (0x2)
  85 #define DMU_BACKUP_FEATURE_SA_SPILL     (0x4)
  86 
  87 /*
  88  * Mask of all supported backup features
  89  */
  90 #define DMU_BACKUP_FEATURE_MASK (DMU_BACKUP_FEATURE_DEDUP | \
  91                 DMU_BACKUP_FEATURE_DEDUPPROPS | DMU_BACKUP_FEATURE_SA_SPILL)
  92 
  93 /* Are all features in the given flag word currently supported? */
  94 #define DMU_STREAM_SUPPORTED(x) (!((x) & ~DMU_BACKUP_FEATURE_MASK))
  95 
  96 /*
  97  * The drr_versioninfo field of the dmu_replay_record has the
  98  * following layout:
  99  *
 100  *      64      56      48      40      32      24      16      8       0
 101  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 102  *      |               reserved        |        feature-flags      |C|S|
 103  *      +-------+-------+-------+-------+-------+-------+-------+-------+
 104  *
 105  * The low order two bits indicate the header type: SUBSTREAM (0x1)
 106  * or COMPOUNDSTREAM (0x2).  Using two bits for this is historical:
 107  * this field used to be a version number, where the two version types
 108  * were 1 and 2.  Using two bits for this allows earlier versions of
 109  * the code to be able to recognize send streams that don't use any
 110  * of the features indicated by feature flags.
 111  */
 112 
 113 #define DMU_BACKUP_MAGIC 0x2F5bacbacULL
 114 
 115 #define DRR_FLAG_CLONE          (1<<0)
 116 #define DRR_FLAG_CI_DATA        (1<<1)
 117 
 118 /*
 119  * flags in the drr_checksumflags field in the DRR_WRITE and
 120  * DRR_WRITE_BYREF blocks
 121  */
 122 #define DRR_CHECKSUM_DEDUP      (1<<0)
 123 
 124 #define DRR_IS_DEDUP_CAPABLE(flags)     ((flags) & DRR_CHECKSUM_DEDUP)
 125 
 126 /*
 127  * zfs ioctl command structure
 128  */
 129 typedef struct dmu_replay_record {
 130         enum {
 131                 DRR_BEGIN, DRR_OBJECT, DRR_FREEOBJECTS,
 132                 DRR_WRITE, DRR_FREE, DRR_END, DRR_WRITE_BYREF,
 133                 DRR_SPILL, DRR_NUMTYPES
 134         } drr_type;
 135         uint32_t drr_payloadlen;
 136         union {
 137                 struct drr_begin {
 138                         uint64_t drr_magic;
 139                         uint64_t drr_versioninfo; /* was drr_version */
 140                         uint64_t drr_creation_time;
 141                         dmu_objset_type_t drr_type;
 142                         uint32_t drr_flags;
 143                         uint64_t drr_toguid;
 144                         uint64_t drr_fromguid;
 145                         char drr_toname[MAXNAMELEN];
 146                 } drr_begin;
 147                 struct drr_end {
 148                         zio_cksum_t drr_checksum;
 149                         uint64_t drr_toguid;
 150                 } drr_end;
 151                 struct drr_object {
 152                         uint64_t drr_object;
 153                         dmu_object_type_t drr_type;
 154                         dmu_object_type_t drr_bonustype;
 155                         uint32_t drr_blksz;
 156                         uint32_t drr_bonuslen;
 157                         uint8_t drr_checksumtype;
 158                         uint8_t drr_compress;
 159                         uint8_t drr_pad[6];
 160                         uint64_t drr_toguid;
 161                         /* bonus content follows */
 162                 } drr_object;
 163                 struct drr_freeobjects {
 164                         uint64_t drr_firstobj;
 165                         uint64_t drr_numobjs;
 166                         uint64_t drr_toguid;
 167                 } drr_freeobjects;
 168                 struct drr_write {
 169                         uint64_t drr_object;
 170                         dmu_object_type_t drr_type;
 171                         uint32_t drr_pad;
 172                         uint64_t drr_offset;
 173                         uint64_t drr_length;
 174                         uint64_t drr_toguid;
 175                         uint8_t drr_checksumtype;
 176                         uint8_t drr_checksumflags;
 177                         uint8_t drr_pad2[6];
 178                         ddt_key_t drr_key; /* deduplication key */
 179                         /* content follows */
 180                 } drr_write;
 181                 struct drr_free {
 182                         uint64_t drr_object;
 183                         uint64_t drr_offset;
 184                         uint64_t drr_length;
 185                         uint64_t drr_toguid;
 186                 } drr_free;
 187                 struct drr_write_byref {
 188                         /* where to put the data */
 189                         uint64_t drr_object;
 190                         uint64_t drr_offset;
 191                         uint64_t drr_length;
 192                         uint64_t drr_toguid;
 193                         /* where to find the prior copy of the data */
 194                         uint64_t drr_refguid;
 195                         uint64_t drr_refobject;
 196                         uint64_t drr_refoffset;
 197                         /* properties of the data */
 198                         uint8_t drr_checksumtype;
 199                         uint8_t drr_checksumflags;
 200                         uint8_t drr_pad2[6];
 201                         ddt_key_t drr_key; /* deduplication key */
 202                 } drr_write_byref;
 203                 struct drr_spill {
 204                         uint64_t drr_object;
 205                         uint64_t drr_length;
 206                         uint64_t drr_toguid;
 207                         uint64_t drr_pad[4]; /* needed for crypto */
 208                         /* spill data follows */
 209                 } drr_spill;
 210         } drr_u;
 211 } dmu_replay_record_t;
 212 
 213 /* diff record range types */
 214 typedef enum diff_type {
 215         DDR_NONE = 0x1,
 216         DDR_INUSE = 0x2,
 217         DDR_FREE = 0x4
 218 } diff_type_t;
 219 
 220 /*
 221  * The diff reports back ranges of free or in-use objects.
 222  */
 223 typedef struct dmu_diff_record {
 224         uint64_t ddr_type;
 225         uint64_t ddr_first;
 226         uint64_t ddr_last;
 227 } dmu_diff_record_t;
 228 
 229 typedef struct zinject_record {
 230         uint64_t        zi_objset;
 231         uint64_t        zi_object;
 232         uint64_t        zi_start;
 233         uint64_t        zi_end;
 234         uint64_t        zi_guid;
 235         uint32_t        zi_level;
 236         uint32_t        zi_error;
 237         uint64_t        zi_type;
 238         uint32_t        zi_freq;
 239         uint32_t        zi_failfast;
 240         char            zi_func[MAXNAMELEN];
 241         uint32_t        zi_iotype;
 242         int32_t         zi_duration;
 243         uint64_t        zi_timer;
 244 } zinject_record_t;
 245 
 246 #define ZINJECT_NULL            0x1
 247 #define ZINJECT_FLUSH_ARC       0x2
 248 #define ZINJECT_UNLOAD_SPA      0x4
 249 
 250 typedef struct zfs_share {
 251         uint64_t        z_exportdata;
 252         uint64_t        z_sharedata;
 253         uint64_t        z_sharetype;    /* 0 = share, 1 = unshare */
 254         uint64_t        z_sharemax;  /* max length of share string */
 255 } zfs_share_t;
 256 
 257 /*
 258  * ZFS file systems may behave the usual, POSIX-compliant way, where
 259  * name lookups are case-sensitive.  They may also be set up so that
 260  * all the name lookups are case-insensitive, or so that only some
 261  * lookups, the ones that set an FIGNORECASE flag, are case-insensitive.
 262  */
 263 typedef enum zfs_case {
 264         ZFS_CASE_SENSITIVE,
 265         ZFS_CASE_INSENSITIVE,
 266         ZFS_CASE_MIXED
 267 } zfs_case_t;
 268 
 269 typedef struct zfs_cmd {
 270         char            zc_name[MAXPATHLEN];    /* name of pool or dataset */
 271         uint64_t        zc_nvlist_src;          /* really (char *) */
 272         uint64_t        zc_nvlist_src_size;
 273         uint64_t        zc_nvlist_dst;          /* really (char *) */
 274         uint64_t        zc_nvlist_dst_size;
 275         boolean_t       zc_nvlist_dst_filled;   /* put an nvlist in dst? */
 276         int             zc_pad2;
 277 
 278         /*
 279          * The following members are for legacy ioctls which haven't been
 280          * converted to the new method.
 281          */
 282         uint64_t        zc_history;             /* really (char *) */
 283         char            zc_value[MAXPATHLEN * 2];
 284         char            zc_string[MAXNAMELEN];
 285         char            zc_top_ds[MAXPATHLEN];
 286         uint64_t        zc_guid;
 287         uint64_t        zc_nvlist_conf;         /* really (char *) */
 288         uint64_t        zc_nvlist_conf_size;
 289         uint64_t        zc_cookie;
 290         uint64_t        zc_objset_type;
 291         uint64_t        zc_perm_action;
 292         uint64_t        zc_history_len;
 293         uint64_t        zc_history_offset;
 294         uint64_t        zc_obj;
 295         uint64_t        zc_iflags;              /* internal to zfs(7fs) */
 296         zfs_share_t     zc_share;
 297         dmu_objset_stats_t zc_objset_stats;
 298         struct drr_begin zc_begin_record;
 299         zinject_record_t zc_inject_record;
 300         boolean_t       zc_defer_destroy;
 301         boolean_t       zc_temphold;
 302         uint64_t        zc_action_handle;
 303         int             zc_cleanup_fd;
 304         uint8_t         zc_pad[4];              /* alignment */
 305         uint64_t        zc_sendobj;
 306         uint64_t        zc_fromobj;
 307         uint64_t        zc_createtxg;
 308         zfs_stat_t      zc_stat;
 309         uint64_t        zc_sendcounter;
 310         boolean_t       zc_sendsize;
 311 } zfs_cmd_t;
 312 
 313 typedef struct zfs_useracct {
 314         char zu_domain[256];
 315         uid_t zu_rid;
 316         uint32_t zu_pad;
 317         uint64_t zu_space;
 318 } zfs_useracct_t;
 319 
 320 #define ZFSDEV_MAX_MINOR        (1 << 16)
 321 #define ZFS_MIN_MINOR   (ZFSDEV_MAX_MINOR + 1)
 322 
 323 #define ZPOOL_EXPORT_AFTER_SPLIT 0x1
 324 
 325 #ifdef _KERNEL
 326 
 327 typedef struct zfs_creat {
 328         nvlist_t        *zct_zplprops;
 329         nvlist_t        *zct_props;
 330 } zfs_creat_t;
 331 
 332 extern dev_info_t *zfs_dip;
 333 
 334 extern int zfs_secpolicy_snapshot_perms(const char *name, cred_t *cr);
 335 extern int zfs_secpolicy_rename_perms(const char *from,
 336     const char *to, cred_t *cr);
 337 extern int zfs_secpolicy_destroy_perms(const char *name, cred_t *cr);
 338 extern int zfs_busy(void);
 339 extern int zfs_unmount_snap(const char *, void *);
 340 
 341 /*
 342  * ZFS minor numbers can refer to either a control device instance or
 343  * a zvol. Depending on the value of zss_type, zss_data points to either
 344  * a zvol_state_t or a zfs_onexit_t.
 345  */
 346 enum zfs_soft_state_type {
 347         ZSST_ZVOL,
 348         ZSST_CTLDEV
 349 };
 350 
 351 typedef struct zfs_soft_state {
 352         enum zfs_soft_state_type zss_type;
 353         void *zss_data;
 354 } zfs_soft_state_t;
 355 
 356 extern void *zfsdev_get_soft_state(minor_t minor,
 357     enum zfs_soft_state_type which);
 358 extern minor_t zfsdev_minor_alloc(void);
 359 
 360 extern void *zfsdev_state;
 361 extern kmutex_t zfsdev_state_lock;
 362 
 363 #endif  /* _KERNEL */
 364 
 365 #ifdef  __cplusplus
 366 }
 367 #endif
 368 
 369 #endif  /* _SYS_ZFS_IOCTL_H */