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

#45 Change to NTSTATUS #65

merged 1 commit into from
Sep 26, 2015

Conversation

Liryna
Copy link
Member

@Liryna Liryna commented Sep 26, 2015

No description provided.

Liryna added a commit that referenced this pull request Sep 26, 2015
@Liryna Liryna merged commit de3cbc5 into master Sep 26, 2015
@suy
Copy link

suy commented Sep 27, 2015

That was a quick merge. :-)

I suppose you know a lot better than me why this is needed and good, so I can't really oppose. I think this is also one of the things that DokanX changed, right? Good that both projects are more aligned, just in case.

Since I probably will need to port to the newer version, it will be good to have some minimum comments on porting. The changes in mirror.c are almost all needed. What surprises me, is that more or less you moved from the library to the user applications the win32 to NTSTATUS switch-case that maps one to other. I don't understand what is gained by that. 😮

The switch-case in create.c was in the wiki of my project because I wanted to know which status code I can return from CreateFile, so the user has a moderately useful error message. I suppose there isn't much that you can do, right? The OS will give generic error messages?

Thank you!

@marinkobabic
Copy link
Contributor

You have a much better control what status should be returned to the os. So you can decide what message should be displayed to the user. Depending on NTSTATUS the os behaves different in specific cases. Now it's up to you to decide what happened in your code and how you want report it to the is respective to user.
Before the change you had the code -1 which means nothing for os.

NTSTATUS provides more direct reporting to os and user. It gives you more flexibility.

@suy
Copy link

suy commented Sep 27, 2015

Oh, then that's excellent news! I reviewed the differences, but not understanding everything properly I thought there was still some checking of specific return values that were the ones supported. Thank you!

@Liryna
Copy link
Member Author

Liryna commented Sep 27, 2015

This commit was in branch since some weeks now, I had one issue that I have only been able to correct yesterday.

you can find some information to convert your Win32 error here:
https://support.microsoft.com/en-us/kb/113996

