1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 255e301fdSFilipe Brandenburger /* 355e301fdSFilipe Brandenburger * Copyright (C) 2007 Oracle. All rights reserved. 455e301fdSFilipe Brandenburger * 555e301fdSFilipe Brandenburger * This program is free software; you can redistribute it and/or 655e301fdSFilipe Brandenburger * modify it under the terms of the GNU General Public 755e301fdSFilipe Brandenburger * License v2 as published by the Free Software Foundation. 855e301fdSFilipe Brandenburger * 955e301fdSFilipe Brandenburger * This program is distributed in the hope that it will be useful, 1055e301fdSFilipe Brandenburger * but WITHOUT ANY WARRANTY; without even the implied warranty of 1155e301fdSFilipe Brandenburger * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 1255e301fdSFilipe Brandenburger * General Public License for more details. 1355e301fdSFilipe Brandenburger * 1455e301fdSFilipe Brandenburger * You should have received a copy of the GNU General Public 1555e301fdSFilipe Brandenburger * License along with this program; if not, write to the 1655e301fdSFilipe Brandenburger * Free Software Foundation, Inc., 59 Temple Place - Suite 330, 1755e301fdSFilipe Brandenburger * Boston, MA 021110-1307, USA. 1855e301fdSFilipe Brandenburger */ 1955e301fdSFilipe Brandenburger 2055e301fdSFilipe Brandenburger #ifndef _UAPI_LINUX_BTRFS_H 2155e301fdSFilipe Brandenburger #define _UAPI_LINUX_BTRFS_H 22a2813530SJosef Bacik 23a2813530SJosef Bacik #ifdef __cplusplus 24a2813530SJosef Bacik extern "C" { 25a2813530SJosef Bacik #endif 26a2813530SJosef Bacik 2755e301fdSFilipe Brandenburger #include <linux/types.h> 2855e301fdSFilipe Brandenburger #include <linux/ioctl.h> 29a2813530SJosef Bacik #include <linux/fs.h> 3055e301fdSFilipe Brandenburger 3155e301fdSFilipe Brandenburger #define BTRFS_IOCTL_MAGIC 0x94 3255e301fdSFilipe Brandenburger #define BTRFS_VOL_NAME_MAX 255 33d4ae133bSJeff Mahoney #define BTRFS_LABEL_SIZE 256 3455e301fdSFilipe Brandenburger 3555e301fdSFilipe Brandenburger /* this should be 4k */ 3655e301fdSFilipe Brandenburger #define BTRFS_PATH_NAME_MAX 4087 3755e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args { 3855e301fdSFilipe Brandenburger __s64 fd; 3955e301fdSFilipe Brandenburger char name[BTRFS_PATH_NAME_MAX + 1]; 4055e301fdSFilipe Brandenburger }; 4155e301fdSFilipe Brandenburger 4255e301fdSFilipe Brandenburger #define BTRFS_DEVICE_PATH_NAME_MAX 1024 43ad8bc4d0SAnand Jain #define BTRFS_SUBVOL_NAME_MAX 4039 44ad8bc4d0SAnand Jain 4534c51814SEugene Syromiatnikov #ifndef __KERNEL__ 4634c51814SEugene Syromiatnikov /* Deprecated since 5.7 */ 4734c51814SEugene Syromiatnikov # define BTRFS_SUBVOL_CREATE_ASYNC (1ULL << 0) 4834c51814SEugene Syromiatnikov #endif 49ad8bc4d0SAnand Jain #define BTRFS_SUBVOL_RDONLY (1ULL << 1) 50ad8bc4d0SAnand Jain #define BTRFS_SUBVOL_QGROUP_INHERIT (1ULL << 2) 5155e301fdSFilipe Brandenburger 52735654eaSDavid Sterba #define BTRFS_DEVICE_SPEC_BY_ID (1ULL << 3) 53735654eaSDavid Sterba 54949964c9SMarcos Paulo de Souza #define BTRFS_SUBVOL_SPEC_BY_ID (1ULL << 4) 55949964c9SMarcos Paulo de Souza 56735654eaSDavid Sterba #define BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED \ 579c1036fdSNikolay Borisov (BTRFS_SUBVOL_RDONLY | \ 586b526ed7SAnand Jain BTRFS_SUBVOL_QGROUP_INHERIT | \ 59949964c9SMarcos Paulo de Souza BTRFS_DEVICE_SPEC_BY_ID | \ 60949964c9SMarcos Paulo de Souza BTRFS_SUBVOL_SPEC_BY_ID) 616b526ed7SAnand Jain 6255e301fdSFilipe Brandenburger #define BTRFS_FSID_SIZE 16 6355e301fdSFilipe Brandenburger #define BTRFS_UUID_SIZE 16 64b2373f25SAnand Jain #define BTRFS_UUID_UNPARSED_SIZE 37 6555e301fdSFilipe Brandenburger 6683288b60SJeff Mahoney /* 6783288b60SJeff Mahoney * flags definition for qgroup limits 6883288b60SJeff Mahoney * 6983288b60SJeff Mahoney * Used by: 7083288b60SJeff Mahoney * struct btrfs_qgroup_limit.flags 7183288b60SJeff Mahoney * struct btrfs_qgroup_limit_item.flags 7283288b60SJeff Mahoney */ 7383288b60SJeff Mahoney #define BTRFS_QGROUP_LIMIT_MAX_RFER (1ULL << 0) 7483288b60SJeff Mahoney #define BTRFS_QGROUP_LIMIT_MAX_EXCL (1ULL << 1) 7583288b60SJeff Mahoney #define BTRFS_QGROUP_LIMIT_RSV_RFER (1ULL << 2) 7683288b60SJeff Mahoney #define BTRFS_QGROUP_LIMIT_RSV_EXCL (1ULL << 3) 7783288b60SJeff Mahoney #define BTRFS_QGROUP_LIMIT_RFER_CMPR (1ULL << 4) 7883288b60SJeff Mahoney #define BTRFS_QGROUP_LIMIT_EXCL_CMPR (1ULL << 5) 7955e301fdSFilipe Brandenburger 8055e301fdSFilipe Brandenburger struct btrfs_qgroup_limit { 8155e301fdSFilipe Brandenburger __u64 flags; 8255e301fdSFilipe Brandenburger __u64 max_rfer; 8355e301fdSFilipe Brandenburger __u64 max_excl; 8455e301fdSFilipe Brandenburger __u64 rsv_rfer; 8555e301fdSFilipe Brandenburger __u64 rsv_excl; 8655e301fdSFilipe Brandenburger }; 8755e301fdSFilipe Brandenburger 8883288b60SJeff Mahoney /* 8983288b60SJeff Mahoney * flags definition for qgroup inheritance 9083288b60SJeff Mahoney * 9183288b60SJeff Mahoney * Used by: 9283288b60SJeff Mahoney * struct btrfs_qgroup_inherit.flags 9383288b60SJeff Mahoney */ 9483288b60SJeff Mahoney #define BTRFS_QGROUP_INHERIT_SET_LIMITS (1ULL << 0) 9586211eeaSQu Wenruo #define BTRFS_QGROUP_INHERIT_FLAGS_SUPP (BTRFS_QGROUP_INHERIT_SET_LIMITS) 9683288b60SJeff Mahoney 9755e301fdSFilipe Brandenburger struct btrfs_qgroup_inherit { 9855e301fdSFilipe Brandenburger __u64 flags; 9955e301fdSFilipe Brandenburger __u64 num_qgroups; 10055e301fdSFilipe Brandenburger __u64 num_ref_copies; 10155e301fdSFilipe Brandenburger __u64 num_excl_copies; 10255e301fdSFilipe Brandenburger struct btrfs_qgroup_limit lim; 10394dfc73eSGustavo A. R. Silva __u64 qgroups[]; 10455e301fdSFilipe Brandenburger }; 10555e301fdSFilipe Brandenburger 10655e301fdSFilipe Brandenburger struct btrfs_ioctl_qgroup_limit_args { 10755e301fdSFilipe Brandenburger __u64 qgroupid; 10855e301fdSFilipe Brandenburger struct btrfs_qgroup_limit lim; 10955e301fdSFilipe Brandenburger }; 11055e301fdSFilipe Brandenburger 111884f6ecaSJeff Mahoney /* 112eed02690SDavid Sterba * Arguments for specification of subvolumes or devices, supporting by-name or 113eed02690SDavid Sterba * by-id and flags 114884f6ecaSJeff Mahoney * 115eed02690SDavid Sterba * The set of supported flags depends on the ioctl 116884f6ecaSJeff Mahoney * 117884f6ecaSJeff Mahoney * BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls: 118884f6ecaSJeff Mahoney * - BTRFS_IOC_SUBVOL_GETFLAGS 119884f6ecaSJeff Mahoney * - BTRFS_IOC_SUBVOL_SETFLAGS 120884f6ecaSJeff Mahoney */ 121884f6ecaSJeff Mahoney 122eed02690SDavid Sterba /* Supported flags for BTRFS_IOC_RM_DEV_V2 */ 123eed02690SDavid Sterba #define BTRFS_DEVICE_REMOVE_ARGS_MASK \ 124eed02690SDavid Sterba (BTRFS_DEVICE_SPEC_BY_ID) 125eed02690SDavid Sterba 126eed02690SDavid Sterba /* Supported flags for BTRFS_IOC_SNAP_CREATE_V2 and BTRFS_IOC_SUBVOL_CREATE_V2 */ 127eed02690SDavid Sterba #define BTRFS_SUBVOL_CREATE_ARGS_MASK \ 1289c1036fdSNikolay Borisov (BTRFS_SUBVOL_RDONLY | \ 129eed02690SDavid Sterba BTRFS_SUBVOL_QGROUP_INHERIT) 130eed02690SDavid Sterba 131949964c9SMarcos Paulo de Souza /* Supported flags for BTRFS_IOC_SNAP_DESTROY_V2 */ 132949964c9SMarcos Paulo de Souza #define BTRFS_SUBVOL_DELETE_ARGS_MASK \ 133949964c9SMarcos Paulo de Souza (BTRFS_SUBVOL_SPEC_BY_ID) 134949964c9SMarcos Paulo de Souza 13555e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args_v2 { 13655e301fdSFilipe Brandenburger __s64 fd; 13755e301fdSFilipe Brandenburger __u64 transid; 13855e301fdSFilipe Brandenburger __u64 flags; 13955e301fdSFilipe Brandenburger union { 14055e301fdSFilipe Brandenburger struct { 14155e301fdSFilipe Brandenburger __u64 size; 14255e301fdSFilipe Brandenburger struct btrfs_qgroup_inherit __user *qgroup_inherit; 14355e301fdSFilipe Brandenburger }; 14455e301fdSFilipe Brandenburger __u64 unused[4]; 14555e301fdSFilipe Brandenburger }; 1466b526ed7SAnand Jain union { 14755e301fdSFilipe Brandenburger char name[BTRFS_SUBVOL_NAME_MAX + 1]; 1481691cf16SVinson Lee __u64 devid; 149949964c9SMarcos Paulo de Souza __u64 subvolid; 1506b526ed7SAnand Jain }; 15155e301fdSFilipe Brandenburger }; 15255e301fdSFilipe Brandenburger 15355e301fdSFilipe Brandenburger /* 15455e301fdSFilipe Brandenburger * structure to report errors and progress to userspace, either as a 15555e301fdSFilipe Brandenburger * result of a finished scrub, a canceled scrub or a progress inquiry 15655e301fdSFilipe Brandenburger */ 15755e301fdSFilipe Brandenburger struct btrfs_scrub_progress { 15855e301fdSFilipe Brandenburger __u64 data_extents_scrubbed; /* # of data extents scrubbed */ 15955e301fdSFilipe Brandenburger __u64 tree_extents_scrubbed; /* # of tree extents scrubbed */ 16055e301fdSFilipe Brandenburger __u64 data_bytes_scrubbed; /* # of data bytes scrubbed */ 16155e301fdSFilipe Brandenburger __u64 tree_bytes_scrubbed; /* # of tree bytes scrubbed */ 16255e301fdSFilipe Brandenburger __u64 read_errors; /* # of read errors encountered (EIO) */ 16355e301fdSFilipe Brandenburger __u64 csum_errors; /* # of failed csum checks */ 1641a9fd417SDavid Sterba __u64 verify_errors; /* # of occurrences, where the metadata 16555e301fdSFilipe Brandenburger * of a tree block did not match the 16655e301fdSFilipe Brandenburger * expected values, like generation or 16755e301fdSFilipe Brandenburger * logical */ 16855e301fdSFilipe Brandenburger __u64 no_csum; /* # of 4k data block for which no csum 16955e301fdSFilipe Brandenburger * is present, probably the result of 17055e301fdSFilipe Brandenburger * data written with nodatasum */ 17155e301fdSFilipe Brandenburger __u64 csum_discards; /* # of csum for which no data was found 17255e301fdSFilipe Brandenburger * in the extent tree. */ 17355e301fdSFilipe Brandenburger __u64 super_errors; /* # of bad super blocks encountered */ 17455e301fdSFilipe Brandenburger __u64 malloc_errors; /* # of internal kmalloc errors. These 17555e301fdSFilipe Brandenburger * will likely cause an incomplete 17655e301fdSFilipe Brandenburger * scrub */ 17755e301fdSFilipe Brandenburger __u64 uncorrectable_errors; /* # of errors where either no intact 17855e301fdSFilipe Brandenburger * copy was found or the writeback 17955e301fdSFilipe Brandenburger * failed */ 18055e301fdSFilipe Brandenburger __u64 corrected_errors; /* # of errors corrected */ 18155e301fdSFilipe Brandenburger __u64 last_physical; /* last physical address scrubbed. In 18255e301fdSFilipe Brandenburger * case a scrub was aborted, this can 18355e301fdSFilipe Brandenburger * be used to restart the scrub */ 1841a9fd417SDavid Sterba __u64 unverified_errors; /* # of occurrences where a read for a 18555e301fdSFilipe Brandenburger * full (64k) bio failed, but the re- 18655e301fdSFilipe Brandenburger * check succeeded for each 4k piece. 18755e301fdSFilipe Brandenburger * Intermittent error. */ 18855e301fdSFilipe Brandenburger }; 18955e301fdSFilipe Brandenburger 19055e301fdSFilipe Brandenburger #define BTRFS_SCRUB_READONLY 1 191604e6681SQu Wenruo #define BTRFS_SCRUB_SUPPORTED_FLAGS (BTRFS_SCRUB_READONLY) 19255e301fdSFilipe Brandenburger struct btrfs_ioctl_scrub_args { 19355e301fdSFilipe Brandenburger __u64 devid; /* in */ 19455e301fdSFilipe Brandenburger __u64 start; /* in */ 19555e301fdSFilipe Brandenburger __u64 end; /* in */ 19655e301fdSFilipe Brandenburger __u64 flags; /* in */ 19755e301fdSFilipe Brandenburger struct btrfs_scrub_progress progress; /* out */ 19855e301fdSFilipe Brandenburger /* pad to 1k */ 19955e301fdSFilipe Brandenburger __u64 unused[(1024-32-sizeof(struct btrfs_scrub_progress))/8]; 20055e301fdSFilipe Brandenburger }; 20155e301fdSFilipe Brandenburger 20255e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS 0 20355e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID 1 20455e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_replace_start_params { 20555e301fdSFilipe Brandenburger __u64 srcdevid; /* in, if 0, use srcdev_name instead */ 20655e301fdSFilipe Brandenburger __u64 cont_reading_from_srcdev_mode; /* in, see #define 20755e301fdSFilipe Brandenburger * above */ 20855e301fdSFilipe Brandenburger __u8 srcdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1]; /* in */ 20955e301fdSFilipe Brandenburger __u8 tgtdev_name[BTRFS_DEVICE_PATH_NAME_MAX + 1]; /* in */ 21055e301fdSFilipe Brandenburger }; 21155e301fdSFilipe Brandenburger 21255e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_STATE_NEVER_STARTED 0 21355e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_STATE_STARTED 1 21455e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_STATE_FINISHED 2 21555e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_STATE_CANCELED 3 21655e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_STATE_SUSPENDED 4 21755e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_replace_status_params { 21855e301fdSFilipe Brandenburger __u64 replace_state; /* out, see #define above */ 21955e301fdSFilipe Brandenburger __u64 progress_1000; /* out, 0 <= x <= 1000 */ 22055e301fdSFilipe Brandenburger __u64 time_started; /* out, seconds since 1-Jan-1970 */ 22155e301fdSFilipe Brandenburger __u64 time_stopped; /* out, seconds since 1-Jan-1970 */ 22255e301fdSFilipe Brandenburger __u64 num_write_errors; /* out */ 22355e301fdSFilipe Brandenburger __u64 num_uncorrectable_read_errors; /* out */ 22455e301fdSFilipe Brandenburger }; 22555e301fdSFilipe Brandenburger 22655e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_CMD_START 0 22755e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_CMD_STATUS 1 22855e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_CMD_CANCEL 2 22955e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_RESULT_NO_ERROR 0 23055e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_RESULT_NOT_STARTED 1 23155e301fdSFilipe Brandenburger #define BTRFS_IOCTL_DEV_REPLACE_RESULT_ALREADY_STARTED 2 2322fc9f6baSEryu Guan #define BTRFS_IOCTL_DEV_REPLACE_RESULT_SCRUB_INPROGRESS 3 23355e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_replace_args { 23455e301fdSFilipe Brandenburger __u64 cmd; /* in */ 23555e301fdSFilipe Brandenburger __u64 result; /* out */ 23655e301fdSFilipe Brandenburger 23755e301fdSFilipe Brandenburger union { 23855e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_replace_start_params start; 23955e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_replace_status_params status; 24055e301fdSFilipe Brandenburger }; /* in/out */ 24155e301fdSFilipe Brandenburger 24255e301fdSFilipe Brandenburger __u64 spare[64]; 24355e301fdSFilipe Brandenburger }; 24455e301fdSFilipe Brandenburger 24555e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_info_args { 24655e301fdSFilipe Brandenburger __u64 devid; /* in/out */ 24755e301fdSFilipe Brandenburger __u8 uuid[BTRFS_UUID_SIZE]; /* in/out */ 24855e301fdSFilipe Brandenburger __u64 bytes_used; /* out */ 24955e301fdSFilipe Brandenburger __u64 total_bytes; /* out */ 2502943868aSQu Wenruo /* 2512943868aSQu Wenruo * Optional, out. 2522943868aSQu Wenruo * 2532943868aSQu Wenruo * Showing the fsid of the device, allowing user space to check if this 2542943868aSQu Wenruo * device is a seeding one. 2552943868aSQu Wenruo * 2562943868aSQu Wenruo * Introduced in v6.3, thus user space still needs to check if kernel 2572943868aSQu Wenruo * changed this value. Older kernel will not touch the values here. 2582943868aSQu Wenruo */ 2592943868aSQu Wenruo __u8 fsid[BTRFS_UUID_SIZE]; 2602943868aSQu Wenruo __u64 unused[377]; /* pad to 4k */ 26155e301fdSFilipe Brandenburger __u8 path[BTRFS_DEVICE_PATH_NAME_MAX]; /* out */ 26255e301fdSFilipe Brandenburger }; 26355e301fdSFilipe Brandenburger 264137c5418SJohannes Thumshirn /* 265137c5418SJohannes Thumshirn * Retrieve information about the filesystem 266137c5418SJohannes Thumshirn */ 267137c5418SJohannes Thumshirn 268137c5418SJohannes Thumshirn /* Request information about checksum type and size */ 269137c5418SJohannes Thumshirn #define BTRFS_FS_INFO_FLAG_CSUM_INFO (1 << 0) 270137c5418SJohannes Thumshirn 2710fb408a5SJohannes Thumshirn /* Request information about filesystem generation */ 2720fb408a5SJohannes Thumshirn #define BTRFS_FS_INFO_FLAG_GENERATION (1 << 1) 27349bac897SJohannes Thumshirn /* Request information about filesystem metadata UUID */ 27449bac897SJohannes Thumshirn #define BTRFS_FS_INFO_FLAG_METADATA_UUID (1 << 2) 2750fb408a5SJohannes Thumshirn 27655e301fdSFilipe Brandenburger struct btrfs_ioctl_fs_info_args { 27755e301fdSFilipe Brandenburger __u64 max_id; /* out */ 27855e301fdSFilipe Brandenburger __u64 num_devices; /* out */ 27955e301fdSFilipe Brandenburger __u8 fsid[BTRFS_FSID_SIZE]; /* out */ 28080a773fbSDavid Sterba __u32 nodesize; /* out */ 28180a773fbSDavid Sterba __u32 sectorsize; /* out */ 28280a773fbSDavid Sterba __u32 clone_alignment; /* out */ 283137c5418SJohannes Thumshirn /* See BTRFS_FS_INFO_FLAG_* */ 284137c5418SJohannes Thumshirn __u16 csum_type; /* out */ 285137c5418SJohannes Thumshirn __u16 csum_size; /* out */ 286137c5418SJohannes Thumshirn __u64 flags; /* in/out */ 2870fb408a5SJohannes Thumshirn __u64 generation; /* out */ 28849bac897SJohannes Thumshirn __u8 metadata_uuid[BTRFS_FSID_SIZE]; /* out */ 28949bac897SJohannes Thumshirn __u8 reserved[944]; /* pad to 1k */ 29055e301fdSFilipe Brandenburger }; 29155e301fdSFilipe Brandenburger 29218db9ac6SJeff Mahoney /* 29318db9ac6SJeff Mahoney * feature flags 29418db9ac6SJeff Mahoney * 29518db9ac6SJeff Mahoney * Used by: 29618db9ac6SJeff Mahoney * struct btrfs_ioctl_feature_flags 29718db9ac6SJeff Mahoney */ 29818db9ac6SJeff Mahoney #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE (1ULL << 0) 2996675df31SOmar Sandoval /* 3006675df31SOmar Sandoval * Older kernels (< 4.9) on big-endian systems produced broken free space tree 3016675df31SOmar Sandoval * bitmaps, and btrfs-progs also used to corrupt the free space tree (versions 3026675df31SOmar Sandoval * < 4.7.3). If this bit is clear, then the free space tree cannot be trusted. 3036675df31SOmar Sandoval * btrfs-progs can also intentionally clear this bit to ask the kernel to 3046675df31SOmar Sandoval * rebuild the free space tree, however this might not work on older kernels 3056675df31SOmar Sandoval * that do not know about this bit. If not sure, clear the cache manually on 3066675df31SOmar Sandoval * first mount when booting older kernel versions. 3076675df31SOmar Sandoval */ 3086675df31SOmar Sandoval #define BTRFS_FEATURE_COMPAT_RO_FREE_SPACE_TREE_VALID (1ULL << 1) 30914605409SBoris Burkov #define BTRFS_FEATURE_COMPAT_RO_VERITY (1ULL << 2) 31018db9ac6SJeff Mahoney 3111c56ab99SQu Wenruo /* 3121c56ab99SQu Wenruo * Put all block group items into a dedicated block group tree, greatly 3131c56ab99SQu Wenruo * reducing mount time for large filesystem due to better locality. 3141c56ab99SQu Wenruo */ 3151c56ab99SQu Wenruo #define BTRFS_FEATURE_COMPAT_RO_BLOCK_GROUP_TREE (1ULL << 3) 3161c56ab99SQu Wenruo 31718db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) 31818db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (1ULL << 1) 31918db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS (1ULL << 2) 32018db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_COMPRESS_LZO (1ULL << 3) 3215c1aab1dSNick Terrell #define BTRFS_FEATURE_INCOMPAT_COMPRESS_ZSTD (1ULL << 4) 32218db9ac6SJeff Mahoney 32318db9ac6SJeff Mahoney /* 32418db9ac6SJeff Mahoney * older kernels tried to do bigger metadata blocks, but the 32518db9ac6SJeff Mahoney * code was pretty buggy. Lets not let them try anymore. 32618db9ac6SJeff Mahoney */ 32718db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_BIG_METADATA (1ULL << 5) 32818db9ac6SJeff Mahoney 32918db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_EXTENDED_IREF (1ULL << 6) 33018db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_RAID56 (1ULL << 7) 33118db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_SKINNY_METADATA (1ULL << 8) 33218db9ac6SJeff Mahoney #define BTRFS_FEATURE_INCOMPAT_NO_HOLES (1ULL << 9) 3337239ff4bSNikolay Borisov #define BTRFS_FEATURE_INCOMPAT_METADATA_UUID (1ULL << 10) 334cfbb825cSDavid Sterba #define BTRFS_FEATURE_INCOMPAT_RAID1C34 (1ULL << 11) 3357b3d5a90SNaohiro Aota #define BTRFS_FEATURE_INCOMPAT_ZONED (1ULL << 12) 3362c7d2a23SJosef Bacik #define BTRFS_FEATURE_INCOMPAT_EXTENT_TREE_V2 (1ULL << 13) 33751502090SJohannes Thumshirn #define BTRFS_FEATURE_INCOMPAT_RAID_STRIPE_TREE (1ULL << 14) 338182940f4SBoris Burkov #define BTRFS_FEATURE_INCOMPAT_SIMPLE_QUOTA (1ULL << 16) 33918db9ac6SJeff Mahoney 3402eaa055fSJeff Mahoney struct btrfs_ioctl_feature_flags { 3412eaa055fSJeff Mahoney __u64 compat_flags; 3422eaa055fSJeff Mahoney __u64 compat_ro_flags; 3432eaa055fSJeff Mahoney __u64 incompat_flags; 3442eaa055fSJeff Mahoney }; 3452eaa055fSJeff Mahoney 34655e301fdSFilipe Brandenburger /* balance control ioctl modes */ 34755e301fdSFilipe Brandenburger #define BTRFS_BALANCE_CTL_PAUSE 1 34855e301fdSFilipe Brandenburger #define BTRFS_BALANCE_CTL_CANCEL 2 34955e301fdSFilipe Brandenburger 35055e301fdSFilipe Brandenburger /* 35155e301fdSFilipe Brandenburger * this is packed, because it should be exactly the same as its disk 35255e301fdSFilipe Brandenburger * byte order counterpart (struct btrfs_disk_balance_args) 35355e301fdSFilipe Brandenburger */ 35455e301fdSFilipe Brandenburger struct btrfs_balance_args { 35555e301fdSFilipe Brandenburger __u64 profiles; 356a2813530SJosef Bacik 357a2813530SJosef Bacik /* 358a2813530SJosef Bacik * usage filter 359a2813530SJosef Bacik * BTRFS_BALANCE_ARGS_USAGE with a single value means '0..N' 360a2813530SJosef Bacik * BTRFS_BALANCE_ARGS_USAGE_RANGE - range syntax, min..max 361a2813530SJosef Bacik */ 362bc309467SDavid Sterba union { 363261cc2ccSHans van Kranenburg __u64 usage; 364bc309467SDavid Sterba struct { 365261cc2ccSHans van Kranenburg __u32 usage_min; 366261cc2ccSHans van Kranenburg __u32 usage_max; 367bc309467SDavid Sterba }; 368bc309467SDavid Sterba }; 36955e301fdSFilipe Brandenburger __u64 devid; 37055e301fdSFilipe Brandenburger __u64 pstart; 37155e301fdSFilipe Brandenburger __u64 pend; 37255e301fdSFilipe Brandenburger __u64 vstart; 37355e301fdSFilipe Brandenburger __u64 vend; 37455e301fdSFilipe Brandenburger 37555e301fdSFilipe Brandenburger __u64 target; 37655e301fdSFilipe Brandenburger 37755e301fdSFilipe Brandenburger __u64 flags; 37855e301fdSFilipe Brandenburger 37912907fc7SDavid Sterba /* 38012907fc7SDavid Sterba * BTRFS_BALANCE_ARGS_LIMIT with value 'limit' 38112907fc7SDavid Sterba * BTRFS_BALANCE_ARGS_LIMIT_RANGE - the extend version can use minimum 38212907fc7SDavid Sterba * and maximum 38312907fc7SDavid Sterba */ 38412907fc7SDavid Sterba union { 3857d824b6fSDavid Sterba __u64 limit; /* limit number of processed chunks */ 38612907fc7SDavid Sterba struct { 38712907fc7SDavid Sterba __u32 limit_min; 38812907fc7SDavid Sterba __u32 limit_max; 38912907fc7SDavid Sterba }; 39012907fc7SDavid Sterba }; 391dee32d0aSGabríel Arthúr Pétursson 392dee32d0aSGabríel Arthúr Pétursson /* 393dee32d0aSGabríel Arthúr Pétursson * Process chunks that cross stripes_min..stripes_max devices, 394dee32d0aSGabríel Arthúr Pétursson * BTRFS_BALANCE_ARGS_STRIPES_RANGE 395dee32d0aSGabríel Arthúr Pétursson */ 396261cc2ccSHans van Kranenburg __u32 stripes_min; 397261cc2ccSHans van Kranenburg __u32 stripes_max; 398dee32d0aSGabríel Arthúr Pétursson 399dee32d0aSGabríel Arthúr Pétursson __u64 unused[6]; 40055e301fdSFilipe Brandenburger } __attribute__ ((__packed__)); 40155e301fdSFilipe Brandenburger 40255e301fdSFilipe Brandenburger /* report balance progress to userspace */ 40355e301fdSFilipe Brandenburger struct btrfs_balance_progress { 40455e301fdSFilipe Brandenburger __u64 expected; /* estimated # of chunks that will be 40555e301fdSFilipe Brandenburger * relocated to fulfill the request */ 40655e301fdSFilipe Brandenburger __u64 considered; /* # of chunks we have considered so far */ 40755e301fdSFilipe Brandenburger __u64 completed; /* # of chunks relocated so far */ 40855e301fdSFilipe Brandenburger }; 40955e301fdSFilipe Brandenburger 41004cd01dfSJeff Mahoney /* 41104cd01dfSJeff Mahoney * flags definition for balance 41204cd01dfSJeff Mahoney * 41304cd01dfSJeff Mahoney * Restriper's general type filter 41404cd01dfSJeff Mahoney * 41504cd01dfSJeff Mahoney * Used by: 41604cd01dfSJeff Mahoney * btrfs_ioctl_balance_args.flags 41704cd01dfSJeff Mahoney * btrfs_balance_control.flags (internal) 41804cd01dfSJeff Mahoney */ 41904cd01dfSJeff Mahoney #define BTRFS_BALANCE_DATA (1ULL << 0) 42004cd01dfSJeff Mahoney #define BTRFS_BALANCE_SYSTEM (1ULL << 1) 42104cd01dfSJeff Mahoney #define BTRFS_BALANCE_METADATA (1ULL << 2) 42204cd01dfSJeff Mahoney 42304cd01dfSJeff Mahoney #define BTRFS_BALANCE_TYPE_MASK (BTRFS_BALANCE_DATA | \ 42404cd01dfSJeff Mahoney BTRFS_BALANCE_SYSTEM | \ 42504cd01dfSJeff Mahoney BTRFS_BALANCE_METADATA) 42604cd01dfSJeff Mahoney 42704cd01dfSJeff Mahoney #define BTRFS_BALANCE_FORCE (1ULL << 3) 42804cd01dfSJeff Mahoney #define BTRFS_BALANCE_RESUME (1ULL << 4) 42904cd01dfSJeff Mahoney 43004cd01dfSJeff Mahoney /* 43104cd01dfSJeff Mahoney * flags definitions for per-type balance args 43204cd01dfSJeff Mahoney * 43304cd01dfSJeff Mahoney * Balance filters 43404cd01dfSJeff Mahoney * 43504cd01dfSJeff Mahoney * Used by: 43604cd01dfSJeff Mahoney * struct btrfs_balance_args 43704cd01dfSJeff Mahoney */ 43804cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_PROFILES (1ULL << 0) 43904cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_USAGE (1ULL << 1) 44004cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_DEVID (1ULL << 2) 44104cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_DRANGE (1ULL << 3) 44204cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_VRANGE (1ULL << 4) 44304cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_LIMIT (1ULL << 5) 44404cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_LIMIT_RANGE (1ULL << 6) 44504cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_STRIPES_RANGE (1ULL << 7) 44604cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_USAGE_RANGE (1ULL << 10) 44704cd01dfSJeff Mahoney 44804cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_MASK \ 44904cd01dfSJeff Mahoney (BTRFS_BALANCE_ARGS_PROFILES | \ 45004cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_USAGE | \ 45104cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_DEVID | \ 45204cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_DRANGE | \ 45304cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_VRANGE | \ 45404cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_LIMIT | \ 45504cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_LIMIT_RANGE | \ 45604cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_STRIPES_RANGE | \ 45704cd01dfSJeff Mahoney BTRFS_BALANCE_ARGS_USAGE_RANGE) 45804cd01dfSJeff Mahoney 45904cd01dfSJeff Mahoney /* 46004cd01dfSJeff Mahoney * Profile changing flags. When SOFT is set we won't relocate chunk if 46104cd01dfSJeff Mahoney * it already has the target profile (even though it may be 46204cd01dfSJeff Mahoney * half-filled). 46304cd01dfSJeff Mahoney */ 46404cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_CONVERT (1ULL << 8) 46504cd01dfSJeff Mahoney #define BTRFS_BALANCE_ARGS_SOFT (1ULL << 9) 46604cd01dfSJeff Mahoney 46704cd01dfSJeff Mahoney 46804cd01dfSJeff Mahoney /* 46904cd01dfSJeff Mahoney * flags definition for balance state 47004cd01dfSJeff Mahoney * 47104cd01dfSJeff Mahoney * Used by: 47204cd01dfSJeff Mahoney * struct btrfs_ioctl_balance_args.state 47304cd01dfSJeff Mahoney */ 47455e301fdSFilipe Brandenburger #define BTRFS_BALANCE_STATE_RUNNING (1ULL << 0) 47555e301fdSFilipe Brandenburger #define BTRFS_BALANCE_STATE_PAUSE_REQ (1ULL << 1) 47655e301fdSFilipe Brandenburger #define BTRFS_BALANCE_STATE_CANCEL_REQ (1ULL << 2) 47755e301fdSFilipe Brandenburger 47855e301fdSFilipe Brandenburger struct btrfs_ioctl_balance_args { 47955e301fdSFilipe Brandenburger __u64 flags; /* in/out */ 48055e301fdSFilipe Brandenburger __u64 state; /* out */ 48155e301fdSFilipe Brandenburger 48255e301fdSFilipe Brandenburger struct btrfs_balance_args data; /* in/out */ 48355e301fdSFilipe Brandenburger struct btrfs_balance_args meta; /* in/out */ 48455e301fdSFilipe Brandenburger struct btrfs_balance_args sys; /* in/out */ 48555e301fdSFilipe Brandenburger 48655e301fdSFilipe Brandenburger struct btrfs_balance_progress stat; /* out */ 48755e301fdSFilipe Brandenburger 48855e301fdSFilipe Brandenburger __u64 unused[72]; /* pad to 1k */ 48955e301fdSFilipe Brandenburger }; 49055e301fdSFilipe Brandenburger 49155e301fdSFilipe Brandenburger #define BTRFS_INO_LOOKUP_PATH_MAX 4080 49255e301fdSFilipe Brandenburger struct btrfs_ioctl_ino_lookup_args { 49355e301fdSFilipe Brandenburger __u64 treeid; 49455e301fdSFilipe Brandenburger __u64 objectid; 49555e301fdSFilipe Brandenburger char name[BTRFS_INO_LOOKUP_PATH_MAX]; 49655e301fdSFilipe Brandenburger }; 49755e301fdSFilipe Brandenburger 49823d0b79dSTomohiro Misono #define BTRFS_INO_LOOKUP_USER_PATH_MAX (4080 - BTRFS_VOL_NAME_MAX - 1) 49923d0b79dSTomohiro Misono struct btrfs_ioctl_ino_lookup_user_args { 50023d0b79dSTomohiro Misono /* in, inode number containing the subvolume of 'subvolid' */ 50123d0b79dSTomohiro Misono __u64 dirid; 50223d0b79dSTomohiro Misono /* in */ 50323d0b79dSTomohiro Misono __u64 treeid; 50423d0b79dSTomohiro Misono /* out, name of the subvolume of 'treeid' */ 50523d0b79dSTomohiro Misono char name[BTRFS_VOL_NAME_MAX + 1]; 50623d0b79dSTomohiro Misono /* 50723d0b79dSTomohiro Misono * out, constructed path from the directory with which the ioctl is 50823d0b79dSTomohiro Misono * called to dirid 50923d0b79dSTomohiro Misono */ 51023d0b79dSTomohiro Misono char path[BTRFS_INO_LOOKUP_USER_PATH_MAX]; 51123d0b79dSTomohiro Misono }; 51223d0b79dSTomohiro Misono 5131a63143dSHans van Kranenburg /* Search criteria for the btrfs SEARCH ioctl family. */ 51455e301fdSFilipe Brandenburger struct btrfs_ioctl_search_key { 5151a63143dSHans van Kranenburg /* 5161a63143dSHans van Kranenburg * The tree we're searching in. 1 is the tree of tree roots, 2 is the 5171a63143dSHans van Kranenburg * extent tree, etc... 5181a63143dSHans van Kranenburg * 5191a63143dSHans van Kranenburg * A special tree_id value of 0 will cause a search in the subvolume 5201a63143dSHans van Kranenburg * tree that the inode which is passed to the ioctl is part of. 5211a63143dSHans van Kranenburg */ 5221a63143dSHans van Kranenburg __u64 tree_id; /* in */ 52355e301fdSFilipe Brandenburger 52455e301fdSFilipe Brandenburger /* 5251a63143dSHans van Kranenburg * When doing a tree search, we're actually taking a slice from a 5261a63143dSHans van Kranenburg * linear search space of 136-bit keys. 5271a63143dSHans van Kranenburg * 5281a63143dSHans van Kranenburg * A full 136-bit tree key is composed as: 5291a63143dSHans van Kranenburg * (objectid << 72) + (type << 64) + offset 5301a63143dSHans van Kranenburg * 5311a63143dSHans van Kranenburg * The individual min and max values for objectid, type and offset 5321a63143dSHans van Kranenburg * define the min_key and max_key values for the search range. All 5331a63143dSHans van Kranenburg * metadata items with a key in the interval [min_key, max_key] will be 5341a63143dSHans van Kranenburg * returned. 5351a63143dSHans van Kranenburg * 5361a63143dSHans van Kranenburg * Additionally, we can filter the items returned on transaction id of 5371a63143dSHans van Kranenburg * the metadata block they're stored in by specifying a transid range. 5381a63143dSHans van Kranenburg * Be aware that this transaction id only denotes when the metadata 5391a63143dSHans van Kranenburg * page that currently contains the item got written the last time as 5401a63143dSHans van Kranenburg * result of a COW operation. The number does not have any meaning 5411a63143dSHans van Kranenburg * related to the transaction in which an individual item that is being 5421a63143dSHans van Kranenburg * returned was created or changed. 54355e301fdSFilipe Brandenburger */ 5441a63143dSHans van Kranenburg __u64 min_objectid; /* in */ 5451a63143dSHans van Kranenburg __u64 max_objectid; /* in */ 5461a63143dSHans van Kranenburg __u64 min_offset; /* in */ 5471a63143dSHans van Kranenburg __u64 max_offset; /* in */ 5481a63143dSHans van Kranenburg __u64 min_transid; /* in */ 5491a63143dSHans van Kranenburg __u64 max_transid; /* in */ 5501a63143dSHans van Kranenburg __u32 min_type; /* in */ 5511a63143dSHans van Kranenburg __u32 max_type; /* in */ 5521a63143dSHans van Kranenburg 5531a63143dSHans van Kranenburg /* 5541a63143dSHans van Kranenburg * input: The maximum amount of results desired. 5551a63143dSHans van Kranenburg * output: The actual amount of items returned, restricted by any of: 5561a63143dSHans van Kranenburg * - reaching the upper bound of the search range 5571a63143dSHans van Kranenburg * - reaching the input nr_items amount of items 5581a63143dSHans van Kranenburg * - completely filling the supplied memory buffer 5591a63143dSHans van Kranenburg */ 5601a63143dSHans van Kranenburg __u32 nr_items; /* in/out */ 56155e301fdSFilipe Brandenburger 56255e301fdSFilipe Brandenburger /* align to 64 bits */ 56355e301fdSFilipe Brandenburger __u32 unused; 56455e301fdSFilipe Brandenburger 56555e301fdSFilipe Brandenburger /* some extra for later */ 56655e301fdSFilipe Brandenburger __u64 unused1; 56755e301fdSFilipe Brandenburger __u64 unused2; 56855e301fdSFilipe Brandenburger __u64 unused3; 56955e301fdSFilipe Brandenburger __u64 unused4; 57055e301fdSFilipe Brandenburger }; 57155e301fdSFilipe Brandenburger 57255e301fdSFilipe Brandenburger struct btrfs_ioctl_search_header { 57355e301fdSFilipe Brandenburger __u64 transid; 57455e301fdSFilipe Brandenburger __u64 objectid; 57555e301fdSFilipe Brandenburger __u64 offset; 57655e301fdSFilipe Brandenburger __u32 type; 57755e301fdSFilipe Brandenburger __u32 len; 578a2813530SJosef Bacik } __attribute__ ((__may_alias__)); 57955e301fdSFilipe Brandenburger 58055e301fdSFilipe Brandenburger #define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) 58155e301fdSFilipe Brandenburger /* 58255e301fdSFilipe Brandenburger * the buf is an array of search headers where 58355e301fdSFilipe Brandenburger * each header is followed by the actual item 58455e301fdSFilipe Brandenburger * the type field is expanded to 32 bits for alignment 58555e301fdSFilipe Brandenburger */ 58655e301fdSFilipe Brandenburger struct btrfs_ioctl_search_args { 58755e301fdSFilipe Brandenburger struct btrfs_ioctl_search_key key; 58855e301fdSFilipe Brandenburger char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; 58955e301fdSFilipe Brandenburger }; 59055e301fdSFilipe Brandenburger 591a2813530SJosef Bacik /* 592a2813530SJosef Bacik * Extended version of TREE_SEARCH ioctl that can return more than 4k of bytes. 593a2813530SJosef Bacik * The allocated size of the buffer is set in buf_size. 594a2813530SJosef Bacik */ 595cc68a8a5SGerhard Heift struct btrfs_ioctl_search_args_v2 { 596cc68a8a5SGerhard Heift struct btrfs_ioctl_search_key key; /* in/out - search parameters */ 597cc68a8a5SGerhard Heift __u64 buf_size; /* in - size of buffer 598cc68a8a5SGerhard Heift * out - on EOVERFLOW: needed size 599cc68a8a5SGerhard Heift * to store item */ 60094dfc73eSGustavo A. R. Silva __u64 buf[]; /* out - found items */ 601cc68a8a5SGerhard Heift }; 602cc68a8a5SGerhard Heift 603a2813530SJosef Bacik /* With a @src_length of zero, the range from @src_offset->EOF is cloned! */ 60455e301fdSFilipe Brandenburger struct btrfs_ioctl_clone_range_args { 60555e301fdSFilipe Brandenburger __s64 src_fd; 60655e301fdSFilipe Brandenburger __u64 src_offset, src_length; 60755e301fdSFilipe Brandenburger __u64 dest_offset; 60855e301fdSFilipe Brandenburger }; 60955e301fdSFilipe Brandenburger 61033ca9133SJeff Mahoney /* 61133ca9133SJeff Mahoney * flags definition for the defrag range ioctl 61233ca9133SJeff Mahoney * 61333ca9133SJeff Mahoney * Used by: 61433ca9133SJeff Mahoney * struct btrfs_ioctl_defrag_range_args.flags 61533ca9133SJeff Mahoney */ 61655e301fdSFilipe Brandenburger #define BTRFS_DEFRAG_RANGE_COMPRESS 1 61755e301fdSFilipe Brandenburger #define BTRFS_DEFRAG_RANGE_START_IO 2 618*fc5c0c58SDaniel Vacek #define BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL 4 619173431b2SQu Wenruo #define BTRFS_DEFRAG_RANGE_FLAGS_SUPP (BTRFS_DEFRAG_RANGE_COMPRESS | \ 620*fc5c0c58SDaniel Vacek BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL | \ 621173431b2SQu Wenruo BTRFS_DEFRAG_RANGE_START_IO) 622173431b2SQu Wenruo 62333ca9133SJeff Mahoney struct btrfs_ioctl_defrag_range_args { 62433ca9133SJeff Mahoney /* start of the defrag operation */ 62533ca9133SJeff Mahoney __u64 start; 62633ca9133SJeff Mahoney 62733ca9133SJeff Mahoney /* number of bytes to defrag, use (u64)-1 to say all */ 62833ca9133SJeff Mahoney __u64 len; 62933ca9133SJeff Mahoney 63033ca9133SJeff Mahoney /* 63133ca9133SJeff Mahoney * flags for the operation, which can include turning 63233ca9133SJeff Mahoney * on compression for this one defrag 63333ca9133SJeff Mahoney */ 63433ca9133SJeff Mahoney __u64 flags; 63533ca9133SJeff Mahoney 63633ca9133SJeff Mahoney /* 63733ca9133SJeff Mahoney * any extent bigger than this will be considered 63833ca9133SJeff Mahoney * already defragged. Use 0 to take the kernel default 63933ca9133SJeff Mahoney * Use 1 to say every single extent must be rewritten 64033ca9133SJeff Mahoney */ 64133ca9133SJeff Mahoney __u32 extent_thresh; 64233ca9133SJeff Mahoney 64333ca9133SJeff Mahoney /* 64433ca9133SJeff Mahoney * which compression method to use if turning on compression 645*fc5c0c58SDaniel Vacek * for this defrag operation. If unspecified, zlib will be 646*fc5c0c58SDaniel Vacek * used. If compression level is also being specified, set the 647*fc5c0c58SDaniel Vacek * BTRFS_DEFRAG_RANGE_COMPRESS_LEVEL flag and fill the compress 648*fc5c0c58SDaniel Vacek * member structure instead of the compress_type field. 64933ca9133SJeff Mahoney */ 650*fc5c0c58SDaniel Vacek union { 65133ca9133SJeff Mahoney __u32 compress_type; 652*fc5c0c58SDaniel Vacek struct { 653*fc5c0c58SDaniel Vacek __u8 type; 654*fc5c0c58SDaniel Vacek __s8 level; 655*fc5c0c58SDaniel Vacek } compress; 656*fc5c0c58SDaniel Vacek }; 65733ca9133SJeff Mahoney 65833ca9133SJeff Mahoney /* spare for later */ 65933ca9133SJeff Mahoney __u32 unused[4]; 66033ca9133SJeff Mahoney }; 66133ca9133SJeff Mahoney 66255e301fdSFilipe Brandenburger 663416161dbSMark Fasheh #define BTRFS_SAME_DATA_DIFFERS 1 664416161dbSMark Fasheh /* For extent-same ioctl */ 665416161dbSMark Fasheh struct btrfs_ioctl_same_extent_info { 666416161dbSMark Fasheh __s64 fd; /* in - destination file */ 667416161dbSMark Fasheh __u64 logical_offset; /* in - start of extent in destination */ 668416161dbSMark Fasheh __u64 bytes_deduped; /* out - total # of bytes we were able 669416161dbSMark Fasheh * to dedupe from this file */ 670416161dbSMark Fasheh /* status of this dedupe operation: 671416161dbSMark Fasheh * 0 if dedup succeeds 672416161dbSMark Fasheh * < 0 for error 673416161dbSMark Fasheh * == BTRFS_SAME_DATA_DIFFERS if data differs 674416161dbSMark Fasheh */ 675416161dbSMark Fasheh __s32 status; /* out - see above description */ 676416161dbSMark Fasheh __u32 reserved; 677416161dbSMark Fasheh }; 678416161dbSMark Fasheh 679416161dbSMark Fasheh struct btrfs_ioctl_same_args { 680416161dbSMark Fasheh __u64 logical_offset; /* in - start of extent in source */ 681416161dbSMark Fasheh __u64 length; /* in - length of extent */ 682416161dbSMark Fasheh __u16 dest_count; /* in - total elements in info array */ 683416161dbSMark Fasheh __u16 reserved1; 684416161dbSMark Fasheh __u32 reserved2; 68594dfc73eSGustavo A. R. Silva struct btrfs_ioctl_same_extent_info info[]; 686416161dbSMark Fasheh }; 687416161dbSMark Fasheh 68855e301fdSFilipe Brandenburger struct btrfs_ioctl_space_info { 68955e301fdSFilipe Brandenburger __u64 flags; 69055e301fdSFilipe Brandenburger __u64 total_bytes; 69155e301fdSFilipe Brandenburger __u64 used_bytes; 69255e301fdSFilipe Brandenburger }; 69355e301fdSFilipe Brandenburger 69455e301fdSFilipe Brandenburger struct btrfs_ioctl_space_args { 69555e301fdSFilipe Brandenburger __u64 space_slots; 69655e301fdSFilipe Brandenburger __u64 total_spaces; 69794dfc73eSGustavo A. R. Silva struct btrfs_ioctl_space_info spaces[]; 69855e301fdSFilipe Brandenburger }; 69955e301fdSFilipe Brandenburger 70055e301fdSFilipe Brandenburger struct btrfs_data_container { 70155e301fdSFilipe Brandenburger __u32 bytes_left; /* out -- bytes not needed to deliver output */ 70255e301fdSFilipe Brandenburger __u32 bytes_missing; /* out -- additional bytes needed for result */ 70355e301fdSFilipe Brandenburger __u32 elem_cnt; /* out */ 70455e301fdSFilipe Brandenburger __u32 elem_missed; /* out */ 70594dfc73eSGustavo A. R. Silva __u64 val[]; /* out */ 70655e301fdSFilipe Brandenburger }; 70755e301fdSFilipe Brandenburger 70855e301fdSFilipe Brandenburger struct btrfs_ioctl_ino_path_args { 70955e301fdSFilipe Brandenburger __u64 inum; /* in */ 71055e301fdSFilipe Brandenburger __u64 size; /* in */ 71155e301fdSFilipe Brandenburger __u64 reserved[4]; 71255e301fdSFilipe Brandenburger /* struct btrfs_data_container *fspath; out */ 71355e301fdSFilipe Brandenburger __u64 fspath; /* out */ 71455e301fdSFilipe Brandenburger }; 71555e301fdSFilipe Brandenburger 71655e301fdSFilipe Brandenburger struct btrfs_ioctl_logical_ino_args { 71755e301fdSFilipe Brandenburger __u64 logical; /* in */ 71855e301fdSFilipe Brandenburger __u64 size; /* in */ 719d24a67b2SZygo Blaxell __u64 reserved[3]; /* must be 0 for now */ 720d24a67b2SZygo Blaxell __u64 flags; /* in, v2 only */ 72155e301fdSFilipe Brandenburger /* struct btrfs_data_container *inodes; out */ 72255e301fdSFilipe Brandenburger __u64 inodes; 72355e301fdSFilipe Brandenburger }; 724a2813530SJosef Bacik 725a2813530SJosef Bacik /* 726a2813530SJosef Bacik * Return every ref to the extent, not just those containing logical block. 727a2813530SJosef Bacik * Requires logical == extent bytenr. 728a2813530SJosef Bacik */ 729d24a67b2SZygo Blaxell #define BTRFS_LOGICAL_INO_ARGS_IGNORE_OFFSET (1ULL << 0) 73055e301fdSFilipe Brandenburger 73155e301fdSFilipe Brandenburger enum btrfs_dev_stat_values { 73255e301fdSFilipe Brandenburger /* disk I/O failure stats */ 73355e301fdSFilipe Brandenburger BTRFS_DEV_STAT_WRITE_ERRS, /* EIO or EREMOTEIO from lower layers */ 73455e301fdSFilipe Brandenburger BTRFS_DEV_STAT_READ_ERRS, /* EIO or EREMOTEIO from lower layers */ 73555e301fdSFilipe Brandenburger BTRFS_DEV_STAT_FLUSH_ERRS, /* EIO or EREMOTEIO from lower layers */ 73655e301fdSFilipe Brandenburger 73755e301fdSFilipe Brandenburger /* stats for indirect indications for I/O failures */ 73855e301fdSFilipe Brandenburger BTRFS_DEV_STAT_CORRUPTION_ERRS, /* checksum error, bytenr error or 73955e301fdSFilipe Brandenburger * contents is illegal: this is an 74055e301fdSFilipe Brandenburger * indication that the block was damaged 74155e301fdSFilipe Brandenburger * during read or write, or written to 74255e301fdSFilipe Brandenburger * wrong location or read from wrong 74355e301fdSFilipe Brandenburger * location */ 74455e301fdSFilipe Brandenburger BTRFS_DEV_STAT_GENERATION_ERRS, /* an indication that blocks have not 74555e301fdSFilipe Brandenburger * been written */ 74655e301fdSFilipe Brandenburger 74755e301fdSFilipe Brandenburger BTRFS_DEV_STAT_VALUES_MAX 74855e301fdSFilipe Brandenburger }; 74955e301fdSFilipe Brandenburger 75055e301fdSFilipe Brandenburger /* Reset statistics after reading; needs SYS_ADMIN capability */ 75155e301fdSFilipe Brandenburger #define BTRFS_DEV_STATS_RESET (1ULL << 0) 75255e301fdSFilipe Brandenburger 75355e301fdSFilipe Brandenburger struct btrfs_ioctl_get_dev_stats { 75455e301fdSFilipe Brandenburger __u64 devid; /* in */ 75555e301fdSFilipe Brandenburger __u64 nr_items; /* in/out */ 75655e301fdSFilipe Brandenburger __u64 flags; /* in/out */ 75755e301fdSFilipe Brandenburger 75855e301fdSFilipe Brandenburger /* out values: */ 75955e301fdSFilipe Brandenburger __u64 values[BTRFS_DEV_STAT_VALUES_MAX]; 76055e301fdSFilipe Brandenburger 76173a3ca20SHans van Kranenburg /* 76273a3ca20SHans van Kranenburg * This pads the struct to 1032 bytes. It was originally meant to pad to 76373a3ca20SHans van Kranenburg * 1024 bytes, but when adding the flags field, the padding calculation 76473a3ca20SHans van Kranenburg * was not adjusted. 76573a3ca20SHans van Kranenburg */ 76673a3ca20SHans van Kranenburg __u64 unused[128 - 2 - BTRFS_DEV_STAT_VALUES_MAX]; 76755e301fdSFilipe Brandenburger }; 76855e301fdSFilipe Brandenburger 76955e301fdSFilipe Brandenburger #define BTRFS_QUOTA_CTL_ENABLE 1 77055e301fdSFilipe Brandenburger #define BTRFS_QUOTA_CTL_DISABLE 2 7712f232036SJan Schmidt #define BTRFS_QUOTA_CTL_RESCAN__NOTUSED 3 772182940f4SBoris Burkov #define BTRFS_QUOTA_CTL_ENABLE_SIMPLE_QUOTA 4 77355e301fdSFilipe Brandenburger struct btrfs_ioctl_quota_ctl_args { 77455e301fdSFilipe Brandenburger __u64 cmd; 77555e301fdSFilipe Brandenburger __u64 status; 77655e301fdSFilipe Brandenburger }; 77755e301fdSFilipe Brandenburger 7782f232036SJan Schmidt struct btrfs_ioctl_quota_rescan_args { 7792f232036SJan Schmidt __u64 flags; 7802f232036SJan Schmidt __u64 progress; 7812f232036SJan Schmidt __u64 reserved[6]; 7822f232036SJan Schmidt }; 7832f232036SJan Schmidt 78455e301fdSFilipe Brandenburger struct btrfs_ioctl_qgroup_assign_args { 78555e301fdSFilipe Brandenburger __u64 assign; 78655e301fdSFilipe Brandenburger __u64 src; 78755e301fdSFilipe Brandenburger __u64 dst; 78855e301fdSFilipe Brandenburger }; 78955e301fdSFilipe Brandenburger 79055e301fdSFilipe Brandenburger struct btrfs_ioctl_qgroup_create_args { 79155e301fdSFilipe Brandenburger __u64 create; 79255e301fdSFilipe Brandenburger __u64 qgroupid; 79355e301fdSFilipe Brandenburger }; 79455e301fdSFilipe Brandenburger struct btrfs_ioctl_timespec { 79555e301fdSFilipe Brandenburger __u64 sec; 79655e301fdSFilipe Brandenburger __u32 nsec; 79755e301fdSFilipe Brandenburger }; 79855e301fdSFilipe Brandenburger 79955e301fdSFilipe Brandenburger struct btrfs_ioctl_received_subvol_args { 80055e301fdSFilipe Brandenburger char uuid[BTRFS_UUID_SIZE]; /* in */ 80155e301fdSFilipe Brandenburger __u64 stransid; /* in */ 80255e301fdSFilipe Brandenburger __u64 rtransid; /* out */ 80355e301fdSFilipe Brandenburger struct btrfs_ioctl_timespec stime; /* in */ 80455e301fdSFilipe Brandenburger struct btrfs_ioctl_timespec rtime; /* out */ 80555e301fdSFilipe Brandenburger __u64 flags; /* in */ 80655e301fdSFilipe Brandenburger __u64 reserved[16]; /* in */ 80755e301fdSFilipe Brandenburger }; 80855e301fdSFilipe Brandenburger 809cb95e7bfSMark Fasheh /* 810cb95e7bfSMark Fasheh * Caller doesn't want file data in the send stream, even if the 811cb95e7bfSMark Fasheh * search of clone sources doesn't find an extent. UPDATE_EXTENT 812cb95e7bfSMark Fasheh * commands will be sent instead of WRITE commands. 813cb95e7bfSMark Fasheh */ 814cb95e7bfSMark Fasheh #define BTRFS_SEND_FLAG_NO_FILE_DATA 0x1 815c2c71324SStefan Behrens 816c2c71324SStefan Behrens /* 817c2c71324SStefan Behrens * Do not add the leading stream header. Used when multiple snapshots 818c2c71324SStefan Behrens * are sent back to back. 819c2c71324SStefan Behrens */ 820c2c71324SStefan Behrens #define BTRFS_SEND_FLAG_OMIT_STREAM_HEADER 0x2 821c2c71324SStefan Behrens 822c2c71324SStefan Behrens /* 823c2c71324SStefan Behrens * Omit the command at the end of the stream that indicated the end 824c2c71324SStefan Behrens * of the stream. This option is used when multiple snapshots are 825c2c71324SStefan Behrens * sent back to back. 826c2c71324SStefan Behrens */ 827c2c71324SStefan Behrens #define BTRFS_SEND_FLAG_OMIT_END_CMD 0x4 828c2c71324SStefan Behrens 829e77fbf99SDavid Sterba /* 830e77fbf99SDavid Sterba * Read the protocol version in the structure 831e77fbf99SDavid Sterba */ 832e77fbf99SDavid Sterba #define BTRFS_SEND_FLAG_VERSION 0x8 833e77fbf99SDavid Sterba 834b7c14f23SOmar Sandoval /* 835b7c14f23SOmar Sandoval * Send compressed data using the ENCODED_WRITE command instead of decompressing 836b7c14f23SOmar Sandoval * the data and sending it with the WRITE command. This requires protocol 837b7c14f23SOmar Sandoval * version >= 2. 838b7c14f23SOmar Sandoval */ 839b7c14f23SOmar Sandoval #define BTRFS_SEND_FLAG_COMPRESSED 0x10 840b7c14f23SOmar Sandoval 841c2c71324SStefan Behrens #define BTRFS_SEND_FLAG_MASK \ 842c2c71324SStefan Behrens (BTRFS_SEND_FLAG_NO_FILE_DATA | \ 843c2c71324SStefan Behrens BTRFS_SEND_FLAG_OMIT_STREAM_HEADER | \ 844e77fbf99SDavid Sterba BTRFS_SEND_FLAG_OMIT_END_CMD | \ 845d6815592SOmar Sandoval BTRFS_SEND_FLAG_VERSION | \ 846d6815592SOmar Sandoval BTRFS_SEND_FLAG_COMPRESSED) 847cb95e7bfSMark Fasheh 84855e301fdSFilipe Brandenburger struct btrfs_ioctl_send_args { 84955e301fdSFilipe Brandenburger __s64 send_fd; /* in */ 85055e301fdSFilipe Brandenburger __u64 clone_sources_count; /* in */ 85155e301fdSFilipe Brandenburger __u64 __user *clone_sources; /* in */ 85255e301fdSFilipe Brandenburger __u64 parent_root; /* in */ 85355e301fdSFilipe Brandenburger __u64 flags; /* in */ 854e77fbf99SDavid Sterba __u32 version; /* in */ 855e77fbf99SDavid Sterba __u8 reserved[28]; /* in */ 85655e301fdSFilipe Brandenburger }; 85755e301fdSFilipe Brandenburger 858b64ec075STomohiro Misono /* 859b64ec075STomohiro Misono * Information about a fs tree root. 860b64ec075STomohiro Misono * 861b64ec075STomohiro Misono * All items are filled by the ioctl 862b64ec075STomohiro Misono */ 863b64ec075STomohiro Misono struct btrfs_ioctl_get_subvol_info_args { 864b64ec075STomohiro Misono /* Id of this subvolume */ 865b64ec075STomohiro Misono __u64 treeid; 866b64ec075STomohiro Misono 867b64ec075STomohiro Misono /* Name of this subvolume, used to get the real name at mount point */ 868b64ec075STomohiro Misono char name[BTRFS_VOL_NAME_MAX + 1]; 869b64ec075STomohiro Misono 870b64ec075STomohiro Misono /* 871b64ec075STomohiro Misono * Id of the subvolume which contains this subvolume. 872b64ec075STomohiro Misono * Zero for top-level subvolume or a deleted subvolume. 873b64ec075STomohiro Misono */ 874b64ec075STomohiro Misono __u64 parent_id; 875b64ec075STomohiro Misono 876b64ec075STomohiro Misono /* 877b64ec075STomohiro Misono * Inode number of the directory which contains this subvolume. 878b64ec075STomohiro Misono * Zero for top-level subvolume or a deleted subvolume 879b64ec075STomohiro Misono */ 880b64ec075STomohiro Misono __u64 dirid; 881b64ec075STomohiro Misono 882b64ec075STomohiro Misono /* Latest transaction id of this subvolume */ 883b64ec075STomohiro Misono __u64 generation; 884b64ec075STomohiro Misono 885b64ec075STomohiro Misono /* Flags of this subvolume */ 886b64ec075STomohiro Misono __u64 flags; 887b64ec075STomohiro Misono 888b64ec075STomohiro Misono /* UUID of this subvolume */ 889b64ec075STomohiro Misono __u8 uuid[BTRFS_UUID_SIZE]; 890b64ec075STomohiro Misono 891b64ec075STomohiro Misono /* 892b64ec075STomohiro Misono * UUID of the subvolume of which this subvolume is a snapshot. 893b64ec075STomohiro Misono * All zero for a non-snapshot subvolume. 894b64ec075STomohiro Misono */ 895b64ec075STomohiro Misono __u8 parent_uuid[BTRFS_UUID_SIZE]; 896b64ec075STomohiro Misono 897b64ec075STomohiro Misono /* 898b64ec075STomohiro Misono * UUID of the subvolume from which this subvolume was received. 899b64ec075STomohiro Misono * All zero for non-received subvolume. 900b64ec075STomohiro Misono */ 901b64ec075STomohiro Misono __u8 received_uuid[BTRFS_UUID_SIZE]; 902b64ec075STomohiro Misono 903b64ec075STomohiro Misono /* Transaction id indicating when change/create/send/receive happened */ 904b64ec075STomohiro Misono __u64 ctransid; 905b64ec075STomohiro Misono __u64 otransid; 906b64ec075STomohiro Misono __u64 stransid; 907b64ec075STomohiro Misono __u64 rtransid; 908b64ec075STomohiro Misono /* Time corresponding to c/o/s/rtransid */ 909b64ec075STomohiro Misono struct btrfs_ioctl_timespec ctime; 910b64ec075STomohiro Misono struct btrfs_ioctl_timespec otime; 911b64ec075STomohiro Misono struct btrfs_ioctl_timespec stime; 912b64ec075STomohiro Misono struct btrfs_ioctl_timespec rtime; 913b64ec075STomohiro Misono 914b64ec075STomohiro Misono /* Must be zero */ 915b64ec075STomohiro Misono __u64 reserved[8]; 916b64ec075STomohiro Misono }; 917b64ec075STomohiro Misono 91842e4b520STomohiro Misono #define BTRFS_MAX_ROOTREF_BUFFER_NUM 255 91942e4b520STomohiro Misono struct btrfs_ioctl_get_subvol_rootref_args { 92042e4b520STomohiro Misono /* in/out, minimum id of rootref's treeid to be searched */ 92142e4b520STomohiro Misono __u64 min_treeid; 92242e4b520STomohiro Misono 92342e4b520STomohiro Misono /* out */ 92442e4b520STomohiro Misono struct { 92542e4b520STomohiro Misono __u64 treeid; 92642e4b520STomohiro Misono __u64 dirid; 92742e4b520STomohiro Misono } rootref[BTRFS_MAX_ROOTREF_BUFFER_NUM]; 92842e4b520STomohiro Misono 92942e4b520STomohiro Misono /* out, number of found items */ 93042e4b520STomohiro Misono __u8 num_items; 93142e4b520STomohiro Misono __u8 align[7]; 93242e4b520STomohiro Misono }; 93342e4b520STomohiro Misono 934dcb77a9aSOmar Sandoval /* 935dcb77a9aSOmar Sandoval * Data and metadata for an encoded read or write. 936dcb77a9aSOmar Sandoval * 937dcb77a9aSOmar Sandoval * Encoded I/O bypasses any encoding automatically done by the filesystem (e.g., 938dcb77a9aSOmar Sandoval * compression). This can be used to read the compressed contents of a file or 939dcb77a9aSOmar Sandoval * write pre-compressed data directly to a file. 940dcb77a9aSOmar Sandoval * 941dcb77a9aSOmar Sandoval * BTRFS_IOC_ENCODED_READ and BTRFS_IOC_ENCODED_WRITE are essentially 942dcb77a9aSOmar Sandoval * preadv/pwritev with additional metadata about how the data is encoded and the 943dcb77a9aSOmar Sandoval * size of the unencoded data. 944dcb77a9aSOmar Sandoval * 945dcb77a9aSOmar Sandoval * BTRFS_IOC_ENCODED_READ fills the given iovecs with the encoded data, fills 946dcb77a9aSOmar Sandoval * the metadata fields, and returns the size of the encoded data. It reads one 947dcb77a9aSOmar Sandoval * extent per call. It can also read data which is not encoded. 948dcb77a9aSOmar Sandoval * 949dcb77a9aSOmar Sandoval * BTRFS_IOC_ENCODED_WRITE uses the metadata fields, writes the encoded data 950dcb77a9aSOmar Sandoval * from the iovecs, and returns the size of the encoded data. Note that the 951dcb77a9aSOmar Sandoval * encoded data is not validated when it is written; if it is not valid (e.g., 952dcb77a9aSOmar Sandoval * it cannot be decompressed), then a subsequent read may return an error. 953dcb77a9aSOmar Sandoval * 954dcb77a9aSOmar Sandoval * Since the filesystem page cache contains decoded data, encoded I/O bypasses 955dcb77a9aSOmar Sandoval * the page cache. Encoded I/O requires CAP_SYS_ADMIN. 956dcb77a9aSOmar Sandoval */ 957dcb77a9aSOmar Sandoval struct btrfs_ioctl_encoded_io_args { 958dcb77a9aSOmar Sandoval /* Input parameters for both reads and writes. */ 959dcb77a9aSOmar Sandoval 960dcb77a9aSOmar Sandoval /* 961dcb77a9aSOmar Sandoval * iovecs containing encoded data. 962dcb77a9aSOmar Sandoval * 963dcb77a9aSOmar Sandoval * For reads, if the size of the encoded data is larger than the sum of 964dcb77a9aSOmar Sandoval * iov[n].iov_len for 0 <= n < iovcnt, then the ioctl fails with 965dcb77a9aSOmar Sandoval * ENOBUFS. 966dcb77a9aSOmar Sandoval * 967dcb77a9aSOmar Sandoval * For writes, the size of the encoded data is the sum of iov[n].iov_len 968dcb77a9aSOmar Sandoval * for 0 <= n < iovcnt. This must be less than 128 KiB (this limit may 969dcb77a9aSOmar Sandoval * increase in the future). This must also be less than or equal to 970dcb77a9aSOmar Sandoval * unencoded_len. 971dcb77a9aSOmar Sandoval */ 972dcb77a9aSOmar Sandoval const struct iovec __user *iov; 973dcb77a9aSOmar Sandoval /* Number of iovecs. */ 974dcb77a9aSOmar Sandoval unsigned long iovcnt; 975dcb77a9aSOmar Sandoval /* 976dcb77a9aSOmar Sandoval * Offset in file. 977dcb77a9aSOmar Sandoval * 978dcb77a9aSOmar Sandoval * For writes, must be aligned to the sector size of the filesystem. 979dcb77a9aSOmar Sandoval */ 980dcb77a9aSOmar Sandoval __s64 offset; 981dcb77a9aSOmar Sandoval /* Currently must be zero. */ 982dcb77a9aSOmar Sandoval __u64 flags; 983dcb77a9aSOmar Sandoval 984dcb77a9aSOmar Sandoval /* 985dcb77a9aSOmar Sandoval * For reads, the following members are output parameters that will 986dcb77a9aSOmar Sandoval * contain the returned metadata for the encoded data. 987dcb77a9aSOmar Sandoval * For writes, the following members must be set to the metadata for the 988dcb77a9aSOmar Sandoval * encoded data. 989dcb77a9aSOmar Sandoval */ 990dcb77a9aSOmar Sandoval 991dcb77a9aSOmar Sandoval /* 992dcb77a9aSOmar Sandoval * Length of the data in the file. 993dcb77a9aSOmar Sandoval * 994dcb77a9aSOmar Sandoval * Must be less than or equal to unencoded_len - unencoded_offset. For 995dcb77a9aSOmar Sandoval * writes, must be aligned to the sector size of the filesystem unless 996dcb77a9aSOmar Sandoval * the data ends at or beyond the current end of the file. 997dcb77a9aSOmar Sandoval */ 998dcb77a9aSOmar Sandoval __u64 len; 999dcb77a9aSOmar Sandoval /* 1000dcb77a9aSOmar Sandoval * Length of the unencoded (i.e., decrypted and decompressed) data. 1001dcb77a9aSOmar Sandoval * 1002dcb77a9aSOmar Sandoval * For writes, must be no more than 128 KiB (this limit may increase in 1003dcb77a9aSOmar Sandoval * the future). If the unencoded data is actually longer than 1004dcb77a9aSOmar Sandoval * unencoded_len, then it is truncated; if it is shorter, then it is 1005dcb77a9aSOmar Sandoval * extended with zeroes. 1006dcb77a9aSOmar Sandoval */ 1007dcb77a9aSOmar Sandoval __u64 unencoded_len; 1008dcb77a9aSOmar Sandoval /* 1009dcb77a9aSOmar Sandoval * Offset from the first byte of the unencoded data to the first byte of 1010dcb77a9aSOmar Sandoval * logical data in the file. 1011dcb77a9aSOmar Sandoval * 1012dcb77a9aSOmar Sandoval * Must be less than unencoded_len. 1013dcb77a9aSOmar Sandoval */ 1014dcb77a9aSOmar Sandoval __u64 unencoded_offset; 1015dcb77a9aSOmar Sandoval /* 1016dcb77a9aSOmar Sandoval * BTRFS_ENCODED_IO_COMPRESSION_* type. 1017dcb77a9aSOmar Sandoval * 1018dcb77a9aSOmar Sandoval * For writes, must not be BTRFS_ENCODED_IO_COMPRESSION_NONE. 1019dcb77a9aSOmar Sandoval */ 1020dcb77a9aSOmar Sandoval __u32 compression; 1021dcb77a9aSOmar Sandoval /* Currently always BTRFS_ENCODED_IO_ENCRYPTION_NONE. */ 1022dcb77a9aSOmar Sandoval __u32 encryption; 1023dcb77a9aSOmar Sandoval /* 1024dcb77a9aSOmar Sandoval * Reserved for future expansion. 1025dcb77a9aSOmar Sandoval * 1026dcb77a9aSOmar Sandoval * For reads, always returned as zero. Users should check for non-zero 1027dcb77a9aSOmar Sandoval * bytes. If there are any, then the kernel has a newer version of this 1028dcb77a9aSOmar Sandoval * structure with additional information that the user definition is 1029dcb77a9aSOmar Sandoval * missing. 1030dcb77a9aSOmar Sandoval * 1031dcb77a9aSOmar Sandoval * For writes, must be zeroed. 1032dcb77a9aSOmar Sandoval */ 1033dcb77a9aSOmar Sandoval __u8 reserved[64]; 1034dcb77a9aSOmar Sandoval }; 1035dcb77a9aSOmar Sandoval 1036dcb77a9aSOmar Sandoval /* Data is not compressed. */ 1037dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_NONE 0 1038dcb77a9aSOmar Sandoval /* Data is compressed as a single zlib stream. */ 1039dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_ZLIB 1 1040dcb77a9aSOmar Sandoval /* 1041dcb77a9aSOmar Sandoval * Data is compressed as a single zstd frame with the windowLog compression 1042dcb77a9aSOmar Sandoval * parameter set to no more than 17. 1043dcb77a9aSOmar Sandoval */ 1044dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_ZSTD 2 1045dcb77a9aSOmar Sandoval /* 1046dcb77a9aSOmar Sandoval * Data is compressed sector by sector (using the sector size indicated by the 1047dcb77a9aSOmar Sandoval * name of the constant) with LZO1X and wrapped in the format documented in 1048dcb77a9aSOmar Sandoval * fs/btrfs/lzo.c. For writes, the compression sector size must match the 1049dcb77a9aSOmar Sandoval * filesystem sector size. 1050dcb77a9aSOmar Sandoval */ 1051dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_LZO_4K 3 1052dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_LZO_8K 4 1053dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_LZO_16K 5 1054dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_LZO_32K 6 1055dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_LZO_64K 7 1056dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_COMPRESSION_TYPES 8 1057dcb77a9aSOmar Sandoval 1058dcb77a9aSOmar Sandoval /* Data is not encrypted. */ 1059dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_ENCRYPTION_NONE 0 1060dcb77a9aSOmar Sandoval #define BTRFS_ENCODED_IO_ENCRYPTION_TYPES 1 1061dcb77a9aSOmar Sandoval 10626c83d153SDavid Sterba /* 10636c83d153SDavid Sterba * Wait for subvolume cleaning process. This queries the kernel queue and it 10646c83d153SDavid Sterba * can change between the calls. 10656c83d153SDavid Sterba * 10666c83d153SDavid Sterba * - FOR_ONE - specify the subvolid 10676c83d153SDavid Sterba * - FOR_QUEUED - wait for all currently queued 10686c83d153SDavid Sterba * - COUNT - count number of queued 10696c83d153SDavid Sterba * - PEEK_FIRST - read which is the first in the queue (to be cleaned or being 10706c83d153SDavid Sterba * cleaned already), or 0 if the queue is empty 10716c83d153SDavid Sterba * - PEEK_LAST - read the last subvolid in the queue, or 0 if the queue is empty 10726c83d153SDavid Sterba */ 10736c83d153SDavid Sterba struct btrfs_ioctl_subvol_wait { 10746c83d153SDavid Sterba __u64 subvolid; 10756c83d153SDavid Sterba __u32 mode; 10766c83d153SDavid Sterba __u32 count; 10776c83d153SDavid Sterba }; 10786c83d153SDavid Sterba 10796c83d153SDavid Sterba #define BTRFS_SUBVOL_SYNC_WAIT_FOR_ONE (0) 10806c83d153SDavid Sterba #define BTRFS_SUBVOL_SYNC_WAIT_FOR_QUEUED (1) 10816c83d153SDavid Sterba #define BTRFS_SUBVOL_SYNC_COUNT (2) 10826c83d153SDavid Sterba #define BTRFS_SUBVOL_SYNC_PEEK_FIRST (3) 10836c83d153SDavid Sterba #define BTRFS_SUBVOL_SYNC_PEEK_LAST (4) 10846c83d153SDavid Sterba 1085183860f6SAnand Jain /* Error codes as returned by the kernel */ 1086183860f6SAnand Jain enum btrfs_err_code { 1087eb710b15SSatoru Takeuchi BTRFS_ERROR_DEV_RAID1_MIN_NOT_MET = 1, 1088183860f6SAnand Jain BTRFS_ERROR_DEV_RAID10_MIN_NOT_MET, 1089183860f6SAnand Jain BTRFS_ERROR_DEV_RAID5_MIN_NOT_MET, 1090183860f6SAnand Jain BTRFS_ERROR_DEV_RAID6_MIN_NOT_MET, 1091183860f6SAnand Jain BTRFS_ERROR_DEV_TGT_REPLACE, 1092183860f6SAnand Jain BTRFS_ERROR_DEV_MISSING_NOT_FOUND, 1093183860f6SAnand Jain BTRFS_ERROR_DEV_ONLY_WRITABLE, 109447e6f742SDavid Sterba BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS, 109547e6f742SDavid Sterba BTRFS_ERROR_DEV_RAID1C3_MIN_NOT_MET, 10968d6fac00SDavid Sterba BTRFS_ERROR_DEV_RAID1C4_MIN_NOT_MET, 1097183860f6SAnand Jain }; 1098183860f6SAnand Jain 109955e301fdSFilipe Brandenburger #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ 110055e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 110155e301fdSFilipe Brandenburger #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ 110255e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 110355e301fdSFilipe Brandenburger #define BTRFS_IOC_RESIZE _IOW(BTRFS_IOCTL_MAGIC, 3, \ 110455e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 110555e301fdSFilipe Brandenburger #define BTRFS_IOC_SCAN_DEV _IOW(BTRFS_IOCTL_MAGIC, 4, \ 110655e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 1107228a73abSAnand Jain #define BTRFS_IOC_FORGET_DEV _IOW(BTRFS_IOCTL_MAGIC, 5, \ 1108228a73abSAnand Jain struct btrfs_ioctl_vol_args) 110955e301fdSFilipe Brandenburger /* trans start and trans end are dangerous, and only for 111055e301fdSFilipe Brandenburger * use by applications that know how to avoid the 111155e301fdSFilipe Brandenburger * resulting deadlocks 111255e301fdSFilipe Brandenburger */ 111355e301fdSFilipe Brandenburger #define BTRFS_IOC_TRANS_START _IO(BTRFS_IOCTL_MAGIC, 6) 111455e301fdSFilipe Brandenburger #define BTRFS_IOC_TRANS_END _IO(BTRFS_IOCTL_MAGIC, 7) 111555e301fdSFilipe Brandenburger #define BTRFS_IOC_SYNC _IO(BTRFS_IOCTL_MAGIC, 8) 111655e301fdSFilipe Brandenburger 111755e301fdSFilipe Brandenburger #define BTRFS_IOC_CLONE _IOW(BTRFS_IOCTL_MAGIC, 9, int) 111855e301fdSFilipe Brandenburger #define BTRFS_IOC_ADD_DEV _IOW(BTRFS_IOCTL_MAGIC, 10, \ 111955e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 112055e301fdSFilipe Brandenburger #define BTRFS_IOC_RM_DEV _IOW(BTRFS_IOCTL_MAGIC, 11, \ 112155e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 112255e301fdSFilipe Brandenburger #define BTRFS_IOC_BALANCE _IOW(BTRFS_IOCTL_MAGIC, 12, \ 112355e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 112455e301fdSFilipe Brandenburger 112555e301fdSFilipe Brandenburger #define BTRFS_IOC_CLONE_RANGE _IOW(BTRFS_IOCTL_MAGIC, 13, \ 112655e301fdSFilipe Brandenburger struct btrfs_ioctl_clone_range_args) 112755e301fdSFilipe Brandenburger 112855e301fdSFilipe Brandenburger #define BTRFS_IOC_SUBVOL_CREATE _IOW(BTRFS_IOCTL_MAGIC, 14, \ 112955e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 113055e301fdSFilipe Brandenburger #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ 113155e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 113255e301fdSFilipe Brandenburger #define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \ 113355e301fdSFilipe Brandenburger struct btrfs_ioctl_defrag_range_args) 113455e301fdSFilipe Brandenburger #define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ 113555e301fdSFilipe Brandenburger struct btrfs_ioctl_search_args) 1136cc68a8a5SGerhard Heift #define BTRFS_IOC_TREE_SEARCH_V2 _IOWR(BTRFS_IOCTL_MAGIC, 17, \ 1137cc68a8a5SGerhard Heift struct btrfs_ioctl_search_args_v2) 113855e301fdSFilipe Brandenburger #define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \ 113955e301fdSFilipe Brandenburger struct btrfs_ioctl_ino_lookup_args) 114068b823efSMike Frysinger #define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, __u64) 114155e301fdSFilipe Brandenburger #define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ 114255e301fdSFilipe Brandenburger struct btrfs_ioctl_space_args) 114355e301fdSFilipe Brandenburger #define BTRFS_IOC_START_SYNC _IOR(BTRFS_IOCTL_MAGIC, 24, __u64) 114455e301fdSFilipe Brandenburger #define BTRFS_IOC_WAIT_SYNC _IOW(BTRFS_IOCTL_MAGIC, 22, __u64) 114555e301fdSFilipe Brandenburger #define BTRFS_IOC_SNAP_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 23, \ 114655e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args_v2) 114755e301fdSFilipe Brandenburger #define BTRFS_IOC_SUBVOL_CREATE_V2 _IOW(BTRFS_IOCTL_MAGIC, 24, \ 114855e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args_v2) 114955e301fdSFilipe Brandenburger #define BTRFS_IOC_SUBVOL_GETFLAGS _IOR(BTRFS_IOCTL_MAGIC, 25, __u64) 115055e301fdSFilipe Brandenburger #define BTRFS_IOC_SUBVOL_SETFLAGS _IOW(BTRFS_IOCTL_MAGIC, 26, __u64) 115155e301fdSFilipe Brandenburger #define BTRFS_IOC_SCRUB _IOWR(BTRFS_IOCTL_MAGIC, 27, \ 115255e301fdSFilipe Brandenburger struct btrfs_ioctl_scrub_args) 115355e301fdSFilipe Brandenburger #define BTRFS_IOC_SCRUB_CANCEL _IO(BTRFS_IOCTL_MAGIC, 28) 115455e301fdSFilipe Brandenburger #define BTRFS_IOC_SCRUB_PROGRESS _IOWR(BTRFS_IOCTL_MAGIC, 29, \ 115555e301fdSFilipe Brandenburger struct btrfs_ioctl_scrub_args) 115655e301fdSFilipe Brandenburger #define BTRFS_IOC_DEV_INFO _IOWR(BTRFS_IOCTL_MAGIC, 30, \ 115755e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_info_args) 115855e301fdSFilipe Brandenburger #define BTRFS_IOC_FS_INFO _IOR(BTRFS_IOCTL_MAGIC, 31, \ 115955e301fdSFilipe Brandenburger struct btrfs_ioctl_fs_info_args) 116055e301fdSFilipe Brandenburger #define BTRFS_IOC_BALANCE_V2 _IOWR(BTRFS_IOCTL_MAGIC, 32, \ 116155e301fdSFilipe Brandenburger struct btrfs_ioctl_balance_args) 116255e301fdSFilipe Brandenburger #define BTRFS_IOC_BALANCE_CTL _IOW(BTRFS_IOCTL_MAGIC, 33, int) 116355e301fdSFilipe Brandenburger #define BTRFS_IOC_BALANCE_PROGRESS _IOR(BTRFS_IOCTL_MAGIC, 34, \ 116455e301fdSFilipe Brandenburger struct btrfs_ioctl_balance_args) 116555e301fdSFilipe Brandenburger #define BTRFS_IOC_INO_PATHS _IOWR(BTRFS_IOCTL_MAGIC, 35, \ 116655e301fdSFilipe Brandenburger struct btrfs_ioctl_ino_path_args) 116755e301fdSFilipe Brandenburger #define BTRFS_IOC_LOGICAL_INO _IOWR(BTRFS_IOCTL_MAGIC, 36, \ 11687af7c616SHans van Kranenburg struct btrfs_ioctl_logical_ino_args) 116955e301fdSFilipe Brandenburger #define BTRFS_IOC_SET_RECEIVED_SUBVOL _IOWR(BTRFS_IOCTL_MAGIC, 37, \ 117055e301fdSFilipe Brandenburger struct btrfs_ioctl_received_subvol_args) 117155e301fdSFilipe Brandenburger #define BTRFS_IOC_SEND _IOW(BTRFS_IOCTL_MAGIC, 38, struct btrfs_ioctl_send_args) 117255e301fdSFilipe Brandenburger #define BTRFS_IOC_DEVICES_READY _IOR(BTRFS_IOCTL_MAGIC, 39, \ 117355e301fdSFilipe Brandenburger struct btrfs_ioctl_vol_args) 117455e301fdSFilipe Brandenburger #define BTRFS_IOC_QUOTA_CTL _IOWR(BTRFS_IOCTL_MAGIC, 40, \ 117555e301fdSFilipe Brandenburger struct btrfs_ioctl_quota_ctl_args) 117655e301fdSFilipe Brandenburger #define BTRFS_IOC_QGROUP_ASSIGN _IOW(BTRFS_IOCTL_MAGIC, 41, \ 117755e301fdSFilipe Brandenburger struct btrfs_ioctl_qgroup_assign_args) 117855e301fdSFilipe Brandenburger #define BTRFS_IOC_QGROUP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 42, \ 117955e301fdSFilipe Brandenburger struct btrfs_ioctl_qgroup_create_args) 118055e301fdSFilipe Brandenburger #define BTRFS_IOC_QGROUP_LIMIT _IOR(BTRFS_IOCTL_MAGIC, 43, \ 118155e301fdSFilipe Brandenburger struct btrfs_ioctl_qgroup_limit_args) 11822f232036SJan Schmidt #define BTRFS_IOC_QUOTA_RESCAN _IOW(BTRFS_IOCTL_MAGIC, 44, \ 11832f232036SJan Schmidt struct btrfs_ioctl_quota_rescan_args) 11842f232036SJan Schmidt #define BTRFS_IOC_QUOTA_RESCAN_STATUS _IOR(BTRFS_IOCTL_MAGIC, 45, \ 11852f232036SJan Schmidt struct btrfs_ioctl_quota_rescan_args) 118657254b6eSJan Schmidt #define BTRFS_IOC_QUOTA_RESCAN_WAIT _IO(BTRFS_IOCTL_MAGIC, 46) 118740cf931fSEric Sandeen #define BTRFS_IOC_GET_FSLABEL FS_IOC_GETFSLABEL 118840cf931fSEric Sandeen #define BTRFS_IOC_SET_FSLABEL FS_IOC_SETFSLABEL 118955e301fdSFilipe Brandenburger #define BTRFS_IOC_GET_DEV_STATS _IOWR(BTRFS_IOCTL_MAGIC, 52, \ 119055e301fdSFilipe Brandenburger struct btrfs_ioctl_get_dev_stats) 119155e301fdSFilipe Brandenburger #define BTRFS_IOC_DEV_REPLACE _IOWR(BTRFS_IOCTL_MAGIC, 53, \ 119255e301fdSFilipe Brandenburger struct btrfs_ioctl_dev_replace_args) 1193416161dbSMark Fasheh #define BTRFS_IOC_FILE_EXTENT_SAME _IOWR(BTRFS_IOCTL_MAGIC, 54, \ 1194416161dbSMark Fasheh struct btrfs_ioctl_same_args) 11952eaa055fSJeff Mahoney #define BTRFS_IOC_GET_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ 11962eaa055fSJeff Mahoney struct btrfs_ioctl_feature_flags) 11972eaa055fSJeff Mahoney #define BTRFS_IOC_SET_FEATURES _IOW(BTRFS_IOCTL_MAGIC, 57, \ 11982eaa055fSJeff Mahoney struct btrfs_ioctl_feature_flags[2]) 11992eaa055fSJeff Mahoney #define BTRFS_IOC_GET_SUPPORTED_FEATURES _IOR(BTRFS_IOCTL_MAGIC, 57, \ 12002eaa055fSJeff Mahoney struct btrfs_ioctl_feature_flags[3]) 12016b526ed7SAnand Jain #define BTRFS_IOC_RM_DEV_V2 _IOW(BTRFS_IOCTL_MAGIC, 58, \ 12026b526ed7SAnand Jain struct btrfs_ioctl_vol_args_v2) 1203d24a67b2SZygo Blaxell #define BTRFS_IOC_LOGICAL_INO_V2 _IOWR(BTRFS_IOCTL_MAGIC, 59, \ 1204d24a67b2SZygo Blaxell struct btrfs_ioctl_logical_ino_args) 1205b64ec075STomohiro Misono #define BTRFS_IOC_GET_SUBVOL_INFO _IOR(BTRFS_IOCTL_MAGIC, 60, \ 1206b64ec075STomohiro Misono struct btrfs_ioctl_get_subvol_info_args) 120742e4b520STomohiro Misono #define BTRFS_IOC_GET_SUBVOL_ROOTREF _IOWR(BTRFS_IOCTL_MAGIC, 61, \ 120842e4b520STomohiro Misono struct btrfs_ioctl_get_subvol_rootref_args) 120923d0b79dSTomohiro Misono #define BTRFS_IOC_INO_LOOKUP_USER _IOWR(BTRFS_IOCTL_MAGIC, 62, \ 121023d0b79dSTomohiro Misono struct btrfs_ioctl_ino_lookup_user_args) 1211949964c9SMarcos Paulo de Souza #define BTRFS_IOC_SNAP_DESTROY_V2 _IOW(BTRFS_IOCTL_MAGIC, 63, \ 1212949964c9SMarcos Paulo de Souza struct btrfs_ioctl_vol_args_v2) 1213dcb77a9aSOmar Sandoval #define BTRFS_IOC_ENCODED_READ _IOR(BTRFS_IOCTL_MAGIC, 64, \ 1214dcb77a9aSOmar Sandoval struct btrfs_ioctl_encoded_io_args) 1215dcb77a9aSOmar Sandoval #define BTRFS_IOC_ENCODED_WRITE _IOW(BTRFS_IOCTL_MAGIC, 64, \ 1216dcb77a9aSOmar Sandoval struct btrfs_ioctl_encoded_io_args) 12176c83d153SDavid Sterba #define BTRFS_IOC_SUBVOL_SYNC_WAIT _IOW(BTRFS_IOCTL_MAGIC, 65, \ 12186c83d153SDavid Sterba struct btrfs_ioctl_subvol_wait) 1219416161dbSMark Fasheh 1220a2813530SJosef Bacik #ifdef __cplusplus 1221a2813530SJosef Bacik } 1222a2813530SJosef Bacik #endif 1223a2813530SJosef Bacik 122455e301fdSFilipe Brandenburger #endif /* _UAPI_LINUX_BTRFS_H */ 1225