Changes in uspace/app/blkdump/blkdump.c [7901ac8:15f3c3f] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/blkdump/blkdump.c
r7901ac8 r15f3c3f 1 1 /* 2 2 * Copyright (c) 2011 Martin Sucha 3 * Copyright (c) 201 3Jiri Svoboda3 * Copyright (c) 2010 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 40 40 #include <stdio.h> 41 41 #include <stdlib.h> 42 #include < block.h>42 #include <libblock.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);56 54 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;60 55 61 56 int main(int argc, char **argv) … … 64 59 int rc; 65 60 char *dev_path; 61 service_id_t service_id; 66 62 size_t block_size; 67 63 char *endptr; … … 69 65 aoff64_t block_count = 1; 70 66 aoff64_t dev_nblocks; 71 bool toc = false; 67 uint8_t *data; 68 size_t data_offset; 69 aoff64_t current; 70 aoff64_t limit; 71 bool relative = 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 87 81 if (str_cmp(*argv, "--relative") == 0) { 88 82 --argc; ++argv; … … 126 120 } 127 121 128 devname:129 122 if (argc != 1) { 130 123 printf(NAME ": Error, unexpected argument.\n"); … … 160 153 printf("Device %s has %" PRIuOFF64 " blocks, %" PRIuOFF64 " bytes each\n", dev_path, dev_nblocks, (aoff64_t) block_size); 161 154 162 if (toc)163 rc = print_toc();164 else165 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 180 155 data = malloc(block_size); 181 156 if (data == NULL) { 182 157 printf(NAME ": Error allocating data buffer of %" PRIuOFF64 " bytes", (aoff64_t) block_size); 158 block_fini(service_id); 183 159 return 3; 184 160 } 185 161 186 162 limit = block_offset + block_count; 187 163 for (current = block_offset; current < limit; current++) { … … 192 168 return 3; 193 169 } 194 170 195 171 printf("---- Block %" PRIuOFF64 " (at %" PRIuOFF64 ") ----\n", current, current*block_size); 196 172 197 173 for (data_offset = 0; data_offset < block_size; data_offset += 16) { 198 174 if (relative) { … … 207 183 printf("\n"); 208 184 } 209 185 210 186 free(data); 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); 187 188 block_fini(service_id); 225 189 226 190 return 0;
Note:
See TracChangeset
for help on using the changeset viewer.