Ignore:
File:
1 edited

Legend:

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

    r1fbe064b r7308e84  
    2929#include <stdio.h>
    3030#include <stdlib.h>
    31 #include <string.h>
     31#include <str.h>
     32#include <sys/typefmt.h>
    3233#include "config.h"
    3334#include "util.h"
     
    4041#include <devmap.h>
    4142#include <errno.h>
     43#include <assert.h>
    4244
    43 #define BLOCK_SIZE      512
    44 #define BPR              16
     45enum {
     46        /* Number of bytes per row */
     47        BPR = 16
     48};
    4549
    4650static const char *cmdname = "bdd";
     
    6569        unsigned int argc;
    6670        unsigned int i, j;
    67         dev_handle_t handle;
    68         block_t *block;
     71        devmap_handle_t handle;
     72        aoff64_t offset;
    6973        uint8_t *blk;
    7074        size_t size, bytes, rows;
     75        size_t block_size;
    7176        int rc;
    72         bn_t boff;
     77        aoff64_t ba;
    7378        uint8_t b;
    7479
     
    8287
    8388        if (argc >= 3)
    84                 boff = strtol(argv[2], NULL, 0);
     89                ba = strtol(argv[2], NULL, 0);
    8590        else
    86                 boff = 0;
     91                ba = 0;
    8792
    8893        if (argc >= 4)
     
    9398        rc = devmap_device_get_handle(argv[1], &handle, 0);
    9499        if (rc != EOK) {
    95                 printf("Error: could not resolve device `%s'.\n", argv[1]);
     100                printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
    96101                return CMD_FAILURE;
    97102        }
    98103
    99         rc = block_init(handle, BLOCK_SIZE);
     104        rc = block_init(handle, 2048);
    100105        if (rc != EOK)  {
    101                 printf("Error: could not init libblock.\n");
     106                printf("%s: Error initializing libblock.\n", cmdname);
    102107                return CMD_FAILURE;
    103108        }
    104109
    105         rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
     110        rc = block_get_bsize(handle, &block_size);
    106111        if (rc != EOK) {
    107                 printf("Error: could not init block cache.\n");
     112                printf("%s: Error determining device block size.\n", cmdname);
    108113                return CMD_FAILURE;
    109114        }
    110115
     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        }
     122
     123        offset = ba * block_size;
     124
    111125        while (size > 0) {
    112                 block = block_get(handle, boff, 0);
    113                 blk = (uint8_t *) block->data;
     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                }
    114133
    115                 bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;
     134                bytes = (size < block_size) ? size : block_size;
    116135                rows = (bytes + BPR - 1) / BPR;
    117136
    118137                for (j = 0; j < rows; j++) {
     138                        printf("[%06" PRIxOFF64 "] ", offset);
    119139                        for (i = 0; i < BPR; i++) {
    120140                                if (j * BPR + i < bytes)
     
    136156                                }
    137157                        }
     158                        offset += BPR;
    138159                        putchar('\n');
    139160                }
    140 
    141                 block_put(block);
    142161
    143162                if (size > rows * BPR)
     
    146165                        size = 0;
    147166
    148                 boff += rows * BPR;
     167                /* Next block */
     168                ba += 1;
    149169        }
    150170
     171        free(blk);
    151172        block_fini(handle);
    152173
Note: See TracChangeset for help on using the changeset viewer.