Changeset 1ff896e in mainline


Ignore:
Timestamp:
2011-03-23T23:07:32Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
694ca93f
Parents:
54e90cc
Message:

Enhanced command-line arguments for ext2info

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/ext2info/ext2info.c

    r54e90cc r1ff896e  
    5858static void print_block_group(ext2_block_group_t *);
    5959static void print_inode_by_number(ext2_filesystem_t *, uint32_t, bool, uint32_t,
    60     bool);
     60    bool, bool);
    6161static void print_data(unsigned char *, size_t);
    62 static void print_inode(ext2_filesystem_t *, ext2_inode_t *);
     62static void print_inode(ext2_filesystem_t *, ext2_inode_t *, bool);
    6363static void print_inode_data(ext2_filesystem_t *, ext2_inode_t *, uint32_t);
    6464static void print_directory_contents(ext2_filesystem_t *, ext2_inode_ref_t *);
     
    6767#define ARG_BLOCK_GROUPS 2
    6868#define ARG_INODE 4
    69 #define ARG_STRICT_CHECK 8
     69#define ARG_NO_CHECK 8
    7070#define ARG_INODE_DATA 16
    7171#define ARG_INODE_LIST 32
    72 #define ARG_COMMON (ARG_SUPERBLOCK | ARG_BLOCK_GROUPS)
    73 #define ARG_ALL (ARG_COMMON | ARG_INODE)
     72#define ARG_INODE_BLOCKS 64
     73#define ARG_COMMON (ARG_SUPERBLOCK)
     74#define ARG_ALL 127
    7475
    7576
     
    9798        --argc; ++argv;
    9899       
    99         if (argc > 0 && str_cmp(*argv, "--strict-check") == 0) {
     100        if (argc > 0 && str_cmp(*argv, "--no-check") == 0) {
    100101                --argc; ++argv;
    101                 arg_flags |= ARG_STRICT_CHECK;
     102                arg_flags |= ARG_NO_CHECK;
    102103        }
    103104       
     
    129130                --argc; ++argv;
    130131               
    131                 if (argc > 0 && str_cmp(*argv, "--inode-data") == 0) {
     132                if (argc > 0 && str_cmp(*argv, "--blocks") == 0) {
     133                        --argc; ++argv;
     134                        arg_flags |= ARG_INODE_BLOCKS;
     135                }
     136               
     137                if (argc > 0 && str_cmp(*argv, "--data") == 0) {
    132138                        --argc; ++argv;
    133139                        if (argc == 0) {
    134                                 printf(NAME ": Argument expected for --inode-data\n");
     140                                printf(NAME ": Argument expected for --data\n");
    135141                                return 2;
    136142                        }
     
    138144                        inode_data = strtol(*argv, &endptr, 10);
    139145                        if (*endptr != '\0') {
    140                                 printf(NAME ": Error, invalid argument for --inode-data.\n");
     146                                printf(NAME ": Error, invalid argument for --data.\n");
    141147                                syntax_print();
    142148                                return 1;
     
    187193        if (rc != EOK) {
    188194                printf(NAME ": Filesystem did not pass sanity check.\n");
    189                 if (arg_flags & ARG_STRICT_CHECK) {
     195                if (!(arg_flags & ARG_NO_CHECK)) {
    190196                        return 3;
    191197                }
     
    202208        if (arg_flags & ARG_INODE) {
    203209                print_inode_by_number(&filesystem, inode, arg_flags & ARG_INODE_DATA,
    204                     inode_data, arg_flags & ARG_INODE_LIST);
     210                    inode_data, arg_flags & ARG_INODE_LIST,
     211                    arg_flags & ARG_INODE_BLOCKS);
    205212        }
    206213
     
    213220static void syntax_print(void)
    214221{
    215         printf("syntax: ext2info [--strict-check] [--superblock] [--block-groups] "
    216             "[--inode <i-number> [--inode-data <block-number>] [--list]] <device_name>\n");
     222        printf("syntax: ext2info [--no-check] [--superblock] [--block-groups] "
     223            "[--inode <i-number> [--blocks] [--data <block-number>] [--list]] "
     224            "<device_name>\n");
    217225}
    218226
     
    362370
    363371void print_inode_by_number(ext2_filesystem_t *fs, uint32_t inode,
    364     bool print_data, uint32_t data, bool list)
     372    bool print_data, uint32_t data, bool list, bool blocks)
    365373{
    366374        int rc;
     
    375383        }
    376384       
    377         print_inode(fs, inode_ref->inode);
     385        print_inode(fs, inode_ref->inode, blocks);
    378386        if (print_data) {
    379387                print_inode_data(fs, inode_ref->inode, data);
     
    391399}
    392400
    393 void print_inode(ext2_filesystem_t *fs, ext2_inode_t *inode)
     401void print_inode(ext2_filesystem_t *fs, ext2_inode_t *inode, bool blocks)
    394402{
    395403        uint32_t mode;
     
    462470        printf("  Flags: %u\n", flags);
    463471        printf("  Total allocated blocks: %u\n", total_blocks);
    464         printf("  Block list: ");
    465        
    466         range_start = 0;
    467         range_current = 0;
    468         range_last = 0;
    469        
    470         printed_range = false;
    471        
    472         for (i = 0; i <= file_blocks; i++) {
    473                 if (i < file_blocks) {
    474                         rc = ext2_filesystem_get_inode_data_block_index(fs, inode, i, &range_current);
    475                         if (rc != EOK) {
    476                                 printf("Error reading data block indexes\n");
    477                                 return;
    478                         }
    479                 }
    480                 if (range_last == 0) {
    481                         range_expected = 0;
    482                 }
    483                 else {
    484                         range_expected = range_last + 1;
    485                 }
    486                 if (range_current != range_expected) {
    487                         if (i > 0) {
    488                                 if (printed_range) {
    489                                         printf(", ");
     472       
     473        if (blocks) {
     474                printf("  Block list: ");
     475               
     476                range_start = 0;
     477                range_current = 0;
     478                range_last = 0;
     479               
     480                printed_range = false;
     481               
     482                for (i = 0; i <= file_blocks; i++) {
     483                        if (i < file_blocks) {
     484                                rc = ext2_filesystem_get_inode_data_block_index(fs, inode, i, &range_current);
     485                                if (rc != EOK) {
     486                                        printf("Error reading data block indexes\n");
     487                                        return;
    490488                                }
    491                                 if (range_start == 0 && range_last == 0) {
    492                                         if (range_start_file == range_last_file) {
    493                                                 printf("%u N/A", range_start_file);
     489                        }
     490                        if (range_last == 0) {
     491                                range_expected = 0;
     492                        }
     493                        else {
     494                                range_expected = range_last + 1;
     495                        }
     496                        if (range_current != range_expected) {
     497                                if (i > 0) {
     498                                        if (printed_range) {
     499                                                printf(", ");
     500                                        }
     501                                        if (range_start == 0 && range_last == 0) {
     502                                                if (range_start_file == range_last_file) {
     503                                                        printf("%u N/A", range_start_file);
     504                                                }
     505                                                else {
     506                                                        printf("[%u, %u] N/A", range_start_file,
     507                                                                range_last_file);
     508                                                }
    494509                                        }
    495510                                        else {
    496                                                 printf("[%u, %u] N/A", range_start_file,
    497                                                     range_last_file);
     511                                                if (range_start_file == range_last_file) {
     512                                                        printf("%u -> %u", range_start_file, range_start);
     513                                                }
     514                                                else {
     515                                                        printf("[%u, %u] -> [%u, %u]", range_start_file,
     516                                                                range_last_file, range_start, range_last);
     517                                                }
    498518                                        }
     519                                        printed_range = true;
    499520                                }
    500                                 else {
    501                                         if (range_start_file == range_last_file) {
    502                                                 printf("%u -> %u", range_start_file, range_start);
    503                                         }
    504                                         else {
    505                                                 printf("[%u, %u] -> [%u, %u]", range_start_file,
    506                                                     range_last_file, range_start, range_last);
    507                                         }
    508                                 }
    509                                 printed_range = true;
    510                         }
    511                         range_start = range_current;
    512                         range_start_file = i;
    513                 }
    514                 range_last = range_current;
    515                 range_last_file = i;
    516         }
    517         printf("\n");
     521                                range_start = range_current;
     522                                range_start_file = i;
     523                        }
     524                        range_last = range_current;
     525                        range_last_file = i;
     526                }
     527                printf("\n");
     528        }
    518529}
    519530
Note: See TracChangeset for help on using the changeset viewer.