Limiting access to device to single app at a time

Since the WDF automatically handles create and close I/O requests for us, how can I limit the number of concurrent applications using my device?

I wish to allow multiple applications to have read access, however only one may write. So, without discretely checking the file mode at the time of creation how can I do this?

KMDF does not provide any infrastructure to let you implement sharing semantics, but the io manager does provide functions that you create this type of semantic. See IoSetShareAccess and IoCheckShareAccess in the wdk. Remember you need to call these apis with a lock held since they do not provide any concurrency on their own, I would probably use a WDFWAITLOCK since these are only callable at IRQL == PASSIVE_LEVEL.

Another way you can do this is to create 2 instances of your device interface, each with a different reference string. RefString1 only allows reads and allows N applications. RefString2 allows only 1 write. If you are using an old legacy style symbolic link, the ref string thing works as well.

http://blogs.msdn.com/doronh/archive/2006/08/18/706717.aspx
http://blogs.msdn.com/doronh/archive/2006/08/23/715612.aspx

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@hotmail.com
Sent: Monday, January 28, 2008 3:20 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Limiting access to device to single app at a time

Since the WDF automatically handles create and close I/O requests for us, how can I limit the number of concurrent applications using my device?

I wish to allow multiple applications to have read access, however only one may write. So, without discretely checking the file mode at the time of creation how can I do this?


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 not just implement EvtDeviceFileCreate, check the file access specified in the FILE_OBJECT, and complete the create request appropriately?

Isn’t that a LOT simpler and easier to understand/maintain than two device interfaces??

Peter
OSR