CreateFile returns ERROR_FILE_NOT_FOUND

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

\.\ resolves to \DosDevices (which in turn resolves to ?? or
\Global??) not \Device. You need to create a symbolic link to your
device object in that directory to use CreateFile.

-p

-----Original Message-----
From: John Nutter [mailto:xxxxx@neartek.com]
Sent: Tuesday, April 22, 2003 9:39 AM
To: NT Developers Interest List

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


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

Thanks Peter for taking the time to respond to my question.

I have created the symbolic links and that was what I was using in the
CreateFile.

I have since found the problem, which I am embarrassed to say, was that
I did not clear the DO_DEVICE_INITIALIZING flag when I created the
device object for the LUN.

“Peter Wieland” wrote in message
news:…

\.\ resolves to \DosDevices (which in turn resolves to ?? or
\Global??) not \Device. You need to create a symbolic link to your
device object in that directory to use CreateFile.

-p

-----Original Message-----
From: John Nutter [mailto:xxxxx@neartek.com]
Sent: Tuesday, April 22, 2003 9:39 AM
To: NT Developers Interest List

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


You are currently subscribed to ntdev as: xxxxx@microsoft.com To
unsubscribe send a blank email to xxxxx@lists.osr.com

----------