4 * NullDC GDI image format
6 * Copyright (c) 2005 Nathan Keynes.
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.
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.
26 #include <glib/gutils.h>
27 #include "gdrom/gddriver.h"
30 static gboolean gdi_image_is_valid( FILE *f );
31 static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f );
33 struct gdrom_image_class gdi_image_class = { "NullDC GD-Rom Image", "gdi",
34 gdi_image_is_valid, gdi_image_open };
36 static gboolean gdi_image_is_valid( FILE *f )
41 fseek(f, 0, SEEK_SET);
42 if( fgets( line, sizeof(line), f ) == NULL ) {
45 track_count = strtoul(line, NULL, 0);
46 if( track_count == 0 || track_count > 99 ) {
52 static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f )
63 fseek(f, 0, SEEK_SET);
65 if( fgets( line, sizeof(line), f ) == NULL ) {
68 track_count = strtoul(line, NULL, 0);
69 if( track_count == 0 || track_count > 99 ) {
73 disc = gdrom_image_new(filename, f);
75 ERROR("Unable to allocate memory!");
78 dirname = g_path_get_dirname(filename);
79 image = (gdrom_image_t)disc;
80 image->disc_type = IDE_DISC_GDROM;
81 image->track_count = track_count;
82 for( i=0; i<track_count; i++ ) {
83 int track_no, start_lba, flags, size, offset;
86 if( fgets( line, sizeof(line), f ) == NULL ) {
87 gdrom_image_destroy_no_close(disc);
90 sscanf( line, "%d %d %d %d %s %d", &track_no, &start_lba, &flags, &size,
92 if( start_lba >= 45000 ) {
95 image->track[i].session = session;
96 image->track[i].lba = start_lba + 150; // 2-second offset
97 image->track[i].flags = (flags & 0x0F)<<4;
98 image->track[i].sector_size = size;
99 if( strcasecmp( filename, "none" ) == 0 ) {
100 image->track[i].file = NULL;
101 image->track[i].sector_count = 0;
102 image->track[i].mode = GDROM_MODE1;
104 gchar *pathname = g_strdup_printf( "%s%c%s", dirname, G_DIR_SEPARATOR, filename );
105 image->track[i].file = fopen( pathname, "ro" );
107 if( image->track[i].file == NULL ) {
108 gdrom_image_destroy_no_close(disc);
112 fstat( fileno(image->track[i].file), &st );
113 image->track[i].sector_count = st.st_size / size;
114 if( image->track[i].flags & TRACK_DATA ) {
117 case 2048: image->track[i].mode = GDROM_MODE1; break;
118 case 2336: image->track[i].mode = GDROM_SEMIRAW_MODE2; break;
119 case 2352: image->track[i].mode = GDROM_RAW_XA; break;
121 gdrom_image_destroy_no_close(disc);
127 image->track[i].mode = GDROM_CDDA;
129 gdrom_image_destroy_no_close(disc);
135 image->track[i].offset = offset;
.