OSDN Git Service

Avoid name length calculation in exfat_calc_name_hash().
authorrelan <relan@users.noreply.github.com>
Fri, 16 Dec 2016 05:52:32 +0000 (08:52 +0300)
committerrelan <relan@users.noreply.github.com>
Mon, 26 Dec 2016 07:01:18 +0000 (10:01 +0300)
We always know it when exfat_calc_name_hash() is called, so pass file
name length as an argument.

libexfat/exfat.h
libexfat/node.c
libexfat/utils.c

index 795bf47..78da924 100644 (file)
@@ -184,7 +184,8 @@ le16_t exfat_calc_checksum(const struct exfat_entry_meta1* meta1,
                const struct exfat_entry_meta2* meta2, const le16_t* name);
 uint32_t exfat_vbr_start_checksum(const void* sector, size_t size);
 uint32_t exfat_vbr_add_checksum(const void* sector, size_t size, uint32_t sum);
-le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name);
+le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name,
+               size_t length);
 void exfat_humanize_bytes(uint64_t value, struct exfat_human_bytes* hb);
 void exfat_print_info(const struct exfat_super_block* sb,
                uint32_t free_clusters);
index 90002eb..94061b4 100644 (file)
@@ -957,7 +957,7 @@ static int write_entry(struct exfat* ef, struct exfat_node* dir,
        meta2.type = EXFAT_ENTRY_FILE_INFO;
        meta2.flags = EXFAT_FLAG_ALWAYS1;
        meta2.name_length = name_length;
-       meta2.name_hash = exfat_calc_name_hash(ef, node->name);
+       meta2.name_hash = exfat_calc_name_hash(ef, node->name, name_length);
        meta2.start_cluster = cpu_to_le32(EXFAT_CLUSTER_FREE);
 
        meta1.checksum = exfat_calc_checksum(&meta1, &meta2, node->name);
@@ -1099,7 +1099,7 @@ static int rename_entry(struct exfat* ef, struct exfat_node* dir,
                return -EIO;
        }
        meta1.continuations = 1 + name_entries;
-       meta2.name_hash = exfat_calc_name_hash(ef, name);
+       meta2.name_hash = exfat_calc_name_hash(ef, name, name_length);
        meta2.name_length = name_length;
        meta1.checksum = exfat_calc_checksum(&meta1, &meta2, name);
 
index e0523e0..8e7cd3e 100644 (file)
@@ -122,10 +122,10 @@ uint32_t exfat_vbr_add_checksum(const void* sector, size_t size, uint32_t sum)
        return sum;
 }
 
-le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name)
+le16_t exfat_calc_name_hash(const struct exfat* ef, const le16_t* name,
+               size_t length)
 {
        size_t i;
-       size_t length = utf16_length(name);
        uint16_t hash = 0;
 
        for (i = 0; i < length; i++)