Ignore:
File:
1 edited

Legend:

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

    r7308e84 r1fbe064b  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <str.h>
    32 #include <sys/typefmt.h>
     31#include <string.h>
    3332#include "config.h"
    3433#include "util.h"
     
    4140#include <devmap.h>
    4241#include <errno.h>
    43 #include <assert.h>
    4442
    45 enum {
    46         /* Number of bytes per row */
    47         BPR = 16
    48 };
     43#define BLOCK_SIZE      512
     44#define BPR              16
    4945
    5046static const char *cmdname = "bdd";
     
    6965        unsigned int argc;
    7066        unsigned int i, j;
    71         devmap_handle_t handle;
    72         aoff64_t offset;
     67        dev_handle_t handle;
     68        block_t *block;
    7369        uint8_t *blk;
    7470        size_t size, bytes, rows;
    75         size_t block_size;
    7671        int rc;
    77         aoff64_t ba;
     72        bn_t boff;
    7873        uint8_t b;
    7974
     
    8782
    8883        if (argc >= 3)
    89                 ba = strtol(argv[2], NULL, 0);
     84                boff = strtol(argv[2], NULL, 0);
    9085        else
    91                 ba = 0;
     86                boff = 0;
    9287
    9388        if (argc >= 4)
     
    9893        rc = devmap_device_get_handle(argv[1], &handle, 0);
    9994        if (rc != EOK) {
    100                 printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
     95                printf("Error: could not resolve device `%s'.\n", argv[1]);
    10196                return CMD_FAILURE;
    10297        }
    10398
    104         rc = block_init(handle, 2048);
     99        rc = block_init(handle, BLOCK_SIZE);
    105100        if (rc != EOK)  {
    106                 printf("%s: Error initializing libblock.\n", cmdname);
     101                printf("Error: could not init libblock.\n");
    107102                return CMD_FAILURE;
    108103        }
    109104
    110         rc = block_get_bsize(handle, &block_size);
     105        rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
    111106        if (rc != EOK) {
    112                 printf("%s: Error determining device block size.\n", cmdname);
     107                printf("Error: could not init block cache.\n");
    113108                return CMD_FAILURE;
    114109        }
    115110
    116         blk = malloc(block_size);
    117         if (blk == NULL) {
    118                 printf("%s: Error allocating memory.\n", cmdname);
    119                 block_fini(handle);
    120                 return CMD_FAILURE;
    121         }
     111        while (size > 0) {
     112                block = block_get(handle, boff, 0);
     113                blk = (uint8_t *) block->data;
    122114
    123         offset = ba * block_size;
    124 
    125         while (size > 0) {
    126                 rc = block_read_direct(handle, ba, 1, blk);
    127                 if (rc != EOK) {
    128                         printf("%s: Error reading block %" PRIuOFF64 "\n", cmdname, ba);
    129                         free(blk);
    130                         block_fini(handle);
    131                         return CMD_FAILURE;
    132                 }
    133 
    134                 bytes = (size < block_size) ? size : block_size;
     115                bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;
    135116                rows = (bytes + BPR - 1) / BPR;
    136117
    137118                for (j = 0; j < rows; j++) {
    138                         printf("[%06" PRIxOFF64 "] ", offset);
    139119                        for (i = 0; i < BPR; i++) {
    140120                                if (j * BPR + i < bytes)
     
    156136                                }
    157137                        }
    158                         offset += BPR;
    159138                        putchar('\n');
    160139                }
     140
     141                block_put(block);
    161142
    162143                if (size > rows * BPR)
     
    165146                        size = 0;
    166147
    167                 /* Next block */
    168                 ba += 1;
     148                boff += rows * BPR;
    169149        }
    170150
    171         free(blk);
    172151        block_fini(handle);
    173152
Note: See TracChangeset for help on using the changeset viewer.