Device Name

hi,

I have a pci device for which i written a driver in Windows ME. i have a
test application to test the device. My mother board has 5 PCI slots on
which i have the same pci device in each slot. i want to test each device
with same application. I used CreateFile() to open the device with XXX0,
XXX1 and so on until XXX4. My question is related to driver that how can i
ensure that for first device i give the name as XXX0 and for next device
as XXX1 and so on in my driver for any number of devices that are present.
If symbolic name XXX0 already exists than i want the next name to be XXX1
and so on.

Thanx.

Regards,
Madhukar.

> XXX1 and so on until XXX4. My question is related to driver that how can i

ensure that for first device i give the name as XXX0 and for next device
as XXX1 and so on in my driver for any number of devices that are present.
If symbolic name XXX0 already exists than i want the next name to be XXX1

Use the device interfaces, it is better :slight_smile:

If you really need the legacy symlinks - then try to create XXX0, then XXX1,
then so on - till STATUS_OBJECT_NAME_COLLISION is returned.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

Are you are asking whether you can tie name XXX0 to a particular piece of
hardware or just that each piece of hardware gets a unique name associated
with it?


Bill McKenzie
Compuware Corporation
Watch your IRPs/IRBs/URBs/SRBs/NDIS pkts with our free WDMSniffer tool:
http://frontline.compuware.com/nashua/patches/utility.htm

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>
> > XXX1 and so on until XXX4. My question is related to driver that how can
i
> > ensure that for first device i give the name as XXX0 and for next device
> > as XXX1 and so on in my driver for any number of devices that are
present.
> > If symbolic name XXX0 already exists than i want the next name to be
XXX1
>
> Use the device interfaces, it is better :slight_smile:
>
> If you really need the legacy symlinks - then try to create XXX0, then
XXX1,
> then so on - till STATUS_OBJECT_NAME_COLLISION is returned.
>
> Maxim Shatskih, Windows DDK MVP
> StorageCraft Corporation
> xxxxx@storagecraft.com
> http://www.storagecraft.com
>
>
>

Hi,

As name of devices are typically named with name of device followed by the
unit number. Your problem is how
to provide numbering to device names.

Use service function called IoGetCongigurationInformation () to determine
next available unit number. It returns pointer to I/O Managers memory
resident CONFIGURATION_INFORMATION data structure.
This structure contains the number of devices of each type found. As it
create each device, the driver should increment the value in
CONFIGURATION_INFORMATION structure.

I think this will help you.

Cheers
Rajesh

----- Original Message -----
From: “madhu”
To: “Windows System Software Devs Interest List”
Sent: Monday, December 29, 2003 12:51 PM
Subject: [ntdev] Device Name

> hi,
>
> I have a pci device for which i written a driver in Windows ME. i have a
> test application to test the device. My mother board has 5 PCI slots on
> which i have the same pci device in each slot. i want to test each device
> with same application. I used CreateFile() to open the device with XXX0,
> XXX1 and so on until XXX4. My question is related to driver that how can i
> ensure that for first device i give the name as XXX0 and for next device
> as XXX1 and so on in my driver for any number of devices that are present.
> If symbolic name XXX0 already exists than i want the next name to be XXX1
> and so on.
>
> Thanx.
>
> Regards,
> Madhukar.
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@hotmail.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com
>

>

As name of devices are typically named with name of device
followed by the unit number. Your problem is how to provide
numbering to device names.

Well no, that is an obsolete legacy (nt4) convention. Devices ought to be
automatically named using a device interface. Applications query for device
interfaces using the ‘SetupDi*’ device enumeration apis.

Use service function called IoGetCongigurationInformation ()
to determine next available unit number. It returns pointer
to I/O Managers memory resident CONFIGURATION_INFORMATION
data structure.

No again. This only works for a restricted class of devices. His PCI device,
for example, is rather unlikely to show up in this list.

As Maxim properly stated, the use of DeviceInterfaces is highly
encouraged. This allows you to have as many of these attached as you
need, and removes the need to try to figure out how to uniquely name the
device. The DDK contains sample code for CDROM.SYS, which both creates
a legacy name (\.\CdromN) and a device interface (using GUID
CdRomClassGuid from ntddstor.h).

