Ignore:
Timestamp:
2009-11-16T21:22:54Z (14 years ago)
Author:
Lenka Trochtova <trochtova.lenka@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5ebdf94
Parents:
fcbd1be (diff), 9c70ed6 (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:

merged with head (unstable)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/bdd/bdd.c

    rfcbd1be r1787e527  
    4040#include <devmap.h>
    4141#include <errno.h>
     42#include <assert.h>
    4243
    43 #define BLOCK_SIZE      512
    44 #define BPR              16
     44enum {
     45        /* Number of bytes per row */
     46        BPR = 16
     47};
    4548
    4649static const char *cmdname = "bdd";
     
    6669        unsigned int i, j;
    6770        dev_handle_t handle;
    68         block_t *block;
    6971        uint8_t *blk;
    7072        size_t size, bytes, rows;
     73        size_t block_size;
    7174        int rc;
    72         bn_t boff;
     75        bn_t ba;
    7376        uint8_t b;
    7477
     
    8285
    8386        if (argc >= 3)
    84                 boff = strtol(argv[2], NULL, 0);
     87                ba = strtol(argv[2], NULL, 0);
    8588        else
    86                 boff = 0;
     89                ba = 0;
    8790
    8891        if (argc >= 4)
     
    9396        rc = devmap_device_get_handle(argv[1], &handle, 0);
    9497        if (rc != EOK) {
    95                 printf("Error: could not resolve device `%s'.\n", argv[1]);
     98                printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
    9699                return CMD_FAILURE;
    97100        }
    98101
    99         rc = block_init(handle, BLOCK_SIZE);
     102        rc = block_init(handle, 2048);
    100103        if (rc != EOK)  {
    101                 printf("Error: could not init libblock.\n");
     104                printf("%s: Error initializing libblock.\n", cmdname);
    102105                return CMD_FAILURE;
    103106        }
    104107
    105         rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
     108        rc = block_get_bsize(handle, &block_size);
    106109        if (rc != EOK) {
    107                 printf("Error: could not init block cache.\n");
     110                printf("%s: Error determining device block size.\n", cmdname);
     111                return CMD_FAILURE;
     112        }
     113
     114        blk = malloc(block_size);
     115        if (blk == NULL) {
     116                printf("%s: Error allocating memory.\n", cmdname);
     117                block_fini(handle);
    108118                return CMD_FAILURE;
    109119        }
    110120
    111121        while (size > 0) {
    112                 block = block_get(handle, boff, 0);
    113                 blk = (uint8_t *) block->data;
     122                rc = block_read_direct(handle, ba, 1, blk);
     123                if (rc != EOK) {
     124                        printf("%s: Error reading block %llu\n", cmdname, ba);
     125                        free(blk);
     126                        block_fini(handle);
     127                        return CMD_FAILURE;
     128                }
    114129
    115                 bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;
     130                bytes = (size < block_size) ? size : block_size;
    116131                rows = (bytes + BPR - 1) / BPR;
    117132
     
    139154                }
    140155
    141                 block_put(block);
    142 
    143156                if (size > rows * BPR)
    144157                        size -= rows * BPR;
     
    146159                        size = 0;
    147160
    148                 boff += rows * BPR;
     161                /* Next block */
     162                ba += 1;
    149163        }
    150164
     165        free(blk);
    151166        block_fini(handle);
    152167
Note: See TracChangeset for help on using the changeset viewer.