Changes in uspace/app/blkdump/blkdump.c [15f3c3f:7901ac8] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/blkdump/blkdump.c
r15f3c3f r7901ac8 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 * … … 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include < libblock.h>42 #include <block.h> 43 43 #include <mem.h> 44 44 #include <loc.h> … … 52 52 53 53 static void syntax_print(void); 54 static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size); 55 static int print_toc(void); 54 56 static void print_hex_row(uint8_t *data, size_t length, size_t bytes_per_row); 57 58 static bool relative = false; 59 static service_id_t service_id; 55 60 56 61 int main(int argc, char **argv) … … 59 64 int rc; 60 65 char *dev_path; 61 service_id_t service_id;62 66 size_t block_size; 63 67 char *endptr; … … 65 69 aoff64_t block_count = 1; 66 70 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; 71 bool toc = false; 72 72 73 73 if (argc < 2) { … … 79 79 --argc; ++argv; 80 80 81 if (str_cmp(*argv, "--toc") == 0) { 82 --argc; ++argv; 83 toc = true; 84 goto devname; 85 } 86 81 87 if (str_cmp(*argv, "--relative") == 0) { 82 88 --argc; ++argv; … … 120 126 } 121 127 128 devname: 122 129 if (argc != 1) { 123 130 printf(NAME ": Error, unexpected argument.\n"); … … 153 160 printf("Device %s has %" PRIuOFF64 " blocks, %" PRIuOFF64 " bytes each\n", dev_path, dev_nblocks, (aoff64_t) block_size); 154 161 162 if (toc) 163 rc = print_toc(); 164 else 165 rc = print_blocks(block_offset, block_count, block_size); 166 167 block_fini(service_id); 168 169 return rc; 170 } 171 172 static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size) 173 { 174 uint8_t *data; 175 aoff64_t current; 176 aoff64_t limit; 177 size_t data_offset; 178 int rc; 179 155 180 data = malloc(block_size); 156 181 if (data == NULL) { 157 182 printf(NAME ": Error allocating data buffer of %" PRIuOFF64 " bytes", (aoff64_t) block_size); 158 block_fini(service_id);159 183 return 3; 160 184 } 161 185 162 186 limit = block_offset + block_count; 163 187 for (current = block_offset; current < limit; current++) { … … 168 192 return 3; 169 193 } 170 194 171 195 printf("---- Block %" PRIuOFF64 " (at %" PRIuOFF64 ") ----\n", current, current*block_size); 172 196 173 197 for (data_offset = 0; data_offset < block_size; data_offset += 16) { 174 198 if (relative) { … … 183 207 printf("\n"); 184 208 } 185 209 186 210 free(data); 187 188 block_fini(service_id); 211 return 0; 212 } 213 214 static int print_toc(void) 215 { 216 toc_block_t *toc; 217 218 toc = block_get_toc(service_id, 0); 219 if (toc == NULL) 220 return 1; 221 222 printf("TOC size: %" PRIu16 " bytes\n", toc->size); 223 printf("First session: %" PRIu8 "\n", toc->first_session); 224 printf("Last_session: %" PRIu8 "\n", toc->last_session); 189 225 190 226 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.