Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These changes add a write-protect option to the dokan framework and mirror sample.
The write-protect functionality is implemented at the driver level (i.e. kernel space) and doesn't require any changes to file system implementations beyond specifying the write-protect option during mounting.
Requests that would result in write operations are intercepted by the driver, avoiding any unnecessary calls into user space. One exception to this is
FILE_OPEN_IF
requests. At the driver level, we don't know if a file exists without calling into the file system implementation. We therefore don't know whether to failFILE_OPEN_IF
requests.The current solution to this is to substitute
FILE_OPEN
forFILE_OPEN_IF
before passing the request to the user mode code, and if we receive a status not found, convert to a status write protected.The basic functionality has been tested from explorer on Win7 x64 and Win10 x64, but certain paths are beyond my current test setup (e.g.
IOCTL_DISK_IS_WRITABLE
andIOCTL_VOLUME_GET_GPT_ATTRIBUTES
calls,FILE_OPEN_IF
).Please take a look.