Changeset 0ca7286 in mainline for uspace/srv/fs/ext2fs/ext2fs_ops.c
- Timestamp:
- 2012-07-21T11:19:27Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 2732c94
- Parents:
- 1c1da4b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/srv/fs/ext2fs/ext2fs_ops.c
r1c1da4b r0ca7286 65 65 #define OPEN_NODES_DEV_HANDLE_KEY 0 66 66 #define OPEN_NODES_INODE_KEY 1 67 #define OPEN_NODES_BUCKETS 25668 67 69 68 typedef struct ext2fs_instance { … … 123 122 124 123 /* Hash table interface for open nodes hash table */ 125 static hash_index_t open_nodes_hash(unsigned long key[]) 126 { 127 /* TODO: This is very simple and probably can be improved */ 128 return key[OPEN_NODES_INODE_KEY] % OPEN_NODES_BUCKETS; 129 } 130 131 static int open_nodes_compare(unsigned long key[], hash_count_t keys, 132 link_t *item) 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); 136 137 assert(enode->instance); 138 assert(enode->inode_ref); 139 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) 133 150 { 134 151 ext2fs_node_t *enode = hash_table_get_instance(item, ext2fs_node_t, link); … … 145 162 } 146 163 147 static void open_nodes_remove_cb(link_t *link) 148 { 149 /* We don't use remove callback for this hash table */ 150 } 151 152 static hash_table_operations_t open_nodes_ops = { 164 static hash_table_ops_t open_nodes_ops = { 153 165 .hash = open_nodes_hash, 154 .compare = open_nodes_compare, 155 .remove_callback = open_nodes_remove_cb, 166 .key_hash = open_nodes_key_hash, 167 .match = open_nodes_match, 168 .equal = 0, 169 .remove_callback = 0, 156 170 }; 157 171 … … 161 175 int ext2fs_global_init(void) 162 176 { 163 if (!hash_table_create(&open_nodes, OPEN_NODES_BUCKETS, 164 OPEN_NODES_KEYS, &open_nodes_ops)) { 177 if (!hash_table_create(&open_nodes, 0, OPEN_NODES_KEYS, &open_nodes_ops)) { 165 178 return ENOMEM; 166 179 } … … 362 375 *rfn = node; 363 376 364 hash_table_insert(&open_nodes, key,&enode->link);377 hash_table_insert(&open_nodes, &enode->link); 365 378 inst->open_nodes_count++; 366 379
Note:
See TracChangeset
for help on using the changeset viewer.