or here, but you should be very careful because like @marinkobabic told, there is specific case where you cannot answer what you want.
So this switch case should only be used as example of error conversion.
https://www.eldos.com/forum/read.php?PAGEN_1=4&TID=688

    NTSTATUS
    Error2NtStatus(
        IN ULONG Win32ErrorCode              
        )
    {
        switch(Win32ErrorCode)
        {
        case ERROR_SUCCESS:
            return STATUS_SUCCESS;

        case ERROR_ACCESS_DENIED:
            return STATUS_ACCESS_DENIED;

        case ERROR_NOACCESS:
            return STATUS_ACCESS_VIOLATION;

        case ERROR_NOT_SUPPORTED:
            return STATUS_NOT_SUPPORTED;

        case ERROR_INVALID_PARAMETER:
            return STATUS_INVALID_PARAMETER;

        case ERROR_INVALID_HANDLE:
            return STATUS_INVALID_HANDLE;

        case ERROR_NOT_LOCKED:
            return STATUS_NOT_LOCKED;

        case ERROR_NO_SYSTEM_RESOURCES:
            return STATUS_INSUFFICIENT_RESOURCES;

        case ERROR_NOT_ENOUGH_MEMORY:
            return STATUS_NO_MEMORY;                        

        case ERROR_MORE_DATA:
            return STATUS_BUFFER_OVERFLOW;

        case ERROR_INSUFFICIENT_BUFFER:
            return STATUS_BUFFER_TOO_SMALL;

        case ERROR_NO_MORE_FILES:
            return STATUS_NO_MORE_FILES;

        case ERROR_FILE_NOT_FOUND:    
            return STATUS_NO_SUCH_FILE;

        case ERROR_INVALID_FUNCTION:
            return STATUS_NOT_SUPPORTED;

        case ERROR_CALL_NOT_IMPLEMENTED:
            return STATUS_NOT_IMPLEMENTED;

        case ERROR_HANDLE_EOF:
            return STATUS_END_OF_FILE;

        case ERROR_INVALID_NAME:
            return STATUS_OBJECT_NAME_INVALID;

        case ERROR_DISK_FULL:
            return STATUS_DISK_FULL;

        case ERROR_DISK_CORRUPT:
            return STATUS_DISK_CORRUPT_ERROR;

        case ERROR_BAD_COMMAND:
            return STATUS_INVALID_DEVICE_STATE;

        case ERROR_FILE_EXISTS:
            return STATUS_OBJECT_NAME_COLLISION;

        case ERROR_ALREADY_EXISTS:
            return STATUS_OBJECT_NAME_COLLISION;

        case ERROR_CANNOT_MAKE:
            return STATUS_CANNOT_MAKE;

        case ERROR_PROC_NOT_FOUND:
            return STATUS_PROCEDURE_NOT_FOUND;

        case ERROR_OPERATION_ABORTED:
            return STATUS_CANCELLED;

        case ERROR_IO_DEVICE:
        case TYPE_E_IOERROR:
            return STATUS_IO_DEVICE_ERROR;

        case ERROR_BAD_UNIT:
            return STATUS_NO_SUCH_DEVICE; //STATUS_DEVICE_DOES_NOT_EXIST

        case ERROR_BAD_ARGUMENTS:
            return STATUS_INVALID_PARAMETER;

        case ERROR_BAD_EXE_FORMAT:
            return STATUS_INVALID_IMAGE_FORMAT;

        case ERROR_WAIT_NO_CHILDREN:
            return STATUS_NOT_FOUND;

        case ERROR_RETRY:
            return STATUS_RETRY;

        case ERROR_INVALID_ADDRESS:
            return STATUS_CONFLICTING_ADDRESSES;

        case ERROR_BUSY:
            return STATUS_DEVICE_BUSY;

        case ERROR_DIRECTORY:
            return STATUS_NOT_A_DIRECTORY;

        case ERROR_TOO_MANY_OPEN_FILES:
            return STATUS_TOO_MANY_OPENED_FILES;

        case ERROR_EA_TABLE_FULL:
            return STATUS_EA_TOO_LARGE;

        case ERROR_FILE_INVALID:
            return STATUS_FILE_INVALID;

        case ERROR_CONNECTION_UNAVAIL:
            return STATUS_CONNECTION_DISCONNECTED; //STATUS_DFS_UNAVAILABLE                  

        case ERROR_TOO_MANY_LINKS:
            return STATUS_TOO_MANY_LINKS;

        case ERROR_BROKEN_PIPE:
            return STATUS_PIPE_BROKEN;

        case ERROR_ARITHMETIC_OVERFLOW:
            return STATUS_INTEGER_OVERFLOW;

        case ERROR_POSSIBLE_DEADLOCK:
            return STATUS_POSSIBLE_DEADLOCK;

        case ERROR_BUFFER_OVERFLOW:
            return STATUS_NAME_TOO_LONG;

        case ERROR_TOO_MANY_SEMAPHORES:
            return STATUS_INSUFFICIENT_RESOURCES;

        case ERROR_DIR_NOT_EMPTY:
            return STATUS_DIRECTORY_NOT_EMPTY;

        case ERROR_PATH_NOT_FOUND:
            return STATUS_OBJECT_PATH_NOT_FOUND;

        case ERROR_ARENA_TRASHED:
            return STATUS_DISK_CORRUPT_ERROR;

        case ERROR_INVALID_BLOCK:
            return STATUS_INVALID_ADDRESS;

        case ERROR_BAD_ENVIRONMENT:
            return STATUS_VARIABLE_NOT_FOUND;

        case ERROR_SHARING_VIOLATION:
            return STATUS_SHARING_VIOLATION;

        case ERROR_FILENAME_EXCED_RANGE:
            return STATUS_NAME_TOO_LONG;

        case ERROR_NOT_READY:
            return STATUS_DEVICE_NOT_READY; //or STATUS_NO_MEDIA_IN_DEVICE, STATUS_VOLUME_DISMOUNTED

        case ERROR_FILE_OFFLINE:
            return STATUS_FILE_IS_OFFLINE;    

        case ERROR_REMOTE_STORAGE_NOT_ACTIVE:
            return STATUS_REMOTE_STORAGE_NOT_ACTIVE;

        //
        // Winsock errors
        //

        case WSAEINTR:
            return STATUS_CANCELLED;

        case WSAEBADF:
            return STATUS_INVALID_HANDLE;

        case WSATRY_AGAIN:
            return STATUS_RETRY;

        default:
            return STATUS_UNSUCCESSFUL;
        }
    }

@Liryna Liryna deleted the NTSTATUS branch September 27, 2015 11:23
@rustyx
Copy link
Contributor

rustyx commented Mar 27, 2016

So, now I'm supposed to map Win32 GetLastError() first to NTSTATUS somehow, then have that mapped to errno, pass it to dokan_fuse, which would translate errno back to NTSTATUS? Does not sound like an improvement to me.

Nice code sample, but there are >2000 NTSTATUSes en Win32 errors.

Don't understand why win32_error_to_errno was removed from dokan_fuse. How am I supposed to pass Win32 errors to dokan_fuse now?

@Liryna
Copy link
Member Author

Liryna commented Mar 28, 2016

@rustyx Without using NTSTATUS error, dokan would not be able to answer correctly to the kernel windows (Kernel Windows does not use Win32 error). Before dokan was answering the same dummy ntstatus error whatever the user was returning a GetLastError(). Now the mirror sample is much more stable and answer correctly to all request.

With the mirror sample and microsoft documentation of this pagen there is no difficulty to make the changes.

If you was using win32_error_to_errno (replaced by ntstatus_error_to_errno) you was anyway already using a switch/case ->

static const struct errentry errtable[] = {
{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 */
};

that I updated.

There is not changes for you if you was already using the wrapper fuse.

@Liryna
Copy link
Member Author

Liryna commented Jun 12, 2016

Helper DokanNtStatusFromWin32 has been added in Dokan Library and can be used to translate Win32 Error code to the NtStatus code's corresponding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants