cryptomator / dokany-nio-adapter

Dokany-based adapter to provide directory contents specified by a java.nio.file.Path (via dokan-java)
GNU Affero General Public License v3.0
14 stars 4 forks source link

Returning correct NTSTATUS #24

Closed infeo closed 5 years ago

infeo commented 5 years ago

Commit: 83f66ec0c99ac7cedb265b851624f8a1a0db2f5f OS version: Windows 10 Pro 1809 Dokan version: 1.2.2.1000

In the dokan mirror example the NTSTATUS code FILE_IS_A_DIRECTORY is returned when in corresponding the zwCreateFile()-call the ressource is a directory but indicated as anything but a directory:

  if (fileAttr != INVALID_FILE_ATTRIBUTES
    && fileAttr & FILE_ATTRIBUTE_DIRECTORY) {
      if (!(CreateOptions & FILE_NON_DIRECTORY_FILE)) {
        DokanFileInfo->IsDirectory = TRUE;
        // Needed by FindFirstFile to list files in it
        // TODO: use ReOpenFile in MirrorFindFiles to set share read temporary
        ShareAccess |= FILE_SHARE_READ;
      } else { // FILE_NON_DIRECTORY_FILE - Cannot open a dir as a file
        DbgPrint(L"\tCannot open a dir as a file\n");
        return STATUS_FILE_IS_A_DIRECTORY;
      }
  }

We should also follow this convention, currently we return a generic failure code.

infeo commented 5 years ago

Since there is no specific Win32ErrorCodes for this case and we use them in our layer and let them convert to NTSTATUS by dokan, the ERROR_INVALID_STATE code is returned and then handled in a special way in our layer.