Changeset 5352d72 in mainline for uspace/app/ext2info/ext2info.c
- Timestamp:
- 2011-02-16T16:47:18Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- a2a1792
- Parents:
- ce13577
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/ext2info/ext2info.c
rce13577 r5352d72 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); 59 static void print_inode(ext2_inode_t *); 60 61 #define ARG_SUPERBLOCK 1 62 #define ARG_BLOCK_GROUPS 2 63 #define ARG_INODE 4 64 #define ARG_STRICT_CHECK 8 65 #define ARG_COMMON (ARG_SUPERBLOCK | ARG_BLOCK_GROUPS) 66 #define ARG_ALL (ARG_COMMON | ARG_INODE) 67 58 68 59 69 int main(int argc, char **argv) … … 61 71 62 72 int rc; 73 char *endptr; 63 74 char *dev_path; 64 75 devmap_handle_t handle; 65 76 ext2_filesystem_t filesystem; 66 bool strict_check; 77 int arg_flags; 78 uint32_t inode = 0; 79 80 arg_flags = 0; 67 81 68 82 if (argc < 2) { … … 72 86 } 73 87 74 strict_check = false; 88 // Skip program name 89 --argc; ++argv; 90 75 91 if (str_cmp(*argv, "--strict-check") == 0) { 76 92 --argc; ++argv; 77 strict_check = true; 78 } 79 80 --argc; ++argv; 93 arg_flags |= ARG_STRICT_CHECK; 94 } 95 96 if (str_cmp(*argv, "--superblock") == 0) { 97 --argc; ++argv; 98 arg_flags |= ARG_SUPERBLOCK; 99 } 100 101 if (str_cmp(*argv, "--block-groups") == 0) { 102 --argc; ++argv; 103 arg_flags |= ARG_BLOCK_GROUPS; 104 } 105 106 if (str_cmp(*argv, "--inode") == 0) { 107 --argc; ++argv; 108 if (argc == 0) { 109 printf(NAME ": Argument expected for --inode\n"); 110 return 2; 111 } 112 113 inode = strtol(*argv, &endptr, 10); 114 if (*endptr != '\0') { 115 printf(NAME ": Error, invalid argument for --inode.\n"); 116 syntax_print(); 117 return 1; 118 } 119 120 arg_flags |= ARG_INODE; 121 --argc; ++argv; 122 } 81 123 82 124 if (argc != 1) { … … 85 127 return 1; 86 128 } 129 130 // Display common things by default 131 if ((arg_flags & ARG_ALL) == 0) { 132 arg_flags = ARG_COMMON; 133 } 87 134 88 135 dev_path = *argv; … … 103 150 if (rc != EOK) { 104 151 printf(NAME ": Filesystem did not pass sanity check.\n"); 105 if ( strict_check) {152 if (arg_flags & ARG_STRICT_CHECK) { 106 153 return 3; 107 154 } 108 155 } 109 156 110 print_superblock(filesystem.superblock); 111 print_block_groups(&filesystem); 157 if (arg_flags & ARG_SUPERBLOCK) { 158 print_superblock(filesystem.superblock); 159 } 160 161 if (arg_flags & ARG_BLOCK_GROUPS) { 162 print_block_groups(&filesystem); 163 } 164 165 if (arg_flags & ARG_INODE) { 166 print_inode_by_number(&filesystem, inode); 167 } 112 168 113 169 ext2_filesystem_fini(&filesystem); … … 119 175 static void syntax_print(void) 120 176 { 121 printf("syntax: ext2info <device_name>\n");177 printf("syntax: ext2info --strict-check --superblock --block-groups --inode <i-number> <device_name>\n"); 122 178 } 123 179 … … 212 268 } 213 269 214 void print_block_groups(ext2_filesystem_t *filesystem) { 270 void print_block_groups(ext2_filesystem_t *filesystem) 271 { 215 272 uint32_t block_group_count; 216 273 uint32_t i; … … 241 298 } 242 299 243 void print_block_group(ext2_block_group_t *bg) { 300 void print_block_group(ext2_block_group_t *bg) 301 { 244 302 uint32_t block_bitmap_block; 245 303 uint32_t inode_bitmap_block; … … 264 322 } 265 323 324 void print_inode_by_number(ext2_filesystem_t *fs, uint32_t inode) 325 { 326 int rc; 327 ext2_inode_ref_t *inode_ref; 328 329 printf("Inode %u\n", inode); 330 331 rc = ext2_filesystem_get_inode_ref(fs, inode, &inode_ref); 332 if (rc != EOK) { 333 printf(" Failed getting inode ref\n"); 334 return; 335 } 336 337 print_inode(inode_ref->inode); 338 339 rc = ext2_filesystem_put_inode_ref(inode_ref); 340 if (rc != EOK) { 341 printf(" Failed putting inode ref\n"); 342 } 343 } 344 345 void print_inode(ext2_inode_t *inode) 346 { 347 uint16_t mode; 348 uint32_t user_id; 349 uint32_t group_id; 350 uint32_t size; 351 uint16_t usage_count; 352 uint32_t flags; 353 uint16_t access; 354 const char *type; 355 uint32_t block; 356 int i; 357 bool all_blocks = false; 358 359 mode = ext2_inode_get_mode(inode); 360 user_id = ext2_inode_get_user_id(inode); 361 group_id = ext2_inode_get_group_id(inode); 362 size = ext2_inode_get_size(inode); 363 usage_count = ext2_inode_get_usage_count(inode); 364 flags = ext2_inode_get_flags(inode); 365 366 type = "Unknown"; 367 if ((mode & EXT2_INODE_MODE_BLOCKDEV) == EXT2_INODE_MODE_BLOCKDEV) { 368 type = "Block device"; 369 } 370 else if (mode & EXT2_INODE_MODE_FIFO) { 371 type = "Fifo (pipe)"; 372 } 373 else if (mode & EXT2_INODE_MODE_CHARDEV) { 374 type = "Character device"; 375 } 376 else if (mode & EXT2_INODE_MODE_DIRECTORY) { 377 type = "Directory"; 378 } 379 else if (mode & EXT2_INODE_MODE_FILE) { 380 type = "File"; 381 } 382 else if (mode & EXT2_INODE_MODE_SOFTLINK) { 383 type = "Soft link"; 384 } 385 else if (mode & EXT2_INODE_MODE_SOCKET) { 386 type = "Socket"; 387 } 388 389 access = mode & EXT2_INODE_MODE_ACCESS_MASK; 390 391 printf(" Mode: %04x (Type: %s, Access bits: %04ho)\n", mode, type, access); 392 printf(" User ID: %u\n", user_id); 393 printf(" Group ID: %u\n", group_id); 394 printf(" Size: %u\n", size); 395 printf(" Usage (link) count: %u\n", usage_count); 396 printf(" Flags: %u\n", flags); 397 printf(" Block list: "); 398 for (i = 0; i < 12; i++) { 399 block = ext2_inode_get_direct_block(inode, i); 400 if (block == 0) { 401 all_blocks = true; 402 break; 403 } 404 printf("%u ", block); 405 } 406 if (!all_blocks) { 407 printf(" and more..."); 408 } 409 printf("\n"); 410 } 411 266 412 /** 267 413 * @}
Note:
See TracChangeset
for help on using the changeset viewer.