Changes in uspace/app/blkdump/blkdump.c [f73b291:da79df42] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/blkdump/blkdump.c
rf73b291 rda79df42 1 1 /* 2 2 * Copyright (c) 2011 Martin Sucha 3 * Copyright (c) 201 0Jiri Svoboda3 * Copyright (c) 2013 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 44 44 #include <loc.h> 45 45 #include <byteorder.h> 46 #include <scsi/mmc.h> 46 47 #include <sys/types.h> 47 48 #include <sys/typefmt.h> … … 52 53 53 54 static void syntax_print(void); 55 static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size); 56 static int print_toc(void); 54 57 static void print_hex_row(uint8_t *data, size_t length, size_t bytes_per_row); 58 59 static bool relative = false; 60 static service_id_t service_id; 55 61 56 62 int main(int argc, char **argv) … … 59 65 int rc; 60 66 char *dev_path; 61 service_id_t service_id;62 67 size_t block_size; 63 68 char *endptr; … … 65 70 aoff64_t block_count = 1; 66 71 aoff64_t dev_nblocks; 67 uint8_t *data; 68 size_t data_offset; 69 aoff64_t current; 70 aoff64_t limit; 71 bool relative = false; 72 bool toc = false; 72 73 73 74 if (argc < 2) { … … 79 80 --argc; ++argv; 80 81 82 if (str_cmp(*argv, "--toc") == 0) { 83 --argc; ++argv; 84 toc = true; 85 goto devname; 86 } 87 81 88 if (str_cmp(*argv, "--relative") == 0) { 82 89 --argc; ++argv; … … 120 127 } 121 128 129 devname: 122 130 if (argc != 1) { 123 131 printf(NAME ": Error, unexpected argument.\n"); … … 153 161 printf("Device %s has %" PRIuOFF64 " blocks, %" PRIuOFF64 " bytes each\n", dev_path, dev_nblocks, (aoff64_t) block_size); 154 162 163 if (toc) 164 rc = print_toc(); 165 else 166 rc = print_blocks(block_offset, block_count, block_size); 167 168 block_fini(service_id); 169 170 return rc; 171 } 172 173 static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size) 174 { 175 uint8_t *data; 176 aoff64_t current; 177 aoff64_t limit; 178 size_t data_offset; 179 int rc; 180 155 181 data = malloc(block_size); 156 182 if (data == NULL) { 157 183 printf(NAME ": Error allocating data buffer of %" PRIuOFF64 " bytes", (aoff64_t) block_size); 158 block_fini(service_id);159 184 return 3; 160 185 } 161 186 162 187 limit = block_offset + block_count; 163 188 for (current = block_offset; current < limit; current++) { … … 168 193 return 3; 169 194 } 170 195 171 196 printf("---- Block %" PRIuOFF64 " (at %" PRIuOFF64 ") ----\n", current, current*block_size); 172 197 173 198 for (data_offset = 0; data_offset < block_size; data_offset += 16) { 174 199 if (relative) { … … 183 208 printf("\n"); 184 209 } 185 210 186 211 free(data); 187 188 block_fini(service_id); 212 return 0; 213 } 214 215 static int print_toc(void) 216 { 217 scsi_toc_multisess_data_t toc; 218 int rc; 219 220 rc = block_read_toc(service_id, 0, &toc, sizeof(toc)); 221 if (rc != EOK) 222 return 1; 223 224 printf("Multisession Information:\n"); 225 printf("\tFirst complete session: %" PRIu8 "\n", toc.first_sess); 226 printf("\tLast complete session: %" PRIu8 "\n", toc.last_sess); 227 printf("\tFirst track of last complete session:\n"); 228 printf("\t\tADR / Control: 0x%" PRIx8 "\n", toc.ftrack_lsess.adr_control); 229 printf("\t\tTrack number: %" PRIu8 "\n", toc.ftrack_lsess.track_no); 230 printf("\t\tStart block address: %" PRIu32 "\n", toc.ftrack_lsess.start_addr); 189 231 190 232 return 0; … … 235 277 static void syntax_print(void) 236 278 { 237 printf("syntax: blkdump [--relative] [--offset <num_blocks>] [--count <num_blocks>] <device_name>\n"); 279 printf("syntax: blkdump [--toc] [--relative] [--offset <num_blocks>] " 280 "[--count <num_blocks>] <device_name>\n"); 238 281 } 239 282
Note:
See TracChangeset
for help on using the changeset viewer.