blob: bd09e7a179070c614f4e488d4e542e11e75112e1 (
plain)
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
|
/*
*
* $Id: sourceheader 511311 2006-02-19 14:51:05Z trueg $
* Copyright (C) 2006 Mark Davies <mark@mcs.vuw.ac.nz>
*
* This file is part of the K3b project.
* Copyright (C) 1998-2007 Sebastian Trueg <trueg@k3b.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* See the file "COPYING" for the exact licensing terms.
*/
#include "k3bscsicommand.h"
#include "k3bdevice.h"
#include <k3bdebug.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 )
{
if( d->cmd.cmdlen < i+1 )
d->cmd.cmdlen = i+1;
return d->cmd.cmd[i];
}
int K3bDevice::ScsiCommand::transport( TransportDirection dir,
void* data,
size_t len )
{
bool needToClose = false;
if( m_device ) {
m_device->usageLock();
if( !m_device->isOpen() ) {
needToClose = true;
}
m_device->open( dir == TR_DIR_WRITE );
m_deviceHandle = m_device->handle();
}
if( m_deviceHandle == -1 ) {
if ( m_device ) {
m_device->usageUnlock();
}
return -1;
}
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 ( m_device ) {
if( needToClose )
m_device->close();
m_device->usageUnlock();
}
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;
}
|