Ignore:
File:
1 edited

Legend:

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

    re272949 r5716e9a  
    22 * Copyright (c) 2008 Jakub Jermar
    33 * Copyright (c) 2008 Martin Decky
    4  * Copyright (c) 2011 Martin Sucha
    54 * All rights reserved.
    65 *
     
    412411        l = hash_table_find(&cache->block_hash, &key);
    413412        if (l) {
     413found:
    414414                /*
    415415                 * We found the block in the cache.
     
    495495                                        goto retry;
    496496                                }
     497                                l = hash_table_find(&cache->block_hash, &key);
     498                                if (l) {
     499                                        /*
     500                                         * Someone else must have already
     501                                         * instantiated the block while we were
     502                                         * not holding the cache lock.
     503                                         * Leave the recycled block on the
     504                                         * freelist and continue as if we
     505                                         * found the block of interest during
     506                                         * the first try.
     507                                         */
     508                                        fibril_mutex_unlock(&b->lock);
     509                                        goto found;
     510                                }
    497511
    498512                        }
     
    627641                        unsigned long key = block->lba;
    628642                        hash_table_remove(&cache->block_hash, &key, 1);
     643                        fibril_mutex_unlock(&block->lock);
    629644                        free(block->data);
    630645                        free(block);
     
    810825}
    811826
    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  */
    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 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 
    864827/** Read blocks from block device.
    865828 *
Note: See TracChangeset for help on using the changeset viewer.