Loading...
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
22 * limit should be assumed, the buffer size is set to be a header with
23 * compressed extent size.
24 */
25#define BTRFS_SEND_BUF_SIZE_V1 SZ_64K
26#define BTRFS_SEND_BUF_SIZE_V2 ALIGN(SZ_16K + BTRFS_MAX_COMPRESSED, PAGE_SIZE)
27
28struct inode;
29struct btrfs_ioctl_send_args;
30
31enum btrfs_tlv_type {
32 BTRFS_TLV_U8,
33 BTRFS_TLV_U16,
34 BTRFS_TLV_U32,
35 BTRFS_TLV_U64,
36 BTRFS_TLV_BINARY,
37 BTRFS_TLV_STRING,
38 BTRFS_TLV_UUID,
39 BTRFS_TLV_TIMESPEC,
40};
41
42struct btrfs_stream_header {
43 char magic[sizeof(BTRFS_SEND_STREAM_MAGIC)];
44 __le32 version;
45} __attribute__ ((__packed__));
46
47struct btrfs_cmd_header {
48 /* len excluding the header */
49 __le32 len;
50 __le16 cmd;
51 /* crc including the header with zero crc field */
52 __le32 crc;
53} __attribute__ ((__packed__));
54
55struct btrfs_tlv_header {
56 __le16 tlv_type;
57 /* len excluding the header */
58 __le16 tlv_len;
59} __attribute__ ((__packed__));
60
61/* commands */
62enum btrfs_send_cmd {
63 BTRFS_SEND_C_UNSPEC = 0,
64
65 /* Version 1 */
66 BTRFS_SEND_C_SUBVOL = 1,
67 BTRFS_SEND_C_SNAPSHOT = 2,
68
69 BTRFS_SEND_C_MKFILE = 3,
70 BTRFS_SEND_C_MKDIR = 4,
71 BTRFS_SEND_C_MKNOD = 5,
72 BTRFS_SEND_C_MKFIFO = 6,
73 BTRFS_SEND_C_MKSOCK = 7,
74 BTRFS_SEND_C_SYMLINK = 8,
75
76 BTRFS_SEND_C_RENAME = 9,
77 BTRFS_SEND_C_LINK = 10,
78 BTRFS_SEND_C_UNLINK = 11,
79 BTRFS_SEND_C_RMDIR = 12,
80
81 BTRFS_SEND_C_SET_XATTR = 13,
82 BTRFS_SEND_C_REMOVE_XATTR = 14,
83
84 BTRFS_SEND_C_WRITE = 15,
85 BTRFS_SEND_C_CLONE = 16,
86
87 BTRFS_SEND_C_TRUNCATE = 17,
88 BTRFS_SEND_C_CHMOD = 18,
89 BTRFS_SEND_C_CHOWN = 19,
90 BTRFS_SEND_C_UTIMES = 20,
91
92 BTRFS_SEND_C_END = 21,
93 BTRFS_SEND_C_UPDATE_EXTENT = 22,
94 BTRFS_SEND_C_MAX_V1 = 22,
95
96 /* Version 2 */
97 BTRFS_SEND_C_FALLOCATE = 23,
98 BTRFS_SEND_C_FILEATTR = 24,
99 BTRFS_SEND_C_ENCODED_WRITE = 25,
100 BTRFS_SEND_C_MAX_V2 = 25,
101
102 /* Version 3 */
103 BTRFS_SEND_C_ENABLE_VERITY = 26,
104 BTRFS_SEND_C_MAX_V3 = 26,
105 /* End */
106 BTRFS_SEND_C_MAX = 26,
107};
108
109/* attributes in send stream */
110enum {
111 BTRFS_SEND_A_UNSPEC = 0,
112
113 /* Version 1 */
114 BTRFS_SEND_A_UUID = 1,
115 BTRFS_SEND_A_CTRANSID = 2,
116
117 BTRFS_SEND_A_INO = 3,
118 BTRFS_SEND_A_SIZE = 4,
119 BTRFS_SEND_A_MODE = 5,
120 BTRFS_SEND_A_UID = 6,
121 BTRFS_SEND_A_GID = 7,
122 BTRFS_SEND_A_RDEV = 8,
123 BTRFS_SEND_A_CTIME = 9,
124 BTRFS_SEND_A_MTIME = 10,
125 BTRFS_SEND_A_ATIME = 11,
126 BTRFS_SEND_A_OTIME = 12,
127
128 BTRFS_SEND_A_XATTR_NAME = 13,
129 BTRFS_SEND_A_XATTR_DATA = 14,
130
131 BTRFS_SEND_A_PATH = 15,
132 BTRFS_SEND_A_PATH_TO = 16,
133 BTRFS_SEND_A_PATH_LINK = 17,
134
135 BTRFS_SEND_A_FILE_OFFSET = 18,
136 /*
137 * As of send stream v2, this attribute is special: it must be the last
138 * attribute in a command, its header contains only the type, and its
139 * length is implicitly the remaining length of the command.
140 */
141 BTRFS_SEND_A_DATA = 19,
142
143 BTRFS_SEND_A_CLONE_UUID = 20,
144 BTRFS_SEND_A_CLONE_CTRANSID = 21,
145 BTRFS_SEND_A_CLONE_PATH = 22,
146 BTRFS_SEND_A_CLONE_OFFSET = 23,
147 BTRFS_SEND_A_CLONE_LEN = 24,
148
149 BTRFS_SEND_A_MAX_V1 = 24,
150
151 /* Version 2 */
152 BTRFS_SEND_A_FALLOCATE_MODE = 25,
153
154 /*
155 * File attributes from the FS_*_FL namespace (i_flags, xflags),
156 * translated to BTRFS_INODE_* bits (BTRFS_INODE_FLAG_MASK) and stored
157 * in btrfs_inode_item::flags (represented by btrfs_inode::flags and
158 * btrfs_inode::ro_flags).
159 */
160 BTRFS_SEND_A_FILEATTR = 26,
161
162 BTRFS_SEND_A_UNENCODED_FILE_LEN = 27,
163 BTRFS_SEND_A_UNENCODED_LEN = 28,
164 BTRFS_SEND_A_UNENCODED_OFFSET = 29,
165 /*
166 * COMPRESSION and ENCRYPTION default to NONE (0) if omitted from
167 * BTRFS_SEND_C_ENCODED_WRITE.
168 */
169 BTRFS_SEND_A_COMPRESSION = 30,
170 BTRFS_SEND_A_ENCRYPTION = 31,
171 BTRFS_SEND_A_MAX_V2 = 31,
172
173 /* Version 3 */
174 BTRFS_SEND_A_VERITY_ALGORITHM = 32,
175 BTRFS_SEND_A_VERITY_BLOCK_SIZE = 33,
176 BTRFS_SEND_A_VERITY_SALT_DATA = 34,
177 BTRFS_SEND_A_VERITY_SIG_DATA = 35,
178 BTRFS_SEND_A_MAX_V3 = 35,
179
180 __BTRFS_SEND_A_MAX = 35,
181};
182
183long btrfs_ioctl_send(struct inode *inode, struct btrfs_ioctl_send_args *arg);
184
185#endif
1/*
2 * Copyright (C) 2012 Alexander Block. All rights reserved.
3 * Copyright (C) 2012 STRATO. All rights reserved.
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public
7 * License v2 as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public
15 * License along with this program; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 021110-1307, USA.
18 */
19
20#include "ctree.h"
21
22#define BTRFS_SEND_STREAM_MAGIC "btrfs-stream"
23#define BTRFS_SEND_STREAM_VERSION 1
24
25#define BTRFS_SEND_BUF_SIZE SZ_64K
26#define BTRFS_SEND_READ_SIZE (48 * SZ_1K)
27
28enum btrfs_tlv_type {
29 BTRFS_TLV_U8,
30 BTRFS_TLV_U16,
31 BTRFS_TLV_U32,
32 BTRFS_TLV_U64,
33 BTRFS_TLV_BINARY,
34 BTRFS_TLV_STRING,
35 BTRFS_TLV_UUID,
36 BTRFS_TLV_TIMESPEC,
37};
38
39struct btrfs_stream_header {
40 char magic[sizeof(BTRFS_SEND_STREAM_MAGIC)];
41 __le32 version;
42} __attribute__ ((__packed__));
43
44struct btrfs_cmd_header {
45 /* len excluding the header */
46 __le32 len;
47 __le16 cmd;
48 /* crc including the header with zero crc field */
49 __le32 crc;
50} __attribute__ ((__packed__));
51
52struct btrfs_tlv_header {
53 __le16 tlv_type;
54 /* len excluding the header */
55 __le16 tlv_len;
56} __attribute__ ((__packed__));
57
58/* commands */
59enum btrfs_send_cmd {
60 BTRFS_SEND_C_UNSPEC,
61
62 BTRFS_SEND_C_SUBVOL,
63 BTRFS_SEND_C_SNAPSHOT,
64
65 BTRFS_SEND_C_MKFILE,
66 BTRFS_SEND_C_MKDIR,
67 BTRFS_SEND_C_MKNOD,
68 BTRFS_SEND_C_MKFIFO,
69 BTRFS_SEND_C_MKSOCK,
70 BTRFS_SEND_C_SYMLINK,
71
72 BTRFS_SEND_C_RENAME,
73 BTRFS_SEND_C_LINK,
74 BTRFS_SEND_C_UNLINK,
75 BTRFS_SEND_C_RMDIR,
76
77 BTRFS_SEND_C_SET_XATTR,
78 BTRFS_SEND_C_REMOVE_XATTR,
79
80 BTRFS_SEND_C_WRITE,
81 BTRFS_SEND_C_CLONE,
82
83 BTRFS_SEND_C_TRUNCATE,
84 BTRFS_SEND_C_CHMOD,
85 BTRFS_SEND_C_CHOWN,
86 BTRFS_SEND_C_UTIMES,
87
88 BTRFS_SEND_C_END,
89 BTRFS_SEND_C_UPDATE_EXTENT,
90 __BTRFS_SEND_C_MAX,
91};
92#define BTRFS_SEND_C_MAX (__BTRFS_SEND_C_MAX - 1)
93
94/* attributes in send stream */
95enum {
96 BTRFS_SEND_A_UNSPEC,
97
98 BTRFS_SEND_A_UUID,
99 BTRFS_SEND_A_CTRANSID,
100
101 BTRFS_SEND_A_INO,
102 BTRFS_SEND_A_SIZE,
103 BTRFS_SEND_A_MODE,
104 BTRFS_SEND_A_UID,
105 BTRFS_SEND_A_GID,
106 BTRFS_SEND_A_RDEV,
107 BTRFS_SEND_A_CTIME,
108 BTRFS_SEND_A_MTIME,
109 BTRFS_SEND_A_ATIME,
110 BTRFS_SEND_A_OTIME,
111
112 BTRFS_SEND_A_XATTR_NAME,
113 BTRFS_SEND_A_XATTR_DATA,
114
115 BTRFS_SEND_A_PATH,
116 BTRFS_SEND_A_PATH_TO,
117 BTRFS_SEND_A_PATH_LINK,
118
119 BTRFS_SEND_A_FILE_OFFSET,
120 BTRFS_SEND_A_DATA,
121
122 BTRFS_SEND_A_CLONE_UUID,
123 BTRFS_SEND_A_CLONE_CTRANSID,
124 BTRFS_SEND_A_CLONE_PATH,
125 BTRFS_SEND_A_CLONE_OFFSET,
126 BTRFS_SEND_A_CLONE_LEN,
127
128 __BTRFS_SEND_A_MAX,
129};
130#define BTRFS_SEND_A_MAX (__BTRFS_SEND_A_MAX - 1)
131
132#ifdef __KERNEL__
133long btrfs_ioctl_send(struct file *mnt_file, void __user *arg);
134#endif