Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'release/1.1.8'
Browse files Browse the repository at this point in the history
  • Loading branch information
infeo committed May 8, 2019
2 parents 52d36eb + 135522c commit 3909e06
Show file tree
Hide file tree
Showing 4 changed files with 169 additions and 35 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.cryptomator</groupId>
<artifactId>dokany-nio-adapter</artifactId>
<version>1.1.7</version>
<version>1.1.8</version>
<description>Access resources at a given NIO path via Dokany.</description>
<name>Dokany-NIO Adapter</name>
<url>https://github.com/cryptomator/dokany-nio-adapter</url>
Expand Down Expand Up @@ -121,7 +121,7 @@
<dependency>
<groupId>org.cryptomator</groupId>
<artifactId>cryptofs</artifactId>
<version>1.8.1</version>
<version>1.8.3</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
175 changes: 147 additions & 28 deletions src/main/java/com/dokany/java/DokanyOperationsProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
import com.sun.jna.platform.win32.WinBase;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.LongByReference;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* Implementation of {@link com.dokany.java.DokanyOperations} which connects to {@link com.dokany.java.DokanyFileSystem}.
*/
final class DokanyOperationsProxy extends com.dokany.java.DokanyOperations {

private final static Logger LOG = LoggerFactory.getLogger(DokanyOperationsProxy.class);

private final DokanyFileSystem fileSystem;

DokanyOperationsProxy(final DokanyFileSystem fileSystem) {
Expand Down Expand Up @@ -55,12 +59,17 @@ public long callback(WString rawPath, WinBase.SECURITY_ATTRIBUTES securityContex
IntByReference desiredAccess = new IntByReference();
IntByReference fileAttributeFlags = new IntByReference();
NativeMethods.DokanMapKernelToUserCreateFileFlags(rawDesiredAccess, rawFileAttributes, rawCreateOptions, rawCreateDisposition, desiredAccess, fileAttributeFlags, createDisposition);
int win32ErrorCode = fileSystem.zwCreateFile(rawPath, securityContext, desiredAccess.getValue(), fileAttributeFlags.getValue(), rawShareAccess, createDisposition.getValue(), rawCreateOptions, dokanyFileInfo);
//little cheat for issue #24
if (win32ErrorCode == Win32ErrorCode.ERROR_INVALID_STATE.getMask()) {
return NtStatus.FILE_IS_A_DIRECTORY.getMask();
} else {
return NativeMethods.DokanNtStatusFromWin32(win32ErrorCode);
try {
int win32ErrorCode = fileSystem.zwCreateFile(rawPath, securityContext, desiredAccess.getValue(), fileAttributeFlags.getValue(), rawShareAccess, createDisposition.getValue(), rawCreateOptions, dokanyFileInfo);
//little cheat for issue #24
if (win32ErrorCode == Win32ErrorCode.ERROR_INVALID_STATE.getMask()) {
return NtStatus.FILE_IS_A_DIRECTORY.getMask();
} else {
return NativeMethods.DokanNtStatusFromWin32(win32ErrorCode);
}
} catch (Exception e) {
LOG.warn("zwCreateFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}
Expand All @@ -77,175 +86,285 @@ class ReadFileProxy implements ReadFile {

@Override
public long callback(WString rawPath, Pointer rawBuffer, int rawBufferLength, IntByReference rawReadLength, long rawOffset, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.readFile(rawPath, rawBuffer, rawBufferLength, rawReadLength, rawOffset, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.readFile(rawPath, rawBuffer, rawBufferLength, rawReadLength, rawOffset, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("readFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class WriteFileProxy implements WriteFile {

@Override
public long callback(WString rawPath, Pointer rawBuffer, int rawNumberOfBytesToWrite, IntByReference rawNumberOfBytesWritten, long rawOffset, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.writeFile(rawPath, rawBuffer, rawNumberOfBytesToWrite, rawNumberOfBytesWritten, rawOffset, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.writeFile(rawPath, rawBuffer, rawNumberOfBytesToWrite, rawNumberOfBytesWritten, rawOffset, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("writeFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class FlushFileBuffersProxy implements FlushFileBuffers {

@Override
public long callback(WString rawPath, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.flushFileBuffers(rawPath, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.flushFileBuffers(rawPath, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("flushFileBuffers(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class GetFileInformationProxy implements GetFileInformation {

@Override
public long callback(WString fileName, ByHandleFileInfo handleFileInfo, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getFileInformation(fileName, handleFileInfo, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getFileInformation(fileName, handleFileInfo, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("getFileInformation(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class FindFilesProxy implements FindFiles {

@Override
public long callback(WString rawPath, FillWin32FindData rawFillFindData, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.findFiles(rawPath, rawFillFindData, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.findFiles(rawPath, rawFillFindData, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("findFiles(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class FindFilesWithPatternProxy implements FindFilesWithPattern {

@Override
public long callback(WString fileName, WString searchPattern, FillWin32FindData rawFillFindData, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.findFilesWithPattern(fileName, searchPattern, rawFillFindData, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.findFilesWithPattern(fileName, searchPattern, rawFillFindData, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("findFilesWithPattern(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class SetFileAttributesProxy implements SetFileAttributes {

@Override
public long callback(WString rawPath, int rawAttributes, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setFileAttributes(rawPath, rawAttributes, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setFileAttributes(rawPath, rawAttributes, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("setFileAttributes(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class SetFileTimeProxy implements SetFileTime {

@Override
public long callback(WString rawPath, WinBase.FILETIME rawCreationTime, WinBase.FILETIME rawLastAccessTime, WinBase.FILETIME rawLastWriteTime, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setFileTime(rawPath, rawCreationTime, rawLastAccessTime, rawLastWriteTime, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setFileTime(rawPath, rawCreationTime, rawLastAccessTime, rawLastWriteTime, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("setFileTime(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class DeleteFileProxy implements DeleteFile {

@Override
public long callback(WString rawPath, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.deleteFile(rawPath, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.deleteFile(rawPath, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("deleteFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class DeleteDirectoryProxy implements DeleteDirectory {

@Override
public long callback(WString rawPath, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.deleteDirectory(rawPath, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.deleteDirectory(rawPath, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("deleteDirectory(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class MoveFileProxy implements MoveFile {

@Override
public long callback(WString rawPath, WString rawNewFileName, boolean rawReplaceIfExisting, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.moveFile(rawPath, rawNewFileName, rawReplaceIfExisting, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.moveFile(rawPath, rawNewFileName, rawReplaceIfExisting, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("moveFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class SetEndOfFileProxy implements SetEndOfFile {

@Override
public long callback(WString rawPath, long rawByteOffset, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setEndOfFile(rawPath, rawByteOffset, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setEndOfFile(rawPath, rawByteOffset, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("setEndOfFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class SetAllocationSizeProxy implements SetAllocationSize {

@Override
public long callback(WString rawPath, long rawLength, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setAllocationSize(rawPath, rawLength, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setAllocationSize(rawPath, rawLength, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("setAllocationSize(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class LockFileProxy implements LockFile {

@Override
public long callback(WString rawPath, long rawByteOffset, long rawLength, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.lockFile(rawPath, rawByteOffset, rawLength, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.lockFile(rawPath, rawByteOffset, rawLength, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("lockFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class UnlockFileProxy implements UnlockFile {

@Override
public long callback(WString rawPath, long rawByteOffset, long rawLength, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.unlockFile(rawPath, rawByteOffset, rawLength, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.unlockFile(rawPath, rawByteOffset, rawLength, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("unlockFile(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class GetDiskFreeSpaceProxy implements GetDiskFreeSpace {

@Override
public long callback(LongByReference freeBytesAvailable, LongByReference totalNumberOfBytes, LongByReference totalNumberOfFreeBytes, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getDiskFreeSpace(freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getDiskFreeSpace(freeBytesAvailable, totalNumberOfBytes, totalNumberOfFreeBytes, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("getDiskFreeSpace(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class GetVolumeInformationProxy implements GetVolumeInformation {

@Override
public long callback(Pointer rawVolumeNameBuffer, int rawVolumeNameSize, IntByReference rawVolumeSerialNumber, IntByReference rawMaximumComponentLength, IntByReference rawFileSystemFlags, Pointer rawFileSystemNameBuffer, int rawFileSystemNameSize, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getVolumeInformation(rawVolumeNameBuffer, rawVolumeNameSize, rawVolumeSerialNumber, rawMaximumComponentLength, rawFileSystemFlags, rawFileSystemNameBuffer, rawFileSystemNameSize, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getVolumeInformation(rawVolumeNameBuffer, rawVolumeNameSize, rawVolumeSerialNumber, rawMaximumComponentLength, rawFileSystemFlags, rawFileSystemNameBuffer, rawFileSystemNameSize, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("getVolumeInformation(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class MountedProxy implements Mounted {

@Override
public long mounted(DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.mounted(dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.mounted(dokanyFileInfo));
} catch (Exception e) {
LOG.warn("mounted(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class UnmountedProxy implements Unmounted {

@Override
public long unmounted(DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.unmounted(dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.unmounted(dokanyFileInfo));
} catch (Exception e) {
LOG.warn("unmounted(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class GetFileSecurityProxy implements GetFileSecurity {

@Override
public long callback(WString rawPath, int rawSecurityInformation, Pointer rawSecurityDescriptor, int rawSecurityDescriptorLength, IntByReference rawSecurityDescriptorLengthNeeded, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getFileSecurity(rawPath, rawSecurityInformation, rawSecurityDescriptor, rawSecurityDescriptorLength, rawSecurityDescriptorLengthNeeded, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.getFileSecurity(rawPath, rawSecurityInformation, rawSecurityDescriptor, rawSecurityDescriptorLength, rawSecurityDescriptorLengthNeeded, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("getFileSecurity(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class SetFileSecurityProxy implements SetFileSecurity {

@Override
public long callback(WString rawPath, int rawSecurityInformation, Pointer rawSecurityDescriptor, int rawSecurityDescriptorLength, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setFileSecurity(rawPath, rawSecurityInformation, rawSecurityDescriptor, rawSecurityDescriptorLength, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.setFileSecurity(rawPath, rawSecurityInformation, rawSecurityDescriptor, rawSecurityDescriptorLength, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("setFileSecurity(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

class FindStreamsProxy implements FindStreams {

@Override
public long callback(WString rawPath, FillWin32FindStreamData rawFillFindData, DokanyFileInfo dokanyFileInfo) {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.findStreams(rawPath, rawFillFindData, dokanyFileInfo));
try {
return NativeMethods.DokanNtStatusFromWin32(fileSystem.findStreams(rawPath, rawFillFindData, dokanyFileInfo));
} catch (Exception e) {
LOG.warn("findStreams(): Uncaught exception. Returning generic failure code.", e);
return NtStatus.UNSUCCESSFUL.getMask();
}
}
}

Expand Down
Loading

0 comments on commit 3909e06

Please sign in to comment.