Changeset 6f50bb0 in mainline


Ignore:
Timestamp:
2011-03-23T10:46:10Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
c7faade
Parents:
7ea69a6
Message:

ext2info: better display of allocated/unallocated data blocks for a given inode

File:
1 edited

Legend:

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

    r7ea69a6 r6f50bb0  
    395395        uint16_t access;
    396396        const char *type;
    397         uint32_t block;
    398397        uint32_t total_blocks;
    399         int i;
    400         bool all_blocks = false;
    401        
     398        uint32_t i;
     399        uint32_t range_start;
     400        uint32_t range_last;
     401        uint32_t range_start_file;
     402        uint32_t range_last_file;
     403        uint32_t range_current;
     404        uint32_t range_expected;
     405        uint32_t block_size;
     406        uint64_t file_blocks;
     407        bool printed_range;
     408        int rc;
     409       
     410        block_size = ext2_superblock_get_block_size(fs->superblock);
    402411        mode = ext2_inode_get_mode(fs->superblock, inode);
    403412        mode_type = mode & EXT2_INODE_MODE_TYPE_MASK;
     
    408417        flags = ext2_inode_get_flags(inode);
    409418        total_blocks = ext2_inode_get_reserved_blocks(fs->superblock, inode);
     419        file_blocks = 0;
     420        if (size > 0) {
     421                file_blocks = ((size-1)/block_size)+1;
     422        }
    410423       
    411424        type = "Unknown";
     
    443456        printf("  Total allocated blocks: %u\n", total_blocks);
    444457        printf("  Block list: ");
    445         for (i = 0; i < 12; i++) {
    446                 block = ext2_inode_get_direct_block(inode, i);
    447                 if (block == 0) {
    448                         all_blocks = true;
    449                         break;
    450                 }
    451                 printf("%u ", block);
    452         }
    453         all_blocks = all_blocks || ext2_inode_get_indirect_block(inode, 0) == 0;
    454         if (!all_blocks) {
    455                 printf(" and more...");
     458       
     459        range_start = 0;
     460        range_current = 0;
     461        range_last = 0;
     462       
     463        printed_range = false;
     464       
     465        for (i = 0; i <= file_blocks; i++) {
     466                if (i < file_blocks) {
     467                        rc = ext2_filesystem_get_inode_data_block_index(fs, inode, i, &range_current);
     468                        if (rc != EOK) {
     469                                printf("Error reading data block indexes\n");
     470                                return;
     471                        }
     472                }
     473                if (range_last == 0) {
     474                        range_expected = 0;
     475                }
     476                else {
     477                        range_expected = range_last + 1;
     478                }
     479                if (range_current != range_expected) {
     480                        if (i > 0) {
     481                                if (printed_range) {
     482                                        printf(", ");
     483                                }
     484                                if (range_start == 0 && range_last == 0) {
     485                                        if (range_start_file == range_last_file) {
     486                                                printf("%u N/A", range_start_file);
     487                                        }
     488                                        else {
     489                                                printf("[%u, %u] N/A", range_start_file,
     490                                                    range_last_file);
     491                                        }
     492                                }
     493                                else {
     494                                        if (range_start_file == range_last_file) {
     495                                                printf("%u -> %u", range_start_file, range_start);
     496                                        }
     497                                        else {
     498                                                printf("[%u, %u] -> [%u, %u]", range_start_file,
     499                                                    range_last_file, range_start, range_last);
     500                                        }
     501                                }
     502                                printed_range = true;
     503                        }
     504                        range_start = range_current;
     505                        range_start_file = i;
     506                }
     507                range_last = range_current;
     508                range_last_file = i;
    456509        }
    457510        printf("\n");
Note: See TracChangeset for help on using the changeset viewer.