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.
25 #include <glib/gutils.h>
26 #include "gdrom/gdrom.h"
29 static gboolean gdi_image_is_valid( FILE *f );
30 static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f );
32 struct gdrom_image_class gdi_image_class = { "NullDC GD-Rom Image", "gdi",
33 gdi_image_is_valid, gdi_image_open };
35 static gboolean gdi_image_is_valid( FILE *f )
40 fseek(f, 0, SEEK_SET);
41 if( fgets( line, sizeof(line), f ) == NULL ) {
44 track_count = strtoul(line, NULL, 0);
45 if( track_count == 0 || track_count > 99 ) {
51 static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f )
61 fseek(f, 0, SEEK_SET);
63 if( fgets( line, sizeof(line), f ) == NULL ) {
66 track_count = strtoul(line, NULL, 0);
67 if( track_count == 0 || track_count > 99 ) {
71 disc = gdrom_image_new(filename, f);
73 ERROR("Unable to allocate memory!");
76 dirname = g_path_get_dirname(filename);
77 image = (gdrom_image_t)disc;
78 image->disc_type = IDE_DISC_GDROM;
79 image->track_count = track_count;
80 for( i=0; i<track_count; i++ ) {
81 int track_no, start_lba, flags, size, offset;
84 if( fgets( line, sizeof(line), f ) == NULL ) {
85 gdrom_image_destroy_no_close(disc);
88 sscanf( line, "%d %d %d %d %s %d", &track_no, &start_lba, &flags, &size,
90 if( start_lba >= 45000 ) {
91 image->track[i].session = 1;
93 image->track[i].session = 0;
95 image->track[i].lba = start_lba + 150; // 2-second offset
96 image->track[i].flags = (flags & 0x0F)<<4;
97 image->track[i].sector_size = size;
98 if( strcasecmp( filename, "none" ) == 0 ) {
99 image->track[i].file = NULL;
100 image->track[i].sector_count = 0;
101 image->track[i].mode = GDROM_MODE1;
103 gchar *pathname = g_strdup_printf( "%s%c%s", dirname, G_DIR_SEPARATOR, filename );
104 image->track[i].file = fopen( pathname, "ro" );
106 if( image->track[i].file == NULL ) {
107 gdrom_image_destroy_no_close(disc);
111 fstat( fileno(image->track[i].file), &st );
112 image->track[i].sector_count = st.st_size / size;
113 if( image->track[i].flags & TRACK_DATA ) {
116 case 2048: image->track[i].mode = GDROM_MODE1; break;
117 case 2336: image->track[i].mode = GDROM_SEMIRAW_MODE2; break;
118 case 2352: image->track[i].mode = GDROM_RAW_XA; break;
120 gdrom_image_destroy_no_close(disc);
126 image->track[i].mode = GDROM_CDDA;
128 gdrom_image_destroy_no_close(disc);
134 image->track[i].offset = offset;
.