Ignore:
File:
1 edited

Legend:

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

    rf73b291 rda79df42  
    11/*
    22 * Copyright (c) 2011 Martin Sucha
    3  * Copyright (c) 2010 Jiri Svoboda
     3 * Copyright (c) 2013 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    4444#include <loc.h>
    4545#include <byteorder.h>
     46#include <scsi/mmc.h>
    4647#include <sys/types.h>
    4748#include <sys/typefmt.h>
     
    5253
    5354static void syntax_print(void);
     55static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size);
     56static int print_toc(void);
    5457static void print_hex_row(uint8_t *data, size_t length, size_t bytes_per_row);
     58
     59static bool relative = false;
     60static service_id_t service_id;
    5561
    5662int main(int argc, char **argv)
     
    5965        int rc;
    6066        char *dev_path;
    61         service_id_t service_id;
    6267        size_t block_size;
    6368        char *endptr;
     
    6570        aoff64_t block_count = 1;
    6671        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;
     72        bool toc = false;
    7273       
    7374        if (argc < 2) {
     
    7980        --argc; ++argv;
    8081
     82        if (str_cmp(*argv, "--toc") == 0) {
     83                --argc; ++argv;
     84                toc = true;
     85                goto devname;
     86        }
     87
    8188        if (str_cmp(*argv, "--relative") == 0) {
    8289                --argc; ++argv;
     
    120127        }
    121128
     129devname:
    122130        if (argc != 1) {
    123131                printf(NAME ": Error, unexpected argument.\n");
     
    153161        printf("Device %s has %" PRIuOFF64 " blocks, %" PRIuOFF64 " bytes each\n", dev_path, dev_nblocks, (aoff64_t) block_size);
    154162
     163        if (toc)
     164                rc = print_toc();
     165        else
     166                rc = print_blocks(block_offset, block_count, block_size);
     167
     168        block_fini(service_id);
     169
     170        return rc;
     171}
     172
     173static int print_blocks(aoff64_t block_offset, aoff64_t block_count, size_t block_size)
     174{
     175        uint8_t *data;
     176        aoff64_t current;
     177        aoff64_t limit;
     178        size_t data_offset;
     179        int rc;
     180
    155181        data = malloc(block_size);
    156182        if (data == NULL) {
    157183                printf(NAME ": Error allocating data buffer of %" PRIuOFF64 " bytes", (aoff64_t) block_size);
    158                 block_fini(service_id);
    159184                return 3;
    160185        }
    161        
     186
    162187        limit = block_offset + block_count;
    163188        for (current = block_offset; current < limit; current++) {
     
    168193                        return 3;
    169194                }
    170                
     195
    171196                printf("---- Block %" PRIuOFF64 " (at %" PRIuOFF64 ") ----\n", current, current*block_size);
    172                
     197
    173198                for (data_offset = 0; data_offset < block_size; data_offset += 16) {
    174199                        if (relative) {
     
    183208                printf("\n");
    184209        }
    185        
     210
    186211        free(data);
    187 
    188         block_fini(service_id);
     212        return 0;
     213}
     214
     215static int print_toc(void)
     216{
     217        scsi_toc_multisess_data_t toc;
     218        int rc;
     219
     220        rc = block_read_toc(service_id, 0, &toc, sizeof(toc));
     221        if (rc != EOK)
     222                return 1;
     223
     224        printf("Multisession Information:\n");
     225        printf("\tFirst complete session: %" PRIu8 "\n", toc.first_sess);
     226        printf("\tLast complete session: %" PRIu8 "\n", toc.last_sess);
     227        printf("\tFirst track of last complete session:\n");
     228        printf("\t\tADR / Control: 0x%" PRIx8 "\n", toc.ftrack_lsess.adr_control);
     229        printf("\t\tTrack number: %" PRIu8 "\n", toc.ftrack_lsess.track_no);
     230        printf("\t\tStart block address: %" PRIu32 "\n", toc.ftrack_lsess.start_addr);
    189231
    190232        return 0;
     
    235277static void syntax_print(void)
    236278{
    237         printf("syntax: blkdump [--relative] [--offset <num_blocks>] [--count <num_blocks>] <device_name>\n");
     279        printf("syntax: blkdump [--toc] [--relative] [--offset <num_blocks>] "
     280            "[--count <num_blocks>] <device_name>\n");
    238281}
    239282
Note: See TracChangeset for help on using the changeset viewer.