linux/include/uapi/linux/btrfs.h
<<
>>
Prefs
   1/*
   2 * Copyright (C) 2007 Oracle.  All rights reserved.
   3 *
   4 * This program is free software; you can redistribute it and/or
   5 * modify it under the terms of the GNU General Public
   6 * License v2 as published by the Free Software Foundation.
   7 *
   8 * This program is distributed in the hope that it will be useful,
   9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11 * General Public License for more details.
  12 *
  13 * You should have received a copy of the GNU General Public
  14 * License along with this program; if not, write to the
  15 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  16 * Boston, MA 021110-1307, USA.
  17 */
  18
  19#ifndef _UAPI_LINUX_BTRFS_H
  20#define _UAPI_LINUX_BTRFS_H
  21#include <linux/types.h>
  22#include <linux/ioctl.h>
  23
  24#define BTRFS_IOCTL_MAGIC 0x94
  25#define BTRFS_VOL_NAME_MAX 255
  26#define BTRFS_LABEL_SIZE 256
  27
  28/* this should be 4k */
  29#define BTRFS_PATH_NAME_MAX 4087
  30struct btrfs_ioctl_vol_args {
  31        __s64 fd;
  32        char name[BTRFS_PATH_NAME_MAX + 1];
  33};
  34
  35#define BTRFS_DEVICE_PATH_NAME_MAX 1024
  36
  37#define BTRFS_SUBVOL_CREATE_ASYNC       (1ULL << 0)
  38#define BTRFS_SUBVOL_RDONLY             (1ULL << 1)
  39#define BTRFS_SUBVOL_QGROUP_INHERIT     (1ULL << 2)
  40#define BTRFS_DEVICE_SPEC_BY_ID         (1ULL << 3)
  41
  42#define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED                \
  43                        (BTRFS_SUBVOL_CREATE_ASYNC |    \
  44                        BTRFS_SUBVOL_RDONLY |           \
  45                        BTRFS_SUBVOL_QGROUP_INHERIT |   \
  46                        BTRFS_DEVICE_SPEC_BY_ID)
  47
  48#define BTRFS_FSID_SIZE 16
  49#define BTRFS_UUID_SIZE 16
  50#define BTRFS_UUID_UNPARSED_SIZE        37
  51
  52/*
  53 * flags definition for qgroup limits
  54 *
  55 * Used by:
  56 * struct btrfs_qgroup_limit.flags
  57 * struct btrfs_qgroup_limit_item.flags
  58 */
  59#define BTRFS_QGROUP_LIMIT_MAX_RFER     (1ULL << 0)
  60#define BTRFS_QGROUP_LIMIT_MAX_EXCL     (1ULL << 1)
  61#define BTRFS_QGROUP_LIMIT_RSV_RFER     (1ULL << 2)
  62#define BTRFS_QGROUP_LIMIT_RSV_EXCL     (1ULL << 3)
  63#define BTRFS_QGROUP_LIMIT_RFER_CMPR    (1ULL << 4)
  64#define BTRFS_QGROUP_LIMIT_EXCL_CMPR    (1ULL << 5)
  65
  66struct btrfs_qgroup_limit {
  67        __u64   flags;
  68        __u64   max_rfer;
  69        __u64   max_excl;
  70        __u64   rsv_rfer;
  71        __u64   rsv_excl;
  72};
  73
  74/*
  75 * flags definition for qgroup inheritance
  76 *
  77 * Used by:
  78 * struct btrfs_qgroup_inherit.flags
  79 */
  80#define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0)
  81
  82struct btrfs_qgroup_inherit {
  83        __u64   flags;
  84        __u64   num_qgroups;
  85        __u64   num_ref_copies;
  86        __u64   num_excl_copies;
  87        struct btrfs_qgroup_limit lim;
  88        __u64   qgroups[0];
  89};
  90
  91struct btrfs_ioctl_qgroup_limit_args {
  92        __u64   qgroupid;
  93        struct btrfs_qgroup_limit lim;
  94};
  95
  96#define BTRFS_SUBVOL_NAME_MAX 4039
  97struct btrfs_ioctl_vol_args_v2 {
  98        __s64 fd;
  99        __u64 transid;
 100        __u64 flags;
 101        union {
 102                struct {
 103                        __u64 size;
 104                        struct btrfs_qgroup_inherit __user *qgroup_inherit;
 105                };
 106                __u64 unused[4];
 107        };
 108        union {
 109                char name[BTRFS_SUBVOL_NAME_MAX + 1];
 110                __u64 devid;
 111        };
 112};
 113
 114/*
 115 * structure to report errors and progress to userspace, either as a
 116 * result of a finished scrub, a canceled scrub or a progress inquiry
 117 */
 118struct btrfs_scrub_progress {
 119        __u64 data_extents_scrubbed;    /* # of data extents scrubbed */
 120        __u64 tree_extents_scrubbed;    /* # of tree extents scrubbed */
 121        __u64 data_bytes_scrubbed;      /* # of data bytes scrubbed */
 122        __u64 tree_bytes_scrubbed;      /* # of tree bytes scrubbed */
 123        __u64 read_errors;              /* # of read errors encountered (EIO) */
 124        __u64 csum_errors;              /* # of failed csum checks */
 125        __u64 verify_errors;            /* # of occurences, where the metadata
 126                                         * of a tree block did not match the
 127                                         * expected values, like generation or
 128                                         * logical */
 129        __u64 no_csum;                  /* # of 4k data block for which no csum
 130                                         * is present, probably the result of
 131                                         * data written with nodatasum */
 132        __u64 csum_discards;            /* # of csum for which no data was found
 133                                         * in the extent tree. */
 134        __u64 super_errors;             /* # of bad super blocks encountered */
 135        __u64 malloc_errors;            /* # of internal kmalloc errors. These
 136                                         * will likely cause an incomplete
 137                                         * scrub */
 138        __u64 uncorrectable_errors;     /* # of errors where either no intact
 139                                         * copy was found or the writeback
 140                                         * failed */
 141        __u64 corrected_errors;         /* # of errors corrected */
 142        __u64 last_physical;            /* last physical address scrubbed. In
 143                                         * case a scrub was aborted, this can
 144                                         * be used to restart the scrub */
 145        __u64 unverified_errors;        /* # of occurences where a read for a
 146                                         * full (64k) bio failed, but the re-
 147                                         * check succeeded for each 4k piece.
 148                                         * Intermittent error. */
 149};
 150
 151#define BTRFS_SCRUB_READONLY    1
 152struct btrfs_ioctl_scrub_args {
 153        __u64 devid;                            /* in */
 154        __u64 start;                            /* in */
 155        __u64 end;                              /* in */
 156        __u64 flags;                            /* in */
 157        struct btrfs_scrub_progress progress;   /* out */
 158        /* pad to 1k */
 159        __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8];
 160};
 161
 162#define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS    0
 163#define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID     1
 164struct btrfs_ioctl_dev_replace_start_params {
 165        __u64 srcdevid; /* in, if 0, use srcdev_name instead */
 166        __u64 cont_reading_from_srcdev_mode;    /* in, see #define
 167                                                 * above */
 168        __u8 srcdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1];       /* in */
 169        __u8 tgtdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1];       /* in */
 170};
 171
 172#define BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED     0
 173#define BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED           1
 174#define BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED          2
 175#define BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED          3
 176#define BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED         4
 177struct btrfs_ioctl_dev_replace_status_params {
 178        __u64 replace_state;    /* out, see #define above */
 179        __u64 progress_1000;    /* out, 0 <= x <= 1000 */
 180        __u64 time_started;     /* out, seconds since 1-Jan-1970 */
 181        __u64 time_stopped;     /* out, seconds since 1-Jan-1970 */
 182        __u64 num_write_errors; /* out */
 183        __u64 num_uncorrectable_read_errors;    /* out */
 184};
 185
 186#define BTRFS_IOCTL_DEV_REPLACE_CMD_START                       0
 187#define BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS                      1
 188#define BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL                      2
 189#define BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR                 0
 190#define BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED              1
 191#define BTRFS_IOCTL_DEV_REPLACE_RESULT_ALREADY_STARTED          2
 192#define BTRFS_IOCTL_DEV_REPLACE_RESULT_SCRUB_INPROGRESS         3
 193struct btrfs_ioctl_dev_replace_args {
 194        __u64 cmd;      /* in */
 195        __u64 result;   /* out */
 196
 197        union {
 198                struct btrfs_ioctl_dev_replace_start_params start;
 199                struct btrfs_ioctl_dev_replace_status_params status;
 200        };      /* in/out */
 201
 202        __u64 spare[64];
 203};
 204
 205struct btrfs_ioctl_dev_info_args {
 206        __u64 devid;                            /* in/out */
 207        __u8 uuid[BTRFS_UUID_SIZE];             /* in/out */
 208        __u64 bytes_used;                       /* out */
 209        __u64 total_bytes;                      /* out */
 210        __u64 unused[379];                      /* pad to 4k */
 211        __u8 path[BTRFS_DEVICE_PATH_NAME_MAX];  /* out */
 212};
 213
 214struct btrfs_ioctl_fs_info_args {
 215        __u64 max_id;                           /* out */
 216        __u64 num_devices;                      /* out */
 217        __u8 fsid[BTRFS_FSID_SIZE];             /* out */
 218        __u32 nodesize;                         /* out */
 219        __u32 sectorsize;                       /* out */
 220        __u32 clone_alignment;                  /* out */
 221        __u32 reserved32;
 222        __u64 reserved[122];                    /* pad to 1k */
 223};
 224
 225/*
 226 * feature flags
 227 *
 228 * Used by:
 229 * struct btrfs_ioctl_feature_flags
 230 */
 231#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE         (1ULL << 0)
 232/*
 233 * Older kernels (< 4.9) on big-endian systems produced broken free space tree
 234 * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions
 235 * < 4.7.3).  If this bit is clear, then the free space tree cannot be trusted.
 236 * btrfs-progs can also intentionally clear this bit to ask the kernel to
 237 * rebuild the free space tree, however this might not work on older kernels
 238 * that do not know about this bit. If not sure, clear the cache manually on
 239 * first mount when booting older kernel versions.
 240 */
 241#define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID   (1ULL << 1)
 242
 243#define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF    (1ULL << 0)
 244#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL   (1ULL << 1)
 245#define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS     (1ULL << 2)
 246#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO     (1ULL << 3)
 247/*
 248 * some patches floated around with a second compression method
 249 * lets save that incompat here for when they do get in
 250 * Note we don't actually support it, we're just reserving the
 251 * number
 252 */
 253#define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZOv2   (1ULL << 4)
 254
 255/*
 256 * older kernels tried to do bigger metadata blocks, but the
 257 * code was pretty buggy.  Lets not let them try anymore.
 258 */
 259#define BTRFS_FEATURE_INCOMPAT_BIG_METADATA     (1ULL << 5)
 260
 261#define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF    (1ULL << 6)
 262#define BTRFS_FEATURE_INCOMPAT_RAID56           (1ULL << 7)
 263#define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA  (1ULL << 8)
 264#define BTRFS_FEATURE_INCOMPAT_NO_HOLES         (1ULL << 9)
 265
 266struct btrfs_ioctl_feature_flags {
 267        __u64 compat_flags;
 268        __u64 compat_ro_flags;
 269        __u64 incompat_flags;
 270};
 271
 272/* balance control ioctl modes */
 273#define BTRFS_BALANCE_CTL_PAUSE         1
 274#define BTRFS_BALANCE_CTL_CANCEL        2
 275
 276/*
 277 * this is packed, because it should be exactly the same as its disk
 278 * byte order counterpart (struct btrfs_disk_balance_args)
 279 */
 280struct btrfs_balance_args {
 281        __u64 profiles;
 282        union {
 283                __le64 usage;
 284                struct {
 285                        __le32 usage_min;
 286                        __le32 usage_max;
 287                };
 288        };
 289        __u64 devid;
 290        __u64 pstart;
 291        __u64 pend;
 292        __u64 vstart;
 293        __u64 vend;
 294
 295        __u64 target;
 296
 297        __u64 flags;
 298
 299        /*
 300         * BTRFS_BALANCE_ARGS_LIMIT with value 'limit'
 301         * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum
 302         * and maximum
 303         */
 304        union {
 305                __u64 limit;            /* limit number of processed chunks */
 306                struct {
 307                        __u32 limit_min;
 308                        __u32 limit_max;
 309                };
 310        };
 311
 312        /*
 313         * Process chunks that cross stripes_min..stripes_max devices,
 314         * BTRFS_BALANCE_ARGS_STRIPES_RANGE
 315         */
 316        __le32 stripes_min;
 317        __le32 stripes_max;
 318
 319        __u64 unused[6];
 320} __attribute__ ((__packed__));
 321
 322/* report balance progress to userspace */
 323struct btrfs_balance_progress {
 324        __u64 expected;         /* estimated # of chunks that will be
 325                                 * relocated to fulfill the request */
 326        __u64 considered;       /* # of chunks we have considered so far */
 327        __u64 completed;        /* # of chunks relocated so far */
 328};
 329
 330/*
 331 * flags definition for balance
 332 *
 333 * Restriper's general type filter
 334 *
 335 * Used by:
 336 * btrfs_ioctl_balance_args.flags
 337 * btrfs_balance_control.flags (internal)
 338 */
 339#define BTRFS_BALANCE_DATA              (1ULL << 0)
 340#define BTRFS_BALANCE_SYSTEM            (1ULL << 1)
 341#define BTRFS_BALANCE_METADATA          (1ULL << 2)
 342
 343#define BTRFS_BALANCE_TYPE_MASK         (BTRFS_BALANCE_DATA |       \
 344                                         BTRFS_BALANCE_SYSTEM |     \
 345                                         BTRFS_BALANCE_METADATA)
 346
 347#define BTRFS_BALANCE_FORCE             (1ULL << 3)
 348#define BTRFS_BALANCE_RESUME            (1ULL << 4)
 349
 350/*
 351 * flags definitions for per-type balance args
 352 *
 353 * Balance filters
 354 *
 355 * Used by:
 356 * struct btrfs_balance_args
 357 */
 358#define BTRFS_BALANCE_ARGS_PROFILES     (1ULL << 0)
 359#define BTRFS_BALANCE_ARGS_USAGE        (1ULL << 1)
 360#define BTRFS_BALANCE_ARGS_DEVID        (1ULL << 2)
 361#define BTRFS_BALANCE_ARGS_DRANGE       (1ULL << 3)
 362#define BTRFS_BALANCE_ARGS_VRANGE       (1ULL << 4)
 363#define BTRFS_BALANCE_ARGS_LIMIT        (1ULL << 5)
 364#define BTRFS_BALANCE_ARGS_LIMIT_RANGE  (1ULL << 6)
 365#define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7)
 366#define BTRFS_BALANCE_ARGS_USAGE_RANGE  (1ULL << 10)
 367
 368#define BTRFS_BALANCE_ARGS_MASK                 \
 369        (BTRFS_BALANCE_ARGS_PROFILES |          \
 370         BTRFS_BALANCE_ARGS_USAGE |             \
 371         BTRFS_BALANCE_ARGS_DEVID |             \
 372         BTRFS_BALANCE_ARGS_DRANGE |            \
 373         BTRFS_BALANCE_ARGS_VRANGE |            \
 374         BTRFS_BALANCE_ARGS_LIMIT |             \
 375         BTRFS_BALANCE_ARGS_LIMIT_RANGE |       \
 376         BTRFS_BALANCE_ARGS_STRIPES_RANGE |     \
 377         BTRFS_BALANCE_ARGS_USAGE_RANGE)
 378
 379/*
 380 * Profile changing flags.  When SOFT is set we won't relocate chunk if
 381 * it already has the target profile (even though it may be
 382 * half-filled).
 383 */
 384#define BTRFS_BALANCE_ARGS_CONVERT      (1ULL << 8)
 385#define BTRFS_BALANCE_ARGS_SOFT         (1ULL << 9)
 386
 387
 388/*
 389 * flags definition for balance state
 390 *
 391 * Used by:
 392 * struct btrfs_ioctl_balance_args.state
 393 */
 394#define BTRFS_BALANCE_STATE_RUNNING     (1ULL << 0)
 395#define BTRFS_BALANCE_STATE_PAUSE_REQ   (1ULL << 1)
 396#define BTRFS_BALANCE_STATE_CANCEL_REQ  (1ULL << 2)
 397
 398struct btrfs_ioctl_balance_args {
 399        __u64 flags;                            /* in/out */
 400        __u64 state;                            /* out */
 401
 402        struct btrfs_balance_args data;         /* in/out */
 403        struct btrfs_balance_args meta;         /* in/out */
 404        struct btrfs_balance_args sys;          /* in/out */
 405
 406        struct btrfs_balance_progress stat;     /* out */
 407
 408        __u64 unused[72];                       /* pad to 1k */
 409};
 410
 411#define BTRFS_INO_LOOKUP_PATH_MAX 4080
 412struct btrfs_ioctl_ino_lookup_args {
 413        __u64 treeid;
 414        __u64 objectid;
 415        char name[BTRFS_INO_LOOKUP_PATH_MAX];
 416};
 417
 418struct btrfs_ioctl_search_key {
 419        /* which root are we searching.  0 is the tree of tree roots */
 420        __u64 tree_id;
 421
 422        /* keys returned will be >= min and <= max */
 423        __u64 min_objectid;
 424        __u64 max_objectid;
 425
 426        /* keys returned will be >= min and <= max */
 427        __u64 min_offset;
 428        __u64 max_offset;
 429
 430        /* max and min transids to search for */
 431        __u64 min_transid;
 432        __u64 max_transid;
 433
 434        /* keys returned will be >= min and <= max */
 435        __u32 min_type;
 436        __u32 max_type;
 437
 438        /*
 439         * how many items did userland ask for, and how many are we
 440         * returning
 441         */
 442        __u32 nr_items;
 443
 444        /* align to 64 bits */
 445        __u32 unused;
 446
 447        /* some extra for later */
 448        __u64 unused1;
 449        __u64 unused2;
 450        __u64 unused3;
 451        __u64 unused4;
 452};
 453
 454struct btrfs_ioctl_search_header {
 455        __u64 transid;
 456        __u64 objectid;
 457        __u64 offset;
 458        __u32 type;
 459        __u32 len;
 460};
 461
 462#define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key))
 463/*
 464 * the buf is an array of search headers where
 465 * each header is followed by the actual item
 466 * the type field is expanded to 32 bits for alignment
 467 */
 468struct btrfs_ioctl_search_args {
 469        struct btrfs_ioctl_search_key key;
 470        char buf[BTRFS_SEARCH_ARGS_BUFSIZE];
 471};
 472
 473struct btrfs_ioctl_search_args_v2 {
 474        struct btrfs_ioctl_search_key key; /* in/out - search parameters */
 475        __u64 buf_size;            /* in - size of buffer
 476                                            * out - on EOVERFLOW: needed size
 477                                            *       to store item */
 478        __u64 buf[0];                       /* out - found items */
 479};
 480
 481struct btrfs_ioctl_clone_range_args {
 482  __s64 src_fd;
 483  __u64 src_offset, src_length;
 484  __u64 dest_offset;
 485};
 486
 487/*
 488 * flags definition for the defrag range ioctl
 489 *
 490 * Used by:
 491 * struct btrfs_ioctl_defrag_range_args.flags
 492 */
 493#define BTRFS_DEFRAG_RANGE_COMPRESS 1
 494#define BTRFS_DEFRAG_RANGE_START_IO 2
 495struct btrfs_ioctl_defrag_range_args {
 496        /* start of the defrag operation */
 497        __u64 start;
 498
 499        /* number of bytes to defrag, use (u64)-1 to say all */
 500        __u64 len;
 501
 502        /*
 503         * flags for the operation, which can include turning
 504         * on compression for this one defrag
 505         */
 506        __u64 flags;
 507
 508        /*
 509         * any extent bigger than this will be considered
 510         * already defragged.  Use 0 to take the kernel default
 511         * Use 1 to say every single extent must be rewritten
 512         */
 513        __u32 extent_thresh;
 514
 515        /*
 516         * which compression method to use if turning on compression
 517         * for this defrag operation.  If unspecified, zlib will
 518         * be used
 519         */
 520        __u32 compress_type;
 521
 522        /* spare for later */
 523        __u32 unused[4];
 524};
 525
 526
 527#define BTRFS_SAME_DATA_DIFFERS 1
 528/* For extent-same ioctl */
 529struct btrfs_ioctl_same_extent_info {
 530        __s64 fd;               /* in - destination file */
 531        __u64 logical_offset;   /* in - start of extent in destination */
 532        __u64 bytes_deduped;    /* out - total # of bytes we were able
 533                                 * to dedupe from this file */
 534        /* status of this dedupe operation:
 535         * 0 if dedup succeeds
 536         * < 0 for error
 537         * == BTRFS_SAME_DATA_DIFFERS if data differs
 538         */
 539        __s32 status;           /* out - see above description */
 540        __u32 reserved;
 541};
 542
 543struct btrfs_ioctl_same_args {
 544        __u64 logical_offset;   /* in - start of extent in source */
 545        __u64 length;           /* in - length of extent */
 546        __u16 dest_count;       /* in - total elements in info array */
 547        __u16 reserved1;
 548        __u32 reserved2;
 549        struct btrfs_ioctl_same_extent_info info[0];
 550};
 551
 552struct btrfs_ioctl_space_info {
 553        __u64 flags;
 554        __u64 total_bytes;
 555        __u64 used_bytes;
 556};
 557
 558struct btrfs_ioctl_space_args {
 559        __u64 space_slots;
 560        __u64 total_spaces;
 561        struct btrfs_ioctl_space_info spaces[0];
 562};
 563
 564struct btrfs_data_container {
 565        __u32   bytes_left;     /* out -- bytes not needed to deliver output */
 566        __u32   bytes_missing;  /* out -- additional bytes needed for result */
 567        __u32   elem_cnt;       /* out */
 568        __u32   elem_missed;    /* out */
 569        __u64   val[0];         /* out */
 570};
 571
 572struct btrfs_ioctl_ino_path_args {
 573        __u64                           inum;           /* in */
 574        __u64                           size;           /* in */
 575        __u64                           reserved[4];
 576        /* struct btrfs_data_container  *fspath;           out */
 577        __u64                           fspath;         /* out */
 578};
 579
 580struct btrfs_ioctl_logical_ino_args {
 581        __u64                           logical;        /* in */
 582        __u64                           size;           /* in */
 583        __u64                           reserved[4];
 584        /* struct btrfs_data_container  *inodes;        out   */
 585        __u64                           inodes;
 586};
 587
 588enum btrfs_dev_stat_values {
 589        /* disk I/O failure stats */
 590        BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */
 591        BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */
 592        BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */
 593
 594        /* stats for indirect indications for I/O failures */
 595        BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or
 596                                         * contents is illegal: this is an
 597                                         * indication that the block was damaged
 598                                         * during read or write, or written to
 599                                         * wrong location or read from wrong
 600                                         * location */
 601        BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not
 602                                         * been written */
 603
 604        BTRFS_DEV_STAT_VALUES_MAX
 605};
 606
 607/* Reset statistics after reading; needs SYS_ADMIN capability */
 608#define BTRFS_DEV_STATS_RESET           (1ULL << 0)
 609
 610struct btrfs_ioctl_get_dev_stats {
 611        __u64 devid;                            /* in */
 612        __u64 nr_items;                         /* in/out */
 613        __u64 flags;                            /* in/out */
 614
 615        /* out values: */
 616        __u64 values[BTRFS_DEV_STAT_VALUES_MAX];
 617
 618        __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; /* pad to 1k */
 619};
 620
 621#define BTRFS_QUOTA_CTL_ENABLE  1
 622#define BTRFS_QUOTA_CTL_DISABLE 2
 623#define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3
 624struct btrfs_ioctl_quota_ctl_args {
 625        __u64 cmd;
 626        __u64 status;
 627};
 628
 629struct btrfs_ioctl_quota_rescan_args {
 630        __u64   flags;
 631        __u64   progress;
 632        __u64   reserved[6];
 633};
 634
 635struct btrfs_ioctl_qgroup_assign_args {
 636        __u64 assign;
 637        __u64 src;
 638        __u64 dst;
 639};
 640
 641struct btrfs_ioctl_qgroup_create_args {
 642        __u64 create;
 643        __u64 qgroupid;
 644};
 645struct btrfs_ioctl_timespec {
 646        __u64 sec;
 647        __u32 nsec;
 648};
 649
 650struct btrfs_ioctl_received_subvol_args {
 651        char    uuid[BTRFS_UUID_SIZE];  /* in */
 652        __u64   stransid;               /* in */
 653        __u64   rtransid;               /* out */
 654        struct btrfs_ioctl_timespec stime; /* in */
 655        struct btrfs_ioctl_timespec rtime; /* out */
 656        __u64   flags;                  /* in */
 657        __u64   reserved[16];           /* in */
 658};
 659
 660/*
 661 * Caller doesn't want file data in the send stream, even if the
 662 * search of clone sources doesn't find an extent. UPDATE_EXTENT
 663 * commands will be sent instead of WRITE commands.
 664 */
 665#define BTRFS_SEND_FLAG_NO_FILE_DATA            0x1
 666
 667/*
 668 * Do not add the leading stream header. Used when multiple snapshots
 669 * are sent back to back.
 670 */
 671#define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER      0x2
 672
 673/*
 674 * Omit the command at the end of the stream that indicated the end
 675 * of the stream. This option is used when multiple snapshots are
 676 * sent back to back.
 677 */
 678#define BTRFS_SEND_FLAG_OMIT_END_CMD            0x4
 679
 680#define BTRFS_SEND_FLAG_MASK \
 681        (BTRFS_SEND_FLAG_NO_FILE_DATA | \
 682         BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \
 683         BTRFS_SEND_FLAG_OMIT_END_CMD)
 684
 685struct btrfs_ioctl_send_args {
 686        __s64 send_fd;                  /* in */
 687        __u64 clone_sources_count;      /* in */
 688        __u64 __user *clone_sources;    /* in */
 689        __u64 parent_root;              /* in */
 690        __u64 flags;                    /* in */
 691        __u64 reserved[4];              /* in */
 692};
 693
 694/* Error codes as returned by the kernel */
 695enum btrfs_err_code {
 696        notused,
 697        BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET,
 698        BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET,
 699        BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET,
 700        BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET,
 701        BTRFS_ERROR_DEV_TGT_REPLACE,
 702        BTRFS_ERROR_DEV_MISSING_NOT_FOUND,
 703        BTRFS_ERROR_DEV_ONLY_WRITABLE,
 704        BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS
 705};
 706/* An error code to error string mapping for the kernel
 707*  error codes
 708*/
 709static inline char *btrfs_err_str(enum btrfs_err_code err_code)
 710{
 711        switch (err_code) {
 712                case BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET:
 713                        return "unable to go below two devices on raid1";
 714                case BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET:
 715                        return "unable to go below four devices on raid10";
 716                case BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET:
 717                        return "unable to go below two devices on raid5";
 718                case BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET:
 719                        return "unable to go below three devices on raid6";
 720                case BTRFS_ERROR_DEV_TGT_REPLACE:
 721                        return "unable to remove the dev_replace target dev";
 722                case BTRFS_ERROR_DEV_MISSING_NOT_FOUND:
 723                        return "no missing devices found to remove";
 724                case BTRFS_ERROR_DEV_ONLY_WRITABLE:
 725                        return "unable to remove the only writeable device";
 726                case BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS:
 727                        return "add/delete/balance/replace/resize operation "\
 728                                "in progress";
 729                default:
 730                        return NULL;
 731        }
 732}
 733
 734#define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \
 735                                   struct btrfs_ioctl_vol_args)
 736#define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \
 737                                   struct btrfs_ioctl_vol_args)
 738#define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \
 739                                   struct btrfs_ioctl_vol_args)
 740#define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \
 741                                   struct btrfs_ioctl_vol_args)
 742/* trans start and trans end are dangerous, and only for
 743 * use by applications that know how to avoid the
 744 * resulting deadlocks
 745 */
 746#define BTRFS_IOC_TRANS_START  _IO(BTRFS_IOCTL_MAGIC, 6)
 747#define BTRFS_IOC_TRANS_END    _IO(BTRFS_IOCTL_MAGIC, 7)
 748#define BTRFS_IOC_SYNC         _IO(BTRFS_IOCTL_MAGIC, 8)
 749
 750#define BTRFS_IOC_CLONE        _IOW(BTRFS_IOCTL_MAGIC, 9, int)
 751#define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \
 752                                   struct btrfs_ioctl_vol_args)
 753#define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \
 754                                   struct btrfs_ioctl_vol_args)
 755#define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \
 756                                   struct btrfs_ioctl_vol_args)
 757
 758#define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \
 759                                  struct btrfs_ioctl_clone_range_args)
 760
 761#define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \
 762                                   struct btrfs_ioctl_vol_args)
 763#define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \
 764                                struct btrfs_ioctl_vol_args)
 765#define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \
 766                                struct btrfs_ioctl_defrag_range_args)
 767#define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \
 768                                   struct btrfs_ioctl_search_args)
 769#define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \
 770                                           struct btrfs_ioctl_search_args_v2)
 771#define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \
 772                                   struct btrfs_ioctl_ino_lookup_args)
 773#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64)
 774#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \
 775                                    struct btrfs_ioctl_space_args)
 776#define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64)
 777#define BTRFS_IOC_WAIT_SYNC  _IOW(BTRFS_IOCTL_MAGIC, 22, __u64)
 778#define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \
 779                                   struct btrfs_ioctl_vol_args_v2)
 780#define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \
 781                                   struct btrfs_ioctl_vol_args_v2)
 782#define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64)
 783#define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64)
 784#define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \
 785                              struct btrfs_ioctl_scrub_args)
 786#define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28)
 787#define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \
 788                                       struct btrfs_ioctl_scrub_args)
 789#define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \
 790                                 struct btrfs_ioctl_dev_info_args)
 791#define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \
 792                               struct btrfs_ioctl_fs_info_args)
 793#define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \
 794                                   struct btrfs_ioctl_balance_args)
 795#define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int)
 796#define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \
 797                                        struct btrfs_ioctl_balance_args)
 798#define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \
 799                                        struct btrfs_ioctl_ino_path_args)
 800#define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \
 801                                        struct btrfs_ioctl_ino_path_args)
 802#define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \
 803                                struct btrfs_ioctl_received_subvol_args)
 804#define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args)
 805#define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \
 806                                     struct btrfs_ioctl_vol_args)
 807#define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \
 808                               struct btrfs_ioctl_quota_ctl_args)
 809#define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \
 810                               struct btrfs_ioctl_qgroup_assign_args)
 811#define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \
 812                               struct btrfs_ioctl_qgroup_create_args)
 813#define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \
 814                               struct btrfs_ioctl_qgroup_limit_args)
 815#define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \
 816                               struct btrfs_ioctl_quota_rescan_args)
 817#define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \
 818                               struct btrfs_ioctl_quota_rescan_args)
 819#define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46)
 820#define BTRFS_IOC_GET_FSLABEL _IOR(BTRFS_IOCTL_MAGIC, 49, \
 821                                   char[BTRFS_LABEL_SIZE])
 822#define BTRFS_IOC_SET_FSLABEL _IOW(BTRFS_IOCTL_MAGIC, 50, \
 823                                   char[BTRFS_LABEL_SIZE])
 824#define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \
 825                                      struct btrfs_ioctl_get_dev_stats)
 826#define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \
 827                                    struct btrfs_ioctl_dev_replace_args)
 828#define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \
 829                                         struct btrfs_ioctl_same_args)
 830#define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
 831                                   struct btrfs_ioctl_feature_flags)
 832#define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \
 833                                   struct btrfs_ioctl_feature_flags[2])
 834#define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \
 835                                   struct btrfs_ioctl_feature_flags[3])
 836#define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \
 837                                   struct btrfs_ioctl_vol_args_v2)
 838
 839#endif /* _UAPI_LINUX_BTRFS_H */
 840