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