Changes in uspace/lib/block/libblock.c [e272949:956d4df8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
re272949 r956d4df8 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 * … … 627 626 unsigned long key = block->lba; 628 627 hash_table_remove(&cache->block_hash, &key, 1); 628 fibril_mutex_unlock(&block->lock); 629 629 free(block->data); 630 630 free(block); … … 810 810 } 811 811 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 812 /** Read blocks from block device. 865 813 *
Note:
See TracChangeset
for help on using the changeset viewer.