Skip to content

Commit be2afb4

Browse files
author
Adrien JUND
committed
Move to import ctypes
1 parent e76d018 commit be2afb4

1 file changed

Lines changed: 57 additions & 58 deletions

File tree

fs/expose/dokan/libdokan.py

Lines changed: 57 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,25 @@
88
"""
99

1010
import ctypes
11-
from ctypes import *
1211

1312
try:
14-
DokanMain = windll.Dokan1.DokanMain
15-
DokanVersion = windll.Dokan1.DokanVersion
13+
DokanMain = ctypes.windll.Dokan1.DokanMain
14+
DokanVersion = ctypes.windll.Dokan1.DokanVersion
1615
except AttributeError:
1716
raise ImportError("Dokan DLL not found")
1817

1918

2019
from ctypes.wintypes import *
21-
ULONG64 = c_ulonglong
22-
PULONGLONG = POINTER(c_ulonglong)
23-
PVOID = c_void_p
24-
PULONG = POINTER(c_ulong)
25-
UCHAR = c_ubyte
26-
LPDWORD = POINTER(c_ulong)
27-
LONGLONG = c_longlong
28-
NTSTATUS = c_long
29-
USHORT = c_ushort
30-
WCHAR = c_wchar
20+
ULONG64 = ctypes.c_ulonglong
21+
PULONGLONG = ctypes.POINTER(ctypes.c_ulonglong)
22+
PVOID = ctypes.c_void_p
23+
PULONG = ctypes.POINTER(ctypes.c_ulong)
24+
UCHAR = ctypes.c_ubyte
25+
LPDWORD = ctypes.POINTER(ctypes.c_ulong)
26+
LONGLONG = ctypes.c_longlong
27+
NTSTATUS = ctypes.c_long
28+
USHORT = ctypes.c_ushort
29+
WCHAR = ctypes.c_wchar
3130

3231

3332
DokanVersion.restype = ULONG
@@ -47,14 +46,14 @@ class SECURITY_DESCRIPTOR(ctypes.Structure): pass
4746
SECURITY_INFORMATION = DWORD
4847
PSECURITY_INFORMATION = ctypes.POINTER(SECURITY_INFORMATION)
4948

50-
class FILETIME(Structure):
49+
class FILETIME(ctypes.Structure):
5150
_fields_ = [
5251
("dwLowDateTime", DWORD),
5352
("dwHighDateTime", DWORD),
5453
]
5554

5655

57-
class WIN32_FIND_DATAW(Structure):
56+
class WIN32_FIND_DATAW(ctypes.Structure):
5857
_fields_ = [
5958
("dwFileAttributes", DWORD),
6059
("ftCreationTime", FILETIME),
@@ -69,7 +68,7 @@ class WIN32_FIND_DATAW(Structure):
6968
]
7069

7170

72-
class BY_HANDLE_FILE_INFORMATION(Structure):
71+
class BY_HANDLE_FILE_INFORMATION(ctypes.Structure):
7372
_fields_ = [
7473
('dwFileAttributes', DWORD),
7574
('ftCreationTime', FILETIME),
@@ -84,7 +83,7 @@ class BY_HANDLE_FILE_INFORMATION(Structure):
8483
]
8584

8685

87-
class DOKAN_OPTIONS(Structure):
86+
class DOKAN_OPTIONS(ctypes.Structure):
8887
_fields_ = [
8988
("Version", USHORT),
9089
("ThreadCount", USHORT),
@@ -98,11 +97,11 @@ class DOKAN_OPTIONS(Structure):
9897
]
9998

10099

101-
class DOKAN_FILE_INFO(Structure):
100+
class DOKAN_FILE_INFO(ctypes.Structure):
102101
_fields_ = [
103102
("Context", ULONG64),
104103
("DokanContext", ULONG64),
105-
("DokanOptions", POINTER(DOKAN_OPTIONS)),
104+
("DokanOptions", ctypes.POINTER(DOKAN_OPTIONS)),
106105
("ProcessId", ULONG),
107106
("IsDirectory", UCHAR),
108107
("DeleteOnClose", UCHAR),
@@ -113,13 +112,13 @@ class DOKAN_FILE_INFO(Structure):
113112
]
114113

115114

116-
PDOKAN_FILE_INFO = POINTER(DOKAN_FILE_INFO)
117-
PFillFindData = WINFUNCTYPE(c_int, POINTER(WIN32_FIND_DATAW), PDOKAN_FILE_INFO)
115+
PDOKAN_FILE_INFO = ctypes.POINTER(DOKAN_FILE_INFO)
116+
PFillFindData = ctypes.WINFUNCTYPE(ctypes.c_int, ctypes.POINTER(WIN32_FIND_DATAW), PDOKAN_FILE_INFO)
118117

119118

120-
class DOKAN_OPERATIONS(Structure):
119+
class DOKAN_OPERATIONS(ctypes.Structure):
121120
_fields_ = [
122-
("ZwCreateFile", WINFUNCTYPE(NTSTATUS,
121+
("ZwCreateFile", ctypes.WINFUNCTYPE(NTSTATUS,
123122
LPCWSTR, # FileName
124123
PVOID, # SecurityContext, see
125124
# https://msdn.microsoft.com/en-us/library/windows/hardware/ff550613(v=vs.85).aspx
@@ -129,87 +128,87 @@ class DOKAN_OPERATIONS(Structure):
129128
ULONG, # CreateDisposition
130129
ULONG, # CreateOptions
131130
PDOKAN_FILE_INFO)),
132-
("Cleanup", WINFUNCTYPE(None,
131+
("Cleanup", ctypes.WINFUNCTYPE(None,
133132
LPCWSTR, # FileName
134133
PDOKAN_FILE_INFO)),
135-
("CloseFile", WINFUNCTYPE(None,
134+
("CloseFile", ctypes.WINFUNCTYPE(None,
136135
LPCWSTR, # FileName
137136
PDOKAN_FILE_INFO)),
138-
("ReadFile", WINFUNCTYPE(NTSTATUS,
137+
("ReadFile", ctypes.WINFUNCTYPE(NTSTATUS,
139138
LPCWSTR, # FileName
140139
LPVOID, # Buffer
141140
DWORD, # NumberOfBytesToRead
142141
LPDWORD, # NumberOfBytesRead
143142
LONGLONG, # Offset
144143
PDOKAN_FILE_INFO)),
145-
("WriteFile", WINFUNCTYPE(NTSTATUS,
144+
("WriteFile", ctypes.WINFUNCTYPE(NTSTATUS,
146145
LPCWSTR, # FileName
147146
LPCVOID, # Buffer
148147
DWORD, # NumberOfBytesToWrite
149148
LPDWORD, # NumberOfBytesWritten
150149
LONGLONG, # Offset
151150
PDOKAN_FILE_INFO)),
152-
("FlushFileBuffers", WINFUNCTYPE(NTSTATUS,
151+
("FlushFileBuffers", ctypes.WINFUNCTYPE(NTSTATUS,
153152
LPCWSTR, # FileName
154153
PDOKAN_FILE_INFO)),
155-
("GetFileInformation", WINFUNCTYPE(NTSTATUS,
154+
("GetFileInformation", ctypes.WINFUNCTYPE(NTSTATUS,
156155
LPCWSTR, # FileName
157-
POINTER(BY_HANDLE_FILE_INFORMATION), # Buffer
156+
ctypes.POINTER(BY_HANDLE_FILE_INFORMATION), # Buffer
158157
PDOKAN_FILE_INFO)),
159-
("FindFiles", WINFUNCTYPE(NTSTATUS,
158+
("FindFiles", ctypes.WINFUNCTYPE(NTSTATUS,
160159
LPCWSTR, # PathName
161160
PFillFindData, # call this function with PWIN32_FIND_DATAW
162161
PDOKAN_FILE_INFO)),
163-
("FindFilesWithPattern", WINFUNCTYPE(NTSTATUS,
162+
("FindFilesWithPattern", ctypes.WINFUNCTYPE(NTSTATUS,
164163
LPCWSTR, # PathName
165164
LPCWSTR, # SearchPattern
166165
PFillFindData, #call this function with PWIN32_FIND_DATAW
167166
PDOKAN_FILE_INFO)),
168-
("SetFileAttributes", WINFUNCTYPE(NTSTATUS,
167+
("SetFileAttributes", ctypes.WINFUNCTYPE(NTSTATUS,
169168
LPCWSTR, # FileName
170169
DWORD, # FileAttributes
171170
PDOKAN_FILE_INFO)),
172-
("SetFileTime", WINFUNCTYPE(NTSTATUS,
171+
("SetFileTime", ctypes.WINFUNCTYPE(NTSTATUS,
173172
LPCWSTR, # FileName
174-
POINTER(FILETIME), # CreationTime
175-
POINTER(FILETIME), # LastAccessTime
176-
POINTER(FILETIME), # LastWriteTime
173+
ctypes.POINTER(FILETIME), # CreationTime
174+
ctypes.POINTER(FILETIME), # LastAccessTime
175+
ctypes.POINTER(FILETIME), # LastWriteTime
177176
PDOKAN_FILE_INFO)),
178-
("DeleteFile", WINFUNCTYPE(NTSTATUS,
177+
("DeleteFile", ctypes.WINFUNCTYPE(NTSTATUS,
179178
LPCWSTR, # FileName
180179
PDOKAN_FILE_INFO)),
181-
("DeleteDirectory", WINFUNCTYPE(NTSTATUS,
180+
("DeleteDirectory", ctypes.WINFUNCTYPE(NTSTATUS,
182181
LPCWSTR, # FileName
183182
PDOKAN_FILE_INFO)),
184-
("MoveFile", WINFUNCTYPE(NTSTATUS,
183+
("MoveFile", ctypes.WINFUNCTYPE(NTSTATUS,
185184
LPCWSTR, # ExistingFileName
186185
LPCWSTR, # NewFileName
187186
BOOL, # ReplaceExisiting
188187
PDOKAN_FILE_INFO)),
189-
("SetEndOfFile", WINFUNCTYPE(NTSTATUS,
188+
("SetEndOfFile", ctypes.WINFUNCTYPE(NTSTATUS,
190189
LPCWSTR, # FileName
191190
LONGLONG, # Length
192191
PDOKAN_FILE_INFO)),
193-
("SetAllocationSize", WINFUNCTYPE(NTSTATUS,
192+
("SetAllocationSize", ctypes.WINFUNCTYPE(NTSTATUS,
194193
LPCWSTR, # FileName
195194
LONGLONG, # Length
196195
PDOKAN_FILE_INFO)),
197-
("LockFile", WINFUNCTYPE(NTSTATUS,
196+
("LockFile", ctypes.WINFUNCTYPE(NTSTATUS,
198197
LPCWSTR, # FileName
199198
LONGLONG, # ByteOffset
200199
LONGLONG, # Length
201200
PDOKAN_FILE_INFO)),
202-
("UnlockFile", WINFUNCTYPE(NTSTATUS,
201+
("UnlockFile", ctypes.WINFUNCTYPE(NTSTATUS,
203202
LPCWSTR, # FileName
204203
LONGLONG, # ByteOffset
205204
LONGLONG, # Length
206205
PDOKAN_FILE_INFO)),
207-
("GetDiskFreeSpace", WINFUNCTYPE(NTSTATUS,
206+
("GetDiskFreeSpace", ctypes.WINFUNCTYPE(NTSTATUS,
208207
PULONGLONG, # FreeBytesAvailable
209208
PULONGLONG, # TotalNumberOfBytes
210209
PULONGLONG, # TotalNumberOfFreeBytes
211210
PDOKAN_FILE_INFO)),
212-
("GetVolumeInformation", WINFUNCTYPE(NTSTATUS,
211+
("GetVolumeInformation", ctypes.WINFUNCTYPE(NTSTATUS,
213212
PVOID, # VolumeNameBuffer
214213
DWORD, # VolumeNameSize in num of chars
215214
LPDWORD, # VolumeSerialNumber
@@ -218,56 +217,56 @@ class DOKAN_OPERATIONS(Structure):
218217
PVOID, # FileSystemNameBuffer
219218
DWORD, # FileSystemNameSize in num of chars
220219
PDOKAN_FILE_INFO)),
221-
("Mounted", WINFUNCTYPE(NTSTATUS,
220+
("Mounted", ctypes.WINFUNCTYPE(NTSTATUS,
222221
PDOKAN_FILE_INFO)),
223-
("Unmounted", WINFUNCTYPE(NTSTATUS,
222+
("Unmounted", ctypes.WINFUNCTYPE(NTSTATUS,
224223
DOKAN_FILE_INFO)),
225-
("GetFileSecurity", WINFUNCTYPE(NTSTATUS,
224+
("GetFileSecurity", ctypes.WINFUNCTYPE(NTSTATUS,
226225
LPCWSTR, # FileName
227226
PULONG, # A pointer to SECURITY_INFORMATION value being requested
228227
PVOID, # A pointer to SECURITY_DESCRIPTOR buffer to be filled
229228
ULONG, # Length of Security descriptor buffer
230229
PULONG, # Length Needed
231230
PDOKAN_FILE_INFO)),
232-
("SetFileSecurity", WINFUNCTYPE(NTSTATUS,
231+
("SetFileSecurity", ctypes.WINFUNCTYPE(NTSTATUS,
233232
LPCWSTR, # FileName
234233
PVOID, # A pointer to SECURITY_INFORMATION value being
235234
PVOID, # A pointer to SECURITY_DESCRIPTOR buffer
236235
ULONG, # Length of Security descriptor buffer
237236
PDOKAN_FILE_INFO)),
238-
("FindStreams", WINFUNCTYPE(NTSTATUS,
237+
("FindStreams", ctypes.WINFUNCTYPE(NTSTATUS,
239238
LPCWSTR, # FileName
240239
PVOID, # call this function with PWIN32_FIND_STREAM_DATA
241240
PDOKAN_FILE_INFO))
242241
]
243242

244243

245-
DokanMain.restype = c_int
244+
DokanMain.restype = ctypes.c_int
246245
DokanMain.argtypes = (
247-
POINTER(DOKAN_OPTIONS),
248-
POINTER(DOKAN_OPERATIONS),
246+
ctypes.POINTER(DOKAN_OPTIONS),
247+
ctypes.POINTER(DOKAN_OPERATIONS),
249248
)
250249

251-
DokanRemoveMountPoint = windll.Dokan1.DokanRemoveMountPoint
250+
DokanRemoveMountPoint = ctypes.windll.Dokan1.DokanRemoveMountPoint
252251
DokanRemoveMountPoint.restype = BOOL
253252
DokanRemoveMountPoint.argtypes = (
254253
LPCWSTR,
255254
)
256255

257-
DokanIsNameInExpression = windll.Dokan1.DokanIsNameInExpression
256+
DokanIsNameInExpression = ctypes.windll.Dokan1.DokanIsNameInExpression
258257
DokanIsNameInExpression.restype = BOOL
259258
DokanIsNameInExpression.argtypes = (
260259
LPCWSTR, # pattern
261260
LPCWSTR, # name
262261
BOOL, # ignore case
263262
)
264263

265-
DokanDriverVersion = windll.Dokan1.DokanDriverVersion
264+
DokanDriverVersion = ctypes.windll.Dokan1.DokanDriverVersion
266265
DokanDriverVersion.restype = ULONG
267266
DokanDriverVersion.argtypes = (
268267
)
269268

270-
DokanResetTimeout = windll.Dokan1.DokanResetTimeout
269+
DokanResetTimeout = ctypes.windll.Dokan1.DokanResetTimeout
271270
DokanResetTimeout.restype = BOOL
272271
DokanResetTimeout.argtypes = (
273272
ULONG, #timeout

0 commit comments

Comments
 (0)