PDA

View Full Version : Help required - SCSI Tape Erase Error



hemanth_hp
05-02-2007, 04:52 AM
Hi
I am issuing the scsi commands to the Tape device \\\\.\\Tape0 using SCSI_PASS_THROUGH interface but the DeviceIoControl() for Tape Erase is failing and returning the error code as 5 which is "Access is Denied" the code is here. Can you let me know is anything wrong in it?

memset(&stScsiCmd, 0, sizeof(stScsiCmd));
memset(bRqBuf, 0, sizeof(bRqBuf));
memset(bCdb, 0, sizeof(bCdb));

bCDB[0] = SCSIOP_ERASE; // Erase command 19h
bCDB[1] = bEraseType;

sptdwb.sptd.Length= sizeof(SCSI_PASS_THROUGH_DIRECT);
sptdwb.sptd.CdbLength= CDB6GENERIC_LENGTH;
sptdwb.sptd.DataIn= SCSI_IOCTL_DATA_UNSPECIFIED;
sptdwb.sptd.SenseInfoLength= sizeof(sptdwb.ucSenseBuf);
sptdwb.sptd.DataTransferLength= 0;
sptdwb.sptd.TimeOutValue= 5;
sptdwb.sptd.DataBuffer= NULL;
sptdwb.sptd.SenseInfoOffset=
offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
memcpy(sptdwb.sptd.Cdb, bCDB, CDB6GENERIC_LENGTH);

status = DeviceIoControl(hTapehandle,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&sptdwb,
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
&sptdwb,
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
&returned,
FALSE);

errCode = GetLastError();
//0 is for failure
if ((iResult == 0) || (stScsiCmd.sptd.ScsiStatus != 0))
{
return -1;
}

CougTek
05-02-2007, 11:09 PM
Sounds familiar? Me too.

http://www.storageforum.net/forum/showthread.php?t=6322

Hi
I am issuing the scsi commands to the Tape device \\\\.\\Tape0 using SCSI_PASS_THROUGH interface but the DeviceIoControl() is failing and returning the error code as 5 which is "Access is Denied" the code is here. Can you let me know is anything wrong in it?

memset(&stScsiCmd, 0, sizeof(stScsiCmd));
memset(bRqBuf, 0, sizeof(bRqBuf));
memset(bCdb, 0, sizeof(bCdb));

bCdb[0] = MTU_REWIND; // Rewind command 01h
bCdb[1] = IMMMODE; // Immed bit=0

stScsiCmd.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
stScsiCmd.sptd.CdbLength = CDB_GROUP0;
stScsiCmd.sptd.DataIn = SCSI_IOCTL_DATA_IN;
stScsiCmd.sptd.SenseInfoLength = sizeof(stScsiCmd.ucSenseBuf); //RQLEN;
stScsiCmd.sptd.DataTransferLength = sizeof(bRqBuf);
stScsiCmd.sptd.TimeOutValue = g_stDeviceData.uiScsiTimeOut;
stScsiCmd.sptd.DataBuffer = bRqBuf;
stScsiCmd.sptd.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
memcpy(stScsiCmd.sptd.Cdb, bCdb, CDB_GROUP0);

//length = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER);

iResult = DeviceIoControl(hDevHndl,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&stScsiCmd,
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
&stScsiCmd,
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
&returned,
FALSE);

errCode = GetLastError();
//0 is for failure
if ((iResult == 0) || (stScsiCmd.sptd.ScsiStatus != 0))
{
return -1;
}

hemanth_hp
05-09-2007, 02:22 AM
Its giving an Error Code as 1117 representing "The request could not be performed because of an I/O device error". But i am able to execute the SCSI commands like read, write, rewind and so on. Have anyone faced the problem if so Please let me know the solution for the same.

I am opening the device handle with

hTapehandle = CreateFile( TEXT("\\\\.\\Tape0"), // tape dev to open
GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE,// read/write access
NULL,
OPEN_EXISTING, // req for tape devs
0,
NULL
);

