@@ -1418,7 +1418,7 @@ static int process_dir_item(struct extent_buffer *eb,
btrfs_dir_item_key_to_cpu(eb, di, &location);
name_len = btrfs_dir_name_len(eb, di);
data_len = btrfs_dir_data_len(eb, di);
- filetype = btrfs_dir_type(eb, di);
+ filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, di));
rec->found_size += name_len;
if (cur + sizeof(*di) + name_len > total ||
@@ -2122,7 +2122,7 @@ static int add_missing_dir_index(struct btrfs_root *root,
disk_key.offset = 0;
btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
- btrfs_set_dir_type(leaf, dir_item, imode_to_type(rec->imode));
+ btrfs_set_dir_flags(leaf, dir_item, imode_to_type(rec->imode));
btrfs_set_dir_data_len(leaf, dir_item, 0);
btrfs_set_dir_name_len(leaf, dir_item, backref->namelen);
name_ptr = (unsigned long)(dir_item + 1);
@@ -754,7 +754,7 @@ static int find_file_type_dir_index(struct btrfs_root *root, u64 ino, u64 dirid,
if (location.objectid != ino || location.type != BTRFS_INODE_ITEM_KEY ||
location.offset != 0)
goto out;
- filetype = btrfs_dir_type(path.nodes[0], di);
+ filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(path.nodes[0], di));
if (filetype >= BTRFS_FT_MAX || filetype == BTRFS_FT_UNKNOWN)
goto out;
len = min_t(u32, BTRFS_NAME_LEN,
@@ -813,7 +813,7 @@ static int find_file_type_dir_item(struct btrfs_root *root, u64 ino, u64 dirid,
location.type != BTRFS_INODE_ITEM_KEY ||
location.offset != 0)
continue;
- filetype = btrfs_dir_type(path.nodes[0], di);
+ filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(path.nodes[0], di));
if (filetype >= BTRFS_FT_MAX || filetype == BTRFS_FT_UNKNOWN)
continue;
len = min_t(u32, BTRFS_NAME_LEN,
@@ -856,7 +856,7 @@ loop:
location.offset != 0)
goto next;
- filetype = btrfs_dir_type(node, di);
+ filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(node, di));
if (file_type != filetype)
goto next;
@@ -954,7 +954,7 @@ static int find_dir_item(struct btrfs_root *root, struct btrfs_key *key,
location.offset != location_key->offset)
goto next;
- filetype = btrfs_dir_type(node, di);
+ filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(node, di));
if (file_type != filetype)
goto next;
@@ -1744,7 +1744,7 @@ begin:
(*size) += name_len;
read_extent_buffer(node, namebuf, (unsigned long)(di + 1),
len);
- filetype = btrfs_dir_type(node, di);
+ filetype = btrfs_dir_flags_to_ftype(btrfs_dir_flags(node, di));
if (di_key->type == BTRFS_DIR_ITEM_KEY &&
di_key->offset != btrfs_name_hash(namebuf, len)) {
@@ -991,7 +991,7 @@ static int search_dir(struct btrfs_root *root, struct btrfs_key *key,
name_len = btrfs_dir_name_len(leaf, dir_item);
read_extent_buffer(leaf, filename, name_ptr, name_len);
filename[name_len] = '\0';
- type = btrfs_dir_type(leaf, dir_item);
+ type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(leaf, dir_item));
btrfs_dir_item_key_to_cpu(leaf, dir_item, &location);
/* full path from root of btrfs being restored */
@@ -176,6 +176,14 @@ enum btrfs_csum_type {
#define BTRFS_FT_XATTR 8
#define BTRFS_FT_MAX 9
+/* Name is encrypted */
+#define BTRFS_FT_FSCRYPT_NAME 0x80
+
+static inline __u8 btrfs_dir_flags_to_ftype(__u8 flags)
+{
+ return flags & ~BTRFS_FT_FSCRYPT_NAME;
+}
+
#define BTRFS_ROOT_SUBVOL_RDONLY (1ULL << 0)
/*
@@ -2039,15 +2047,21 @@ BTRFS_SETGET_STACK_FUNCS(stack_root_ref_name_len, struct btrfs_root_ref, name_le
/* struct btrfs_dir_item */
BTRFS_SETGET_FUNCS(dir_data_len, struct btrfs_dir_item, data_len, 16);
-BTRFS_SETGET_FUNCS(dir_type, struct btrfs_dir_item, type, 8);
+BTRFS_SETGET_FUNCS(dir_flags, struct btrfs_dir_item, type, 8);
BTRFS_SETGET_FUNCS(dir_name_len, struct btrfs_dir_item, name_len, 16);
BTRFS_SETGET_FUNCS(dir_transid, struct btrfs_dir_item, transid, 64);
BTRFS_SETGET_STACK_FUNCS(stack_dir_data_len, struct btrfs_dir_item, data_len, 16);
-BTRFS_SETGET_STACK_FUNCS(stack_dir_type, struct btrfs_dir_item, type, 8);
+BTRFS_SETGET_STACK_FUNCS(stack_dir_flags, struct btrfs_dir_item, type, 8);
BTRFS_SETGET_STACK_FUNCS(stack_dir_name_len, struct btrfs_dir_item, name_len, 16);
BTRFS_SETGET_STACK_FUNCS(stack_dir_transid, struct btrfs_dir_item, transid, 64);
+static inline __u8 btrfs_dir_ftype(const struct extent_buffer *eb,
+ const struct btrfs_dir_item *item)
+{
+ return btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, item));
+}
+
static inline void btrfs_dir_item_key(struct extent_buffer *eb,
struct btrfs_dir_item *item,
struct btrfs_disk_key *key)
@@ -89,7 +89,7 @@ int btrfs_insert_xattr_item(struct btrfs_trans_handle *trans,
leaf = path->nodes[0];
btrfs_cpu_key_to_disk(&disk_key, &location);
btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
- btrfs_set_dir_type(leaf, dir_item, BTRFS_FT_XATTR);
+ btrfs_set_dir_flags(leaf, dir_item, BTRFS_FT_XATTR);
btrfs_set_dir_name_len(leaf, dir_item, name_len);
btrfs_set_dir_data_len(leaf, dir_item, data_len);
name_ptr = (unsigned long)(dir_item + 1);
@@ -141,7 +141,7 @@ int btrfs_insert_dir_item(struct btrfs_trans_handle *trans, struct btrfs_root
leaf = path->nodes[0];
btrfs_cpu_key_to_disk(&disk_key, location);
btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
- btrfs_set_dir_type(leaf, dir_item, type);
+ btrfs_set_dir_flags(leaf, dir_item, type);
btrfs_set_dir_data_len(leaf, dir_item, 0);
btrfs_set_dir_name_len(leaf, dir_item, name_len);
name_ptr = (unsigned long)(dir_item + 1);
@@ -170,7 +170,7 @@ insert:
leaf = path->nodes[0];
btrfs_cpu_key_to_disk(&disk_key, location);
btrfs_set_dir_item_key(leaf, dir_item, &disk_key);
- btrfs_set_dir_type(leaf, dir_item, type);
+ btrfs_set_dir_flags(leaf, dir_item, type);
btrfs_set_dir_data_len(leaf, dir_item, 0);
btrfs_set_dir_name_len(leaf, dir_item, name_len);
name_ptr = (unsigned long)(dir_item + 1);
@@ -292,7 +292,7 @@ static int verify_dir_item(struct btrfs_root *root,
struct btrfs_dir_item *dir_item)
{
u16 namelen = BTRFS_NAME_LEN;
- u8 type = btrfs_dir_type(leaf, dir_item);
+ u8 type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(leaf, dir_item));
if (type == BTRFS_FT_XATTR)
namelen = XATTR_NAME_MAX;
@@ -541,6 +541,7 @@ int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root,
if (dir_item) {
struct btrfs_key found_key;
+ u8 type;
/*
* Already have conflicting name, check if it is a dir.
@@ -548,7 +549,8 @@ int btrfs_mkdir(struct btrfs_trans_handle *trans, struct btrfs_root *root,
*/
btrfs_dir_item_key_to_cpu(path->nodes[0], dir_item, &found_key);
ret_ino = found_key.objectid;
- if (btrfs_dir_type(path->nodes[0], dir_item) != BTRFS_FT_DIR)
+ type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(path->nodes[0], dir_item));
+ if (type != BTRFS_FT_DIR)
ret = -EEXIST;
goto out;
}
@@ -31,7 +31,7 @@
static void print_dir_item_type(struct extent_buffer *eb,
struct btrfs_dir_item *di)
{
- u8 type = btrfs_dir_type(eb, di);
+ u8 type = btrfs_dir_flags_to_ftype(btrfs_dir_flags(eb, di));
static const char* dir_item_str[] = {
[BTRFS_FT_REG_FILE] = "FILE",
[BTRFS_FT_DIR] = "DIR",
@@ -322,6 +322,9 @@
#define BTRFS_FT_XATTR 8
#define BTRFS_FT_MAX 9
+/* Name is encrypted */
+#define BTRFS_FT_FSCRYPT_NAME 0x80
+
/*
* The key defines the order in the tree, and so it also defines (optimal)
* block layout.
The advent of encryption necessitates converting the directory type into a directory type and a flag indicating encryption. Thus, rename the field dir_type to dir_flags. For those uses which don't care about encryption and just want to know what type the directory is, a new helper is added to strip the encryption flag. This renaming, and use of the helper where appropriate, is reflected throughout the codebase. Signed-off-by: Sweet Tea Dorminy <sweettea-kernel@dorminy.me> --- check/main.c | 4 ++-- check/mode-common.c | 4 ++-- check/mode-lowmem.c | 6 +++--- cmds/restore.c | 2 +- kernel-shared/ctree.h | 18 ++++++++++++++++-- kernel-shared/dir-item.c | 8 ++++---- kernel-shared/inode.c | 4 +++- kernel-shared/print-tree.c | 2 +- libbtrfsutil/btrfs_tree.h | 3 +++ 9 files changed, 35 insertions(+), 16 deletions(-)