Ignore:
File:
1 edited

Legend:

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

    r08232ee red903174  
    11/*
    2  * Copyright (c) 2008 Jakub Jermar 
    3  * Copyright (c) 2008 Martin Decky 
     2 * Copyright (c) 2008 Jakub Jermar
     3 * Copyright (c) 2008 Martin Decky
    44 * All rights reserved.
    55 *
     
    5252#include <macros.h>
    5353#include <mem.h>
     54#include <sys/typefmt.h>
     55#include <stacktrace.h>
    5456
    5557/** Lock protecting the device connection list */
     
    7981        size_t comm_size;
    8082        void *bb_buf;
    81         bn_t bb_addr;
     83        aoff64_t bb_addr;
    8284        size_t pblock_size;             /**< Physical block size. */
    8385        cache_t *cache;
    8486} devcon_t;
    8587
    86 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
    87 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt);
     88static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);
     89static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt);
    8890static int get_block_size(int dev_phone, size_t *bsize);
    89 static int get_num_blocks(int dev_phone, bn_t *nblocks);
     91static int get_num_blocks(int dev_phone, aoff64_t *nblocks);
    9092
    9193static devcon_t *devcon_search(dev_handle_t dev_handle)
     
    198200        assert(devcon);
    199201       
     202        if (devcon->cache)
     203                (void) block_cache_fini(dev_handle);
     204
    200205        devcon_remove(devcon);
    201206
     
    203208                free(devcon->bb_buf);
    204209
    205         if (devcon->cache) {
    206                 hash_table_destroy(&devcon->cache->block_hash);
    207                 free(devcon->cache);
    208         }
    209 
    210210        munmap(devcon->comm_area, devcon->comm_size);
    211211        ipc_hangup(devcon->dev_phone);
     
    214214}
    215215
    216 int block_bb_read(dev_handle_t dev_handle, bn_t ba)
     216int block_bb_read(dev_handle_t dev_handle, aoff64_t ba)
    217217{
    218218        void *bb_buf;
     
    305305}
    306306
     307int block_cache_fini(dev_handle_t dev_handle)
     308{
     309        devcon_t *devcon = devcon_search(dev_handle);
     310        cache_t *cache;
     311        int rc;
     312
     313        if (!devcon)
     314                return ENOENT;
     315        if (!devcon->cache)
     316                return EOK;
     317        cache = devcon->cache;
     318       
     319        /*
     320         * We are expecting to find all blocks for this device handle on the
     321         * free list, i.e. the block reference count should be zero. Do not
     322         * bother with the cache and block locks because we are single-threaded.
     323         */
     324        while (!list_empty(&cache->free_head)) {
     325                block_t *b = list_get_instance(cache->free_head.next,
     326                    block_t, free_link);
     327
     328                list_remove(&b->free_link);
     329                if (b->dirty) {
     330                        memcpy(devcon->comm_area, b->data, b->size);
     331                        rc = write_blocks(devcon, b->boff, 1);
     332                        if (rc != EOK)
     333                                return rc;
     334                }
     335
     336                unsigned long key = b->boff;
     337                hash_table_remove(&cache->block_hash, &key, 1);
     338               
     339                free(b->data);
     340                free(b);
     341        }
     342
     343        hash_table_destroy(&cache->block_hash);
     344        devcon->cache = NULL;
     345        free(cache);
     346
     347        return EOK;
     348}
     349
    307350#define CACHE_LO_WATERMARK      10     
    308351#define CACHE_HI_WATERMARK      20     
     
    339382 * @return                      EOK on success or a negative error code.
    340383 */
    341 int block_get(block_t **block, dev_handle_t dev_handle, bn_t boff, int flags)
     384int block_get(block_t **block, dev_handle_t dev_handle, aoff64_t boff, int flags)
    342385{
    343386        devcon_t *devcon;
     
    614657 * @return              EOK on success or a negative return code on failure.
    615658 */
    616 int block_seqread(dev_handle_t dev_handle, off_t *bufpos, size_t *buflen,
    617     off_t *pos, void *dst, size_t size)
    618 {
    619         off_t offset = 0;
     659int block_seqread(dev_handle_t dev_handle, size_t *bufpos, size_t *buflen,
     660    aoff64_t *pos, void *dst, size_t size)
     661{
     662        size_t offset = 0;
    620663        size_t left = size;
    621664        size_t block_size;
     
    647690                }
    648691               
    649                 if (*bufpos == (off_t) *buflen) {
     692                if (*bufpos == *buflen) {
    650693                        /* Refill the communication buffer with a new block. */
    651694                        int rc;
     
    675718 * @return              EOK on success or negative error code on failure.
    676719 */
    677 int block_read_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt, void *buf)
     720int block_read_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt, void *buf)
    678721{
    679722        devcon_t *devcon;
     
    703746 * @return              EOK on success or negative error code on failure.
    704747 */
    705 int block_write_direct(dev_handle_t dev_handle, bn_t ba, size_t cnt,
     748int block_write_direct(dev_handle_t dev_handle, aoff64_t ba, size_t cnt,
    706749    const void *data)
    707750{
     
    746789 * @return              EOK on success or negative error code on failure.
    747790 */
    748 int block_get_nblocks(dev_handle_t dev_handle, bn_t *nblocks)
     791int block_get_nblocks(dev_handle_t dev_handle, aoff64_t *nblocks)
    749792{
    750793        devcon_t *devcon;
     
    765808 * @return              EOK on success or negative error code on failure.
    766809 */
    767 static int read_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
     810static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)
    768811{
    769812        int rc;
     
    772815        rc = async_req_3_0(devcon->dev_phone, BD_READ_BLOCKS, LOWER32(ba),
    773816            UPPER32(ba), cnt);
     817        if (rc != EOK) {
     818                printf("Error %d reading %d blocks starting at block %" PRIuOFF64
     819                    " from device handle %d\n", rc, cnt, ba,
     820                    devcon->dev_handle);
     821#ifndef NDEBUG
     822                stacktrace_print();
     823#endif
     824        }
    774825        return rc;
    775826}
     
    784835 * @return              EOK on success or negative error code on failure.
    785836 */
    786 static int write_blocks(devcon_t *devcon, bn_t ba, size_t cnt)
     837static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt)
    787838{
    788839        int rc;
     
    791842        rc = async_req_3_0(devcon->dev_phone, BD_WRITE_BLOCKS, LOWER32(ba),
    792843            UPPER32(ba), cnt);
     844        if (rc != EOK) {
     845                printf("Error %d writing %d blocks starting at block %" PRIuOFF64
     846                    " to device handle %d\n", rc, cnt, ba, devcon->dev_handle);
     847#ifndef NDEBUG
     848                stacktrace_print();
     849#endif
     850        }
    793851        return rc;
    794852}
     
    808866
    809867/** Get total number of blocks on block device. */
    810 static int get_num_blocks(int dev_phone, bn_t *nblocks)
     868static int get_num_blocks(int dev_phone, aoff64_t *nblocks)
    811869{
    812870        ipcarg_t nb_l, nb_h;
     
    815873        rc = async_req_0_2(dev_phone, BD_GET_NUM_BLOCKS, &nb_l, &nb_h);
    816874        if (rc == EOK) {
    817                 *nblocks = (bn_t) MERGE_LOUP32(nb_l, nb_h);
     875                *nblocks = (aoff64_t) MERGE_LOUP32(nb_l, nb_h);
    818876        }
    819877
Note: See TracChangeset for help on using the changeset viewer.