阅读:1504回复:10
高手求救呀!!请教SCSI miniport与Application沟通…
各位大大好:
小弟目前在撰写SCSI miniport driver, 因为需要用Application与SCSI miniport沟通, 在客户端利用下面函式CreateFile,已取得handle, hDevice = CreateFile(string, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); 在利用下面的函式DeviceIoControl传到SCSI miniport driver bRc = DeviceIoControl(hDevice, // device handle IOCTL_SCSI_MINIPORT, // io control code &smpi, // input buffer sizeof(SRB_IO_CONTROL), // input buffer length &smpi, // output buffer sizeof(SRB_IO_CONTROL), // output buffer length &cbReturnedData, // # bytes returned NULL); // synchronous call 目前,SCSI miniport driver没有收到请求,请问各位大大有可以那里出了问题?感谢各位的帮助,谢谢! 在DriverEntry时, 我的设定如下: hwInitializationData.HwAdapterControl = TulAdapterControl; 不过,刚开始开机时,当加载我的驱动程序时, 我的卡还不能找到device, 所以在当上层送下来的SRB,我在StartIO routine时, 我的回应为: srb->SrbStatus = SRB_STATUS_NO_DEVICE; ScsiPortNotification(RequestComplete, HwDeviceExtension, srb); ScsiPortNotification(NextRequest, HwDeviceExtension, NULL); 不知道这样的设定有问题吗? 如果,你有driver与application沟通的范例,可以寄给我参考吗? wujumper@yahoo.com.tw 不胜感激! |
|
驱动老牛
![]() |
沙发#
发布于:2005-08-10 12:39
PHW_STOP_ADAPTER HwAdapterControl;
这个位置设置了没 |
|
板凳#
发布于:2005-08-11 09:52
我已经在DriverEntry时有设定好了,设定如下:
hwInitializationData.HwAdapterControl = DispatchAdapterControl; 不过,刚开始开机时,当加载我的驱动程序时, 我的卡还不能找到device, 所以在当上层送下来的SRB,我在StartIO routine时, 我的回应为: srb->SrbStatus = SRB_STATUS_NO_DEVICE; ScsiPortNotification(RequestComplete, HwDeviceExtension, srb); ScsiPortNotification(NextRequest, HwDeviceExtension, NULL); 不知道这样的设定有问题吗? |
|
地板#
发布于:2005-08-11 09:55
sizeof(SRB_IO_CONTROL), // input buffer length,这个长度肯定是错误的,还没到Miniport driver 就被IO manager 给返回错误了
|
|
|
地下室#
发布于:2005-08-11 10:33
driver参考的范例为DDK下的src\\storage\\miniport\\initio
application范例如下: //************************************************************* // // SMPI.H // //************************************************************* #define IOCTL_SCSI_MINIPORT 0x0004d008 // see NTDDSCSI.H for definition #define SMP_RETURN_3F 0x80012140 // defined by our miniport driver // using the Microsoft template #define SMP_PRINT_STRING 0x80000001 // random number // // Define header for I/O control SRB. See NTDDSCSI.H for definition // typedef struct _SRB_IO_CONTROL { ULONG HeaderLength; UCHAR Signature[8]; ULONG Timeout; ULONG ControlCode; ULONG ReturnCode; ULONG Length; } SRB_IO_CONTROL, *PSRB_IO_CONTROL; typedef struct { SRB_IO_CONTROL sic; UCHAR ucDataBuffer[3072]; } SRB_BUFFER, *PSRB_BUFFER; |
|
5楼#
发布于:2005-08-11 10:34
#include <stdio.h>
#include <string.h> #include <windows.h> #include "smpi.h" PCHAR string = "\\\\.\\Scsi2:"; PCHAR DbgString = "This string is in the data buffer area\n"; PCHAR UniqueString = "SCSIDISK"; int __cdecl main() { BOOL bRc; DWORD cbReturnedData; HANDLE hDevice; SHORT DbgStringLength = (SHORT)strlen(DbgString); SHORT UniqueStringLength = (SHORT)strlen(UniqueString); SRB_BUFFER smpi; //************************************************************* // // obtain a handle to the SCSI miniport driver // //************************************************************* printf("Attempting to get a handle for %s\n",string); hDevice = CreateFile(string, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (hDevice == (HANDLE)-1) { printf("Attempt failed! Error number = %d\n",GetLastError()); return; } printf("Attempt on %s succeeded\n\n",string); //************************************************************* // // fill in the SRB_IO_CONTROL structure // //************************************************************* smpi.sic.HeaderLength = sizeof(SRB_IO_CONTROL); smpi.sic.Length = 0; _memccpy(&smpi.sic.Signature,UniqueString,0,UniqueStringLength); smpi.sic.Timeout = 10000; smpi.sic.ControlCode = SMP_RETURN_3F; //************************************************************* // // call the driver // //************************************************************* bRc = DeviceIoControl(hDevice, // device handle IOCTL_SCSI_MINIPORT, // io control code &smpi, // input buffer sizeof(SRB_IO_CONTROL), // input buffer length &smpi, // output buffer sizeof(SRB_IO_CONTROL), // output buffer length &cbReturnedData, // # bytes returned NULL); // synchronous call //************************************************************* // // check for errors // //************************************************************* if (!bRc) printf("DeviceIoControl request for SMP_RETURN_3F failed : %d\n", GetLastError()); //************************************************************* // // verify the driver's access to the SRB_IO_CONTROL structure // //************************************************************* else { printf("The SMP_RETURN_3F Return Code is 0x%08Xh\n", smpi.sic.ReturnCode); printf("The number of bytes returned by the driver is %d\n\n", cbReturnedData); } //************************************************************* // // fill in the SRB_IO_CONTROL structure // //************************************************************* smpi.sic.HeaderLength = sizeof(SRB_IO_CONTROL); smpi.sic.Length = 100; // random large number _memccpy(&smpi.sic.Signature,UniqueString,0,UniqueStringLength); smpi.sic.Timeout = 0; smpi.sic.ControlCode = SMP_PRINT_STRING; strcpy(smpi.ucDataBuffer,DbgString); //************************************************************* // // call the driver // //************************************************************* bRc = DeviceIoControl(hDevice, // device handle IOCTL_SCSI_MINIPORT, // io control code &smpi, // input buffer sizeof(SRB_IO_CONTROL) + // input buffer length DbgStringLength + 1, &smpi, // output buffer sizeof(SRB_IO_CONTROL) + // output buffer length 100, // random large number &cbReturnedData, // # bytes returned NULL); // synchronous call //************************************************************* // // check for errors // //************************************************************* if (!bRc) printf("DeviceIoControl request for SMP_PRINT_STRING failed : %d\n", GetLastError()); //************************************************************* // // verify the driver's access to the SRB_IO_CONTROL structure // //************************************************************* else { printf("%s",smpi.ucDataBuffer); printf("The number of bytes returned by the driver is %d\n\n", cbReturnedData); } //************************************************************* // // close the handle to the SCSI miniport driver // //************************************************************* CloseHandle(hDevice); return 0; } |
|
6楼#
发布于:2005-08-11 10:39
下面是引用liuyan1于2005-08-11 09:55发表的: 我已经知道sizeof(SRB_IO_CONTROL)的大小为0x16,直接给值好像也是不行,GetLastError()回传的值一样也是5。 |
|
7楼#
发布于:2005-08-11 10:42
下面是引用zhangshengyu于2005-08-10 12:39发表的: 在DriverEntry时, 我的设定如下: hwInitializationData.HwAdapterControl = TulAdapterControl; |
|
8楼#
发布于:2005-08-11 10:56
下面是引用wujumper于2005-08-11 10:39发表的: sizeof(SRB_IO_CONTROL)的大小为0x16并不符合该函数的规范,该函数的传入缓冲的大小是要大于SRB_IO_CONTROL这个结构的大小的,体的情况请看IOCTL_SCSI_MINIPORT 的解释,确实是M$在这里太BT了,让人理解上产生歧义. |
|
|
9楼#
发布于:2005-08-11 11:08
下面是引用liuyan1于2005-08-11 10:56发表的: IOCTL_SCSI_MINIPORT Operation Sends a special control function to an HBA-specific miniport driver. Results vary, depending on the particular miniport driver to which this request is forwarded. If the caller specifies a nonzero Length, either the input or output buffer must be at least (sizeof(SRB_IO_CONTROL) + DataBufferLength)). 如果设定改为下面所示,回传的值还是5 bRc = DeviceIoControl(hDevice, // device handle IOCTL_SCSI_MINIPORT, // io control code &smpi, // input buffer sizeof(SRB_IO_CONTROL)+4, // input buffer length &smpi, // output buffer sizeof(SRB_IO_CONTROL)+4, // output buffer length &cbReturnedData, // # bytes returned NULL); // synchronous call |
|
10楼#
发布于:2005-08-11 11:21
下面是引用liuyan1于2005-08-11 10:56发表的: 请问”M$在这里太BT了”,是什么意思,我看不懂,谢谢! |
|