Changeset 309ede1 in mainline


Ignore:
Timestamp:
2009-09-04T22:08:55Z (15 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
5f70118, b53e6d9
Parents:
ad4b32c
Message:

In bdd do not use block cache, fix block address advancing, improve style of error messages.

File:
1 edited

Legend:

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

    rad4b32c r309ede1  
    4242#include <assert.h>
    4343
    44 #define BLOCK_SIZE      512
    45 #define BPR              16
     44enum {
     45        /* Number of bytes per row */
     46        BPR = 16
     47};
    4648
    4749static const char *cmdname = "bdd";
     
    6769        unsigned int i, j;
    6870        dev_handle_t handle;
    69         block_t *block;
    7071        uint8_t *blk;
    7172        size_t size, bytes, rows;
     73        size_t block_size;
    7274        int rc;
    73         bn_t boff;
     75        bn_t ba;
    7476        uint8_t b;
    7577
     
    8385
    8486        if (argc >= 3)
    85                 boff = strtol(argv[2], NULL, 0);
     87                ba = strtol(argv[2], NULL, 0);
    8688        else
    87                 boff = 0;
     89                ba = 0;
    8890
    8991        if (argc >= 4)
     
    9496        rc = devmap_device_get_handle(argv[1], &handle, 0);
    9597        if (rc != EOK) {
    96                 printf("Error: could not resolve device `%s'.\n", argv[1]);
     98                printf("%s: Error resolving device `%s'.\n", cmdname, argv[1]);
    9799                return CMD_FAILURE;
    98100        }
    99101
    100         rc = block_init(handle, BLOCK_SIZE);
     102        rc = block_init(handle, 2048);
    101103        if (rc != EOK)  {
    102                 printf("Error: could not init libblock.\n");
     104                printf("%s: Error initializing libblock.\n", cmdname);
    103105                return CMD_FAILURE;
    104106        }
    105107
    106         rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB);
     108        rc = block_get_bsize(handle, &block_size);
    107109        if (rc != EOK) {
    108                 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);
    109118                return CMD_FAILURE;
    110119        }
    111120
    112121        while (size > 0) {
    113                 rc = block_get(&block, handle, boff, 0);
     122                rc = block_read_direct(handle, ba, 1, blk);
    114123                if (rc != EOK) {
    115                         printf("Error: could not get block %u, device %u.\n",
    116                             boff, handle);
     124                        printf("%s: Error reading block %llu\n", cmdname, ba);
     125                        free(blk);
     126                        block_fini(handle);
    117127                        return CMD_FAILURE;
    118128                }
    119                 blk = (uint8_t *) block->data;
    120129
    121                 bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE;
     130                bytes = (size < block_size) ? size : block_size;
    122131                rows = (bytes + BPR - 1) / BPR;
    123132
     
    145154                }
    146155
    147                 rc = block_put(block);
    148                 if (rc != EOK) {
    149                         printf("Error: could not put block %p.\n",
    150                             block);
    151                         return CMD_FAILURE;
    152                 }
    153 
    154156                if (size > rows * BPR)
    155157                        size -= rows * BPR;
     
    157159                        size = 0;
    158160
    159                 boff += rows * BPR;
     161                /* Next block */
     162                ba += 1;
    160163        }
    161164
     165        free(blk);
    162166        block_fini(handle);
    163167
Note: See TracChangeset for help on using the changeset viewer.