Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#45 Change to NTSTATUS #65

Merged
merged 1 commit into from
Sep 26, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions dokan/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <ntstatus.h>
#include "dokani.h"
#include "fileinfo.h"

Expand Down
1 change: 1 addition & 0 deletions dokan/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include <ntstatus.h>
#include "dokani.h"
#include "fileinfo.h"

Expand Down
77 changes: 17 additions & 60 deletions dokan/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include <ntstatus.h>
#include "dokani.h"
#include "fileinfo.h"

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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) &&
Expand Down
8 changes: 4 additions & 4 deletions dokan/directory.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ You should have received a copy of the GNU Lesser General Public License along
with this program. If not, see <http://www.gnu.org/licenses/>.
*/


#include <ntstatus.h>
#include "dokani.h"
#include "fileinfo.h"
#include "list.h"
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down
65 changes: 31 additions & 34 deletions dokan/dokan.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,43 +79,40 @@ 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
DWORD, // CreationDisposition
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
Expand All @@ -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
Expand All @@ -133,38 +130,38 @@ 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);


// 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
Expand All @@ -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
Expand All @@ -227,15 +224,15 @@ 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
PDOKAN_FILE_INFO);


// see Win32 API GetVolumeInformation
int (DOKAN_CALLBACK *GetVolumeInformation) (
NTSTATUS (DOKAN_CALLBACK *GetVolumeInformation) (
LPWSTR, // VolumeNameBuffer
DWORD, // VolumeNameSize in num of chars
LPDWORD,// VolumeSerialNumber
Expand All @@ -246,28 +243,28 @@ 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
ULONG, // length of Security descriptor buffer
PULONG, // LengthNeeded
PDOKAN_FILE_INFO);

int (DOKAN_CALLBACK *SetFileSecurity) (
NTSTATUS (DOKAN_CALLBACK *SetFileSecurity) (
LPCWSTR, // FileName
PSECURITY_INFORMATION,
PSECURITY_DESCRIPTOR, // SecurityDescriptor
ULONG, // SecurityDescriptor length
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
Expand Down
1 change: 0 additions & 1 deletion dokan/dokan.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@
<ClCompile Include="read.c" />
<ClCompile Include="security.c" />
<ClCompile Include="setfile.c" />
<ClCompile Include="status.c" />
<ClCompile Include="timeout.c" />
<ClCompile Include="version.c" />
<ClCompile Include="volume.c" />
Expand Down
Loading