Changeset f1ba5d6 in mainline
- Timestamp:
- 2008-11-02T13:38:56Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e1c88d5
- Parents:
- 0c243b4
- Location:
- uspace
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r0c243b4 rf1ba5d6 49 49 #include <futex.h> 50 50 #include <libadt/list.h> 51 #include <libadt/hash_table.h> 51 52 52 53 /** Lock protecting the device connection list */ … … 54 55 /** Device connection list head. */ 55 56 static LIST_INITIALIZE(dcl_head); 57 58 #define CACHE_BUCKETS_LOG2 10 59 #define CACHE_BUCKETS (1 << CACHE_BUCKETS_LOG2) 60 61 typedef struct { 62 futex_t lock; 63 size_t block_size; /**< Block size. */ 64 unsigned block_count; /**< Total number of blocks. */ 65 hash_table_t block_hash; 66 link_t free_head; 67 } cache_t; 56 68 57 69 typedef struct { … … 64 76 off_t bb_off; 65 77 size_t bb_size; 78 cache_t *cache; 66 79 } devcon_t; 67 80 … … 100 113 devcon->bb_off = 0; 101 114 devcon->bb_size = 0; 115 devcon->cache = NULL; 102 116 103 117 futex_down(&dcl_lock); … … 168 182 if (devcon->bb_buf) 169 183 free(devcon->bb_buf); 184 185 if (devcon->cache) { 186 hash_table_destroy(&devcon->cache->block_hash); 187 free(devcon->cache); 188 } 189 170 190 munmap(devcon->com_area, devcon->com_size); 171 191 ipc_hangup(devcon->dev_phone); … … 208 228 assert(devcon); 209 229 return devcon->bb_buf; 230 } 231 232 static hash_index_t cache_hash(unsigned long *key) 233 { 234 return *key & (CACHE_BUCKETS - 1); 235 } 236 237 static int cache_compare(unsigned long *key, hash_count_t keys, link_t *item) 238 { 239 block_t *b = hash_table_get_instance(item, block_t, hash_link); 240 return b->boff == *key; 241 } 242 243 static void cache_remove_callback(link_t *item) 244 { 245 } 246 247 static hash_table_operations_t cache_ops = { 248 .hash = cache_hash, 249 .compare = cache_compare, 250 .remove_callback = cache_remove_callback 251 }; 252 253 int block_cache_init(dev_handle_t dev_handle, size_t size, unsigned blocks) 254 { 255 devcon_t *devcon = devcon_search(dev_handle); 256 cache_t *cache; 257 if (!devcon) 258 return ENOENT; 259 if (devcon->cache) 260 return EEXIST; 261 cache = malloc(sizeof(cache_t)); 262 if (!cache) 263 return ENOMEM; 264 265 futex_initialize(&cache->lock, 0); 266 list_initialize(&cache->free_head); 267 cache->block_size = size; 268 cache->block_count = blocks; 269 270 if (!hash_table_create(&cache->block_hash, CACHE_BUCKETS, 1, 271 &cache_ops)) { 272 free(cache); 273 return ENOMEM; 274 } 275 276 devcon->cache = cache; 277 return EOK; 210 278 } 211 279 -
uspace/lib/libblock/libblock.h
r0c243b4 rf1ba5d6 74 74 extern void *block_bb_get(dev_handle_t); 75 75 76 extern int block_cache_init(dev_handle_t, size_t, unsigned); 77 76 78 extern block_t *block_get(dev_handle_t, off_t, size_t); 77 79 extern void block_put(block_t *); -
uspace/srv/fs/fat/fat_ops.c
r0c243b4 rf1ba5d6 462 462 } 463 463 464 /* Initialize the block cache */ 465 rc = block_cache_init(dev_handle, bps, 0 /* XXX */); 466 if (rc != EOK) { 467 block_fini(dev_handle); 468 ipc_answer_0(rid, rc); 469 return; 470 } 471 464 472 rc = fat_idx_init_by_dev_handle(dev_handle); 465 473 if (rc != EOK) {
Note:
See TracChangeset
for help on using the changeset viewer.