Note that the “MaximumTransferLength” (16MB) problably is not be
achievable since MaximumPhysicalPages would limit you to 516KB (129
pages) if all pages were discontiguous. Also, are you going to a real
SCSI device, or is this ATA. If ATA, I’m surprised the AlignmentMask is
not a “1”, and you may want to treat it as such just to play it safe.
-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Rajendrakumar
Sent: Friday, December 10, 2004 4:49 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] SCSI_PASS_THROUGH_DIRECT Invalid Access To Memeory
Here is detail information I get from IO_SCSI_CAPABILITIES
AlignmentMask = 0
MaximumTransferLength = 0x00FFFFFF
MaximumPhysicalPages = 0x00000081
Here is code fragment
PUCHAR
AllocateAlignedBuffer(ULONG size, ULONG Align)
{
PUCHAR ptr;
UINT_PTR Align64 = (UINT_PTR)Align;
fprintf(stderr,“Allignement = %d”, Align) ;
if (!Align) {
ptr = (PUCHAR)malloc(size);
}
else {
ptr = (PUCHAR)malloc(size + Align);
ptr = (PUCHAR)(((UINT_PTR)ptr + Align64) & ~Align64);
}
return ptr ;
}
int main() {
…
…
…
/*
Some Part of Main Function…
*/
dataBuffer = AllocateAlignedBuffer(sectorSize,
capabilities.AlignmentMask);
if (dataBuffer == NULL) {
fprintf(stderr,“\n Can not allocate AlignedBuffer\n”) ;
return TR_ERROR ;
}
memcpy(dataBuffer,sectorSize) ;
ZeroMemory(&scsiCmd,sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER));
scsiCmd.sptd.Length = sizeof(SCSI_PASS_THROUGH_DIRECT);
scsiCmd.sptd.PathId = m_Handle.PathID;
scsiCmd.sptd.TargetId = m_Handle.Target ;
scsiCmd.sptd.Lun = m_Handle.Lun ;
scsiCmd.sptd.CdbLength = m_scsiCmdBuffer.SRB_CDBLen;
scsiCmd.sptd.SenseInfoLength = m_scsiCmdBuffer.SRB_SenseLen ;
scsiCmd.sptd.DataIn = m_scsiCmdBuffer.SRB_Flags;
scsiCmd.sptd.DataTransferLength = m_scsiCmdBuffer.SRB_BufLen ;
scsiCmd.sptd.TimeOutValue = USCSI_TIMEOUT ;
scsiCmd.sptd.DataBuffer = dataBuffer ;
scsiCmd.sptd.SenseInfoOffset =
offsetof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER,ucSenseBuf) ;
if (m_scsiCmdBuffer.SRB_BufLen <
sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER))
length = sizeof(SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER) ;
else
length = m_scsiCmdBuffer.SRB_BufLen ;
iRetVal = DeviceIoControl(m_Handle.Handle,
IOCTL_SCSI_PASS_THROUGH_DIRECT,
&scsiCmd,
length ,
&scsiCmd,
length,
&returned,
FALSE);
…
…
…
} //main Ends
Now I am not able to understand why it is failing sometimes with
“Invalid
Access To Memory Location”…
How do I ensure that memory I am allocating is aligned properly and is
continuous if require.
Any suggestions form anybody?
Thanks in advance.
-Kumsi.
You must pay attention to all of AlignmentMask, MaximumTransferLength,
and MaximumPhysicalPages of either STORAGE_ADAPTER_DESCRIPTOR or
IO_SCSI_CAPABILITIES.
Chuck
----- Original Message -----
From: “Rajendrakumar”
To: “Windows System Software Devs Interest List”
Sent: Friday, December 10, 2004 4:51 PM
Subject: [ntdev] SCSI_PASS_THROUGH_DIRECT Invalid Access To Memeory
> Hi All,
>
> I’m using an IOCTL_SCSI_PASS_THROUGH_DIRECT in user mode, and
> sometimes
> DeviceIoControl call is failing with “Invalid Access To Memeory”. I
> am
> allocating 64K databuffer using “malloc”. At first I thought the
> device
> might
> require certain alignment restrictions, but I queried the device’s bus
> adapter which had an AlignmentMask of
> 0, which the documentation indicates as meaning byte alignment is
> sufficient. I guess there is some issue with byte alignment of
> DataBuffer.
>
> I am trying this stuff on Windows 2003 Server.
>
> Can anybody suggest me way out?
>
> Thanks and regards,
> Kumsi.
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: rajendra@in-reality.com
To unsubscribe send a blank email to xxxxx@lists.osr.com
—
Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
You are currently subscribed to ntdev as: xxxxx@intel.com
To unsubscribe send a blank email to xxxxx@lists.osr.com