diff --git a/dokan/cleanup.c b/dokan/cleanup.c index d7a66d0ca..d626bffdf 100644 --- a/dokan/cleanup.c +++ b/dokan/cleanup.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ +#include #include "dokani.h" #include "fileinfo.h" diff --git a/dokan/close.c b/dokan/close.c index a1bac6ec1..6509c15f1 100644 --- a/dokan/close.c +++ b/dokan/close.c @@ -19,6 +19,7 @@ with this program. If not, see . */ +#include #include "dokani.h" #include "fileinfo.h" diff --git a/dokan/create.c b/dokan/create.c index d0b8f2785..610c71b6b 100644 --- a/dokan/create.c +++ b/dokan/create.c @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ - +#include #include "dokani.h" #include "fileinfo.h" @@ -32,7 +32,7 @@ DispatchCreate( static int eventId = 0; ULONG length = sizeof(EVENT_INFORMATION); PEVENT_INFORMATION eventInfo = (PEVENT_INFORMATION)malloc(length); - int status; + NTSTATUS status = STATUS_INSUFFICIENT_RESOURCES; DOKAN_FILE_INFO fileInfo; DWORD disposition; PDOKAN_OPEN_INFO openInfo; @@ -73,8 +73,6 @@ DispatchCreate( // The high 8 bits of this parameter correspond to the Disposition parameter disposition = (EventContext->Operation.Create.CreateOptions >> 24) & 0x000000ff; - - status = -1; // in case being not dispatched // The low 24 bits of this member correspond to the CreateOptions parameter options = EventContext->Operation.Create.CreateOptions & FILE_VALID_OPTION_FLAGS; @@ -187,58 +185,25 @@ DispatchCreate( // FILE_SUPERSEDED - DbgPrint("CreateFile status = %d\n", status); - if (status < 0) { - - int error = status * -1; - + DbgPrint("CreateFile status = %lu\n", status); + if (status != STATUS_SUCCESS) { + if (EventContext->Flags & SL_OPEN_TARGET_DIRECTORY) + { + DbgPrint("SL_OPEN_TARGET_DIRECTORY spcefied\n"); + } eventInfo->Operation.Create.Information = FILE_DOES_NOT_EXIST; + eventInfo->Status = status; - switch(error) { - case ERROR_FILE_NOT_FOUND: - if (EventContext->Flags & SL_OPEN_TARGET_DIRECTORY) - eventInfo->Status = STATUS_OBJECT_PATH_NOT_FOUND; - else - eventInfo->Status = STATUS_OBJECT_NAME_NOT_FOUND; - break; - case ERROR_PATH_NOT_FOUND: - //if (EventContext->Flags & SL_OPEN_TARGET_DIRECTORY) - // eventInfo->Status = STATUS_SUCCESS; - //else - eventInfo->Status = STATUS_OBJECT_PATH_NOT_FOUND; - break; - case ERROR_ACCESS_DENIED: - eventInfo->Status = STATUS_ACCESS_DENIED; - break; - case ERROR_SHARING_VIOLATION: - eventInfo->Status = STATUS_SHARING_VIOLATION; - break; - case ERROR_INVALID_NAME: - eventInfo->Status = STATUS_OBJECT_NAME_NOT_FOUND; - break; - case ERROR_FILE_EXISTS: - case ERROR_ALREADY_EXISTS: - eventInfo->Status = STATUS_OBJECT_NAME_COLLISION; - eventInfo->Operation.Create.Information = FILE_EXISTS; - break; - case ERROR_PRIVILEGE_NOT_HELD: - eventInfo->Status = STATUS_PRIVILEGE_NOT_HELD; - break; - case ERROR_NOT_READY: - eventInfo->Status = STATUS_DEVICE_NOT_READY; - break; - default: - eventInfo->Status = STATUS_INVALID_PARAMETER; - DbgPrint("Create got unknown error code %d\n", error); + if (status == STATUS_OBJECT_NAME_NOT_FOUND && EventContext->Flags & SL_OPEN_TARGET_DIRECTORY) + { + DbgPrint("This case should be returned as SUCCESS\n"); + eventInfo->Status = STATUS_SUCCESS; } - - if (eventInfo->Status != STATUS_SUCCESS) { - // Needs to free openInfo because Close is never called. - free(openInfo); - eventInfo->Context = 0; + if (status == STATUS_OBJECT_NAME_COLLISION) + { + eventInfo->Operation.Create.Information = FILE_EXISTS; } - } else { //DbgPrint("status = %d\n", status); @@ -250,15 +215,7 @@ DispatchCreate( disposition == FILE_OPEN_IF || disposition == FILE_OVERWRITE_IF) { - if (status == ERROR_ALREADY_EXISTS || status == ERROR_FILE_EXISTS) { - if (disposition == FILE_OPEN_IF) { - eventInfo->Operation.Create.Information = FILE_OPENED; - } else if (disposition == FILE_OVERWRITE_IF) { - eventInfo->Operation.Create.Information = FILE_OVERWRITTEN; - } - } else { - eventInfo->Operation.Create.Information = FILE_CREATED; - } + eventInfo->Operation.Create.Information = FILE_CREATED; } if ((disposition == FILE_OVERWRITE_IF || disposition == FILE_OVERWRITE) && diff --git a/dokan/directory.c b/dokan/directory.c index 95814528b..6163b6ff7 100644 --- a/dokan/directory.c +++ b/dokan/directory.c @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ - +#include #include "dokani.h" #include "fileinfo.h" #include "list.h" @@ -441,7 +441,7 @@ DispatchDirectoryInformation( PEVENT_INFORMATION eventInfo; DOKAN_FILE_INFO fileInfo; PDOKAN_OPEN_INFO openInfo; - int status = 0; + NTSTATUS status = STATUS_SUCCESS; ULONG fileInfoClass = EventContext->Operation.Directory.FileInformationClass; ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION) - 8 + EventContext->Operation.Directory.BufferLength; @@ -517,13 +517,13 @@ DispatchDirectoryInformation( DokanFillFileData, &fileInfo); } else { - status = -1; + status = STATUS_NOT_IMPLEMENTED; } } - if (status < 0) { + if (status != STATUS_SUCCESS) { if (EventContext->Operation.Directory.FileIndex == 0) { DbgPrint(" STATUS_NO_SUCH_FILE\n"); diff --git a/dokan/dokan.h b/dokan/dokan.h index 4383234dd..ceb1796ce 100644 --- a/dokan/dokan.h +++ b/dokan/dokan.h @@ -79,17 +79,14 @@ typedef int (WINAPI *PFillFindData) (PWIN32_FIND_DATAW, PDOKAN_FILE_INFO); typedef struct _DOKAN_OPERATIONS { - // When an error occurs, return a negative value. - // Usually you should return -GetLastError(). + // When an error occurs, return NTSTATUS (https://support.microsoft.com/en-us/kb/113996) // CreateFile // If file is a directory, CreateFile (not OpenDirectory) may be called. - // In this case, CreateFile should return 0 when that directory can be opened. + // In this case, CreateFile should return STATUS_SUCCESS when that directory can be opened. // You should set TRUE on DokanFileInfo->IsDirectory when file is a directory. - // When CreationDisposition is CREATE_ALWAYS or OPEN_ALWAYS and a file already exists, - // you should return ERROR_ALREADY_EXISTS(183) (not negative value) - int (DOKAN_CALLBACK *CreateFile) ( + NTSTATUS (DOKAN_CALLBACK *CreateFile) ( LPCWSTR, // FileName DWORD, // DesiredAccess DWORD, // ShareMode @@ -97,25 +94,25 @@ typedef struct _DOKAN_OPERATIONS { DWORD, // FlagsAndAttributes PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *OpenDirectory) ( + NTSTATUS (DOKAN_CALLBACK *OpenDirectory) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *CreateDirectory) ( + NTSTATUS (DOKAN_CALLBACK *CreateDirectory) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); // When FileInfo->DeleteOnClose is true, you must delete the file in Cleanup. // Refer to comment at DeleteFile definition below in this file for explanation. - int (DOKAN_CALLBACK *Cleanup) ( + void (DOKAN_CALLBACK *Cleanup) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *CloseFile) ( + void (DOKAN_CALLBACK *CloseFile) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *ReadFile) ( + NTSTATUS (DOKAN_CALLBACK *ReadFile) ( LPCWSTR, // FileName LPVOID, // Buffer DWORD, // NumberOfBytesToRead @@ -124,7 +121,7 @@ typedef struct _DOKAN_OPERATIONS { PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *WriteFile) ( + NTSTATUS (DOKAN_CALLBACK *WriteFile) ( LPCWSTR, // FileName LPCVOID, // Buffer DWORD, // NumberOfBytesToWrite @@ -133,12 +130,12 @@ typedef struct _DOKAN_OPERATIONS { PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *FlushFileBuffers) ( + NTSTATUS (DOKAN_CALLBACK *FlushFileBuffers) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *GetFileInformation) ( + NTSTATUS (DOKAN_CALLBACK *GetFileInformation) ( LPCWSTR, // FileName LPBY_HANDLE_FILE_INFORMATION, // Buffer PDOKAN_FILE_INFO); @@ -146,25 +143,25 @@ typedef struct _DOKAN_OPERATIONS { // You should implement either FindFiles or FindFilesWithPattern - int (DOKAN_CALLBACK *FindFiles) ( + NTSTATUS (DOKAN_CALLBACK *FindFiles) ( LPCWSTR, // PathName PFillFindData, // call this function with PWIN32_FIND_DATAW PDOKAN_FILE_INFO); // (see PFillFindData definition) - int (DOKAN_CALLBACK *FindFilesWithPattern) ( + NTSTATUS (DOKAN_CALLBACK *FindFilesWithPattern) ( LPCWSTR, // PathName LPCWSTR, // SearchPattern PFillFindData, // call this function with PWIN32_FIND_DATAW PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *SetFileAttributes) ( + NTSTATUS (DOKAN_CALLBACK *SetFileAttributes) ( LPCWSTR, // FileName DWORD, // FileAttributes PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *SetFileTime) ( + NTSTATUS (DOKAN_CALLBACK *SetFileTime) ( LPCWSTR, // FileName CONST FILETIME*, // CreationTime CONST FILETIME*, // LastAccessTime @@ -174,47 +171,47 @@ typedef struct _DOKAN_OPERATIONS { // You should not delete the file on DeleteFile or DeleteDirectory, but instead // you must only check whether you can delete the file or not, - // and return 0 (when you can delete it) or appropriate error codes such as - // -ERROR_DIR_NOT_EMPTY, -ERROR_SHARING_VIOLATION. - // When you return 0 (ERROR_SUCCESS), you get a Cleanup call afterwards with + // and return ERROR_SUCCESS (when you can delete it) or appropriate error codes such as + // STATUS_ACCESS_DENIED, STATUS_OBJECT_PATH_NOT_FOUND, STATUS_OBJECT_NAME_NOT_FOUND. + // When you return ERROR_SUCCESS, you get a Cleanup call afterwards with // FileInfo->DeleteOnClose set to TRUE and only then you have to actually delete // the file being closed. - int (DOKAN_CALLBACK *DeleteFile) ( + NTSTATUS (DOKAN_CALLBACK *DeleteFile) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *DeleteDirectory) ( + NTSTATUS (DOKAN_CALLBACK *DeleteDirectory) ( LPCWSTR, // FileName PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *MoveFile) ( + NTSTATUS (DOKAN_CALLBACK *MoveFile) ( LPCWSTR, // ExistingFileName LPCWSTR, // NewFileName BOOL, // ReplaceExisiting PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *SetEndOfFile) ( + NTSTATUS (DOKAN_CALLBACK *SetEndOfFile) ( LPCWSTR, // FileName LONGLONG, // Length PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *SetAllocationSize) ( + NTSTATUS (DOKAN_CALLBACK *SetAllocationSize) ( LPCWSTR, // FileName LONGLONG, // Length PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *LockFile) ( + NTSTATUS (DOKAN_CALLBACK *LockFile) ( LPCWSTR, // FileName LONGLONG, // ByteOffset LONGLONG, // Length PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *UnlockFile) ( + NTSTATUS (DOKAN_CALLBACK *UnlockFile) ( LPCWSTR, // FileName LONGLONG,// ByteOffset LONGLONG,// Length @@ -227,7 +224,7 @@ typedef struct _DOKAN_OPERATIONS { // (ditto CloseFile and Cleanup) // see Win32 API GetDiskFreeSpaceEx - int (DOKAN_CALLBACK *GetDiskFreeSpace) ( + NTSTATUS (DOKAN_CALLBACK *GetDiskFreeSpace) ( PULONGLONG, // FreeBytesAvailable PULONGLONG, // TotalNumberOfBytes PULONGLONG, // TotalNumberOfFreeBytes @@ -235,7 +232,7 @@ typedef struct _DOKAN_OPERATIONS { // see Win32 API GetVolumeInformation - int (DOKAN_CALLBACK *GetVolumeInformation) ( + NTSTATUS (DOKAN_CALLBACK *GetVolumeInformation) ( LPWSTR, // VolumeNameBuffer DWORD, // VolumeNameSize in num of chars LPDWORD,// VolumeSerialNumber @@ -246,12 +243,12 @@ typedef struct _DOKAN_OPERATIONS { PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *Unmount) ( + NTSTATUS (DOKAN_CALLBACK *Unmount) ( PDOKAN_FILE_INFO); // Suported since 0.6.0. You must specify the version at DOKAN_OPTIONS.Version. - int (DOKAN_CALLBACK *GetFileSecurity) ( + NTSTATUS (DOKAN_CALLBACK *GetFileSecurity) ( LPCWSTR, // FileName PSECURITY_INFORMATION, // A pointer to SECURITY_INFORMATION value being requested PSECURITY_DESCRIPTOR, // A pointer to SECURITY_DESCRIPTOR buffer to be filled @@ -259,7 +256,7 @@ typedef struct _DOKAN_OPERATIONS { PULONG, // LengthNeeded PDOKAN_FILE_INFO); - int (DOKAN_CALLBACK *SetFileSecurity) ( + NTSTATUS (DOKAN_CALLBACK *SetFileSecurity) ( LPCWSTR, // FileName PSECURITY_INFORMATION, PSECURITY_DESCRIPTOR, // SecurityDescriptor @@ -267,7 +264,7 @@ typedef struct _DOKAN_OPERATIONS { PDOKAN_FILE_INFO); // Supported since 0.8.0. You must specify the version at DOKAN_OPTIONS.Version. - int (DOKAN_CALLBACK *EnumerateNamedStreams) ( + NTSTATUS (DOKAN_CALLBACK *EnumerateNamedStreams) ( LPCWSTR, // FileName PVOID*, // EnumContext LPWSTR, // StreamName diff --git a/dokan/dokan.vcxproj b/dokan/dokan.vcxproj index 6ece7dcaa..59fa782b8 100644 --- a/dokan/dokan.vcxproj +++ b/dokan/dokan.vcxproj @@ -155,7 +155,6 @@ - diff --git a/dokan/dokani.h b/dokan/dokani.h index b6b68ba52..293eb57a3 100644 --- a/dokan/dokani.h +++ b/dokan/dokani.h @@ -22,7 +22,9 @@ with this program. If not, see . #ifndef _DOKANI_H_ #define _DOKANI_H_ +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS #include #include @@ -260,10 +262,6 @@ UINT WINAPI DokanKeepAlive( PVOID Param); - -ULONG -GetNTStatus(DWORD ErrorCode); - PDOKAN_OPEN_INFO GetDokanOpenInfo( PEVENT_CONTEXT EventInfomation, diff --git a/dokan/fileinfo.c b/dokan/fileinfo.c index 039761d8a..c222082fa 100644 --- a/dokan/fileinfo.c +++ b/dokan/fileinfo.c @@ -18,14 +18,17 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS +#include #include #include #include "dokani.h" #include "fileinfo.h" -ULONG +NTSTATUS DokanFillFileBasicInfo( PFILE_BASIC_INFORMATION BasicInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -51,7 +54,7 @@ DokanFillFileBasicInfo( } -ULONG +NTSTATUS DokanFillFileStandardInfo( PFILE_STANDARD_INFORMATION StandardInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -80,7 +83,7 @@ DokanFillFileStandardInfo( } -ULONG +NTSTATUS DokanFillFilePositionInfo( PFILE_POSITION_INFORMATION PosInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -102,7 +105,7 @@ DokanFillFilePositionInfo( } -ULONG +NTSTATUS DokanFillFileAllInfo( PFILE_ALL_INFORMATION AllInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -154,7 +157,7 @@ DokanFillFileAllInfo( } -ULONG +NTSTATUS DokanFillFileNameInfo( PFILE_NAME_INFORMATION NameInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -180,7 +183,7 @@ DokanFillFileNameInfo( } -ULONG +NTSTATUS DokanFillFileAttributeTagInfo( PFILE_ATTRIBUTE_TAG_INFORMATION AttrTagInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -199,7 +202,7 @@ DokanFillFileAttributeTagInfo( } -ULONG +NTSTATUS DokanFillNetworkOpenInfo( PFILE_NETWORK_OPEN_INFORMATION NetInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -230,7 +233,7 @@ DokanFillNetworkOpenInfo( } -ULONG +NTSTATUS DokanFillInternalInfo( PFILE_INTERNAL_INFORMATION InternalInfo, PBY_HANDLE_FILE_INFORMATION FileInfo, @@ -248,7 +251,7 @@ DokanFillInternalInfo( return STATUS_SUCCESS; } -ULONG +NTSTATUS DokanEnumerateNamedStreams( PFILE_STREAM_INFORMATION StreamInfo, PDOKAN_FILE_INFO FileInfo, @@ -271,7 +274,7 @@ DokanEnumerateNamedStreams( return STATUS_BUFFER_OVERFLOW; } - while (result > -1) { + while (result == STATUS_SUCCESS) { ZeroMemory(streamName, sizeof(streamName)); streamNameLength = 0; streamSize = 0; @@ -283,7 +286,7 @@ DokanEnumerateNamedStreams( &streamSize, FileInfo); - if (result > -1) { + if (result == STATUS_SUCCESS) { if (*RemainingLength < sizeof(FILE_STREAM_INFORMATION)) { return STATUS_BUFFER_OVERFLOW; } @@ -326,8 +329,7 @@ DispatchQueryInformation( DOKAN_FILE_INFO fileInfo; BY_HANDLE_FILE_INFORMATION byHandleFileInfo; ULONG remainingLength; - ULONG status = STATUS_INVALID_PARAMETER; - int result; + NTSTATUS status = STATUS_INVALID_PARAMETER; PDOKAN_OPEN_INFO openInfo; ULONG sizeOfEventInfo; @@ -345,17 +347,19 @@ DispatchQueryInformation( DbgPrint("###GetFileInfo %04d\n", openInfo != NULL ? openInfo->EventId : -1); if (DokanInstance->DokanOperations->GetFileInformation) { - result = DokanInstance->DokanOperations->GetFileInformation( + status = DokanInstance->DokanOperations->GetFileInformation( EventContext->Operation.File.FileName, &byHandleFileInfo, &fileInfo); } else { - result = -1; + status = STATUS_NOT_IMPLEMENTED; } remainingLength = eventInfo->BufferLength; - if (result < 0) { + DbgPrint("\tresult = %lu\n", status); + + if (status != STATUS_SUCCESS) { eventInfo->Status = STATUS_INVALID_PARAMETER; eventInfo->BufferLength = 0; } else { @@ -431,6 +435,7 @@ DispatchQueryInformation( break; default: { + status = STATUS_INVALID_PARAMETER; DbgPrint(" unknown type:%d\n", EventContext->Operation.File.FileInformationClass); } break; diff --git a/dokan/fileinfo.h b/dokan/fileinfo.h index 9321cda99..e7fda66bf 100644 --- a/dokan/fileinfo.h +++ b/dokan/fileinfo.h @@ -468,35 +468,6 @@ typedef struct _FILE_NETWORK_OPEN_INFORMATION { ) -#define STATUS_SUCCESS (ULONG)0 -#define STATUS_NO_MORE_FILES ((ULONG)0x80000006L) -#define STATUS_END_OF_FILE ((ULONG)0xC0000011L) -#define STATUS_NO_SUCH_FILE ((ULONG)0xC000000FL) -#ifndef STATUS_INVALID_PARAMETER - #define STATUS_INVALID_PARAMETER ((ULONG)0xC000000DL) -#endif -#define STATUS_NOT_IMPLEMENTED ((ULONG)0xC0000002L) -#define STATUS_BUFFER_OVERFLOW ((ULONG)0x80000005L) -#define STATUS_FILE_IS_A_DIRECTORY ((ULONG)0xC00000BAL) -#define STATUS_SHARING_VIOLATION ((ULONG)0xC0000043L) -#define STATUS_OBJECT_NAME_INVALID ((ULONG)0xC0000033L) -#define STATUS_OBJECT_NAME_NOT_FOUND ((ULONG)0xC0000034L) -#define STATUS_OBJECT_NAME_COLLISION ((ULONG)0xC0000035L) -#define STATUS_OBJECT_PATH_INVALID ((ULONG)0xC0000039L) -#define STATUS_OBJECT_PATH_NOT_FOUND ((ULONG)0xC000003AL) -#define STATUS_OBJECT_PATH_SYNTAX_BAD ((ULONG)0xC000003BL) -#define STATUS_ACCESS_DENIED ((ULONG)0xC0000022L) -#define STATUS_NOT_SUPPORTED ((ULONG)0xC00000BBL) -#define STATUS_FILE_LOCK_CONFLICT ((ULONG)0xC0000054L) -#define STATUS_LOCK_NOT_GRANTED ((ULONG)0xC0000055L) -#define STATUS_DELETE_PENDING ((ULONG)0xC0000056L) -#define STATUS_DIRECTORY_NOT_EMPTY ((ULONG)0xC0000101L) -#define STATUS_CANNOT_DELETE ((ULONG)0xC0000121L) -#define STATUS_PRIVILEGE_NOT_HELD ((ULONG)0xC0000061L) -#define STATUS_DISK_FULL ((ULONG)0xC000007FL) -#define STATUS_INSUFFICIENT_RESOURCES ((ULONG)0xC000009AL) -#define STATUS_DEVICE_NOT_READY ((ULONG)0xC00000A3L) - #define FILE_SUPERSEDE 0x00000000 #define FILE_OPEN 0x00000001 #define FILE_CREATE 0x00000002 diff --git a/dokan/flush.c b/dokan/flush.c index b75fdbfbc..9e2ad4a44 100644 --- a/dokan/flush.c +++ b/dokan/flush.c @@ -19,6 +19,7 @@ with this program. If not, see . */ +#include #include "dokani.h" #include "fileinfo.h" @@ -33,7 +34,7 @@ DispatchFlush( PEVENT_INFORMATION eventInfo; ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION); PDOKAN_OPEN_INFO openInfo; - int status; + NTSTATUS status; CheckFileName(EventContext->Operation.Flush.FileName); @@ -50,7 +51,7 @@ DispatchFlush( EventContext->Operation.Flush.FileName, &fileInfo); - eventInfo->Status = status < 0 ? + eventInfo->Status = status != STATUS_SUCCESS ? STATUS_NOT_SUPPORTED : STATUS_SUCCESS; } diff --git a/dokan/lock.c b/dokan/lock.c index 1933b0765..7352557a9 100644 --- a/dokan/lock.c +++ b/dokan/lock.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ +#include #include "dokani.h" #include "fileinfo.h" @@ -32,7 +33,7 @@ DispatchLock( PEVENT_INFORMATION eventInfo; ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION); PDOKAN_OPEN_INFO openInfo; - int status; + NTSTATUS status; CheckFileName(EventContext->Operation.Lock.FileName); @@ -54,7 +55,7 @@ DispatchLock( //EventContext->Operation.Lock.Key, &fileInfo); - eventInfo->Status = status < 0 ? + eventInfo->Status = status != STATUS_SUCCESS ? STATUS_LOCK_NOT_GRANTED : STATUS_SUCCESS; } break; diff --git a/dokan/read.c b/dokan/read.c index 9136bda55..167a5667f 100644 --- a/dokan/read.c +++ b/dokan/read.c @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ - +#include #include "dokani.h" #include "fileinfo.h" @@ -32,7 +32,7 @@ DispatchRead( PEVENT_INFORMATION eventInfo; PDOKAN_OPEN_INFO openInfo; ULONG readLength = 0; - int status; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; DOKAN_FILE_INFO fileInfo; ULONG sizeOfEventInfo; @@ -54,21 +54,22 @@ DispatchRead( EventContext->Operation.Read.ByteOffset.QuadPart, &fileInfo); } else { - status = -1; + status = STATUS_NOT_IMPLEMENTED; } openInfo->UserContext = fileInfo.Context; eventInfo->BufferLength = 0; - - if (status < 0) { - eventInfo->Status = STATUS_INVALID_PARAMETER; - } else if(readLength == 0) { - eventInfo->Status = STATUS_END_OF_FILE; - } else { - eventInfo->Status = STATUS_SUCCESS; - eventInfo->BufferLength = readLength; - eventInfo->Operation.Read.CurrentByteOffset.QuadPart = - EventContext->Operation.Read.ByteOffset.QuadPart + readLength; + eventInfo->Status = status; + + if (status == STATUS_SUCCESS) + { + if (readLength == 0) { + eventInfo->Status = STATUS_END_OF_FILE; + } else { + eventInfo->BufferLength = readLength; + eventInfo->Operation.Read.CurrentByteOffset.QuadPart = + EventContext->Operation.Read.ByteOffset.QuadPart + readLength; + } } SendEventInformation(Handle, eventInfo, sizeOfEventInfo, DokanInstance); diff --git a/dokan/security.c b/dokan/security.c index 040fbc580..edbcbc8c9 100644 --- a/dokan/security.c +++ b/dokan/security.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ +#include #include "dokani.h" #include "fileinfo.h" @@ -31,7 +32,7 @@ DispatchQuerySecurity( DOKAN_FILE_INFO fileInfo; PDOKAN_OPEN_INFO openInfo; ULONG eventInfoLength; - int status = -ERROR_CALL_NOT_IMPLEMENTED; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; ULONG lengthNeeded = 0; eventInfoLength = sizeof(EVENT_INFORMATION) - 8 + EventContext->Operation.Security.BufferLength; @@ -51,29 +52,16 @@ DispatchQuerySecurity( &fileInfo); } - if (status < 0) { - int error = status * -1; - if (error == ERROR_INSUFFICIENT_BUFFER && lengthNeeded > 0) { - eventInfo->Status = STATUS_BUFFER_OVERFLOW; - eventInfo->BufferLength = lengthNeeded; - } else if (error == ERROR_ACCESS_DENIED) { - eventInfo->Status = STATUS_ACCESS_DENIED; - eventInfo->BufferLength = 0; - } else if (error == ERROR_CALL_NOT_IMPLEMENTED) { - eventInfo->Status = STATUS_NOT_IMPLEMENTED; - eventInfo->BufferLength = 0; - } else { - eventInfo->Status = STATUS_INVALID_PARAMETER; - eventInfo->BufferLength = 0; - } + eventInfo->Status = status; + + if (status != STATUS_SUCCESS && status != STATUS_BUFFER_OVERFLOW) { + eventInfo->BufferLength = 0; } else { + eventInfo->BufferLength = lengthNeeded; + if (EventContext->Operation.Security.BufferLength < lengthNeeded) { - // Filesystem Application should return -ERROR_BUFFER_OVERFLOW in this case. - eventInfo->BufferLength = lengthNeeded; + // Filesystem Application should return STATUS_BUFFER_OVERFLOW in this case. eventInfo->Status = STATUS_BUFFER_OVERFLOW; - } else { - eventInfo->BufferLength = lengthNeeded; - eventInfo->Status = STATUS_SUCCESS; } } @@ -92,7 +80,7 @@ DispatchSetSecurity( DOKAN_FILE_INFO fileInfo; PDOKAN_OPEN_INFO openInfo; ULONG eventInfoLength; - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; PSECURITY_DESCRIPTOR securityDescriptor; eventInfoLength = sizeof(EVENT_INFORMATION); @@ -112,7 +100,7 @@ DispatchSetSecurity( &fileInfo); } - if (status < 0) { + if (status > 0) { eventInfo->Status = STATUS_INVALID_PARAMETER; eventInfo->BufferLength = 0; } else { diff --git a/dokan/setfile.c b/dokan/setfile.c index 824b45e21..4807e0479 100644 --- a/dokan/setfile.c +++ b/dokan/setfile.c @@ -18,15 +18,17 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ - +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS +#include #include #include #include "dokani.h" #include "fileinfo.h" -int +NTSTATUS DokanSetAllocationInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, @@ -58,34 +60,34 @@ DokanSetAllocationInformation( allocInfo->AllocationSize.QuadPart); } - return 0; + return STATUS_SUCCESS; } -int +NTSTATUS DokanSetBasicInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, PDOKAN_OPERATIONS DokanOperations) { FILETIME creation, lastAccess, lastWrite; - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; PFILE_BASIC_INFORMATION basicInfo = (PFILE_BASIC_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); if (!DokanOperations->SetFileAttributes) - return -1; + return STATUS_NOT_IMPLEMENTED; if (!DokanOperations->SetFileTime) - return -1; + return STATUS_NOT_IMPLEMENTED; status = DokanOperations->SetFileAttributes( EventContext->Operation.SetFile.FileName, basicInfo->FileAttributes, FileInfo); - if (status < 0) + if (status > 0) return status; creation.dwLowDateTime = basicInfo->CreationTime.LowPart; @@ -105,7 +107,7 @@ DokanSetBasicInformation( } -int +NTSTATUS DokanSetDispositionInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, @@ -115,10 +117,10 @@ DokanSetDispositionInformation( (PFILE_DISPOSITION_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); if (!DokanOperations->DeleteFile || !DokanOperations->DeleteDirectory) - return -1; + return STATUS_NOT_IMPLEMENTED; if (!dispositionInfo->DeleteFile) { - return 0; + return STATUS_SUCCESS; } if (FileInfo->IsDirectory) { @@ -133,7 +135,7 @@ DokanSetDispositionInformation( } -int +NTSTATUS DokanSetEndOfFileInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, @@ -143,7 +145,7 @@ DokanSetEndOfFileInformation( (PFILE_END_OF_FILE_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); if (!DokanOperations->SetEndOfFile) - return -1; + return STATUS_NOT_IMPLEMENTED; return DokanOperations->SetEndOfFile( EventContext->Operation.SetFile.FileName, @@ -152,7 +154,7 @@ DokanSetEndOfFileInformation( } -int +NTSTATUS DokanSetLinkInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, @@ -163,12 +165,12 @@ DokanSetLinkInformation( UNREFERENCED_PARAMETER(DokanOperations); //PDOKAN_LINK_INFORMATION linkInfo = (PDOKAN_LINK_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); - return -1; + return STATUS_NOT_IMPLEMENTED; } -int +NTSTATUS DokanSetRenameInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, @@ -194,7 +196,7 @@ PEVENT_CONTEXT EventContext, } if (!DokanOperations->MoveFile) - return -1; + return STATUS_NOT_IMPLEMENTED; return DokanOperations->MoveFile( EventContext->Operation.SetFile.FileName, @@ -204,7 +206,7 @@ PEVENT_CONTEXT EventContext, } -int +NTSTATUS DokanSetValidDataLengthInformation( PEVENT_CONTEXT EventContext, PDOKAN_FILE_INFO FileInfo, @@ -214,7 +216,7 @@ DokanSetValidDataLengthInformation( (PFILE_VALID_DATA_LENGTH_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); if (!DokanOperations->SetEndOfFile) - return -1; + return STATUS_NOT_IMPLEMENTED; return DokanOperations->SetEndOfFile( EventContext->Operation.SetFile.FileName, @@ -232,7 +234,7 @@ DispatchSetInformation( PEVENT_INFORMATION eventInfo; PDOKAN_OPEN_INFO openInfo; DOKAN_FILE_INFO fileInfo; - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; ULONG sizeOfEventInfo = sizeof(EVENT_INFORMATION); @@ -277,7 +279,7 @@ DispatchSetInformation( case FilePositionInformation: // this case is dealed with by driver - status = -1; + status = STATUS_NOT_IMPLEMENTED; break; case FileRenameInformation: @@ -294,37 +296,23 @@ DispatchSetInformation( openInfo->UserContext = fileInfo.Context; eventInfo->BufferLength = 0; + eventInfo->Status = status; if (EventContext->Operation.SetFile.FileInformationClass == FileDispositionInformation) { - if (status == 0) { + if (status == STATUS_SUCCESS) { PFILE_DISPOSITION_INFORMATION dispositionInfo = (PFILE_DISPOSITION_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); eventInfo->Operation.Delete.DeleteOnClose = dispositionInfo->DeleteFile ? TRUE : FALSE; DbgPrint(" dispositionInfo->DeleteFile = %d\n", dispositionInfo->DeleteFile); - eventInfo->Status = STATUS_SUCCESS; - } else if (status == -ERROR_DIR_NOT_EMPTY) { - DbgPrint(" DispositionInfo status = STATUS_DIRECTORY_NOT_EMPTY\n"); - eventInfo->Status = STATUS_DIRECTORY_NOT_EMPTY; - } else if (status < 0) { - DbgPrint(" DispositionInfo status = STATUS_CANNOT_DELETE\n"); - eventInfo->Status = STATUS_CANNOT_DELETE; } } else { - if (status < 0) { - int error = status * -1; - eventInfo->Status = GetNTStatus(error); - - } else { - eventInfo->Status = STATUS_SUCCESS; - - // notice new file name to driver - if (EventContext->Operation.SetFile.FileInformationClass == FileRenameInformation) { - PDOKAN_RENAME_INFORMATION renameInfo = - (PDOKAN_RENAME_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); - eventInfo->BufferLength = renameInfo->FileNameLength; - CopyMemory(eventInfo->Buffer, renameInfo->FileName, renameInfo->FileNameLength); - } + // notice new file name to driver + if (status == STATUS_SUCCESS && EventContext->Operation.SetFile.FileInformationClass == FileRenameInformation) { + PDOKAN_RENAME_INFORMATION renameInfo = + (PDOKAN_RENAME_INFORMATION)((PCHAR)EventContext + EventContext->Operation.SetFile.BufferOffset); + eventInfo->BufferLength = renameInfo->FileNameLength; + CopyMemory(eventInfo->Buffer, renameInfo->FileName, renameInfo->FileNameLength); } } diff --git a/dokan/status.c b/dokan/status.c deleted file mode 100644 index c4783d79d..000000000 --- a/dokan/status.c +++ /dev/null @@ -1,45 +0,0 @@ -/* - Dokan : user-mode file system library for Windows - - Copyright (C) 2008 Hiroki Asakawa info@dokan-dev.net - - http://dokan-dev.net/en - -This program is free software; you can redistribute it and/or modify it under -the terms of the GNU Lesser General Public License as published by the Free -Software Foundation; either version 3 of the License, or (at your option) any -later version. - -This program is distributed in the hope that it will be useful, but WITHOUT ANY -WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS -FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. - -You should have received a copy of the GNU Lesser General Public License along -with this program. If not, see . -*/ - - -#include -#include "dokani.h" -#include "fileinfo.h" - - -ULONG GetNTStatus(DWORD ErrorCode) -{ - switch (ErrorCode) { - case ERROR_DIR_NOT_EMPTY: - return STATUS_DIRECTORY_NOT_EMPTY; - case ERROR_ACCESS_DENIED: - return STATUS_ACCESS_DENIED; - case ERROR_SHARING_VIOLATION: - return STATUS_SHARING_VIOLATION; - case ERROR_INVALID_NAME: - return STATUS_OBJECT_NAME_NOT_FOUND; - case ERROR_ALREADY_EXISTS: - return STATUS_OBJECT_NAME_COLLISION; - case ERROR_DISK_FULL: - return STATUS_DISK_FULL; - default: - return STATUS_OBJECT_NAME_NOT_FOUND; - } -} \ No newline at end of file diff --git a/dokan/timeout.c b/dokan/timeout.c index 4973e91ed..8b41a0997 100644 --- a/dokan/timeout.c +++ b/dokan/timeout.c @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ +#include #include #include "dokani.h" @@ -108,5 +109,5 @@ DokanKeepAlive( CloseHandle(device); _endthreadex(0); - return 0; + return STATUS_SUCCESS; } diff --git a/dokan/version.c b/dokan/version.c index ea2f839f9..336d1538d 100644 --- a/dokan/version.c +++ b/dokan/version.c @@ -19,7 +19,10 @@ with this program. If not, see . */ +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS +#include #include #include "dokani.h" @@ -49,5 +52,5 @@ DokanDriverVersion() return version; } - return 0; + return STATUS_SUCCESS; } \ No newline at end of file diff --git a/dokan/volume.c b/dokan/volume.c index 6722e60c9..5416f3d30 100644 --- a/dokan/volume.c +++ b/dokan/volume.c @@ -18,12 +18,12 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ - +#include #include "dokani.h" #include "fileinfo.h" -int DOKAN_CALLBACK DokanGetDiskFreeSpace( +NTSTATUS DOKAN_CALLBACK DokanGetDiskFreeSpace( PULONGLONG FreeBytesAvailable, PULONGLONG TotalNumberOfBytes, PULONGLONG TotalNumberOfFreeBytes, @@ -35,11 +35,11 @@ int DOKAN_CALLBACK DokanGetDiskFreeSpace( *TotalNumberOfBytes = 1024*1024*1024; *TotalNumberOfFreeBytes = 512*1024*1024; - return 0; + return STATUS_SUCCESS; } -int DOKAN_CALLBACK DokanGetVolumeInformation( +NTSTATUS DOKAN_CALLBACK DokanGetVolumeInformation( LPWSTR VolumeNameBuffer, DWORD VolumeNameSize, LPDWORD VolumeSerialNumber, @@ -61,12 +61,12 @@ int DOKAN_CALLBACK DokanGetVolumeInformation( wcscpy_s(FileSystemNameBuffer, FileSystemNameSize / sizeof(WCHAR), L"Dokan"); - return 0; + return STATUS_SUCCESS; } -ULONG +NTSTATUS DokanFsVolumeInformation( PEVENT_INFORMATION EventInfo, PEVENT_CONTEXT EventContext, @@ -80,8 +80,7 @@ DokanFsVolumeInformation( WCHAR fsName[MAX_PATH]; ULONG remainingLength; ULONG bytesToCopy; - - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; PFILE_FS_VOLUME_INFORMATION volumeInfo = (PFILE_FS_VOLUME_INFORMATION)EventInfo->Buffer; @@ -112,8 +111,9 @@ DokanFsVolumeInformation( sizeof(fsName) / sizeof(WCHAR), // FileSystemNameSize FileInfo); - if (status < 0) { - return STATUS_INVALID_PARAMETER; + if (status != STATUS_SUCCESS) + { + return status; } @@ -138,7 +138,7 @@ DokanFsVolumeInformation( } -ULONG +NTSTATUS DokanFsSizeInformation( PEVENT_INFORMATION EventInfo, PEVENT_CONTEXT EventContext, @@ -148,8 +148,7 @@ DokanFsSizeInformation( ULONGLONG freeBytesAvailable = 0; ULONGLONG totalBytes = 0; ULONGLONG freeBytes = 0; - - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; PFILE_FS_SIZE_INFORMATION sizeInfo = (PFILE_FS_SIZE_INFORMATION)EventInfo->Buffer; @@ -169,8 +168,9 @@ DokanFsSizeInformation( &freeBytes, // TotalNumberOfFreeBytes FileInfo); - if (status < 0) { - return STATUS_INVALID_PARAMETER; + if (status != STATUS_SUCCESS) + { + return status; } sizeInfo->TotalAllocationUnits.QuadPart = totalBytes / DOKAN_ALLOCATION_UNIT_SIZE; @@ -184,7 +184,7 @@ DokanFsSizeInformation( } -ULONG +NTSTATUS DokanFsAttributeInformation( PEVENT_INFORMATION EventInfo, PEVENT_CONTEXT EventContext, @@ -198,8 +198,7 @@ DokanFsAttributeInformation( WCHAR fsName[MAX_PATH]; ULONG remainingLength; ULONG bytesToCopy; - - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; PFILE_FS_ATTRIBUTE_INFORMATION attrInfo = (PFILE_FS_ATTRIBUTE_INFORMATION)EventInfo->Buffer; @@ -229,8 +228,9 @@ DokanFsAttributeInformation( sizeof(fsName) / sizeof(WCHAR), // FileSystemNameSize FileInfo); - if (status < 0) { - return STATUS_INVALID_PARAMETER; + if (status != STATUS_SUCCESS) + { + return status; } @@ -254,7 +254,7 @@ DokanFsAttributeInformation( } -ULONG +NTSTATUS DokanFsFullSizeInformation( PEVENT_INFORMATION EventInfo, PEVENT_CONTEXT EventContext, @@ -264,8 +264,7 @@ DokanFsFullSizeInformation( ULONGLONG freeBytesAvailable = 0; ULONGLONG totalBytes = 0; ULONGLONG freeBytes = 0; - - int status = -1; + NTSTATUS status = STATUS_NOT_IMPLEMENTED; PFILE_FS_FULL_SIZE_INFORMATION sizeInfo = (PFILE_FS_FULL_SIZE_INFORMATION)EventInfo->Buffer; @@ -285,8 +284,9 @@ DokanFsFullSizeInformation( &freeBytes, // TotalNumberOfFreeBytes FileInfo); - if (status < 0) { - return STATUS_INVALID_PARAMETER; + if (status != STATUS_SUCCESS) + { + return status; } sizeInfo->TotalAllocationUnits.QuadPart = totalBytes / DOKAN_ALLOCATION_UNIT_SIZE; diff --git a/dokan/write.c b/dokan/write.c index 85bae76bb..785c8d6f7 100644 --- a/dokan/write.c +++ b/dokan/write.c @@ -18,11 +18,9 @@ You should have received a copy of the GNU Lesser General Public License along with this program. If not, see . */ - - +#include #include "dokani.h" #include "fileinfo.h" -#include VOID SendWriteRequest( HANDLE Handle, @@ -99,20 +97,19 @@ DispatchWrite( EventContext->Operation.Write.ByteOffset.QuadPart, &fileInfo); } else { - status = -1; + status = STATUS_NOT_IMPLEMENTED; } openInfo->UserContext = fileInfo.Context; eventInfo->BufferLength = 0; - - if (status < 0) { - eventInfo->Status = STATUS_INVALID_PARAMETER; - } else { - eventInfo->Status = STATUS_SUCCESS; + if (status == STATUS_SUCCESS) { + eventInfo->Status = status; eventInfo->BufferLength = writtenLength; eventInfo->Operation.Write.CurrentByteOffset.QuadPart = EventContext->Operation.Write.ByteOffset.QuadPart + writtenLength; + } else { + eventInfo->Status = STATUS_INVALID_PARAMETER; } SendEventInformation(Handle, eventInfo, sizeOfEventInfo, DokanInstance); diff --git a/dokan_control/dokanctl.c b/dokan_control/dokanctl.c index 7bb0cefc1..db4903719 100644 --- a/dokan_control/dokanctl.c +++ b/dokan_control/dokanctl.c @@ -44,10 +44,10 @@ int ShowMountList() control.Option, control.MountPoint, control.DeviceName); control.Option++; } else { - return 0; + return EXIT_SUCCESS; } } - return 0; + return EXIT_SUCCESS; } int ShowUsage() @@ -75,12 +75,12 @@ int ShowUsage() " /r n : Remove network provider\n" \ " /d [0-9] : Enable Kernel Debug output\n" \ " /v : Print Dokan version\n"); - return -1; + return EXIT_FAILURE; } int Unmount(LPCWSTR MountPoint, BOOL ForceUnmount) { - int status = 0; + int status = EXIT_SUCCESS; DOKAN_CONTROL control; ZeroMemory(&control, sizeof(DOKAN_CONTROL)); @@ -89,11 +89,10 @@ int Unmount(LPCWSTR MountPoint, BOOL ForceUnmount) control.Option = MountPoint[0] - L'0'; DokanMountControl(&control); - if (control.Status == DOKAN_CONTROL_SUCCESS) { - status = DokanRemoveMountPoint(control.MountPoint); - } else { + if (control.Status != DOKAN_CONTROL_SUCCESS + || (control.Status == DOKAN_CONTROL_SUCCESS && !DokanRemoveMountPoint(control.MountPoint))) { fwprintf(stderr, L"Mount entry %d not found\n", control.Option); - status = -1; + status = EXIT_FAILURE; } } else if (ForceUnmount) { control.Type = DOKAN_CONTROL_UNMOUNT; @@ -101,17 +100,13 @@ int Unmount(LPCWSTR MountPoint, BOOL ForceUnmount) wcscpy_s(control.MountPoint, sizeof(control.MountPoint) / sizeof(WCHAR), MountPoint); DokanMountControl(&control); - if (control.Status == DOKAN_CONTROL_SUCCESS) { - fwprintf(stderr, L"Unmount success: %s", MountPoint); - status = 0; - } else { - fwprintf(stderr, L"Unmount failed: %s", MountPoint); - status = -1; - } + if (control.Status != DOKAN_CONTROL_SUCCESS) + status = EXIT_FAILURE; - } else { - status = DokanRemoveMountPoint(MountPoint); - } + fwprintf(stderr, L"Unmount status %d - %s\tn", status, MountPoint); + + } else if (!DokanRemoveMountPoint(MountPoint)) + status = EXIT_FAILURE; fwprintf(stderr, L"Unmount status = %d\n", status); return status; @@ -157,7 +152,7 @@ wmain(int argc, PWCHAR argv[]) fprintf(stderr, "dokanctl : %s %s\n", __DATE__, __TIME__); fprintf(stderr, "Dokan version : %d\n", DokanVersion()); fprintf(stderr, "Dokan driver version : 0x%X\n", DokanDriverVersion()); - return 0; + return EXIT_SUCCESS; } else if (GetOption(argc, argv, 1) == L'm') { return ShowMountList(); @@ -181,85 +176,85 @@ wmain(int argc, PWCHAR argv[]) if (DokanServiceInstall(DOKAN_DRIVER_SERVICE, SERVICE_FILE_SYSTEM_DRIVER, driverFullPath)) - fprintf(stderr, "driver install ok"); + fprintf(stderr, "driver install ok\n"); else - fprintf(stderr, "driver install failed"); + fprintf(stderr, "driver install failed\n"); } else if (type == L's') { if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE, SERVICE_WIN32_OWN_PROCESS, mounterFullPath)) - fprintf(stderr, "mounter install ok"); + fprintf(stderr, "mounter install ok\n"); else - fprintf(stderr, "mounter install failed"); + fprintf(stderr, "mounter install failed\n"); } else if (type == L'a') { if (DokanServiceInstall(DOKAN_DRIVER_SERVICE, SERVICE_FILE_SYSTEM_DRIVER, driverFullPath)) - fprintf(stderr, "driver install ok"); + fprintf(stderr, "driver install ok\n"); else - fprintf(stderr, "driver install failed"); + fprintf(stderr, "driver install failed\n"); if (DokanServiceInstall(DOKAN_MOUNTER_SERVICE, SERVICE_WIN32_OWN_PROCESS, mounterFullPath)) - fprintf(stderr, "mounter install ok"); + fprintf(stderr, "mounter install ok\n"); else - fprintf(stderr, "mounter install failed"); + fprintf(stderr, "mounter install failed\n"); } else if (type == L'n') { if (DokanNetworkProviderInstall()) - fprintf(stderr, "network provider install ok"); + fprintf(stderr, "network provider install ok\n"); else - fprintf(stderr, "network provider install failed"); + fprintf(stderr, "network provider install failed\n"); } break; case L'r': if (type == L'd') { if (DokanServiceDelete(DOKAN_DRIVER_SERVICE)) - fprintf(stderr, "driver remove ok"); + fprintf(stderr, "driver remove ok\n"); else - fprintf(stderr, "driver remvoe failed"); + fprintf(stderr, "driver remvoe failed\n"); } else if (type == L's') { if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE)) - fprintf(stderr, "mounter remove ok"); + fprintf(stderr, "mounter remove ok\n"); else - fprintf(stderr, "mounter remvoe failed"); + fprintf(stderr, "mounter remvoe failed\n"); } else if (type == L'a') { if (DokanServiceDelete(DOKAN_MOUNTER_SERVICE)) - fprintf(stderr, "mounter remove ok"); + fprintf(stderr, "mounter remove ok\n"); else - fprintf(stderr, "mounter remvoe failed"); + fprintf(stderr, "mounter remvoe failed\n"); if (DokanServiceDelete(DOKAN_DRIVER_SERVICE)) - fprintf(stderr, "driver remove ok"); + fprintf(stderr, "driver remove ok\n"); else - fprintf(stderr, "driver remvoe failed"); + fprintf(stderr, "driver remvoe failed\n"); } else if (type == L'n') { if (DokanNetworkProviderUninstall()) - fprintf(stderr, "network provider remove ok"); + fprintf(stderr, "network provider remove ok\n"); else - fprintf(stderr, "network provider remove failed"); + fprintf(stderr, "network provider remove failed\n"); } break; case L'd': if (L'0' <= type && type <= L'9') { ULONG mode = type - L'0'; if (DokanSetDebugMode(mode)) { - fprintf(stderr, "set debug mode ok"); + fprintf(stderr, "set debug mode ok\n"); } else { - fprintf(stderr, "set debug mode failed"); + fprintf(stderr, "set debug mode failed\n"); } } break; default: - fprintf(stderr, "unknown option"); + fprintf(stderr, "unknown option\n"); } - return 0; + return EXIT_SUCCESS; } diff --git a/dokan_fuse/include/fuse.h b/dokan_fuse/include/fuse.h index d5542780d..124720d56 100644 --- a/dokan_fuse/include/fuse.h +++ b/dokan_fuse/include/fuse.h @@ -89,9 +89,7 @@ typedef int (*fuse_dirfil_t) (fuse_dirh_t h, const char *name, int type, * The file system operations: * * Most of these should work very similarly to the well known UNIX - * file system operations. A major exception is that instead of - * returning an error in 'errno', the operation should return the - * negated error value (-errno) directly. + * file system operations. * * All methods are optional, but some are essential for a useful * filesystem (e.g. getattr). Open, flush, release, fsync, opendir, diff --git a/dokan_fuse/include/fuse_win.h b/dokan_fuse/include/fuse_win.h index c5e9c21bc..681f1dd66 100644 --- a/dokan_fuse/include/fuse_win.h +++ b/dokan_fuse/include/fuse_win.h @@ -28,8 +28,8 @@ #ifdef __cplusplus extern "C" { #endif -int win32_error_to_errno(int win_res); -int errno_to_win32_error(int err); +int ntstatus_error_to_errno(int win_res); +int errno_to_ntstatus_error(int err); //This stuff is useful only on Windows in MSVC #ifdef _MSC_VER diff --git a/dokan_fuse/include/fusemain.h b/dokan_fuse/include/fusemain.h index 1d9df0b39..e41a91be1 100644 --- a/dokan_fuse/include/fusemain.h +++ b/dokan_fuse/include/fusemain.h @@ -55,7 +55,7 @@ class impl_chain_guard class win_error { public: - win_error(int _err): err(errno_to_win32_error(_err)) {} + win_error(int _err): err(errno_to_ntstatus_error(_err)) {} win_error(int _err, bool): err(_err) {} operator int() { return err; } private: diff --git a/dokan_fuse/src/docanfuse.cpp b/dokan_fuse/src/docanfuse.cpp index e170900f9..acfa6ce44 100644 --- a/dokan_fuse/src/docanfuse.cpp +++ b/dokan_fuse/src/docanfuse.cpp @@ -30,7 +30,7 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpRes return TRUE; } -static int DOKAN_CALLBACK FuseFindFiles( +static NTSTATUS DOKAN_CALLBACK FuseFindFiles( LPCWSTR FileName, PFillFindData FillFindData, // function pointer PDOKAN_FILE_INFO DokanFileInfo) @@ -39,11 +39,11 @@ static int DOKAN_CALLBACK FuseFindFiles( if (impl->debug()) FWPRINTF(stderr, L"FindFiles :%s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->find_files(FileName,FillFindData, + return errno_to_ntstatus_error(impl->find_files(FileName,FillFindData, DokanFileInfo)); } -static int DOKAN_CALLBACK FuseOpenDirectory( +static NTSTATUS DOKAN_CALLBACK FuseOpenDirectory( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -51,10 +51,10 @@ static int DOKAN_CALLBACK FuseOpenDirectory( if (impl->debug()) FWPRINTF(stderr, L"OpenDirectory : %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->open_directory(FileName,DokanFileInfo)); + return errno_to_ntstatus_error(impl->open_directory(FileName,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseCleanup( +static void DOKAN_CALLBACK FuseCleanup( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -62,10 +62,10 @@ static int DOKAN_CALLBACK FuseCleanup( if (impl->debug()) FWPRINTF(stderr, L"Cleanup: %s\n\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->cleanup(FileName,DokanFileInfo)); + impl->cleanup(FileName,DokanFileInfo); } -static int DOKAN_CALLBACK FuseCreateDirectory( +static NTSTATUS DOKAN_CALLBACK FuseCreateDirectory( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -73,10 +73,10 @@ static int DOKAN_CALLBACK FuseCreateDirectory( if (impl->debug()) FWPRINTF(stderr, L"CreateDirectory : %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->create_directory(FileName,DokanFileInfo)); + return errno_to_ntstatus_error(impl->create_directory(FileName,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseDeleteDirectory( +static NTSTATUS DOKAN_CALLBACK FuseDeleteDirectory( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -84,7 +84,7 @@ static int DOKAN_CALLBACK FuseDeleteDirectory( if (impl->debug()) FWPRINTF(stderr, L"DeleteDirectory %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->delete_directory(FileName,DokanFileInfo)); + return errno_to_ntstatus_error(impl->delete_directory(FileName,DokanFileInfo)); } @@ -182,7 +182,7 @@ void DebugConstantBit(const char *name, DWORD value, Constant *cs) fprintf(stderr, "\n"); } -static int DOKAN_CALLBACK FuseCreateFile( +static NTSTATUS DOKAN_CALLBACK FuseCreateFile( LPCWSTR FileName, DWORD AccessMode, DWORD ShareMode, @@ -205,7 +205,7 @@ static int DOKAN_CALLBACK FuseCreateFile( CreationDisposition,FlagsAndAttributes,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseCloseFile( +static void DOKAN_CALLBACK FuseCloseFile( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -213,10 +213,10 @@ static int DOKAN_CALLBACK FuseCloseFile( if (impl->debug()) FWPRINTF(stderr, L"Close: %s\n\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->close_file(FileName,DokanFileInfo)); + impl->close_file(FileName,DokanFileInfo); } -static int DOKAN_CALLBACK FuseReadFile( +static NTSTATUS DOKAN_CALLBACK FuseReadFile( LPCWSTR FileName, LPVOID Buffer, DWORD BufferLength, @@ -228,11 +228,11 @@ static int DOKAN_CALLBACK FuseReadFile( if (impl->debug()) FWPRINTF(stderr, L"ReadFile : %s from %I64d len %u\n", FileName, (__int64) Offset, (unsigned) BufferLength); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->read_file(FileName,Buffer, + return errno_to_ntstatus_error(impl->read_file(FileName,Buffer, BufferLength,ReadLength,Offset,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseWriteFile( +static NTSTATUS DOKAN_CALLBACK FuseWriteFile( LPCWSTR FileName, LPCVOID Buffer, DWORD NumberOfBytesToWrite, @@ -245,11 +245,11 @@ static int DOKAN_CALLBACK FuseWriteFile( FileName, Offset, NumberOfBytesToWrite); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->write_file(FileName,Buffer, + return errno_to_ntstatus_error(impl->write_file(FileName,Buffer, NumberOfBytesToWrite,NumberOfBytesWritten,Offset,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseFlushFileBuffers( +static NTSTATUS DOKAN_CALLBACK FuseFlushFileBuffers( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -257,11 +257,11 @@ static int DOKAN_CALLBACK FuseFlushFileBuffers( if (impl->debug()) FWPRINTF(stderr, L"FlushFileBuffers : %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->flush_file_buffers(FileName, + return errno_to_ntstatus_error(impl->flush_file_buffers(FileName, DokanFileInfo)); } -static int DOKAN_CALLBACK FuseGetFileInformation( +static NTSTATUS DOKAN_CALLBACK FuseGetFileInformation( LPCWSTR FileName, LPBY_HANDLE_FILE_INFORMATION HandleFileInformation, PDOKAN_FILE_INFO DokanFileInfo) @@ -270,11 +270,11 @@ static int DOKAN_CALLBACK FuseGetFileInformation( if (impl->debug()) FWPRINTF(stderr, L"GetFileInfo : %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->get_file_information(FileName, + return errno_to_ntstatus_error(impl->get_file_information(FileName, HandleFileInformation,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseDeleteFile( +static NTSTATUS DOKAN_CALLBACK FuseDeleteFile( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) { @@ -282,10 +282,10 @@ static int DOKAN_CALLBACK FuseDeleteFile( if (impl->debug()) FWPRINTF(stderr, L"DeleteFile %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->delete_file(FileName,DokanFileInfo)); + return errno_to_ntstatus_error(impl->delete_file(FileName,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseMoveFile( +static NTSTATUS DOKAN_CALLBACK FuseMoveFile( LPCWSTR FileName, // existing file name LPCWSTR NewFileName, BOOL ReplaceIfExisting, @@ -295,11 +295,11 @@ static int DOKAN_CALLBACK FuseMoveFile( if (impl->debug()) FWPRINTF(stderr, L"MoveFile %s -> %s\n\n", FileName, NewFileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->move_file(FileName,NewFileName, + return errno_to_ntstatus_error(impl->move_file(FileName,NewFileName, ReplaceIfExisting,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseLockFile( +static NTSTATUS DOKAN_CALLBACK FuseLockFile( LPCWSTR FileName, LONGLONG ByteOffset, LONGLONG Length, @@ -309,11 +309,11 @@ static int DOKAN_CALLBACK FuseLockFile( if (impl->debug()) FWPRINTF(stderr, L"LockFile %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->lock_file(FileName,ByteOffset, + return errno_to_ntstatus_error(impl->lock_file(FileName,ByteOffset, Length,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseUnlockFile( +static NTSTATUS DOKAN_CALLBACK FuseUnlockFile( LPCWSTR FileName, LONGLONG ByteOffset, LONGLONG Length, @@ -323,11 +323,11 @@ static int DOKAN_CALLBACK FuseUnlockFile( if (impl->debug()) FWPRINTF(stderr, L"UnlockFile %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->unlock_file(FileName,ByteOffset, + return errno_to_ntstatus_error(impl->unlock_file(FileName,ByteOffset, Length,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseSetEndOfFile( +static NTSTATUS DOKAN_CALLBACK FuseSetEndOfFile( LPCWSTR FileName, LONGLONG ByteOffset, PDOKAN_FILE_INFO DokanFileInfo) @@ -336,11 +336,11 @@ static int DOKAN_CALLBACK FuseSetEndOfFile( if (impl->debug()) FWPRINTF(stderr, L"SetEndOfFile %s, %I64d\n", FileName, ByteOffset); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->set_end_of_file(FileName, + return errno_to_ntstatus_error(impl->set_end_of_file(FileName, ByteOffset,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseSetFileAttributes( +static NTSTATUS DOKAN_CALLBACK FuseSetFileAttributes( LPCWSTR FileName, DWORD FileAttributes, PDOKAN_FILE_INFO DokanFileInfo) @@ -349,11 +349,11 @@ static int DOKAN_CALLBACK FuseSetFileAttributes( if (impl->debug()) FWPRINTF(stderr, L"SetFileAttributes %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->set_file_attributes(FileName, + return errno_to_ntstatus_error(impl->set_file_attributes(FileName, FileAttributes,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseSetFileTime( +static NTSTATUS DOKAN_CALLBACK FuseSetFileTime( LPCWSTR FileName, CONST FILETIME* CreationTime, CONST FILETIME* LastAccessTime, @@ -364,11 +364,11 @@ static int DOKAN_CALLBACK FuseSetFileTime( if (impl->debug()) FWPRINTF(stderr, L"SetFileTime %s\n", FileName); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->set_file_time(FileName, + return errno_to_ntstatus_error(impl->set_file_time(FileName, CreationTime,LastAccessTime,LastWriteTime,DokanFileInfo)); } -static int DOKAN_CALLBACK FuseGetDiskFreeSpace(PULONGLONG FreeBytesAvailable, +static NTSTATUS DOKAN_CALLBACK FuseGetDiskFreeSpace(PULONGLONG FreeBytesAvailable, PULONGLONG TotalNumberOfBytes, PULONGLONG TotalNumberOfFreeBytes, PDOKAN_FILE_INFO DokanFileInfo) { @@ -376,11 +376,11 @@ static int DOKAN_CALLBACK FuseGetDiskFreeSpace(PULONGLONG FreeBytesAvailable, if (impl->debug()) FWPRINTF(stderr, L"GetDiskFreeSpace\n"); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->get_disk_free_space(FreeBytesAvailable,TotalNumberOfBytes, + return errno_to_ntstatus_error(impl->get_disk_free_space(FreeBytesAvailable,TotalNumberOfBytes, TotalNumberOfFreeBytes, DokanFileInfo)); } -static int DOKAN_CALLBACK GetVolumeInformation( +static NTSTATUS DOKAN_CALLBACK GetVolumeInformation( LPWSTR VolumeNameBuffer, DWORD VolumeNameSize, LPDWORD VolumeSerialNumber, @@ -396,17 +396,17 @@ static int DOKAN_CALLBACK GetVolumeInformation( impl_chain_guard guard(impl,DokanFileInfo->ProcessId); *VolumeSerialNumber = 0; *MaximumComponentLength = 255; - return -errno_to_win32_error(impl->get_volume_information(VolumeNameBuffer,VolumeNameSize, + return errno_to_ntstatus_error(impl->get_volume_information(VolumeNameBuffer,VolumeNameSize, FileSystemNameBuffer,FileSystemNameSize, DokanFileInfo, FileSystemFlags)); } -static int DOKAN_CALLBACK FuseUnmount(PDOKAN_FILE_INFO DokanFileInfo) +static NTSTATUS DOKAN_CALLBACK FuseUnmount(PDOKAN_FILE_INFO DokanFileInfo) { impl_fuse_context *impl=the_impl; if (impl->debug()) FWPRINTF(stderr, L"Unmount\n"); impl_chain_guard guard(impl,DokanFileInfo->ProcessId); - return -errno_to_win32_error(impl->unmount(DokanFileInfo)); + return errno_to_ntstatus_error(impl->unmount(DokanFileInfo)); } int fuse_interrupted(void) diff --git a/dokan_fuse/src/dokanfuse.def b/dokan_fuse/src/dokanfuse.def index 0dccb5f4b..46314d381 100644 --- a/dokan_fuse/src/dokanfuse.def +++ b/dokan_fuse/src/dokanfuse.def @@ -77,7 +77,7 @@ fuse_set_signal_handlers fuse_remove_signal_handlers ; Win32 Helpers -win32_error_to_errno -errno_to_win32_error +ntstatus_error_to_errno +errno_to_ntstatus_error convert_args free_converted_args diff --git a/dokan_fuse/src/utils.cpp b/dokan_fuse/src/utils.cpp index 4f160677a..a5ae9501c 100644 --- a/dokan_fuse/src/utils.cpp +++ b/dokan_fuse/src/utils.cpp @@ -1,4 +1,7 @@ +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS +#include #include #include #include "utils.h" @@ -267,60 +270,60 @@ time_t filetimeToUnixTime(const FILETIME *ft) /////////////////////////////////////////////////////////////////////////////////////// struct errentry { - unsigned long oscode; /* OS return value */ + NTSTATUS oscode; /* OS return value */ int errnocode; /* System V error code */ }; static const struct errentry errtable[] = { - { ERROR_INVALID_FUNCTION, EINVAL }, /* 1 */ - { ERROR_FILE_NOT_FOUND, ENOENT }, /* 2 */ - { ERROR_PATH_NOT_FOUND, ENOENT }, /* 3 */ - { ERROR_TOO_MANY_OPEN_FILES, EMFILE }, /* 4 */ - { ERROR_ACCESS_DENIED, EACCES }, /* 5 */ - { ERROR_INVALID_HANDLE, EBADF }, /* 6 */ - { ERROR_ARENA_TRASHED, ENOMEM }, /* 7 */ - { ERROR_NOT_ENOUGH_MEMORY, ENOMEM }, /* 8 */ - { ERROR_INVALID_BLOCK, ENOMEM }, /* 9 */ - { ERROR_BAD_ENVIRONMENT, E2BIG }, /* 10 */ - { ERROR_BAD_FORMAT, ENOEXEC }, /* 11 */ - { ERROR_INVALID_ACCESS, EINVAL }, /* 12 */ - { ERROR_INVALID_DATA, EINVAL }, /* 13 */ - { ERROR_INVALID_DRIVE, ENOENT }, /* 15 */ - { ERROR_CURRENT_DIRECTORY, EACCES }, /* 16 */ - { ERROR_NOT_SAME_DEVICE, EXDEV }, /* 17 */ - { ERROR_NO_MORE_FILES, ENOENT }, /* 18 */ - { ERROR_LOCK_VIOLATION, EACCES }, /* 33 */ - { ERROR_BAD_NETPATH, ENOENT }, /* 53 */ - { ERROR_NETWORK_ACCESS_DENIED, EACCES }, /* 65 */ - { ERROR_BAD_NET_NAME, ENOENT }, /* 67 */ - { ERROR_ALREADY_EXISTS, EEXIST }, /* 183 */ - { ERROR_FILE_EXISTS, EEXIST }, /* 80 */ - { ERROR_CANNOT_MAKE, EACCES }, /* 82 */ - { ERROR_FAIL_I24, EACCES }, /* 83 */ - { ERROR_INVALID_PARAMETER, EINVAL }, /* 87 */ - { ERROR_NO_PROC_SLOTS, EAGAIN }, /* 89 */ - { ERROR_DRIVE_LOCKED, EACCES }, /* 108 */ - { ERROR_BROKEN_PIPE, EPIPE }, /* 109 */ - { ERROR_DISK_FULL, ENOSPC }, /* 112 */ - { ERROR_INVALID_TARGET_HANDLE, EBADF }, /* 114 */ - { ERROR_INVALID_HANDLE, EINVAL }, /* 124 */ - { ERROR_WAIT_NO_CHILDREN, ECHILD }, /* 128 */ - { ERROR_CHILD_NOT_COMPLETE, ECHILD }, /* 129 */ - { ERROR_DIRECT_ACCESS_HANDLE, EBADF }, /* 130 */ - { ERROR_NEGATIVE_SEEK, EINVAL }, /* 131 */ - { ERROR_SEEK_ON_DEVICE, EACCES }, /* 132 */ - { ERROR_DIR_NOT_EMPTY, ENOTEMPTY }, /* 145 */ - { ERROR_NOT_LOCKED, EACCES }, /* 158 */ - { ERROR_BAD_PATHNAME, ENOENT }, /* 161 */ - { ERROR_MAX_THRDS_REACHED, EAGAIN }, /* 164 */ - { ERROR_LOCK_FAILED, EACCES }, /* 167 */ - { ERROR_FILENAME_EXCED_RANGE, ENOENT }, /* 206 */ - { ERROR_NESTING_NOT_ALLOWED, EAGAIN }, /* 215 */ - { ERROR_NOT_ENOUGH_QUOTA, ENOMEM } /* 1816 */ + { STATUS_NOT_IMPLEMENTED, EINVAL }, /* 1 */ + { STATUS_OBJECT_NAME_NOT_FOUND, ENOENT }, /* 2 */ + { STATUS_OBJECT_PATH_NOT_FOUND, ENOENT }, /* 3 */ + { STATUS_TOO_MANY_OPENED_FILES, EMFILE }, /* 4 */ + { STATUS_ACCESS_DENIED, EACCES }, /* 5 */ + { STATUS_INVALID_HANDLE, EBADF }, /* 6 */ + { STATUS_DISK_CORRUPT_ERROR, ENOMEM }, /* 7 */ + { STATUS_NO_MEMORY, ENOMEM }, /* 8 */ + { STATUS_INVALID_ADDRESS, ENOMEM }, /* 9 */ + { STATUS_VARIABLE_NOT_FOUND, E2BIG }, /* 10 */ + //{ ERROR_BAD_FORMAT, ENOEXEC }, /* 11 */ Need to convert it to NTSTATUS + //{ ERROR_INVALID_ACCESS, EINVAL }, /* 12 */ + //{ ERROR_INVALID_DATA, EINVAL }, /* 13 */ + //{ ERROR_INVALID_DRIVE, ENOENT }, /* 15 */ + //{ ERROR_CURRENT_DIRECTORY, EACCES }, /* 16 */ + { STATUS_NOT_SAME_DEVICE, EXDEV }, /* 17 */ + { STATUS_NO_MORE_FILES, ENOENT }, /* 18 */ + { STATUS_FILE_LOCK_CONFLICT, EACCES }, /* 33 */ + { STATUS_BAD_NETWORK_PATH, ENOENT }, /* 53 */ + { STATUS_NETWORK_ACCESS_DENIED, EACCES }, /* 65 */ + { STATUS_BAD_NETWORK_NAME, ENOENT }, /* 67 */ + { STATUS_OBJECT_NAME_COLLISION, EEXIST }, /* 183 */ + { STATUS_OBJECT_NAME_COLLISION, EEXIST }, /* 80 */ + { STATUS_CANNOT_MAKE, EACCES }, /* 82 */ + //{ ERROR_FAIL_I24, EACCES }, /* 83 */ + { STATUS_INVALID_PARAMETER, EINVAL }, /* 87 */ + //{ ERROR_NO_PROC_SLOTS, EAGAIN }, /* 89 */ + //{ ERROR_DRIVE_LOCKED, EACCES }, /* 108 */ + { STATUS_PIPE_BROKEN, EPIPE }, /* 109 */ + { STATUS_DISK_FULL, ENOSPC }, /* 112 */ + //{ ERROR_INVALID_TARGET_HANDLE, EBADF }, /* 114 */ + { STATUS_INVALID_HANDLE, EINVAL }, /* 124 */ + { STATUS_NOT_FOUND, ECHILD }, /* 128 */ + //{ ERROR_CHILD_NOT_COMPLETE, ECHILD }, /* 129 */ + //{ ERROR_DIRECT_ACCESS_HANDLE, EBADF }, /* 130 */ + //{ ERROR_NEGATIVE_SEEK, EINVAL }, /* 131 */ + //{ ERROR_SEEK_ON_DEVICE, EACCES }, /* 132 */ + { STATUS_DIRECTORY_NOT_EMPTY, ENOTEMPTY }, /* 145 */ + { STATUS_NOT_LOCKED, EACCES }, /* 158 */ + { STATUS_OBJECT_PATH_SYNTAX_BAD, ENOENT }, /* 161 */ + //{ ERROR_MAX_THRDS_REACHED, EAGAIN }, /* 164 */ + { STATUS_LOCK_NOT_GRANTED, EACCES }, /* 167 */ + { STATUS_NAME_TOO_LONG, ENOENT }, /* 206 */ + //{ ERROR_NESTING_NOT_ALLOWED, EAGAIN }, /* 215 */ + { STATUS_QUOTA_EXCEEDED, ENOMEM } /* 1816 */ }; const int errtable_size=sizeof(errtable)/sizeof(errtable[0]); -extern "C" int win32_error_to_errno(int win_res) +extern "C" int ntstatus_error_to_errno(int win_res) { if (win_res==0) return 0; //No error @@ -330,7 +333,7 @@ extern "C" int win32_error_to_errno(int win_res) return EINVAL; } -extern "C" int errno_to_win32_error(int err) +extern "C" int errno_to_ntstatus_error(int err) { if (err==0) return 0; //No error diff --git a/dokan_mirror/mirror.c b/dokan_mirror/mirror.c index 6b6ba33ef..c9d906267 100644 --- a/dokan_mirror/mirror.c +++ b/dokan_mirror/mirror.c @@ -21,8 +21,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#define WIN32_NO_STATUS #include +#undef WIN32_NO_STATUS #include +#include #include #include #include "../dokan/dokan.h" @@ -99,9 +102,24 @@ PrintUserName(PDOKAN_FILE_INFO DokanFileInfo) DbgPrint(L" AccountName: %s, DomainName: %s\n", accountName, domainName); } +NTSTATUS ToNtStatus(DWORD dwError) +{ + switch (dwError) + { + case ERROR_FILE_NOT_FOUND: + return STATUS_OBJECT_NAME_NOT_FOUND; + case ERROR_PATH_NOT_FOUND: + return STATUS_OBJECT_PATH_NOT_FOUND; + case ERROR_INVALID_PARAMETER: + return STATUS_INVALID_PARAMETER; + default: + return STATUS_ACCESS_DENIED; + } +} + #define MirrorCheckFlag(val, flag) if (val&flag) { DbgPrint(L"\t" L#flag L"\n"); } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorCreateFile( LPCWSTR FileName, DWORD AccessMode, @@ -113,6 +131,7 @@ MirrorCreateFile( WCHAR filePath[MAX_PATH]; HANDLE handle; DWORD fileAttr; + NTSTATUS status = STATUS_SUCCESS; GetFilePath(filePath, MAX_PATH, FileName); @@ -214,18 +233,46 @@ MirrorCreateFile( if (handle == INVALID_HANDLE_VALUE) { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; // error codes are negated value of Windows System Error codes - } - DbgPrint(L"\n"); + switch (error) { + case ERROR_FILE_NOT_FOUND: + status = STATUS_OBJECT_NAME_NOT_FOUND; + break; + case ERROR_PATH_NOT_FOUND: + status = STATUS_OBJECT_PATH_NOT_FOUND; + break; + case ERROR_ACCESS_DENIED: + status = STATUS_ACCESS_DENIED; + break; + case ERROR_SHARING_VIOLATION: + status = STATUS_SHARING_VIOLATION; + break; + case ERROR_INVALID_NAME: + status = STATUS_OBJECT_NAME_NOT_FOUND; + break; + case ERROR_FILE_EXISTS: + case ERROR_ALREADY_EXISTS: + status = STATUS_OBJECT_NAME_COLLISION; + break; + case ERROR_PRIVILEGE_NOT_HELD: + status = STATUS_PRIVILEGE_NOT_HELD; + break; + case ERROR_NOT_READY: + status = STATUS_DEVICE_NOT_READY; + break; + default: + status = STATUS_INVALID_PARAMETER; + DbgPrint(L"Create got unknown error code %d\n", error); + } + } else + DokanFileInfo->Context = (ULONG64)handle; // save the file handle in Context - // save the file handle in Context - DokanFileInfo->Context = (ULONG64)handle; - return 0; + DbgPrint(L"\n"); + return status; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorCreateDirectory( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -239,13 +286,13 @@ MirrorCreateDirectory( if (!CreateDirectory(filePath, NULL)) { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; // error codes are negated value of Windows System Error codes + return ToNtStatus(error); } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorOpenDirectory( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -262,10 +309,10 @@ MirrorOpenDirectory( if (attr == INVALID_FILE_ATTRIBUTES) { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + return ToNtStatus(error); } if (!(attr & FILE_ATTRIBUTE_DIRECTORY)) { - return -1; + return STATUS_NOT_IMPLEMENTED; } handle = CreateFile( @@ -280,18 +327,18 @@ MirrorOpenDirectory( if (handle == INVALID_HANDLE_VALUE) { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + return ToNtStatus(error); } DbgPrint(L"\n"); DokanFileInfo->Context = (ULONG64)handle; - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static void DOKAN_CALLBACK MirrorCloseFile( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -305,17 +352,12 @@ MirrorCloseFile( CloseHandle((HANDLE)DokanFileInfo->Context); DokanFileInfo->Context = 0; } else { - //DbgPrint(L"Close: %s\n\tinvalid handle\n\n", filePath); DbgPrint(L"Close: %s\n\n", filePath); - return 0; } - - //DbgPrint(L"\n"); - return 0; } -static int DOKAN_CALLBACK +static void DOKAN_CALLBACK MirrorCleanup( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -349,14 +391,11 @@ MirrorCleanup( } else { DbgPrint(L"Cleanup: %s\n\tinvalid handle\n\n", filePath); - return -1; } - - return 0; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorReadFile( LPCWSTR FileName, LPVOID Buffer, @@ -385,8 +424,9 @@ MirrorReadFile( 0, NULL); if (handle == INVALID_HANDLE_VALUE) { - DbgPrint(L"\tCreateFile error : %d\n\n", GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tCreateFile error : %d\n\n", error); + return ToNtStatus(error); } opened = TRUE; } @@ -394,19 +434,21 @@ MirrorReadFile( LARGE_INTEGER distanceToMove; distanceToMove.QuadPart = Offset; if (!SetFilePointerEx(handle, distanceToMove, NULL, FILE_BEGIN)) { + DWORD error = GetLastError(); DbgPrint(L"\tseek error, offset = %d\n\n", offset); if (opened) CloseHandle(handle); - return -1; + return ToNtStatus(error); } if (!ReadFile(handle, Buffer, BufferLength, ReadLength,NULL)) { + DWORD error = GetLastError(); DbgPrint(L"\tread error = %u, buffer length = %d, read length = %d\n\n", - GetLastError(), BufferLength, *ReadLength); + error, BufferLength, *ReadLength); if (opened) CloseHandle(handle); - return -1; + return ToNtStatus(error); } else { DbgPrint(L"\tread %d, offset %d\n\n", *ReadLength, offset); @@ -415,11 +457,11 @@ MirrorReadFile( if (opened) CloseHandle(handle); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorWriteFile( LPCWSTR FileName, LPCVOID Buffer, @@ -449,8 +491,9 @@ MirrorWriteFile( 0, NULL); if (handle == INVALID_HANDLE_VALUE) { - DbgPrint(L"\tCreateFile error : %d\n\n", GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tCreateFile error : %d\n\n", error); + return ToNtStatus(error); } opened = TRUE; } @@ -462,20 +505,23 @@ MirrorWriteFile( LARGE_INTEGER z; z.QuadPart = 0; if (!SetFilePointerEx(handle, z, NULL, FILE_END)) { - DbgPrint(L"\tseek error, offset = EOF, error = %d\n", GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tseek error, offset = EOF, error = %d\n", error); + return ToNtStatus(error); } } else if (!SetFilePointerEx(handle, distanceToMove, NULL, FILE_BEGIN)) { - DbgPrint(L"\tseek error, offset = %d, error = %d\n", offset, GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tseek error, offset = %d, error = %d\n", offset, error); + return ToNtStatus(error); } if (!WriteFile(handle, Buffer, NumberOfBytesToWrite, NumberOfBytesWritten, NULL)) { + DWORD error = GetLastError(); DbgPrint(L"\twrite error = %u, buffer length = %d, write length = %d\n", - GetLastError(), NumberOfBytesToWrite, *NumberOfBytesWritten); - return -1; + error, NumberOfBytesToWrite, *NumberOfBytesWritten); + return ToNtStatus(error); } else { DbgPrint(L"\twrite %d, offset %d\n\n", *NumberOfBytesWritten, offset); @@ -485,11 +531,11 @@ MirrorWriteFile( if (opened) CloseHandle(handle); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorFlushFileBuffers( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -503,20 +549,21 @@ MirrorFlushFileBuffers( if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return 0; + return STATUS_SUCCESS; } if (FlushFileBuffers(handle)) { - return 0; + return STATUS_SUCCESS; } else { - DbgPrint(L"\tflush error code = %d\n", GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tflush error code = %d\n", error); + return ToNtStatus(error); } } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorGetFileInformation( LPCWSTR FileName, LPBY_HANDLE_FILE_INFORMATION HandleFileInformation, @@ -538,7 +585,11 @@ MirrorGetFileInformation( handle = CreateFile(filePath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL); if (handle == INVALID_HANDLE_VALUE) - return -1; + { + DWORD error = GetLastError(); + DbgPrint(L"GetFileInfo failed(%d)\n", error); + return ToNtStatus(error); + } opened = TRUE; } @@ -556,8 +607,9 @@ MirrorGetFileInformation( ZeroMemory(&find, sizeof(WIN32_FIND_DATAW)); handle = FindFirstFile(filePath, &find); if (handle == INVALID_HANDLE_VALUE) { - DbgPrint(L"\tFindFirstFile error code = %d\n\n", GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tFindFirstFile error code = %d\n\n", error); + return ToNtStatus(error); } HandleFileInformation->dwFileAttributes = find.dwFileAttributes; HandleFileInformation->ftCreationTime = find.ftCreationTime; @@ -579,11 +631,11 @@ MirrorGetFileInformation( CloseHandle(handle); } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorFindFiles( LPCWSTR FileName, PFillFindData FillFindData, // function pointer @@ -604,8 +656,9 @@ MirrorFindFiles( hFind = FindFirstFile(filePath, &findData); if (hFind == INVALID_HANDLE_VALUE) { - DbgPrint(L"\tinvalid file handle. Error is %u\n\n", GetLastError()); - return -1; + error = GetLastError(); + DbgPrint(L"\tinvalid file handle. Error is %u\n\n", error); + return ToNtStatus(error); } FillFindData(&findData, DokanFileInfo); @@ -621,16 +674,16 @@ MirrorFindFiles( if (error != ERROR_NO_MORE_FILES) { DbgPrint(L"\tFindNextFile error. Error is %u\n\n", error); - return -1; + return ToNtStatus(error); } DbgPrint(L"\tFindFiles return %d entries in %s\n\n", count, filePath); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorDeleteFile( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -644,11 +697,11 @@ MirrorDeleteFile( DbgPrint(L"DeleteFile %s\n", filePath); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorDeleteDirectory( LPCWSTR FileName, PDOKAN_FILE_INFO DokanFileInfo) @@ -675,8 +728,9 @@ MirrorDeleteDirectory( hFind = FindFirstFile(filePath, &findData); if (hFind == INVALID_HANDLE_VALUE) { - DbgPrint(L"\tDeleteDirectory error code = %d\n\n", GetLastError()); - return -1; + DWORD error = GetLastError(); + DbgPrint(L"\tDeleteDirectory error code = %d\n\n", error); + return ToNtStatus(error); } while (hFind != INVALID_HANDLE_VALUE) { @@ -684,7 +738,7 @@ MirrorDeleteDirectory( wcscmp(findData.cFileName, L".") != 0) { FindClose(hFind); DbgPrint(L"\tDirectory is not empty: %s\n", findData.cFileName); - return -(int)ERROR_DIR_NOT_EMPTY; + return STATUS_DIRECTORY_NOT_EMPTY; } if (!FindNextFile(hFind, &findData)) { break; @@ -695,14 +749,14 @@ MirrorDeleteDirectory( if (error != ERROR_NO_MORE_FILES) { DbgPrint(L"\tDeleteDirectory error code = %d\n\n", error); - return -1; + return ToNtStatus(error); } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorMoveFile( LPCWSTR FileName, // existing file name LPCWSTR NewFileName, @@ -732,14 +786,14 @@ MirrorMoveFile( if (status == FALSE) { DWORD error = GetLastError(); DbgPrint(L"\tMoveFile failed status = %d, code = %d\n", status, error); - return -(int)error; + return ToNtStatus(error); } else { - return 0; + return STATUS_SUCCESS; } } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorLockFile( LPCWSTR FileName, LONGLONG ByteOffset, @@ -758,23 +812,24 @@ MirrorLockFile( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } length.QuadPart = Length; offset.QuadPart = ByteOffset; - if (LockFile(handle, offset.HighPart, offset.LowPart, length.HighPart, length.LowPart)) { - DbgPrint(L"\tsuccess\n\n"); - return 0; - } else { - DbgPrint(L"\tfail\n\n"); - return -1; + if (!LockFile(handle, offset.HighPart, offset.LowPart, length.HighPart, length.LowPart)) { + DWORD error = GetLastError(); + DbgPrint(L"\tfailed(%d)\n", error); + return ToNtStatus(error); } + + DbgPrint(L"\tsuccess\n\n"); + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorSetEndOfFile( LPCWSTR FileName, LONGLONG ByteOffset, @@ -791,27 +846,28 @@ MirrorSetEndOfFile( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } offset.QuadPart = ByteOffset; if (!SetFilePointerEx(handle, offset, NULL, FILE_BEGIN)) { + DWORD error = GetLastError(); DbgPrint(L"\tSetFilePointer error: %d, offset = %I64d\n\n", - GetLastError(), ByteOffset); - return GetLastError() * -1; + error, ByteOffset); + return ToNtStatus(error); } if (!SetEndOfFile(handle)) { DWORD error = GetLastError(); - DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + DbgPrint(L"\tSetEndOfFile error code = %d\n\n", error); + return ToNtStatus(error); } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorSetAllocationSize( LPCWSTR FileName, LONGLONG AllocSize, @@ -828,33 +884,34 @@ MirrorSetAllocationSize( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } if (GetFileSizeEx(handle, &fileSize)) { if (AllocSize < fileSize.QuadPart) { fileSize.QuadPart = AllocSize; if (!SetFilePointerEx(handle, fileSize, NULL, FILE_BEGIN)) { + DWORD error = GetLastError(); DbgPrint(L"\tSetAllocationSize: SetFilePointer eror: %d, " - L"offset = %I64d\n\n", GetLastError(), AllocSize); - return GetLastError() * -1; + L"offset = %I64d\n\n", error, AllocSize); + return ToNtStatus(error); } if (!SetEndOfFile(handle)) { DWORD error = GetLastError(); - DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + DbgPrint(L"\tSetEndOfFile error code = %d\n\n", error); + return ToNtStatus(error); } } } else { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + return ToNtStatus(error); } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorSetFileAttributes( LPCWSTR FileName, DWORD FileAttributes, @@ -871,15 +928,15 @@ MirrorSetFileAttributes( if (!SetFileAttributes(filePath, FileAttributes)) { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + return ToNtStatus(error); } DbgPrint(L"\n"); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorSetFileTime( LPCWSTR FileName, CONST FILETIME* CreationTime, @@ -898,21 +955,21 @@ MirrorSetFileTime( if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } if (!SetFileTime(handle, CreationTime, LastAccessTime, LastWriteTime)) { DWORD error = GetLastError(); DbgPrint(L"\terror code = %d\n\n", error); - return error * -1; + return ToNtStatus(error); } DbgPrint(L"\n"); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorUnlockFile( LPCWSTR FileName, LONGLONG ByteOffset, @@ -931,23 +988,24 @@ MirrorUnlockFile( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } length.QuadPart = Length; offset.QuadPart = ByteOffset; - if (UnlockFile(handle, offset.HighPart, offset.LowPart, length.HighPart, length.LowPart)) { - DbgPrint(L"\tsuccess\n\n"); - return 0; - } else { - DbgPrint(L"\tfail\n\n"); - return -1; + if (!UnlockFile(handle, offset.HighPart, offset.LowPart, length.HighPart, length.LowPart)) { + DWORD error = GetLastError(); + DbgPrint(L"\terror code = %d\n\n", error); + return ToNtStatus(error); } + + DbgPrint(L"\tsuccess\n\n"); + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorGetFileSecurity( LPCWSTR FileName, PSECURITY_INFORMATION SecurityInformation, @@ -966,7 +1024,7 @@ MirrorGetFileSecurity( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } if (!GetUserObjectSecurity(handle, SecurityInformation, SecurityDescriptor, @@ -974,17 +1032,17 @@ MirrorGetFileSecurity( int error = GetLastError(); if (error == ERROR_INSUFFICIENT_BUFFER) { DbgPrint(L" GetUserObjectSecurity failed: ERROR_INSUFFICIENT_BUFFER\n"); - return error * -1; + return STATUS_BUFFER_OVERFLOW; } else { DbgPrint(L" GetUserObjectSecurity failed: %d\n", error); - return -1; + return ToNtStatus(error); } } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorSetFileSecurity( LPCWSTR FileName, PSECURITY_INFORMATION SecurityInformation, @@ -1004,18 +1062,18 @@ MirrorSetFileSecurity( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_INVALID_HANDLE; } if (!SetUserObjectSecurity(handle, SecurityInformation, SecurityDescriptor)) { int error = GetLastError(); DbgPrint(L" SetUserObjectSecurity failed: %d\n", error); - return -1; + return ToNtStatus(error); } - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorGetVolumeInformation( LPWSTR VolumeNameBuffer, DWORD VolumeNameSize, @@ -1039,18 +1097,18 @@ MirrorGetVolumeInformation( wcscpy_s(FileSystemNameBuffer, FileSystemNameSize, L"Dokan"); - return 0; + return STATUS_SUCCESS; } -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorUnmount( PDOKAN_FILE_INFO DokanFileInfo) { UNREFERENCED_PARAMETER(DokanFileInfo); DbgPrint(L"Unmount\n"); - return 0; + return STATUS_SUCCESS; } /** @@ -1075,7 +1133,7 @@ NTSYSCALLAPI NTSTATUS NTAPI NtQueryInformationFile(_In_ HANDLE FileHandle, _Out * END */ -static int DOKAN_CALLBACK +static NTSTATUS DOKAN_CALLBACK MirrorEnumerateNamedStreams( LPCWSTR FileName, PVOID* EnumContext, @@ -1094,7 +1152,7 @@ MirrorEnumerateNamedStreams( handle = (HANDLE)DokanFileInfo->Context; if (!handle || handle == INVALID_HANDLE_VALUE) { DbgPrint(L"\tinvalid handle\n\n"); - return -1; + return STATUS_NOT_IMPLEMENTED; } // As we are requested one by one, it would be better to use FindFirstStream / FindNextStream instead of requesting all streams each time @@ -1107,12 +1165,12 @@ MirrorEnumerateNamedStreams( NTSTATUS status = NtQueryInformationFile(handle, &ioStatus, InfoBlock, sizeof(InfoBlock), FileStreamInformation); if (status != STATUS_SUCCESS) { DbgPrint(L"\tNtQueryInformationFile failed with %d.\n", status); - return -1; + return STATUS_NOT_IMPLEMENTED; } if (pStreamInfo->StreamNameLength == 0) { DbgPrint(L"\tNo stream found.\n"); - return -1; + return STATUS_NOT_IMPLEMENTED; } UINT index = (UINT)*EnumContext; @@ -1121,7 +1179,7 @@ MirrorEnumerateNamedStreams( for (UINT i = 0; i != index; ++i) { if (pStreamInfo->NextEntryOffset == 0) { DbgPrint(L"\tNo more stream.\n"); - return -1; + return STATUS_NOT_IMPLEMENTED; } pStreamInfo = (PFILE_STREAM_INFORMATION) ((LPBYTE)pStreamInfo + pStreamInfo->NextEntryOffset); // Next stream record } @@ -1135,7 +1193,7 @@ MirrorEnumerateNamedStreams( // Remember next stream entry index *EnumContext = (PVOID)++index; - return 0; + return STATUS_SUCCESS; } @@ -1147,13 +1205,13 @@ wmain(ULONG argc, PWCHAR argv[]) PDOKAN_OPERATIONS dokanOperations = (PDOKAN_OPERATIONS)malloc(sizeof(DOKAN_OPERATIONS)); if (dokanOperations == NULL) { - return -1; + return EXIT_FAILURE; } PDOKAN_OPTIONS dokanOptions = (PDOKAN_OPTIONS)malloc(sizeof(DOKAN_OPTIONS)); if (dokanOptions == NULL) { free(dokanOperations); - return -1; + return EXIT_FAILURE; } if (argc < 5) { @@ -1166,7 +1224,7 @@ wmain(ULONG argc, PWCHAR argv[]) " /n (use network drive)\n" " /m (use removable drive)\n" " /i (Timeout in Milliseconds ex. /i 30000)\n"); - return -1; + return EXIT_FAILURE; } g_DebugMode = FALSE; @@ -1210,7 +1268,7 @@ wmain(ULONG argc, PWCHAR argv[]) break; default: fwprintf(stderr, L"unknown command: %s\n", argv[command]); - return -1; + return EXIT_FAILURE; } } @@ -1281,6 +1339,6 @@ wmain(ULONG argc, PWCHAR argv[]) free(dokanOptions); free(dokanOperations); - return 0; + return EXIT_SUCCESS; } diff --git a/dokan_mount/mounter.c b/dokan_mount/mounter.c index b9dd0f2bf..f8bd4602e 100644 --- a/dokan_mount/mounter.c +++ b/dokan_mount/mounter.c @@ -464,7 +464,7 @@ int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstPrev, LPSTR lpszCmdLine, int StartServiceCtrlDispatcher(serviceTable); - return 0; + return EXIT_SUCCESS; } diff --git a/sys/directory.c b/sys/directory.c index 3d5bd5ff1..1787998b4 100644 --- a/sys/directory.c +++ b/sys/directory.c @@ -368,9 +368,9 @@ DokanCompleteDirectoryControl( //DDbgPrint(" copy DirectoryInfo\n"); RtlCopyMemory(buffer, EventInfo->Buffer, EventInfo->BufferLength); - DDbgPrint(" eventInfo->Directory.Index = %d\n", EventInfo->Operation.Directory.Index); - DDbgPrint(" eventInfo->BufferLength = %d\n", EventInfo->BufferLength); - DDbgPrint(" eventInfo->Status = %x (%d)\n", EventInfo->Status, EventInfo->Status); + DDbgPrint(" eventInfo->Directory.Index = %lu\n", EventInfo->Operation.Directory.Index); + DDbgPrint(" eventInfo->BufferLength = %lu\n", EventInfo->BufferLength); + DDbgPrint(" eventInfo->Status = %x (%lu)\n", EventInfo->Status, EventInfo->Status); // update index which specified n-th directory entry is returned // this should be locked before writing? diff --git a/sys/dokan.c b/sys/dokan.c index dd629c51f..37088657d 100644 --- a/sys/dokan.c +++ b/sys/dokan.c @@ -189,7 +189,7 @@ Return Value: status = DokanCreateGlobalDiskDevice(DriverObject, &dokanGlobal); - if (status != STATUS_SUCCESS) { + if (NT_ERROR(status)) { return status; } // diff --git a/sys/public.h b/sys/public.h index c3da5c0f1..872a4f592 100644 --- a/sys/public.h +++ b/sys/public.h @@ -243,7 +243,7 @@ typedef struct _EVENT_CONTEXT { typedef struct _EVENT_INFORMATION { ULONG SerialNumber; - ULONG Status; + NTSTATUS Status; ULONG Flags; union { struct { diff --git a/sys/read.c b/sys/read.c index d48b16af8..2db3ef470 100644 --- a/sys/read.c +++ b/sys/read.c @@ -242,7 +242,7 @@ DokanCompleteRead( } } - if (status == STATUS_SUCCESS) { + if (NT_SUCCESS(status)) { DDbgPrint(" STATUS_SUCCESS\n"); } else if (status == STATUS_INSUFFICIENT_RESOURCES) { DDbgPrint(" STATUS_INSUFFICIENT_RESOURCES\n");