@@ -2775,7 +2775,10 @@ static inline void btrfs_crc32c_final(u32 crc, u8 *result)
static inline u64 btrfs_name_hash(struct fscrypt_name *name)
{
- return crc32c((u32)~1, fname_name(name), fname_len(name));
+ if (fname_name(name))
+ return crc32c((u32)~1, fname_name(name), fname_len(name));
+ else
+ return name->hash | ((u64)name->minor_hash << 32);
}
/*
@@ -2784,8 +2787,20 @@ static inline u64 btrfs_name_hash(struct fscrypt_name *name)
static inline u64 btrfs_extref_hash(u64 parent_objectid,
struct fscrypt_name *name)
{
- return (u64) crc32c(parent_objectid, fname_name(name),
- fname_len(name));
+ /*
+ * If the name is encrypted and we don't have the key, we can use the
+ * fscrypt-provided hash instead of the normal name, and do the steps
+ * of crc32c() manually. Else, just hash the name, parent objectid,
+ * and name length.
+ */
+ if (fname_name(name))
+ return (u64) crc32c(parent_objectid, fname_name(name),
+ fname_len(name));
+ else
+ return (__crc32c_le_combine(parent_objectid,
+ name->hash,
+ fname_len(name)) ^
+ __crc32c_le_shift(~1, fname_len(name)));
}
static inline gfp_t btrfs_alloc_write_mask(struct address_space *mapping)