Changes in uspace/lib/libblock/libblock.c [ed903174:08232ee] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/libblock/libblock.c
red903174 r08232ee 1 1 /* 2 * Copyright (c) 2008 Jakub Jermar 3 * Copyright (c) 2008 Martin Decky 2 * Copyright (c) 2008 Jakub Jermar 3 * Copyright (c) 2008 Martin Decky 4 4 * All rights reserved. 5 5 * … … 52 52 #include <macros.h> 53 53 #include <mem.h> 54 #include <sys/typefmt.h>55 #include <stacktrace.h>56 54 57 55 /** Lock protecting the device connection list */ … … 81 79 size_t comm_size; 82 80 void *bb_buf; 83 aoff64_t bb_addr;81 bn_t bb_addr; 84 82 size_t pblock_size; /**< Physical block size. */ 85 83 cache_t *cache; 86 84 } devcon_t; 87 85 88 static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);89 static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);86 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt); 87 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt); 90 88 static int get_block_size(int dev_phone, size_t *bsize); 91 static int get_num_blocks(int dev_phone, aoff64_t *nblocks);89 static int get_num_blocks(int dev_phone, bn_t *nblocks); 92 90 93 91 static devcon_t *devcon_search(dev_handle_t dev_handle) … … 200 198 assert(devcon); 201 199 202 if (devcon->cache)203 (void) block_cache_fini(dev_handle);204 205 200 devcon_remove(devcon); 206 201 … … 208 203 free(devcon->bb_buf); 209 204 205 if (devcon->cache) { 206 hash_table_destroy(&devcon->cache->block_hash); 207 free(devcon->cache); 208 } 209 210 210 munmap(devcon->comm_area, devcon->comm_size); 211 211 ipc_hangup(devcon->dev_phone); … … 214 214 } 215 215 216 int block_bb_read(dev_handle_t dev_handle, aoff64_t ba)216 int block_bb_read(dev_handle_t dev_handle, bn_t ba) 217 217 { 218 218 void *bb_buf; … … 305 305 } 306 306 307 int block_cache_fini(dev_handle_t dev_handle)308 {309 devcon_t *devcon = devcon_search(dev_handle);310 cache_t *cache;311 int rc;312 313 if (!devcon)314 return ENOENT;315 if (!devcon->cache)316 return EOK;317 cache = devcon->cache;318 319 /*320 * We are expecting to find all blocks for this device handle on the321 * free list, i.e. the block reference count should be zero. Do not322 * bother with the cache and block locks because we are single-threaded.323 */324 while (!list_empty(&cache->free_head)) {325 block_t *b = list_get_instance(cache->free_head.next,326 block_t, free_link);327 328 list_remove(&b->free_link);329 if (b->dirty) {330 memcpy(devcon->comm_area, b->data, b->size);331 rc = write_blocks(devcon, b->boff, 1);332 if (rc != EOK)333 return rc;334 }335 336 unsigned long key = b->boff;337 hash_table_remove(&cache->block_hash, &key, 1);338 339 free(b->data);340 free(b);341 }342 343 hash_table_destroy(&cache->block_hash);344 devcon->cache = NULL;345 free(cache);346 347 return EOK;348 }349 350 307 #define CACHE_LO_WATERMARK 10 351 308 #define CACHE_HI_WATERMARK 20 … … 382 339 * @return EOK on success or a negative error code. 383 340 */ 384 int block_get(block_t **block, dev_handle_t dev_handle, aoff64_t boff, int flags)341 int block_get(block_t **block, dev_handle_t dev_handle, bn_t boff, int flags) 385 342 { 386 343 devcon_t *devcon; … … 657 614 * @return EOK on success or a negative return code on failure. 658 615 */ 659 int block_seqread(dev_handle_t dev_handle, size_t *bufpos, size_t *buflen,660 aoff64_t *pos, void *dst, size_t size)661 { 662 size_t offset = 0;616 int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen, 617 off_t *pos, void *dst, size_t size) 618 { 619 off_t offset = 0; 663 620 size_t left = size; 664 621 size_t block_size; … … 690 647 } 691 648 692 if (*bufpos == *buflen) {649 if (*bufpos == (off_t) *buflen) { 693 650 /* Refill the communication buffer with a new block. */ 694 651 int rc; … … 718 675 * @return EOK on success or negative error code on failure. 719 676 */ 720 int block_read_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt, void *buf)677 int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf) 721 678 { 722 679 devcon_t *devcon; … … 746 703 * @return EOK on success or negative error code on failure. 747 704 */ 748 int block_write_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt,705 int block_write_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, 749 706 const void *data) 750 707 { … … 789 746 * @return EOK on success or negative error code on failure. 790 747 */ 791 int block_get_nblocks(dev_handle_t dev_handle, aoff64_t *nblocks)748 int block_get_nblocks(dev_handle_t dev_handle, bn_t *nblocks) 792 749 { 793 750 devcon_t *devcon; … … 808 765 * @return EOK on success or negative error code on failure. 809 766 */ 810 static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)767 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt) 811 768 { 812 769 int rc; … … 815 772 rc = async_req_3_0(devcon->dev_phone, BD_READ_BLOCKS, LOWER32(ba), 816 773 UPPER32(ba), cnt); 817 if (rc != EOK) {818 printf("Error %d reading %d blocks starting at block %" PRIuOFF64819 " from device handle %d\n", rc, cnt, ba,820 devcon->dev_handle);821 #ifndef NDEBUG822 stacktrace_print();823 #endif824 }825 774 return rc; 826 775 } … … 835 784 * @return EOK on success or negative error code on failure. 836 785 */ 837 static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)786 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt) 838 787 { 839 788 int rc; … … 842 791 rc = async_req_3_0(devcon->dev_phone, BD_WRITE_BLOCKS, LOWER32(ba), 843 792 UPPER32(ba), cnt); 844 if (rc != EOK) {845 printf("Error %d writing %d blocks starting at block %" PRIuOFF64846 " to device handle %d\n", rc, cnt, ba, devcon->dev_handle);847 #ifndef NDEBUG848 stacktrace_print();849 #endif850 }851 793 return rc; 852 794 } … … 866 808 867 809 /** Get total number of blocks on block device. */ 868 static int get_num_blocks(int dev_phone, aoff64_t *nblocks)810 static int get_num_blocks(int dev_phone, bn_t *nblocks) 869 811 { 870 812 ipcarg_t nb_l, nb_h; … … 873 815 rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h); 874 816 if (rc == EOK) { 875 *nblocks = ( aoff64_t) MERGE_LOUP32(nb_l, nb_h);817 *nblocks = (bn_t) MERGE_LOUP32(nb_l, nb_h); 876 818 } 877 819
Note:
See TracChangeset
for help on using the changeset viewer.