00001 #include <errno.h>
00002 #include <sys/fcntl.h>
00003 #include <unistd.h>
00004
00005 #include <IOKit/storage/IOCDMediaBSDClient.h>
00006 #include <IOKit/storage/IODVDMediaBSDClient.h>
00007
00008 #include "mythcdrom.h"
00009 #include "mythcdrom-darwin.h"
00010 #include "mythlogging.h"
00011
00012 #define LOC QString("MythCDROMDarwin:")
00013
00014 class MythCDROMDarwin: public MythCDROM
00015 {
00016 public:
00017 MythCDROMDarwin(QObject* par, const char* DevicePath,
00018 bool SuperMount, bool AllowEject):
00019 MythCDROM(par, DevicePath, SuperMount, AllowEject) {};
00020
00021 virtual void setSpeed(int speed);
00022 virtual void setSpeed(const char *device, int speed);
00023 };
00024
00025 MythCDROM *GetMythCDROMDarwin(QObject* par, const char* devicePath,
00026 bool SuperMount, bool AllowEject)
00027 {
00028 return new MythCDROMDarwin(par, devicePath, SuperMount, AllowEject);
00029 }
00030
00031 void MythCDROMDarwin::setSpeed(int speed)
00032 {
00033 MythCDROMDarwin::setSpeed(m_DevicePath.toLocal8Bit().constData(), speed);
00034 }
00035
00036 void MythCDROMDarwin::setSpeed(const char *device, int speed)
00037 {
00038 int fd;
00039 QString raw = device;
00040 uint16_t spd = speed;
00041
00042
00043 fd = open(raw.toLocal8Bit().constData(), O_RDONLY | O_NONBLOCK);
00044 if (fd == -1)
00045 {
00046 LOG(VB_MEDIA, LOG_ERR, LOC + "setSpeed() can't open drive " + raw);
00047 return;
00048 }
00049
00050 if (ioctl(fd, DKIOCCDSETSPEED, &spd) == -1 &&
00051 ioctl(fd, DKIOCDVDSETSPEED, &spd) == -1)
00052 {
00053 LOG(VB_MEDIA, LOG_ERR, LOC + "setSpeed() failed: " + ENO);
00054 close(fd);
00055 return;
00056 }
00057 LOG(VB_MEDIA, LOG_INFO, LOC + ":setSpeed() - CD/DVD speed now " +
00058 QString::number(spd));
00059 close(fd);
00060 }