Search
lxdream.org :: lxdream :: r709:18c39a8e504c
lxdream 0.9.1
released Jun 29
Download Now
changeset709:18c39a8e504c
parent708:0b8b5eaa3b52
child710:f6eaa3bcfa5b
authornkeynes
dateWed Jun 25 10:40:45 2008 +0000 (11 years ago)
Commit OSX CD-ROM driver work-in-progress
Makefile.in
configure
configure.in
src/Makefile.am
src/Makefile.in
src/drivers/cd_linux.c
src/drivers/cd_none.c
src/drivers/cd_osx.c
src/gdlist.c
src/gdrom/gddriver.h
src/gdrom/gdimage.c
src/gdrom/gdrom.c
src/gdrom/gdrom.h
1.1 --- a/Makefile.in Wed Jun 25 10:39:05 2008 +0000
1.2 +++ b/Makefile.in Wed Jun 25 10:40:45 2008 +0000
1.3 @@ -113,6 +113,10 @@
1.4 CCDEPMODE = @CCDEPMODE@
1.5 CDROM_LINUX_FALSE = @CDROM_LINUX_FALSE@
1.6 CDROM_LINUX_TRUE = @CDROM_LINUX_TRUE@
1.7 +CDROM_NONE_FALSE = @CDROM_NONE_FALSE@
1.8 +CDROM_NONE_TRUE = @CDROM_NONE_TRUE@
1.9 +CDROM_OSX_FALSE = @CDROM_OSX_FALSE@
1.10 +CDROM_OSX_TRUE = @CDROM_OSX_TRUE@
1.11 CFLAGS = @CFLAGS@
1.12 CPP = @CPP@
1.13 CPPFLAGS = @CPPFLAGS@
2.1 --- a/configure Wed Jun 25 10:39:05 2008 +0000
2.2 +++ b/configure Wed Jun 25 10:40:45 2008 +0000
2.3 @@ -764,6 +764,10 @@
2.4 AUDIO_ALSA_FALSE
2.5 CDROM_LINUX_TRUE
2.6 CDROM_LINUX_FALSE
2.7 +CDROM_OSX_TRUE
2.8 +CDROM_OSX_FALSE
2.9 +CDROM_NONE_TRUE
2.10 +CDROM_NONE_FALSE
2.11 JOY_LINUX_TRUE
2.12 JOY_LINUX_FALSE
2.13 SHCC
2.14 @@ -9195,16 +9199,15 @@
2.15
2.16 fi
2.17 if test $ac_cv_header_linux_cdrom_h = yes; then
2.18 - HAVE_LINUX_CDROM_H=yes
2.19 -else
2.20 -
2.21 - echo "Linux CDROM support not found, building without it."
2.22 -fi
2.23 -
2.24 -
2.25 -
2.26 -
2.27 -if test "$HAVE_LINUX_CDROM_H" = "yes"; then
2.28 + CDROM_DRIVER=linux
2.29 +else
2.30 + true
2.31 +fi
2.32 +
2.33 +
2.34 +
2.35 +
2.36 +if test "x$CDROM_DRIVER" = "xlinux"; then
2.37 CDROM_LINUX_TRUE=
2.38 CDROM_LINUX_FALSE='#'
2.39 else
2.40 @@ -9213,6 +9216,26 @@
2.41 fi
2.42
2.43
2.44 +
2.45 +if test "x$CDROM_DRIVER" = "xosx"; then
2.46 + CDROM_OSX_TRUE=
2.47 + CDROM_OSX_FALSE='#'
2.48 +else
2.49 + CDROM_OSX_TRUE='#'
2.50 + CDROM_OSX_FALSE=
2.51 +fi
2.52 +
2.53 +
2.54 +
2.55 +if test "x$CDROM_DRIVER" = "x"; then
2.56 + CDROM_NONE_TRUE=
2.57 + CDROM_NONE_FALSE='#'
2.58 +else
2.59 + CDROM_NONE_TRUE='#'
2.60 + CDROM_NONE_FALSE=
2.61 +fi
2.62 +
2.63 +
2.64 if test "${ac_cv_header_linux_joystick_h+set}" = set; then
2.65 { $as_echo "$as_me:$LINENO: checking for linux/joystick.h" >&5
2.66 $as_echo_n "checking for linux/joystick.h... " >&6; }
2.67 @@ -11448,6 +11471,20 @@
2.68 Usually this means the macro was only invoked conditionally." >&2;}
2.69 { (exit 1); exit 1; }; }
2.70 fi
2.71 +if test -z "${CDROM_OSX_TRUE}" && test -z "${CDROM_OSX_FALSE}"; then
2.72 + { { $as_echo "$as_me:$LINENO: error: conditional \"CDROM_OSX\" was never defined.
2.73 +Usually this means the macro was only invoked conditionally." >&5
2.74 +$as_echo "$as_me: error: conditional \"CDROM_OSX\" was never defined.
2.75 +Usually this means the macro was only invoked conditionally." >&2;}
2.76 + { (exit 1); exit 1; }; }
2.77 +fi
2.78 +if test -z "${CDROM_NONE_TRUE}" && test -z "${CDROM_NONE_FALSE}"; then
2.79 + { { $as_echo "$as_me:$LINENO: error: conditional \"CDROM_NONE\" was never defined.
2.80 +Usually this means the macro was only invoked conditionally." >&5
2.81 +$as_echo "$as_me: error: conditional \"CDROM_NONE\" was never defined.
2.82 +Usually this means the macro was only invoked conditionally." >&2;}
2.83 + { (exit 1); exit 1; }; }
2.84 +fi
2.85 if test -z "${JOY_LINUX_TRUE}" && test -z "${JOY_LINUX_FALSE}"; then
2.86 { { $as_echo "$as_me:$LINENO: error: conditional \"JOY_LINUX\" was never defined.
2.87 Usually this means the macro was only invoked conditionally." >&5
2.88 @@ -12821,3 +12858,8 @@
2.89 echo " Audio drivers: $AUDIO_DRIVERS"
2.90 fi
2.91
2.92 +if test "x$CDROM_DRIVER" = "x"; then
2.93 + echo " CD-ROM driver: none (no supported cd-rom devices found)"
2.94 +else
2.95 + echo " CD-ROM driver: $CDROM_DRIVER"
2.96 +fi
3.1 --- a/configure.in Wed Jun 25 10:39:05 2008 +0000
3.2 +++ b/configure.in Wed Jun 25 10:40:45 2008 +0000
3.3 @@ -185,10 +185,14 @@
3.4 AM_CONDITIONAL( AUDIO_ALSA, [test "$HAVE_ALSA" = 'yes'] )
3.5
3.6
3.7 -dnl Check for linux cdrom device support
3.8 -AC_CHECK_HEADER([linux/cdrom.h], [HAVE_LINUX_CDROM_H=yes], [
3.9 - echo "Linux CDROM support not found, building without it."] )
3.10 -AM_CONDITIONAL(CDROM_LINUX, [test "$HAVE_LINUX_CDROM_H" = "yes"])
3.11 +dnl Check for native cdrom support. There can be only one.
3.12 +AC_CHECK_HEADER([linux/cdrom.h], [CDROM_DRIVER=linux], [true])
3.13 +dnl AC_CHECK_HEADER([IOKit/IOKitLib.h], [
3.14 +dnl CDROM_DRIVER=osx
3.15 +dnl LIBS="$LIBS -framework IOKit"],[true])
3.16 +AM_CONDITIONAL(CDROM_LINUX, [test "x$CDROM_DRIVER" = "xlinux"])
3.17 +AM_CONDITIONAL(CDROM_OSX, [test "x$CDROM_DRIVER" = "xosx"])
3.18 +AM_CONDITIONAL(CDROM_NONE, [test "x$CDROM_DRIVER" = "x"])
3.19
3.20 AC_CHECK_HEADER([linux/joystick.h], [
3.21 HAVE_LINUX_JOYSTICK_H=yes
3.22 @@ -270,3 +274,8 @@
3.23 echo " Audio drivers: $AUDIO_DRIVERS"
3.24 fi
3.25
3.26 +if test "x$CDROM_DRIVER" = "x"; then
3.27 + echo " CD-ROM driver: none (no supported cd-rom devices found)"
3.28 +else
3.29 + echo " CD-ROM driver: $CDROM_DRIVER"
3.30 +fi
4.1 --- a/src/Makefile.am Wed Jun 25 10:39:05 2008 +0000
4.2 +++ b/src/Makefile.am Wed Jun 25 10:40:45 2008 +0000
4.3 @@ -106,7 +106,13 @@
4.4
4.5 if CDROM_LINUX
4.6 lxdream_SOURCES += drivers/cd_linux.c
4.7 -else
4.8 +endif
4.9 +
4.10 +if CDROM_OSX
4.11 +lxdream_SOURCES += drivers/cd_osx.c
4.12 +endif
4.13 +
4.14 +if CDROM_NONE
4.15 lxdream_SOURCES += drivers/cd_none.c
4.16 endif
4.17
5.1 --- a/src/Makefile.in Wed Jun 25 10:39:05 2008 +0000
5.2 +++ b/src/Makefile.in Wed Jun 25 10:40:45 2008 +0000
5.3 @@ -63,8 +63,9 @@
5.4 @AUDIO_ESOUND_TRUE@am__append_10 = drivers/audio_esd.c
5.5 @AUDIO_ALSA_TRUE@am__append_11 = drivers/audio_alsa.c
5.6 @CDROM_LINUX_TRUE@am__append_12 = drivers/cd_linux.c
5.7 -@CDROM_LINUX_FALSE@am__append_13 = drivers/cd_none.c
5.8 -@JOY_LINUX_TRUE@am__append_14 = drivers/joy_linux.c
5.9 +@CDROM_OSX_TRUE@am__append_13 = drivers/cd_osx.c
5.10 +@CDROM_NONE_TRUE@am__append_14 = drivers/cd_none.c
5.11 +@JOY_LINUX_TRUE@am__append_15 = drivers/joy_linux.c
5.12 subdir = src
5.13 DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
5.14 ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
5.15 @@ -120,7 +121,7 @@
5.16 drivers/video_glx.c drivers/video_glx.h drivers/video_nsgl.c \
5.17 drivers/video_nsgl.h drivers/audio_osx.c drivers/audio_pulse.c \
5.18 drivers/audio_esd.c drivers/audio_alsa.c drivers/cd_linux.c \
5.19 - drivers/cd_none.c drivers/joy_linux.c
5.20 + drivers/cd_osx.c drivers/cd_none.c drivers/joy_linux.c
5.21 @BUILD_SH4X86_TRUE@am__objects_1 = sh4x86.$(OBJEXT) sh4trans.$(OBJEXT) \
5.22 @BUILD_SH4X86_TRUE@ x86dasm.$(OBJEXT) i386-dis.$(OBJEXT) \
5.23 @BUILD_SH4X86_TRUE@ dis-init.$(OBJEXT) dis-buf.$(OBJEXT)
5.24 @@ -139,8 +140,9 @@
5.25 @AUDIO_ESOUND_TRUE@am__objects_9 = audio_esd.$(OBJEXT)
5.26 @AUDIO_ALSA_TRUE@am__objects_10 = audio_alsa.$(OBJEXT)
5.27 @CDROM_LINUX_TRUE@am__objects_11 = cd_linux.$(OBJEXT)
5.28 -@CDROM_LINUX_FALSE@am__objects_12 = cd_none.$(OBJEXT)
5.29 -@JOY_LINUX_TRUE@am__objects_13 = joy_linux.$(OBJEXT)
5.30 +@CDROM_OSX_TRUE@am__objects_12 = cd_osx.$(OBJEXT)
5.31 +@CDROM_NONE_TRUE@am__objects_13 = cd_none.$(OBJEXT)
5.32 +@JOY_LINUX_TRUE@am__objects_14 = joy_linux.$(OBJEXT)
5.33 am_lxdream_OBJECTS = main.$(OBJEXT) config.$(OBJEXT) mem.$(OBJEXT) \
5.34 watch.$(OBJEXT) asic.$(OBJEXT) syscall.$(OBJEXT) \
5.35 bios.$(OBJEXT) dcload.$(OBJEXT) ide.$(OBJEXT) \
5.36 @@ -163,7 +165,8 @@
5.37 $(am__objects_2) $(am__objects_3) $(am__objects_4) \
5.38 $(am__objects_5) $(am__objects_6) $(am__objects_7) \
5.39 $(am__objects_8) $(am__objects_9) $(am__objects_10) \
5.40 - $(am__objects_11) $(am__objects_12) $(am__objects_13)
5.41 + $(am__objects_11) $(am__objects_12) $(am__objects_13) \
5.42 + $(am__objects_14)
5.43 lxdream_OBJECTS = $(am_lxdream_OBJECTS)
5.44 lxdream_DEPENDENCIES = $(am__DEPENDENCIES_1)
5.45 am__test_testsh4x86_SOURCES_DIST = test/testsh4x86.c x86dasm/x86dasm.c \
5.46 @@ -234,6 +237,10 @@
5.47 CCDEPMODE = @CCDEPMODE@
5.48 CDROM_LINUX_FALSE = @CDROM_LINUX_FALSE@
5.49 CDROM_LINUX_TRUE = @CDROM_LINUX_TRUE@
5.50 +CDROM_NONE_FALSE = @CDROM_NONE_FALSE@
5.51 +CDROM_NONE_TRUE = @CDROM_NONE_TRUE@
5.52 +CDROM_OSX_FALSE = @CDROM_OSX_FALSE@
5.53 +CDROM_OSX_TRUE = @CDROM_OSX_TRUE@
5.54 CFLAGS = @CFLAGS@
5.55 CPP = @CPP@
5.56 CPPFLAGS = @CPPFLAGS@
5.57 @@ -393,7 +400,7 @@
5.58 $(am__append_4) $(am__append_5) $(am__append_6) \
5.59 $(am__append_7) $(am__append_8) $(am__append_9) \
5.60 $(am__append_10) $(am__append_11) $(am__append_12) \
5.61 - $(am__append_13) $(am__append_14)
5.62 + $(am__append_13) $(am__append_14) $(am__append_15)
5.63 @BUILD_SH4X86_TRUE@test_testsh4x86_LDADD = @GLIB_LIBS@ @GTK_LIBS@ @LIBPNG_LIBS@
5.64 @BUILD_SH4X86_TRUE@test_testsh4x86_SOURCES = test/testsh4x86.c x86dasm/x86dasm.c \
5.65 @BUILD_SH4X86_TRUE@ x86dasm/x86dasm.h x86dasm/i386-dis.c x86dasm/dis-init.c \
5.66 @@ -509,6 +516,7 @@
5.67 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/bootstrap.Po@am__quote@
5.68 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cd_linux.Po@am__quote@
5.69 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cd_none.Po@am__quote@
5.70 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cd_osx.Po@am__quote@
5.71 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cdi.Po@am__quote@
5.72 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_gd.Po@am__quote@
5.73 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cocoa_win.Po@am__quote@
5.74 @@ -1667,6 +1675,20 @@
5.75 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
5.76 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cd_linux.obj `if test -f 'drivers/cd_linux.c'; then $(CYGPATH_W) 'drivers/cd_linux.c'; else $(CYGPATH_W) '$(srcdir)/drivers/cd_linux.c'; fi`
5.77
5.78 +cd_osx.o: drivers/cd_osx.c
5.79 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cd_osx.o -MD -MP -MF "$(DEPDIR)/cd_osx.Tpo" -c -o cd_osx.o `test -f 'drivers/cd_osx.c' || echo '$(srcdir)/'`drivers/cd_osx.c; \
5.80 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cd_osx.Tpo" "$(DEPDIR)/cd_osx.Po"; else rm -f "$(DEPDIR)/cd_osx.Tpo"; exit 1; fi
5.81 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/cd_osx.c' object='cd_osx.o' libtool=no @AMDEPBACKSLASH@
5.82 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
5.83 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cd_osx.o `test -f 'drivers/cd_osx.c' || echo '$(srcdir)/'`drivers/cd_osx.c
5.84 +
5.85 +cd_osx.obj: drivers/cd_osx.c
5.86 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cd_osx.obj -MD -MP -MF "$(DEPDIR)/cd_osx.Tpo" -c -o cd_osx.obj `if test -f 'drivers/cd_osx.c'; then $(CYGPATH_W) 'drivers/cd_osx.c'; else $(CYGPATH_W) '$(srcdir)/drivers/cd_osx.c'; fi`; \
5.87 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cd_osx.Tpo" "$(DEPDIR)/cd_osx.Po"; else rm -f "$(DEPDIR)/cd_osx.Tpo"; exit 1; fi
5.88 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='drivers/cd_osx.c' object='cd_osx.obj' libtool=no @AMDEPBACKSLASH@
5.89 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
5.90 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -c -o cd_osx.obj `if test -f 'drivers/cd_osx.c'; then $(CYGPATH_W) 'drivers/cd_osx.c'; else $(CYGPATH_W) '$(srcdir)/drivers/cd_osx.c'; fi`
5.91 +
5.92 cd_none.o: drivers/cd_none.c
5.93 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT cd_none.o -MD -MP -MF "$(DEPDIR)/cd_none.Tpo" -c -o cd_none.o `test -f 'drivers/cd_none.c' || echo '$(srcdir)/'`drivers/cd_none.c; \
5.94 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/cd_none.Tpo" "$(DEPDIR)/cd_none.Po"; else rm -f "$(DEPDIR)/cd_none.Tpo"; exit 1; fi
6.1 --- a/src/drivers/cd_linux.c Wed Jun 25 10:39:05 2008 +0000
6.2 +++ b/src/drivers/cd_linux.c Wed Jun 25 10:40:45 2008 +0000
6.3 @@ -60,7 +60,7 @@
6.4
6.5 struct gdrom_image_class cdrom_device_class = { "Linux", NULL,
6.6 linux_image_is_valid, linux_open_device };
6.7 -GList *gdrom_get_native_devices(void)
6.8 +GList *cdrom_get_native_devices(void)
6.9 {
6.10 GList *list = NULL;
6.11 struct fstab *ent;
6.12 @@ -76,7 +76,7 @@
6.13 int caps = ioctl(fd, CDROM_GET_CAPABILITY);
6.14 if( caps != -1 ) {
6.15 /* Appears to support CDROM functions */
6.16 - list = g_list_append( list, g_strdup(ent->fs_spec) );
6.17 + list = g_list_append( list, gdrom_device_new(ent->fs_spec, ent->fs_spec));
6.18 }
6.19 close(fd);
6.20 }
6.21 @@ -84,6 +84,11 @@
6.22 return list;
6.23 }
6.24
6.25 +gdrom_disc_t cdrom_open_device( const gchar *method, const gchar *path )
6.26 +{
6.27 + return NULL;
6.28 +}
6.29 +
6.30 static gboolean linux_image_is_valid( FILE *f )
6.31 {
6.32 struct stat st;
7.1 --- a/src/drivers/cd_none.c Wed Jun 25 10:39:05 2008 +0000
7.2 +++ b/src/drivers/cd_none.c Wed Jun 25 10:40:45 2008 +0000
7.3 @@ -24,11 +24,18 @@
7.4 struct gdrom_image_class cdrom_device_class = { "None", NULL,
7.5 cdnone_image_is_valid, cdnone_open_device };
7.6
7.7 -GList *gdrom_get_native_devices(void)
7.8 +GList *cdrom_get_native_devices(void)
7.9 {
7.10 return NULL;
7.11 }
7.12
7.13 +gdrom_disc_t cdrom_open_device( const gchar *method, const gchar *path )
7.14 +{
7.15 + return NULL;
7.16 +}
7.17 +
7.18 +
7.19 +
7.20 static gboolean cdnone_image_is_valid( FILE *f )
7.21 {
7.22 return FALSE;
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
8.2 +++ b/src/drivers/cd_osx.c Wed Jun 25 10:40:45 2008 +0000
8.3 @@ -0,0 +1,218 @@
8.4 +/**
8.5 + * $Id$
8.6 + *
8.7 + * OSX native cd-rom driver.
8.8 + *
8.9 + * Copyright (c) 2005 Nathan Keynes.
8.10 + *
8.11 + * This program is free software; you can redistribute it and/or modify
8.12 + * it under the terms of the GNU General Public License as published by
8.13 + * the Free Software Foundation; either version 2 of the License, or
8.14 + * (at your option) any later version.
8.15 + *
8.16 + * This program is distributed in the hope that it will be useful,
8.17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
8.18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8.19 + * GNU General Public License for more details.
8.20 + */
8.21 +
8.22 +#include <IOKit/IOKitLib.h>
8.23 +#include <IOKit/storage/IOStorageDeviceCharacteristics.h>
8.24 +#include <IOKit/scsi-commands/SCSITaskLib.h>
8.25 +#include <IOKit/scsi-commands/SCSICommandOperationCodes.h>
8.26 +#include <stdio.h>
8.27 +#include "gdrom/gddriver.h"
8.28 +
8.29 +static gboolean osx_image_is_valid( FILE *f );
8.30 +static gdrom_disc_t osx_open_device( const gchar *filename, FILE *f );
8.31 +
8.32 +struct gdrom_image_class cdrom_device_class = { "osx", NULL,
8.33 + osx_image_is_valid, osx_open_device };
8.34 +
8.35 +typedef struct osx_cdrom_disc {
8.36 + struct gdrom_disc disc;
8.37 +
8.38 + io_object_t entry;
8.39 + MMCDeviceInterface **mmc;
8.40 + SCSITaskDeviceInterface **scsi;
8.41 +} *osx_cdrom_disc_t;
8.42 +
8.43 +/**
8.44 + * CD-ROM drive visitor. Returns FALSE to continue iterating, TRUE if the desired CD-ROM
8.45 + * has been found. In the latter case, the io_object is returned from find_cdrom_device
8.46 + * (and not freed)
8.47 + */
8.48 +typedef gboolean (*find_cdrom_callback_t)( io_object_t object, char *vendor, char *product,
8.49 + void *user_data );
8.50 +
8.51 +io_object_t find_cdrom_device( find_cdrom_callback_t callback, void *user_data )
8.52 +{
8.53 + mach_port_t master_port;
8.54 + CFMutableDictionaryRef match;
8.55 + io_iterator_t services;
8.56 + io_object_t object;
8.57 +
8.58 + if( IOMasterPort( MACH_PORT_NULL, &master_port ) != KERN_SUCCESS ) {
8.59 + return; // Failed to get the master port?
8.60 + }
8.61 +
8.62 + match = IOServiceMatching("IODVDServices");
8.63 + if( IOServiceGetMatchingServices(master_port, match, &services) != kIOReturnSuccess ) {
8.64 + return;
8.65 + }
8.66 +
8.67 + while( (object = IOIteratorNext(services)) != 0 ) {
8.68 + CFMutableDictionaryRef props = 0;
8.69 + if( IORegistryEntryCreateCFProperties(object, &props, kCFAllocatorDefault, kNilOptions) == KERN_SUCCESS ) {
8.70 + CFDictionaryRef dict =
8.71 + (CFDictionaryRef)CFDictionaryGetValue(props, CFSTR(kIOPropertyDeviceCharacteristicsKey));
8.72 + if( dict ) {
8.73 + /* The vendor name. */
8.74 + char vendor[256] = "", product[256] = "";
8.75 + CFTypeRef value = CFDictionaryGetValue(dict, CFSTR(kIOPropertyVendorNameKey));
8.76 + if( value && CFGetTypeID(value) == CFStringGetTypeID() ) {
8.77 + CFStringGetCString( (CFStringRef)value, vendor, sizeof(vendor),
8.78 + kCFStringEncodingUTF8 );
8.79 + }
8.80 + value = CFDictionaryGetValue(dict, CFSTR(kIOPropertyProductNameKey));
8.81 + if ( value && CFGetTypeID(value) == CFStringGetTypeID() ) {
8.82 + CFStringGetCString( (CFStringRef)value, product, sizeof(product),
8.83 + kCFStringEncodingUTF8 );
8.84 + }
8.85 + if( callback(object, vendor, product, user_data) ) {
8.86 + CFRelease(props);
8.87 + IOObjectRelease(services);
8.88 + return object;
8.89 + }
8.90 + }
8.91 + CFRelease(props);
8.92 + }
8.93 +
8.94 + IOObjectRelease(object);
8.95 + }
8.96 + IOObjectRelease(services);
8.97 +}
8.98 +
8.99 +io_object_t get_cdrom_by_service_path( const gchar *path )
8.100 +{
8.101 + mach_port_t master_port;
8.102 + io_object_t result;
8.103 +
8.104 + if( IOMasterPort( MACH_PORT_NULL, &master_port ) != KERN_SUCCESS ) {
8.105 + return MACH_PORT_NULL; // Failed to get the master port?
8.106 + }
8.107 +
8.108 + return IORegistryEntryFromPath( master_port, path );
8.109 +}
8.110 +
8.111 +void cdrom_osx_destroy( gdrom_disc_t disc )
8.112 +{
8.113 + osx_cdrom_disc_t cdrom = (osx_cdrom_disc_t)disc;
8.114 +
8.115 + if( cdrom->scsi != NULL ) {
8.116 + (*cdrom->scsi)->Release(cdrom->scsi);
8.117 + cdrom->scsi = NULL;
8.118 + }
8.119 + if( cdrom->mmc != NULL ) {
8.120 + (*cdrom->mmc)->Release(cdrom->mmc);
8.121 + cdrom->mmc = NULL;
8.122 + }
8.123 + if( cdrom->entry != MACH_PORT_NULL ) {
8.124 + IOObjectRelease( cdrom->entry );
8.125 + cdrom->entry = MACH_PORT_NULL;
8.126 + }
8.127 +
8.128 + if( disc->name != NULL ) {
8.129 + g_free( (gpointer)disc->name );
8.130 + disc->name = NULL;
8.131 + }
8.132 + g_free(disc);
8.133 +}
8.134 +
8.135 +gdrom_disc_t cdrom_osx_new( io_object_t obj )
8.136 +{
8.137 + osx_cdrom_disc_t cdrom = g_malloc0( sizeof(struct osx_cdrom_disc) );
8.138 + gdrom_disc_t disc = &cdrom->disc;
8.139 + IOCFPlugInInterface **pluginInterface = NULL;
8.140 + HRESULT herr;
8.141 + SInt32 score = 0;
8.142 +
8.143 + cdrom->entry = obj;
8.144 +
8.145 + if( IOCreatePlugInInterfaceForService( obj, kIOMMCDeviceUserClientTypeID,
8.146 + kIOCFPlugInInterfaceID, &pluginInterface, &score ) != KERN_SUCCESS ) {
8.147 + ERROR( "Failed to create plugin interface" );
8.148 + cdrom_osx_destroy(disc);
8.149 + return NULL;
8.150 + }
8.151 +
8.152 + herr = (*pluginInterface)->QueryInterface( pluginInterface,
8.153 + CFUUIDGetUUIDBytes( kIOMMCDeviceInterfaceID ), (LPVOID *)&cdrom->mmc );
8.154 + (*pluginInterface)->Release(pluginInterface);
8.155 + pluginInterface = NULL;
8.156 + if( herr != S_OK ) {
8.157 + ERROR( "Failed to create MMC interface" );
8.158 + cdrom_osx_destroy(disc);
8.159 + return NULL;
8.160 + }
8.161 +
8.162 + cdrom->scsi = (*cdrom->mmc)->GetSCSITaskDeviceInterface( cdrom->mmc );
8.163 + if( cdrom->scsi == NULL ) {
8.164 + ERROR( "Failed to create SCSI interface" );
8.165 + cdrom_osx_destroy(disc);
8.166 + return NULL;
8.167 + }
8.168 +
8.169 + char name[sizeof(io_string_t) + 6] = "dvd://";
8.170 + IORegistryEntryGetPath( cdrom->entry, kIOServicePlane, name+6 );
8.171 + disc->name = g_strdup(name);
8.172 +
8.173 + disc->close = cdrom_osx_destroy;
8.174 + return disc;
8.175 +}
8.176 +
8.177 +gboolean cdrom_enum_callback( io_object_t object, char *vendor, char *product, void *ptr )
8.178 +{
8.179 + GList **list = (GList **)ptr;
8.180 + char tmp1[sizeof(io_string_t) + 6] = "dvd://";
8.181 + char tmp2[512];
8.182 + IORegistryEntryGetPath( object, kIOServicePlane, tmp1+6 );
8.183 + snprintf( tmp2, sizeof(tmp2), "%s %s", vendor, product );
8.184 + *list = g_list_append( *list, gdrom_device_new( tmp1, tmp2 ) );
8.185 + return FALSE;
8.186 +}
8.187 +
8.188 +GList *cdrom_get_native_devices(void)
8.189 +{
8.190 + GList *list = NULL;
8.191 + find_cdrom_device(cdrom_enum_callback, &list);
8.192 + return list;
8.193 +}
8.194 +
8.195 +gdrom_disc_t cdrom_open_device( const gchar *method, const gchar *path )
8.196 +{
8.197 + io_object_t obj;
8.198 + gdrom_disc_t result = NULL;
8.199 +
8.200 + if( strncasecmp( path, "IOService:", 10 ) == 0 ) {
8.201 + obj = get_cdrom_by_service_path( path );
8.202 + }
8.203 +
8.204 + if( obj == MACH_PORT_NULL ) {
8.205 + return NULL;
8.206 + } else {
8.207 + return cdrom_osx_new( obj );
8.208 + }
8.209 +}
8.210 +
8.211 +
8.212 +
8.213 +static gboolean osx_image_is_valid( FILE *f )
8.214 +{
8.215 + return FALSE;
8.216 +}
8.217 +
8.218 +static gdrom_disc_t osx_open_device( const gchar *filename, FILE *f )
8.219 +{
8.220 + return NULL;
8.221 +}
9.1 --- a/src/gdlist.c Wed Jun 25 10:39:05 2008 +0000
9.2 +++ b/src/gdlist.c Wed Jun 25 10:40:45 2008 +0000
9.3 @@ -43,9 +43,9 @@
9.4 GList *ptr;
9.5
9.6 for( ptr = gdrom_device_list; ptr != NULL; ptr = g_list_next(ptr) ) {
9.7 - gchar *device = (gchar *)ptr->data;
9.8 + gdrom_device_t device = (gdrom_device_t)ptr->data;
9.9 posn++;
9.10 - if( strcmp(device, name) == 0 ) {
9.11 + if( strcmp(device->name, name) == 0 ) {
9.12 return posn;
9.13 }
9.14 }
9.15 @@ -148,7 +148,7 @@
9.16 {
9.17 const gchar *recent = lxdream_get_config_value( CONFIG_RECENT );
9.18 register_gdrom_disc_change_hook( gdrom_list_disc_changed, NULL );
9.19 - gdrom_device_list = gdrom_get_native_devices();
9.20 + gdrom_device_list = cdrom_get_native_devices();
9.21 if( recent != NULL ) {
9.22 gchar **list = g_strsplit(recent, ":", MAX_RECENT_ITEMS);
9.23 int i;
9.24 @@ -172,8 +172,8 @@
9.25 }
9.26
9.27 if( posn <= gdrom_device_count ) {
9.28 - gchar *entry = g_list_nth_data(gdrom_device_list, posn-1);
9.29 - return gdrom_mount_image(entry);
9.30 + gdrom_device_t device = g_list_nth_data(gdrom_device_list, posn-1);
9.31 + return gdrom_mount_image(device->name);
9.32 }
9.33
9.34 posn -= FIRST_RECENT_INDEX;
9.35 @@ -207,7 +207,8 @@
9.36 }
9.37
9.38 if( posn <= gdrom_device_count ) {
9.39 - return g_list_nth_data(gdrom_device_list, posn-1);
9.40 + gdrom_device_t device = g_list_nth_data(gdrom_device_list, posn-1);
9.41 + return device->device_name;
9.42 }
9.43
9.44 if( posn == gdrom_device_count + 1) {
9.45 @@ -229,7 +230,8 @@
9.46 }
9.47
9.48 if( posn <= gdrom_device_count ) {
9.49 - return g_list_nth_data(gdrom_device_list, posn-1);
9.50 + gdrom_device_t device = g_list_nth_data(gdrom_device_list, posn-1);
9.51 + return device->name;
9.52 }
9.53
9.54 if( posn == gdrom_device_count + 1) {
10.1 --- a/src/gdrom/gddriver.h Wed Jun 25 10:39:05 2008 +0000
10.2 +++ b/src/gdrom/gddriver.h Wed Jun 25 10:40:45 2008 +0000
10.3 @@ -28,6 +28,7 @@
10.4
10.5 #define MAX_SECTOR_SIZE 2352
10.6
10.7 +
10.8 struct gdrom_toc {
10.9 uint32_t track[99];
10.10 uint32_t first, last, leadout;
10.11 @@ -202,4 +203,8 @@
10.12 */
10.13 gchar *gdrom_get_relative_filename( const gchar *base_name, const gchar *find_name );
10.14
10.15 +gdrom_device_t gdrom_device_new( const gchar *name, const gchar *dev_name );
10.16 +
10.17 +void gdrom_device_destroy( gdrom_device_t dev );
10.18 +
10.19 #endif
11.1 --- a/src/gdrom/gdimage.c Wed Jun 25 10:39:05 2008 +0000
11.2 +++ b/src/gdrom/gdimage.c Wed Jun 25 10:40:45 2008 +0000
11.3 @@ -477,3 +477,24 @@
11.4 }
11.5 }
11.6
11.7 +gdrom_device_t gdrom_device_new( const gchar *name, const gchar *dev_name )
11.8 +{
11.9 + struct gdrom_device *dev = g_malloc0( sizeof(struct gdrom_device) );
11.10 + dev->name = g_strdup(name);
11.11 + dev->device_name = g_strdup(dev_name);
11.12 + return dev;
11.13 +}
11.14 +
11.15 +void gdrom_device_destroy( gdrom_device_t dev )
11.16 +{
11.17 + if( dev->name != NULL ) {
11.18 + g_free( dev->name );
11.19 + dev->name = NULL;
11.20 + }
11.21 + if( dev->device_name != NULL ) {
11.22 + g_free( dev->device_name );
11.23 + dev->device_name = NULL;
11.24 + }
11.25 + g_free( dev );
11.26 +}
11.27 +
11.28 \ No newline at end of file
12.1 --- a/src/gdrom/gdrom.c Wed Jun 25 10:39:05 2008 +0000
12.2 +++ b/src/gdrom/gdrom.c Wed Jun 25 10:40:45 2008 +0000
12.3 @@ -46,18 +46,40 @@
12.4 "Mode 2 semiraw", "XA Raw", "Non-XA Raw" };
12.5 uint32_t gdrom_sector_size[] = { 0, 2048, 2336, 2048, 2324, 2352, 2336, 2352, 2352 };
12.6
12.7 -gdrom_disc_t gdrom_image_open( const gchar *filename )
12.8 +gdrom_disc_t gdrom_image_open( const gchar *inFilename )
12.9 {
12.10 + const gchar *filename = inFilename;
12.11 const gchar *ext = strrchr(filename, '.');
12.12 gdrom_disc_t disc = NULL;
12.13 -
12.14 - int fd = open( filename, O_RDONLY | O_NONBLOCK );
12.15 + int fd;
12.16 FILE *f;
12.17 int i;
12.18 gdrom_image_class_t extclz = NULL;
12.19
12.20 + // Check for a url-style filename.
12.21 + char *lizard_lips = strstr( filename, "://" );
12.22 + if( lizard_lips != NULL ) {
12.23 + gchar *path = lizard_lips + 3;
12.24 + int method_len = (lizard_lips-filename);
12.25 + gchar method[method_len + 1];
12.26 + memcpy( method, filename, method_len );
12.27 + method[method_len] = '\0';
12.28 +
12.29 + if( strcasecmp( method, "file" ) == 0 ) {
12.30 + filename = path;
12.31 + } else if( strcasecmp( method, "dvd" ) == 0 ||
12.32 + strcasecmp( method, "cd" ) == 0 ||
12.33 + strcasecmp( method, "cdrom" ) ) {
12.34 + return cdrom_open_device( method, path );
12.35 + } else {
12.36 + ERROR( "Unrecognized URL method '%s' in filename '%s'", method, filename );
12.37 + return NULL;
12.38 + }
12.39 + }
12.40 +
12.41 + fd = open( filename, O_RDONLY | O_NONBLOCK );
12.42 if( fd == -1 ) {
12.43 - return NULL;
12.44 + return NULL;
12.45 }
12.46
12.47 f = fdopen(fd, "ro");
13.1 --- a/src/gdrom/gdrom.h Wed Jun 25 10:39:05 2008 +0000
13.2 +++ b/src/gdrom/gdrom.h Wed Jun 25 10:40:45 2008 +0000
13.3 @@ -26,6 +26,14 @@
13.4
13.5 typedef uint16_t gdrom_error_t;
13.6
13.7 +
13.8 +struct gdrom_device {
13.9 + char *name; // internal name
13.10 + char *device_name; // Human-readable device name
13.11 +};
13.12 +
13.13 +typedef struct gdrom_device *gdrom_device_t;
13.14 +
13.15 typedef struct gdrom_disc *gdrom_disc_t;
13.16
13.17 typedef gboolean (*gdrom_disc_change_hook_t)( gdrom_disc_t new_disc, const gchar *new_disc_name, void *user_data );
13.18 @@ -59,8 +67,6 @@
13.19
13.20 const gchar *gdrom_get_current_disc_name();
13.21
13.22 -GList *gdrom_get_native_devices();
13.23 -
13.24 uint32_t gdrom_read_sectors( uint32_t sector, uint32_t sector_count,
13.25 int mode, unsigned char *buf, uint32_t *length );
13.26
13.27 @@ -80,4 +86,26 @@
13.28
13.29 uint8_t gdrom_get_track_no_by_lba( uint32_t lba );
13.30
13.31 +
13.32 +/**
13.33 + * Native CD-ROM API - provided by drivers/cd_*.c
13.34 + *
13.35 + * A device name is either a system special file (most unixes) or a url of the
13.36 + * form dvd://<identifier> or cd://<identifier>, where <identifier> is a system
13.37 + * defined string that uniquely identifies a particular device.
13.38 + */
13.39 +
13.40 +/**
13.41 + * Return a list of gdrom_device_t defining all CD/DVD drives in the host system.
13.42 + */
13.43 +GList *cdrom_get_native_devices();
13.44 +
13.45 +/**
13.46 + * Open a native device given a device name and url method. Eg, for the url dvd://1
13.47 + * this function will be invoked with method = "dvd" and name = "1"
13.48 + *
13.49 + * @return NULL on failure, otherwise a valid gdrom_disc_t that can be mounted.
13.50 + */
13.51 +gdrom_disc_t cdrom_open_device( const gchar *method, const gchar *name );
13.52 +
13.53 #endif
.