Changeset 4c53333 in mainline for uspace/srv/fs


Ignore:
Timestamp:
2013-07-11T08:21:10Z (12 years ago)
Author:
Maurizio Lombardi <m.lombardi85@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
64e63ce1
Parents:
80445cf (diff), c8bb1633 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

merge mainline changes

Location:
uspace/srv/fs
Files:
16 added
1 deleted
26 edited
3 moved

Legend:

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

    r80445cf r4c53333  
    3737 */
    3838
    39 #include <bool.h>
     39#include "cdfs_ops.h"
     40#include <stdbool.h>
    4041#include <adt/hash_table.h>
     42#include <adt/hash.h>
    4143#include <malloc.h>
    4244#include <mem.h>
     
    4446#include <libfs.h>
    4547#include <errno.h>
    46 #include <libblock.h>
     48#include <block.h>
    4749#include <str.h>
    4850#include <byteorder.h>
     
    5052#include "cdfs.h"
    5153#include "cdfs_endian.h"
    52 #include "cdfs_ops.h"
    5354
    5455/** Standard CD-ROM block size */
    5556#define BLOCK_SIZE  2048
    5657
    57 /** Implicit node cache size
    58  *
    59  * More nodes can be actually cached if the files remain
    60  * opended.
    61  *
    62  */
    63 #define NODE_CACHE_SIZE  200
    64 
    65 #define NODES_BUCKETS  256
    66 
    67 #define NODES_KEY_SRVC   0
    68 #define NODES_KEY_INDEX  1
     58#define NODE_CACHE_SIZE 200
    6959
    7060/** All root nodes have index 0 */
     
    205195        service_id_t service_id;  /**< Service ID of block device */
    206196       
    207         link_t nh_link;           /**< Nodes hash table link */
     197        ht_link_t nh_link;        /**< Nodes hash table link */
    208198        cdfs_dentry_type_t type;  /**< Dentry type */
    209199       
     
    226216static hash_table_t nodes;
    227217
    228 static hash_index_t nodes_hash(unsigned long key[])
    229 {
    230         return key[NODES_KEY_INDEX] % NODES_BUCKETS;
    231 }
    232 
    233 static int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)
    234 {
    235         cdfs_node_t *node =
    236             hash_table_get_instance(item, cdfs_node_t, nh_link);
    237        
    238         switch (keys) {
    239         case 1:
    240                 return (node->service_id == key[NODES_KEY_SRVC]);
    241         case 2:
    242                 return ((node->service_id == key[NODES_KEY_SRVC]) &&
    243                     (node->index == key[NODES_KEY_INDEX]));
    244         default:
    245                 assert((keys == 1) || (keys == 2));
    246         }
    247        
    248         return 0;
    249 }
    250 
    251 static void nodes_remove_callback(link_t *item)
    252 {
    253         cdfs_node_t *node =
    254             hash_table_get_instance(item, cdfs_node_t, nh_link);
     218/*
     219 * Hash table support functions.
     220 */
     221
     222typedef struct {
     223        service_id_t service_id;
     224    fs_index_t index;
     225} ht_key_t;
     226
     227static size_t nodes_key_hash(void *k)
     228{
     229        ht_key_t *key = (ht_key_t*)k;
     230        return hash_combine(key->service_id, key->index);
     231}
     232
     233static size_t nodes_hash(const ht_link_t *item)
     234{
     235        cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link);
     236        return hash_combine(node->service_id, node->index);
     237}
     238
     239static bool nodes_key_equal(void *k, const ht_link_t *item)
     240{
     241        cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link);
     242        ht_key_t *key = (ht_key_t*)k;
     243       
     244        return key->service_id == node->service_id && key->index == node->index;
     245}
     246
     247static void nodes_remove_callback(ht_link_t *item)
     248{
     249        cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link);
    255250       
    256251        assert(node->type == CDFS_DIRECTORY);
     
    268263
    269264/** Nodes hash table operations */
    270 static hash_table_operations_t nodes_ops = {
     265static hash_table_ops_t nodes_ops = {
    271266        .hash = nodes_hash,
    272         .compare = nodes_compare,
     267        .key_hash = nodes_key_hash,
     268        .key_equal = nodes_key_equal,
     269        .equal = NULL,
    273270        .remove_callback = nodes_remove_callback
    274271};
     
    277274    fs_index_t index)
    278275{
    279         unsigned long key[] = {
    280                 [NODES_KEY_SRVC] = service_id,
    281                 [NODES_KEY_INDEX] = index
     276        ht_key_t key = {
     277                .index = index,
     278                .service_id = service_id
    282279        };
    283280       
    284         link_t *link = hash_table_find(&nodes, key);
     281        ht_link_t *link = hash_table_find(&nodes, &key);
    285282        if (link) {
    286283                cdfs_node_t *node =
    287                     hash_table_get_instance(link, cdfs_node_t, nh_link);
     284                    hash_table_get_inst(link, cdfs_node_t, nh_link);
    288285               
    289286                *rfn = FS_NODE(node);
     
    311308        node->opened = 0;
    312309       
    313         link_initialize(&node->nh_link);
    314310        list_initialize(&node->cs_list);
    315311}
     
    353349       
    354350        /* Insert the new node into the nodes hash table. */
    355         unsigned long key[] = {
    356                 [NODES_KEY_SRVC] = node->service_id,
    357                 [NODES_KEY_INDEX] = node->index
    358         };
    359        
    360         hash_table_insert(&nodes, key, &node->nh_link);
     351        hash_table_insert(&nodes, &node->nh_link);
    361352       
    362353        *rfn = FS_NODE(node);
     
    508499static fs_node_t *get_cached_node(service_id_t service_id, fs_index_t index)
    509500{
    510         unsigned long key[] = {
    511                 [NODES_KEY_SRVC] = service_id,
    512                 [NODES_KEY_INDEX] = index
     501        ht_key_t key = {
     502                .index = index,
     503                .service_id = service_id
    513504        };
    514505       
    515         link_t *link = hash_table_find(&nodes, key);
     506        ht_link_t *link = hash_table_find(&nodes, &key);
    516507        if (link) {
    517508                cdfs_node_t *node =
    518                     hash_table_get_instance(link, cdfs_node_t, nh_link);
     509                    hash_table_get_inst(link, cdfs_node_t, nh_link);
    519510                return FS_NODE(node);
    520511        }
     
    669660         */
    670661        if ((vol_desc->type != VOL_DESC_PRIMARY) ||
    671             (bcmp(vol_desc->standard_ident, CDFS_STANDARD_IDENT, 5) != 0) ||
     662            (memcmp(vol_desc->standard_ident, CDFS_STANDARD_IDENT, 5) != 0) ||
    672663            (vol_desc->version != 1)) {
    673664                block_put(block);
     
    802793}
    803794
     795static bool rm_service_id_nodes(ht_link_t *item, void *arg)
     796{
     797        service_id_t service_id = *(service_id_t*)arg;
     798        cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link);
     799       
     800        if (node->service_id == service_id) {
     801                hash_table_remove_item(&nodes, &node->nh_link);
     802        }
     803       
     804        return true;
     805}
     806
    804807static void cdfs_instance_done(service_id_t service_id)
    805808{
    806         unsigned long key[] = {
    807                 [NODES_KEY_SRVC] = service_id
    808         };
    809        
    810         hash_table_remove(&nodes, key, 1);
     809        hash_table_apply(&nodes, rm_service_id_nodes, &service_id);
    811810        block_cache_fini(service_id);
    812811        block_fini(service_id);
     
    822821    size_t *rbytes)
    823822{
    824         unsigned long key[] = {
    825                 [NODES_KEY_SRVC] = service_id,
    826                 [NODES_KEY_INDEX] = index
     823        ht_key_t key = {
     824                .index = index,
     825                .service_id = service_id
    827826        };
    828827       
    829         link_t *link = hash_table_find(&nodes, key);
     828        ht_link_t *link = hash_table_find(&nodes, &key);
    830829        if (link == NULL)
    831830                return ENOENT;
    832831       
    833832        cdfs_node_t *node =
    834             hash_table_get_instance(link, cdfs_node_t, nh_link);
     833            hash_table_get_inst(link, cdfs_node_t, nh_link);
    835834       
    836835        if (!node->processed) {
     
    912911}
    913912
     913static bool cache_remove_closed(ht_link_t *item, void *arg)
     914{
     915        size_t *premove_cnt = (size_t*)arg;
     916       
     917        /* Some nodes were requested to be removed from the cache. */
     918        if (0 < *premove_cnt) {
     919                cdfs_node_t *node =     hash_table_get_inst(item, cdfs_node_t, nh_link);
     920
     921                if (!node->opened) {
     922                        hash_table_remove_item(&nodes, item);
     923                       
     924                        --nodes_cached;
     925                        --*premove_cnt;
     926                }
     927        }
     928       
     929        /* Only continue if more nodes were requested to be removed. */
     930        return 0 < *premove_cnt;
     931}
     932
    914933static void cleanup_cache(service_id_t service_id)
    915934{
    916935        if (nodes_cached > NODE_CACHE_SIZE) {
    917                 size_t remove = nodes_cached - NODE_CACHE_SIZE;
    918                
    919                 // FIXME: this accesses the internals of the hash table
    920                 //        and should be rewritten in a clean way
    921                
    922                 for (hash_index_t chain = 0; chain < nodes.entries; chain++) {
    923                         for (link_t *link = nodes.entry[chain].head.next;
    924                             link != &nodes.entry[chain].head;
    925                             link = link->next) {
    926                                 if (remove == 0)
    927                                         return;
    928                                
    929                                 cdfs_node_t *node =
    930                                     hash_table_get_instance(link, cdfs_node_t, nh_link);
    931                                 if (node->opened == 0) {
    932                                         link_t *tmp = link;
    933                                         link = link->prev;
    934                                        
    935                                         list_remove(tmp);
    936                                         nodes.op->remove_callback(tmp);
    937                                         nodes_cached--;
    938                                         remove--;
    939                                        
    940                                         continue;
    941                                 }
    942                         }
    943                 }
     936                size_t remove_cnt = nodes_cached - NODE_CACHE_SIZE;
     937               
     938                if (0 < remove_cnt)
     939                        hash_table_apply(&nodes, cache_remove_closed, &remove_cnt);
    944940        }
    945941}
     
    951947                return EOK;
    952948       
    953         unsigned long key[] = {
    954                 [NODES_KEY_SRVC] = service_id,
    955                 [NODES_KEY_INDEX] = index
     949        ht_key_t key = {
     950                .index = index,
     951                .service_id = service_id
    956952        };
    957953       
    958         link_t *link = hash_table_find(&nodes, key);
     954        ht_link_t *link = hash_table_find(&nodes, &key);
    959955        if (link == 0)
    960956                return ENOENT;
    961957       
    962958        cdfs_node_t *node =
    963             hash_table_get_instance(link, cdfs_node_t, nh_link);
     959            hash_table_get_inst(link, cdfs_node_t, nh_link);
    964960       
    965961        assert(node->opened > 0);
     
    10071003bool cdfs_init(void)
    10081004{
    1009         if (!hash_table_create(&nodes, NODES_BUCKETS, 2, &nodes_ops))
     1005        if (!hash_table_create(&nodes, 0, 0, &nodes_ops))
    10101006                return false;
    10111007       
  • uspace/srv/fs/cdfs/cdfs_ops.h

    r80445cf r4c53333  
    3434#define CDFS_CDFS_OPS_H_
    3535
    36 #include <bool.h>
     36#include <stdbool.h>
    3737
    3838extern bool cdfs_init(void);
  • uspace/srv/fs/exfat/exfat.h

    r80445cf r4c53333  
    4040#include <atomic.h>
    4141#include <sys/types.h>
    42 #include <bool.h>
     42#include <stdbool.h>
    4343#include "../../vfs/vfs.h"
    4444
     
    106106typedef struct {
    107107        /** Used indices (position) hash table link. */
    108         link_t          uph_link;
     108        ht_link_t               uph_link;
    109109        /** Used indices (index) hash table link. */
    110         link_t          uih_link;
     110        ht_link_t               uih_link;
    111111
    112112        fibril_mutex_t  lock;
  • uspace/srv/fs/exfat/exfat_bitmap.c

    r80445cf r4c53333  
    3939#include "../../vfs/vfs.h"
    4040#include <libfs.h>
    41 #include <libblock.h>
     41#include <block.h>
    4242#include <errno.h>
    4343#include <byteorder.h>
  • uspace/srv/fs/exfat/exfat_dentry.h

    r80445cf r4c53333  
    3535
    3636#include <stdint.h>
    37 #include <bool.h>
     37#include <stdbool.h>
    3838
    3939#define EXFAT_FILENAME_LEN      255
  • uspace/srv/fs/exfat/exfat_directory.c

    r80445cf r4c53333  
    3939#include "exfat_directory.h"
    4040#include "exfat_fat.h"
    41 #include <libblock.h>
     41#include <block.h>
    4242#include <errno.h>
    4343#include <byteorder.h>
  • uspace/srv/fs/exfat/exfat_fat.c

    r80445cf r4c53333  
    4242#include "../../vfs/vfs.h"
    4343#include <libfs.h>
    44 #include <libblock.h>
     44#include <block.h>
    4545#include <errno.h>
    4646#include <byteorder.h>
     
    401401{
    402402        service_id_t service_id = nodep->idx->service_id;
    403         exfat_cluster_t lastc;
     403        exfat_cluster_t lastc = 0;
    404404        int rc;
    405405
  • uspace/srv/fs/exfat/exfat_fat.h

    r80445cf r4c53333  
    3737#include "../../vfs/vfs.h"
    3838#include <stdint.h>
    39 #include <libblock.h>
     39#include <block.h>
    4040
    4141#define EXFAT_ROOT_IDX          0
  • uspace/srv/fs/exfat/exfat_idx.c

    r80445cf r4c53333  
    4141#include <str.h>
    4242#include <adt/hash_table.h>
     43#include <adt/hash.h>
    4344#include <adt/list.h>
    4445#include <assert.h>
     
    9192        if (lock)
    9293                fibril_mutex_lock(&unused_lock);
     94
    9395        list_foreach(unused_list, l) {
    9496                u = list_get_instance(l, unused_t, link);
     
    112114static hash_table_t up_hash;
    113115
    114 #define UPH_BUCKETS_LOG 12
    115 #define UPH_BUCKETS     (1 << UPH_BUCKETS_LOG)
    116 
    117 #define UPH_SID_KEY     0
    118 #define UPH_PFC_KEY     1
    119 #define UPH_PDI_KEY     2
    120 
    121 static hash_index_t pos_hash(unsigned long key[])
    122 {
    123         service_id_t service_id = (service_id_t)key[UPH_SID_KEY];
    124         exfat_cluster_t pfc = (exfat_cluster_t)key[UPH_PFC_KEY];
    125         unsigned pdi = (unsigned)key[UPH_PDI_KEY];
    126 
    127         hash_index_t h;
    128 
    129         /*
    130          * The least significant half of all bits are the least significant bits
    131          * of the parent node's first cluster.
    132          *
    133          * The least significant half of the most significant half of all bits
    134          * are the least significant bits of the node's dentry index within the
    135          * parent directory node.
    136          *
    137          * The most significant half of the most significant half of all bits
    138          * are the least significant bits of the device handle.
    139          */
    140         h = pfc & ((1 << (UPH_BUCKETS_LOG / 2)) - 1);
    141         h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    142             (UPH_BUCKETS_LOG / 2);
    143         h |= (service_id & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    144             (3 * (UPH_BUCKETS_LOG / 4));
    145 
    146         return h;
    147 }
    148 
    149 static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
    150 {
    151         service_id_t service_id = (service_id_t)key[UPH_SID_KEY];
     116typedef struct {
     117        service_id_t service_id;
    152118        exfat_cluster_t pfc;
    153119        unsigned pdi;
    154         exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uph_link);
    155 
    156         switch (keys) {
    157         case 1:
    158                 return (service_id == fidx->service_id);
    159         case 3:
    160                 pfc = (exfat_cluster_t) key[UPH_PFC_KEY];
    161                 pdi = (unsigned) key[UPH_PDI_KEY];
    162                 return (service_id == fidx->service_id) && (pfc == fidx->pfc) &&
    163                     (pdi == fidx->pdi);
    164         default:
    165                 assert((keys == 1) || (keys == 3));
    166         }
    167 
    168         return 0;
    169 }
    170 
    171 static void pos_remove_callback(link_t *item)
    172 {
    173         /* nothing to do */
    174 }
    175 
    176 static hash_table_operations_t uph_ops = {
     120} pos_key_t;
     121
     122static inline size_t pos_key_hash(void *key)
     123{
     124        pos_key_t *pos = (pos_key_t*)key;
     125       
     126        size_t hash = 0;
     127        hash = hash_combine(pos->pfc, pos->pdi);
     128        return hash_combine(hash, pos->service_id);
     129}
     130
     131static size_t pos_hash(const ht_link_t *item)
     132{
     133        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uph_link);
     134       
     135        pos_key_t pkey = {
     136                .service_id = fidx->service_id,
     137                .pfc = fidx->pfc,
     138                .pdi = fidx->pdi,
     139        };
     140       
     141        return pos_key_hash(&pkey);
     142}
     143
     144static bool pos_key_equal(void *key, const ht_link_t *item)
     145{
     146        pos_key_t *pos = (pos_key_t*)key;
     147        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uph_link);
     148       
     149        return pos->service_id == fidx->service_id
     150                && pos->pdi == fidx->pdi
     151                && pos->pfc == fidx->pfc;
     152}
     153
     154static hash_table_ops_t uph_ops = {
    177155        .hash = pos_hash,
    178         .compare = pos_compare,
    179         .remove_callback = pos_remove_callback,
     156        .key_hash = pos_key_hash,
     157        .key_equal = pos_key_equal,
     158        .equal = NULL,
     159        .remove_callback = NULL,
    180160};
    181161
     
    186166static hash_table_t ui_hash;
    187167
    188 #define UIH_BUCKETS_LOG 12
    189 #define UIH_BUCKETS     (1 << UIH_BUCKETS_LOG)
    190 
    191 #define UIH_SID_KEY     0
    192 #define UIH_INDEX_KEY   1
    193 
    194 static hash_index_t idx_hash(unsigned long key[])
    195 {
    196         service_id_t service_id = (service_id_t)key[UIH_SID_KEY];
    197         fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
    198 
    199         hash_index_t h;
    200 
    201         h = service_id & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
    202         h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) <<
    203             (UIH_BUCKETS_LOG / 2);
    204 
    205         return h;
    206 }
    207 
    208 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
    209 {
    210         service_id_t service_id = (service_id_t)key[UIH_SID_KEY];
     168typedef struct {
     169        service_id_t service_id;
    211170        fs_index_t index;
    212         exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uih_link);
    213 
    214         switch (keys) {
    215         case 1:
    216                 return (service_id == fidx->service_id);
    217         case 2:
    218                 index = (fs_index_t) key[UIH_INDEX_KEY];
    219                 return (service_id == fidx->service_id) &&
    220                     (index == fidx->index);
    221         default:
    222                 assert((keys == 1) || (keys == 2));
    223         }
    224 
    225         return 0;
    226 }
    227 
    228 static void idx_remove_callback(link_t *item)
    229 {
    230         exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uih_link);
     171} idx_key_t;
     172
     173static size_t idx_key_hash(void *key_arg)
     174{
     175        idx_key_t *key = (idx_key_t*)key_arg;
     176        return hash_combine(key->service_id, key->index);
     177}
     178
     179static size_t idx_hash(const ht_link_t *item)
     180{
     181        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uih_link);
     182        return hash_combine(fidx->service_id, fidx->index);
     183}
     184
     185static bool idx_key_equal(void *key_arg, const ht_link_t *item)
     186{
     187        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uih_link);
     188        idx_key_t *key = (idx_key_t*)key_arg;
     189       
     190        return key->index == fidx->index && key->service_id == fidx->service_id;
     191}
     192
     193static void idx_remove_callback(ht_link_t *item)
     194{
     195        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uih_link);
    231196
    232197        free(fidx);
    233198}
    234199
    235 static hash_table_operations_t uih_ops = {
     200static hash_table_ops_t uih_ops = {
    236201        .hash = idx_hash,
    237         .compare = idx_compare,
     202        .key_hash = idx_key_hash,
     203        .key_equal = idx_key_equal,
     204        .equal = NULL,
    238205        .remove_callback = idx_remove_callback,
    239206};
     
    376343        }
    377344               
    378         link_initialize(&fidx->uph_link);
    379         link_initialize(&fidx->uih_link);
    380345        fibril_mutex_initialize(&fidx->lock);
    381346        fidx->service_id = service_id;
     
    400365        }
    401366               
    402         unsigned long ikey[] = {
    403                 [UIH_SID_KEY] = service_id,
    404                 [UIH_INDEX_KEY] = fidx->index,
    405         };
    406        
    407         hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
     367        hash_table_insert(&ui_hash, &fidx->uih_link);
    408368        fibril_mutex_lock(&fidx->lock);
    409369        fibril_mutex_unlock(&used_lock);
     
    417377{
    418378        exfat_idx_t *fidx;
    419         link_t *l;
    420         unsigned long pkey[] = {
    421                 [UPH_SID_KEY] = service_id,
    422                 [UPH_PFC_KEY] = pfc,
    423                 [UPH_PDI_KEY] = pdi,
     379       
     380        pos_key_t pos_key = {
     381                .service_id = service_id,
     382                .pfc = pfc,
     383                .pdi = pdi,
    424384        };
    425385
    426386        fibril_mutex_lock(&used_lock);
    427         l = hash_table_find(&up_hash, pkey);
     387        ht_link_t *l = hash_table_find(&up_hash, &pos_key);
    428388        if (l) {
    429                 fidx = hash_table_get_instance(l, exfat_idx_t, uph_link);
     389                fidx = hash_table_get_inst(l, exfat_idx_t, uph_link);
    430390        } else {
    431391                int rc;
     
    437397                }
    438398               
    439                 unsigned long ikey[] = {
    440                         [UIH_SID_KEY] = service_id,
    441                         [UIH_INDEX_KEY] = fidx->index,
    442                 };
    443        
    444399                fidx->pfc = pfc;
    445400                fidx->pdi = pdi;
    446401
    447                 hash_table_insert(&up_hash, pkey, &fidx->uph_link);
    448                 hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
     402                hash_table_insert(&up_hash, &fidx->uph_link);
     403                hash_table_insert(&ui_hash, &fidx->uih_link);
    449404        }
    450405        fibril_mutex_lock(&fidx->lock);
     
    456411void exfat_idx_hashin(exfat_idx_t *idx)
    457412{
    458         unsigned long pkey[] = {
    459                 [UPH_SID_KEY] = idx->service_id,
    460                 [UPH_PFC_KEY] = idx->pfc,
    461                 [UPH_PDI_KEY] = idx->pdi,
    462         };
    463 
    464         fibril_mutex_lock(&used_lock);
    465         hash_table_insert(&up_hash, pkey, &idx->uph_link);
     413        fibril_mutex_lock(&used_lock);
     414        hash_table_insert(&up_hash, &idx->uph_link);
    466415        fibril_mutex_unlock(&used_lock);
    467416}
     
    469418void exfat_idx_hashout(exfat_idx_t *idx)
    470419{
    471         unsigned long pkey[] = {
    472                 [UPH_SID_KEY] = idx->service_id,
    473                 [UPH_PFC_KEY] = idx->pfc,
    474                 [UPH_PDI_KEY] = idx->pdi,
    475         };
    476 
    477         fibril_mutex_lock(&used_lock);
    478         hash_table_remove(&up_hash, pkey, 3);
     420        fibril_mutex_lock(&used_lock);
     421        hash_table_remove_item(&up_hash, &idx->uph_link);
    479422        fibril_mutex_unlock(&used_lock);
    480423}
     
    484427{
    485428        exfat_idx_t *fidx = NULL;
    486         link_t *l;
    487         unsigned long ikey[] = {
    488                 [UIH_SID_KEY] = service_id,
    489                 [UIH_INDEX_KEY] = index,
     429
     430        idx_key_t idx_key = {
     431                .service_id = service_id,
     432                .index = index,
    490433        };
    491434
    492435        fibril_mutex_lock(&used_lock);
    493         l = hash_table_find(&ui_hash, ikey);
     436        ht_link_t *l = hash_table_find(&ui_hash, &idx_key);
    494437        if (l) {
    495                 fidx = hash_table_get_instance(l, exfat_idx_t, uih_link);
     438                fidx = hash_table_get_inst(l, exfat_idx_t, uih_link);
    496439                fibril_mutex_lock(&fidx->lock);
    497440        }
     
    507450void exfat_idx_destroy(exfat_idx_t *idx)
    508451{
    509         unsigned long ikey[] = {
    510                 [UIH_SID_KEY] = idx->service_id,
    511                 [UIH_INDEX_KEY] = idx->index,
     452        idx_key_t idx_key = {
     453                .service_id = idx->service_id,
     454                .index = idx->index,
    512455        };
    513         service_id_t service_id = idx->service_id;
    514         fs_index_t index = idx->index;
    515456
    516457        /* TODO: assert(idx->pfc == FAT_CLST_RES0); */
     
    523464         * the index hash only.
    524465         */
    525         hash_table_remove(&ui_hash, ikey, 2);
     466        hash_table_remove(&ui_hash, &idx_key);
    526467        fibril_mutex_unlock(&used_lock);
    527468        /* Release the VFS index. */
    528         exfat_index_free(service_id, index);
     469        exfat_index_free(idx_key.service_id, idx_key.index);
    529470        /* The index structure itself is freed in idx_remove_callback(). */
    530471}
     
    532473int exfat_idx_init(void)
    533474{
    534         if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
     475        if (!hash_table_create(&up_hash, 0, 0, &uph_ops))
    535476                return ENOMEM;
    536         if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {
     477        if (!hash_table_create(&ui_hash, 0, 0, &uih_ops)) {
    537478                hash_table_destroy(&up_hash);
    538479                return ENOMEM;
     
    544485{
    545486        /* We assume the hash tables are empty. */
     487        assert(hash_table_empty(&up_hash) && hash_table_empty(&ui_hash));
    546488        hash_table_destroy(&up_hash);
    547489        hash_table_destroy(&ui_hash);
     
    568510}
    569511
     512static bool rm_pos_service_id(ht_link_t *item, void *arg)
     513{
     514        service_id_t service_id = *(service_id_t*)arg;
     515        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uph_link);
     516
     517        if (fidx->service_id == service_id) {
     518                hash_table_remove_item(&up_hash, item);
     519        }
     520       
     521        return true;
     522}
     523
     524static bool rm_idx_service_id(ht_link_t *item, void *arg)
     525{
     526        service_id_t service_id = *(service_id_t*)arg;
     527        exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uih_link);
     528
     529        if (fidx->service_id == service_id) {
     530                hash_table_remove_item(&ui_hash, item);
     531        }
     532       
     533        return true;
     534}
     535
    570536void exfat_idx_fini_by_service_id(service_id_t service_id)
    571537{
    572         unsigned long ikey[] = {
    573                 [UIH_SID_KEY] = service_id
    574         };
    575         unsigned long pkey[] = {
    576                 [UPH_SID_KEY] = service_id
    577         };
    578 
    579538        /*
    580539         * Remove this instance's index structure from up_hash and ui_hash.
     
    583542         */
    584543        fibril_mutex_lock(&used_lock);
    585         hash_table_remove(&up_hash, pkey, 1);
    586         hash_table_remove(&ui_hash, ikey, 1);
     544        hash_table_apply(&up_hash, rm_pos_service_id, &service_id);
     545        hash_table_apply(&ui_hash, rm_idx_service_id, &service_id);
    587546        fibril_mutex_unlock(&used_lock);
    588547
  • uspace/srv/fs/exfat/exfat_ops.c

    r80445cf r4c53333  
    4545#include "../../vfs/vfs.h"
    4646#include <libfs.h>
    47 #include <libblock.h>
     47#include <block.h>
    4848#include <ipc/services.h>
    4949#include <ipc/loc.h>
     
    5454#include <byteorder.h>
    5555#include <adt/hash_table.h>
     56#include <adt/hash.h>
    5657#include <adt/list.h>
    5758#include <assert.h>
  • uspace/srv/fs/ext4fs/Makefile

    r80445cf r4c53333  
    11#
    2 # Copyright (c) 2005 Martin Decky
    3 # Copyright (c) 2007 Jakub Jermar
    4 # Copyright (c) 2010 Martin Sucha
     2# Copyright (c) 2012 Frantisek Princ
    53# All rights reserved.
    64#
     
    3028
    3129USPACE_PREFIX = ../../..
    32 LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBEXT2_PREFIX)/libext2.a
    33 EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX) -I$(LIBEXT2_PREFIX)
    34 BINARY = ext2fs
     30LIBS = $(LIBBLOCK_PREFIX)/libblock.a $(LIBFS_PREFIX)/libfs.a $(LIBEXT4_PREFIX)/libext4.a
     31EXTRA_CFLAGS += -I$(LIBBLOCK_PREFIX) -I$(LIBFS_PREFIX) -I$(LIBEXT4_PREFIX)
     32BINARY = ext4fs
    3533
    3634SOURCES = \
    37         ext2fs.c \
    38         ext2fs_ops.c
     35        ext4fs.c \
     36        ext4fs_ops.c
    3937
    4038include $(USPACE_PREFIX)/Makefile.common
  • uspace/srv/fs/ext4fs/ext4fs.c

    r80445cf r4c53333  
    11/*
    2  * Copyright (c) 2006 Martin Decky
    3  * Copyright (c) 2011 Martin Sucha
     2 * Copyright (c) 2012 Frantisek Princ
    43 * All rights reserved.
    54 *
     
    3029/** @addtogroup fs
    3130 * @{
    32  */
    33 
     31 */
    3432/**
    35  * @file        ext2.c
    36  * @brief       EXT2 file system driver for HelenOS.
     33 * @file  ext4fs.c
     34 * @brief Ext4 file system driver for HelenOS.
    3735 */
    3836
    39 #include "ext2fs.h"
    40 #include <ipc/services.h>
    41 #include <ns.h>
    4237#include <async.h>
    4338#include <errno.h>
    44 #include <unistd.h>
     39#include <libfs.h>
     40#include <ns.h>
     41#include <stdio.h>
    4542#include <task.h>
    46 #include <stdio.h>
    47 #include <libfs.h>
     43#include <ipc/services.h>
     44#include "ext4fs.h"
    4845#include "../../vfs/vfs.h"
    4946
    50 #define NAME    "ext2fs"
     47#define NAME  "ext4fs"
    5148
    52 vfs_info_t ext2fs_vfs_info = {
     49vfs_info_t ext4fs_vfs_info = {
    5350        .name = NAME,
    54         .instance = 0,
     51        .instance = 0
    5552};
    5653
    5754int main(int argc, char **argv)
    5855{
    59         printf(NAME ": HelenOS EXT2 file system server\n");
    60 
     56        printf("%s: HelenOS ext4 file system server\n", NAME);
     57       
    6158        if (argc == 3) {
    6259                if (!str_cmp(argv[1], "--instance"))
    63                         ext2fs_vfs_info.instance = strtol(argv[2], NULL, 10);
     60                        ext4fs_vfs_info.instance = strtol(argv[2], NULL, 10);
    6461                else {
    65                         printf(NAME " Unrecognized parameters");
    66                         return -1;
     62                        printf("%s: Unrecognized parameters\n", NAME);
     63                        return 1;
    6764                }
    6865        }
     
    7168            SERVICE_VFS, 0, 0);
    7269        if (!vfs_sess) {
    73                 printf(NAME ": failed to connect to VFS\n");
    74                 return -1;
    75         }
    76 
    77         int rc = ext2fs_global_init();
    78         if (rc != EOK) {
    79                 printf(NAME ": Failed global initialization\n");
    80                 return 1;
    81         }       
    82                
    83         rc = fs_register(vfs_sess, &ext2fs_vfs_info, &ext2fs_ops,
    84             &ext2fs_libfs_ops);
    85         if (rc != EOK) {
    86                 fprintf(stdout, NAME ": Failed to register fs (%d)\n", rc);
    87                 return 1;
     70                printf("%s: Failed to connect to VFS\n", NAME);
     71                return 2;
    8872        }
    8973       
    90         printf(NAME ": Accepting connections\n");
     74        int rc = ext4fs_global_init();
     75        if (rc != EOK) {
     76                printf("%s: Global initialization failed\n", NAME);
     77                return rc;
     78        }
     79       
     80        rc = fs_register(vfs_sess, &ext4fs_vfs_info, &ext4fs_ops,
     81            &ext4fs_libfs_ops);
     82        if (rc != EOK) {
     83                printf("%s: Failed to register file system\n", NAME);
     84                return rc;
     85        }
     86       
     87        printf("%s: Accepting connections\n", NAME);
    9188        task_retval(0);
    9289        async_manager();
    93         /* not reached */
     90       
     91        /* Not reached */
    9492        return 0;
    9593}
     
    9795/**
    9896 * @}
    99  */ 
     97 */
  • uspace/srv/fs/fat/fat.h

    r80445cf r4c53333  
    4040#include <atomic.h>
    4141#include <sys/types.h>
    42 #include <bool.h>
     42#include <stdbool.h>
    4343#include "../../vfs/vfs.h"
    4444
     
    190190typedef struct {
    191191        /** Used indices (position) hash table link. */
    192         link_t          uph_link;
     192        ht_link_t               uph_link;
    193193        /** Used indices (index) hash table link. */
    194         link_t          uih_link;
     194        ht_link_t               uih_link;
    195195
    196196        fibril_mutex_t  lock;
  • uspace/srv/fs/fat/fat_dentry.c

    r80445cf r4c53333  
    4343#include <byteorder.h>
    4444#include <assert.h>
     45#include <unistd.h>
     46#include <sys/types.h>
    4547
    4648/** Compare path component with the name read from the dentry.
     
    231233/** Get number of bytes in a string with size limit.
    232234 *
    233  * @param str  NULL-terminated (or not) string.
     235 * @param str  NULL-terminated (or not) string. The pointer comes from a packed
     236 *             structure and as such is expected to be unaligned.
    234237 * @param size Maximum number of bytes to consider.
    235238 *
     
    237240 *
    238241 */
    239 size_t fat_lfn_str_nlength(const uint16_t *str, size_t size)
     242size_t fat_lfn_str_nlength(const unaligned_uint16_t *str, size_t size)
    240243{
    241244        size_t offset = 0;
  • uspace/srv/fs/fat/fat_dentry.h

    r80445cf r4c53333  
    3636
    3737#include <stdint.h>
    38 #include <bool.h>
     38#include <stdbool.h>
     39#include <sys/types.h>
    3940
    4041#define IS_D_CHAR(ch) (isalnum(ch) || ch == '_')
     
    132133} __attribute__ ((packed)) fat_dentry_t;
    133134
    134 
    135135extern int fat_dentry_namecmp(char *, const char *);
    136136extern void fat_dentry_name_get(const fat_dentry_t *, char *);
     
    139139extern uint8_t fat_dentry_chksum(uint8_t *);
    140140
    141 extern size_t fat_lfn_str_nlength(const uint16_t *, size_t);
     141extern size_t fat_lfn_str_nlength(const unaligned_uint16_t *, size_t);
    142142extern size_t fat_lfn_size(const fat_dentry_t *);
    143143extern size_t fat_lfn_get_entry(const fat_dentry_t *, uint16_t *, size_t *);
  • uspace/srv/fs/fat/fat_directory.c

    r80445cf r4c53333  
    3838#include "fat_directory.h"
    3939#include "fat_fat.h"
    40 #include <libblock.h>
     40#include <block.h>
    4141#include <errno.h>
    4242#include <byteorder.h>
     
    516516                        return false;
    517517                case FAT_DENTRY_VALID:
    518                         if (bcmp(de->name, d->name,
    519                             FAT_NAME_LEN + FAT_EXT_LEN)==0)
     518                        if (memcmp(de->name, d->name,
     519                            FAT_NAME_LEN + FAT_EXT_LEN) == 0)
    520520                                return true;
    521521                        break;
  • uspace/srv/fs/fat/fat_fat.c

    r80445cf r4c53333  
    4242#include "../../vfs/vfs.h"
    4343#include <libfs.h>
    44 #include <libblock.h>
     44#include <block.h>
    4545#include <errno.h>
    4646#include <byteorder.h>
     
    128128{
    129129        fat_cluster_t firstc = nodep->firstc;
    130         fat_cluster_t currc;
     130        fat_cluster_t currc = 0;
    131131        aoff64_t relbn = bn;
    132132        int rc;
     
    194194        uint32_t clusters;
    195195        uint32_t max_clusters;
    196         fat_cluster_t c;
     196        fat_cluster_t c = 0;
    197197        int rc;
    198198
     
    679679        fat_cluster_t *lifo;    /* stack for storing free cluster numbers */
    680680        unsigned found = 0;     /* top of the free cluster number stack */
    681         fat_cluster_t clst, value, clst_last1 = FAT_CLST_LAST1(bs);
     681        fat_cluster_t clst;
     682        fat_cluster_t value = 0;
     683        fat_cluster_t clst_last1 = FAT_CLST_LAST1(bs);
    682684        int rc = EOK;
    683685
     
    783785{
    784786        service_id_t service_id = nodep->idx->service_id;
    785         fat_cluster_t lastc;
     787        fat_cluster_t lastc = 0;
    786788        uint8_t fatno;
    787789        int rc;
     
    907909int fat_sanity_check(fat_bs_t *bs, service_id_t service_id)
    908910{
    909         fat_cluster_t e0, e1;
     911        fat_cluster_t e0 = 0;
     912        fat_cluster_t e1 = 0;
    910913        unsigned fat_no;
    911914        int rc;
  • uspace/srv/fs/fat/fat_fat.h

    r80445cf r4c53333  
    3737#include "../../vfs/vfs.h"
    3838#include <stdint.h>
    39 #include <libblock.h>
     39#include <block.h>
    4040
    4141#define FAT1            0
  • uspace/srv/fs/fat/fat_idx.c

    r80445cf r4c53333  
    4141#include <str.h>
    4242#include <adt/hash_table.h>
     43#include <adt/hash.h>
    4344#include <adt/list.h>
    4445#include <assert.h>
     
    5859 */
    5960typedef struct {
    60         link_t          link;
    61         service_id_t    service_id;
     61        link_t link;
     62        service_id_t service_id;
    6263
    6364        /** Next unassigned index. */
     
    9798                        return u;
    9899        }
    99        
     100
    100101        if (lock)
    101102                fibril_mutex_unlock(&unused_lock);
     
    113114static hash_table_t up_hash;
    114115
    115 #define UPH_BUCKETS_LOG 12
    116 #define UPH_BUCKETS     (1 << UPH_BUCKETS_LOG)
    117 
    118 #define UPH_SID_KEY     0
    119 #define UPH_PFC_KEY     1
    120 #define UPH_PDI_KEY     2
    121 
    122 static hash_index_t pos_hash(unsigned long key[])
    123 {
    124         service_id_t service_id = (service_id_t)key[UPH_SID_KEY];
    125         fat_cluster_t pfc = (fat_cluster_t)key[UPH_PFC_KEY];
    126         unsigned pdi = (unsigned)key[UPH_PDI_KEY];
    127 
    128         hash_index_t h;
    129 
    130         /*
    131          * The least significant half of all bits are the least significant bits
    132          * of the parent node's first cluster.
    133          *
    134          * The least significant half of the most significant half of all bits
    135          * are the least significant bits of the node's dentry index within the
    136          * parent directory node.
    137          *
    138          * The most significant half of the most significant half of all bits
    139          * are the least significant bits of the device handle.
    140          */
    141         h = pfc & ((1 << (UPH_BUCKETS_LOG / 2)) - 1);
    142         h |= (pdi & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    143             (UPH_BUCKETS_LOG / 2);
    144         h |= (service_id & ((1 << (UPH_BUCKETS_LOG / 4)) - 1)) <<
    145             (3 * (UPH_BUCKETS_LOG / 4));
    146 
    147         return h;
    148 }
    149 
    150 static int pos_compare(unsigned long key[], hash_count_t keys, link_t *item)
    151 {
    152         service_id_t service_id = (service_id_t)key[UPH_SID_KEY];
     116typedef struct {
     117        service_id_t service_id;
    153118        fat_cluster_t pfc;
    154119        unsigned pdi;
    155         fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uph_link);
    156 
    157         switch (keys) {
    158         case 1:
    159                 return (service_id == fidx->service_id);
    160         case 3:
    161                 pfc = (fat_cluster_t) key[UPH_PFC_KEY];
    162                 pdi = (unsigned) key[UPH_PDI_KEY];
    163                 return (service_id == fidx->service_id) && (pfc == fidx->pfc) &&
    164                     (pdi == fidx->pdi);
    165         default:
    166                 assert((keys == 1) || (keys == 3));
    167         }
    168 
    169         return 0;
    170 }
    171 
    172 static void pos_remove_callback(link_t *item)
    173 {
    174         /* nothing to do */
    175 }
    176 
    177 static hash_table_operations_t uph_ops = {
     120} pos_key_t;
     121
     122static inline size_t pos_key_hash(void *key)
     123{
     124        pos_key_t *pos = (pos_key_t*)key;
     125       
     126        size_t hash = 0;
     127        hash = hash_combine(pos->pfc, pos->pdi);
     128        return hash_combine(hash, pos->service_id);
     129}
     130
     131static size_t pos_hash(const ht_link_t *item)
     132{
     133        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uph_link);
     134       
     135        pos_key_t pkey = {
     136                .service_id = fidx->service_id,
     137                .pfc = fidx->pfc,
     138                .pdi = fidx->pdi,
     139        };
     140       
     141        return pos_key_hash(&pkey);
     142}
     143
     144static bool pos_key_equal(void *key, const ht_link_t *item)
     145{
     146        pos_key_t *pos = (pos_key_t*)key;
     147        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uph_link);
     148       
     149        return pos->service_id == fidx->service_id
     150                && pos->pdi == fidx->pdi
     151                && pos->pfc == fidx->pfc;
     152}
     153
     154static hash_table_ops_t uph_ops = {
    178155        .hash = pos_hash,
    179         .compare = pos_compare,
    180         .remove_callback = pos_remove_callback,
     156        .key_hash = pos_key_hash,
     157        .key_equal = pos_key_equal,
     158        .equal = NULL,
     159        .remove_callback = NULL,
    181160};
    182161
     
    187166static hash_table_t ui_hash;
    188167
    189 #define UIH_BUCKETS_LOG 12
    190 #define UIH_BUCKETS     (1 << UIH_BUCKETS_LOG)
    191 
    192 #define UIH_SID_KEY     0
    193 #define UIH_INDEX_KEY   1
    194 
    195 static hash_index_t idx_hash(unsigned long key[])
    196 {
    197         service_id_t service_id = (service_id_t)key[UIH_SID_KEY];
    198         fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY];
    199 
    200         hash_index_t h;
    201 
    202         h = service_id & ((1 << (UIH_BUCKETS_LOG / 2)) - 1);
    203         h |= (index & ((1 << (UIH_BUCKETS_LOG / 2)) - 1)) <<
    204             (UIH_BUCKETS_LOG / 2);
    205 
    206         return h;
    207 }
    208 
    209 static int idx_compare(unsigned long key[], hash_count_t keys, link_t *item)
    210 {
    211         service_id_t service_id = (service_id_t)key[UIH_SID_KEY];
     168typedef struct {
     169        service_id_t service_id;
    212170        fs_index_t index;
    213         fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link);
    214 
    215         switch (keys) {
    216         case 1:
    217                 return (service_id == fidx->service_id);
    218         case 2:
    219                 index = (fs_index_t) key[UIH_INDEX_KEY];
    220                 return (service_id == fidx->service_id) &&
    221                     (index == fidx->index);
    222         default:
    223                 assert((keys == 1) || (keys == 2));
    224         }
    225 
    226         return 0;
    227 }
    228 
    229 static void idx_remove_callback(link_t *item)
    230 {
    231         fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link);
     171} idx_key_t;
     172
     173static size_t idx_key_hash(void *key_arg)
     174{
     175        idx_key_t *key = (idx_key_t*)key_arg;
     176        return hash_combine(key->service_id, key->index);
     177}
     178
     179static size_t idx_hash(const ht_link_t *item)
     180{
     181        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uih_link);
     182        return hash_combine(fidx->service_id, fidx->index);
     183}
     184
     185static bool idx_key_equal(void *key_arg, const ht_link_t *item)
     186{
     187        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uih_link);
     188        idx_key_t *key = (idx_key_t*)key_arg;
     189       
     190        return key->index == fidx->index && key->service_id == fidx->service_id;
     191}
     192
     193static void idx_remove_callback(ht_link_t *item)
     194{
     195        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uih_link);
    232196
    233197        free(fidx);
    234198}
    235199
    236 static hash_table_operations_t uih_ops = {
     200static hash_table_ops_t uih_ops = {
    237201        .hash = idx_hash,
    238         .compare = idx_compare,
     202        .key_hash = idx_key_hash,
     203        .key_equal = idx_key_equal,
     204        .equal = NULL,
    239205        .remove_callback = idx_remove_callback,
    240206};
     
    377343        }
    378344               
    379         link_initialize(&fidx->uph_link);
    380         link_initialize(&fidx->uih_link);
    381345        fibril_mutex_initialize(&fidx->lock);
    382346        fidx->service_id = service_id;
     
    401365        }
    402366               
    403         unsigned long ikey[] = {
    404                 [UIH_SID_KEY] = service_id,
    405                 [UIH_INDEX_KEY] = fidx->index,
    406         };
    407        
    408         hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
     367        hash_table_insert(&ui_hash, &fidx->uih_link);
    409368        fibril_mutex_lock(&fidx->lock);
    410369        fibril_mutex_unlock(&used_lock);
     
    418377{
    419378        fat_idx_t *fidx;
    420         link_t *l;
    421         unsigned long pkey[] = {
    422                 [UPH_SID_KEY] = service_id,
    423                 [UPH_PFC_KEY] = pfc,
    424                 [UPH_PDI_KEY] = pdi,
     379
     380        pos_key_t pos_key = {
     381                .service_id = service_id,
     382                .pfc = pfc,
     383                .pdi = pdi,
    425384        };
    426385
    427386        fibril_mutex_lock(&used_lock);
    428         l = hash_table_find(&up_hash, pkey);
     387        ht_link_t *l = hash_table_find(&up_hash, &pos_key);
    429388        if (l) {
    430                 fidx = hash_table_get_instance(l, fat_idx_t, uph_link);
     389                fidx = hash_table_get_inst(l, fat_idx_t, uph_link);
    431390        } else {
    432391                int rc;
     
    438397                }
    439398               
    440                 unsigned long ikey[] = {
    441                         [UIH_SID_KEY] = service_id,
    442                         [UIH_INDEX_KEY] = fidx->index,
    443                 };
    444        
    445399                fidx->pfc = pfc;
    446400                fidx->pdi = pdi;
    447401
    448                 hash_table_insert(&up_hash, pkey, &fidx->uph_link);
    449                 hash_table_insert(&ui_hash, ikey, &fidx->uih_link);
     402                hash_table_insert(&up_hash, &fidx->uph_link);
     403                hash_table_insert(&ui_hash, &fidx->uih_link);
    450404        }
    451405        fibril_mutex_lock(&fidx->lock);
     
    457411void fat_idx_hashin(fat_idx_t *idx)
    458412{
    459         unsigned long pkey[] = {
    460                 [UPH_SID_KEY] = idx->service_id,
    461                 [UPH_PFC_KEY] = idx->pfc,
    462                 [UPH_PDI_KEY] = idx->pdi,
    463         };
    464 
    465         fibril_mutex_lock(&used_lock);
    466         hash_table_insert(&up_hash, pkey, &idx->uph_link);
     413        fibril_mutex_lock(&used_lock);
     414        hash_table_insert(&up_hash, &idx->uph_link);
    467415        fibril_mutex_unlock(&used_lock);
    468416}
     
    470418void fat_idx_hashout(fat_idx_t *idx)
    471419{
    472         unsigned long pkey[] = {
    473                 [UPH_SID_KEY] = idx->service_id,
    474                 [UPH_PFC_KEY] = idx->pfc,
    475                 [UPH_PDI_KEY] = idx->pdi,
    476         };
    477 
    478         fibril_mutex_lock(&used_lock);
    479         hash_table_remove(&up_hash, pkey, 3);
     420        fibril_mutex_lock(&used_lock);
     421        hash_table_remove_item(&up_hash, &idx->uph_link);
    480422        fibril_mutex_unlock(&used_lock);
    481423}
     
    485427{
    486428        fat_idx_t *fidx = NULL;
    487         link_t *l;
    488         unsigned long ikey[] = {
    489                 [UIH_SID_KEY] = service_id,
    490                 [UIH_INDEX_KEY] = index,
     429
     430        idx_key_t idx_key = {
     431                .service_id = service_id,
     432                .index = index,
    491433        };
    492434
    493435        fibril_mutex_lock(&used_lock);
    494         l = hash_table_find(&ui_hash, ikey);
     436        ht_link_t *l = hash_table_find(&ui_hash, &idx_key);
    495437        if (l) {
    496                 fidx = hash_table_get_instance(l, fat_idx_t, uih_link);
     438                fidx = hash_table_get_inst(l, fat_idx_t, uih_link);
    497439                fibril_mutex_lock(&fidx->lock);
    498440        }
     
    508450void fat_idx_destroy(fat_idx_t *idx)
    509451{
    510         unsigned long ikey[] = {
    511                 [UIH_SID_KEY] = idx->service_id,
    512                 [UIH_INDEX_KEY] = idx->index,
     452        idx_key_t idx_key = {
     453                .service_id = idx->service_id,
     454                .index = idx->index,
    513455        };
    514         service_id_t service_id = idx->service_id;
    515         fs_index_t index = idx->index;
    516456
    517457        assert(idx->pfc == FAT_CLST_RES0);
     
    523463         * the index hash only.
    524464         */
    525         hash_table_remove(&ui_hash, ikey, 2);
     465        hash_table_remove(&ui_hash, &idx_key);
    526466        fibril_mutex_unlock(&used_lock);
    527467        /* Release the VFS index. */
    528         fat_index_free(service_id, index);
     468        fat_index_free(idx_key.service_id, idx_key.index);
    529469        /* The index structure itself is freed in idx_remove_callback(). */
    530470}
     
    532472int fat_idx_init(void)
    533473{
    534         if (!hash_table_create(&up_hash, UPH_BUCKETS, 3, &uph_ops))
     474        if (!hash_table_create(&up_hash, 0, 0, &uph_ops))
    535475                return ENOMEM;
    536         if (!hash_table_create(&ui_hash, UIH_BUCKETS, 2, &uih_ops)) {
     476        if (!hash_table_create(&ui_hash, 0, 0, &uih_ops)) {
    537477                hash_table_destroy(&up_hash);
    538478                return ENOMEM;
     
    544484{
    545485        /* We assume the hash tables are empty. */
     486        assert(hash_table_empty(&up_hash) && hash_table_empty(&ui_hash));
    546487        hash_table_destroy(&up_hash);
    547488        hash_table_destroy(&ui_hash);
     
    568509}
    569510
     511static bool rm_pos_service_id(ht_link_t *item, void *arg)
     512{
     513        service_id_t service_id = *(service_id_t*)arg;
     514        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uph_link);
     515
     516        if (fidx->service_id == service_id) {
     517                hash_table_remove_item(&up_hash, item);
     518        }
     519       
     520        return true;
     521}
     522
     523static bool rm_idx_service_id(ht_link_t *item, void *arg)
     524{
     525        service_id_t service_id = *(service_id_t*)arg;
     526        fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uih_link);
     527
     528        if (fidx->service_id == service_id) {
     529                hash_table_remove_item(&ui_hash, item);
     530        }
     531       
     532        return true;
     533}
     534
    570535void fat_idx_fini_by_service_id(service_id_t service_id)
    571536{
    572         unsigned long ikey[] = {
    573                 [UIH_SID_KEY] = service_id
    574         };
    575         unsigned long pkey[] = {
    576                 [UPH_SID_KEY] = service_id
    577         };
    578 
    579537        /*
    580538         * Remove this instance's index structure from up_hash and ui_hash.
     
    583541         */
    584542        fibril_mutex_lock(&used_lock);
    585         hash_table_remove(&up_hash, pkey, 1);
    586         hash_table_remove(&ui_hash, ikey, 1);
     543        hash_table_apply(&up_hash, rm_pos_service_id, &service_id);
     544        hash_table_apply(&ui_hash, rm_idx_service_id, &service_id);
    587545        fibril_mutex_unlock(&used_lock);
    588546
  • uspace/srv/fs/fat/fat_ops.c

    r80445cf r4c53333  
    4343#include "../../vfs/vfs.h"
    4444#include <libfs.h>
    45 #include <libblock.h>
     45#include <block.h>
    4646#include <ipc/services.h>
    4747#include <ipc/loc.h>
     
    651651                d = (fat_dentry_t *) b->data;
    652652                if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) ||
    653                     (bcmp(d->name, FAT_NAME_DOT, FAT_NAME_LEN)) == 0) {
     653                    (memcmp(d->name, FAT_NAME_DOT, FAT_NAME_LEN)) == 0) {
    654654                        memset(d, 0, sizeof(fat_dentry_t));
    655655                        memcpy(d->name, FAT_NAME_DOT, FAT_NAME_LEN);
     
    661661                d++;
    662662                if ((fat_classify_dentry(d) == FAT_DENTRY_LAST) ||
    663                     (bcmp(d->name, FAT_NAME_DOT_DOT, FAT_NAME_LEN) == 0)) {
     663                    (memcmp(d->name, FAT_NAME_DOT_DOT, FAT_NAME_LEN) == 0)) {
    664664                        memset(d, 0, sizeof(fat_dentry_t));
    665665                        memcpy(d->name, FAT_NAME_DOT_DOT, FAT_NAME_LEN);
     
    10421042        info = (fat32_fsinfo_t *) b->data;
    10431043
    1044         if (bcmp(info->sig1, FAT32_FSINFO_SIG1, sizeof(info->sig1)) ||
    1045             bcmp(info->sig2, FAT32_FSINFO_SIG2, sizeof(info->sig2)) ||
    1046             bcmp(info->sig3, FAT32_FSINFO_SIG3, sizeof(info->sig3))) {
     1044        if (memcmp(info->sig1, FAT32_FSINFO_SIG1, sizeof(info->sig1)) != 0 ||
     1045            memcmp(info->sig2, FAT32_FSINFO_SIG2, sizeof(info->sig2)) != 0 ||
     1046            memcmp(info->sig3, FAT32_FSINFO_SIG3, sizeof(info->sig3)) != 0) {
    10471047                (void) block_put(b);
    10481048                return EINVAL;
  • uspace/srv/fs/locfs/locfs_ops.c

    r80445cf r4c53333  
    3737
    3838#include <macros.h>
    39 #include <bool.h>
     39#include <stdbool.h>
    4040#include <errno.h>
    4141#include <malloc.h>
     
    6161        async_sess_t *sess;       /**< If NULL, the structure is incomplete. */
    6262        size_t refcount;
    63         link_t link;
     63        ht_link_t link;
    6464        fibril_condvar_t cv;      /**< Broadcast when completed. */
    6565} service_t;
     
    7171static FIBRIL_MUTEX_INITIALIZE(services_mutex);
    7272
    73 #define SERVICES_KEYS        1
    74 #define SERVICES_KEY_HANDLE  0
    75 #define SERVICES_BUCKETS     256
    76 
    7773/* Implementation of hash table interface for the nodes hash table. */
    78 static hash_index_t services_hash(unsigned long key[])
    79 {
    80         return key[SERVICES_KEY_HANDLE] % SERVICES_BUCKETS;
    81 }
    82 
    83 static int services_compare(unsigned long key[], hash_count_t keys, link_t *item)
    84 {
    85         service_t *dev = hash_table_get_instance(item, service_t, link);
    86         return (dev->service_id == (service_id_t) key[SERVICES_KEY_HANDLE]);
    87 }
    88 
    89 static void services_remove_callback(link_t *item)
    90 {
    91         free(hash_table_get_instance(item, service_t, link));
    92 }
    93 
    94 static hash_table_operations_t services_ops = {
     74
     75static size_t services_key_hash(void *key)
     76{
     77        return *(service_id_t*)key;
     78}
     79
     80static size_t services_hash(const ht_link_t *item)
     81{
     82        service_t *dev = hash_table_get_inst(item, service_t, link);
     83        return dev->service_id;
     84}
     85
     86static bool services_key_equal(void *key, const ht_link_t *item)
     87{
     88        service_t *dev = hash_table_get_inst(item, service_t, link);
     89        return (dev->service_id == *(service_id_t*)key);
     90}
     91
     92static void services_remove_callback(ht_link_t *item)
     93{
     94        free(hash_table_get_inst(item, service_t, link));
     95}
     96
     97static hash_table_ops_t services_ops = {
    9598        .hash = services_hash,
    96         .compare = services_compare,
     99        .key_hash = services_key_hash,
     100        .key_equal = services_key_equal,
     101        .equal = NULL,
    97102        .remove_callback = services_remove_callback
    98103};
     
    229234                /* Device node */
    230235               
    231                 unsigned long key[] = {
    232                         [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id
    233                 };
    234                 link_t *lnk;
    235                
    236236                fibril_mutex_lock(&services_mutex);
     237                ht_link_t *lnk;
    237238restart:
    238                 lnk = hash_table_find(&services, key);
     239                lnk = hash_table_find(&services, &node->service_id);
    239240                if (lnk == NULL) {
    240241                        service_t *dev = (service_t *) malloc(sizeof(service_t));
     
    256257                         * below.
    257258                         */
    258                         hash_table_insert(&services, key, &dev->link);
     259                        hash_table_insert(&services, &dev->link);
    259260                       
    260261                        /*
     
    279280                                 * entry and free the device structure.
    280281                                 */
    281                                 hash_table_remove(&services, key, SERVICES_KEYS);
     282                                hash_table_remove(&services, &node->service_id);
    282283                                fibril_mutex_unlock(&services_mutex);
    283284                               
     
    288289                        dev->sess = sess;
    289290                } else {
    290                         service_t *dev = hash_table_get_instance(lnk, service_t, link);
     291                        service_t *dev = hash_table_get_inst(lnk, service_t, link);
    291292                       
    292293                        if (!dev->sess) {
     
    450451bool locfs_init(void)
    451452{
    452         if (!hash_table_create(&services, SERVICES_BUCKETS,
    453             SERVICES_KEYS, &services_ops))
     453        if (!hash_table_create(&services, 0,  0, &services_ops))
    454454                return false;
    455455       
     
    555555                /* Device node */
    556556               
    557                 unsigned long key[] = {
    558                         [SERVICES_KEY_HANDLE] = (unsigned long) index
    559                 };
    560                
    561557                fibril_mutex_lock(&services_mutex);
    562                 link_t *lnk = hash_table_find(&services, key);
     558                service_id_t service_index = index;
     559                ht_link_t *lnk = hash_table_find(&services, &service_index);
    563560                if (lnk == NULL) {
    564561                        fibril_mutex_unlock(&services_mutex);
     
    566563                }
    567564               
    568                 service_t *dev = hash_table_get_instance(lnk, service_t, link);
     565                service_t *dev = hash_table_get_inst(lnk, service_t, link);
    569566                assert(dev->sess);
    570567               
     
    621618        if (type == LOC_OBJECT_SERVICE) {
    622619                /* Device node */
    623                 unsigned long key[] = {
    624                         [SERVICES_KEY_HANDLE] = (unsigned long) index
    625                 };
    626620               
    627621                fibril_mutex_lock(&services_mutex);
    628                 link_t *lnk = hash_table_find(&services, key);
     622                service_id_t service_index = index;
     623                ht_link_t *lnk = hash_table_find(&services, &service_index);
    629624                if (lnk == NULL) {
    630625                        fibril_mutex_unlock(&services_mutex);
     
    632627                }
    633628               
    634                 service_t *dev = hash_table_get_instance(lnk, service_t, link);
     629                service_t *dev = hash_table_get_inst(lnk, service_t, link);
    635630                assert(dev->sess);
    636631               
     
    691686       
    692687        if (type == LOC_OBJECT_SERVICE) {
    693                 unsigned long key[] = {
    694                         [SERVICES_KEY_HANDLE] = (unsigned long) index
    695                 };
    696688               
    697689                fibril_mutex_lock(&services_mutex);
    698                 link_t *lnk = hash_table_find(&services, key);
     690                service_id_t service_index = index;
     691                ht_link_t *lnk = hash_table_find(&services, &service_index);
    699692                if (lnk == NULL) {
    700693                        fibril_mutex_unlock(&services_mutex);
     
    702695                }
    703696               
    704                 service_t *dev = hash_table_get_instance(lnk, service_t, link);
     697                service_t *dev = hash_table_get_inst(lnk, service_t, link);
    705698                assert(dev->sess);
    706699                dev->refcount--;
     
    708701                if (dev->refcount == 0) {
    709702                        async_hangup(dev->sess);
    710                         hash_table_remove(&services, key, SERVICES_KEYS);
     703                        service_id_t service_index = index;
     704                        hash_table_remove(&services, &service_index);
    711705                }
    712706               
     
    732726       
    733727        if (type == LOC_OBJECT_SERVICE) {
    734                 unsigned long key[] = {
    735                         [SERVICES_KEY_HANDLE] = (unsigned long) index
    736                 };
    737                
     728
    738729                fibril_mutex_lock(&services_mutex);
    739                 link_t *lnk = hash_table_find(&services, key);
     730                service_id_t service_index = index;
     731                ht_link_t *lnk = hash_table_find(&services, &service_index);
    740732                if (lnk == NULL) {
    741733                        fibril_mutex_unlock(&services_mutex);
     
    743735                }
    744736               
    745                 service_t *dev = hash_table_get_instance(lnk, service_t, link);
     737                service_t *dev = hash_table_get_inst(lnk, service_t, link);
    746738                assert(dev->sess);
    747739               
  • uspace/srv/fs/locfs/locfs_ops.h

    r80445cf r4c53333  
    3434#define LOCFS_LOCFS_OPS_H_
    3535
    36 #include <bool.h>
     36#include <stdbool.h>
    3737
    3838extern bool locfs_init(void);
  • uspace/srv/fs/mfs/mfs.h

    r80445cf r4c53333  
    3636#include <minix.h>
    3737#include <macros.h>
    38 #include <libblock.h>
     38#include <block.h>
    3939#include <libfs.h>
    4040#include <adt/list.h>
     
    142142        unsigned refcnt;
    143143        fs_node_t *fsnode;
    144         link_t link;
     144        ht_link_t link;
    145145};
    146146
  • uspace/srv/fs/mfs/mfs_dentry.c

    r80445cf r4c53333  
    178178
    179179                if (name_len == d_name_len &&
    180                     !bcmp(d_info.d_name, d_name, name_len)) {
     180                    memcmp(d_info.d_name, d_name, name_len) == 0) {
    181181
    182182                        d_info.d_inum = 0;
  • uspace/srv/fs/mfs/mfs_ops.c

    r80445cf r4c53333  
    3535#include <align.h>
    3636#include <adt/hash_table.h>
     37#include <adt/hash.h>
    3738#include "mfs.h"
    3839
    39 #define OPEN_NODES_KEYS 2
    40 #define OPEN_NODES_SERVICE_KEY 0
    41 #define OPEN_NODES_INODE_KEY 1
    42 #define OPEN_NODES_BUCKETS 256
    4340
    4441static bool check_magic_number(uint16_t magic, bool *native,
     
    6158static int mfs_unlink(fs_node_t *, fs_node_t *, const char *name);
    6259static int mfs_destroy_node(fs_node_t *fn);
    63 static hash_index_t open_nodes_hash(unsigned long key[]);
    64 static int open_nodes_compare(unsigned long key[], hash_count_t keys,
    65     link_t *item);
    66 static void open_nodes_remove_cb(link_t *link);
    6760static int mfs_node_get(fs_node_t **rfn, service_id_t service_id,
    6861    fs_index_t index);
     
    9588
    9689/* Hash table interface for open nodes hash table */
    97 static hash_index_t
    98 open_nodes_hash(unsigned long key[])
    99 {
    100         /* TODO: This is very simple and probably can be improved */
    101         return key[OPEN_NODES_INODE_KEY] % OPEN_NODES_BUCKETS;
    102 }
    103 
    104 static int
    105 open_nodes_compare(unsigned long key[], hash_count_t keys,
    106     link_t *item)
    107 {
    108         struct mfs_node *mnode = hash_table_get_instance(item,
    109             struct mfs_node, link);
    110         assert(keys > 0);
    111         if (mnode->instance->service_id !=
    112             ((service_id_t) key[OPEN_NODES_SERVICE_KEY])) {
    113                 return false;
    114         }
    115         if (keys == 1) {
    116                 return true;
    117         }
    118         assert(keys == 2);
    119         return (mnode->ino_i->index == key[OPEN_NODES_INODE_KEY]);
    120 }
    121 
    122 static void
    123 open_nodes_remove_cb(link_t *link)
    124 {
    125         /* We don't use remove callback for this hash table */
    126 }
    127 
    128 static hash_table_operations_t open_nodes_ops = {
     90typedef struct {
     91        service_id_t service_id;
     92        fs_index_t index;
     93} node_key_t;
     94
     95static size_t
     96open_nodes_key_hash(void *key)
     97{
     98        node_key_t *node_key = (node_key_t*)key;
     99        return hash_combine(node_key->service_id, node_key->index);
     100}
     101
     102static size_t
     103open_nodes_hash(const ht_link_t *item)
     104{
     105        struct mfs_node *m = hash_table_get_inst(item, struct mfs_node, link);
     106        return hash_combine(m->instance->service_id, m->ino_i->index);
     107}
     108
     109static bool
     110open_nodes_key_equal(void *key, const ht_link_t *item)
     111{
     112        node_key_t *node_key = (node_key_t*)key;
     113        struct mfs_node *mnode = hash_table_get_inst(item, struct mfs_node, link);
     114
     115        return node_key->service_id == mnode->instance->service_id
     116                && node_key->index == mnode->ino_i->index;
     117}
     118
     119static hash_table_ops_t open_nodes_ops = {
    129120        .hash = open_nodes_hash,
    130         .compare = open_nodes_compare,
    131         .remove_callback = open_nodes_remove_cb,
     121        .key_hash = open_nodes_key_hash,
     122        .key_equal = open_nodes_key_equal,
     123        .equal = NULL,
     124        .remove_callback = NULL,
    132125};
    133126
     
    135128mfs_global_init(void)
    136129{
    137         if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS,
    138             OPEN_NODES_KEYS, &open_nodes_ops)) {
     130        if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) {
    139131                return ENOMEM;
    140132        }
     
    408400        mnode->refcnt = 1;
    409401
    410         link_initialize(&mnode->link);
    411 
    412         unsigned long key[] = {
    413                 [OPEN_NODES_SERVICE_KEY] = inst->service_id,
    414                 [OPEN_NODES_INODE_KEY] = inum,
    415         };
    416 
    417402        fibril_mutex_lock(&open_nodes_lock);
    418         hash_table_insert(&open_nodes, key, &mnode->link);
     403        hash_table_insert(&open_nodes, &mnode->link);
    419404        fibril_mutex_unlock(&open_nodes_lock);
    420405        inst->open_nodes_cnt++;
     
    467452
    468453                if (comp_size == dentry_name_size &&
    469                     !bcmp(component, d_info.d_name, dentry_name_size)) {
     454                    memcmp(component, d_info.d_name, dentry_name_size) == 0) {
    470455                        /* Hit! */
    471456                        mfs_node_core_get(rfn, mnode->instance,
     
    515500        mnode->refcnt--;
    516501        if (mnode->refcnt == 0) {
    517                 unsigned long key[] = {
    518                         [OPEN_NODES_SERVICE_KEY] = mnode->instance->service_id,
    519                         [OPEN_NODES_INODE_KEY] = mnode->ino_i->index
    520                 };
    521                 hash_table_remove(&open_nodes, key, OPEN_NODES_KEYS);
     502                hash_table_remove_item(&open_nodes, &mnode->link);
    522503                assert(mnode->instance->open_nodes_cnt > 0);
    523504                mnode->instance->open_nodes_cnt--;
     
    578559
    579560        /* Check if the node is not already open */
    580         unsigned long key[] = {
    581                 [OPEN_NODES_SERVICE_KEY] = inst->service_id,
    582                 [OPEN_NODES_INODE_KEY] = index,
     561        node_key_t key = {
     562                .service_id = inst->service_id,
     563                .index = index
    583564        };
    584         link_t *already_open = hash_table_find(&open_nodes, key);
     565       
     566        ht_link_t *already_open = hash_table_find(&open_nodes, &key);
    585567
    586568        if (already_open) {
    587                 mnode = hash_table_get_instance(already_open,
    588                     struct mfs_node, link);
     569                mnode = hash_table_get_inst(already_open, struct mfs_node, link);
     570
    589571                *rfn = mnode->fsnode;
    590572                mnode->refcnt++;
     
    617599        mnode->ino_i = ino_i;
    618600        mnode->refcnt = 1;
    619         link_initialize(&mnode->link);
    620601
    621602        mnode->instance = inst;
     
    624605        *rfn = node;
    625606
    626         hash_table_insert(&open_nodes, key, &mnode->link);
     607        hash_table_insert(&open_nodes, &mnode->link);
    627608        inst->open_nodes_cnt++;
    628609
     
    793774{
    794775        int rc;
    795         fs_node_t *fn;
     776        fs_node_t *fn = NULL;
    796777
    797778        rc = mfs_node_get(&fn, service_id, index);
     
    11281109mfs_sync(service_id_t service_id, fs_index_t index)
    11291110{
    1130         fs_node_t *fn;
     1111        fs_node_t *fn = NULL;
    11311112        int rc = mfs_node_get(&fn, service_id, index);
    11321113        if (rc != EOK)
  • uspace/srv/fs/tmpfs/tmpfs.h

    r80445cf r4c53333  
    3737#include <atomic.h>
    3838#include <sys/types.h>
    39 #include <bool.h>
     39#include <stdbool.h>
    4040#include <adt/hash_table.h>
    4141
     
    6262        fs_index_t index;       /**< TMPFS node index. */
    6363        service_id_t service_id;/**< Service ID of block device. */
    64         link_t nh_link;         /**< Nodes hash table link. */
     64        ht_link_t nh_link;              /**< Nodes hash table link. */
    6565        tmpfs_dentry_type_t type;
    6666        unsigned lnkcnt;        /**< Link count. */
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    r80445cf r4c53333  
    4444#include <sys/types.h>
    4545#include <as.h>
    46 #include <libblock.h>
     46#include <block.h>
    4747#include <byteorder.h>
    4848
    4949#define TMPFS_COMM_SIZE         1024
     50
     51static uint8_t tmpfs_buf[TMPFS_COMM_SIZE];
    5052
    5153struct rdentry {
     
    6870                uint32_t size;
    6971               
    70                 if (block_seqread(dsid, bufpos, buflen, pos, &entry,
     72                if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, &entry,
    7173                    sizeof(entry)) != EOK)
    7274                        return false;
     
    8890                        }
    8991                       
    90                         if (block_seqread(dsid, bufpos, buflen, pos, fname,
     92                        if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, fname,
    9193                            entry.len) != EOK) {
    9294                                (void) ops->destroy(fn);
     
    104106                        free(fname);
    105107                       
    106                         if (block_seqread(dsid, bufpos, buflen, pos, &size,
     108                        if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, &size,
    107109                            sizeof(size)) != EOK)
    108110                                return false;
     
    116118                       
    117119                        nodep->size = size;
    118                         if (block_seqread(dsid, bufpos, buflen, pos, nodep->data,
     120                        if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, nodep->data,
    119121                            size) != EOK)
    120122                                return false;
     
    132134                        }
    133135                       
    134                         if (block_seqread(dsid, bufpos, buflen, pos, fname,
     136                        if (block_seqread(dsid, tmpfs_buf, bufpos, buflen, pos, fname,
    135137                            entry.len) != EOK) {
    136138                                (void) ops->destroy(fn);
     
    176178       
    177179        char tag[6];
    178         if (block_seqread(dsid, &bufpos, &buflen, &pos, tag, 5) != EOK)
     180        if (block_seqread(dsid, tmpfs_buf, &bufpos, &buflen, &pos, tag, 5) != EOK)
    179181                goto error;
    180182       
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    r80445cf r4c53333  
    5050#include <sys/types.h>
    5151#include <adt/hash_table.h>
     52#include <adt/hash.h>
    5253#include <as.h>
    5354#include <libfs.h>
     
    5556#define min(a, b)               ((a) < (b) ? (a) : (b))
    5657#define max(a, b)               ((a) > (b) ? (a) : (b))
    57 
    58 #define NODES_BUCKETS   256
    5958
    6059/** All root nodes have index 0. */
     
    142141hash_table_t nodes;
    143142
    144 #define NODES_KEY_DEV   0       
    145 #define NODES_KEY_INDEX 1
    146 
    147 /* Implementation of hash table interface for the nodes hash table. */
    148 static hash_index_t nodes_hash(unsigned long key[])
    149 {
    150         return key[NODES_KEY_INDEX] % NODES_BUCKETS;
    151 }
    152 
    153 static int nodes_compare(unsigned long key[], hash_count_t keys, link_t *item)
    154 {
    155         tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
    156             nh_link);
    157        
    158         switch (keys) {
    159         case 1:
    160                 return (nodep->service_id == key[NODES_KEY_DEV]);
    161         case 2:
    162                 return ((nodep->service_id == key[NODES_KEY_DEV]) &&
    163                     (nodep->index == key[NODES_KEY_INDEX]));
    164         default:
    165                 assert((keys == 1) || (keys == 2));
    166         }
    167 
    168         return 0;
    169 }
    170 
    171 static void nodes_remove_callback(link_t *item)
    172 {
    173         tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t,
    174             nh_link);
     143/*
     144 * Implementation of hash table interface for the nodes hash table.
     145 */
     146
     147typedef struct {
     148        service_id_t service_id;
     149        fs_index_t index;
     150} node_key_t;
     151
     152static size_t nodes_key_hash(void *k)
     153{
     154        node_key_t *key = (node_key_t *)k;
     155        return hash_combine(key->service_id, key->index);
     156}
     157
     158static size_t nodes_hash(const ht_link_t *item)
     159{
     160        tmpfs_node_t *nodep = hash_table_get_inst(item, tmpfs_node_t, nh_link);
     161        return hash_combine(nodep->service_id, nodep->index);
     162}
     163
     164static bool nodes_key_equal(void *key_arg, const ht_link_t *item)
     165{
     166        tmpfs_node_t *node = hash_table_get_inst(item, tmpfs_node_t, nh_link);
     167        node_key_t *key = (node_key_t *)key_arg;
     168       
     169        return key->service_id == node->service_id && key->index == node->index;
     170}
     171
     172static void nodes_remove_callback(ht_link_t *item)
     173{
     174        tmpfs_node_t *nodep = hash_table_get_inst(item, tmpfs_node_t, nh_link);
    175175
    176176        while (!list_empty(&nodep->cs_list)) {
     
    192192
    193193/** TMPFS nodes hash table operations. */
    194 hash_table_operations_t nodes_ops = {
     194hash_table_ops_t nodes_ops = {
    195195        .hash = nodes_hash,
    196         .compare = nodes_compare,
     196        .key_hash = nodes_key_hash,
     197        .key_equal = nodes_key_equal,
     198        .equal = NULL,
    197199        .remove_callback = nodes_remove_callback
    198200};
     
    207209        nodep->size = 0;
    208210        nodep->data = NULL;
    209         link_initialize(&nodep->nh_link);
    210211        list_initialize(&nodep->cs_list);
    211212}
     
    220221bool tmpfs_init(void)
    221222{
    222         if (!hash_table_create(&nodes, NODES_BUCKETS, 2, &nodes_ops))
     223        if (!hash_table_create(&nodes, 0, 0, &nodes_ops))
    223224                return false;
    224225       
     
    238239}
    239240
     241static bool rm_service_id_nodes(ht_link_t *item, void *arg)
     242{
     243        service_id_t sid = *(service_id_t*)arg;
     244        tmpfs_node_t *node = hash_table_get_inst(item, tmpfs_node_t, nh_link);
     245       
     246        if (node->service_id == sid) {
     247                hash_table_remove_item(&nodes, &node->nh_link);
     248        }
     249        return true;
     250}
     251
    240252static void tmpfs_instance_done(service_id_t service_id)
    241 {
    242         unsigned long key[] = {
    243                 [NODES_KEY_DEV] = service_id
    244         };
    245         /*
    246          * Here we are making use of one special feature of our hash table
    247          * implementation, which allows to remove more items based on a partial
    248          * key match. In the following, we are going to remove all nodes
    249          * matching our device handle. The nodes_remove_callback() function will
    250          * take care of resource deallocation.
    251          */
    252         hash_table_remove(&nodes, key, 1);
     253{       
     254        hash_table_apply(&nodes, rm_service_id_nodes, &service_id);
    253255}
    254256
     
    272274int tmpfs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index)
    273275{
    274         unsigned long key[] = {
    275                 [NODES_KEY_DEV] = service_id,
    276                 [NODES_KEY_INDEX] = index
     276        node_key_t key = {
     277                .service_id = service_id,
     278                .index = index
    277279        };
    278         link_t *lnk = hash_table_find(&nodes, key);
     280       
     281        ht_link_t *lnk = hash_table_find(&nodes, &key);
     282       
    279283        if (lnk) {
    280284                tmpfs_node_t *nodep;
    281                 nodep = hash_table_get_instance(lnk, tmpfs_node_t, nh_link);
     285                nodep = hash_table_get_inst(lnk, tmpfs_node_t, nh_link);
    282286                *rfn = FS_NODE(nodep);
    283287        } else {
     
    331335
    332336        /* Insert the new node into the nodes hash table. */
    333         unsigned long key[] = {
    334                 [NODES_KEY_DEV] = nodep->service_id,
    335                 [NODES_KEY_INDEX] = nodep->index
    336         };
    337         hash_table_insert(&nodes, key, &nodep->nh_link);
     337        hash_table_insert(&nodes, &nodep->nh_link);
    338338        *rfn = FS_NODE(nodep);
    339339        return EOK;
     
    346346        assert(!nodep->lnkcnt);
    347347        assert(list_empty(&nodep->cs_list));
    348 
    349         unsigned long key[] = {
    350                 [NODES_KEY_DEV] = nodep->service_id,
    351                 [NODES_KEY_INDEX] = nodep->index
    352         };
    353         hash_table_remove(&nodes, key, 2);
     348       
     349        hash_table_remove_item(&nodes, &nodep->nh_link);
    354350
    355351        /*
     
    476472         * Lookup the respective TMPFS node.
    477473         */
    478         link_t *hlp;
    479         unsigned long key[] = {
    480                 [NODES_KEY_DEV] = service_id,
    481                 [NODES_KEY_INDEX] = index
     474        node_key_t key = {
     475                .service_id = service_id,
     476                .index = index
    482477        };
    483         hlp = hash_table_find(&nodes, key);
     478       
     479        ht_link_t *hlp = hash_table_find(&nodes, &key);
    484480        if (!hlp)
    485481                return ENOENT;
    486         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    487             nh_link);
     482       
     483        tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link);
    488484       
    489485        /*
     
    538534         * Lookup the respective TMPFS node.
    539535         */
    540         link_t *hlp;
    541         unsigned long key[] = {
    542                 [NODES_KEY_DEV] = service_id,
    543                 [NODES_KEY_INDEX] = index
     536        node_key_t key = {
     537                .service_id = service_id,
     538                .index = index
    544539        };
    545         hlp = hash_table_find(&nodes, key);
     540       
     541        ht_link_t *hlp = hash_table_find(&nodes, &key);
     542       
    546543        if (!hlp)
    547544                return ENOENT;
    548         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
    549             nh_link);
     545       
     546        tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link);
    550547
    551548        /*
     
    600597         * Lookup the respective TMPFS node.
    601598         */
    602         unsigned long key[] = {
    603                 [NODES_KEY_DEV] = service_id,
    604                 [NODES_KEY_INDEX] = index
     599        node_key_t key = {
     600                .service_id = service_id,
     601                .index = index
    605602        };
    606         link_t *hlp = hash_table_find(&nodes, key);
     603       
     604        ht_link_t *hlp = hash_table_find(&nodes, &key);
     605       
    607606        if (!hlp)
    608607                return ENOENT;
    609         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t, nh_link);
     608        tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link);
    610609       
    611610        if (size == nodep->size)
     
    636635static int tmpfs_destroy(service_id_t service_id, fs_index_t index)
    637636{
    638         link_t *hlp;
    639         unsigned long key[] = {
    640                 [NODES_KEY_DEV] = service_id,
    641                 [NODES_KEY_INDEX] = index
     637        node_key_t key = {
     638                .service_id = service_id,
     639                .index = index
    642640        };
    643         hlp = hash_table_find(&nodes, key);
     641       
     642        ht_link_t *hlp = hash_table_find(&nodes, &key);
    644643        if (!hlp)
    645644                return ENOENT;
    646         tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,
     645        tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t,
    647646            nh_link);
    648647        return tmpfs_destroy_node(FS_NODE(nodep));
  • uspace/srv/fs/udf/udf_idx.h

    r80445cf r4c53333  
    11/*
    2  * Copyright (c) 2011 Martin Sucha
     2 * Copyright (c) 2012 Julia Medvedeva
    33 * All rights reserved.
    44 *
     
    2929/** @addtogroup fs
    3030 * @{
    31  */ 
     31 */
    3232
    33 #ifndef EXT2FS_EXT2FS_H_
    34 #define EXT2FS_EXT2FS_H_
     33#ifndef UDF_IDX_H_
     34#define UDF_IDX_H_
    3535
    36 #include <libext2.h>
    37 #include <libfs.h>
    38 #include <sys/types.h>
     36#include "udf.h"
    3937
    40 #define min(a, b)               ((a) < (b) ? (a) : (b))
     38extern int udf_idx_init(void);
     39extern int udf_idx_fini(void);
     40extern int udf_idx_get(udf_node_t **, udf_instance_t *, fs_index_t);
     41extern int udf_idx_add(udf_node_t **, udf_instance_t *, fs_index_t);
     42extern int udf_idx_del(udf_node_t *);
    4143
    42 extern vfs_out_ops_t ext2fs_ops;
    43 extern libfs_ops_t ext2fs_libfs_ops;
    44 
    45 extern int ext2fs_global_init(void);
    46 extern int ext2fs_global_fini(void);
    47 
    48 #endif
     44#endif /* UDF_IDX_H_ */
    4945
    5046/**
Note: See TracChangeset for help on using the changeset viewer.