@@ -1698,7 +1698,6 @@ static int process_file_extent(struct btrfs_root *root,
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (extent_type == BTRFS_FILE_EXTENT_PREALLOC &&
(btrfs_file_extent_compression(eb, fi) ||
- btrfs_file_extent_encryption(eb, fi) ||
btrfs_file_extent_other_encoding(eb, fi)))
rec->errors |= I_ERR_BAD_FILE_EXTENT;
if (compression && rec->nodatasum)
@@ -6352,6 +6351,7 @@ static int run_next_block(struct btrfs_root *root,
for (i = 0; i < nritems; i++) {
struct btrfs_file_extent_item *fi;
unsigned long inline_offset;
+ size_t extra_size = 0;
inline_offset = offsetof(struct btrfs_file_extent_item,
disk_bytenr);
@@ -6487,13 +6487,19 @@ static int run_next_block(struct btrfs_root *root,
continue;
/* Prealloc/regular extent must have fixed item size */
+ if (btrfs_file_extent_encryption(buf, fi))
+ extra_size = btrfs_file_extent_encryption_info_size(buf, fi) +
+ sizeof(struct btrfs_encryption_info);
+
if (btrfs_item_size(buf, i) !=
- sizeof(struct btrfs_file_extent_item)) {
+ (sizeof(struct btrfs_file_extent_item) +
+ extra_size)) {
ret = -EUCLEAN;
error(
"invalid file extent item size, have %u expect %zu",
btrfs_item_size(buf, i),
- sizeof(struct btrfs_file_extent_item));
+ sizeof(struct btrfs_file_extent_item) +
+ extra_size);
continue;
}
/* key.offset (file offset) must be aligned */
@@ -356,6 +356,26 @@ static void compress_type_to_str(u8 compress_type, char *ret)
}
}
+static void generate_encryption_string(struct extent_buffer *leaf,
+ struct btrfs_file_extent_item *fi,
+ char *ret)
+{
+ u8 policy = btrfs_file_extent_encryption(leaf, fi);
+ u32 ctxsize = btrfs_file_extent_encryption_ctx_size(leaf, fi);
+ const __u8 *ctx = (__u8 *)(leaf->data +
+ btrfs_file_extent_encryption_ctx_offset(fi));
+
+ ret += sprintf(ret, "(%hhu, %u", policy, ctxsize);
+
+ if (ctxsize) {
+ int i;
+ ret += sprintf(ret, ": context ");
+ for (i = 0; i < ctxsize; i++)
+ ret += sprintf(ret, "%02hhx", ctx[i]);
+ }
+ sprintf(ret, ")");
+}
+
static const char* file_extent_type_to_str(u8 type)
{
switch (type) {
@@ -372,9 +392,11 @@ static void print_file_extent_item(struct extent_buffer *eb,
{
unsigned char extent_type = btrfs_file_extent_type(eb, fi);
char compress_str[16];
+ char encrypt_str[16];
compress_type_to_str(btrfs_file_extent_compression(eb, fi),
compress_str);
+ generate_encryption_string(eb, fi, encrypt_str);
printf("\t\tgeneration %llu type %hhu (%s)\n",
btrfs_file_extent_generation(eb, fi),
@@ -407,6 +429,9 @@ static void print_file_extent_item(struct extent_buffer *eb,
printf("\t\textent compression %hhu (%s)\n",
btrfs_file_extent_compression(eb, fi),
compress_str);
+ printf("\t\textent encryption %hhu (%s)\n",
+ btrfs_file_extent_encryption(eb, fi),
+ encrypt_str);
}
/* Caller should ensure sizeof(*ret) >= 16("DATA|TREE_BLOCK") */