Search
lxdream.org :: lxdream/src/test/testisoread.c :: diff
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
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/test/testisoread.c Wed Feb 10 18:16:19 2010 +1000
1.3 @@ -0,0 +1,63 @@
1.4 +/**
1.5 + * $Id$
1.6 + *
1.7 + * Unit tests for the ISO9660 filesystem reader
1.8 + *
1.9 + * Copyright (c) 2010 Nathan Keynes.
1.10 + *
1.11 + * This program is free software; you can redistribute it and/or modify
1.12 + * it under the terms of the GNU General Public License as published by
1.13 + * the Free Software Foundation; either version 2 of the License, or
1.14 + * (at your option) any later version.
1.15 + *
1.16 + * This program is distributed in the hope that it will be useful,
1.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.19 + * GNU General Public License for more details.
1.20 + */
1.21 +
1.22 +#include "drivers/cdrom/cdrom.h"
1.23 +#include "drivers/cdrom/isoread.h"
1.24 +#include <stdio.h>
1.25 +
1.26 +int main( int argc, char *argv[] )
1.27 +{
1.28 + if( argc < 2 ) {
1.29 + fprintf( stderr, "Usage: testisoread <disc image>\n" );
1.30 + return 1;
1.31 + }
1.32 +
1.33 + ERROR err;
1.34 + cdrom_disc_t disc = cdrom_disc_open(argv[1], &err);
1.35 +
1.36 + if( disc == NULL ) {
1.37 + fprintf( stderr, "Unable to open disc image '%s': %s\n", argv[1], err.msg );
1.38 + return 2;
1.39 + }
1.40 + cdrom_track_t track = cdrom_disc_get_last_data_track(disc);
1.41 + if( track == NULL ) {
1.42 + fprintf( stderr, "Disc has no data tracks\n" );
1.43 + return 3;
1.44 + }
1.45 +
1.46 + isofs_reader_t iso = isofs_reader_new_from_track( disc, track, &err );
1.47 + if( iso == NULL ) {
1.48 + fprintf( stderr, "Unable to open ISO filesystem: %s\n", err.msg );
1.49 + return 4;
1.50 + }
1.51 + isofs_reader_print_dir( stdout, isofs_reader_get_root_dir(iso) );
1.52 +
1.53 + isofs_reader_dirent_t boot = isofs_reader_get_file( iso, "1st_read.bin" );
1.54 + if( boot == NULL ) {
1.55 + fprintf( stderr, "Unable to find 1st_read.bin" );
1.56 + return 5;
1.57 + }
1.58 +
1.59 + printf( "Bootstrap: %s (%d)\n", boot->name, boot->size );
1.60 + char tmp[boot->size];
1.61 + if( isofs_reader_read_file( iso, boot, 0, boot->size, tmp ) != CDROM_ERROR_OK ) {
1.62 + fprintf( stderr, "Unable to read 1st_read.bin" );
1.63 + return 6;
1.64 + }
1.65 + return 0;
1.66 +}
.