Changes in uspace/app/bdsh/cmds/modules/bdd/bdd.c [309ede1:1fbe064b] in mainline
- File:
-
- 1 edited
-
uspace/app/bdsh/cmds/modules/bdd/bdd.c (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/cmds/modules/bdd/bdd.c
r309ede1 r1fbe064b 40 40 #include <devmap.h> 41 41 #include <errno.h> 42 #include <assert.h>43 42 44 enum { 45 /* Number of bytes per row */ 46 BPR = 16 47 }; 43 #define BLOCK_SIZE 512 44 #define BPR 16 48 45 49 46 static const char *cmdname = "bdd"; … … 69 66 unsigned int i, j; 70 67 dev_handle_t handle; 68 block_t *block; 71 69 uint8_t *blk; 72 70 size_t size, bytes, rows; 73 size_t block_size;74 71 int rc; 75 bn_t b a;72 bn_t boff; 76 73 uint8_t b; 77 74 … … 85 82 86 83 if (argc >= 3) 87 b a= strtol(argv[2], NULL, 0);84 boff = strtol(argv[2], NULL, 0); 88 85 else 89 b a= 0;86 boff = 0; 90 87 91 88 if (argc >= 4) … … 96 93 rc = devmap_device_get_handle(argv[1], &handle, 0); 97 94 if (rc != EOK) { 98 printf(" %s: Error resolving device `%s'.\n", cmdname, argv[1]);95 printf("Error: could not resolve device `%s'.\n", argv[1]); 99 96 return CMD_FAILURE; 100 97 } 101 98 102 rc = block_init(handle, 2048);99 rc = block_init(handle, BLOCK_SIZE); 103 100 if (rc != EOK) { 104 printf(" %s: Error initializing libblock.\n", cmdname);101 printf("Error: could not init libblock.\n"); 105 102 return CMD_FAILURE; 106 103 } 107 104 108 rc = block_ get_bsize(handle, &block_size);105 rc = block_cache_init(handle, BLOCK_SIZE, 2, CACHE_MODE_WB); 109 106 if (rc != EOK) { 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); 107 printf("Error: could not init block cache.\n"); 118 108 return CMD_FAILURE; 119 109 } 120 110 121 111 while (size > 0) { 122 rc = block_read_direct(handle, ba, 1, blk); 123 if (rc != EOK) { 124 printf("%s: Error reading block %llu\n", cmdname, ba); 125 free(blk); 126 block_fini(handle); 127 return CMD_FAILURE; 128 } 112 block = block_get(handle, boff, 0); 113 blk = (uint8_t *) block->data; 129 114 130 bytes = (size < block_size) ? size : block_size;115 bytes = (size < BLOCK_SIZE) ? size : BLOCK_SIZE; 131 116 rows = (bytes + BPR - 1) / BPR; 132 117 … … 154 139 } 155 140 141 block_put(block); 142 156 143 if (size > rows * BPR) 157 144 size -= rows * BPR; … … 159 146 size = 0; 160 147 161 /* Next block */ 162 ba += 1; 148 boff += rows * BPR; 163 149 } 164 150 165 free(blk);166 151 block_fini(handle); 167 152
Note:
See TracChangeset
for help on using the changeset viewer.
