Changes in uspace/lib/block/libblock.c [c4aa9cf:c7bbf029] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/block/libblock.c
rc4aa9cf rc7bbf029 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 * … … 828 827 } 829 828 830 /** Read bytes directly from the device (bypass cache)831 *832 * @param devmap_handle Device handle of the block device.833 * @param abs_offset Absolute offset in bytes where to start reading834 * @param bytes Number of bytes to read835 * @param data Buffer that receives the data836 *837 * @return EOK on success or negative error code on failure.838 */839 int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,840 size_t bytes, void *data)841 {842 int rc;843 size_t phys_block_size;844 size_t buf_size;845 void *buffer;846 aoff64_t first_block;847 aoff64_t last_block;848 size_t blocks;849 size_t offset;850 851 rc = block_get_bsize(devmap_handle, &phys_block_size);852 if (rc != EOK) {853 return rc;854 }855 856 /* calculate data position and required space */857 first_block = abs_offset / phys_block_size;858 offset = abs_offset % phys_block_size;859 last_block = (abs_offset + bytes - 1) / phys_block_size;860 blocks = last_block - first_block + 1;861 buf_size = blocks * phys_block_size;862 863 /* read the data into memory */864 buffer = malloc(buf_size);865 if (buffer == NULL) {866 return ENOMEM;867 }868 869 rc = block_read_direct(devmap_handle, first_block, blocks, buffer);870 if (rc != EOK) {871 free(buffer);872 return rc;873 }874 875 /* copy the data from the buffer */876 memcpy(data, buffer + offset, bytes);877 free(buffer);878 879 return EOK;880 }881 882 829 /** Read blocks from block device. 883 830 *
Note:
See TracChangeset
for help on using the changeset viewer.