send.h 4.3 KB

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