Changes in uspace/lib/block/libblock.c [e272949:5716e9a] in mainline
- File:
-
- 1 edited
-
uspace/lib/block/libblock.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
re272949 r5716e9a 2 2 * Copyright (c) 2008 Jakub Jermar 3 3 * Copyright (c) 2008 Martin Decky 4 * Copyright (c) 2011 Martin Sucha5 4 * All rights reserved. 6 5 * … … 412 411 l = hash_table_find(&cache->block_hash, &key); 413 412 if (l) { 413 found: 414 414 /* 415 415 * We found the block in the cache. … … 495 495 goto retry; 496 496 } 497 l = hash_table_find(&cache->block_hash, &key); 498 if (l) { 499 /* 500 * Someone else must have already 501 * instantiated the block while we were 502 * not holding the cache lock. 503 * Leave the recycled block on the 504 * freelist and continue as if we 505 * found the block of interest during 506 * the first try. 507 */ 508 fibril_mutex_unlock(&b->lock); 509 goto found; 510 } 497 511 498 512 } … … 627 641 unsigned long key = block->lba; 628 642 hash_table_remove(&cache->block_hash, &key, 1); 643 fibril_mutex_unlock(&block->lock); 629 644 free(block->data); 630 645 free(block); … … 810 825 } 811 826 812 /** Read bytes directly from the device (bypass cache)813 *814 * @param devmap_handle Device handle of the block device.815 * @param abs_offset Absolute offset in bytes where to start reading816 * @param bytes Number of bytes to read817 * @param data Buffer that receives the data818 *819 * @return EOK on success or negative error code on failure.820 */821 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,822 size_t bytes, void *data)823 {824 int rc;825 size_t phys_block_size;826 size_t buf_size;827 void *buffer;828 aoff64_t first_block;829 aoff64_t last_block;830 size_t blocks;831 size_t offset;832 833 rc = block_get_bsize(devmap_handle, &phys_block_size);834 if (rc != EOK) {835 return rc;836 }837 838 // calculate data position and required space839 first_block = abs_offset / phys_block_size;840 offset = abs_offset % phys_block_size;841 last_block = (abs_offset + bytes - 1) / phys_block_size;842 blocks = last_block - first_block + 1;843 buf_size = blocks * phys_block_size;844 845 // read the data into memory846 buffer = malloc(buf_size);847 if (buffer == NULL) {848 return ENOMEM;849 }850 851 rc = block_read_direct(devmap_handle, first_block, blocks, buffer);852 if (rc != EOK) {853 free(buffer);854 return rc;855 }856 857 // copy the data from the buffer858 memcpy(data, buffer + offset, bytes);859 free(buffer);860 861 return EOK;862 }863 864 827 /** Read blocks from block device. 865 828 *
Note:
See TracChangeset
for help on using the changeset viewer.
