Search
lxdream.org :: lxdream/src/test/testisoread.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/test/testisoread.c
changeset 1099:566cdeb157ec
author nkeynes
date Wed Feb 10 18:16:19 2010 +1000 (10 years ago)
permissions -rw-r--r--
last change First draft of basic ISO9660 filesystem reader
file annotate diff log raw
nkeynes@1099
     1
/**
nkeynes@1099
     2
 * $Id$
nkeynes@1099
     3
 *
nkeynes@1099
     4
 * Unit tests for the ISO9660 filesystem reader
nkeynes@1099
     5
 *
nkeynes@1099
     6
 * Copyright (c) 2010 Nathan Keynes.
nkeynes@1099
     7
 *
nkeynes@1099
     8
 * This program is free software; you can redistribute it and/or modify
nkeynes@1099
     9
 * it under the terms of the GNU General Public License as published by
nkeynes@1099
    10
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@1099
    11
 * (at your option) any later version.
nkeynes@1099
    12
 *
nkeynes@1099
    13
 * This program is distributed in the hope that it will be useful,
nkeynes@1099
    14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@1099
    15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@1099
    16
 * GNU General Public License for more details.
nkeynes@1099
    17
 */
nkeynes@1099
    18
nkeynes@1099
    19
#include "drivers/cdrom/cdrom.h"
nkeynes@1099
    20
#include "drivers/cdrom/isoread.h"
nkeynes@1099
    21
#include <stdio.h>
nkeynes@1099
    22
nkeynes@1099
    23
int main( int argc, char *argv[] )
nkeynes@1099
    24
{
nkeynes@1099
    25
    if( argc < 2 ) {
nkeynes@1099
    26
        fprintf( stderr, "Usage: testisoread <disc image>\n" );
nkeynes@1099
    27
        return 1;
nkeynes@1099
    28
    }
nkeynes@1099
    29
nkeynes@1099
    30
    ERROR err;
nkeynes@1099
    31
    cdrom_disc_t disc = cdrom_disc_open(argv[1], &err);
nkeynes@1099
    32
nkeynes@1099
    33
    if( disc == NULL ) {
nkeynes@1099
    34
        fprintf( stderr, "Unable to open disc image '%s': %s\n", argv[1], err.msg );
nkeynes@1099
    35
        return 2;
nkeynes@1099
    36
    }
nkeynes@1099
    37
    cdrom_track_t track = cdrom_disc_get_last_data_track(disc);
nkeynes@1099
    38
    if( track == NULL ) {
nkeynes@1099
    39
        fprintf( stderr, "Disc has no data tracks\n" );
nkeynes@1099
    40
        return 3;
nkeynes@1099
    41
    }
nkeynes@1099
    42
nkeynes@1099
    43
    isofs_reader_t iso = isofs_reader_new_from_track( disc, track, &err );
nkeynes@1099
    44
    if( iso == NULL ) {
nkeynes@1099
    45
        fprintf( stderr, "Unable to open ISO filesystem: %s\n", err.msg );
nkeynes@1099
    46
        return 4;
nkeynes@1099
    47
    }
nkeynes@1099
    48
    isofs_reader_print_dir( stdout, isofs_reader_get_root_dir(iso) );
nkeynes@1099
    49
nkeynes@1099
    50
    isofs_reader_dirent_t boot = isofs_reader_get_file( iso, "1st_read.bin" );
nkeynes@1099
    51
    if( boot == NULL ) {
nkeynes@1099
    52
        fprintf( stderr, "Unable to find 1st_read.bin" );
nkeynes@1099
    53
        return 5;
nkeynes@1099
    54
    }
nkeynes@1099
    55
nkeynes@1099
    56
    printf( "Bootstrap: %s (%d)\n", boot->name, boot->size );
nkeynes@1099
    57
    char tmp[boot->size];
nkeynes@1099
    58
    if( isofs_reader_read_file( iso, boot, 0, boot->size, tmp ) != CDROM_ERROR_OK ) {
nkeynes@1099
    59
        fprintf( stderr, "Unable to read 1st_read.bin" );
nkeynes@1099
    60
        return 6;
nkeynes@1099
    61
    }
nkeynes@1099
    62
    return 0;
nkeynes@1099
    63
}
.