1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gdrom/gdi.c Tue Nov 06 08:35:16 2007 +0000
1.5 + * $Id: gdi.c,v 1.1 2007-11-06 08:35:16 nkeynes Exp $
1.7 + * NullDC GDI image format
1.9 + * Copyright (c) 2005 Nathan Keynes.
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.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.22 +#include <stdlib.h>
1.24 +#include <stdint.h>
1.27 +#include <sys/stat.h>
1.28 +#include <glib/gutils.h>
1.29 +#include "gdrom/gdrom.h"
1.32 +static gboolean gdi_image_is_valid( FILE *f );
1.33 +static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f );
1.35 +struct gdrom_image_class gdi_image_class = { "NullDC GD-Rom Image", "gdi",
1.36 + gdi_image_is_valid, gdi_image_open };
1.38 +static gboolean gdi_image_is_valid( FILE *f )
1.41 + uint32_t track_count;
1.43 + fseek(f, 0, SEEK_SET);
1.44 + if( fgets( line, sizeof(line), f ) == NULL ) {
1.47 + track_count = strtoul(line, NULL, 0);
1.48 + if( track_count == 0 || track_count > 99 ) {
1.54 +static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f )
1.57 + uint32_t track_count;
1.58 + gdrom_disc_t disc;
1.59 + gdrom_image_t image;
1.64 + fseek(f, 0, SEEK_SET);
1.66 + if( fgets( line, sizeof(line), f ) == NULL ) {
1.69 + track_count = strtoul(line, NULL, 0);
1.70 + if( track_count == 0 || track_count > 99 ) {
1.74 + disc = gdrom_image_new(filename, f);
1.75 + if( disc == NULL ) {
1.76 + ERROR("Unable to allocate memory!");
1.79 + dirname = g_path_get_dirname(filename);
1.80 + image = (gdrom_image_t)disc;
1.81 + image->disc_type = IDE_DISC_GDROM;
1.82 + image->track_count = track_count;
1.83 + for( i=0; i<track_count; i++ ) {
1.84 + int track_no, start_lba, flags, size, offset;
1.85 + char filename[256];
1.87 + if( fgets( line, sizeof(line), f ) == NULL ) {
1.88 + gdrom_image_destroy_no_close(disc);
1.91 + sscanf( line, "%d %d %d %d %s %d", &track_no, &start_lba, &flags, &size,
1.92 + &filename, &offset );
1.93 + if( start_lba >= 45000 ) {
1.94 + image->track[i].session = 1;
1.96 + image->track[i].session = 0;
1.98 + image->track[i].lba = start_lba + 150; // 2-second offset
1.99 + image->track[i].flags = (flags & 0x0F)<<4;
1.100 + image->track[i].sector_size = size;
1.101 + if( strcasecmp( filename, "none" ) == 0 ) {
1.102 + image->track[i].file = NULL;
1.103 + image->track[i].sector_count = 0;
1.104 + image->track[i].mode = GDROM_MODE1;
1.106 + gchar *pathname = g_strdup_printf( "%s%c%s", dirname, G_DIR_SEPARATOR, filename );
1.107 + image->track[i].file = fopen( pathname, "ro" );
1.108 + g_free(pathname);
1.109 + if( image->track[i].file == NULL ) {
1.110 + gdrom_image_destroy_no_close(disc);
1.114 + fstat( fileno(image->track[i].file), &st );
1.115 + image->track[i].sector_count = st.st_size / size;
1.117 + case 2048: image->track[i].mode = GDROM_MODE1; break;
1.118 + case 2336: image->track[i].mode = GDROM_GD; break;
1.119 + case 2352: image->track[i].mode = GDROM_CDDA; break;
1.121 + gdrom_image_destroy_no_close(disc);
1.126 + image->track[i].offset = offset;