CreateDeviceAccessInstance does not allow file sharing (?!)
-
jueves, 05 de abril de 2012 14:37
Hi everyone,
I successfully communicate with a custom driver through CreateDeviceAccessInstance / IDeviceIoControl API.
But.. now I face the following issue:
Question #1
Is there a way to configure CreateDeviceAccessInstance so that underling file object is shared for r/w access (FILE_SHARE_READ | FILE_SHARE_WRITE) ?
My custom driver is a UMDF (filter driver). It is also accessed via the desktop through plain old CreateFile (with above sharing flags set on).
If I try to play with CreateDeviceAccessInstance() flags it has no effect on file sharing options.
I can confirm it also by registering to IQueueCallbackCreate::OnCreateFile() in my driver : IWDFIoRequest::GetCreateParameters(&options, &fileAttributes, &shareAccess);
Question #2
Is there a way to modify the CreateFile request in the driver (for instance in above-mentionned callback), or issue another create file (internal to the driver) request, which would set FILE_SHARE_READ | FILE_SHARE_WRITE on? I just see IWDFIoRequest::GetCreateParameters, but no way to set them..
Thanks in advance!!
Julien
- Tipo cambiado Eric Hanson-MSFTMicrosoft Employee, Moderator viernes, 08 de junio de 2012 22:43
- Tipo cambiado Eric Hanson-MSFTMicrosoft Employee, Moderator viernes, 08 de junio de 2012 22:43
Todas las respuestas
-
jueves, 05 de abril de 2012 15:47Moderador
Julien,
I will look into this for you.
Best Wishes - Eric
-
jueves, 05 de abril de 2012 18:52
Hi Eric,
thanks very much! If you need more detailed context (or less obscure explanation :) I can provide some!
Regards,
Julien
Julien Racle
-
viernes, 06 de abril de 2012 19:28Moderador
Julien,
Createfile supports a flag for ShareMode as well as DesiredAccess:
HANDLE WINAPI CreateFile(
__in LPCTSTR lpFileName,
__in DWORD dwDesiredAccess,
__in DWORD dwShareMode,
__in_opt LPSECURITY_ATTRIBUTES lpSecurityAttributes,
__in DWORD dwCreationDisposition,
__in DWORD dwFlagsAndAttributes,
__in_opt HANDLE hTemplateFile
);However CreateDeviceAccessInstance has only desiredAccess:
HRESULT WINAPI
CreateDeviceAccessInstance(
_In_ REFIID riid,
_In_ LPCWSTR deviceInterfacePath,
_In_ DWORD desiredAccess,
_Outptr_ ICreateDeviceAccessAsync **createAsync
);However what we recommend is that your device driver have an additional interface for your Metro style device app. Please let me know if you have any questions.
Best Wishes - Eric
- Propuesto como respuesta Eric Hanson-MSFTMicrosoft Employee, Moderator viernes, 06 de abril de 2012 19:28
- Editado Eric Hanson-MSFTMicrosoft Employee, Moderator viernes, 06 de abril de 2012 19:32
-
viernes, 06 de abril de 2012 20:47
Hi Eric,
Thanks for your kind reply. Indeed I'd need a bit more explanation :
CreateDeviceAccessInstance() is the only way I have to access my UMDF filter driver from within the Metro app I'm developing. It indeed does not support file sharing mode. Now, the trouble is that the same driver is also accessed from desktop mode via existing apps, which all use CreateFile (with sharing flags ON). Those apps are on the field, already published and used by many people.
So I'm a bit puzzled : why no sharing option in CreateDeviceAccessInstance? Indeed, apart from my use case, multiple privileged metro apps are likely to access same device at the same time.
Is there a way to get around the issue by enforcing those flags, for instance in my driver's IQueueCallbackCreate::OnCreateFile(), so that I don't get a sharing violation error..
Thanks so much for investigating!
JulienJulien Racle
-
sábado, 07 de abril de 2012 8:47
Eric,
Again thanks for your answer. If no other way than creating another interface in my driver is found, I gonna try to do so.
BTW my filter driver also is on top of (your) HID class driver, and it forwards many IO requests, so I don't know how to do the relationship between both interfaces/file objects (HID and mine).
You may consider raising the issue for DWORD dwShareMode abscence in CreateDeviceAccessInstance() : indeed the problem will be now that 2 metro apps running in parallel (tiled for instance, or 1 app and a background task), will encounter same file sharing issue (hence option would be to create several interfaces in the diver?! ;).
Thanks!
Julien
Julien Racle
-
miércoles, 11 de abril de 2012 5:37Moderador
Julien,
Is your driver a device filter or class filter? I will raise the issue about the WinRT API.
Best Wishes - Eric
-
miércoles, 11 de abril de 2012 5:52
Hi Eric,
this is a HID class filter driver installed over a HID vendor collection.
It already works, "except" this file sharing violation issue, which prevents multiple clients.
Best Regards,
Julien
Julien Racle
-
viernes, 13 de abril de 2012 5:44Moderador
Julien,
I am looking into this for you.
Best Wishes - Eric
-
lunes, 16 de abril de 2012 18:04Moderador
Julien,
A HID vendor collection does not use file sharing modes in its create path. Are you building this driver on top of a file system? A file system driver is the only driver I am aware of that would need SharedMode.
Are you certain you need the share access in the desktop application?
Best Wishes - Eric
-
martes, 17 de abril de 2012 12:22
Hi Eric,
no, my HID filter driver is built on top of HID class driver, not the filesystem.
I'm not sure to catch what you mean by "A HID vendor collection does not use file sharing modes in its create path.".
Indeed my legacy app uses CreateFile(.... FILE_SHARE_WRITE | FILE_SHARE_READ...) on top level collection's interface path.
If I remove this, then obviously it becomes single client.
Apps I have in the field already use file sharing option : they communicate via a single top level collection through HID class driver.
If I don't have share access in desktop, then it will :
- break legacy support
- break also device access sharing between metro apps / contracts / background tasks (imagine the pb when 2 apps are tiled, or 1 app is running and another needs a contract which also makes use of this device in question)
Best,
Julien
Julien Racle
-
martes, 24 de abril de 2012 22:07Moderador
Julien,
For MDA access to HID devices it is recommended to write a HID function driver using UMDF or KMDF to avoid sharing conflicts.
Best Wishes - Eric
- Marcado como respuesta Eric Hanson-MSFTMicrosoft Employee, Moderator viernes, 25 de mayo de 2012 5:32
- Desmarcado como respuesta jracle viernes, 25 de mayo de 2012 6:03
-
viernes, 25 de mayo de 2012 6:09
Sorry Eric, but that means I have to write HID class driver myself?
(I repeat : goal is to use HID class driver, and additionally provide shared access to custom features via a vendor collection).
We have dozens of thousands of devices (mice, keyboards) which work this way in my company actually on desktop side, and I would bet we won't plan to develop a function driver to replace HID class driver..
From my point of view, this sounds like a missing parameter in your API, isn't it?
Regards,
Julien
Julien Racle
-
sábado, 26 de mayo de 2012 5:36Moderador
Julien,
I will continue to look into this.
Best Wishes - Eric
-
martes, 29 de mayo de 2012 6:27Thanks again very much Eric, and sorry for taking your bandwidth :)
Julien Racle
-
martes, 29 de mayo de 2012 6:32Moderador
You are very welcome Julien. I appreciate the question.
Best Wishes - Eric
-
viernes, 08 de junio de 2012 22:43Moderador
Julien,
We now have a sample of a HID function driver:
http://code.msdn.microsoft.com/windowshardware/HID-Client-Sample-2e2a6281
The function:
HRESULT WINAPI
CreateDeviceAccessInstance(
_In_ REFIID riid,
_In_ LPCWSTR deviceInterfacePath,
_In_ DWORD desiredAccess,
_Outptr_ ICreateDeviceAccessAsync **createAsync
);is not likely to have sharemode added to it.
Best Wishes - Eric
- Marcado como respuesta Eric Hanson-MSFTMicrosoft Employee, Moderator lunes, 11 de junio de 2012 23:45
-
lunes, 09 de julio de 2012 20:25
Hi Eric,
thanks again for your reply. I'll try that out and hope it'll address my point!
Thanks very much!
Julien Racle
-
lunes, 09 de julio de 2012 20:29Moderador
Julien,
You are very welcome. Thank You!
Best Wishes - Eric

