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 )
62 fseek(f, 0, SEEK_SET);
64 if( fgets( line, sizeof(line), f ) == NULL ) {
67 track_count = strtoul(line, NULL, 0);
68 if( track_count == 0 || track_count > 99 ) {
72 disc = gdrom_image_new(filename, f);
74 ERROR("Unable to allocate memory!");
77 dirname = g_path_get_dirname(filename);
78 disc->disc_type = IDE_DISC_GDROM;
79 disc->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 disc->destroy(disc,FALSE);
88 sscanf( line, "%d %d %d %d %s %d", &track_no, &start_lba, &flags, &size,
90 if( start_lba >= 45000 ) {
93 disc->track[i].session = session;
94 disc->track[i].lba = start_lba + 150; // 2-second offset
95 disc->track[i].flags = (flags & 0x0F)<<4;
96 disc->track[i].sector_size = size;
97 if( strcasecmp( filename, "none" ) == 0 ) {
98 disc->track[i].file = NULL;
99 disc->track[i].sector_count = 0;
100 disc->track[i].mode = GDROM_MODE1;
102 gchar *pathname = g_strdup_printf( "%s%c%s", dirname, G_DIR_SEPARATOR, filename );
103 disc->track[i].file = fopen( pathname, "ro" );
105 if( disc->track[i].file == NULL ) {
106 disc->destroy(disc,FALSE);
110 fstat( fileno(disc->track[i].file), &st );
111 disc->track[i].sector_count = st.st_size / size;
112 if( disc->track[i].flags & TRACK_DATA ) {
115 case 2048: disc->track[i].mode = GDROM_MODE1; break;
116 case 2336: disc->track[i].mode = GDROM_SEMIRAW_MODE2; break;
117 case 2352: disc->track[i].mode = GDROM_RAW_XA; break;
119 disc->destroy(disc,FALSE);
125 disc->track[i].mode = GDROM_CDDA;
127 disc->destroy(disc,FALSE);
133 disc->track[i].offset = offset;
.