| 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
| 2 | /* |
| 3 | * Copyright (C) 2012 Alexander Block. All rights reserved. |
| 4 | * Copyright (C) 2012 STRATO. All rights reserved. |
| 5 | */ |
| 6 | |
| 7 | #ifndef BTRFS_SEND_H |
| 8 | #define BTRFS_SEND_H |
| 9 | |
| 10 | #include <linux/types.h> |
| 11 | #include <linux/sizes.h> |
| 12 | #include <linux/align.h> |
| 13 | |
| 14 | struct btrfs_root; |
| 15 | struct btrfs_ioctl_send_args; |
| 16 | |
| 17 | #define BTRFS_SEND_STREAM_MAGIC "btrfs-stream" |
| 18 | /* Conditional support for the upcoming protocol version. */ |
| 19 | #ifdef CONFIG_BTRFS_EXPERIMENTAL |
| 20 | #define BTRFS_SEND_STREAM_VERSION 3 |
| 21 | #else |
| 22 | #define BTRFS_SEND_STREAM_VERSION 2 |
| 23 | #endif |
| 24 | |
| 25 | /* |
| 26 | * In send stream v1, no command is larger than 64K. In send stream v2, no |
| 27 | * limit should be assumed, the buffer size is set to be a header with |
| 28 | * compressed extent size. |
| 29 | */ |
| 30 | #define BTRFS_SEND_BUF_SIZE_V1 SZ_64K |
| 31 | #define BTRFS_SEND_BUF_SIZE_V2 ALIGN(SZ_16K + BTRFS_MAX_COMPRESSED, PAGE_SIZE) |
| 32 | |
| 33 | enum btrfs_tlv_type { |
| 34 | BTRFS_TLV_U8, |
| 35 | BTRFS_TLV_U16, |
| 36 | BTRFS_TLV_U32, |
| 37 | BTRFS_TLV_U64, |
| 38 | BTRFS_TLV_BINARY, |
| 39 | BTRFS_TLV_STRING, |
| 40 | BTRFS_TLV_UUID, |
| 41 | BTRFS_TLV_TIMESPEC, |
| 42 | }; |
| 43 | |
| 44 | struct { |
| 45 | char [sizeof(BTRFS_SEND_STREAM_MAGIC)]; |
| 46 | __le32 ; |
| 47 | } __attribute__ ((__packed__)); |
| 48 | |
| 49 | struct { |
| 50 | /* len excluding the header */ |
| 51 | __le32 ; |
| 52 | __le16 ; |
| 53 | /* crc including the header with zero crc field */ |
| 54 | __le32 ; |
| 55 | } __attribute__ ((__packed__)); |
| 56 | |
| 57 | struct { |
| 58 | __le16 ; |
| 59 | /* len excluding the header */ |
| 60 | __le16 ; |
| 61 | } __attribute__ ((__packed__)); |
| 62 | |
| 63 | /* commands */ |
| 64 | enum btrfs_send_cmd { |
| 65 | BTRFS_SEND_C_UNSPEC = 0, |
| 66 | |
| 67 | /* Version 1 */ |
| 68 | BTRFS_SEND_C_SUBVOL = 1, |
| 69 | BTRFS_SEND_C_SNAPSHOT = 2, |
| 70 | |
| 71 | BTRFS_SEND_C_MKFILE = 3, |
| 72 | BTRFS_SEND_C_MKDIR = 4, |
| 73 | BTRFS_SEND_C_MKNOD = 5, |
| 74 | BTRFS_SEND_C_MKFIFO = 6, |
| 75 | BTRFS_SEND_C_MKSOCK = 7, |
| 76 | BTRFS_SEND_C_SYMLINK = 8, |
| 77 | |
| 78 | BTRFS_SEND_C_RENAME = 9, |
| 79 | BTRFS_SEND_C_LINK = 10, |
| 80 | BTRFS_SEND_C_UNLINK = 11, |
| 81 | BTRFS_SEND_C_RMDIR = 12, |
| 82 | |
| 83 | BTRFS_SEND_C_SET_XATTR = 13, |
| 84 | BTRFS_SEND_C_REMOVE_XATTR = 14, |
| 85 | |
| 86 | BTRFS_SEND_C_WRITE = 15, |
| 87 | BTRFS_SEND_C_CLONE = 16, |
| 88 | |
| 89 | BTRFS_SEND_C_TRUNCATE = 17, |
| 90 | BTRFS_SEND_C_CHMOD = 18, |
| 91 | BTRFS_SEND_C_CHOWN = 19, |
| 92 | BTRFS_SEND_C_UTIMES = 20, |
| 93 | |
| 94 | BTRFS_SEND_C_END = 21, |
| 95 | BTRFS_SEND_C_UPDATE_EXTENT = 22, |
| 96 | BTRFS_SEND_C_MAX_V1 = 22, |
| 97 | |
| 98 | /* Version 2 */ |
| 99 | BTRFS_SEND_C_FALLOCATE = 23, |
| 100 | BTRFS_SEND_C_FILEATTR = 24, |
| 101 | BTRFS_SEND_C_ENCODED_WRITE = 25, |
| 102 | BTRFS_SEND_C_MAX_V2 = 25, |
| 103 | |
| 104 | /* Version 3 */ |
| 105 | BTRFS_SEND_C_ENABLE_VERITY = 26, |
| 106 | BTRFS_SEND_C_MAX_V3 = 26, |
| 107 | /* End */ |
| 108 | BTRFS_SEND_C_MAX = 26, |
| 109 | }; |
| 110 | |
| 111 | /* attributes in send stream */ |
| 112 | enum { |
| 113 | BTRFS_SEND_A_UNSPEC = 0, |
| 114 | |
| 115 | /* Version 1 */ |
| 116 | BTRFS_SEND_A_UUID = 1, |
| 117 | BTRFS_SEND_A_CTRANSID = 2, |
| 118 | |
| 119 | BTRFS_SEND_A_INO = 3, |
| 120 | BTRFS_SEND_A_SIZE = 4, |
| 121 | BTRFS_SEND_A_MODE = 5, |
| 122 | BTRFS_SEND_A_UID = 6, |
| 123 | BTRFS_SEND_A_GID = 7, |
| 124 | BTRFS_SEND_A_RDEV = 8, |
| 125 | BTRFS_SEND_A_CTIME = 9, |
| 126 | BTRFS_SEND_A_MTIME = 10, |
| 127 | BTRFS_SEND_A_ATIME = 11, |
| 128 | BTRFS_SEND_A_OTIME = 12, |
| 129 | |
| 130 | BTRFS_SEND_A_XATTR_NAME = 13, |
| 131 | BTRFS_SEND_A_XATTR_DATA = 14, |
| 132 | |
| 133 | BTRFS_SEND_A_PATH = 15, |
| 134 | BTRFS_SEND_A_PATH_TO = 16, |
| 135 | BTRFS_SEND_A_PATH_LINK = 17, |
| 136 | |
| 137 | BTRFS_SEND_A_FILE_OFFSET = 18, |
| 138 | /* |
| 139 | * As of send stream v2, this attribute is special: it must be the last |
| 140 | * attribute in a command, its header contains only the type, and its |
| 141 | * length is implicitly the remaining length of the command. |
| 142 | */ |
| 143 | BTRFS_SEND_A_DATA = 19, |
| 144 | |
| 145 | BTRFS_SEND_A_CLONE_UUID = 20, |
| 146 | BTRFS_SEND_A_CLONE_CTRANSID = 21, |
| 147 | BTRFS_SEND_A_CLONE_PATH = 22, |
| 148 | BTRFS_SEND_A_CLONE_OFFSET = 23, |
| 149 | BTRFS_SEND_A_CLONE_LEN = 24, |
| 150 | |
| 151 | BTRFS_SEND_A_MAX_V1 = 24, |
| 152 | |
| 153 | /* Version 2 */ |
| 154 | BTRFS_SEND_A_FALLOCATE_MODE = 25, |
| 155 | |
| 156 | /* |
| 157 | * File attributes from the FS_*_FL namespace (i_flags, xflags), |
| 158 | * translated to BTRFS_INODE_* bits (BTRFS_INODE_FLAG_MASK) and stored |
| 159 | * in btrfs_inode_item::flags (represented by btrfs_inode::flags and |
| 160 | * btrfs_inode::ro_flags). |
| 161 | */ |
| 162 | BTRFS_SEND_A_FILEATTR = 26, |
| 163 | |
| 164 | BTRFS_SEND_A_UNENCODED_FILE_LEN = 27, |
| 165 | BTRFS_SEND_A_UNENCODED_LEN = 28, |
| 166 | BTRFS_SEND_A_UNENCODED_OFFSET = 29, |
| 167 | /* |
| 168 | * COMPRESSION and ENCRYPTION default to NONE (0) if omitted from |
| 169 | * BTRFS_SEND_C_ENCODED_WRITE. |
| 170 | */ |
| 171 | BTRFS_SEND_A_COMPRESSION = 30, |
| 172 | BTRFS_SEND_A_ENCRYPTION = 31, |
| 173 | BTRFS_SEND_A_MAX_V2 = 31, |
| 174 | |
| 175 | /* Version 3 */ |
| 176 | BTRFS_SEND_A_VERITY_ALGORITHM = 32, |
| 177 | BTRFS_SEND_A_VERITY_BLOCK_SIZE = 33, |
| 178 | BTRFS_SEND_A_VERITY_SALT_DATA = 34, |
| 179 | BTRFS_SEND_A_VERITY_SIG_DATA = 35, |
| 180 | BTRFS_SEND_A_MAX_V3 = 35, |
| 181 | |
| 182 | __BTRFS_SEND_A_MAX = 35, |
| 183 | }; |
| 184 | |
| 185 | long btrfs_ioctl_send(struct btrfs_root *send_root, const struct btrfs_ioctl_send_args *arg); |
| 186 | |
| 187 | #endif |
| 188 | |