Changeset bc216a0 in mainline for uspace/srv
- Timestamp:
- 2012-08-07T22:13:44Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- da68871a
- Parents:
- b17518e
- Location:
- uspace/srv
- Files:
-
- 20 edited
-
devman/devman.c (modified) (12 diffs)
-
devman/devman.h (modified) (2 diffs)
-
fs/cdfs/cdfs_ops.c (modified) (14 diffs)
-
fs/exfat/exfat.h (modified) (1 diff)
-
fs/exfat/exfat_idx.c (modified) (16 diffs)
-
fs/exfat/exfat_ops.c (modified) (1 diff)
-
fs/ext2fs/ext2fs_ops.c (modified) (9 diffs)
-
fs/fat/fat.h (modified) (1 diff)
-
fs/fat/fat_idx.c (modified) (16 diffs)
-
fs/locfs/locfs_ops.c (modified) (16 diffs)
-
fs/mfs/mfs.h (modified) (1 diff)
-
fs/mfs/mfs_ops.c (modified) (8 diffs)
-
fs/tmpfs/tmpfs.h (modified) (1 diff)
-
fs/tmpfs/tmpfs_ops.c (modified) (12 diffs)
-
hid/input/generic/gsp.c (modified) (4 diffs)
-
hid/input/include/gsp.h (modified) (1 diff)
-
ns/service.c (modified) (9 diffs)
-
ns/task.c (modified) (17 diffs)
-
vfs/vfs.h (modified) (2 diffs)
-
vfs/vfs_node.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/devman/devman.c
rb17518e rbc216a0 66 66 /* hash table operations */ 67 67 68 static size_t devices_key_hash(unsigned long key[]) 69 { 70 return key[0]; 71 } 72 73 static size_t devman_devices_hash(const link_t *item) 74 { 75 dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev); 76 unsigned long key = dev->handle; 77 return devices_key_hash(&key); 78 } 79 80 static size_t devman_functions_hash(const link_t *item) 81 { 82 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun); 83 unsigned long key = fun->handle; 84 return devices_key_hash(&key); 85 } 86 87 static size_t loc_functions_hash(const link_t *item) 88 { 89 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun); 90 unsigned long key = fun->service_id; 91 return devices_key_hash(&key); 92 } 93 94 static bool devman_devices_match(unsigned long key[], size_t keys, 95 const link_t *item) 96 { 97 dev_node_t *dev = hash_table_get_instance(item, dev_node_t, devman_dev); 98 return (dev->handle == (devman_handle_t) key[0]); 99 } 100 101 static bool devman_functions_match(unsigned long key[], size_t keys, 102 const link_t *item) 103 { 104 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, devman_fun); 105 return (fun->handle == (devman_handle_t) key[0]); 106 } 107 108 static bool loc_functions_match(unsigned long key[], size_t keys, 109 const link_t *item) 110 { 111 fun_node_t *fun = hash_table_get_instance(item, fun_node_t, loc_fun); 112 return (fun->service_id == (service_id_t) key[0]); 68 static inline size_t handle_key_hash(void *key) 69 { 70 devman_handle_t handle = *(devman_handle_t*)key; 71 return handle; 72 } 73 74 static size_t devman_devices_hash(const ht_link_t *item) 75 { 76 dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev); 77 return handle_key_hash(&dev->handle); 78 } 79 80 static size_t devman_functions_hash(const ht_link_t *item) 81 { 82 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun); 83 return handle_key_hash(&fun->handle); 84 } 85 86 static bool devman_devices_key_equal(void *key, const ht_link_t *item) 87 { 88 devman_handle_t handle = *(devman_handle_t*)key; 89 dev_node_t *dev = hash_table_get_inst(item, dev_node_t, devman_dev); 90 return dev->handle == handle; 91 } 92 93 static bool devman_functions_key_equal(void *key, const ht_link_t *item) 94 { 95 devman_handle_t handle = *(devman_handle_t*)key; 96 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, devman_fun); 97 return fun->handle == handle; 98 } 99 100 static inline size_t service_id_key_hash(void *key) 101 { 102 service_id_t service_id = *(service_id_t*)key; 103 return service_id; 104 } 105 106 static size_t loc_functions_hash(const ht_link_t *item) 107 { 108 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun); 109 return service_id_key_hash(&fun->service_id); 110 } 111 112 static bool loc_functions_key_equal(void *key, const ht_link_t *item) 113 { 114 service_id_t service_id = *(service_id_t*)key; 115 fun_node_t *fun = hash_table_get_inst(item, fun_node_t, loc_fun); 116 return fun->service_id == service_id; 113 117 } 114 118 … … 116 120 static hash_table_ops_t devman_devices_ops = { 117 121 .hash = devman_devices_hash, 118 .key_hash = devices_key_hash,119 . match = devman_devices_match,122 .key_hash = handle_key_hash, 123 .key_equal = devman_devices_key_equal, 120 124 .equal = 0, 121 125 .remove_callback = 0 … … 124 128 static hash_table_ops_t devman_functions_ops = { 125 129 .hash = devman_functions_hash, 126 .key_hash = devices_key_hash,127 . match = devman_functions_match,130 .key_hash = handle_key_hash, 131 .key_equal = devman_functions_key_equal, 128 132 .equal = 0, 129 133 .remove_callback = 0 … … 132 136 static hash_table_ops_t loc_devices_ops = { 133 137 .hash = loc_functions_hash, 134 .key_hash = devices_key_hash,135 . match = loc_functions_match,138 .key_hash = service_id_key_hash, 139 .key_equal = loc_functions_key_equal, 136 140 .equal = 0, 137 141 .remove_callback = 0 … … 998 1002 tree->current_handle = 0; 999 1003 1000 hash_table_create(&tree->devman_devices, 0, 1, &devman_devices_ops);1001 hash_table_create(&tree->devman_functions, 0, 1, &devman_functions_ops);1002 hash_table_create(&tree->loc_functions, 0, 1, &loc_devices_ops);1004 hash_table_create(&tree->devman_devices, 0, 0, &devman_devices_ops); 1005 hash_table_create(&tree->devman_functions, 0, 0, &devman_functions_ops); 1006 hash_table_create(&tree->loc_functions, 0, 0, &loc_devices_ops); 1003 1007 1004 1008 fibril_rwlock_initialize(&tree->rwlock); … … 1034 1038 list_initialize(&dev->functions); 1035 1039 link_initialize(&dev->driver_devices); 1036 link_initialize(&dev->devman_dev);1037 1040 1038 1041 return dev; … … 1082 1085 dev_node_t *find_dev_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1083 1086 { 1084 unsigned long key = handle;1085 link_t *link;1086 1087 1087 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1088 1088 1089 link = hash_table_find(&tree->devman_devices, &key);1089 ht_link_t *link = hash_table_find(&tree->devman_devices, &handle); 1090 1090 if (link == NULL) 1091 1091 return NULL; 1092 1092 1093 return hash_table_get_inst ance(link, dev_node_t, devman_dev);1093 return hash_table_get_inst(link, dev_node_t, devman_dev); 1094 1094 } 1095 1095 … … 1165 1165 link_initialize(&fun->dev_functions); 1166 1166 list_initialize(&fun->match_ids.ids); 1167 link_initialize(&fun->devman_fun);1168 link_initialize(&fun->loc_fun);1169 1167 1170 1168 return fun; … … 1215 1213 fun_node_t *find_fun_node_no_lock(dev_tree_t *tree, devman_handle_t handle) 1216 1214 { 1217 unsigned long key = handle;1218 link_t *link;1219 1215 fun_node_t *fun; 1220 1216 1221 1217 assert(fibril_rwlock_is_locked(&tree->rwlock)); 1222 1218 1223 link = hash_table_find(&tree->devman_functions, &key);1219 ht_link_t *link = hash_table_find(&tree->devman_functions, &handle); 1224 1220 if (link == NULL) 1225 1221 return NULL; 1226 1222 1227 fun = hash_table_get_inst ance(link, fun_node_t, devman_fun);1223 fun = hash_table_get_inst(link, fun_node_t, devman_fun); 1228 1224 1229 1225 return fun; … … 1324 1320 1325 1321 /* Remove node from the handle-to-node map. */ 1326 unsigned long key = dev->handle; 1327 hash_table_remove(&tree->devman_devices, &key, 1); 1322 hash_table_remove(&tree->devman_devices, &dev->handle); 1328 1323 1329 1324 /* Unlink from parent function. */ … … 1386 1381 1387 1382 /* Remove the node from the handle-to-node map. */ 1388 unsigned long key = fun->handle; 1389 hash_table_remove(&tree->devman_functions, &key, 1); 1383 hash_table_remove(&tree->devman_functions, &fun->handle); 1390 1384 1391 1385 /* Remove the node from the list of its parent's children. */ … … 1500 1494 { 1501 1495 fun_node_t *fun = NULL; 1502 link_t *link;1503 unsigned long key = (unsigned long) service_id;1504 1496 1505 1497 fibril_rwlock_read_lock(&tree->rwlock); 1506 link = hash_table_find(&tree->loc_functions, &key);1498 ht_link_t *link = hash_table_find(&tree->loc_functions, &service_id); 1507 1499 if (link != NULL) { 1508 fun = hash_table_get_inst ance(link, fun_node_t, loc_fun);1500 fun = hash_table_get_inst(link, fun_node_t, loc_fun); 1509 1501 fun_add_ref(fun); 1510 1502 } -
uspace/srv/devman/devman.h
rb17518e rbc216a0 150 150 * Used by the hash table of devices indexed by devman device handles. 151 151 */ 152 link_t devman_dev;152 ht_link_t devman_dev; 153 153 154 154 /** … … 201 201 * Used by the hash table of functions indexed by devman device handles. 202 202 */ 203 link_t devman_fun;203 ht_link_t devman_fun; 204 204 205 205 /** 206 206 * Used by the hash table of functions indexed by service IDs. 207 207 */ 208 link_t loc_fun;208 ht_link_t loc_fun; 209 209 }; 210 210 -
uspace/srv/fs/cdfs/cdfs_ops.c
rb17518e rbc216a0 37 37 */ 38 38 39 #include "cdfs_ops.h" 39 40 #include <bool.h> 40 41 #include <adt/hash_table.h> 42 #include <adt/hash.h> 41 43 #include <malloc.h> 42 44 #include <mem.h> … … 50 52 #include "cdfs.h" 51 53 #include "cdfs_endian.h" 52 #include "cdfs_ops.h"53 54 54 55 /** Standard CD-ROM block size */ 55 56 #define BLOCK_SIZE 2048 56 57 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_KEY_SRVC 0 66 #define NODES_KEY_INDEX 1 58 #define NODE_CACHE_SIZE 200 67 59 68 60 /** All root nodes have index 0 */ … … 203 195 service_id_t service_id; /**< Service ID of block device */ 204 196 205 link_t nh_link;/**< Nodes hash table link */197 ht_link_t nh_link; /**< Nodes hash table link */ 206 198 cdfs_dentry_type_t type; /**< Dentry type */ 207 199 … … 224 216 static hash_table_t nodes; 225 217 226 static size_t nodes_key_hash(unsigned long key[]) 227 { 228 return key[NODES_KEY_INDEX]; 229 } 230 231 static size_t nodes_hash(const link_t *item) 232 { 233 cdfs_node_t *node = hash_table_get_instance(item, cdfs_node_t, nh_link); 234 235 unsigned long key[] = { 236 [NODES_KEY_INDEX] = node->index 237 }; 238 239 return nodes_key_hash(key); 240 } 241 242 static bool nodes_match(unsigned long key[], size_t keys, const link_t *item) 243 { 244 cdfs_node_t *node = hash_table_get_instance(item, cdfs_node_t, nh_link); 245 246 if (keys == 1) { 247 return (node->service_id == key[NODES_KEY_SRVC]); 248 } else { 249 assert(keys == 2); 250 return ((node->service_id == key[NODES_KEY_SRVC]) && 251 (node->index == key[NODES_KEY_INDEX])); 252 } 253 } 254 255 static bool nodes_equal(const link_t *item1, const link_t *item2) 256 { 257 cdfs_node_t *node1 = hash_table_get_instance(item1, cdfs_node_t, nh_link); 258 cdfs_node_t *node2 = hash_table_get_instance(item2, cdfs_node_t, nh_link); 259 260 return node1->service_id == node2->service_id 261 && node1->index == node2->index; 262 } 263 264 static void nodes_remove_callback(link_t *item) 265 { 266 cdfs_node_t *node = hash_table_get_instance(item, cdfs_node_t, nh_link); 218 /* 219 * Hash table support functions. 220 */ 221 222 typedef struct { 223 service_id_t service_id; 224 fs_index_t index; 225 } ht_key_t; 226 227 static 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 233 static 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 239 static 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 247 static void nodes_remove_callback(ht_link_t *item) 248 { 249 cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link); 267 250 268 251 assert(node->type == CDFS_DIRECTORY); … … 283 266 .hash = nodes_hash, 284 267 .key_hash = nodes_key_hash, 285 . match = nodes_match,286 .equal = nodes_equal,268 .key_equal = nodes_key_equal, 269 .equal = 0, 287 270 .remove_callback = nodes_remove_callback 288 271 }; … … 291 274 fs_index_t index) 292 275 { 293 unsigned long key[]= {294 [NODES_KEY_SRVC] = service_id,295 [NODES_KEY_INDEX] = index276 ht_key_t key = { 277 .index = index, 278 .service_id = service_id 296 279 }; 297 280 298 link_t *link = hash_table_find(&nodes,key);281 ht_link_t *link = hash_table_find(&nodes, &key); 299 282 if (link) { 300 283 cdfs_node_t *node = 301 hash_table_get_inst ance(link, cdfs_node_t, nh_link);284 hash_table_get_inst(link, cdfs_node_t, nh_link); 302 285 303 286 *rfn = FS_NODE(node); … … 325 308 node->opened = 0; 326 309 327 link_initialize(&node->nh_link);328 310 list_initialize(&node->cs_list); 329 311 } … … 517 499 static fs_node_t *get_cached_node(service_id_t service_id, fs_index_t index) 518 500 { 519 unsigned long key[]= {520 [NODES_KEY_SRVC] = service_id,521 [NODES_KEY_INDEX] = index501 ht_key_t key = { 502 .index = index, 503 .service_id = service_id 522 504 }; 523 505 524 link_t *link = hash_table_find(&nodes,key);506 ht_link_t *link = hash_table_find(&nodes, &key); 525 507 if (link) { 526 508 cdfs_node_t *node = 527 hash_table_get_inst ance(link, cdfs_node_t, nh_link);509 hash_table_get_inst(link, cdfs_node_t, nh_link); 528 510 return FS_NODE(node); 529 511 } … … 811 793 } 812 794 795 static 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 813 807 static void cdfs_instance_done(service_id_t service_id) 814 808 { 815 unsigned long key[] = { 816 [NODES_KEY_SRVC] = service_id 817 }; 818 819 hash_table_remove(&nodes, key, 1); 809 hash_table_apply(&nodes, rm_service_id_nodes, &service_id); 820 810 block_cache_fini(service_id); 821 811 block_fini(service_id); … … 831 821 size_t *rbytes) 832 822 { 833 unsigned long key[]= {834 [NODES_KEY_SRVC] = service_id,835 [NODES_KEY_INDEX] = index823 ht_key_t key = { 824 .index = index, 825 .service_id = service_id 836 826 }; 837 827 838 link_t *link = hash_table_find(&nodes,key);828 ht_link_t *link = hash_table_find(&nodes, &key); 839 829 if (link == NULL) 840 830 return ENOENT; 841 831 842 832 cdfs_node_t *node = 843 hash_table_get_inst ance(link, cdfs_node_t, nh_link);833 hash_table_get_inst(link, cdfs_node_t, nh_link); 844 834 845 835 if (!node->processed) { … … 921 911 } 922 912 923 static bool cache_remove_closed( link_t *item, void *arg)913 static bool cache_remove_closed(ht_link_t *item, void *arg) 924 914 { 925 915 size_t *premove_cnt = (size_t*)arg; … … 927 917 /* Some nodes were requested to be removed from the cache. */ 928 918 if (0 < *premove_cnt) { 929 cdfs_node_t *node = hash_table_get_inst ance(item, cdfs_node_t, nh_link);919 cdfs_node_t *node = hash_table_get_inst(item, cdfs_node_t, nh_link); 930 920 931 921 if (!node->opened) { … … 957 947 return EOK; 958 948 959 unsigned long key[]= {960 [NODES_KEY_SRVC] = service_id,961 [NODES_KEY_INDEX] = index949 ht_key_t key = { 950 .index = index, 951 .service_id = service_id 962 952 }; 963 953 964 link_t *link = hash_table_find(&nodes,key);954 ht_link_t *link = hash_table_find(&nodes, &key); 965 955 if (link == 0) 966 956 return ENOENT; 967 957 968 958 cdfs_node_t *node = 969 hash_table_get_inst ance(link, cdfs_node_t, nh_link);959 hash_table_get_inst(link, cdfs_node_t, nh_link); 970 960 971 961 assert(node->opened > 0); … … 1013 1003 bool cdfs_init(void) 1014 1004 { 1015 if (!hash_table_create(&nodes, 0, 2, &nodes_ops))1005 if (!hash_table_create(&nodes, 0, 0, &nodes_ops)) 1016 1006 return false; 1017 1007 -
uspace/srv/fs/exfat/exfat.h
rb17518e rbc216a0 106 106 typedef struct { 107 107 /** Used indices (position) hash table link. */ 108 link_t uph_link;108 ht_link_t uph_link; 109 109 /** Used indices (index) hash table link. */ 110 link_t uih_link;110 ht_link_t uih_link; 111 111 112 112 fibril_mutex_t lock; -
uspace/srv/fs/exfat/exfat_idx.c
rb17518e rbc216a0 41 41 #include <str.h> 42 42 #include <adt/hash_table.h> 43 #include <adt/hash.h> 43 44 #include <adt/list.h> 44 45 #include <assert.h> … … 91 92 if (lock) 92 93 fibril_mutex_lock(&unused_lock); 94 93 95 list_foreach(unused_list, l) { 94 96 u = list_get_instance(l, unused_t, link); … … 112 114 static hash_table_t up_hash; 113 115 114 #define UPH_SID_KEY 0 115 #define UPH_PFC_KEY 1 116 #define UPH_PDI_KEY 2 117 118 static size_t pos_key_hash(unsigned long key[]) 119 { 120 /* Inspired by Effective Java, 2nd edition. */ 121 size_t hash = 17; 122 123 hash = 31 * hash + key[UPH_PFC_KEY]; 124 hash = 31 * hash + key[UPH_PDI_KEY]; 125 hash = 31 * hash + key[UPH_SID_KEY]; 126 127 return hash; 128 } 129 130 static size_t pos_hash(const link_t *item) 131 { 132 exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uph_link); 133 134 unsigned long pkey[] = { 135 [UPH_SID_KEY] = fidx->service_id, 136 [UPH_PFC_KEY] = fidx->pfc, 137 [UPH_PDI_KEY] = fidx->pdi, 138 }; 139 140 return pos_key_hash(pkey); 141 } 142 143 static bool pos_match(unsigned long key[], size_t keys, const link_t *item) 144 { 145 service_id_t service_id = (service_id_t)key[UPH_SID_KEY]; 116 typedef struct { 117 service_id_t service_id; 146 118 exfat_cluster_t pfc; 147 119 unsigned pdi; 148 exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uph_link); 149 150 switch (keys) { 151 case 1: 152 return (service_id == fidx->service_id); 153 case 3: 154 pfc = (exfat_cluster_t) key[UPH_PFC_KEY]; 155 pdi = (unsigned) key[UPH_PDI_KEY]; 156 return (service_id == fidx->service_id) && (pfc == fidx->pfc) && 157 (pdi == fidx->pdi); 158 default: 159 assert((keys == 1) || (keys == 3)); 160 } 161 162 return 0; 120 } pos_key_t; 121 122 static 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 131 static 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 144 static 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; 163 152 } 164 153 … … 166 155 .hash = pos_hash, 167 156 .key_hash = pos_key_hash, 168 . match = pos_match,157 .key_equal = pos_key_equal, 169 158 .equal = 0, 170 159 .remove_callback = 0, … … 177 166 static hash_table_t ui_hash; 178 167 179 #define UIH_SID_KEY 0 180 #define UIH_INDEX_KEY 1 181 182 static size_t idx_key_hash(unsigned long key[]) 183 { 184 service_id_t service_id = (service_id_t)key[UIH_SID_KEY]; 185 fs_index_t index = (fs_index_t)key[UIH_INDEX_KEY]; 186 187 /* 188 * Compute a simple hash unlimited by specific table size as per: 189 * Effective Java, 2nd edition. 190 */ 191 size_t hash = 17; 192 hash = 31 * hash + (size_t)service_id; 193 hash = 31 * hash + (size_t)index; 194 return hash; 195 } 196 197 static size_t idx_hash(const link_t *item) 198 { 199 exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uih_link); 200 201 unsigned long ikey[] = { 202 [UIH_SID_KEY] = fidx->service_id, 203 [UIH_INDEX_KEY] = fidx->index, 204 }; 205 206 return idx_key_hash(ikey); 207 } 208 209 static bool idx_match(unsigned long key[], size_t keys, const link_t *item) 210 { 211 service_id_t service_id = (service_id_t)key[UIH_SID_KEY]; 168 typedef struct { 169 service_id_t service_id; 212 170 fs_index_t index; 213 exfat_idx_t *fidx = list_get_instance(item, exfat_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 exfat_idx_t *fidx = list_get_instance(item, exfat_idx_t, uih_link); 171 } idx_key_t; 172 173 static 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 179 static 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 185 static 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 193 static void idx_remove_callback(ht_link_t *item) 194 { 195 exfat_idx_t *fidx = hash_table_get_inst(item, exfat_idx_t, uih_link); 232 196 233 197 free(fidx); … … 237 201 .hash = idx_hash, 238 202 .key_hash = idx_key_hash, 239 . match = idx_match,203 .key_equal = idx_key_equal, 240 204 .equal = 0, 241 205 .remove_callback = idx_remove_callback, … … 379 343 } 380 344 381 link_initialize(&fidx->uph_link);382 link_initialize(&fidx->uih_link);383 345 fibril_mutex_initialize(&fidx->lock); 384 346 fidx->service_id = service_id; … … 415 377 { 416 378 exfat_idx_t *fidx; 417 link_t *l;418 unsigned long pkey[]= {419 [UPH_SID_KEY]= service_id,420 [UPH_PFC_KEY]= pfc,421 [UPH_PDI_KEY]= pdi,379 380 pos_key_t pos_key = { 381 .service_id = service_id, 382 .pfc = pfc, 383 .pdi = pdi, 422 384 }; 423 385 424 386 fibril_mutex_lock(&used_lock); 425 l = hash_table_find(&up_hash, pkey);387 ht_link_t *l = hash_table_find(&up_hash, &pos_key); 426 388 if (l) { 427 fidx = hash_table_get_inst ance(l, exfat_idx_t, uph_link);389 fidx = hash_table_get_inst(l, exfat_idx_t, uph_link); 428 390 } else { 429 391 int rc; … … 456 418 void exfat_idx_hashout(exfat_idx_t *idx) 457 419 { 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_remove(&up_hash, pkey, 3); 420 fibril_mutex_lock(&used_lock); 421 hash_table_remove_item(&up_hash, &idx->uph_link); 466 422 fibril_mutex_unlock(&used_lock); 467 423 } … … 471 427 { 472 428 exfat_idx_t *fidx = NULL; 473 link_t *l; 474 unsigned long ikey[]= {475 [UIH_SID_KEY]= service_id,476 [UIH_INDEX_KEY]= index,429 430 idx_key_t idx_key = { 431 .service_id = service_id, 432 .index = index, 477 433 }; 478 434 479 435 fibril_mutex_lock(&used_lock); 480 l = hash_table_find(&ui_hash, ikey);436 ht_link_t *l = hash_table_find(&ui_hash, &idx_key); 481 437 if (l) { 482 fidx = hash_table_get_inst ance(l, exfat_idx_t, uih_link);438 fidx = hash_table_get_inst(l, exfat_idx_t, uih_link); 483 439 fibril_mutex_lock(&fidx->lock); 484 440 } … … 494 450 void exfat_idx_destroy(exfat_idx_t *idx) 495 451 { 496 unsigned long ikey[]= {497 [UIH_SID_KEY]= idx->service_id,498 [UIH_INDEX_KEY]= idx->index,452 idx_key_t idx_key = { 453 .service_id = idx->service_id, 454 .index = idx->index, 499 455 }; 500 service_id_t service_id = idx->service_id;501 fs_index_t index = idx->index;502 456 503 457 /* TODO: assert(idx->pfc == FAT_CLST_RES0); */ … … 510 464 * the index hash only. 511 465 */ 512 hash_table_remove(&ui_hash, ikey, 2);466 hash_table_remove(&ui_hash, &idx_key); 513 467 fibril_mutex_unlock(&used_lock); 514 468 /* Release the VFS index. */ 515 exfat_index_free( service_id,index);469 exfat_index_free(idx_key.service_id, idx_key.index); 516 470 /* The index structure itself is freed in idx_remove_callback(). */ 517 471 } … … 519 473 int exfat_idx_init(void) 520 474 { 521 if (!hash_table_create(&up_hash, 0, 3, &uph_ops))475 if (!hash_table_create(&up_hash, 0, 0, &uph_ops)) 522 476 return ENOMEM; 523 if (!hash_table_create(&ui_hash, 0, 2, &uih_ops)) {477 if (!hash_table_create(&ui_hash, 0, 0, &uih_ops)) { 524 478 hash_table_destroy(&up_hash); 525 479 return ENOMEM; … … 531 485 { 532 486 /* We assume the hash tables are empty. */ 487 assert(hash_table_empty(&up_hash) && hash_table_empty(&ui_hash)); 533 488 hash_table_destroy(&up_hash); 534 489 hash_table_destroy(&ui_hash); … … 555 510 } 556 511 512 static 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 524 static 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 557 536 void exfat_idx_fini_by_service_id(service_id_t service_id) 558 537 { 559 unsigned long ikey[] = {560 [UIH_SID_KEY] = service_id561 };562 unsigned long pkey[] = {563 [UPH_SID_KEY] = service_id564 };565 566 538 /* 567 539 * Remove this instance's index structure from up_hash and ui_hash. … … 570 542 */ 571 543 fibril_mutex_lock(&used_lock); 572 hash_table_ remove(&up_hash, pkey, 1);573 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); 574 546 fibril_mutex_unlock(&used_lock); 575 547 -
uspace/srv/fs/exfat/exfat_ops.c
rb17518e rbc216a0 54 54 #include <byteorder.h> 55 55 #include <adt/hash_table.h> 56 #include <adt/hash.h> 56 57 #include <adt/list.h> 57 58 #include <assert.h> -
uspace/srv/fs/ext2fs/ext2fs_ops.c
rb17518e rbc216a0 49 49 #include <byteorder.h> 50 50 #include <adt/hash_table.h> 51 #include <adt/hash.h> 51 52 #include <adt/list.h> 52 53 #include <assert.h> … … 62 63 #define EXT2FS_NODE(node) ((node) ? (ext2fs_node_t *) (node)->data : NULL) 63 64 #define EXT2FS_DBG(format, ...) {if (false) printf("ext2fs: %s: " format "\n", __FUNCTION__, ##__VA_ARGS__);} 64 #define OPEN_NODES_KEYS 265 #define OPEN_NODES_DEV_HANDLE_KEY 066 #define OPEN_NODES_INODE_KEY 167 65 68 66 typedef struct ext2fs_instance { … … 77 75 ext2_inode_ref_t *inode_ref; 78 76 fs_node_t *fs_node; 79 link_t link;77 ht_link_t link; 80 78 unsigned int references; 81 79 } ext2fs_node_t; … … 121 119 static FIBRIL_MUTEX_INITIALIZE(open_nodes_lock); 122 120 123 /* Hash table interface for open nodes hash table */ 124 static size_t open_nodes_key_hash(unsigned long key[]) 125 { 126 /* Hash construction recommended in Effective Java, 2nd Edition. */ 127 size_t hash = 17; 128 hash = 31 * hash + key[OPEN_NODES_DEV_HANDLE_KEY]; 129 hash = 31 * hash + key[OPEN_NODES_INODE_KEY]; 130 return hash; 131 } 132 133 static size_t open_nodes_hash(const link_t *item) 134 { 135 ext2fs_node_t *enode = hash_table_get_instance(item, ext2fs_node_t, link); 121 /* 122 * Hash table interface for open nodes hash table 123 */ 124 125 typedef struct { 126 service_id_t service_id; 127 fs_index_t index; 128 } node_key_t; 129 130 static size_t open_nodes_key_hash(void *key) 131 { 132 node_key_t *node_key = (node_key_t*)key; 133 return hash_combine(node_key->service_id, node_key->index); 134 } 135 136 static size_t open_nodes_hash(const ht_link_t *item) 137 { 138 ext2fs_node_t *enode = hash_table_get_inst(item, ext2fs_node_t, link); 136 139 137 140 assert(enode->instance); 138 141 assert(enode->inode_ref); 139 142 140 unsigned long key[] = { 141 [OPEN_NODES_DEV_HANDLE_KEY] = enode->instance->service_id, 142 [OPEN_NODES_INODE_KEY] = enode->inode_ref->index, 143 }; 144 145 return open_nodes_key_hash(key); 146 } 147 148 static bool open_nodes_match(unsigned long key[], size_t keys, 149 const link_t *item) 150 { 151 ext2fs_node_t *enode = hash_table_get_instance(item, ext2fs_node_t, link); 152 assert(keys > 0); 153 if (enode->instance->service_id != 154 ((service_id_t) key[OPEN_NODES_DEV_HANDLE_KEY])) { 155 return false; 156 } 157 if (keys == 1) { 158 return true; 159 } 160 assert(keys == 2); 161 return (enode->inode_ref->index == key[OPEN_NODES_INODE_KEY]); 143 return hash_combine(enode->instance->service_id, enode->inode_ref->index); 144 } 145 146 static bool open_nodes_key_equal(void *key, const ht_link_t *item) 147 { 148 node_key_t *node_key = (node_key_t*)key; 149 ext2fs_node_t *enode = hash_table_get_inst(item, ext2fs_node_t, link); 150 151 return node_key->service_id == enode->instance->service_id 152 && node_key->index == enode->inode_ref->index; 162 153 } 163 154 … … 165 156 .hash = open_nodes_hash, 166 157 .key_hash = open_nodes_key_hash, 167 . match = open_nodes_match,158 .key_equal = open_nodes_key_equal, 168 159 .equal = 0, 169 160 .remove_callback = 0, … … 175 166 int ext2fs_global_init(void) 176 167 { 177 if (!hash_table_create(&open_nodes, 0, OPEN_NODES_KEYS, &open_nodes_ops)) {168 if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) { 178 169 return ENOMEM; 179 170 } … … 329 320 330 321 /* Check if the node is not already open */ 331 unsigned long key[]= {332 [OPEN_NODES_DEV_HANDLE_KEY]= inst->service_id,333 [OPEN_NODES_INODE_KEY] = index,322 node_key_t key = { 323 .service_id = inst->service_id, 324 .index = index 334 325 }; 335 link_t *already_open = hash_table_find(&open_nodes,key);326 ht_link_t *already_open = hash_table_find(&open_nodes, &key); 336 327 337 328 if (already_open) { 338 enode = hash_table_get_inst ance(already_open, ext2fs_node_t, link);329 enode = hash_table_get_inst(already_open, ext2fs_node_t, link); 339 330 *rfn = enode->fs_node; 340 331 enode->references++; … … 370 361 enode->references = 1; 371 362 enode->fs_node = node; 372 link_initialize(&enode->link);373 363 374 364 node->data = enode; … … 421 411 int ext2fs_node_put_core(ext2fs_node_t *enode) 422 412 { 423 int rc; 424 425 unsigned long key[] = { 426 [OPEN_NODES_DEV_HANDLE_KEY] = enode->instance->service_id, 427 [OPEN_NODES_INODE_KEY] = enode->inode_ref->index, 413 node_key_t key = { 414 .service_id = enode->instance->service_id, 415 .index = enode->inode_ref->index 428 416 }; 429 hash_table_remove(&open_nodes, key, OPEN_NODES_KEYS); 417 418 hash_table_remove(&open_nodes, &key); 419 430 420 assert(enode->instance->open_nodes_count > 0); 431 421 enode->instance->open_nodes_count--; 432 422 433 rc = ext2_filesystem_put_inode_ref(enode->inode_ref);423 int rc = ext2_filesystem_put_inode_ref(enode->inode_ref); 434 424 if (rc != EOK) { 435 425 EXT2FS_DBG("ext2_filesystem_put_inode_ref failed"); -
uspace/srv/fs/fat/fat.h
rb17518e rbc216a0 190 190 typedef struct { 191 191 /** Used indices (position) hash table link. */ 192 link_t uph_link;192 ht_link_t uph_link; 193 193 /** Used indices (index) hash table link. */ 194 link_t uih_link;194 ht_link_t uih_link; 195 195 196 196 fibril_mutex_t lock; -
uspace/srv/fs/fat/fat_idx.c
rb17518e rbc216a0 41 41 #include <str.h> 42 42 #include <adt/hash_table.h> 43 #include <adt/hash.h> 43 44 #include <adt/list.h> 44 45 #include <assert.h> 45 46 #include <fibril_synch.h> 46 47 #include <malloc.h> 47 48 48 49 49 /** Each instance of this type describes one interval of freed VFS indices. */ … … 59 59 */ 60 60 typedef struct { 61 link_t link;62 service_id_t service_id;61 link_t link; 62 service_id_t service_id; 63 63 64 64 /** Next unassigned index. */ … … 98 98 return u; 99 99 } 100 100 101 101 if (lock) 102 102 fibril_mutex_unlock(&unused_lock); … … 114 114 static hash_table_t up_hash; 115 115 116 #define UPH_SID_KEY 0 117 #define UPH_PFC_KEY 1 118 #define UPH_PDI_KEY 2 119 120 static size_t pos_key_hash(unsigned long key[]) 121 { 122 /* Inspired by Effective Java, 2nd edition. */ 123 size_t hash = 17; 124 125 hash = 31 * hash + key[UPH_PFC_KEY]; 126 hash = 31 * hash + key[UPH_PDI_KEY]; 127 hash = 31 * hash + key[UPH_SID_KEY]; 128 129 return hash; 130 } 131 132 static size_t pos_hash(const link_t *item) 133 { 134 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uph_link); 135 136 unsigned long pkey[] = { 137 [UPH_SID_KEY] = fidx->service_id, 138 [UPH_PFC_KEY] = fidx->pfc, 139 [UPH_PDI_KEY] = fidx->pdi, 140 }; 141 142 return pos_key_hash(pkey); 143 } 144 145 static bool pos_match(unsigned long key[], size_t keys, const link_t *item) 146 { 147 service_id_t service_id = (service_id_t)key[UPH_SID_KEY]; 116 typedef struct { 117 service_id_t service_id; 148 118 fat_cluster_t pfc; 149 119 unsigned pdi; 150 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uph_link); 151 152 switch (keys) { 153 case 1: 154 return (service_id == fidx->service_id); 155 case 3: 156 pfc = (fat_cluster_t) key[UPH_PFC_KEY]; 157 pdi = (unsigned) key[UPH_PDI_KEY]; 158 return (service_id == fidx->service_id) && (pfc == fidx->pfc) && 159 (pdi == fidx->pdi); 160 default: 161 assert((keys == 1) || (keys == 3)); 162 } 163 164 return 0; 120 } pos_key_t; 121 122 static 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 131 static 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 144 static 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; 165 152 } 166 153 … … 168 155 .hash = pos_hash, 169 156 .key_hash = pos_key_hash, 170 . match = pos_match,157 .key_equal = pos_key_equal, 171 158 .equal = 0, 172 159 .remove_callback = 0, … … 179 166 static hash_table_t ui_hash; 180 167 181 #define UIH_SID_KEY 0 182 #define UIH_INDEX_KEY 1 183 184 static size_t idx_key_hash(unsigned long key[]) 185 { 186 /* 187 * Compute a simple hash unlimited by specific table size as per: 188 * Effective Java, 2nd edition. 189 */ 190 size_t hash = 17; 191 hash = 31 * hash + key[UIH_SID_KEY]; 192 hash = 31 * hash + key[UIH_INDEX_KEY]; 193 return hash; 194 } 195 196 static size_t idx_hash(const link_t *item) 197 { 198 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link); 199 200 unsigned long ikey[] = { 201 [UIH_SID_KEY] = fidx->service_id, 202 [UIH_INDEX_KEY] = fidx->index, 203 }; 204 205 return idx_key_hash(ikey); 206 } 207 208 static bool idx_match(unsigned long key[], size_t keys, const link_t *item) 209 { 210 service_id_t service_id = (service_id_t)key[UIH_SID_KEY]; 168 typedef struct { 169 service_id_t service_id; 211 170 fs_index_t index; 212 fat_idx_t *fidx = list_get_instance(item, fat_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 fat_idx_t *fidx = list_get_instance(item, fat_idx_t, uih_link); 171 } idx_key_t; 172 173 static 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 179 static 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 185 static 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 193 static void idx_remove_callback(ht_link_t *item) 194 { 195 fat_idx_t *fidx = hash_table_get_inst(item, fat_idx_t, uih_link); 231 196 232 197 free(fidx); … … 236 201 .hash = idx_hash, 237 202 .key_hash = idx_key_hash, 238 . match = idx_match,203 .key_equal = idx_key_equal, 239 204 .equal = 0, 240 205 .remove_callback = idx_remove_callback, … … 378 343 } 379 344 380 link_initialize(&fidx->uph_link);381 link_initialize(&fidx->uih_link);382 345 fibril_mutex_initialize(&fidx->lock); 383 346 fidx->service_id = service_id; … … 414 377 { 415 378 fat_idx_t *fidx; 416 link_t *l; 417 unsigned long pkey[]= {418 [UPH_SID_KEY]= service_id,419 [UPH_PFC_KEY]= pfc,420 [UPH_PDI_KEY]= pdi,379 380 pos_key_t pos_key = { 381 .service_id = service_id, 382 .pfc = pfc, 383 .pdi = pdi, 421 384 }; 422 385 423 386 fibril_mutex_lock(&used_lock); 424 l = hash_table_find(&up_hash, pkey);387 ht_link_t *l = hash_table_find(&up_hash, &pos_key); 425 388 if (l) { 426 fidx = hash_table_get_inst ance(l, fat_idx_t, uph_link);389 fidx = hash_table_get_inst(l, fat_idx_t, uph_link); 427 390 } else { 428 391 int rc; … … 464 427 { 465 428 fat_idx_t *fidx = NULL; 466 link_t *l; 467 unsigned long ikey[]= {468 [UIH_SID_KEY]= service_id,469 [UIH_INDEX_KEY]= index,429 430 idx_key_t idx_key = { 431 .service_id = service_id, 432 .index = index, 470 433 }; 471 434 472 435 fibril_mutex_lock(&used_lock); 473 l = hash_table_find(&ui_hash, ikey);436 ht_link_t *l = hash_table_find(&ui_hash, &idx_key); 474 437 if (l) { 475 fidx = hash_table_get_inst ance(l, fat_idx_t, uih_link);438 fidx = hash_table_get_inst(l, fat_idx_t, uih_link); 476 439 fibril_mutex_lock(&fidx->lock); 477 440 } … … 487 450 void fat_idx_destroy(fat_idx_t *idx) 488 451 { 489 unsigned long ikey[]= {490 [UIH_SID_KEY]= idx->service_id,491 [UIH_INDEX_KEY]= idx->index,452 idx_key_t idx_key = { 453 .service_id = idx->service_id, 454 .index = idx->index, 492 455 }; 493 service_id_t service_id = idx->service_id;494 fs_index_t index = idx->index;495 456 496 457 assert(idx->pfc == FAT_CLST_RES0); … … 502 463 * the index hash only. 503 464 */ 504 hash_table_remove(&ui_hash, ikey, 2);465 hash_table_remove(&ui_hash, &idx_key); 505 466 fibril_mutex_unlock(&used_lock); 506 467 /* Release the VFS index. */ 507 fat_index_free( service_id,index);468 fat_index_free(idx_key.service_id, idx_key.index); 508 469 /* The index structure itself is freed in idx_remove_callback(). */ 509 470 } … … 511 472 int fat_idx_init(void) 512 473 { 513 if (!hash_table_create(&up_hash, 0, 3, &uph_ops))474 if (!hash_table_create(&up_hash, 0, 0, &uph_ops)) 514 475 return ENOMEM; 515 if (!hash_table_create(&ui_hash, 0, 2, &uih_ops)) {476 if (!hash_table_create(&ui_hash, 0, 0, &uih_ops)) { 516 477 hash_table_destroy(&up_hash); 517 478 return ENOMEM; … … 523 484 { 524 485 /* We assume the hash tables are empty. */ 486 assert(hash_table_empty(&up_hash) && hash_table_empty(&ui_hash)); 525 487 hash_table_destroy(&up_hash); 526 488 hash_table_destroy(&ui_hash); … … 547 509 } 548 510 511 static 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 523 static 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 549 535 void fat_idx_fini_by_service_id(service_id_t service_id) 550 536 { 551 unsigned long ikey[] = {552 [UIH_SID_KEY] = service_id553 };554 unsigned long pkey[] = {555 [UPH_SID_KEY] = service_id556 };557 558 537 /* 559 538 * Remove this instance's index structure from up_hash and ui_hash. … … 562 541 */ 563 542 fibril_mutex_lock(&used_lock); 564 hash_table_ remove(&up_hash, pkey, 1);565 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); 566 545 fibril_mutex_unlock(&used_lock); 567 546 -
uspace/srv/fs/locfs/locfs_ops.c
rb17518e rbc216a0 61 61 async_sess_t *sess; /**< If NULL, the structure is incomplete. */ 62 62 size_t refcount; 63 link_t link;63 ht_link_t link; 64 64 fibril_condvar_t cv; /**< Broadcast when completed. */ 65 65 } service_t; … … 71 71 static FIBRIL_MUTEX_INITIALIZE(services_mutex); 72 72 73 #define SERVICES_KEYS 174 #define SERVICES_KEY_HANDLE 075 76 73 /* Implementation of hash table interface for the nodes hash table. */ 77 74 78 static size_t services_key_hash(unsigned long key[]) 79 { 80 return key[SERVICES_KEY_HANDLE]; 81 } 82 83 static size_t services_hash(const link_t *item) 84 { 85 service_t *dev = hash_table_get_instance(item, service_t, link); 86 unsigned long key[] = { 87 [SERVICES_KEY_HANDLE] = dev->service_id 88 }; 89 90 return services_key_hash(key); 91 } 92 93 static bool services_match(unsigned long key[], size_t keys, const link_t *item) 94 { 95 assert(keys == 1); 96 service_t *dev = hash_table_get_instance(item, service_t, link); 97 return (dev->service_id == (service_id_t) key[SERVICES_KEY_HANDLE]); 98 } 99 100 static void services_remove_callback(link_t *item) 101 { 102 free(hash_table_get_instance(item, service_t, link)); 75 static size_t services_key_hash(void *key) 76 { 77 return *(service_id_t*)key; 78 } 79 80 static 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 86 static 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 92 static void services_remove_callback(ht_link_t *item) 93 { 94 free(hash_table_get_inst(item, service_t, link)); 103 95 } 104 96 … … 106 98 .hash = services_hash, 107 99 .key_hash = services_key_hash, 108 . match = services_match,100 .key_equal = services_key_equal, 109 101 .equal = 0, 110 102 .remove_callback = services_remove_callback … … 242 234 /* Device node */ 243 235 244 unsigned long key[] = {245 [SERVICES_KEY_HANDLE] = (unsigned long) node->service_id246 };247 link_t *lnk;248 249 236 fibril_mutex_lock(&services_mutex); 237 ht_link_t *lnk; 250 238 restart: 251 lnk = hash_table_find(&services, key);239 lnk = hash_table_find(&services, &node->service_id); 252 240 if (lnk == NULL) { 253 241 service_t *dev = (service_t *) malloc(sizeof(service_t)); … … 292 280 * entry and free the device structure. 293 281 */ 294 hash_table_remove(&services, key, SERVICES_KEYS);282 hash_table_remove(&services, &node->service_id); 295 283 fibril_mutex_unlock(&services_mutex); 296 284 … … 301 289 dev->sess = sess; 302 290 } else { 303 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);291 service_t *dev = hash_table_get_inst(lnk, service_t, link); 304 292 305 293 if (!dev->sess) { … … 463 451 bool locfs_init(void) 464 452 { 465 if (!hash_table_create(&services, 0, SERVICES_KEYS, &services_ops))453 if (!hash_table_create(&services, 0, 0, &services_ops)) 466 454 return false; 467 455 … … 567 555 /* Device node */ 568 556 569 unsigned long key[] = {570 [SERVICES_KEY_HANDLE] = (unsigned long) index571 };572 573 557 fibril_mutex_lock(&services_mutex); 574 link_t *lnk = hash_table_find(&services, key);558 ht_link_t *lnk = hash_table_find(&services, &index); 575 559 if (lnk == NULL) { 576 560 fibril_mutex_unlock(&services_mutex); … … 578 562 } 579 563 580 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);564 service_t *dev = hash_table_get_inst(lnk, service_t, link); 581 565 assert(dev->sess); 582 566 … … 633 617 if (type == LOC_OBJECT_SERVICE) { 634 618 /* Device node */ 635 unsigned long key[] = {636 [SERVICES_KEY_HANDLE] = (unsigned long) index637 };638 619 639 620 fibril_mutex_lock(&services_mutex); 640 link_t *lnk = hash_table_find(&services, key);621 ht_link_t *lnk = hash_table_find(&services, &index); 641 622 if (lnk == NULL) { 642 623 fibril_mutex_unlock(&services_mutex); … … 644 625 } 645 626 646 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);627 service_t *dev = hash_table_get_inst(lnk, service_t, link); 647 628 assert(dev->sess); 648 629 … … 703 684 704 685 if (type == LOC_OBJECT_SERVICE) { 705 unsigned long key[] = {706 [SERVICES_KEY_HANDLE] = (unsigned long) index707 };708 686 709 687 fibril_mutex_lock(&services_mutex); 710 link_t *lnk = hash_table_find(&services, key);688 ht_link_t *lnk = hash_table_find(&services, &index); 711 689 if (lnk == NULL) { 712 690 fibril_mutex_unlock(&services_mutex); … … 714 692 } 715 693 716 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);694 service_t *dev = hash_table_get_inst(lnk, service_t, link); 717 695 assert(dev->sess); 718 696 dev->refcount--; … … 720 698 if (dev->refcount == 0) { 721 699 async_hangup(dev->sess); 722 hash_table_remove(&services, key, SERVICES_KEYS);700 hash_table_remove(&services, &index); 723 701 } 724 702 … … 744 722 745 723 if (type == LOC_OBJECT_SERVICE) { 746 unsigned long key[] = { 747 [SERVICES_KEY_HANDLE] = (unsigned long) index 748 }; 749 724 750 725 fibril_mutex_lock(&services_mutex); 751 link_t *lnk = hash_table_find(&services, key);726 ht_link_t *lnk = hash_table_find(&services, &index); 752 727 if (lnk == NULL) { 753 728 fibril_mutex_unlock(&services_mutex); … … 755 730 } 756 731 757 service_t *dev = hash_table_get_inst ance(lnk, service_t, link);732 service_t *dev = hash_table_get_inst(lnk, service_t, link); 758 733 assert(dev->sess); 759 734 -
uspace/srv/fs/mfs/mfs.h
rb17518e rbc216a0 142 142 unsigned refcnt; 143 143 fs_node_t *fsnode; 144 link_t link;144 ht_link_t link; 145 145 }; 146 146 -
uspace/srv/fs/mfs/mfs_ops.c
rb17518e rbc216a0 35 35 #include <align.h> 36 36 #include <adt/hash_table.h> 37 #include <adt/hash.h> 37 38 #include "mfs.h" 38 39 39 #define OPEN_NODES_KEYS 240 #define OPEN_NODES_SERVICE_KEY 041 #define OPEN_NODES_INODE_KEY 142 40 43 41 static bool check_magic_number(uint16_t magic, bool *native, … … 60 58 static int mfs_unlink(fs_node_t *, fs_node_t *, const char *name); 61 59 static int mfs_destroy_node(fs_node_t *fn); 62 static size_t open_nodes_hash(const link_t *item);63 static size_t open_nodes_key_hash(unsigned long key[]);64 static bool open_nodes_match(unsigned long key[], size_t keys,65 const link_t *item);66 60 static int mfs_node_get(fs_node_t **rfn, service_id_t service_id, 67 61 fs_index_t index); … … 95 89 /* Hash table interface for open nodes hash table */ 96 90 91 typedef struct { 92 service_id_t service_id; 93 fs_index_t index; 94 } node_key_t; 95 97 96 static size_t 98 open_nodes_key_hash(unsigned long key[]) 99 { 100 /* As recommended by Effective Java, 2nd Edition. */ 101 size_t hash = 17; 102 hash = 37 * hash + key[OPEN_NODES_SERVICE_KEY]; 103 hash = 37 * hash + key[OPEN_NODES_INODE_KEY]; 104 return hash; 97 open_nodes_key_hash(void *key) 98 { 99 node_key_t *node_key = (node_key_t*)key; 100 return hash_combine(node_key->service_id, node_key->index); 105 101 } 106 102 107 103 static size_t 108 open_nodes_hash(const link_t *item) 109 { 110 struct mfs_node *m = hash_table_get_instance(item, struct mfs_node, link); 111 112 unsigned long key[] = { 113 [OPEN_NODES_SERVICE_KEY] = m->instance->service_id, 114 [OPEN_NODES_INODE_KEY] = m->ino_i->index, 115 }; 116 117 return open_nodes_key_hash(key); 104 open_nodes_hash(const ht_link_t *item) 105 { 106 struct mfs_node *m = hash_table_get_inst(item, struct mfs_node, link); 107 return hash_combine(m->instance->service_id, m->ino_i->index); 118 108 } 119 109 120 110 static bool 121 open_nodes_match(unsigned long key[], size_t keys, const link_t *item) 122 { 123 assert(keys == 2); 124 struct mfs_node *mnode = hash_table_get_instance(item, struct mfs_node, link); 125 126 service_id_t service_id = ((service_id_t) key[OPEN_NODES_SERVICE_KEY]); 127 128 return mnode->instance->service_id == service_id 129 && mnode->ino_i->index == key[OPEN_NODES_INODE_KEY]; 130 } 131 111 open_nodes_key_equal(void *key, const ht_link_t *item) 112 { 113 node_key_t *node_key = (node_key_t*)key; 114 struct mfs_node *mnode = hash_table_get_inst(item, struct mfs_node, link); 115 116 return node_key->service_id == mnode->instance->service_id 117 && node_key->index == mnode->ino_i->index; 118 } 132 119 133 120 static hash_table_ops_t open_nodes_ops = { 134 121 .hash = open_nodes_hash, 135 122 .key_hash = open_nodes_key_hash, 136 . match = open_nodes_match,123 .key_equal = open_nodes_key_equal, 137 124 .equal = 0, 138 125 .remove_callback = 0, … … 142 129 mfs_global_init(void) 143 130 { 144 if (!hash_table_create(&open_nodes, 0, OPEN_NODES_KEYS, &open_nodes_ops)) {131 if (!hash_table_create(&open_nodes, 0, 0, &open_nodes_ops)) { 145 132 return ENOMEM; 146 133 } … … 413 400 mnode->refcnt = 1; 414 401 415 link_initialize(&mnode->link);416 417 402 fibril_mutex_lock(&open_nodes_lock); 418 403 hash_table_insert(&open_nodes, &mnode->link); … … 515 500 mnode->refcnt--; 516 501 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); 522 503 assert(mnode->instance->open_nodes_cnt > 0); 523 504 mnode->instance->open_nodes_cnt--; … … 578 559 579 560 /* 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 583 564 }; 584 link_t *already_open = hash_table_find(&open_nodes, key); 565 566 ht_link_t *already_open = hash_table_find(&open_nodes, &key); 585 567 586 568 if (already_open) { 587 mnode = hash_table_get_inst ance(already_open, struct mfs_node, link);569 mnode = hash_table_get_inst(already_open, struct mfs_node, link); 588 570 *rfn = mnode->fsnode; 589 571 mnode->refcnt++; … … 616 598 mnode->ino_i = ino_i; 617 599 mnode->refcnt = 1; 618 link_initialize(&mnode->link);619 600 620 601 mnode->instance = inst; -
uspace/srv/fs/tmpfs/tmpfs.h
rb17518e rbc216a0 62 62 fs_index_t index; /**< TMPFS node index. */ 63 63 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. */ 65 65 tmpfs_dentry_type_t type; 66 66 unsigned lnkcnt; /**< Link count. */ -
uspace/srv/fs/tmpfs/tmpfs_ops.c
rb17518e rbc216a0 50 50 #include <sys/types.h> 51 51 #include <adt/hash_table.h> 52 #include <adt/hash.h> 52 53 #include <as.h> 53 54 #include <libfs.h> … … 140 141 hash_table_t nodes; 141 142 142 #define NODES_KEY_DEV 0 143 #define NODES_KEY_INDEX 1 144 145 /* Implementation of hash table interface for the nodes hash table. */ 146 static size_t nodes_key_hash(unsigned long key[]) 147 { 148 /* Based on Effective Java, 2nd Edition. */ 149 size_t hash = 17; 150 hash = 37 * hash + key[NODES_KEY_DEV]; 151 hash = 37 * hash + key[NODES_KEY_INDEX]; 152 return hash; 153 } 154 155 static size_t nodes_hash(const link_t *item) 156 { 157 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, nh_link); 158 159 unsigned long key[] = { 160 [NODES_KEY_DEV] = nodep->service_id, 161 [NODES_KEY_INDEX] = nodep->index 162 }; 163 164 return nodes_key_hash(key); 165 } 166 167 static bool nodes_match(unsigned long key[], size_t keys, const link_t *item) 168 { 169 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 170 nh_link); 171 172 switch (keys) { 173 case 1: 174 return (nodep->service_id == key[NODES_KEY_DEV]); 175 case 2: 176 return ((nodep->service_id == key[NODES_KEY_DEV]) && 177 (nodep->index == key[NODES_KEY_INDEX])); 178 default: 179 assert((keys == 1) || (keys == 2)); 180 } 181 182 return 0; 183 } 184 185 static void nodes_remove_callback(link_t *item) 186 { 187 tmpfs_node_t *nodep = hash_table_get_instance(item, tmpfs_node_t, 188 nh_link); 143 /* 144 * Implementation of hash table interface for the nodes hash table. 145 */ 146 147 typedef struct { 148 service_id_t service_id; 149 fs_index_t index; 150 } node_key_t; 151 152 static 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 158 static 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 164 static 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 172 static void nodes_remove_callback(ht_link_t *item) 173 { 174 tmpfs_node_t *nodep = hash_table_get_inst(item, tmpfs_node_t, nh_link); 189 175 190 176 while (!list_empty(&nodep->cs_list)) { … … 209 195 .hash = nodes_hash, 210 196 .key_hash = nodes_key_hash, 211 . match = nodes_match,197 .key_equal = nodes_key_equal, 212 198 .equal = 0, 213 199 .remove_callback = nodes_remove_callback … … 223 209 nodep->size = 0; 224 210 nodep->data = NULL; 225 link_initialize(&nodep->nh_link);226 211 list_initialize(&nodep->cs_list); 227 212 } … … 236 221 bool tmpfs_init(void) 237 222 { 238 if (!hash_table_create(&nodes, 0, 2, &nodes_ops))223 if (!hash_table_create(&nodes, 0, 0, &nodes_ops)) 239 224 return false; 240 225 … … 254 239 } 255 240 241 static 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 256 252 static void tmpfs_instance_done(service_id_t service_id) 257 { 258 unsigned long key[] = { 259 [NODES_KEY_DEV] = service_id 260 }; 261 /* 262 * Here we are making use of one special feature of our hash table 263 * implementation, which allows to remove more items based on a partial 264 * key match. In the following, we are going to remove all nodes 265 * matching our device handle. The nodes_remove_callback() function will 266 * take care of resource deallocation. 267 */ 268 hash_table_remove(&nodes, key, 1); 253 { 254 hash_table_apply(&nodes, rm_service_id_nodes, &service_id); 269 255 } 270 256 … … 288 274 int tmpfs_node_get(fs_node_t **rfn, service_id_t service_id, fs_index_t index) 289 275 { 290 unsigned long key[]= {291 [NODES_KEY_DEV]= service_id,292 [NODES_KEY_INDEX]= index276 node_key_t key = { 277 .service_id = service_id, 278 .index = index 293 279 }; 294 link_t *lnk = hash_table_find(&nodes, key); 280 281 ht_link_t *lnk = hash_table_find(&nodes, &key); 282 295 283 if (lnk) { 296 284 tmpfs_node_t *nodep; 297 nodep = hash_table_get_inst ance(lnk, tmpfs_node_t, nh_link);285 nodep = hash_table_get_inst(lnk, tmpfs_node_t, nh_link); 298 286 *rfn = FS_NODE(nodep); 299 287 } else { … … 358 346 assert(!nodep->lnkcnt); 359 347 assert(list_empty(&nodep->cs_list)); 360 361 unsigned long key[] = { 362 [NODES_KEY_DEV] = nodep->service_id, 363 [NODES_KEY_INDEX] = nodep->index 364 }; 365 hash_table_remove(&nodes, key, 2); 348 349 hash_table_remove_item(&nodes, &nodep->nh_link); 366 350 367 351 /* … … 488 472 * Lookup the respective TMPFS node. 489 473 */ 490 link_t *hlp; 491 unsigned long key[] = { 492 [NODES_KEY_DEV] = service_id, 493 [NODES_KEY_INDEX] = index 474 node_key_t key = { 475 .service_id = service_id, 476 .index = index 494 477 }; 495 hlp = hash_table_find(&nodes, key); 478 479 ht_link_t *hlp = hash_table_find(&nodes, &key); 496 480 if (!hlp) 497 481 return ENOENT; 498 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,499 nh_link);482 483 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link); 500 484 501 485 /* … … 550 534 * Lookup the respective TMPFS node. 551 535 */ 552 link_t *hlp; 553 unsigned long key[] = { 554 [NODES_KEY_DEV] = service_id, 555 [NODES_KEY_INDEX] = index 536 node_key_t key = { 537 .service_id = service_id, 538 .index = index 556 539 }; 557 hlp = hash_table_find(&nodes, key); 540 541 ht_link_t *hlp = hash_table_find(&nodes, &key); 542 558 543 if (!hlp) 559 544 return ENOENT; 560 tmpfs_node_t *nodep = hash_table_get_instance(hlp, tmpfs_node_t,561 nh_link);545 546 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link); 562 547 563 548 /* … … 612 597 * Lookup the respective TMPFS node. 613 598 */ 614 unsigned long key[]= {615 [NODES_KEY_DEV]= service_id,616 [NODES_KEY_INDEX]= index599 node_key_t key = { 600 .service_id = service_id, 601 .index = index 617 602 }; 618 link_t *hlp = hash_table_find(&nodes, key); 603 604 ht_link_t *hlp = hash_table_find(&nodes, &key); 605 619 606 if (!hlp) 620 607 return ENOENT; 621 tmpfs_node_t *nodep = hash_table_get_inst ance(hlp, tmpfs_node_t, nh_link);608 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, nh_link); 622 609 623 610 if (size == nodep->size) … … 648 635 static int tmpfs_destroy(service_id_t service_id, fs_index_t index) 649 636 { 650 link_t *hlp; 651 unsigned long key[] = { 652 [NODES_KEY_DEV] = service_id, 653 [NODES_KEY_INDEX] = index 637 node_key_t key = { 638 .service_id = service_id, 639 .index = index 654 640 }; 655 hlp = hash_table_find(&nodes, key); 641 642 ht_link_t *hlp = hash_table_find(&nodes, &key); 656 643 if (!hlp) 657 644 return ENOENT; 658 tmpfs_node_t *nodep = hash_table_get_inst ance(hlp, tmpfs_node_t,645 tmpfs_node_t *nodep = hash_table_get_inst(hlp, tmpfs_node_t, 659 646 nh_link); 660 647 return tmpfs_destroy_node(FS_NODE(nodep)); -
uspace/srv/hid/input/generic/gsp.c
rb17518e rbc216a0 51 51 #include <gsp.h> 52 52 #include <adt/hash_table.h> 53 #include <adt/hash.h> 53 54 #include <stdlib.h> 54 55 #include <stdio.h> 55 56 56 57 /* 57 * Hash table operations for the transition function. 58 */ 59 60 static size_t trans_op_hash(const link_t *item); 61 static size_t trans_op_key_hash(unsigned long key[]); 62 static bool trans_op_match(unsigned long key[], size_t keys, const link_t *item); 58 * Transition function hash table operations. 59 */ 60 typedef struct { 61 int old_state; 62 int input; 63 } trans_key_t; 64 65 static size_t trans_key_hash(void *key) 66 { 67 trans_key_t *trans_key = (trans_key_t *)key; 68 return hash_combine(trans_key->input, trans_key->old_state); 69 } 70 71 static size_t trans_hash(const ht_link_t *item) 72 { 73 gsp_trans_t *t = hash_table_get_inst(item, gsp_trans_t, link); 74 return hash_combine(t->input, t->old_state); 75 } 76 77 static bool trans_key_equal(void *key, const ht_link_t *item) 78 { 79 trans_key_t *trans_key = (trans_key_t *)key; 80 gsp_trans_t *t = hash_table_get_inst(item, gsp_trans_t, link); 81 82 return trans_key->input == t->input && trans_key->old_state == t->old_state; 83 } 63 84 64 85 static hash_table_ops_t trans_ops = { 65 .hash = trans_ op_hash,66 .key_hash = trans_ op_key_hash,67 . match = trans_op_match,86 .hash = trans_hash, 87 .key_hash = trans_key_hash, 88 .key_equal = trans_key_equal, 68 89 .equal = 0, 69 90 .remove_callback = 0 70 91 }; 71 92 93 72 94 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input); 73 95 static void trans_insert(gsp_t *p, gsp_trans_t *t); … … 78 100 { 79 101 p->states = 1; 80 hash_table_create(&p->trans, 0, 2, &trans_ops);102 hash_table_create(&p->trans, 0, 0, &trans_ops); 81 103 } 82 104 … … 222 244 static gsp_trans_t *trans_lookup(gsp_t *p, int state, int input) 223 245 { 224 link_t *item; 225 unsigned long key[2]; 226 227 key[0] = state; 228 key[1] = input; 229 230 item = hash_table_find(&p->trans, key); 246 ht_link_t *item; 247 248 trans_key_t key = { 249 .input = input, 250 .old_state = state 251 }; 252 253 item = hash_table_find(&p->trans, &key); 231 254 if (item == NULL) return NULL; 232 255 233 return hash_table_get_inst ance(item, gsp_trans_t, link);256 return hash_table_get_inst(item, gsp_trans_t, link); 234 257 } 235 258 … … 258 281 } 259 282 260 /*261 * Transition function hash table operations.262 */263 264 static size_t trans_op_key_hash(unsigned long key[])265 {266 return (key[0] * 17 + key[1]);267 }268 269 static size_t trans_op_hash(const link_t *item)270 {271 gsp_trans_t *t = hash_table_get_instance(item, gsp_trans_t, link);272 unsigned long key[] = {273 t->old_state,274 t->input275 };276 277 return trans_op_key_hash(key);278 }279 280 static bool trans_op_match(unsigned long key[], size_t keys, const link_t *item)281 {282 gsp_trans_t *t = hash_table_get_instance(item, gsp_trans_t, link);283 return ((key[0] == (unsigned long) t->old_state)284 && (key[1] == (unsigned long) t->input));285 }286 283 287 284 /** -
uspace/srv/hid/input/include/gsp.h
rb17518e rbc216a0 56 56 /** Scancode parser transition. */ 57 57 typedef struct { 58 link_t link; /**< Link to hash table in @c gsp_t */58 ht_link_t link; /**< Link to hash table in @c gsp_t */ 59 59 60 60 /* Preconditions */ -
uspace/srv/ns/service.c
rb17518e rbc216a0 43 43 /** Service hash table item. */ 44 44 typedef struct { 45 link_t link;45 ht_link_t link; 46 46 sysarg_t service; /**< Service ID. */ 47 47 sysarg_t phone; /**< Phone registered with the service. */ … … 49 49 } hashed_service_t; 50 50 51 /** Compute hash index into service hash table. 52 * 53 * @param key Pointer keys. However, only the first key (i.e. service number) 54 * is used to compute the hash index. 55 * 56 * @return Hash index corresponding to key[0]. 57 * 58 */ 59 static size_t service_key_hash(unsigned long key[]) 51 52 static size_t service_key_hash(void *key) 60 53 { 61 assert(key); 62 return key[0]; 54 return *(sysarg_t*)key; 63 55 } 64 56 65 static size_t service_hash(const link_t *item)57 static size_t service_hash(const ht_link_t *item) 66 58 { 67 hashed_service_t *hs = hash_table_get_instance(item, hashed_service_t, link); 68 unsigned long key = hs->service; 69 return service_key_hash(&key); 59 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 60 return hs->service; 70 61 } 71 62 72 /** Compare a key with hashed item. 73 * 74 * This compare function always ignores the third key. 75 * It exists only to make it possible to remove records 76 * originating from connection with key[1] in_phone_hash 77 * value. Note that this is close to being classified 78 * as a nasty hack. 79 * 80 * @param key Array of keys. 81 * @param keys Must be lesser or equal to 3. 82 * @param item Pointer to a hash table item. 83 * 84 * @return Non-zero if the key matches the item, zero otherwise. 85 * 86 */ 87 static bool service_match(unsigned long key[], size_t keys, const link_t *item) 63 static bool service_key_equal(void *key, const ht_link_t *item) 88 64 { 89 assert(key); 90 assert(keys <= 3); 91 assert(item); 92 93 hashed_service_t *hs = hash_table_get_instance(item, hashed_service_t, link); 94 95 if (keys == 2) 96 return ((key[0] == hs->service) && (key[1] == hs->in_phone_hash)); 97 else 98 return (key[0] == hs->service); 99 } 100 101 /** Perform actions after removal of item from the hash table. 102 * 103 * @param item Item that was removed from the hash table. 104 * 105 */ 106 static void service_remove(link_t *item) 107 { 108 assert(item); 109 free(hash_table_get_instance(item, hashed_service_t, link)); 65 hashed_service_t *hs = hash_table_get_inst(item, hashed_service_t, link); 66 return hs->service == *(sysarg_t*)key; 110 67 } 111 68 … … 114 71 .hash = service_hash, 115 72 .key_hash = service_key_hash, 116 . match = service_match,73 .key_equal = service_key_equal, 117 74 .equal = 0, 118 .remove_callback = service_remove75 .remove_callback = 0 119 76 }; 120 77 … … 135 92 int service_init(void) 136 93 { 137 if (!hash_table_create(&service_hash_table, 0, 3, &service_hash_table_ops)) {94 if (!hash_table_create(&service_hash_table, 0, 0, &service_hash_table_ops)) { 138 95 printf(NAME ": No memory available for services\n"); 139 96 return ENOMEM; … … 152 109 pending_conn_t *pr = list_get_instance(cur, pending_conn_t, link); 153 110 154 unsigned long keys[3] = { 155 pr->service, 156 0, 157 0 158 }; 159 160 link_t *link = hash_table_find(&service_hash_table, keys); 111 ht_link_t *link = hash_table_find(&service_hash_table, &pr->service); 161 112 if (!link) 162 113 continue; 163 114 164 hashed_service_t *hs = hash_table_get_inst ance(link, hashed_service_t, link);115 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link); 165 116 (void) ipc_forward_fast(pr->callid, hs->phone, pr->arg2, 166 117 pr->arg3, 0, IPC_FF_NONE); … … 183 134 int register_service(sysarg_t service, sysarg_t phone, ipc_call_t *call) 184 135 { 185 unsigned long keys[3] = { 186 service, 187 call->in_phone_hash, 188 0 189 }; 190 191 if (hash_table_find(&service_hash_table, keys)) 136 if (hash_table_find(&service_hash_table, &service)) 192 137 return EEXISTS; 193 138 … … 196 141 return ENOMEM; 197 142 198 link_initialize(&hs->link);199 143 hs->service = service; 200 144 hs->phone = phone; … … 217 161 { 218 162 sysarg_t retval; 219 unsigned long keys[3] = {220 service,221 0,222 0223 };224 163 225 link_t *link = hash_table_find(&service_hash_table, keys);164 ht_link_t *link = hash_table_find(&service_hash_table, &service); 226 165 if (!link) { 227 166 if (IPC_GET_ARG4(*call) & IPC_FLAG_BLOCKING) { … … 246 185 } 247 186 248 hashed_service_t *hs = hash_table_get_inst ance(link, hashed_service_t, link);187 hashed_service_t *hs = hash_table_get_inst(link, hashed_service_t, link); 249 188 (void) ipc_forward_fast(callid, hs->phone, IPC_GET_ARG2(*call), 250 189 IPC_GET_ARG3(*call), 0, IPC_FF_NONE); -
uspace/srv/ns/task.c
rb17518e rbc216a0 53 53 /** Task hash table item. */ 54 54 typedef struct { 55 link_t link;55 ht_link_t link; 56 56 57 57 task_id_t id; /**< Task ID. */ … … 61 61 } hashed_task_t; 62 62 63 /** Compute hash index into task hash table. 64 * 65 * @param key Pointer keys. However, only the first key (i.e. truncated task 66 * number) is used to compute the hash index. 67 * 68 * @return Hash index corresponding to key[0]. 69 * 70 */ 71 static size_t task_key_hash(unsigned long key[]) 72 { 73 size_t hash = 17; 74 hash = 37 * hash + key[1]; 75 hash = 37 * hash + key[0]; 76 return hash; 77 } 78 79 static size_t task_hash(const link_t *item) 80 { 81 hashed_task_t *ht = hash_table_get_instance(item, hashed_task_t, link); 82 83 unsigned long key[] = { 84 LOWER32(ht->id), 85 UPPER32(ht->id) 86 }; 87 88 return task_key_hash(key); 89 } 90 91 /** Compare a key with hashed item. 92 * 93 * @param key Array of keys. 94 * @param keys Must be less than or equal to 2. 95 * @param item Pointer to a hash table item. 96 * 97 * @return Non-zero if the key matches the item, zero otherwise. 98 * 99 */ 100 static bool task_match(unsigned long key[], size_t keys, const link_t *item) 101 { 102 assert(key); 103 assert(keys == 2); 104 assert(item); 105 106 hashed_task_t *ht = hash_table_get_instance(item, hashed_task_t, link); 107 108 return (key[0] == LOWER32(ht->id)) 109 && (key[1] == UPPER32(ht->id)); 110 } 111 112 /** Perform actions after removal of item from the hash table. 113 * 114 * @param item Item that was removed from the hash table. 115 * 116 */ 117 static void task_remove(link_t *item) 118 { 119 assert(item); 120 free(hash_table_get_instance(item, hashed_task_t, link)); 63 64 static size_t task_key_hash(void *key) 65 { 66 return *(task_id_t*)key; 67 } 68 69 static size_t task_hash(const ht_link_t *item) 70 { 71 hashed_task_t *ht = hash_table_get_inst(item, hashed_task_t, link); 72 return ht->id; 73 } 74 75 static bool task_key_equal(void *key, const ht_link_t *item) 76 { 77 hashed_task_t *ht = hash_table_get_inst(item, hashed_task_t, link); 78 return ht->id == *(task_id_t*)key; 79 } 80 81 /** Perform actions after removal of item from the hash table. */ 82 static void task_remove(ht_link_t *item) 83 { 84 free(hash_table_get_inst(item, hashed_task_t, link)); 121 85 } 122 86 … … 125 89 .hash = task_hash, 126 90 .key_hash = task_key_hash, 127 . match = task_match,91 .key_equal = task_key_equal, 128 92 .equal = 0, 129 93 .remove_callback = task_remove … … 134 98 135 99 typedef struct { 136 link_t link;100 ht_link_t link; 137 101 sysarg_t in_phone_hash; /**< Incoming phone hash. */ 138 102 task_id_t id; /**< Task ID. */ 139 103 } p2i_entry_t; 140 104 141 /** Compute hash index into task hash table. 142 * 143 * @param key Array of keys. 144 * 145 * @return Hash index corresponding to key[0]. 146 * 147 */ 148 static size_t p2i_key_hash(unsigned long key[]) 149 { 150 assert(key); 151 return key[0]; 152 } 153 154 static size_t p2i_hash(const link_t *item) 155 { 156 p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link); 157 unsigned long key = entry->in_phone_hash; 158 return p2i_key_hash(&key); 159 } 160 161 /** Compare a key with hashed item. 162 * 163 * @param key Array of keys. 164 * @param keys Must be less than or equal to 1. 165 * @param item Pointer to a hash table item. 166 * 167 * @return Non-zero if the key matches the item, zero otherwise. 168 * 169 */ 170 static bool p2i_match(unsigned long key[], size_t keys, const link_t *item) 171 { 172 assert(key); 173 assert(keys == 1); 105 /* phone-to-id hash table operations */ 106 107 static size_t p2i_key_hash(void *key) 108 { 109 sysarg_t in_phone_hash = *(sysarg_t*)key; 110 return in_phone_hash; 111 } 112 113 static size_t p2i_hash(const ht_link_t *item) 114 { 115 p2i_entry_t *entry = hash_table_get_inst(item, p2i_entry_t, link); 116 return entry->in_phone_hash; 117 } 118 119 static bool p2i_key_equal(void *key, const ht_link_t *item) 120 { 121 sysarg_t in_phone_hash = *(sysarg_t*)key; 122 p2i_entry_t *entry = hash_table_get_inst(item, p2i_entry_t, link); 123 124 return (in_phone_hash == entry->in_phone_hash); 125 } 126 127 /** Perform actions after removal of item from the hash table. 128 * 129 * @param item Item that was removed from the hash table. 130 * 131 */ 132 static void p2i_remove(ht_link_t *item) 133 { 174 134 assert(item); 175 176 p2i_entry_t *entry = hash_table_get_instance(item, p2i_entry_t, link); 177 178 return (key[0] == entry->in_phone_hash); 179 } 180 181 /** Perform actions after removal of item from the hash table. 182 * 183 * @param item Item that was removed from the hash table. 184 * 185 */ 186 static void p2i_remove(link_t *item) 187 { 188 assert(item); 189 free(hash_table_get_instance(item, p2i_entry_t, link)); 135 free(hash_table_get_inst(item, p2i_entry_t, link)); 190 136 } 191 137 … … 194 140 .hash = p2i_hash, 195 141 .key_hash = p2i_key_hash, 196 . match = p2i_match,142 .key_equal = p2i_key_equal, 197 143 .equal = 0, 198 144 .remove_callback = p2i_remove … … 213 159 int task_init(void) 214 160 { 215 if (!hash_table_create(&task_hash_table, 0, 2, &task_hash_table_ops)) {161 if (!hash_table_create(&task_hash_table, 0, 0, &task_hash_table_ops)) { 216 162 printf(NAME ": No memory available for tasks\n"); 217 163 return ENOMEM; 218 164 } 219 165 220 if (!hash_table_create(&phone_to_id, 0, 1, &p2i_ops)) {166 if (!hash_table_create(&phone_to_id, 0, 0, &p2i_ops)) { 221 167 printf(NAME ": No memory available for tasks\n"); 222 168 return ENOMEM; … … 236 182 pending_wait_t *pr = list_get_instance(cur, pending_wait_t, link); 237 183 238 unsigned long keys[2] = { 239 LOWER32(pr->id), 240 UPPER32(pr->id) 241 }; 242 243 link_t *link = hash_table_find(&task_hash_table, keys); 184 ht_link_t *link = hash_table_find(&task_hash_table, &pr->id); 244 185 if (!link) 245 186 continue; 246 187 247 hashed_task_t *ht = hash_table_get_inst ance(link, hashed_task_t, link);188 hashed_task_t *ht = hash_table_get_inst(link, hashed_task_t, link); 248 189 if (!ht->finished) 249 190 continue; … … 256 197 } 257 198 258 hash_table_remove(&task_hash_table, keys, 2);199 hash_table_remove(&task_hash_table, &pr->id); 259 200 list_remove(cur); 260 201 free(pr); … … 268 209 task_exit_t texit; 269 210 270 unsigned long keys[2] = { 271 LOWER32(id), 272 UPPER32(id) 273 }; 274 275 link_t *link = hash_table_find(&task_hash_table, keys); 211 ht_link_t *link = hash_table_find(&task_hash_table, &id); 276 212 hashed_task_t *ht = (link != NULL) ? 277 hash_table_get_inst ance(link, hashed_task_t, link) : NULL;213 hash_table_get_inst(link, hashed_task_t, link) : NULL; 278 214 279 215 if (ht == NULL) { … … 299 235 } 300 236 301 hash_table_remove (&task_hash_table, keys, 2);237 hash_table_remove_item(&task_hash_table, link); 302 238 retval = EOK; 303 239 … … 314 250 task_id_t id = MERGE_LOUP32(IPC_GET_ARG1(*call), IPC_GET_ARG2(*call)); 315 251 316 unsigned long keys[] = { call->in_phone_hash }; 317 318 link_t *link = hash_table_find(&phone_to_id, keys); 252 ht_link_t *link = hash_table_find(&phone_to_id, &call->in_phone_hash); 319 253 if (link != NULL) 320 254 return EEXISTS; … … 332 266 */ 333 267 334 link_initialize(&entry->link);335 268 entry->in_phone_hash = call->in_phone_hash; 336 269 entry->id = id; … … 341 274 */ 342 275 343 link_initialize(&ht->link);344 276 ht->id = id; 345 277 ht->finished = false; … … 353 285 static int get_id_by_phone(sysarg_t phone_hash, task_id_t *id) 354 286 { 355 unsigned long keys[1] = {phone_hash}; 356 357 link_t *link = hash_table_find(&phone_to_id, keys); 287 ht_link_t *link = hash_table_find(&phone_to_id, &phone_hash); 358 288 if (link == NULL) 359 289 return ENOENT; 360 290 361 p2i_entry_t *entry = hash_table_get_inst ance(link, p2i_entry_t, link);291 p2i_entry_t *entry = hash_table_get_inst(link, p2i_entry_t, link); 362 292 *id = entry->id; 363 293 … … 372 302 return rc; 373 303 374 unsigned long keys[2] = { 375 LOWER32(id), 376 UPPER32(id) 377 }; 378 379 link_t *link = hash_table_find(&task_hash_table, keys); 304 ht_link_t *link = hash_table_find(&task_hash_table, &id); 380 305 hashed_task_t *ht = (link != NULL) ? 381 hash_table_get_inst ance(link, hashed_task_t, link) : NULL;306 hash_table_get_inst(link, hashed_task_t, link) : NULL; 382 307 383 308 if ((ht == NULL) || (ht->finished)) … … 393 318 int ns_task_disconnect(ipc_call_t *call) 394 319 { 395 unsigned long keys[2];396 397 320 task_id_t id; 398 321 int rc = get_id_by_phone(call->in_phone_hash, &id); … … 401 324 402 325 /* Delete from phone-to-id map. */ 403 keys[0] = call->in_phone_hash; 404 hash_table_remove(&phone_to_id, keys, 1); 326 hash_table_remove(&phone_to_id, &call->in_phone_hash); 405 327 406 328 /* Mark task as finished. */ 407 keys[0] = LOWER32(id); 408 keys[1] = UPPER32(id); 409 410 link_t *link = hash_table_find(&task_hash_table, keys); 329 ht_link_t *link = hash_table_find(&task_hash_table, &id); 411 330 if (link == NULL) 412 331 return EOK; 413 332 414 hashed_task_t *ht = 415 hash_table_get_instance(link, hashed_task_t, link); 333 hashed_task_t *ht = hash_table_get_inst(link, hashed_task_t, link); 416 334 417 335 ht->finished = true; -
uspace/srv/vfs/vfs.h
rb17518e rbc216a0 36 36 #include <async.h> 37 37 #include <adt/list.h> 38 #include <adt/hash_table.h> 38 39 #include <fibril_synch.h> 39 40 #include <sys/types.h> … … 112 113 unsigned lnkcnt; 113 114 114 link_t nh_link; /**< Node hash-table link. */115 ht_link_t nh_link; /**< Node hash-table link. */ 115 116 116 117 vfs_node_type_t type; /**< Partial info about the node type. */ -
uspace/srv/vfs/vfs_node.c
rb17518e rbc216a0 41 41 #include <fibril_synch.h> 42 42 #include <adt/hash_table.h> 43 #include <adt/hash.h> 43 44 #include <assert.h> 44 45 #include <async.h> … … 58 59 #define KEY_INDEX 2 59 60 60 static size_t nodes_key_hash(unsigned long []); 61 static size_t nodes_hash(const link_t *); 62 static bool nodes_match(unsigned long [], size_t, const link_t *); 61 static size_t nodes_key_hash(void *); 62 static size_t nodes_hash(const ht_link_t *); 63 static bool nodes_key_equal(void *, const ht_link_t *); 64 static vfs_triplet_t node_triplet(vfs_node_t *node); 63 65 64 66 /** VFS node hash table operations. */ … … 66 68 .hash = nodes_hash, 67 69 .key_hash = nodes_key_hash, 68 . match = nodes_match,70 .key_equal = nodes_key_equal, 69 71 .equal = 0, 70 72 .remove_callback = 0, … … 77 79 bool vfs_nodes_init(void) 78 80 { 79 return hash_table_create(&nodes, 0, 3, &nodes_ops);81 return hash_table_create(&nodes, 0, 0, &nodes_ops); 80 82 } 81 83 … … 116 118 */ 117 119 118 unsigned long key[] = { 119 [KEY_FS_HANDLE] = node->fs_handle, 120 [KEY_DEV_HANDLE] = node->service_id, 121 [KEY_INDEX] = node->index 122 }; 123 124 hash_table_remove(&nodes, key, 3); 120 hash_table_remove_item(&nodes, &node->nh_link); 125 121 free_vfs_node = true; 126 122 … … 160 156 { 161 157 fibril_mutex_lock(&nodes_mutex); 162 unsigned long key[] = { 163 [KEY_FS_HANDLE] = node->fs_handle, 164 [KEY_DEV_HANDLE] = node->service_id, 165 [KEY_INDEX] = node->index 166 }; 167 hash_table_remove(&nodes, key, 3); 158 hash_table_remove_item(&nodes, &node->nh_link); 168 159 fibril_mutex_unlock(&nodes_mutex); 169 160 free(node); … … 184 175 vfs_node_t *vfs_node_get(vfs_lookup_res_t *result) 185 176 { 186 unsigned long key[] = {187 [KEY_FS_HANDLE] = result->triplet.fs_handle,188 [KEY_DEV_HANDLE] = result->triplet.service_id,189 [KEY_INDEX] = result->triplet.index190 };191 link_t *tmp;192 177 vfs_node_t *node; 193 178 194 179 fibril_mutex_lock(&nodes_mutex); 195 tmp = hash_table_find(&nodes, key);180 ht_link_t *tmp = hash_table_find(&nodes, &result->triplet); 196 181 if (!tmp) { 197 182 node = (vfs_node_t *) malloc(sizeof(vfs_node_t)); … … 207 192 node->lnkcnt = result->lnkcnt; 208 193 node->type = result->type; 209 link_initialize(&node->nh_link);210 194 fibril_rwlock_initialize(&node->contents_rwlock); 211 195 hash_table_insert(&nodes, &node->nh_link); 212 196 } else { 213 node = hash_table_get_inst ance(tmp, vfs_node_t, nh_link);197 node = hash_table_get_inst(tmp, vfs_node_t, nh_link); 214 198 if (node->type == VFS_NODE_UNKNOWN && 215 199 result->type != VFS_NODE_UNKNOWN) { … … 242 226 } 243 227 244 size_t nodes_key_hash(unsigned long key[])245 {246 /* Combine into a hash like they do in Effective Java, 2nd edition. */247 size_t hash = 17;248 hash = 37 * hash + key[KEY_FS_HANDLE];249 hash = 37 * hash + key[KEY_DEV_HANDLE];250 hash = 37 * hash + key[KEY_INDEX];251 return hash;252 }253 254 size_t nodes_hash(const link_t *item)255 {256 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);257 258 unsigned long key[] = {259 [KEY_FS_HANDLE] = node->fs_handle,260 [KEY_DEV_HANDLE] = node->service_id,261 [KEY_INDEX] = node->index262 };263 264 return nodes_key_hash(key);265 }266 267 268 bool nodes_match(unsigned long key[], size_t keys, const link_t *item)269 {270 vfs_node_t *node = hash_table_get_instance(item, vfs_node_t, nh_link);271 return (node->fs_handle == (fs_handle_t) key[KEY_FS_HANDLE]) &&272 (node->service_id == key[KEY_DEV_HANDLE]) &&273 (node->index == key[KEY_INDEX]);274 }275 276 277 228 struct refcnt_data { 278 229 /** Sum of all reference counts for this file system instance. */ … … 282 233 }; 283 234 284 static bool refcnt_visitor( link_t *item, void *arg)285 { 286 vfs_node_t *node = hash_table_get_inst ance(item, vfs_node_t, nh_link);235 static bool refcnt_visitor(ht_link_t *item, void *arg) 236 { 237 vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link); 287 238 struct refcnt_data *rd = (void *) arg; 288 239 … … 332 283 } 333 284 285 286 static size_t nodes_key_hash(void *key) 287 { 288 vfs_triplet_t *tri = key; 289 size_t hash = hash_combine(tri->fs_handle, tri->index); 290 return hash_combine(hash, tri->service_id); 291 } 292 293 static size_t nodes_hash(const ht_link_t *item) 294 { 295 vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link); 296 vfs_triplet_t tri = node_triplet(node); 297 return nodes_key_hash(&tri); 298 } 299 300 static bool nodes_key_equal(void *key, const ht_link_t *item) 301 { 302 vfs_triplet_t *tri = key; 303 vfs_node_t *node = hash_table_get_inst(item, vfs_node_t, nh_link); 304 return node->fs_handle == tri->fs_handle 305 && node->service_id == tri->service_id 306 && node->index == tri->index; 307 } 308 309 static inline vfs_triplet_t node_triplet(vfs_node_t *node) 310 { 311 vfs_triplet_t tri = { 312 .fs_handle = node->fs_handle, 313 .service_id = node->service_id, 314 .index = node->index 315 }; 316 317 return tri; 318 } 319 334 320 /** 335 321 * @}
Note:
See TracChangeset
for help on using the changeset viewer.