One simple reason to not use the legacy names is that there is no
guarantee that they will stay the same for a given device. The
interface names (at least how CDROM uses them) *do* stay the same across
system reboots. In addition, user mode and kernel mode apps can
register for device interface arrivals and removals, and you can delay
the creation/deletion of the device interfaces until the device is
actually ready to accept IO, too! So, the use of device interfaces has
many advantages.

The disadvantage is that it is difficult to start enumerating these
devices. Once you know the key routines, however, the code is easy to
write. To enumerate the devices using the device interface, look at the
following three routines in MSDN:

SetupDiGetClassDevs()
SetupDiEnumDeviceInterfaces()
SetupDiGetDeviceInterfaceDetail()

Here’s some untested, no-warranty psuedo-code for how to find all given
devices. Closing any opened handles and freeing allocated memory is
specifically left as an exercise for the reader.

========================================================================

How to enumerate all devices of a class (such as CDROM):

// SetupDiGetClassDevs – gets the set of all devices of a specified
class,
// such as CdRomClassGuid (ntddstor.h).

GUID cdromGuid = CdRomClassGuid;
deviceInfoHandle =
SetupDiGetClassDevs(&cdromGuid, NULL, NULL,
(DIGCF_PRESENT | DIGCF_INTERFACEDEVICE));

for (int i = 0; i < 0x40000; i++)
{
SP_DEVICE_INTERFACE_DATA diData;
ULONG requiredSize = 0;
DWORD error;
RtlZeroMemory(&diData, sizeof(SP_DEVICE_INTERFACE_DATA));
diData.cbSize = sizeof(SP_DEVICE_INTERFACE_DATA);

// SetupDiEnumDeviceInterfaces() – enumerates devices with a
specific
// interface GUID, such as CdRomClassGuid (ntddstor.h).
// request the Nth device – nonzero return on success
if (!SetupDiEnumDeviceInterfaces(deviceInfoHandle, 0,
&cdromGuid,
currentDeviceIndex, &diData))
{
DWORD error = GetLastError();
if (error == ERROR_NO_MORE_ITEMS)
{
break;
}
}
// SetupDiGetDeviceInterfaceDetail() – using the
DeviceInterfaceDetail
// returned above, call this twice (first to determine size
required,
// then to get info) to get the PNP path to the device.
// should never succeed with NULL buffer…
if (SetupDiGetDeviceInterfaceDetails(deviceInfoHandle, &diData,
NULL,
0, &requiredSize, NULL))
{
// throw Exception
}
if (GetLastError() != ERROR_INSUFFICIENT_BUFFER)
{
// throw Exception – the error must always be
INSUFFICIENT_BUFFER
}
if (requiredSize == 0)
{
// throw Exception – size should never, ever be zero!
}
// allocate diDetails. Add sizeof(TCHAR) to ensure NULL
termination.
diDetails = Alloc(requiredSize+sizeof(WCHAR));
if (!SetupDiGetDeviceInterfaceDetails(deviceInfoHandle, &diData,
diDetails, requiredSize,
&updatedSize, NULL))
{
// thow Exception - should succeed this time around
}
// diDetails->DevicePath is a NULL-terminated unicode string
// save (or use) that string for opening the device directly

}

========

There really should be a FAQ, and this one of the questions in that FAQ.
:slight_smile:
.

-----Original Message-----
From: Maxim S. Shatskih [mailto:xxxxx@storagecraft.com]
Sent: Monday, December 29, 2003 2:26 AM
Subject: Re: Device Name

XXX1 and so on until XXX4. My question is related to driver that how
can i
ensure that for first device i give the name as XXX0 and for next
device
as XXX1 and so on in my driver for any number of devices that are
present.
If symbolic name XXX0 already exists than i want the next name to be
XXX1

Use the device interfaces, it is better :slight_smile:

If you really need the legacy symlinks - then try to create XXX0, then
XXX1,
then so on - till STATUS_OBJECT_NAME_COLLISION is returned.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com