Commit d373c1a1 authored by Alexandre Julliard's avatar Alexandre Julliard

wnaspi32: Remove Linux-specific SCSI ioctls.

This has been broken at least since 19549d11. Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent bf8b185b
...@@ -36,17 +36,6 @@ ...@@ -36,17 +36,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include <sys/types.h> #include <sys/types.h>
#ifdef HAVE_SYS_IOCTL_H
#include <sys/ioctl.h>
#endif
#include <fcntl.h>
#ifdef HAVE_DIRENT_H
# include <dirent.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <errno.h>
#include <string.h> #include <string.h>
#include "windef.h" #include "windef.h"
...@@ -60,61 +49,6 @@ ...@@ -60,61 +49,6 @@
WINE_DEFAULT_DEBUG_CHANNEL(aspi); WINE_DEFAULT_DEBUG_CHANNEL(aspi);
#ifdef linux
static void set_last_error(void)
{
int save_errno = errno; /* errno gets overwritten by printf */
switch (errno)
{
case EAGAIN:
SetLastError( ERROR_SHARING_VIOLATION );
break;
case EBADF:
SetLastError( ERROR_INVALID_HANDLE );
break;
case ENOSPC:
SetLastError( ERROR_HANDLE_DISK_FULL );
break;
case EACCES:
case EPERM:
case EROFS:
SetLastError( ERROR_ACCESS_DENIED );
break;
case EBUSY:
SetLastError( ERROR_LOCK_VIOLATION );
break;
case ENOENT:
SetLastError( ERROR_FILE_NOT_FOUND );
break;
case EISDIR:
SetLastError( ERROR_CANNOT_MAKE );
break;
case ENFILE:
case EMFILE:
SetLastError( ERROR_NO_MORE_FILES );
break;
case EEXIST:
SetLastError( ERROR_FILE_EXISTS );
break;
case EINVAL:
case ESPIPE:
SetLastError( ERROR_SEEK );
break;
case ENOTEMPTY:
SetLastError( ERROR_DIR_NOT_EMPTY );
break;
case ENOEXEC:
SetLastError( ERROR_BAD_FORMAT );
break;
default:
WARN( "unknown file error: %s\n", strerror(save_errno) );
SetLastError( ERROR_GEN_FAILURE );
break;
}
errno = save_errno;
}
#endif
static const WCHAR wDevicemapScsi[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0}; static const WCHAR wDevicemapScsi[] = {'H','A','R','D','W','A','R','E','\\','D','E','V','I','C','E','M','A','P','\\','S','c','s','i',0};
/* Exported functions */ /* Exported functions */
...@@ -148,31 +82,6 @@ int ASPI_GetNumControllers(void) ...@@ -148,31 +82,6 @@ int ASPI_GetNumControllers(void)
return num_ha; return num_ha;
} }
static BOOL SCSI_GetDeviceName( int h, int c, int t, int d, LPSTR devstr, LPDWORD lpcbData )
{
char buffer[200];
HKEY hkeyScsi;
DWORD type;
snprintf(buffer, sizeof(buffer), KEYNAME_SCSI, h, c, t, d);
if( RegOpenKeyExA(HKEY_LOCAL_MACHINE, buffer, 0, KEY_ALL_ACCESS, &hkeyScsi ) != ERROR_SUCCESS )
{
TRACE("Could not open HKLM\\%s; device does not exist\n", buffer);
return FALSE;
}
if( RegQueryValueExA(hkeyScsi, "UnixDeviceName", NULL, &type, (LPBYTE)devstr, lpcbData) != ERROR_SUCCESS )
{
WARN("Could not query value HKLM\\%s\\UnixDeviceName\n", buffer);
RegCloseKey(hkeyScsi);
return FALSE;
}
RegCloseKey(hkeyScsi);
TRACE("Device name: %s\n", devstr);
return TRUE;
}
/* SCSI_GetHCforController /* SCSI_GetHCforController
* RETURNS * RETURNS
* HIWORD: Host Adapter * HIWORD: Host Adapter
...@@ -225,135 +134,3 @@ DWORD ASPI_GetHCforController( int controller ) ...@@ -225,135 +134,3 @@ DWORD ASPI_GetHCforController( int controller )
return (atoiW(&wPortName[9]) << 16) + atoiW(&wBusName[9]); return (atoiW(&wPortName[9]) << 16) + atoiW(&wBusName[9]);
} }
int SCSI_OpenDevice( int h, int c, int t, int d )
{
char devstr[20];
DWORD cbData = 20;
int fd = -1;
if(!SCSI_GetDeviceName( h, c, t, d, devstr, &cbData ))
{
WARN("Could not get device name for h%02dc%02dt%02dd%02d\n", h, c, t, d);
return -1;
}
TRACE("Opening device %s mode O_RDWR\n",devstr);
fd = open(devstr, O_RDWR);
if (fd == -1) {
char *errstring = strerror(errno);
ERR("Failed to open device %s: %s\n", devstr, errstring);
}
return fd;
}
#ifdef linux
/* SCSI_Fix_CMD_LEN
* Checks to make sure the CMD_LEN is correct
*/
void
SCSI_Fix_CMD_LEN(int fd, int cmd, int len)
{
/* This is what the linux kernel thinks.... */
static const unsigned char scsi_command_size[8] =
{
6, 10, 10, 12,
12, 12, 10, 10
};
int index=(cmd>>5)&7;
if (len!=scsi_command_size[index])
{
TRACE("CDBLen for command %d claims to be %d, expected %d\n",
cmd, len, scsi_command_size[index]);
ioctl(fd,SG_NEXT_CMD_LEN,&len);
}
}
int
SCSI_LinuxSetTimeout( int fd, int timeout )
{
int retval;
TRACE("Setting timeout to %d jiffies\n", timeout);
retval=ioctl(fd,SG_SET_TIMEOUT,&timeout);
if(retval)
{
WARN("Could not set timeout ! (%s)\n", strerror(errno));
}
return retval;
}
/* This function takes care of the write/read to the linux sg device.
* It returns TRUE or FALSE and uses set_last_error() to convert
* UNIX errno to Windows GetLastError(). The reason for that is that
* several programs will check that error and we might as well set
* it here. We also return the value of the read call in
* lpcbBytesReturned.
*/
BOOL /* NOTE: This function SHOULD BLOCK */
SCSI_LinuxDeviceIo( int fd,
struct sg_header * lpInBuffer, DWORD cbInBuffer,
struct sg_header * lpOutBuffer, DWORD cbOutBuffer,
LPDWORD lpcbBytesReturned )
{
DWORD dwBytes;
DWORD save_error;
TRACE("Writing to Linux sg device\n");
dwBytes = write( fd, lpInBuffer, cbInBuffer );
if( dwBytes != cbInBuffer )
{
set_last_error();
save_error = GetLastError();
WARN("Not enough bytes written to scsi device. bytes=%d .. %d\n", cbInBuffer, dwBytes );
/* FIXME: set_last_error() never sets error to ERROR_NOT_ENOUGH_MEMORY... */
if( save_error == ERROR_NOT_ENOUGH_MEMORY )
MESSAGE("Your Linux kernel was not able to handle the amount of data sent to the scsi device. Try recompiling with a larger SG_BIG_BUFF value (kernel 2.0.x sg.h)\n");
WARN("error= %d\n", save_error );
*lpcbBytesReturned = 0;
return FALSE;
}
TRACE("Reading reply from Linux sg device\n");
*lpcbBytesReturned = read( fd, lpOutBuffer, cbOutBuffer );
if( *lpcbBytesReturned != cbOutBuffer )
{
set_last_error();
save_error = GetLastError();
WARN("Not enough bytes read from scsi device. bytes=%d .. %d\n", cbOutBuffer, *lpcbBytesReturned);
WARN("error= %d\n", save_error );
return FALSE;
}
return TRUE;
}
static void SCSI_Linux_CheckDevices(void)
{
DIR *devdir;
struct dirent *dent = NULL;
devdir = opendir("/dev");
for (dent=readdir(devdir);dent;dent=readdir(devdir))
{
if (!(strncmp(dent->d_name, "sg", 2)))
break;
}
closedir(devdir);
if (dent == NULL)
{
TRACE("WARNING: You don't have any /dev/sgX generic scsi devices ! \"man MAKEDEV\" !\n");
return;
}
}
#endif
void SCSI_Init(void)
{
#ifdef linux
SCSI_Linux_CheckDevices();
#endif
}
...@@ -19,106 +19,10 @@ ...@@ -19,106 +19,10 @@
#ifndef __WINESCSI_H__ #ifndef __WINESCSI_H__
#define __WINESCSI_H__ #define __WINESCSI_H__
#ifdef linux
/* Copy of info from 2.2.x kernel */
#define SG_MAX_SENSE 16 /* too little, unlikely to change in 2.2.x */
#define SG_NEXT_CMD_LEN 0x2283 /* override SCSI command length with given
number on the next write() on this file descriptor */
struct sg_header
{
int pack_len; /* [o] reply_len (ie useless), ignored as input */
int reply_len; /* [i] max length of expected reply (inc. sg_header) */
int pack_id; /* [io] id number of packet (use ints >= 0) */
int result; /* [o] 0==ok, else (+ve) Unix errno (best ignored) */
unsigned int twelve_byte:1;
/* [i] Force 12 byte command length for group 6 & 7 commands */
unsigned int target_status:5; /* [o] scsi status from target */
unsigned int host_status:8; /* [o] host status (see "DID" codes) */
unsigned int driver_status:8; /* [o] driver status+suggestion */
unsigned int other_flags:10; /* unused */
unsigned char sense_buffer[SG_MAX_SENSE]; /* [o] Output in 3 cases:
when target_status is CHECK_CONDITION or
when target_status is COMMAND_TERMINATED or
when (driver_status & DRIVER_SENSE) is true. */
}; /* This structure is 36 bytes long on i386 */
#define SCSI_OFF sizeof(struct sg_header)
#define SG_SET_TIMEOUT 0x2201
#define SG_GET_TIMEOUT 0x2202
#define SCSI_DEFAULT_TIMEOUT 6000*5 /* 5 minutes */
#endif
/* RegKey used for SCSI info under HKLM */
#define KEYNAME_SCSI "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d"
/* Function prototypes from dlls/wnaspi32/aspi.c */
void
SCSI_Init(void) DECLSPEC_HIDDEN;
int int
ASPI_GetNumControllers(void) DECLSPEC_HIDDEN; ASPI_GetNumControllers(void) DECLSPEC_HIDDEN;
int
SCSI_OpenDevice( int h, int c, int t, int d ) DECLSPEC_HIDDEN;
int
SCSI_LinuxSetTimeout( int fd, int timeout ) DECLSPEC_HIDDEN;
#ifdef linux
BOOL
SCSI_LinuxDeviceIo( int fd,
struct sg_header * lpvInBuffer, DWORD cbInBuffer,
struct sg_header * lpvOutBuffer, DWORD cbOutBuffer,
LPDWORD lpcbBytesReturned ) DECLSPEC_HIDDEN;
void
SCSI_Fix_CMD_LEN( int fd, int cmd, int len ) DECLSPEC_HIDDEN;
#endif
DWORD DWORD
ASPI_GetHCforController( int controller ) DECLSPEC_HIDDEN; ASPI_GetHCforController( int controller ) DECLSPEC_HIDDEN;
/*** This is where we throw some miscellaneous crap ***/
#define ASPI_POSTING(prb) (prb->SRB_Flags & 0x1)
/* WNASPI32/WINASPI defs */
#define HOST_TO_TARGET(prb) (((prb->SRB_Flags>>3) & 0x3) == 0x2)
#define TARGET_TO_HOST(prb) (((prb->SRB_Flags>>3) & 0x3) == 0x1)
#define NO_DATA_TRANSFERRED(prb) (((prb->SRB_Flags>>3) & 0x3) == 0x3)
#define INQUIRY_VENDOR 8
#define MUSTEK_SCSI_AREA_AND_WINDOWS 0x04
#define MUSTEK_SCSI_READ_SCANNED_DATA 0x08
#define MUSTEK_SCSI_GET_IMAGE_STATUS 0x0f
#define MUSTEK_SCSI_ADF_AND_BACKTRACE 0x10
#define MUSTEK_SCSI_CCD_DISTANCE 0x11
#define MUSTEK_SCSI_START_STOP 0x1b
#define INQURIY_CMDLEN 6
#define INQURIY_REPLY_LEN 96
#define INQUIRY_VENDOR 8
#define SENSE_BUFFER(prb) (&prb->CDBByte[prb->SRB_CDBLen])
/* Just a container for seeing what devices are open */
struct ASPI_DEVICE_INFO {
struct ASPI_DEVICE_INFO * next;
int fd;
int hostId;
int target;
int lun;
};
typedef struct ASPI_DEVICE_INFO ASPI_DEVICE_INFO;
/*** End Miscellaneous crap ***/
#endif /* #ifndef __WINESCSI_H */ #endif /* #ifndef __WINESCSI_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment