Re: FILE_SHARE_READ and FILE_SHARE_WRITE

From: Gary Chanson (gchanson_at_No.Spam.TheWorld.net)
Date: 06/30/04


Date: Wed, 30 Jun 2004 13:39:27 -0400


"PEACEMAKER" <do.not.email@yo.mamas.hairy.ass.com> wrote in message
news:%236ZrErrXEHA.3044@TK2MSFTNGP09.phx.gbl...
> I have an application that needs to be able to open any file for reading.
> Currently I only use FILE_SHARE_READ but I looking at the docs it mentions
> that if a file was opened by another processes with FILE_SHARE_WRITE then
> all subsequent open operations on the file has to include this flag or
> opening will fail (eg if I only specificy FILE_SHARE_READ). The docs don't
> say what happens in the reverse case.. eg a file is created with
> FILE_SHARE_READ, but I attempt to open it with
> FILE_SHARE_READ|FILE_SHARE_WRITE.

    Not quite. The file sharing flags determine what file modes are
permitted to other handles to the same file object. In other words, if I
open a file with FILE_SHARE_READ, the file can also be opened for read by
another call to open. If I specify FILE_SHARE_WRITE, the file can be opened
for write by another call. If I specify neither, the file cannot be opened
by another call. Any subsequent open has to specify whatever flags are
needed to account for my open mode. If I open the file for read, they must
specify FILE_SHARE_READ and so on.

> Which flags should I use to be able to
> open all shared files without any problems?

    This isn't possible. The best you can do is to specify both
FILE_SHARE_READ and FILE_SHARE_WRITE. This will permit you to open any file
for reading which has specified FILE_SHARE_READ but you will still not be
able to open files opened in exclusive mode.

-- 
-GJC [MS Windows SDK MVP]
-Software Consultant (Embedded systems and Real Time Controls)
- http://www.mvps.org/ArcaneIncantations/consulting.htm
-gchanson@mvps.org


Relevant Pages

  • RE: Reading Audio CD Text Data
    ... You should specify 2048 bytes when reading in cooked ... Reading Audio CD Text Data ... using IOCTL_CDROM_MEDIA_REMOVAL then I read the TOC from the cd using ...
    (microsoft.public.development.device.drivers)
  • Re: [RFC/RFT][PATCH -mm] swsusp: userland interface
    ... > Looks mostly okay, few nits... ... >> +The device can be open either for reading or for writing. ... please refer to the source code. ... > We should specify that userland suspend/resume utilities should lock ...
    (Linux-Kernel)
  • Re: Strategey Reading VERY large files
    ... I found fscan to be considerably faster for reading text coded numbers than ... dlmread, especially if you read line by line. ... values R and C specify the row and column where the upper left corner ...
    (comp.soft-sys.matlab)
  • Re: [RFC/RFT][PATCH -mm] swsusp: userland interface
    ... Looks mostly okay, few nits... ... > +The device can be open either for reading or for writing. ... please refer to the source code. ... We should specify that userland suspend/resume utilities should lock ...
    (Linux-Kernel)
  • Re: File.new error
    ... Kai Vermehr wrote: ... If you don't specify the 2nd argument (the open mode) Ruby assumes you ... want to open the file for reading only. ...
    (comp.lang.ruby)

Loading