Changeset 6408be3 in mainline for uspace/lib/libblock/libblock.c


Ignore:
Timestamp:
2009-06-28T12:08:07Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
4198f9c3
Parents:
00fe6bb
Message:

Fix chaos in block library.

File:
1 edited

Legend:

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

    r00fe6bb r6408be3  
    8181} devcon_t;
    8282
    83 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
    84     const void *src);
     83static int read_block(devcon_t *devcon, bn_t boff, size_t block_size);
     84static int write_block(devcon_t *devcon, bn_t boff, size_t block_size);
    8585
    8686static devcon_t *devcon_search(dev_handle_t dev_handle)
     
    212212                return ENOMEM;
    213213       
    214         off_t bufpos = 0;
    215         size_t buflen = 0;
    216         rc = block_read(dev_handle, &bufpos, &buflen, &off,
    217             bb_buf, size, size);
     214        rc = read_block(devcon, 0, size);
    218215        if (rc != EOK) {
    219216                free(bb_buf);
    220217                return rc;
    221218        }
     219
     220        memcpy(bb_buf, devcon->com_area, size);
     221
    222222        devcon->bb_buf = bb_buf;
    223223        devcon->bb_off = off;
     
    340340                 */
    341341                int rc;
    342                 off_t bufpos = 0;
    343                 size_t buflen = 0;
    344                 off_t pos = boff * cache->block_size;
    345342                bool sync = false;
    346343
     
    400397                         * the new contents from the device.
    401398                         */
    402                         rc = block_read(dev_handle, &bufpos, &buflen, &pos,
    403                             b->data, cache->block_size, cache->block_size);
     399                        rc = read_block(devcon, b->boff, cache->block_size);
    404400                        assert(rc == EOK);
     401                        memcpy(b->data, devcon->com_area, cache->block_size);
    405402                }
    406403
     
    435432                list_append(&block->free_link, &cache->free_head);
    436433                if (cache->mode != CACHE_MODE_WB && block->dirty) {
    437                         rc = write_block(devcon, block->boff, block->size,
    438                             block->data);
     434                        memcpy(devcon->com_area, block->data, block->size);
     435                        rc = write_block(devcon, block->boff, block->size);
    439436                        assert(rc == EOK);
    440437
     
    446443}
    447444
    448 /** Read data from a block device.
     445/** Read sequential data from a block device.
    449446 *
    450447 * @param dev_handle    Device handle of the block device.
     
    460457 * @return              EOK on success or a negative return code on failure.
    461458 */
    462 int
    463 block_read(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen, off_t *pos,
    464     void *dst, size_t size, size_t block_size)
     459int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen,
     460    off_t *pos, void *dst, size_t size, size_t block_size)
    465461{
    466462        off_t offset = 0;
     
    491487                if (*bufpos == (off_t) *buflen) {
    492488                        /* Refill the communication buffer with a new block. */
    493                         ipcarg_t retval;
    494                         int rc = async_req_2_1(devcon->dev_phone, BD_READ_BLOCK,
    495                             *pos / block_size, block_size, &retval);
    496                         if ((rc != EOK) || (retval != EOK))
    497                                 return (rc != EOK ? rc : (int) retval);
     489                        int rc;
     490
     491                        rc = read_block(devcon, *pos / block_size, block_size);
     492                        if (rc != EOK)
     493                                return rc;
    498494                       
    499495                        *bufpos = 0;
     
    502498        }
    503499       
     500        return EOK;
     501}
     502
     503/** Read block from block device.
     504 *
     505 * @param devcon        Device connection.
     506 * @param boff          Block index.
     507 * @param block_size    Block size.
     508 * @param src           Buffer for storing the data.
     509 *
     510 * @return              EOK on success or negative error code on failure.
     511 */
     512static int read_block(devcon_t *devcon, bn_t boff, size_t block_size)
     513{
     514        ipcarg_t retval;
     515        int rc;
     516
     517        assert(devcon);
     518        rc = async_req_2_1(devcon->dev_phone, BD_READ_BLOCK, boff, block_size,
     519            &retval);
     520        if ((rc != EOK) || (retval != EOK))
     521                return (rc != EOK ? rc : (int) retval);
     522
    504523        return EOK;
    505524}
     
    514533 * @return              EOK on success or negative error code on failure.
    515534 */
    516 static int write_block(devcon_t *devcon, bn_t boff, size_t block_size,
    517     const void *src)
     535static int write_block(devcon_t *devcon, bn_t boff, size_t block_size)
    518536{
    519537        ipcarg_t retval;
     
    521539
    522540        assert(devcon);
    523         memcpy(devcon->com_area, src, block_size);
    524        
    525         rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK,
    526             boff, block_size, &retval);
     541        rc = async_req_2_1(devcon->dev_phone, BD_WRITE_BLOCK, boff, block_size,
     542            &retval);
    527543        if ((rc != EOK) || (retval != EOK))
    528544                return (rc != EOK ? rc : (int) retval);
Note: See TracChangeset for help on using the changeset viewer.