Map driver letter to device interface

Hello all.

Here: http://www.osronline.com/showthread.cfm?link=209654 I asked a question, but didn’t get any answers. Hope this is because nobody noticed the question. I get device interface symbolic link name from PnP event handler. After that I want to create a file on the attached device. To do that I have to get attached drive’s letter, by its device interface symbolic link. It looks like there is no such routine, so I have to implement it by myself. The question is how to do it. I have idea to call IoGetDeviceObjectPointer passing all possible letters to it (??\a: ??\b: ??\c: and so on), then call IoGetDeviceAttachmentBaseRef for every device pointer to get PDO and then call IoGetDeviceInterfaces passing GUID_DEVINTERFACE_DISK and PDO from IoGetDeviceAttachmentBaseRef. I didn’t try it yet and not sure that this is correct. Is there another shorter ways to do this task?


Thanking In Advance,
Mikae.

I haven’t done this for disk drives, but I was under the distinct impression
that if you had the interface ID, you could convert it to a string that
worked with CreateFile. In fact, this is well-documented. I looked at this
about five years ago, and I recall it was quite straightforward, even though
the APIs were badly-named by a bunch of people who were clueless about how
to create names (why I would *want* to call an API called “Setup…” to open
a file makes no sense; but in fact that is exactly how it is done, because
the word Setup in the APIs is meaningless noise). At no point in this
sequence of calls does the need for a drive letter appear. I was doing it
for serial ports, and at no point did I need COMn: for any aspect of opening
the serial port. I needed to enumerate all the serial ports on the machine,
and this was the recommended practice. So I think it works the same way for
disks, but first find out how to create the device string using the Setup
APIs. There’s even an example in the DDK source, which is where I started.
joe

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Tuesday, August 02, 2011 5:18 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Map driver letter to device interface

Hello all.

Here: http://www.osronline.com/showthread.cfm?link=209654 I asked a
question, but didn’t get any answers. Hope this is because nobody noticed
the question. I get device interface symbolic link name from PnP event
handler. After that I want to create a file on the attached device. To do
that I have to get attached drive’s letter, by its device interface symbolic
link. It looks like there is no such routine, so I have to implement it by
myself. The question is how to do it. I have idea to call
IoGetDeviceObjectPointer passing all possible letters to it (??\a: ??\b:
??\c: and so on), then call IoGetDeviceAttachmentBaseRef for every device
pointer to get PDO and then call IoGetDeviceInterfaces passing
GUID_DEVINTERFACE_DISK and PDO from IoGetDeviceAttachmentBaseRef. I didn’t
try it yet and not sure that this is correct. Is there another shorter ways
to do this task?


Thanking In Advance,
Mikae.


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Probably I don’t know something, but Setup API is user mode API while I operate in kernel mode.

Joseph M. Newcomer wrote:

I haven’t done this for disk drives, but I was under the distinct impression
that if you had the interface ID, you could convert it to a string that
worked with CreateFile.

Yes, and he was able to call CreateFile, but in this particular case,
the driver he asked for is not the driver he wants. He’s using the
device interface for disks, and he’s opening a disk device, but what he
really wants to do is to create files ON that disk. For that he needs a
file system driver.

So, he’s asking the wrong question. I think the question he meant to
ask was, “given the VID and PID of a USB mass storage device, how can I
create files on that device?” That’s a more complicated question.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

lol I know the op wants to create a file on his device, but which partition
I am not sure. The fact that with many storage devices the answer is ‘the
one any only’ doesn’t imply that the choice can be skipped. And what will
happen to a spanned or RAID partition I can’t fathom.

To the OP: even if your choice is arbitrary (ex the first one I can find),
you still need to enumerate the volumes and check if it is the one that you
want.

“Tim Roberts” wrote in message news:xxxxx@ntdev…

Joseph M. Newcomer wrote:

I haven’t done this for disk drives, but I was under the distinct
impression
that if you had the interface ID, you could convert it to a string that
worked with CreateFile.

Yes, and he was able to call CreateFile, but in this particular case,
the driver he asked for is not the driver he wants. He’s using the
device interface for disks, and he’s opening a disk device, but what he
really wants to do is to create files ON that disk. For that he needs a
file system driver.

So, he’s asking the wrong question. I think the question he meant to
ask was, “given the VID and PID of a USB mass storage device, how can I
create files on that device?” That’s a more complicated question.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Ok, let me explain what the OP wants. He has read about IoRegisterPluPlayNotification in Oney’s book. Now he wants to play a bit with this function. So he invented a task for himself: create a file on disk drive when it is attached to PC. This is why the question is a little bit fuzzy.

NTDEV:
Yes, I understand that even flash drive may have more than one partition. Let’s create a file on every partition.

Tim Roberts:
How VID and PID of a USB mass storage device are connected to the task? Could you explain please?

So, I still don’t understand, is the way I suggested correct or incorrect? Is there other ways? Are they shorter o longer? If they are long, could you explain them or where I can read about them?

Thank you.

Register for GUID_DEVINTERFACE_VOLUME, or enumerate all those interfaces. You can then use the returned name as a path to the root of the volume, instead of a drive letter. In fact, you can use it even if the volume doesn’t have any letter assigned to it.

Ok, let me try to do that. By the way, where it is possible to read about this hierarchy: filesystem ->volume ->disk? Another question is how to filter fixed disks from GUID_DEVINTERFACE_VOLUME? I suspect that they also belong to this interface.

Volume is a filesystem instance. It can span multiple physical disks and partitions. A drive letter is assigned to a volume.

Ok, I tried GUID_DEVINTERFACE_VOLUME – the file was created on all mounted file systems, which is not exactly what I want. Ok, it looks like I have to read something about that.