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