Changes in uspace/app/bdsh/cmds/modules/bdd/bdd.c [7308e84:1fbe064b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/bdd/bdd.c
r7308e84 r1fbe064b 29 29 #include <stdio.h> 30 30 #include <stdlib.h> 31 #include <str.h> 32 #include <sys/typefmt.h> 31 #include <string.h> 33 32 #include "config.h" 34 33 #include "util.h" … … 41 40 #include <devmap.h> 42 41 #include <errno.h> 43 #include <assert.h>44 42 45 enum { 46 /* Number of bytes per row */ 47 BPR = 16 48 }; 43 #define BLOCK_SIZE 512 44 #define BPR 16 49 45 50 46 static const char *cmdname = "bdd"; … … 69 65 unsigned int argc; 70 66 unsigned int i, j; 71 dev map_handle_t handle;72 aoff64_t offset;67 dev_handle_t handle; 68 block_t *block; 73 69 uint8_t *blk; 74 70 size_t size, bytes, rows; 75 size_t block_size;76 71 int rc; 77 aoff64_t ba;72 bn_t boff; 78 73 uint8_t b; 79 74 … … 87 82 88 83 if (argc >= 3) 89 b a= strtol(argv[2], NULL, 0);84 boff = strtol(argv[2], NULL, 0); 90 85 else 91 b a= 0;86 boff = 0; 92 87 93 88 if (argc >= 4) … … 98 93 rc = devmap_device_get_handle(argv[1], &handle, 0); 99 94 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]); 101 96 return CMD_FAILURE; 102 97 } 103 98 104 rc = block_init(handle, 2048);99 rc = block_init(handle, BLOCK_SIZE); 105 100 if (rc != EOK) { 106 printf(" %s: Error initializing libblock.\n", cmdname);101 printf("Error: could not init libblock.\n"); 107 102 return CMD_FAILURE; 108 103 } 109 104 110 rc = block_ get_bsize(handle, &block_size);105 rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB); 111 106 if (rc != EOK) { 112 printf(" %s: Error determining device block size.\n", cmdname);107 printf("Error: could not init block cache.\n"); 113 108 return CMD_FAILURE; 114 109 } 115 110 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; 122 114 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; 135 116 rows = (bytes + BPR - 1) / BPR; 136 117 137 118 for (j = 0; j < rows; j++) { 138 printf("[%06" PRIxOFF64 "] ", offset);139 119 for (i = 0; i < BPR; i++) { 140 120 if (j * BPR + i < bytes) … … 156 136 } 157 137 } 158 offset += BPR;159 138 putchar('\n'); 160 139 } 140 141 block_put(block); 161 142 162 143 if (size > rows * BPR) … … 165 146 size = 0; 166 147 167 /* Next block */ 168 ba += 1; 148 boff += rows * BPR; 169 149 } 170 150 171 free(blk);172 151 block_fini(handle); 173 152
Note:
See TracChangeset
for help on using the changeset viewer.