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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
$NetBSD: patch-af,v 1.1.1.1 2006/02/01 00:53:00 markd Exp $
--- /dev/null 2006-01-31 00:47:43.000000000 +1300
+++ libk3bdevice/k3bscsicommand_netbsd.cpp 2006-01-31 00:08:25.000000000 +1300
@@ -0,0 +1,136 @@
+/*
+ *
+ */
+
+#include "k3bscsicommand.h"
+#include "k3bdevice.h"
+
+#include <kdebug.h>
+
+#include <sys/ioctl.h>
+#include <sys/scsiio.h>
+#include <sys/cdio.h>
+#include <sys/dkio.h>
+
+#include <unistd.h>
+#include <sys/types.h>
+
+
+class K3bDevice::ScsiCommand::Private
+{
+public:
+ struct scsireq cmd;
+};
+
+
+void K3bDevice::ScsiCommand::clear()
+{
+ ::memset( &d->cmd, 0, sizeof(struct scsireq ) );
+}
+
+
+unsigned char& K3bDevice::ScsiCommand::operator[]( size_t i )
+{
+ return d->cmd.cmd[i];
+}
+
+
+int K3bDevice::ScsiCommand::transport( TransportDirection dir,
+ void* data,
+ size_t len )
+{
+ bool needToClose = false;
+ if( m_device ) {
+ if( !m_device->isOpen() ) {
+ needToClose = true;
+ }
+ m_device->open( dir == TR_DIR_WRITE );
+ m_deviceHandle = m_device->handle();
+ }
+
+ if( m_deviceHandle == -1 )
+ return -1;
+
+ d->cmd.cmdlen = 12;
+ d->cmd.timeout = 10000;
+ d->cmd.databuf = (caddr_t) data;
+ d->cmd.datalen = len;
+ // d->cmd.datalen_used = len;
+ d->cmd.senselen = SENSEBUFLEN;
+ switch (dir)
+ {
+ case TR_DIR_READ:
+ d->cmd.flags = SCCMD_READ;
+ break;
+ case TR_DIR_WRITE:
+ d->cmd.flags = SCCMD_WRITE;
+ break;
+ default:
+ d->cmd.flags = SCCMD_READ;
+ break;
+ }
+
+ int i = ::ioctl( m_deviceHandle, SCIOCCOMMAND, &d->cmd );
+
+ if( needToClose )
+ m_device->close();
+
+ if( i || (d->cmd.retsts != SCCMD_OK)) {
+ debugError( d->cmd.cmd[0],
+ d->cmd.retsts,
+ d->cmd.sense[2],
+ d->cmd.sense[12],
+ d->cmd.sense[13] );
+
+ return 1;
+ }
+ else
+ return 0;
+}
+
+bool K3bDevice::ScsiCommand::eject ( bool open )
+{
+ unsigned long request = open ? DIOCEJECT : CDIOCCLOSE;
+ int arg = 0;
+ bool needToClose = false;
+ if( m_device ) {
+ if( !m_device->isOpen() ) {
+ needToClose = true;
+ }
+ m_device->open( false );
+ m_deviceHandle = m_device->handle();
+ }
+
+ if( m_deviceHandle == -1 )
+ return false;
+
+ int i = ::ioctl( m_deviceHandle, request, &arg );
+
+ if( needToClose )
+ m_device->close();
+
+ return i >= 0;
+}
+
+bool K3bDevice::ScsiCommand::traylock ( bool on )
+{
+ int arg = on ? 1 : 0;
+ bool needToClose = false;
+ if( m_device ) {
+ if( !m_device->isOpen() ) {
+ needToClose = true;
+ }
+ m_device->open( false );
+ m_deviceHandle = m_device->handle();
+ }
+
+ if( m_deviceHandle == -1 )
+ return false;
+
+ int i = ::ioctl( m_deviceHandle, DIOCLOCK, &arg );
+
+ if( needToClose )
+ m_device->close();
+
+ return i >= 0;
+}
|