Class ReadWriteAdapter
- All Implemented Interfaces:
DokanyFileSystem
-
Constructor Summary
ConstructorsConstructorDescriptionReadWriteAdapter(Path root, LockManager lockManager, VolumeInformation volumeInformation) ReadWriteAdapter(Path fileSystemRoot, LockManager lockManager, VolumeInformation volumeInfo, AtomicReference<SafeUnmountCheck> safeUnmountCheck) Creates a new ReadWriteAdapter with the given Path as root and adds to the OpenHandleCheckBuilder the check if the OpenHandleFactory is empty or not. -
Method Summary
Modifier and TypeMethodDescriptionvoidcleanup(com.sun.jna.WString rawPath, DokanyFileInfo dokanyFileInfo) The handle is closed in this method, due to the requirements of the dokany implementation to delete a file in the cleanUp methodvoidcloseFile(com.sun.jna.WString rawPath, DokanyFileInfo dokanyFileInfo) CloseFile is called at the end of the life of the context.intdeleteDirectory(com.sun.jna.WString rawPath, DokanyFileInfo dokanyFileInfo) Check if it is possible to delete a directory.intdeleteFile(com.sun.jna.WString rawPath, DokanyFileInfo dokanyFileInfo) Check if it is possible to delete a file.voidfillWin32FindData(com.sun.jna.platform.win32.WinBase.WIN32_FIND_DATA rawFillFindData, DokanyFileInfo dokanyFileInfo) intfindFiles(com.sun.jna.WString rawPath, DokanyOperations.FillWin32FindData rawFillFindData, DokanyFileInfo dokanyFileInfo) List all files in the path requested.intfindFilesWithPattern(com.sun.jna.WString fileName, com.sun.jna.WString searchPattern, DokanyOperations.FillWin32FindData rawFillFindData, DokanyFileInfo dokanyFileInfo) Same asDokanyFileSystem.findFiles(WString, DokanyOperations.FillWin32FindData, DokanyFileInfo)but with a search pattern to filter the result.intfindStreams(com.sun.jna.WString rawPath, DokanyOperations.FillWin32FindStreamData rawFillFindData, DokanyFileInfo dokanyFileInfo) Retrieve all NTFS Streams informations on the file.intflushFileBuffers(com.sun.jna.WString rawPath, DokanyFileInfo dokanyFileInfo) Clears buffers for this context and causes any buffered data to be written to the file.intgetDiskFreeSpace(com.sun.jna.ptr.LongByReference freeBytesAvailable, com.sun.jna.ptr.LongByReference totalNumberOfBytes, com.sun.jna.ptr.LongByReference totalNumberOfFreeBytes, DokanyFileInfo dokanyFileInfo) Retrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.intgetFileInformation(com.sun.jna.WString fileName, ByHandleFileInfo handleFileInfo, DokanyFileInfo dokanyFileInfo) Get specific informations on a file.intgetFileSecurity(com.sun.jna.WString rawPath, int rawSecurityInformation, com.sun.jna.Pointer rawSecurityDescriptor, int rawSecurityDescriptorLength, com.sun.jna.ptr.IntByReference rawSecurityDescriptorLengthNeeded, DokanyFileInfo dokanyFileInfo) Not implemented, handled in proxy.intgetVolumeInformation(com.sun.jna.Pointer rawVolumeNameBuffer, int rawVolumeNameSize, com.sun.jna.ptr.IntByReference rawVolumeSerialNumber, com.sun.jna.ptr.IntByReference rawMaximumComponentLength, com.sun.jna.ptr.IntByReference rawFileSystemFlags, com.sun.jna.Pointer rawFileSystemNameBuffer, int rawFileSystemNameSize, DokanyFileInfo dokanyFileInfo) TODO: this method is copy pasta.intlockFile(com.sun.jna.WString rawPath, long rawByteOffset, long rawLength, DokanyFileInfo dokanyFileInfo) Lock file at a specific offset and data length.intmounted(DokanyFileInfo dokanyFileInfo) Is called when Dokany succeeded mounting the volume.intmoveFile(com.sun.jna.WString rawPath, com.sun.jna.WString rawNewFileName, boolean rawReplaceIfExisting, DokanyFileInfo dokanyFileInfo) Move a file or directory to a new location.intreadFile(com.sun.jna.WString rawPath, com.sun.jna.Pointer rawBuffer, int rawBufferLength, com.sun.jna.ptr.IntByReference rawReadLength, long rawOffset, DokanyFileInfo dokanyFileInfo) ReadFile callback on the file previously opened inDokanyFileSystem.zwCreateFile(WString, WinBase.SECURITY_ATTRIBUTES, int, int, int, int, int, DokanyFileInfo).intsetAllocationSize(com.sun.jna.WString rawPath, long rawLength, DokanyFileInfo dokanyFileInfo) SetAllocationSize is used to truncate or extend a file.intsetEndOfFile(com.sun.jna.WString rawPath, long rawByteOffset, DokanyFileInfo dokanyFileInfo) SetEndOfFile is used to truncate or extend a file (physical file size).intsetFileAttributes(com.sun.jna.WString rawPath, int rawAttributes, DokanyFileInfo dokanyFileInfo) Set file attributes on a specific file.intsetFileSecurity(com.sun.jna.WString rawPath, int rawSecurityInformation, com.sun.jna.Pointer rawSecurityDescriptor, int rawSecurityDescriptorLength, DokanyFileInfo dokanyFileInfo) Sets the security of a file or directory object.intsetFileTime(com.sun.jna.WString rawPath, com.sun.jna.platform.win32.WinBase.FILETIME rawCreationTime, com.sun.jna.platform.win32.WinBase.FILETIME rawLastAccessTime, com.sun.jna.platform.win32.WinBase.FILETIME rawLastWriteTime, DokanyFileInfo dokanyFileInfo) Set file times on a specific file.intunlockFile(com.sun.jna.WString rawPath, long rawByteOffset, long rawLength, DokanyFileInfo dokanyFileInfo) Unlock file at a specific offset and data length.intunmounted(DokanyFileInfo dokanyFileInfo) Is called when Dokany succeeded unmounting the volume.intwriteFile(com.sun.jna.WString rawPath, com.sun.jna.Pointer rawBuffer, int rawNumberOfBytesToWrite, com.sun.jna.ptr.IntByReference rawNumberOfBytesWritten, long rawOffset, DokanyFileInfo dokanyFileInfo) WriteFile callback on the file previously opened inDokanyFileSystem.zwCreateFile(WString, WinBase.SECURITY_ATTRIBUTES, int, int, int, int, int, DokanyFileInfo)It can be called by different thread at the same time, therefore the write/context has to be thread safe.intzwCreateFile(com.sun.jna.WString rawPath, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanyFileInfo dokanyFileInfo) CreateFile Dokan API callback.
-
Constructor Details
-
ReadWriteAdapter
-
ReadWriteAdapter
public ReadWriteAdapter(Path fileSystemRoot, LockManager lockManager, VolumeInformation volumeInfo, AtomicReference<SafeUnmountCheck> safeUnmountCheck) Creates a new ReadWriteAdapter with the given Path as root and adds to the OpenHandleCheckBuilder the check if the OpenHandleFactory is empty or not.- Parameters:
fileSystemRoot-lockManager-volumeInfo-safeUnmountCheck-
-
-
Method Details
-
zwCreateFile
public int zwCreateFile(com.sun.jna.WString rawPath, com.sun.jna.platform.win32.WinBase.SECURITY_ATTRIBUTES securityContext, int rawDesiredAccess, int rawFileAttributes, int rawShareAccess, int rawCreateDisposition, int rawCreateOptions, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemCreateFile Dokan API callback. CreateFile is called each time a request is made on a file system object. In case OPEN_ALWAYS & CREATE_ALWAYS are successfully opening an existing file, STATUS_OBJECT_NAME_COLLISION should be returned instead of STATUS_SUCCESS . This will inform Dokan that the file has been opened and not created during the request. If the file is a directory, CreateFile is also called. In this case, CreateFile should returnNtStatus.SUCCESSwhen that directory can be opened andDokanyFileInfo.IsDirectoryhas to be set to TRUE. On the other hand, ifDokanyFileInfo.IsDirectoryis set to TRUE but the path targets a file,NtStatus.NOT_A_DIRECTORYmust be returned.DokanyFileInfo.Contextcan be used to store Data (like a filehandle) that can be retrieved in all other requests related to the Context. To avoid memory leak, Context needs to be released inDokanyFileSystem.cleanup(WString, DokanyFileInfo).- Specified by:
zwCreateFilein interfaceDokanyFileSystem- Parameters:
rawPath- Path requested by the Kernel on the File System. TODO: rewrite this parameter description to link to winBasesecurityContext- the security context of the kernel (see also in the windows driver API IO_SECURITY_CONTEXT)rawDesiredAccess- Permissions for file or directory. (see also in the windows API ACCESS_MASKrawFileAttributes- Provides attributes for files and directories. (see also in the .NET API System.IO.FileAttributes}rawShareAccess- Type of share access to other threads. Device and intermediate drivers usually set ShareAccess to zero, which gives the caller exclusive access to the open file.rawCreateDisposition- Specifies the action to perform if the file does or does not exist. Can be translated into a readable thing viaCreationDispositionrawCreateOptions- Specifies the options to apply when the driver creates or opens the file. (see also in the .NET API System.IO.FileOptions)dokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
- integer code of a
NtStatus - See Also:
-
cleanup
The handle is closed in this method, due to the requirements of the dokany implementation to delete a file in the cleanUp method- Specified by:
cleanupin interfaceDokanyFileSystem- Parameters:
rawPath-dokanyFileInfo-DokanyFileInfowith information about the file or directory.
-
closeFile
Description copied from interface:DokanyFileSystemCloseFile is called at the end of the life of the context. Receipt of this request indicates that the last handle of the file object that is associated with the target device object has been closed and released. All outstanding I/O requests have been completed or canceled.CloseFile is requested after
DokanyFileSystem.cleanup(WString, DokanyFileInfo)is called. Anything remaining inDokanyFileInfo.Contexthas to be cleared before return.- Specified by:
closeFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.
-
readFile
public int readFile(com.sun.jna.WString rawPath, com.sun.jna.Pointer rawBuffer, int rawBufferLength, com.sun.jna.ptr.IntByReference rawReadLength, long rawOffset, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemReadFile callback on the file previously opened inDokanyFileSystem.zwCreateFile(WString, WinBase.SECURITY_ATTRIBUTES, int, int, int, int, int, DokanyFileInfo). It can be called by different thread at the same time, therefore the read has to be thread safe.- Specified by:
readFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
writeFile
public int writeFile(com.sun.jna.WString rawPath, com.sun.jna.Pointer rawBuffer, int rawNumberOfBytesToWrite, com.sun.jna.ptr.IntByReference rawNumberOfBytesWritten, long rawOffset, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemWriteFile callback on the file previously opened inDokanyFileSystem.zwCreateFile(WString, WinBase.SECURITY_ATTRIBUTES, int, int, int, int, int, DokanyFileInfo)It can be called by different thread at the same time, therefore the write/context has to be thread safe.- Specified by:
writeFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
flushFileBuffers
Description copied from interface:DokanyFileSystemClears buffers for this context and causes any buffered data to be written to the file.- Specified by:
flushFileBuffersin interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
getFileInformation
public int getFileInformation(com.sun.jna.WString fileName, ByHandleFileInfo handleFileInfo, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemGet specific informations on a file.- Specified by:
getFileInformationin interfaceDokanyFileSystem- Parameters:
fileName-handleFileInfo-dokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
-
findFiles
public int findFiles(com.sun.jna.WString rawPath, DokanyOperations.FillWin32FindData rawFillFindData, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemList all files in the path requested.- Specified by:
findFilesin interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
findFilesWithPattern
public int findFilesWithPattern(com.sun.jna.WString fileName, com.sun.jna.WString searchPattern, DokanyOperations.FillWin32FindData rawFillFindData, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemSame asDokanyFileSystem.findFiles(WString, DokanyOperations.FillWin32FindData, DokanyFileInfo)but with a search pattern to filter the result.- Specified by:
findFilesWithPatternin interfaceDokanyFileSystem- Parameters:
fileName-searchPattern-rawFillFindData-dokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
-
setFileAttributes
public int setFileAttributes(com.sun.jna.WString rawPath, int rawAttributes, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemSet file attributes on a specific file.- Specified by:
setFileAttributesin interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
setFileTime
public int setFileTime(com.sun.jna.WString rawPath, com.sun.jna.platform.win32.WinBase.FILETIME rawCreationTime, com.sun.jna.platform.win32.WinBase.FILETIME rawLastAccessTime, com.sun.jna.platform.win32.WinBase.FILETIME rawLastWriteTime, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemSet file times on a specific file.- Specified by:
setFileTimein interfaceDokanyFileSystem- Parameters:
rawPath- path to file or directoryrawCreationTime- time of creationrawLastAccessTime- time of last accessrawLastWriteTime- time of last modificationdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
deleteFile
Description copied from interface:DokanyFileSystemCheck if it is possible to delete a file.You should NOT delete the file in this method, but instead you must only check whether you can delete the file or not, and return
NtStatus.SUCCESS(when you can delete it) or appropriate error codes such asNtStatus.ACCESS_DENIED,NtStatus.OBJECT_NO_LONGER_EXISTS,NtStatus.OBJECT_NAME_NOT_FOUND.DokanyFileSystem.deleteFile(WString, DokanyFileInfo)will also be called withDokanyFileInfo.DeleteOnCloseset to false to notify the driver when the file is no longer requested to be deleted.When you return
NtStatus.SUCCESS, you get aDokanyFileSystem.cleanup(WString, DokanyFileInfo)call afterwards withDokanyFileInfo.DeleteOnCloseset to true and only then you have to actually delete the file being closed.- Specified by:
deleteFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file.- Returns:
NtStatus- See Also:
-
deleteDirectory
Description copied from interface:DokanyFileSystemCheck if it is possible to delete a directory.- Specified by:
deleteDirectoryin interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the directory.- Returns:
NtStatus- See Also:
-
moveFile
public int moveFile(com.sun.jna.WString rawPath, com.sun.jna.WString rawNewFileName, boolean rawReplaceIfExisting, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemMove a file or directory to a new location.- Specified by:
moveFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
setEndOfFile
public int setEndOfFile(com.sun.jna.WString rawPath, long rawByteOffset, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemSetEndOfFile is used to truncate or extend a file (physical file size).- Specified by:
setEndOfFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
setAllocationSize
public int setAllocationSize(com.sun.jna.WString rawPath, long rawLength, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemSetAllocationSize is used to truncate or extend a file.- Specified by:
setAllocationSizein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
lockFile
public int lockFile(com.sun.jna.WString rawPath, long rawByteOffset, long rawLength, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemLock file at a specific offset and data length. This is only used ifDokanOption.FILELOCK_USER_MODEis enabled.- Specified by:
lockFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
unlockFile
public int unlockFile(com.sun.jna.WString rawPath, long rawByteOffset, long rawLength, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemUnlock file at a specific offset and data length. This is only used ifDokanOption.FILELOCK_USER_MODEis enabled.- Specified by:
unlockFilein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
getDiskFreeSpace
public int getDiskFreeSpace(com.sun.jna.ptr.LongByReference freeBytesAvailable, com.sun.jna.ptr.LongByReference totalNumberOfBytes, com.sun.jna.ptr.LongByReference totalNumberOfFreeBytes, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemRetrieves information about the amount of space that is available on a disk volume, which is the total amount of space, the total amount of free space, and the total amount of free space available to the user that is associated with the calling thread.Neither this method nor
DokanyFileSystem.getVolumeInformation(Pointer, int, IntByReference, IntByReference, IntByReference, Pointer, int, DokanyFileInfo)save theDokanyFileInfo.Context. Before these methods are called,DokanyFileSystem.zwCreateFile(WString, WinBase.SECURITY_ATTRIBUTES, int, int, int, int, int, DokanyFileInfo)may not be called. (ditto @{link DokanyOperations.CloseFile} and @{link DokanyOperations.Cleanup}).- Specified by:
getDiskFreeSpacein interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
getVolumeInformation
public int getVolumeInformation(com.sun.jna.Pointer rawVolumeNameBuffer, int rawVolumeNameSize, com.sun.jna.ptr.IntByReference rawVolumeSerialNumber, com.sun.jna.ptr.IntByReference rawMaximumComponentLength, com.sun.jna.ptr.IntByReference rawFileSystemFlags, com.sun.jna.Pointer rawFileSystemNameBuffer, int rawFileSystemNameSize, DokanyFileInfo dokanyFileInfo) TODO: this method is copy pasta. Check it!- Specified by:
getVolumeInformationin interfaceDokanyFileSystem- Parameters:
rawVolumeNameBuffer-rawVolumeNameSize-rawVolumeSerialNumber-rawMaximumComponentLength-rawFileSystemFlags-rawFileSystemNameBuffer-rawFileSystemNameSize-dokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
-
mounted
Description copied from interface:DokanyFileSystemIs called when Dokany succeeded mounting the volume.- Specified by:
mountedin interfaceDokanyFileSystem
-
unmounted
Description copied from interface:DokanyFileSystemIs called when Dokany succeeded unmounting the volume.- Specified by:
unmountedin interfaceDokanyFileSystem
-
getFileSecurity
public int getFileSecurity(com.sun.jna.WString rawPath, int rawSecurityInformation, com.sun.jna.Pointer rawSecurityDescriptor, int rawSecurityDescriptorLength, com.sun.jna.ptr.IntByReference rawSecurityDescriptorLengthNeeded, DokanyFileInfo dokanyFileInfo) Not implemented, handled in proxy.- Specified by:
getFileSecurityin interfaceDokanyFileSystem- Parameters:
rawPath-rawSecurityInformation-rawSecurityDescriptor-rawSecurityDescriptorLength-rawSecurityDescriptorLengthNeeded-dokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
-
setFileSecurity
public int setFileSecurity(com.sun.jna.WString rawPath, int rawSecurityInformation, com.sun.jna.Pointer rawSecurityDescriptor, int rawSecurityDescriptorLength, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemSets the security of a file or directory object.Supported since version 0.6.0. You must specify the version in
DeviceOptions.Version.- Specified by:
setFileSecurityin interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-
fillWin32FindData
public void fillWin32FindData(com.sun.jna.platform.win32.WinBase.WIN32_FIND_DATA rawFillFindData, DokanyFileInfo dokanyFileInfo) - Specified by:
fillWin32FindDatain interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.
-
findStreams
public int findStreams(com.sun.jna.WString rawPath, DokanyOperations.FillWin32FindStreamData rawFillFindData, DokanyFileInfo dokanyFileInfo) Description copied from interface:DokanyFileSystemRetrieve all NTFS Streams informations on the file. This is only called ifDokanOption.ALT_STREAMis enabled.- Specified by:
findStreamsin interfaceDokanyFileSystemdokanyFileInfo-DokanyFileInfowith information about the file or directory.- Returns:
NtStatus
-