diff options
author | Liryna <liryna.stark@gmail.com> | 2016-07-27 20:55:20 +0200 |
---|---|---|
committer | Adrien JUND <adrien.jund@islog.com> | 2016-10-20 13:39:57 +0200 |
commit | 7a0e8f66785f165d76477105c2298e03eb5d0695 (patch) | |
tree | fb48bd467a4a991fd180a110196b758f9401e151 /fs/expose/dokan/libdokan.py | |
parent | 040e18b6f8f20b9dc86d5e85797f07f86f0aeba3 (diff) | |
download | pyfilesystem-git-7a0e8f66785f165d76477105c2298e03eb5d0695.tar.gz |
Update Dokan wrapper to 1.0.0
Diffstat (limited to 'fs/expose/dokan/libdokan.py')
-rw-r--r-- | fs/expose/dokan/libdokan.py | 304 |
1 files changed, 171 insertions, 133 deletions
diff --git a/fs/expose/dokan/libdokan.py b/fs/expose/dokan/libdokan.py index 5391d2c..b848316 100644 --- a/fs/expose/dokan/libdokan.py +++ b/fs/expose/dokan/libdokan.py @@ -1,4 +1,5 @@ # Copyright (c) 2009-2010, Cloud Matrix Pty. Ltd. +# Copyright (c) 2016-2016, Adrien J. <liryna.stark@gmail.com>. # All rights reserved; available under the terms of the MIT License. """ @@ -9,41 +10,49 @@ from ctypes import * try: - DokanMain = windll.Dokan.DokanMain - DokanVersion = windll.Dokan.DokanVersion + DokanMain = windll.Dokan1.DokanMain + DokanVersion = windll.Dokan1.DokanVersion except AttributeError: raise ImportError("Dokan DLL not found") from ctypes.wintypes import * ULONG64 = c_ulonglong -ULONGLONG = c_ulonglong -PULONGLONG = POINTER(ULONGLONG) +PULONGLONG = POINTER(c_ulonglong) +PVOID = c_void_p +PULONG = POINTER(c_ulong) UCHAR = c_ubyte -LPDWORD = POINTER(DWORD) +LPDWORD = POINTER(c_ulong) LONGLONG = c_longlong - -try: - USHORT = USHORT -except NameError: - # Not available in older python versions - USHORT = c_ushort +NTSTATUS = c_long +USHORT = c_ushort +WCHAR = c_wchar DokanVersion.restype = ULONG DokanVersion.argtypes = () -if DokanVersion() < 392: # ths is release 0.5.3 +DOKAN_MINIMUM_COMPATIBLE_VERSION = 100 # this is release 1.0.0 +if DokanVersion() < DOKAN_MINIMUM_COMPATIBLE_VERSION: raise ImportError("Dokan DLL is too old") MAX_PATH = 260 +class SECURITY_DESCRIPTOR(ctypes.Structure): pass + +PSECURITY_DESCRIPTOR = ctypes.POINTER(SECURITY_DESCRIPTOR) +PPSECURITY_DESCRIPTOR = ctypes.POINTER(PSECURITY_DESCRIPTOR) + +SECURITY_INFORMATION = DWORD +PSECURITY_INFORMATION = ctypes.POINTER(SECURITY_INFORMATION) + class FILETIME(Structure): _fields_ = [ ("dwLowDateTime", DWORD), ("dwHighDateTime", DWORD), ] + class WIN32_FIND_DATAW(Structure): _fields_ = [ ("dwFileAttributes", DWORD), @@ -58,6 +67,7 @@ class WIN32_FIND_DATAW(Structure): ("cAlternateFileName", WCHAR * 14), ] + class BY_HANDLE_FILE_INFORMATION(Structure): _fields_ = [ ('dwFileAttributes', DWORD), @@ -72,12 +82,18 @@ class BY_HANDLE_FILE_INFORMATION(Structure): ('nFileIndexLow', DWORD), ] + class DOKAN_OPTIONS(Structure): _fields_ = [ - ("DriveLetter", WCHAR), - ("ThreadCount", USHORT), - ("Options", ULONG), - ("GlobalContext", ULONG64), + ("Version", USHORT), + ("ThreadCount", USHORT), + ("Options", ULONG), + ("GlobalContext", ULONG64), + ("MountPoint", LPCWSTR), + ("UNCName", LPCWSTR), + ("Timeout", ULONG), + ("AllocationUnitSize", ULONG), + ("SectorSize", ULONG), ] @@ -93,137 +109,151 @@ class DOKAN_FILE_INFO(Structure): ("SyncronousIo", UCHAR), ("Nocache", UCHAR), ("WriteToEndOfFile", UCHAR), -] + ] PDOKAN_FILE_INFO = POINTER(DOKAN_FILE_INFO) -PFillFindData = WINFUNCTYPE(c_int,POINTER(WIN32_FIND_DATAW),PDOKAN_FILE_INFO) +PFillFindData = WINFUNCTYPE(c_int, POINTER(WIN32_FIND_DATAW), PDOKAN_FILE_INFO) + class DOKAN_OPERATIONS(Structure): _fields_ = [ - ("CreateFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - DWORD, # DesiredAccess - DWORD, # ShareMode - DWORD, # CreationDisposition - DWORD, # FlagsAndAttributes - PDOKAN_FILE_INFO)), - ("OpenDirectory", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("CreateDirectory", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("Cleanup", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("CloseFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("ReadFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - POINTER(c_char), # Buffer - DWORD, # NumberOfBytesToRead - LPDWORD, # NumberOfBytesRead - LONGLONG, # Offset - PDOKAN_FILE_INFO)), - ("WriteFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - POINTER(c_char), # Buffer - DWORD, # NumberOfBytesToWrite - LPDWORD, # NumberOfBytesWritten - LONGLONG, # Offset - PDOKAN_FILE_INFO)), - ("FlushFileBuffers", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("GetFileInformation", CFUNCTYPE(c_int, - LPCWSTR, # FileName - POINTER(BY_HANDLE_FILE_INFORMATION), # Buffer - PDOKAN_FILE_INFO)), - ("FindFiles", CFUNCTYPE(c_int, - LPCWSTR, # PathName - PFillFindData, # call this function with PWIN32_FIND_DATAW - PDOKAN_FILE_INFO)), - ("FindFilesWithPattern", CFUNCTYPE(c_int, - LPCWSTR, # PathName - LPCWSTR, # SearchPattern - PFillFindData, #call this function with PWIN32_FIND_DATAW - PDOKAN_FILE_INFO)), - ("SetFileAttributes", CFUNCTYPE(c_int, - LPCWSTR, # FileName - DWORD, # FileAttributes - PDOKAN_FILE_INFO)), - ("SetFileTime", CFUNCTYPE(c_int, - LPCWSTR, # FileName - POINTER(FILETIME), # CreationTime - POINTER(FILETIME), # LastAccessTime - POINTER(FILETIME), # LastWriteTime - PDOKAN_FILE_INFO)), - ("DeleteFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("DeleteDirectory", CFUNCTYPE(c_int, - LPCWSTR, # FileName - PDOKAN_FILE_INFO)), - ("MoveFile", CFUNCTYPE(c_int, - LPCWSTR, # ExistingFileName - LPCWSTR, # NewFileName - BOOL, # ReplaceExisiting - PDOKAN_FILE_INFO)), - ("SetEndOfFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - LONGLONG, # Length - PDOKAN_FILE_INFO)), - ("SetAllocationSize", CFUNCTYPE(c_int, - LPCWSTR, # FileName - LONGLONG, # Length - PDOKAN_FILE_INFO)), - ("LockFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - LONGLONG, # ByteOffset - LONGLONG, # Length - PDOKAN_FILE_INFO)), - ("UnlockFile", CFUNCTYPE(c_int, - LPCWSTR, # FileName - LONGLONG, # ByteOffset - LONGLONG, # Length - PDOKAN_FILE_INFO)), - ("GetDiskFreeSpaceEx", CFUNCTYPE(c_int, - PULONGLONG, # FreeBytesAvailable - PULONGLONG, # TotalNumberOfBytes - PULONGLONG, # TotalNumberOfFreeBytes - PDOKAN_FILE_INFO)), - ("GetVolumeInformation", CFUNCTYPE(c_int, - POINTER(c_wchar), # VolumeNameBuffer - DWORD, # VolumeNameSize in num of chars - LPDWORD, # VolumeSerialNumber - LPDWORD, # MaximumComponentLength in num of chars - LPDWORD, # FileSystemFlags - POINTER(c_wchar), # FileSystemNameBuffer - DWORD, # FileSystemNameSize in num of chars - PDOKAN_FILE_INFO)), - ("Unmount", CFUNCTYPE(c_int, - PDOKAN_FILE_INFO)), + ("ZwCreateFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PVOID, # SecurityContext, see + # https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx + DWORD, # DesiredAccess + ULONG, # FileAttributes + ULONG, # ShareAccess + ULONG, # CreateDisposition + ULONG, # CreateOptions + PDOKAN_FILE_INFO)), + ("Cleanup", WINFUNCTYPE(None, + LPCWSTR, # FileName + PDOKAN_FILE_INFO)), + ("CloseFile", WINFUNCTYPE(None, + LPCWSTR, # FileName + PDOKAN_FILE_INFO)), + ("ReadFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + LPVOID, # Buffer + DWORD, # NumberOfBytesToRead + LPDWORD, # NumberOfBytesRead + LONGLONG, # Offset + PDOKAN_FILE_INFO)), + ("WriteFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + LPCVOID, # Buffer + DWORD, # NumberOfBytesToWrite + LPDWORD, # NumberOfBytesWritten + LONGLONG, # Offset + PDOKAN_FILE_INFO)), + ("FlushFileBuffers", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PDOKAN_FILE_INFO)), + ("GetFileInformation", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + POINTER(BY_HANDLE_FILE_INFORMATION), # Buffer + PDOKAN_FILE_INFO)), + ("FindFiles", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # PathName + PFillFindData, # call this function with PWIN32_FIND_DATAW + PDOKAN_FILE_INFO)), + ("FindFilesWithPattern", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # PathName + LPCWSTR, # SearchPattern + PFillFindData, #call this function with PWIN32_FIND_DATAW + PDOKAN_FILE_INFO)), + ("SetFileAttributes", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + DWORD, # FileAttributes + PDOKAN_FILE_INFO)), + ("SetFileTime", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + POINTER(FILETIME), # CreationTime + POINTER(FILETIME), # LastAccessTime + POINTER(FILETIME), # LastWriteTime + PDOKAN_FILE_INFO)), + ("DeleteFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PDOKAN_FILE_INFO)), + ("DeleteDirectory", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PDOKAN_FILE_INFO)), + ("MoveFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # ExistingFileName + LPCWSTR, # NewFileName + BOOL, # ReplaceExisiting + PDOKAN_FILE_INFO)), + ("SetEndOfFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + LONGLONG, # Length + PDOKAN_FILE_INFO)), + ("SetAllocationSize", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + LONGLONG, # Length + PDOKAN_FILE_INFO)), + ("LockFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + LONGLONG, # ByteOffset + LONGLONG, # Length + PDOKAN_FILE_INFO)), + ("UnlockFile", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + LONGLONG, # ByteOffset + LONGLONG, # Length + PDOKAN_FILE_INFO)), + ("GetDiskFreeSpace", WINFUNCTYPE(NTSTATUS, + PULONGLONG, # FreeBytesAvailable + PULONGLONG, # TotalNumberOfBytes + PULONGLONG, # TotalNumberOfFreeBytes + PDOKAN_FILE_INFO)), + ("GetVolumeInformation", WINFUNCTYPE(NTSTATUS, + PVOID, # VolumeNameBuffer + DWORD, # VolumeNameSize in num of chars + LPDWORD, # VolumeSerialNumber + LPDWORD, # MaximumComponentLength in num of chars + LPDWORD, # FileSystemFlags + PVOID, # FileSystemNameBuffer + DWORD, # FileSystemNameSize in num of chars + PDOKAN_FILE_INFO)), + ("Mounted", WINFUNCTYPE(NTSTATUS, + PDOKAN_FILE_INFO)), + ("Unmounted", WINFUNCTYPE(NTSTATUS, + DOKAN_FILE_INFO)), + ("GetFileSecurity", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PULONG, # A pointer to SECURITY_INFORMATION value being requested + PVOID, # A pointer to SECURITY_DESCRIPTOR buffer to be filled + ULONG, # Length of Security descriptor buffer + PULONG, # Length Needed + PDOKAN_FILE_INFO)), + ("SetFileSecurity", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PVOID, # A pointer to SECURITY_INFORMATION value being + PVOID, # A pointer to SECURITY_DESCRIPTOR buffer + ULONG, # Length of Security descriptor buffer + PDOKAN_FILE_INFO)), + ("FindStreams", WINFUNCTYPE(NTSTATUS, + LPCWSTR, # FileName + PVOID, # call this function with PWIN32_FIND_STREAM_DATA + PDOKAN_FILE_INFO)) ] - DokanMain.restype = c_int DokanMain.argtypes = ( POINTER(DOKAN_OPTIONS), POINTER(DOKAN_OPERATIONS), ) - - -DokanUnmount = windll.Dokan.DokanUnmount -DokanUnmount.restype = BOOL -DokanUnmount.argtypes = ( - WCHAR, +DokanRemoveMountPoint = windll.Dokan1.DokanRemoveMountPoint +DokanRemoveMountPoint.restype = BOOL +DokanRemoveMountPoint.argtypes = ( + LPCWSTR, ) -DokanIsNameInExpression = windll.Dokan.DokanIsNameInExpression +DokanIsNameInExpression = windll.Dokan1.DokanIsNameInExpression DokanIsNameInExpression.restype = BOOL DokanIsNameInExpression.argtypes = ( LPCWSTR, # pattern @@ -231,16 +261,24 @@ DokanIsNameInExpression.argtypes = ( BOOL, # ignore case ) -DokanDriverVersion = windll.Dokan.DokanDriverVersion +DokanDriverVersion = windll.Dokan1.DokanDriverVersion DokanDriverVersion.restype = ULONG DokanDriverVersion.argtypes = ( ) -DokanResetTimeout = windll.Dokan.DokanResetTimeout +DokanResetTimeout = windll.Dokan1.DokanResetTimeout DokanResetTimeout.restype = BOOL DokanResetTimeout.argtypes = ( ULONG, #timeout PDOKAN_FILE_INFO, # file info pointer ) - +GetFileSecurity = ctypes.windll.advapi32.GetFileSecurityW +GetFileSecurity.restype = BOOL +GetFileSecurity.argtypes = ( + LPWSTR, # _In_ LPCTSTR lpFileName, + SECURITY_INFORMATION, # _In_ SECURITY_INFORMATION RequestedInformation, + PSECURITY_DESCRIPTOR, # _Out_opt_ PSECURITY_DESCRIPTOR pSecurityDescriptor, + DWORD, # _In_ DWORD nLength, + LPDWORD, # _Out_ LPDWORD lpnLengthNeeded +) |