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