-
Notifications
You must be signed in to change notification settings - Fork 342
/
mythcdrom-darwin.cpp
61 lines (50 loc) · 1.7 KB
/
mythcdrom-darwin.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <errno.h>
#include <sys/fcntl.h>
#include <unistd.h> // for close definition
#include <IOKit/storage/IOCDMediaBSDClient.h>
#include <IOKit/storage/IODVDMediaBSDClient.h>
#include "mythcdrom.h"
#include "mythcdrom-darwin.h"
#include "mythverbose.h"
#define LOC QString("MythCDROMDarwin:")
#define LOC_ERR QString("mythcdrom-darwin, Error: ")
class MythCDROMDarwin: public MythCDROM
{
public:
MythCDROMDarwin(QObject* par, const char* DevicePath,
bool SuperMount, bool AllowEject):
MythCDROM(par, DevicePath, SuperMount, AllowEject) {};
virtual void setSpeed(int speed);
virtual void setSpeed(const char *device, int speed);
};
MythCDROM *GetMythCDROMDarwin(QObject* par, const char* devicePath,
bool SuperMount, bool AllowEject)
{
return new MythCDROMDarwin(par, devicePath, SuperMount, AllowEject);
}
void MythCDROMDarwin::setSpeed(int speed)
{
MythCDROMDarwin::setSpeed(m_DevicePath.toLocal8Bit().constData(), speed);
}
void MythCDROMDarwin::setSpeed(const char *device, int speed)
{
int fd;
QString raw = "/dev/r"; raw += device;
uint16_t spd = speed;
fd = open(raw.toLocal8Bit().constData(), O_RDONLY | O_NONBLOCK);
if (fd == -1)
{
VERBOSE(VB_MEDIA, LOC_ERR + "setSpeed() can't open drive " + raw);
return;
}
if (ioctl(fd, DKIOCCDSETSPEED, &spd) == -1 &&
ioctl(fd, DKIOCDVDSETSPEED, &spd) == -1)
{
VERBOSE(VB_MEDIA, (LOC_ERR + "setSpeed() failed: ") + strerror(errno));
close(fd);
return;
}
VERBOSE(VB_MEDIA, LOC + ":setSpeed() - CD/DVD Speed Set to "
+ QString::number(spd));
close(fd);
}