Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/block/libblock.c

    r956d4df8 re272949  
    22 * Copyright (c) 2008 Jakub Jermar
    33 * Copyright (c) 2008 Martin Decky
     4 * Copyright (c) 2011 Martin Sucha
    45 * All rights reserved.
    56 *
     
    626627                        unsigned long key = block->lba;
    627628                        hash_table_remove(&cache->block_hash, &key, 1);
    628                         fibril_mutex_unlock(&block->lock);
    629629                        free(block->data);
    630630                        free(block);
     
    810810}
    811811
     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 reading
     816 * @param bytes                 Number of bytes to read
     817 * @param data                  Buffer that receives the data
     818 *
     819 * @return              EOK on success or negative error code on failure.
     820 */
     821int 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 space
     839        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 memory
     846        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 buffer
     858        memcpy(data, buffer + offset, bytes);
     859        free(buffer);
     860       
     861        return EOK;
     862}
     863
    812864/** Read blocks from block device.
    813865 *
Note: See TracChangeset for help on using the changeset viewer.