Search
lxdream.org :: lxdream/src/gdrom/linux.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gdrom/linux.c
changeset 464:8e099fad42a6
prev422:61a0598e07ff
next468:3a49695e081a
author nkeynes
date Sat Oct 27 05:44:54 2007 +0000 (14 years ago)
permissions -rw-r--r--
last change Initial gdrom attachment menu
file annotate diff log raw
1.1 --- a/src/gdrom/linux.c Sat Oct 06 09:03:24 2007 +0000
1.2 +++ b/src/gdrom/linux.c Sat Oct 27 05:44:54 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: linux.c,v 1.5 2007-10-06 08:58:00 nkeynes Exp $
1.6 + * $Id: linux.c,v 1.6 2007-10-27 05:44:54 nkeynes Exp $
1.7 *
1.8 * Linux cd-rom device driver.
1.9 *
1.10 @@ -22,6 +22,8 @@
1.11 #include <linux/cdrom.h>
1.12 #include <sys/stat.h>
1.13 #include <sys/ioctl.h>
1.14 +#include <fstab.h>
1.15 +#include <fcntl.h>
1.16
1.17 #include "gdrom/gdrom.h"
1.18 #include "gdrom/packet.h"
1.19 @@ -57,6 +59,29 @@
1.20
1.21 struct gdrom_image_class linux_device_class = { "Linux", NULL,
1.22 linux_image_is_valid, linux_open_device };
1.23 +GList *gdrom_get_native_devices(void)
1.24 +{
1.25 + GList *list = NULL;
1.26 + struct fstab *ent;
1.27 + struct stat st;
1.28 + setfsent();
1.29 + while( (ent = getfsent()) != NULL ) {
1.30 + if( (stat(ent->fs_spec, &st) != -1) &&
1.31 + S_ISBLK(st.st_mode) ) {
1.32 + /* Got a valid block device - is it a CDROM? */
1.33 + int fd = open(ent->fs_spec, O_RDONLY|O_NONBLOCK);
1.34 + if( fd == -1 )
1.35 + continue;
1.36 + int caps = ioctl(fd, CDROM_GET_CAPABILITY);
1.37 + if( caps != -1 ) {
1.38 + /* Appears to support CDROM functions */
1.39 + list = g_list_append( list, g_strdup(ent->fs_spec) );
1.40 + }
1.41 + close(fd);
1.42 + }
1.43 + }
1.44 + return list;
1.45 +}
1.46
1.47 static gboolean linux_image_is_valid( FILE *f )
1.48 {
1.49 @@ -82,7 +107,7 @@
1.50 {
1.51 gdrom_disc_t disc;
1.52
1.53 - disc = gdrom_image_new(f);
1.54 + disc = gdrom_image_new(filename, f);
1.55 if( disc == NULL ) {
1.56 ERROR("Unable to allocate memory!");
1.57 return NULL;
1.58 @@ -186,6 +211,33 @@
1.59 return 0;
1.60 }
1.61
1.62 +static gdrom_error_t linux_play_audio( gdrom_disc_t disc, uint32_t lba, uint32_t endlba )
1.63 +{
1.64 + int fd = fileno( ((gdrom_image_t)disc)->file );
1.65 + uint32_t real_sector = lba - CD_MSF_OFFSET;
1.66 + uint32_t length = endlba - lba;
1.67 + uint32_t buflen = 0;
1.68 + char cmd[12] = { 0xA5, 0,0,0, 0,0,0,0, 0,0,0,0 };
1.69 + cmd[2] = (real_sector >> 24) & 0xFF;
1.70 + cmd[3] = (real_sector >> 16) & 0xFF;
1.71 + cmd[4] = (real_sector >> 8) & 0xFF;
1.72 + cmd[5] = real_sector & 0xFF;
1.73 + cmd[6] = (length >> 24) & 0xFF;
1.74 + cmd[7] = (length >> 16) & 0xFF;
1.75 + cmd[8] = (length >> 8) & 0xFF;
1.76 + cmd[9] = length & 0xFF;
1.77 +
1.78 + return linux_send_command( fd, cmd, NULL, &buflen, CGC_DATA_NONE );
1.79 +}
1.80 +
1.81 +static gdrom_error_t linux_stop_audio( gdrom_disc_t disc )
1.82 +{
1.83 + int fd = fileno( ((gdrom_image_t)disc)->file );
1.84 + uint32_t buflen = 0;
1.85 + char cmd[12] = {0x4E,0,0,0, 0,0,0,0, 0,0,0,0};
1.86 + return linux_send_command( fd, cmd, NULL, &buflen, CGC_DATA_NONE );
1.87 +}
1.88 +
1.89 static gdrom_error_t linux_read_sector( gdrom_disc_t disc, uint32_t sector,
1.90 int mode, unsigned char *buf, uint32_t *length )
1.91 {
.