Changeset ad34feb in mainline for uspace/app/ext2info/ext2info.c
- Timestamp:
- 2011-02-23T23:07:28Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 102d400
- Parents:
- a54af66
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ext2info/ext2info.c
ra54af66 rad34feb 56 56 static void print_block_groups(ext2_filesystem_t *); 57 57 static void print_block_group(ext2_block_group_t *); 58 static void print_inode_by_number(ext2_filesystem_t *, uint32_t );58 static void print_inode_by_number(ext2_filesystem_t *, uint32_t, bool, uint32_t); 59 59 static void print_inode(ext2_filesystem_t *, ext2_inode_t *); 60 static void print_inode_data(ext2_filesystem_t *, ext2_inode_t *, uint32_t); 60 61 61 62 #define ARG_SUPERBLOCK 1 … … 63 64 #define ARG_INODE 4 64 65 #define ARG_STRICT_CHECK 8 66 #define ARG_INODE_DATA 16 65 67 #define ARG_COMMON (ARG_SUPERBLOCK | ARG_BLOCK_GROUPS) 66 68 #define ARG_ALL (ARG_COMMON | ARG_INODE) … … 77 79 int arg_flags; 78 80 uint32_t inode = 0; 81 uint32_t inode_data = 0; 79 82 80 83 arg_flags = 0; … … 120 123 arg_flags |= ARG_INODE; 121 124 --argc; ++argv; 125 126 if (str_cmp(*argv, "--inode-data") == 0) { 127 --argc; ++argv; 128 if (argc == 0) { 129 printf(NAME ": Argument expected for --inode-data\n"); 130 return 2; 131 } 132 133 inode_data = strtol(*argv, &endptr, 10); 134 if (*endptr != '\0') { 135 printf(NAME ": Error, invalid argument for --inode-data.\n"); 136 syntax_print(); 137 return 1; 138 } 139 140 arg_flags |= ARG_INODE_DATA; 141 --argc; ++argv; 142 } 122 143 } 123 144 … … 164 185 165 186 if (arg_flags & ARG_INODE) { 166 print_inode_by_number(&filesystem, inode); 187 print_inode_by_number(&filesystem, inode, arg_flags & ARG_INODE_DATA, 188 inode_data); 167 189 } 168 190 … … 175 197 static void syntax_print(void) 176 198 { 177 printf("syntax: ext2info --strict-check --superblock --block-groups --inode <i-number> <device_name>\n"); 199 printf("syntax: ext2info [--strict-check] [--superblock] [--block-groups] " 200 "[--inode <i-number> [--inode-data <block-number>]] <device_name>\n"); 178 201 } 179 202 … … 322 345 } 323 346 324 void print_inode_by_number(ext2_filesystem_t *fs, uint32_t inode) 347 void print_inode_by_number(ext2_filesystem_t *fs, uint32_t inode, 348 bool print_data, uint32_t data) 325 349 { 326 350 int rc; … … 336 360 337 361 print_inode(fs, inode_ref->inode); 362 if (print_data) { 363 print_inode_data(fs, inode_ref->inode, data); 364 } 338 365 339 366 rc = ext2_filesystem_put_inode_ref(inode_ref); … … 355 382 const char *type; 356 383 uint32_t block; 384 uint32_t total_blocks; 357 385 int i; 358 386 bool all_blocks = false; … … 365 393 usage_count = ext2_inode_get_usage_count(inode); 366 394 flags = ext2_inode_get_flags(inode); 395 total_blocks = ext2_inode_get_reserved_blocks(fs->superblock, inode); 367 396 368 397 type = "Unknown"; … … 390 419 391 420 access = mode & EXT2_INODE_MODE_ACCESS_MASK; 421 392 422 393 423 printf(" Mode: %08x (Type: %s, Access bits: %04ho)\n", mode, type, access); … … 397 427 printf(" Usage (link) count: %u\n", usage_count); 398 428 printf(" Flags: %u\n", flags); 429 printf(" Total allocated blocks: %u\n", total_blocks); 399 430 printf(" Block list: "); 400 431 for (i = 0; i < 12; i++) { … … 406 437 printf("%u ", block); 407 438 } 439 all_blocks = all_blocks || ext2_inode_get_indirect_block(inode, 0) == 0; 408 440 if (!all_blocks) { 409 441 printf(" and more..."); 410 442 } 411 443 printf("\n"); 444 } 445 446 void print_inode_data(ext2_filesystem_t *fs, ext2_inode_t *inode, uint32_t data) 447 { 448 int rc; 449 uint32_t data_block_index; 450 block_t *block; 451 size_t i; 452 unsigned char c; 453 454 rc = ext2_filesystem_get_inode_data_block_index(fs, inode, data, 455 &data_block_index); 456 457 if (rc != EOK) { 458 printf("Failed getting data block #%u\n", data); 459 return; 460 } 461 462 printf("Data for inode contents block #%u is located in filesystem " 463 "block %u\n", data, data_block_index); 464 465 printf("Data preview (only printable characters):\n"); 466 467 rc = block_get(&block, fs->device, data_block_index, 0); 468 if (rc != EOK) { 469 printf("Failed reading filesystem block %u\n", data_block_index); 470 return; 471 } 472 473 for (i = 0; i < block->size; i++) { 474 c = ((unsigned char *)block->data)[i]; 475 if (c >= 32 && c < 127) { 476 putchar(c); 477 } 478 else { 479 putchar('.'); 480 } 481 } 482 483 printf("\n"); 484 485 rc = block_put(block); 486 if (rc != EOK) { 487 printf("Failed putting filesystem block\n"); 488 } 489 412 490 } 413 491
Note:
See TracChangeset
for help on using the changeset viewer.