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