Changeset 5c96b2a in mainline for uspace/lib/block/libblock.c


Ignore:
Timestamp:
2011-06-02T21:26:44Z (14 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
ff4f073
Parents:
4a06045 (diff), 21300a2 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from http://ho.st.dcs.fmph.uniba.sk/~mato/bzr/helenos-ext2.

Changes made against the ext2 branch parent:

  • removed .bzrignore
  • removed all traces of pipefs
File:
1 edited

Legend:

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

    r4a06045 r5c96b2a  
    22 * Copyright (c) 2008 Jakub Jermar
    33 * Copyright (c) 2008 Martin Decky
     4 * Copyright (c) 2011 Martin Sucha
    45 * All rights reserved.
    56 *
     
    827828}
    828829
     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 reading
     834 * @param bytes                 Number of bytes to read
     835 * @param data                  Buffer that receives the data
     836 *
     837 * @return              EOK on success or negative error code on failure.
     838 */
     839int 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
    829882/** Read blocks from block device.
    830883 *
Note: See TracChangeset for help on using the changeset viewer.