Hi,
I am working on a driver that will emulate a SCSI target device. I have
code that creates a device object for the port and a device object for each
LUN I am emulating. Here is what the IoCreateDevice function call looks
like.
Port:
swprintf(devNameBuffer, L"\Device\MPTPort%d", portNumber);
RtlInitUnicodeString(&devNameUnicode, devNameBuffer);
status = IoCreateDevice(pDrvObj,
sizeof (MPTPort),
&devNameUnicode,
FILE_DEVICE_CONTROLLER,
0,
FALSE,
&pDevObj);
LUNs:
swprintf(devNameUnicodeBuffer, L"\Device\MPTPort%dLun%d", PortNum,
Lun);
RtlInitUnicodeString(&devNameUnicodeString, devNameUnicodeBuffer);
Status=IoCreateDevice(DriverObject,
sizeof(DEVICE_EXT_LUN),
&devNameUnicodeString,
FILE_DEVICE_CONTROLLER,
0,
FALSE,
&pDevObjLUN);
They all return with status set to success.
I then try to get a file handle for the port and LUN device objects using
the following arguments to the CreateFile
hndFile = CreateFile(
string, // Open the Device “file”
GENERIC_READ,
FILE_SHARE_READ,
NULL,
OPEN_EXISTING,
FILE_FLAG_OVERLAPPED,
NULL
);
string = “\\.\MPTPort0” when trying to get a file handle for the Port 0
string = \\.\MPTPort0Lun0 when trying to get a file handle for Port 0 Lun
0
I can get a file handle for the port device object but the LUN device object
returns INVALID_HANDLE_VALUE. The GetLastError returns a 2 which is
ERROR_FILE_NOT_FOUND.
When I view the window objects using WinObj.exe from Systems Internals I can
see the LUN device listed under Device but I gat Unable to open
\Device\MPTPort0Lun0.
Does anyone have any ideas why CreateFile is returning file not found?
John Nutter
Neartek, Inc.
1500 West Park Drive
Westborough, MA 01581
(508) 475-3313