How-to: File Sharing modes

When an application creates a new file or opens an existing file, it must specify whether it wants to share the file for reading, writing, both, or neither. This is known as the sharing mode.

In the table below, on the left hand side select the row with the Generic Read and /or Write access that your process requires, then select the column with the File Sharing mode to see what other activity will then be able to co-exist with your process.

For example if your process needs GENERIC_WRITE access to a file plus FILE_SHARE_READ sharing mode, then that will allow it to share the file with a GENERIC_READ process that in turn has enabled FILE_SHARE_WRITE.

The file sharing is a two way street - to be compatible, both processes must have FILE_SHARE settings that are compatible with whatever the other process needs. If they don’t have compatible sharing modes then the file will be locked by the first process.


FILE_SHARE_READ FILE_SHARE_WRITE FILE_SHARE_READ +
FILE_SHARE_WRITE
< The file_share bits indicate what you want to allow other processes to do.
GENERIC_READ Share with any READ process that has File_Share_Read Share with any WRITE process that has File_Share_Read Share with any other process that has File_Share_Read
GENERIC_WRITE Share with any READ process that has File_Share_Write Share with any WRITE process that has File_Share_Write. Share with any other process that has File_Share_Write
GENERIC_READ +
GENERIC_WRITE
Share with any READ process that has File_Share_Read + File_Share_Write Share with any WRITE process that has File_Share_Read + File_Share_Write Share with any other process that has File_Share_Read + File_Share_Write
^ The Generic_access bits indicate what your process needs to do.



"plus ça change, plus c'est la même chose (The more things change, the more they are the same)” ~ Jean-Baptiste Alphonse Karr 1849.

Related commands:

Creating and Opening Files - docs.microsoft.com
How do the FILE_SHARE_* bits interact with the desired access bits? - Raymond Chen [MSFT]


 
Copyright © 1999-2022 SS64.com
Some rights reserved