Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/libblock/libblock.c

    r64bc4b6 r08232ee  
    198198        assert(devcon);
    199199       
    200         if (devcon->cache)
    201                 (void) block_cache_fini(dev_handle);
    202 
    203200        devcon_remove(devcon);
    204201
    205202        if (devcon->bb_buf)
    206203                free(devcon->bb_buf);
     204
     205        if (devcon->cache) {
     206                hash_table_destroy(&devcon->cache->block_hash);
     207                free(devcon->cache);
     208        }
    207209
    208210        munmap(devcon->comm_area, devcon->comm_size);
     
    300302
    301303        devcon->cache = cache;
    302         return EOK;
    303 }
    304 
    305 int block_cache_fini(dev_handle_t dev_handle)
    306 {
    307         devcon_t *devcon = devcon_search(dev_handle);
    308         cache_t *cache;
    309         int rc;
    310 
    311         if (!devcon)
    312                 return ENOENT;
    313         if (!devcon->cache)
    314                 return EOK;
    315         cache = devcon->cache;
    316        
    317         /*
    318          * We are expecting to find all blocks for this device handle on the
    319          * free list, i.e. the block reference count should be zero. Do not
    320          * bother with the cache and block locks because we are single-threaded.
    321          */
    322         while (!list_empty(&cache->free_head)) {
    323                 block_t *b = list_get_instance(cache->free_head.next,
    324                     block_t, free_link);
    325 
    326                 list_remove(&b->free_link);
    327                 if (b->dirty) {
    328                         memcpy(devcon->comm_area, b->data, b->size);
    329                         rc = write_blocks(devcon, b->boff, 1);
    330                         if (rc != EOK)
    331                                 return rc;
    332                 }
    333 
    334                 long key = b->boff;
    335                 hash_table_remove(&cache->block_hash, &key, 1);
    336                
    337                 free(b->data);
    338                 free(b);
    339         }
    340 
    341         hash_table_destroy(&cache->block_hash);
    342         devcon->cache = NULL;
    343         free(cache);
    344 
    345304        return EOK;
    346305}
Note: See TracChangeset for help on using the changeset viewer.