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