Search
lxdream.org :: lxdream/src/gdrom/gdi.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdi.c
changeset 736:a02d1475ccfd
prev678:35eb00945316
next759:f16975739abc
author nkeynes
date Mon Jul 14 07:44:42 2008 +0000 (11 years ago)
permissions -rw-r--r--
last change Re-indent everything consistently
Fix include guards for consistency as well
file annotate diff log raw
1.1 --- a/src/gdrom/gdi.c Thu May 29 11:00:26 2008 +0000
1.2 +++ b/src/gdrom/gdi.c Mon Jul 14 07:44:42 2008 +0000
1.3 @@ -30,20 +30,20 @@
1.4 static gdrom_disc_t gdi_image_open( const gchar *filename, FILE *f );
1.5
1.6 struct gdrom_image_class gdi_image_class = { "NullDC GD-Rom Image", "gdi",
1.7 - gdi_image_is_valid, gdi_image_open };
1.8 + gdi_image_is_valid, gdi_image_open };
1.9
1.10 static gboolean gdi_image_is_valid( FILE *f )
1.11 {
1.12 char line[512];
1.13 uint32_t track_count;
1.14 -
1.15 +
1.16 fseek(f, 0, SEEK_SET);
1.17 if( fgets( line, sizeof(line), f ) == NULL ) {
1.18 - return FALSE;
1.19 + return FALSE;
1.20 }
1.21 track_count = strtoul(line, NULL, 0);
1.22 if( track_count == 0 || track_count > 99 ) {
1.23 - return FALSE;
1.24 + return FALSE;
1.25 }
1.26 return TRUE;
1.27 }
1.28 @@ -59,79 +59,79 @@
1.29 gchar *dirname;
1.30
1.31 fseek(f, 0, SEEK_SET);
1.32 -
1.33 +
1.34 if( fgets( line, sizeof(line), f ) == NULL ) {
1.35 - return FALSE;
1.36 + return FALSE;
1.37 }
1.38 track_count = strtoul(line, NULL, 0);
1.39 if( track_count == 0 || track_count > 99 ) {
1.40 - return NULL;
1.41 + return NULL;
1.42 }
1.43
1.44 disc = gdrom_image_new(filename, f);
1.45 if( disc == NULL ) {
1.46 - ERROR("Unable to allocate memory!");
1.47 - return NULL;
1.48 + ERROR("Unable to allocate memory!");
1.49 + return NULL;
1.50 }
1.51 dirname = g_path_get_dirname(filename);
1.52 image = (gdrom_image_t)disc;
1.53 image->disc_type = IDE_DISC_GDROM;
1.54 image->track_count = track_count;
1.55 for( i=0; i<track_count; i++ ) {
1.56 - int track_no, start_lba, flags, size, offset;
1.57 - char filename[256];
1.58 + int track_no, start_lba, flags, size, offset;
1.59 + char filename[256];
1.60
1.61 - if( fgets( line, sizeof(line), f ) == NULL ) {
1.62 - gdrom_image_destroy_no_close(disc);
1.63 - return NULL;
1.64 - }
1.65 - sscanf( line, "%d %d %d %d %s %d", &track_no, &start_lba, &flags, &size,
1.66 - filename, &offset );
1.67 - if( start_lba >= 45000 ) {
1.68 - image->track[i].session = 1;
1.69 - } else {
1.70 - image->track[i].session = 0;
1.71 - }
1.72 - image->track[i].lba = start_lba + 150; // 2-second offset
1.73 - image->track[i].flags = (flags & 0x0F)<<4;
1.74 - image->track[i].sector_size = size;
1.75 - if( strcasecmp( filename, "none" ) == 0 ) {
1.76 - image->track[i].file = NULL;
1.77 - image->track[i].sector_count = 0;
1.78 - image->track[i].mode = GDROM_MODE1;
1.79 - } else {
1.80 - gchar *pathname = g_strdup_printf( "%s%c%s", dirname, G_DIR_SEPARATOR, filename );
1.81 - image->track[i].file = fopen( pathname, "ro" );
1.82 - g_free(pathname);
1.83 - if( image->track[i].file == NULL ) {
1.84 - gdrom_image_destroy_no_close(disc);
1.85 - g_free(dirname);
1.86 - return NULL;
1.87 - }
1.88 - fstat( fileno(image->track[i].file), &st );
1.89 - image->track[i].sector_count = st.st_size / size;
1.90 - if( image->track[i].flags & TRACK_DATA ) {
1.91 - /* Data track */
1.92 - switch(size) {
1.93 - case 2048: image->track[i].mode = GDROM_MODE1; break;
1.94 - case 2336: image->track[i].mode = GDROM_SEMIRAW_MODE2; break;
1.95 - case 2352: image->track[i].mode = GDROM_RAW_XA; break;
1.96 - default:
1.97 - gdrom_image_destroy_no_close(disc);
1.98 - g_free(dirname);
1.99 - return NULL;
1.100 - }
1.101 - } else {
1.102 - /* Audio track */
1.103 - image->track[i].mode = GDROM_CDDA;
1.104 - if( size != 2352 ) {
1.105 - gdrom_image_destroy_no_close(disc);
1.106 - g_free(dirname);
1.107 - return NULL;
1.108 - }
1.109 - }
1.110 - }
1.111 - image->track[i].offset = offset;
1.112 + if( fgets( line, sizeof(line), f ) == NULL ) {
1.113 + gdrom_image_destroy_no_close(disc);
1.114 + return NULL;
1.115 + }
1.116 + sscanf( line, "%d %d %d %d %s %d", &track_no, &start_lba, &flags, &size,
1.117 + filename, &offset );
1.118 + if( start_lba >= 45000 ) {
1.119 + image->track[i].session = 1;
1.120 + } else {
1.121 + image->track[i].session = 0;
1.122 + }
1.123 + image->track[i].lba = start_lba + 150; // 2-second offset
1.124 + image->track[i].flags = (flags & 0x0F)<<4;
1.125 + image->track[i].sector_size = size;
1.126 + if( strcasecmp( filename, "none" ) == 0 ) {
1.127 + image->track[i].file = NULL;
1.128 + image->track[i].sector_count = 0;
1.129 + image->track[i].mode = GDROM_MODE1;
1.130 + } else {
1.131 + gchar *pathname = g_strdup_printf( "%s%c%s", dirname, G_DIR_SEPARATOR, filename );
1.132 + image->track[i].file = fopen( pathname, "ro" );
1.133 + g_free(pathname);
1.134 + if( image->track[i].file == NULL ) {
1.135 + gdrom_image_destroy_no_close(disc);
1.136 + g_free(dirname);
1.137 + return NULL;
1.138 + }
1.139 + fstat( fileno(image->track[i].file), &st );
1.140 + image->track[i].sector_count = st.st_size / size;
1.141 + if( image->track[i].flags & TRACK_DATA ) {
1.142 + /* Data track */
1.143 + switch(size) {
1.144 + case 2048: image->track[i].mode = GDROM_MODE1; break;
1.145 + case 2336: image->track[i].mode = GDROM_SEMIRAW_MODE2; break;
1.146 + case 2352: image->track[i].mode = GDROM_RAW_XA; break;
1.147 + default:
1.148 + gdrom_image_destroy_no_close(disc);
1.149 + g_free(dirname);
1.150 + return NULL;
1.151 + }
1.152 + } else {
1.153 + /* Audio track */
1.154 + image->track[i].mode = GDROM_CDDA;
1.155 + if( size != 2352 ) {
1.156 + gdrom_image_destroy_no_close(disc);
1.157 + g_free(dirname);
1.158 + return NULL;
1.159 + }
1.160 + }
1.161 + }
1.162 + image->track[i].offset = offset;
1.163 }
1.164 g_free(dirname);
1.165 return disc;
.