Ignore:
File:
1 edited

Legend:

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

    r309ede1 r1fbe064b  
    4040#include <devmap.h>
    4141#include <errno.h>
    42 #include <assert.h>
    4342
    44 enum {
    45         /* Number of bytes per row */
    46         BPR = 16
    47 };
     43#define BLOCK_SIZE      512
     44#define BPR              16
    4845
    4946static const char *cmdname = "bdd";
     
    6966        unsigned int i, j;
    7067        dev_handle_t handle;
     68        block_t *block;
    7169        uint8_t *blk;
    7270        size_t size, bytes, rows;
    73         size_t block_size;
    7471        int rc;
    75         bn_t ba;
     72        bn_t boff;
    7673        uint8_t b;
    7774
     
    8582
    8683        if (argc >= 3)
    87                 ba = strtol(argv[2], NULL, 0);
     84                boff = strtol(argv[2], NULL, 0);
    8885        else
    89                 ba = 0;
     86                boff = 0;
    9087
    9188        if (argc >= 4)
     
    9693        rc = devmap_device_get_handle(argv[1], &handle, 0);
    9794        if (rc != EOK) {
    98                 printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
     95                printf("Error: could not resolve device `%s'.\n", argv[1]);
    9996                return CMD_FAILURE;
    10097        }
    10198
    102         rc = block_init(handle, 2048);
     99        rc = block_init(handle, BLOCK_SIZE);
    103100        if (rc != EOK)  {
    104                 printf("%s: Error initializing libblock.\n", cmdname);
     101                printf("Error: could not init libblock.\n");
    105102                return CMD_FAILURE;
    106103        }
    107104
    108         rc = block_get_bsize(handle, &block_size);
     105        rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
    109106        if (rc != EOK) {
    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);
     107                printf("Error: could not init block cache.\n");
    118108                return CMD_FAILURE;
    119109        }
    120110
    121111        while (size > 0) {
    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                 }
     112                block = block_get(handle, boff, 0);
     113                blk = (uint8_t *) block->data;
    129114
    130                 bytes = (size < block_size) ? size : block_size;
     115                bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;
    131116                rows = (bytes + BPR - 1) / BPR;
    132117
     
    154139                }
    155140
     141                block_put(block);
     142
    156143                if (size > rows * BPR)
    157144                        size -= rows * BPR;
     
    159146                        size = 0;
    160147
    161                 /* Next block */
    162                 ba += 1;
     148                boff += rows * BPR;
    163149        }
    164150
    165         free(blk);
    166151        block_fini(handle);
    167152
Note: See TracChangeset for help on using the changeset viewer.