xref: /openbmc/linux/fs/btrfs/send.h (revision 82806c25)
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 	/* End */
96 	BTRFS_SEND_C_MAX		= 25,
97 };
98 
99 /* attributes in send stream */
100 enum {
101 	BTRFS_SEND_A_UNSPEC		= 0,
102 
103 	/* Version 1 */
104 	BTRFS_SEND_A_UUID		= 1,
105 	BTRFS_SEND_A_CTRANSID		= 2,
106 
107 	BTRFS_SEND_A_INO		= 3,
108 	BTRFS_SEND_A_SIZE		= 4,
109 	BTRFS_SEND_A_MODE		= 5,
110 	BTRFS_SEND_A_UID		= 6,
111 	BTRFS_SEND_A_GID		= 7,
112 	BTRFS_SEND_A_RDEV		= 8,
113 	BTRFS_SEND_A_CTIME		= 9,
114 	BTRFS_SEND_A_MTIME		= 10,
115 	BTRFS_SEND_A_ATIME		= 11,
116 	BTRFS_SEND_A_OTIME		= 12,
117 
118 	BTRFS_SEND_A_XATTR_NAME		= 13,
119 	BTRFS_SEND_A_XATTR_DATA		= 14,
120 
121 	BTRFS_SEND_A_PATH		= 15,
122 	BTRFS_SEND_A_PATH_TO		= 16,
123 	BTRFS_SEND_A_PATH_LINK		= 17,
124 
125 	BTRFS_SEND_A_FILE_OFFSET	= 18,
126 	/*
127 	 * As of send stream v2, this attribute is special: it must be the last
128 	 * attribute in a command, its header contains only the type, and its
129 	 * length is implicitly the remaining length of the command.
130 	 */
131 	BTRFS_SEND_A_DATA		= 19,
132 
133 	BTRFS_SEND_A_CLONE_UUID		= 20,
134 	BTRFS_SEND_A_CLONE_CTRANSID	= 21,
135 	BTRFS_SEND_A_CLONE_PATH		= 22,
136 	BTRFS_SEND_A_CLONE_OFFSET	= 23,
137 	BTRFS_SEND_A_CLONE_LEN		= 24,
138 
139 	BTRFS_SEND_A_MAX_V1		= 24,
140 
141 	/* Version 2 */
142 	BTRFS_SEND_A_FALLOCATE_MODE	= 25,
143 
144 	/*
145 	 * File attributes from the FS_*_FL namespace (i_flags, xflags),
146 	 * translated to BTRFS_INODE_* bits (BTRFS_INODE_FLAG_MASK) and stored
147 	 * in btrfs_inode_item::flags (represented by btrfs_inode::flags and
148 	 * btrfs_inode::ro_flags).
149 	 */
150 	BTRFS_SEND_A_FILEATTR		= 26,
151 
152 	BTRFS_SEND_A_UNENCODED_FILE_LEN	= 27,
153 	BTRFS_SEND_A_UNENCODED_LEN	= 28,
154 	BTRFS_SEND_A_UNENCODED_OFFSET	= 29,
155 	/*
156 	 * COMPRESSION and ENCRYPTION default to NONE (0) if omitted from
157 	 * BTRFS_SEND_C_ENCODED_WRITE.
158 	 */
159 	BTRFS_SEND_A_COMPRESSION	= 30,
160 	BTRFS_SEND_A_ENCRYPTION		= 31,
161 	BTRFS_SEND_A_MAX_V2		= 31,
162 
163 	/* End */
164 	BTRFS_SEND_A_MAX		= 31,
165 };
166 
167 long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg);
168 
169 #endif
170