Search
lxdream.org :: lxdream/src/gdrom/gdrom.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.c
changeset 237:6f1a429c9d12
prev168:203a72138e16
next245:a1d0655a88d3
author nkeynes
date Fri Dec 15 10:17:08 2006 +0000 (17 years ago)
permissions -rw-r--r--
last change Add UI for the trace flag
file annotate diff log raw
1.1 --- a/src/gdrom/gdrom.c Mon Jun 26 10:30:42 2006 +0000
1.2 +++ b/src/gdrom/gdrom.c Fri Dec 15 10:17:08 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: gdrom.c,v 1.9 2006-06-26 10:30:42 nkeynes Exp $
1.6 + * $Id: gdrom.c,v 1.10 2006-12-14 12:31:38 nkeynes Exp $
1.7 *
1.8 * GD-Rom access functions.
1.9 *
1.10 @@ -17,6 +17,7 @@
1.11 */
1.12
1.13 #include <stdio.h>
1.14 +#include <fcntl.h>
1.15 #include <errno.h>
1.16 #include "gdrom/ide.h"
1.17 #include "gdrom/gdrom.h"
1.18 @@ -26,7 +27,7 @@
1.19 static void gdrom_image_destroy( gdrom_disc_t );
1.20 static gdrom_error_t gdrom_image_read_sectors( gdrom_disc_t, uint32_t, uint32_t, int, char *, uint32_t * );
1.21
1.22 -gdrom_image_class_t gdrom_image_classes[] = { &nrg_image_class, &cdi_image_class, NULL };
1.23 +gdrom_image_class_t gdrom_image_classes[] = { &linux_device_class, &nrg_image_class, &cdi_image_class, NULL };
1.24
1.25 gdrom_disc_t gdrom_disc = NULL;
1.26
1.27 @@ -37,20 +38,26 @@
1.28 {
1.29 const gchar *ext = strrchr(filename, '.');
1.30 gdrom_disc_t disc = NULL;
1.31 - FILE *f = fopen(filename, "ro");
1.32 +
1.33 + int fd = open( filename, O_RDONLY | O_NONBLOCK );
1.34 + FILE *f;
1.35 int i,j;
1.36 gdrom_image_class_t extclz = NULL;
1.37
1.38 - if( f == NULL ) {
1.39 + if( fd == -1 ) {
1.40 ERROR("Unable to open file '%s': %s", filename, strerror(errno));
1.41 return NULL;
1.42 }
1.43
1.44 + f = fdopen(fd, "ro");
1.45 +
1.46 +
1.47 /* try extensions */
1.48 if( ext != NULL ) {
1.49 ext++; /* Skip the '.' */
1.50 for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
1.51 - if( strcasecmp( gdrom_image_classes[i]->extension, ext ) == 0 ) {
1.52 + if( gdrom_image_classes[i]->extension != NULL &&
1.53 + strcasecmp( gdrom_image_classes[i]->extension, ext ) == 0 ) {
1.54 extclz = gdrom_image_classes[i];
1.55 if( extclz->is_valid_file(f) ) {
1.56 disc = extclz->open_image_file(filename, f);
1.57 @@ -63,15 +70,20 @@
1.58 }
1.59
1.60 /* Okay, fall back to magic */
1.61 + gboolean recognized = FALSE;
1.62 for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
1.63 if( gdrom_image_classes[i] != extclz &&
1.64 gdrom_image_classes[i]->is_valid_file(f) ) {
1.65 + recognized = TRUE;
1.66 disc = gdrom_image_classes[i]->open_image_file(filename, f);
1.67 if( disc != NULL )
1.68 return disc;
1.69 }
1.70 }
1.71
1.72 + if( !recognized ) {
1.73 + ERROR( "Unable to open disc %s: Unsupported format", filename );
1.74 + }
1.75 fclose(f);
1.76 return NULL;
1.77 }
.