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