Interfaces clarification please

Hello all.

I’ve read about IoRegisterPlugPlayNotification and try to get notifications about PnP events. Especially I’m trying to get notification when a USB drive is connected. I made the same mistake as here: http://www.osronline.com/showthread.cfm?link=205833 – passed device class GUID. Ok, from this topic I understand that I have to pass device interface GUID. The thing I don’t understand is if there a set of predefined interface GUIDs or not? If I want to know that a USB drive is connected, should I write filter driver (and to which device stack?) or I can get the notification about new USB device? If I need a filter drive, what is the purpose of IoRegisterPlugPlayNotification?


Thanking In Advance,
Mikae.

xxxxx@yahoo.com wrote:

I’ve read about IoRegisterPlugPlayNotification and try to get notifications about PnP events. Especially I’m trying to get notification when a USB drive is connected.

From a driver? Why?

The thing I don’t understand is if there a set of predefined interface GUIDs or not? If I want to know that a USB drive is connected, should I write filter driver (and to which device stack?) or I can get the notification about new USB device?

It depends what you want to do. There are some pre-defined interface
GUIDs, including GUID_DEVINTERFACE_DISK, that might do the job.

What are you going to do when you get this notification? If you need to
affect the device in some way, you’ll need to be part of the driver
stack, and that means you should have been using a filter driver to
begin with.

If I need a filter drive, what is the purpose of IoRegisterPlugPlayNotification?

The only reason you should want to know when a device arrives is because
you want to talk to it. In order to talk to it, you need to know HOW to
talk to it. That’s the point. IoRegisterPlugPlayNotification can tell
you that “a device with the interface you want has just arrived”, so you
can go fetch that interface and talk to it.


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

>From a driver? Why?

Well, I’ve read about this function in Oney’s book and I want to try it.

It depends what you want to do. There are some pre-defined interface
GUIDs, including GUID_DEVINTERFACE_DISK, that might do the job.

Ah, found, thanks.

The only reason you should want to know when a device arrives is because
you want to talk to it. In order to talk to it, you need to know HOW to
talk to it. That’s the point. IoRegisterPlugPlayNotification can tell
you that “a device with the interface you want has just arrived”, so you
can go fetch that interface and talk to it.

Well, I precede two goals: I want to understand how to work with interfaces and what to do with them and also I want to understand how to work with this function. This is kind of studying. Also as far as I understand I can decline device removal when getting notification.

And one more question: if I want to attach to device stack I have to get device object pointer when a device arrives (IoGetDeviceObjectPointer with SymbolicLinkName from the event) and the IoAttachDeviceToDeviceStack, right?

Thanks.

You don’t dynamically attach to pnp device stacks this way. By doing so, you can miss already sent io and already opened handles. If you want to be a part of the stack, install yourself as a filter appropriately.

Also as far as I understand I can decline device removal when getting notification.

Why do you want to do that? All that does is make the user reboot when they try to disable the device or update the drivers

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@yahoo.com
Sent: Friday, July 29, 2011 11:31 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Interfaces clarification please

From a driver? Why?

Well, I’ve read about this function in Oney’s book and I want to try it.

It depends what you want to do. There are some pre-defined interface
GUIDs, including GUID_DEVINTERFACE_DISK, that might do the job.

Ah, found, thanks.

The only reason you should want to know when a device arrives is
because
you want to talk to it. In order to talk to it, you need to know HOW to talk to it. That’s the point. IoRegisterPlugPlayNotification can tell you that “a device with the interface you want has just arrived”, so you can go fetch that interface and talk to it.

Well, I precede two goals: I want to understand how to work with interfaces and what to do with them and also I want to understand how to work with this function. This is kind of studying. Also as far as I understand I can decline device removal when getting notification.

And one more question: if I want to attach to device stack I have to get device object pointer when a device arrives (IoGetDeviceObjectPointer with SymbolicLinkName from the event) and the IoAttachDeviceToDeviceStack, right?

Thanks.


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

>Why do you want to do that? All that does is make the user reboot when they try
to disable the device or update the drivers

Well, I just want to understand which options I have using IoRegisterPlugPlayNotification.

Ok, I tried the function, it works. But more questions have appeared while working with the function.

  1. Are interface arrival notifications delivered simultaneously in different threads? I allocate memory when getting a notification and copy there SymbolicLinkName. Then I execute work item rountine, do everything I need and the free the buffer. I’ve got BAD_POOL_CALLER BSoD when trying to free allocated buffer when inserting flash drive. It looks like that I have to use linked list for allocated buffers, but I’m not sure.

  2. Can I use SymbolicLinkName to create a file on flash hard drive? I tried to append “\text.txt” string and then call ZwCreateFile. It returns STATUS_SUCCESS, but no file appeared on the drive. Why?

Thank you.

wrote in message news:xxxxx@ntdev…


> This is kind of studying. Also as far as I understand I can decline device
> removal when getting notification.

Be careful with declinig user-initiated actions. Because, user will
disconnect that USB drive no matter what your driver does.
If data loss or other disorder occurs, you will be blamed.

–pa

Ok, I think I understand how to handle DeviceInterfaceChange. Now the problem is that I try to write a file on the arrived device, but I get very strange behavior: ZwCreateFile returns STATUS_SUCCESS, IO_STATUS_BLOCK set to zeros (FILE_SUPERSEDED), but I don’t see the file on the drive. The consequent ZwWriteFile fails with STATUS_INVALID_PARAMETER, but as far as I understand the file must be created anyway. The path that I pass to InitializeObjectAttributes is: “??\USBSTOR#Disk&Ven_Seagate&Prod_FreeAgent&Rev_0138#2HC015KJ&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}\text.txt”. The first part of the path is taken from Notification ->SymblicLinkName, then I append slash and the filename. Is this path wrong? Why I don’t see the file?

Thank you.

xxxxx@yahoo.com wrote:

Ok, I think I understand how to handle DeviceInterfaceChange. Now the problem is that I try to write a file on the arrived device, but I get very strange behavior: ZwCreateFile returns STATUS_SUCCESS, IO_STATUS_BLOCK set to zeros (FILE_SUPERSEDED), but I don’t see the file on the drive. The consequent ZwWriteFile fails with STATUS_INVALID_PARAMETER, but as far as I understand the file must be created anyway. The path that I pass to InitializeObjectAttributes is: “??\USBSTOR#Disk&Ven_Seagate&Prod_FreeAgent&Rev_0138#2HC015KJ&0#{53f56307-b6bf-11d0-94f2-00a0c91efb8b}\text.txt”. The first part of the path is taken from Notification ->SymblicLinkName, then I append slash and the filename. Is this path wrong?

Yes.

Why I don’t see the file?

Because that device is a disk. It speaks in disk ioctls and understands
sectors. It doesn’t understand file systems. The concept of a “file”
is way too advanced for that level. Sitting on top of your disk driver
is a file system driver that understands things like files and
directories, and translates them to sectors and bytes. That’s what you
need to contact.

Your device is being exposed as a drive letter, isn’t it?


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

Ough, now I understand. I need another level. The question is how to map drive letter to symbolic link name? As I understand I need something like QueryDosDevice for kernel mode. Is there such service or I have to implement it by myself?

Thank you.