Re: About the settings in CreateFile



sharing modes really apply to file systems, not device drivers. your CreateFile needs to return failure if you want to have exclusivity and there is alraedy an open handle

d

--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


"Felix" <Felix@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:FE2756BE-19A1-4782-BAD5-474D9BE6B103@xxxxxxxxxxxxxxxx
Thanks for your replies.
But I still have confusion in sharing mode of CreateFile.
If the dispatch routine for IRP_MJ_CREATE in my driver always returns
NT_SUCCESS, any application can open the handle although I set non-sharing
mode in first application?


"Anand Choubey" wrote:


Read second point :
When you implement your dispatch routine for IRP_MJ_CREATE (in WDM) or
EvtDeviceFileCreate (in KMDF), you maintain a count of handles which
have been opened against your device and fail requests when the count
is > 1. Typically this count is maintained on a field in the device
extension using the InterlockedIncrement()/Decrement() functions and
is decremented in your IRP_MJ_CLOSE dispatch routine (in WDM) or
EvtFileClose (in KMDF). Note: in KMDF you don't need to do this at
all. During device initialization, if you call
WdfDeviceInitSetExclusive(), KMDF will maintain this count for you
automatically.


Regards,
Anand
On Sep 11, 5:43 pm, "Don Burn" <b...@xxxxxxxxxxxxxxxxxxxx> wrote:
> What are you talking about IOCTL? Sorry the create file DISPATCH > routine is
> called in the driver there is no IOCTL present here. As far as the > OP's
> problem, sharing of devices happens by default, > seehttp://blogs.msdn.com/doronh/archive/2006/05/25/607708.aspx
>
> --
> Don Burn (MVP, Windows DDK)
> Windows 2k/XP/2k3 Filesystem and Driver Consulting
> Website:http://www.windrvr.com
> Blog:http://msmvps.com/blogs/WinDrvr
> Remove StopSpam to reply
>
> "Anand Choubey" <anand.chou...@xxxxxxxxx> wrote in message
>
> news:5488095e-6ca3-405a-8ee8-e13acd4cfaf8@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> When you call createfile, MJ_CREATE IOCTL is hit in driver.
> If you do not want to open multiple handle of driver at a time.
>
> you should add reference counter mj_create ioctl.
>
> Regards,
> Anand
>
> On Sep 11, 2:24 pm, Felix <Fe...@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> > Hi,
> > I write a DLL file which can open my device by calling CreateFIle
> > function.
> > The settings of CreateFile are like
>
> > CreateFile("\\\\.\\Device",
> > GENERIC_READ|GENERIC_WRITE,
> > 0,
> > NULL,
> > OPEN_EXISTING,
> > FILE_ATTRIBUTE_NORMAL,
> > NULL);
>
> > The sharing mode parameter is 0 !
> > Besides, I have two different applications which load the same DLL > > file
> > individually when startup.
> > I found they can get two handles at one time without closing handle!
> > Is this result against the rule of sharing mode 0 ?
> > Any suggestion is appreciated.
> > Thanks.
>
> > Felix



.



Relevant Pages

  • Re: About the settings in CreateFile
    ... What are you talking about IOCTL? ... Windows 2k/XP/2k3 Filesystem and Driver Consulting ... I write a DLL file which can open my device by calling CreateFIle ... Is this result against the rule of sharing mode 0? ...
    (microsoft.public.development.device.drivers)
  • Re: WinCE USB
    ... do a CreateFile( ... If it's a storage card driver, ... If it's a network USB device, ... SetupDiEnumDeviceInterfaces() ...
    (microsoft.public.windowsce.platbuilder)
  • Re: USB Testing
    ... I have no idea if the port is displayed in a GUI or is in the ... Trying to do a CreateFile in XP...As I said above, ... As for using CreateFilefrom XP, I used the device ID for the USB ... WCEUSBSH driver to load. ...
    (microsoft.public.windowsce.platbuilder)
  • Re: CreateFile performance
    ... If many applications are calling driver, ... context need a separate handle or duplicate handle for CreateFile. ... CreateFile() for each process context. ... more than one packet from driver to user mode. ...
    (microsoft.public.development.device.drivers)
  • Re: WinCE USB
    ... do a CreateFile( ... If it's a storage card driver, ... If it's a network USB device, it should provide an IP to ... SetupDiEnumDeviceInterfaces() ...
    (microsoft.public.windowsce.platbuilder)

Loading