Changes in uspace/lib/libblock/libblock.c [0da4e41:64bc4b6] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
r0da4e41 r64bc4b6 47 47 #include <as.h> 48 48 #include <assert.h> 49 #include <fibril_sync .h>49 #include <fibril_synch.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); 89 90 90 91 static devcon_t *devcon_search(dev_handle_t dev_handle) … … 197 198 assert(devcon); 198 199 200 if (devcon->cache) 201 (void) block_cache_fini(dev_handle); 202 199 203 devcon_remove(devcon); 200 204 201 205 if (devcon->bb_buf) 202 206 free(devcon->bb_buf); 203 204 if (devcon->cache) {205 hash_table_destroy(&devcon->cache->block_hash);206 free(devcon->cache);207 }208 207 209 208 munmap(devcon->comm_area, devcon->comm_size); … … 301 300 302 301 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 303 345 return EOK; 304 346 } … … 714 756 715 757 memcpy(devcon->comm_area, data, devcon->pblock_size * cnt); 716 rc = read_blocks(devcon, ba, cnt);758 rc = write_blocks(devcon, ba, cnt); 717 759 718 760 fibril_mutex_unlock(&devcon->comm_area_lock); … … 736 778 737 779 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); 738 797 } 739 798 … … 789 848 } 790 849 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 791 864 /** @} 792 865 */
Note:
See TracChangeset
for help on using the changeset viewer.