Search
lxdream.org :: lxdream/src/gdrom/gdrom.c
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/gdrom.c
changeset 489:45c8ddcf52cb
prev464:8e099fad42a6
next492:84e33e4dda1c
author nkeynes
date Sun Nov 04 05:07:49 2007 +0000 (13 years ago)
permissions -rw-r--r--
last change Test for presence of linux/cdrom.h at configure time, and only build the
linux driver if it's found successfully
file annotate diff log raw
nkeynes@342
     1
nkeynes@138
     2
/**
nkeynes@489
     3
 * $Id: gdrom.c,v 1.18 2007-11-04 05:07:49 nkeynes Exp $
nkeynes@138
     4
 *
nkeynes@138
     5
 * GD-Rom  access functions.
nkeynes@138
     6
 *
nkeynes@138
     7
 * Copyright (c) 2005 Nathan Keynes.
nkeynes@138
     8
 *
nkeynes@138
     9
 * This program is free software; you can redistribute it and/or modify
nkeynes@138
    10
 * it under the terms of the GNU General Public License as published by
nkeynes@138
    11
 * the Free Software Foundation; either version 2 of the License, or
nkeynes@138
    12
 * (at your option) any later version.
nkeynes@138
    13
 *
nkeynes@138
    14
 * This program is distributed in the hope that it will be useful,
nkeynes@138
    15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
nkeynes@138
    16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
nkeynes@138
    17
 * GNU General Public License for more details.
nkeynes@138
    18
 */
nkeynes@138
    19
nkeynes@138
    20
#include <stdio.h>
nkeynes@237
    21
#include <fcntl.h>
nkeynes@168
    22
#include <errno.h>
nkeynes@138
    23
#include "gdrom/ide.h"
nkeynes@138
    24
#include "gdrom/gdrom.h"
nkeynes@143
    25
#include "gdrom/packet.h"
nkeynes@138
    26
#include "dream.h"
nkeynes@138
    27
nkeynes@342
    28
extern gdrom_disc_t gdrom_disc;
nkeynes@138
    29
nkeynes@489
    30
gdrom_image_class_t gdrom_image_classes[] = { &cdrom_device_class, &nrg_image_class, &cdi_image_class, NULL };
nkeynes@138
    31
nkeynes@138
    32
char *gdrom_mode_names[] = { "Mode1", "Mode2", "XA 1", "XA2", "Audio", "GD-Rom" };
nkeynes@138
    33
uint32_t gdrom_sector_size[] = { 2048, 2336, 2048, 2324, 2352, 2336 };
nkeynes@138
    34
nkeynes@138
    35
gdrom_disc_t gdrom_image_open( const gchar *filename )
nkeynes@138
    36
{
nkeynes@168
    37
    const gchar *ext = strrchr(filename, '.');
nkeynes@168
    38
    gdrom_disc_t disc = NULL;
nkeynes@237
    39
nkeynes@237
    40
    int fd = open( filename, O_RDONLY | O_NONBLOCK );
nkeynes@237
    41
    FILE *f;
nkeynes@422
    42
    int i;
nkeynes@168
    43
    gdrom_image_class_t extclz = NULL;
nkeynes@168
    44
nkeynes@237
    45
    if( fd == -1 ) {
nkeynes@168
    46
	return NULL;
nkeynes@168
    47
    }
nkeynes@168
    48
nkeynes@237
    49
    f = fdopen(fd, "ro");
nkeynes@237
    50
nkeynes@237
    51
nkeynes@168
    52
    /* try extensions */
nkeynes@168
    53
    if( ext != NULL ) {
nkeynes@168
    54
	ext++; /* Skip the '.' */
nkeynes@168
    55
	for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
nkeynes@237
    56
	    if( gdrom_image_classes[i]->extension != NULL &&
nkeynes@237
    57
		strcasecmp( gdrom_image_classes[i]->extension, ext ) == 0 ) {
nkeynes@168
    58
		extclz = gdrom_image_classes[i];
nkeynes@168
    59
		if( extclz->is_valid_file(f) ) {
nkeynes@168
    60
		    disc = extclz->open_image_file(filename, f);
nkeynes@168
    61
		    if( disc != NULL )
nkeynes@168
    62
			return disc;
nkeynes@168
    63
		}
nkeynes@168
    64
		break;
nkeynes@168
    65
	    }
nkeynes@168
    66
	}
nkeynes@168
    67
    }
nkeynes@168
    68
nkeynes@168
    69
    /* Okay, fall back to magic */
nkeynes@237
    70
    gboolean recognized = FALSE;
nkeynes@168
    71
    for( i=0; gdrom_image_classes[i] != NULL; i++ ) {
nkeynes@168
    72
	if( gdrom_image_classes[i] != extclz &&
nkeynes@168
    73
	    gdrom_image_classes[i]->is_valid_file(f) ) {
nkeynes@237
    74
	    recognized = TRUE;
nkeynes@168
    75
	    disc = gdrom_image_classes[i]->open_image_file(filename, f);
nkeynes@168
    76
	    if( disc != NULL )
nkeynes@168
    77
		return disc;
nkeynes@168
    78
	}
nkeynes@168
    79
    }
nkeynes@168
    80
nkeynes@168
    81
    fclose(f);
nkeynes@168
    82
    return NULL;
nkeynes@138
    83
}
nkeynes@138
    84
nkeynes@138
    85
void gdrom_mount_disc( gdrom_disc_t disc ) 
nkeynes@138
    86
{
nkeynes@138
    87
    gdrom_unmount_disc();
nkeynes@138
    88
    gdrom_disc = disc;
nkeynes@342
    89
    gdrom_image_dump_info( disc );
nkeynes@138
    90
}
nkeynes@138
    91
nkeynes@433
    92
gboolean gdrom_mount_image( const gchar *filename )
nkeynes@138
    93
{
nkeynes@138
    94
    gdrom_disc_t disc = gdrom_image_open(filename);
nkeynes@433
    95
    if( disc != NULL ) {
nkeynes@138
    96
	gdrom_mount_disc( disc );
nkeynes@433
    97
	return TRUE;
nkeynes@433
    98
    }
nkeynes@433
    99
    return FALSE;
nkeynes@138
   100
}
nkeynes@138
   101
nkeynes@138
   102
void gdrom_unmount_disc( ) 
nkeynes@138
   103
{
nkeynes@138
   104
    if( gdrom_disc != NULL ) {
nkeynes@138
   105
	gdrom_disc->close(gdrom_disc);
nkeynes@138
   106
    }
nkeynes@138
   107
    gdrom_disc = NULL;
nkeynes@342
   108
nkeynes@138
   109
}
nkeynes@138
   110
nkeynes@464
   111
gdrom_disc_t gdrom_get_current_disc()
nkeynes@464
   112
{
nkeynes@464
   113
    return gdrom_disc;
nkeynes@464
   114
}
.