Can anyone help me out?

MaxBurn
05-09-2007, 10:02 AM
This stuff is so far over my head I am laughing.

timwhit
05-09-2007, 10:19 AM
Is that C++ or Java or something else entirely? What kind of device is it? Manufacturer? Model #?

I don't know how anyone is supposed to respond without knowing more details.

LiamC
05-09-2007, 08:25 PM
More info please.

OS? Appears to be Windows. Which version?
"Access denied." Is it being run as an administrator? Program/group level access?
Appears to be C++. Vendor? Version? Patch level?
Calling the API directly? Why?
File or device in use?
Same error on another machine?

hemanth_hp
05-10-2007, 06:30 AM
OS - Win2k
Device - Tape Device HP C1537A Scsi Sequential Device

This is SCSI programmming.

This is purely C code with Windows APIs. The code uses SPTI interface for communication with the Scsi Devices. this interface uses Tape Class driver i.e Tape.sys supplied by MS.

The code is an small scsi application firing the scsi commands using the deviceIoControl API of windows.

Any ways found the solution.

I found the solution for the same. I just changed the structure to SCSI_PASS_THROUGH instead of SCSI_PASS_THROUGH_DIRECT.

I even changed the data direction flags to SCSI_IOCTL_DATA_IN and timeout value to 10.

It executed Successfully. The code is here as follows:

int GetScsiErase_SPT(HANDLE hTapehandle, BYTE bEraseType)
{
printf(" ***** ERASE - SCSI_PASS_THROUGH *****\n");

ZeroMemory(&sptwb,sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS));
ZeroMemory(&bCDB,sizeof(bCDB));

bCDB[0] = SCSIOP_ERASE; // Erase command 11h
bCDB[1] = bEraseType; // Erase Type Short(0) or Long(1)

sptwb.spt.Length = sizeof(sptwb.spt);
sptwb.spt.CdbLength = CDB6GENERIC_LENGTH;
sptwb.spt.DataIn = SCSI_IOCTL_DATA_IN;
sptwb.spt.SenseInfoLength = sizeof(sptwb.ucSenseBuf);
sptwb.spt.DataTransferLength = 0;
sptwb.spt.SenseInfoOffset = offsetof(SCSI_PASS_THROUGH_WITH_BUFFERS, ucSenseBuf);
sptwb.spt.DataBufferOffset = 0;
sptwb.spt.TimeOutValue = 10;
memcpy(sptwb.spt.Cdb, bCDB, CDB6GENERIC_LENGTH);

status = DeviceIoControl(hTapehandle,
IOCTL_SCSI_PASS_THROUGH,
&sptwb,
sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS),
&sptwb,
sizeof(SCSI_PASS_THROUGH_WITH_BUFFERS),
&returned,
FALSE);

if (!status)
{
printf( "Error Erase information; error was %d\n",
errorCode = GetLastError());
PrintError(errorCode);
printf("Scsi Status = %d",sptwb.spt.ScsiStatus);
return 0;
}

if ((sptwb.spt.ScsiStatus == 0) && (status != 0))
PrintDataBuffer((char *)sptwb.ucDataBuf,sptwb.spt.DataTransferLength);
else
PrintDataBuffer((char *)sptwb.ucSenseBuf,sptwb.spt.SenseInfoLength);

printf( "Scsi Status : %d\n\n",sptwb.spt.ScsiStatus);

return 1;
}

But i am not understanding what could be the reason for failing when SCSI_PASS_THROUGH_DIRECT structure is used.

Can anyone specify the techical reason for the same.

Chewy509
05-10-2007, 06:30 PM
But i am not understanding what could be the reason for failing when SCSI_PASS_THROUGH_DIRECT structure is used.

Can anyone specify the techical reason for the same.

Easy, get a MSDN subscription (if you already don't) and ask MS themselves.

Anyone here (unless someone here works secretly for MS, and write SCSI drivers all day), will only be able to speculate on the actual reason...