private int openExisting(
      VirtualFile file,
      int desiredAccess,
      int shareMode,
      int flagsAndAttributes,
      DokanFileInfo dokanFileInfo) {
    if (file == null) {
      dokanFileInfo.context = 0;
      return -ERROR_FILE_NOT_FOUND;
    }

    if (file.isReadOnly() && Is.in(desiredAccess).set(GENERIC_WRITE | FILE_WRITE_DATA)) {
      return -ERROR_ACCESS_DENIED;
    }

    dokanFileInfo.isDirectory = file.isDirectory() ? (byte) 1 : 0;
    dokanFileInfo.context = file.hashCode();
    return ERROR_SUCCESS;
  }
  private int createNew(
      VirtualFile file,
      WString path,
      int desiredAccess,
      int shareMode,
      int flagsAndAttributes,
      DokanFileInfo dokanFileInfo) {
    if (file != null) {
      return -ERROR_FILE_EXISTS;
    }

    file = (VirtualFile) root.createFile(path, flagsAndAttributes);
    if (file == null) {
      return -ERROR_PATH_NOT_FOUND;
    }
    dokanFileInfo.isDirectory = file.isDirectory() ? (byte) 1 : 0;
    dokanFileInfo.context = file.hashCode();
    return ERROR_SUCCESS;
  }
  private int createAlways(
      VirtualFile file,
      WString path,
      int desiredAccess,
      int shareMode,
      int flagsAndAttributes,
      DokanFileInfo dokanFileInfo) {
    int returnCode = ERROR_SUCCESS;

    if (file != null) {
      returnCode = file.flush(flagsAndAttributes) ? ERROR_ALREADY_EXISTS : -ERROR_ACCESS_DENIED;
    } else {
      file = (VirtualFile) root.createFile(path, flagsAndAttributes);
      if (file == null) {
        return -ERROR_PATH_NOT_FOUND;
      }
    }

    dokanFileInfo.isDirectory = file.isDirectory() ? (byte) 1 : 0;
    dokanFileInfo.context = file.hashCode();
    return returnCode;
  }
  private int openAlways(
      VirtualFile file,
      WString path,
      int desiredAccess,
      int shareMode,
      int flagsAndAttributes,
      DokanFileInfo dokanFileInfo) {
    int returnCode = ERROR_ALREADY_EXISTS;

    if (file == null) {
      file = (VirtualFile) root.createFile(path, flagsAndAttributes);
      returnCode = ERROR_SUCCESS;
    }

    if (file.isReadOnly() && Is.in(desiredAccess).set(GENERIC_WRITE | FILE_WRITE_DATA)) {
      return -ERROR_ACCESS_DENIED;
    }

    dokanFileInfo.isDirectory = file.isDirectory() ? (byte) 1 : 0;
    dokanFileInfo.context = file.hashCode();
    return returnCode;
  }