Changeset 7901ac8 in mainline


Ignore:
Timestamp:
2013-06-21T17:55:51Z (11 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
96cbd18
Parents:
08bb73b
Message:

Rudimentary support for dumping TOC in blkdump.

File:
1 edited

Legend:

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

    r08bb73b r7901ac8  
    11/*
    22 * Copyright (c) 2011 Martin Sucha
    3  * Copyright (c) 2010 Jiri Svoboda
     3 * Copyright (c) 2013 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    5252
    5353static void syntax_print(void);
     54static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size);
     55static int print_toc(void);
    5456static void print_hex_row(uint8_t *data, size_t length, size_t bytes_per_row);
     57
     58static bool relative = false;
     59static service_id_t service_id;
    5560
    5661int main(int argc, char **argv)
     
    5964        int rc;
    6065        char *dev_path;
    61         service_id_t service_id;
    6266        size_t block_size;
    6367        char *endptr;
     
    6569        aoff64_t block_count = 1;
    6670        aoff64_t dev_nblocks;
    67         uint8_t *data;
    68         size_t data_offset;
    69         aoff64_t current;
    70         aoff64_t limit;
    71         bool relative = false;
     71        bool toc = false;
    7272       
    7373        if (argc < 2) {
     
    7979        --argc; ++argv;
    8080
     81        if (str_cmp(*argv, "--toc") == 0) {
     82                --argc; ++argv;
     83                toc = true;
     84                goto devname;
     85        }
     86
    8187        if (str_cmp(*argv, "--relative") == 0) {
    8288                --argc; ++argv;
     
    120126        }
    121127
     128devname:
    122129        if (argc != 1) {
    123130                printf(NAME ": Error, unexpected argument.\n");
     
    153160        printf("Device %s has %" PRIuOFF64 " blocks, %" PRIuOFF64 " bytes each\n", dev_path, dev_nblocks, (aoff64_t) block_size);
    154161
     162        if (toc)
     163                rc = print_toc();
     164        else
     165                rc = print_blocks(block_offset, block_count, block_size);
     166
     167        block_fini(service_id);
     168
     169        return rc;
     170}
     171
     172static 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
    155180        data = malloc(block_size);
    156181        if (data == NULL) {
    157182                printf(NAME ": Error allocating data buffer of %" PRIuOFF64 " bytes", (aoff64_t) block_size);
    158                 block_fini(service_id);
    159183                return 3;
    160184        }
    161        
     185
    162186        limit = block_offset + block_count;
    163187        for (current = block_offset; current < limit; current++) {
     
    168192                        return 3;
    169193                }
    170                
     194
    171195                printf("---- Block %" PRIuOFF64 " (at %" PRIuOFF64 ") ----\n", current, current*block_size);
    172                
     196
    173197                for (data_offset = 0; data_offset < block_size; data_offset += 16) {
    174198                        if (relative) {
     
    183207                printf("\n");
    184208        }
    185        
     209
    186210        free(data);
    187 
    188         block_fini(service_id);
     211        return 0;
     212}
     213
     214static 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);
    189225
    190226        return 0;
Note: See TracChangeset for help on using the changeset viewer.