Changeset 5e801dc in mainline for uspace/srv/fs


Ignore:
Timestamp:
2019-02-25T14:42:38Z (7 years ago)
Author:
GitHub <noreply@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
a4e78743
Parents:
ee8d4d6
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2019-02-25 14:42:38)
git-committer:
GitHub <noreply@…> (2019-02-25 14:42:38)
Message:

Indicate and enforce constness of hash table key in certain functions (#158)

The assumption here is that modifying key in the hash/equal functions in something completely unexpected, and not something you would ever want to do intentionally, so it makes sense to disallow it entirely to get that extra level of checking.

Location:
uspace/srv/fs
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fs/cdfs/cdfs_ops.c

    ree8d4d6 r5e801dc  
    285285} ht_key_t;
    286286
    287 static size_t nodes_key_hash(void *k)
    288 {
    289         ht_key_t *key = (ht_key_t *)k;
     287static size_t nodes_key_hash(const void *k)
     288{
     289        const ht_key_t *key = k;
    290290        return hash_combine(key->service_id, key->index);
    291291}
     
    297297}
    298298
    299 static bool nodes_key_equal(void *k, const ht_link_t *item)
     299static bool nodes_key_equal(const void *k, const ht_link_t *item)
    300300{
    301301        cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link);
    302         ht_key_t *key = (ht_key_t *)k;
     302        const ht_key_t *key = k;
    303303
    304304        return key->service_id == node->fs->service_id && key->index == node->index;
  • uspace/srv/fs/exfat/exfat_idx.c

    ree8d4d6 r5e801dc  
    117117} pos_key_t;
    118118
    119 static inline size_t pos_key_hash(void *key)
    120 {
    121         pos_key_t *pos = (pos_key_t *)key;
     119static inline size_t pos_key_hash(const void *key)
     120{
     121        const pos_key_t *pos = key;
    122122
    123123        size_t hash = 0;
     
    139139}
    140140
    141 static bool pos_key_equal(void *key, const ht_link_t *item)
    142 {
    143         pos_key_t *pos = (pos_key_t *)key;
     141static bool pos_key_equal(const void *key, const ht_link_t *item)
     142{
     143        const pos_key_t *pos = key;
    144144        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uph_link);
    145145
     
    168168} idx_key_t;
    169169
    170 static size_t idx_key_hash(void *key_arg)
    171 {
    172         idx_key_t *key = (idx_key_t *)key_arg;
     170static size_t idx_key_hash(const void *key_arg)
     171{
     172        const idx_key_t *key = key_arg;
    173173        return hash_combine(key->service_id, key->index);
    174174}
     
    180180}
    181181
    182 static bool idx_key_equal(void *key_arg, const ht_link_t *item)
     182static bool idx_key_equal(const void *key_arg, const ht_link_t *item)
    183183{
    184184        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uih_link);
    185         idx_key_t *key = (idx_key_t *)key_arg;
     185        const idx_key_t *key = key_arg;
    186186
    187187        return key->index == fidx->index && key->service_id == fidx->service_id;
  • uspace/srv/fs/fat/fat_idx.c

    ree8d4d6 r5e801dc  
    117117} pos_key_t;
    118118
    119 static inline size_t pos_key_hash(void *key)
    120 {
    121         pos_key_t *pos = (pos_key_t *)key;
     119static inline size_t pos_key_hash(const void *key)
     120{
     121        const pos_key_t *pos = key;
    122122
    123123        size_t hash = 0;
     
    139139}
    140140
    141 static bool pos_key_equal(void *key, const ht_link_t *item)
    142 {
    143         pos_key_t *pos = (pos_key_t *)key;
     141static bool pos_key_equal(const void *key, const ht_link_t *item)
     142{
     143        const pos_key_t *pos = key;
    144144        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uph_link);
    145145
     
    168168} idx_key_t;
    169169
    170 static size_t idx_key_hash(void *key_arg)
    171 {
    172         idx_key_t *key = (idx_key_t *)key_arg;
     170static size_t idx_key_hash(const void *key_arg)
     171{
     172        const idx_key_t *key = key_arg;
    173173        return hash_combine(key->service_id, key->index);
    174174}
     
    180180}
    181181
    182 static bool idx_key_equal(void *key_arg, const ht_link_t *item)
     182static bool idx_key_equal(const void *key_arg, const ht_link_t *item)
    183183{
    184184        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uih_link);
    185         idx_key_t *key = (idx_key_t *)key_arg;
     185        const idx_key_t *key = key_arg;
    186186
    187187        return key->index == fidx->index && key->service_id == fidx->service_id;
  • uspace/srv/fs/locfs/locfs_ops.c

    ree8d4d6 r5e801dc  
    7171/* Implementation of hash table interface for the nodes hash table. */
    7272
    73 static size_t services_key_hash(void *key)
    74 {
    75         return *(service_id_t *)key;
     73static size_t services_key_hash(const void *key)
     74{
     75        const service_id_t *k = key;
     76        return *k;
    7677}
    7778
     
    8283}
    8384
    84 static bool services_key_equal(void *key, const ht_link_t *item)
    85 {
     85static bool services_key_equal(const void *key, const ht_link_t *item)
     86{
     87        const service_id_t *k = key;
    8688        service_t *dev = hash_table_get_inst(item, service_t, link);
    87         return (dev->service_id == *(service_id_t *)key);
     89        return (dev->service_id == *k);
    8890}
    8991
  • uspace/srv/fs/mfs/mfs_ops.c

    ree8d4d6 r5e801dc  
    100100
    101101static size_t
    102 open_nodes_key_hash(void *key)
    103 {
    104         node_key_t *node_key = (node_key_t *)key;
     102open_nodes_key_hash(const void *key)
     103{
     104        const node_key_t *node_key = key;
    105105        return hash_combine(node_key->service_id, node_key->index);
    106106}
     
    114114
    115115static bool
    116 open_nodes_key_equal(void *key, const ht_link_t *item)
    117 {
    118         node_key_t *node_key = (node_key_t *)key;
     116open_nodes_key_equal(const void *key, const ht_link_t *item)
     117{
     118        const node_key_t *node_key = key;
    119119        struct mfs_node *mnode = hash_table_get_inst(item, struct mfs_node, link);
    120120
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    ree8d4d6 r5e801dc  
    147147} node_key_t;
    148148
    149 static size_t nodes_key_hash(void *k)
    150 {
    151         node_key_t *key = (node_key_t *)k;
     149static size_t nodes_key_hash(const void *k)
     150{
     151        const node_key_t *key = k;
    152152        return hash_combine(key->service_id, key->index);
    153153}
     
    159159}
    160160
    161 static bool nodes_key_equal(void *key_arg, const ht_link_t *item)
     161static bool nodes_key_equal(const void *key_arg, const ht_link_t *item)
    162162{
    163163        tmpfs_node_t *node = hash_table_get_inst(item, tmpfs_node_t, nh_link);
    164         node_key_t *key = (node_key_t *)key_arg;
     164        const node_key_t *key = key_arg;
    165165
    166166        return key->service_id == node->service_id && key->index == node->index;
  • uspace/srv/fs/udf/udf_idx.c

    ree8d4d6 r5e801dc  
    6363}
    6464
    65 static size_t udf_idx_key_hash(void *k)
    66 {
    67         udf_ht_key_t *key = (udf_ht_key_t *) k;
     65static size_t udf_idx_key_hash(const void *k)
     66{
     67        const udf_ht_key_t *key = k;
    6868        return hash_combine(key->service_id, key->index);
    6969}
    7070
    71 static bool udf_idx_key_equal(void *k, const ht_link_t *item)
    72 {
    73         udf_ht_key_t *key = (udf_ht_key_t *) k;
     71static bool udf_idx_key_equal(const void *k, const ht_link_t *item)
     72{
     73        const udf_ht_key_t *key = k;
    7474        udf_node_t *node = hash_table_get_inst(item, udf_node_t, link);
    7575
Note: See TracChangeset for help on using the changeset viewer.