]> git.tuebingen.mpg.de Git - osl.git/commitdiff
Prepare hash_function() for multiple hash algorithms.
authorAndre Noll <maan@tuebingen.mpg.de>
Wed, 19 Apr 2017 13:12:44 +0000 (15:12 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 17 Jun 2020 20:30:31 +0000 (22:30 +0200)
In order to transparently support more than one hash function in the
future, we now pass the table version to hash_function(). The version
is always one at the moment, and only the sha1 hash is implemented
so far.

fsck.c
hash.h
osl.c
osl_core.h

diff --git a/fsck.c b/fsck.c
index 8a32abae24dc38d49821711d0acc0511a3ff0872..42312d9fb472463963b84b3fb93c7190a05ddc7c 100644 (file)
--- a/fsck.c
+++ b/fsck.c
@@ -718,7 +718,7 @@ static int check_disk_storage_presence(struct osl_table *t)
                ret = get_mapped_object(t, dsnc, i, &obj);
                if (ret < 0)
                        return ret;
-               hash_object(&obj, hashes + i * HASH_SIZE);
+               hash_object(t, &obj, hashes + i * HASH_SIZE);
                hash_obj.data = hashes + i * HASH_SIZE;
                osl_add_row(hash_tree_table, &hash_obj);
                ds_name = disk_storage_name_of_hash(t, hashes + i * HASH_SIZE);
@@ -1041,7 +1041,7 @@ static int dump_row(struct osl_table *t, unsigned row_num, const char *row_dir)
        ret = get_mapped_object(t, dsnc, row_num, &obj);
        if (ret < 0)
                return ret;
-       hash_object(&obj, hash);
+       hash_object(t, &obj, hash);
        ds_name = disk_storage_name_of_hash(t, hash);
        FOR_EACH_DISK_STORAGE_COLUMN(i, t, cd) {
                filename = disk_storage_path(t, i, ds_name);
diff --git a/hash.h b/hash.h
index 6244d081e178c69281eb6c3b2dfbcd0e38cfbeaa..08153383218a36bdd664508b920e2725153656b4 100644 (file)
--- a/hash.h
+++ b/hash.h
 
 void sha1_hash(const char *data, unsigned long len, unsigned char *sha1);
 
-/** Our own sha1 implementation, see sha1.c. */
-#define hash_function sha1_hash
+static inline void hash_function(uint8_t table_version, const char *data,
+               unsigned long len, unsigned char *result)
+{
+       assert(table_version == 1);
+       sha1_hash(data, len, result);
+}
 
 /**
  * Compare two hashes.
diff --git a/osl.c b/osl.c
index 40b0a24f38bea36b2379836ee447f0e2923e726d..8e19bc403ae79f1ff94ee7e0fafe04af8598e42a 100644 (file)
--- a/osl.c
+++ b/osl.c
@@ -168,7 +168,7 @@ static char *disk_storage_name_of_object(const struct osl_table *t,
        const struct osl_object *obj)
 {
        HASH_TYPE hash[HASH_SIZE];
-       hash_object(obj, hash);
+       hash_object(t, obj, hash);
        return disk_storage_name_of_hash(t, hash);
 }
 
@@ -186,9 +186,10 @@ static int disk_storage_name_of_row(const struct osl_table *t,
        return -E_OSL_NOMEM;
 }
 
-static void column_name_hash(const char *col_name, HASH_TYPE *hash)
+static void column_name_hash(const struct osl_table *t, const char *col_name,
+               HASH_TYPE *hash)
 {
-       hash_function(col_name, strlen(col_name), hash);
+       hash_function(t->version, col_name, strlen(col_name), hash);
 }
 
 static int init_column_descriptions(struct osl_table *t)
@@ -553,7 +554,7 @@ __export int osl_create_table(const struct osl_table_description *desc)
                        if (ret < 0)
                                goto out;
                }
-               column_name_hash(cd->name, t->columns[i].name_hash);
+               column_name_hash(t, cd->name, t->columns[i].name_hash);
                ret = -E_OSL_NOMEM;
                filename = column_filename(t, i);
                if (!filename)
@@ -724,7 +725,7 @@ int map_table(struct osl_table *t, enum map_table_flags flags)
        FOR_EACH_COLUMN(i, t->desc, cd) {
                if (cd->storage_type == OSL_NO_STORAGE)
                        continue;
-               column_name_hash(cd->name, t->columns[i].name_hash);
+               column_name_hash(t, cd->name, t->columns[i].name_hash);
                if (num_rows > 0 && cd->storage_type == OSL_MAPPED_STORAGE) {
                        ret = map_column(t, i);
                        if (ret < 0)
index 9879b1e316d1e358fe110d1b6fb31a1f95ef96ad..91489c95a3aa3b606652568c02ece75bc5158ffa 100644 (file)
@@ -456,12 +456,14 @@ _static_inline_ struct osl_row *get_row_pointer(const struct rb_node *node,
 /**
  * Compute a cryptographic hash of an osl object.
  *
+ * \param t Determines the hash function to use.
  * \param obj the Object to compute the hash value from.
  * \param hash Result is returned here.
  */
-_static_inline_ void hash_object(const struct osl_object *obj, HASH_TYPE *hash)
+_static_inline_ void hash_object(const struct osl_table *t,
+               const struct osl_object *obj, HASH_TYPE *hash)
 {
-       hash_function(obj->data, obj->size, hash);
+       hash_function(t->version, obj->data, obj->size, hash);
 }
 
 /**