2
2
* Copyright (c) 2008 Jakub Jermar
3
3
* Copyright (c) 2008 Martin Decky
4
* Copyright (c) 2011 Martin Sucha
4
5
* All rights reserved.
6
7
* Redistribution and use in source and binary forms, with or without
826
827
return get_num_blocks(devcon->dev_phone, nblocks);
830
/** Read bytes directly from the device (bypass cache)
832
* @param devmap_handle Device handle of the block device.
833
* @param abs_offset Absolute offset in bytes where to start reading
834
* @param bytes Number of bytes to read
835
* @param data Buffer that receives the data
837
* @return EOK on success or negative error code on failure.
839
int block_read_bytes_direct(devmap_handle_t devmap_handle, aoff64_t abs_offset,
840
size_t bytes, void *data)
843
size_t phys_block_size;
846
aoff64_t first_block;
851
rc = block_get_bsize(devmap_handle, &phys_block_size);
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;
863
/* read the data into memory */
864
buffer = malloc(buf_size);
865
if (buffer == NULL) {
869
rc = block_read_direct(devmap_handle, first_block, blocks, buffer);
875
/* copy the data from the buffer */
876
memcpy(data, buffer + offset, bytes);
829
882
/** Read blocks from block device.
831
884
* @param devcon Device connection.