Changes in uspace/lib/libblock/libblock.c [64bc4b6:0da4e41] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r64bc4b6 r0da4e41 47 47 #include <as.h> 48 48 #include <assert.h> 49 #include <fibril_sync h.h>49 #include <fibril_sync.h> 50 50 #include <adt/list.h> 51 51 #include <adt/hash_table.h> … … 87 87 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt); 88 88 static int get_block_size(int dev_phone, size_t *bsize); 89 static int get_num_blocks(int dev_phone, bn_t *nblocks);90 89 91 90 static devcon_t *devcon_search(dev_handle_t dev_handle) … … 198 197 assert(devcon); 199 198 200 if (devcon->cache)201 (void) block_cache_fini(dev_handle);202 203 199 devcon_remove(devcon); 204 200 205 201 if (devcon->bb_buf) 206 202 free(devcon->bb_buf); 203 204 if (devcon->cache) { 205 hash_table_destroy(&devcon->cache->block_hash); 206 free(devcon->cache); 207 } 207 208 208 209 munmap(devcon->comm_area, devcon->comm_size); … … 300 301 301 302 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 the319 * free list, i.e. the block reference count should be zero. Do not320 * 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 345 303 return EOK; 346 304 } … … 756 714 757 715 memcpy(devcon->comm_area, data, devcon->pblock_size * cnt); 758 rc = write_blocks(devcon, ba, cnt);716 rc = read_blocks(devcon, ba, cnt); 759 717 760 718 fibril_mutex_unlock(&devcon->comm_area_lock); … … 778 736 779 737 return get_block_size(devcon->dev_phone, bsize); 780 }781 782 /** Get number of blocks on device.783 *784 * @param dev_handle Device handle of the block device.785 * @param nblocks Output number of blocks.786 *787 * @return EOK on success or negative error code on failure.788 */789 int block_get_nblocks(dev_handle_t dev_handle, bn_t *nblocks)790 {791 devcon_t *devcon;792 793 devcon = devcon_search(dev_handle);794 assert(devcon);795 796 return get_num_blocks(devcon->dev_phone, nblocks);797 738 } 798 739 … … 848 789 } 849 790 850 /** Get total number of blocks on block device. */851 static int get_num_blocks(int dev_phone, bn_t *nblocks)852 {853 ipcarg_t nb_l, nb_h;854 int rc;855 856 rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);857 if (rc == EOK) {858 *nblocks = (bn_t) MERGE_LOUP32(nb_l, nb_h);859 }860 861 return rc;862 }863 864 791 /** @} 865 792 */
Note:
See TracChangeset
for help on using the changeset viewer.