EldoS | Feel safer!

Software components for data protection, secure storage and transfer

'File already exists' error code.

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#6165
Posted: 05/07/2008 10:25:02
by Vladimir Lichman (Priority Standard support level)
Joined: 05/01/2008
Posts: 19

What error code should I pass to ECBFSError exception constructor thrown in OnCreateFile to inform the system that file or folder can not be created?
private void CbFsCreateFile(…)
{
...
throw new ECBFSError(ERROR_CANNOT_MAKE);
}

I have tried this codes:
ERROR_FILE_EXISTS = 80; // The file exists.
ERROR_ALREADY_EXISTS = 183; // Cannot create a file when that file already exists.
ERROR_CANNOT_MAKE = 82; // The directory or file cannot be created.

But they all show same popup in Windows Explorer:
Unable to create folder ‘New Folder’
A device attached to the system is not functioning.


How do I show a meaningful message using predefined windows error codes? I want to show something similar to “The file or folder cannot be created.”or “File or folder with such name already exists” popup.
#6168
Posted: 05/07/2008 12:37:25
by Volodymyr Zinin (EldoS Corp.)

I'll check it and answer a little later.
#6182
Posted: 05/08/2008 15:26:38
by Volodymyr Zinin (EldoS Corp.)

The problem is in the CallbackFS driver code. We convert the win32 error codes into the native ones using the table of errors that doesn't contain all error pairs yet. That's why some errors are converted into the default value STATUS_UNSUCCESSFUL.

Quote

I have tried this codes: ERROR_FILE_EXISTS = 80; // The file exists. ERROR_ALREADY_EXISTS = 183; // Cannot create a file when that file already exists. ERROR_CANNOT_MAKE = 82; // The directory or file cannot be created.

I've added these codes and in the next update they will work.

Now you can use the following errors:
ERROR_INVALID_NAME
ERROR_ACCESS_DENIED
ERROR_NOACCESS
ERROR_NOT_SUPPORTED
ERROR_INVALID_HANDLE
ERROR_NOT_ENOUGH_MEMORY
ERROR_FILE_NOT_FOUND
etc.
#11230
Posted: 10/02/2009 13:18:01
by Hunter Hagewood (Standard support level)
Joined: 10/02/2009
Posts: 9

Hi Vladimir,

I´m having problems with error codes that are not converted yet. I know that some errors map to "STATUS_UNSUCCESSFUL (with code 0xC0000001)"

Can you please show a list of know converted codes? It´s ok to include at least the codes above?

ERROR_SUCCESS
ERROR_NOT_READY
ERROR_FILE_EXISTS
ERROR_FILE_NOT_FOUND
ERROR_HANDLE_EOF
ERROR_DIR_NOT_EMPTY
ERROR_DIRECTORY
ERROR_NO_MORE_FILES
ERROR_ACCESS_DENIED
ERROR_DISK_FULL
ERROR_FILE_OFFLINE
ERROR_REMOTE_STORAGE_NOT_ACTIVE

Thank you,
Fabio
#11231
Posted: 10/03/2009 03:24:09
by Volodymyr Zinin (EldoS Corp.)

Hi,

All of the specified error codes except ERROR_NOT_READY, ERROR_FILE_OFFLINE, and ERROR_REMOTE_STORAGE_NOT_ACTIVE have already been included. And we will add the last ones to the next build.

Quote
Hunter Hagewood wrote:
Can you please show a list of know converted codes?

Code
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;

    //
    // Winsock errors
    //

    case WSAEINTR:
        return STATUS_CANCELLED;

    case WSAEBADF:
        return STATUS_INVALID_HANDLE;

    case WSATRY_AGAIN:
        return STATUS_RETRY;

    default:
        return STATUS_UNSUCCESSFUL;
    }
}
#21102
Posted: 08/21/2012 11:58:54
by Ivan P (Priority Standard support level)
Joined: 04/11/2011
Posts: 66

Hi there,

How actual is this list?

Is it possible to manually return ERROR_TIME_OUT? Will it be converted to STATUS_TIMEOUT?
Does it make sense for applications (for example, Windows Explorer) if they receive ERROR_TIMEOUT?

Thanks,
IP
#21109
Posted: 08/21/2012 13:03:45
by Volodymyr Zinin (EldoS Corp.)

Quote
Ivan P wrote:
How actual is this list?

Here is the current state of it.
Code
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;

    case ERROR_NO_SUCH_PRIVILEGE:  
        return STATUS_NO_SUCH_PRIVILEGE;                
      
    case ERROR_PRIVILEGE_NOT_HELD:
        return STATUS_PRIVILEGE_NOT_HELD;

    case ERROR_CANNOT_IMPERSONATE:
        return STATUS_CANNOT_IMPERSONATE;

    case ERROR_WRITE_PROTECT:
        return STATUS_MEDIA_WRITE_PROTECTED;

    case ERROR_LOGON_FAILURE:
        return STATUS_LOGON_FAILURE;

    //
    // Winsock errors
    //

    case WSAEINTR:
        return STATUS_CANCELLED;

    case WSAEBADF:
        return STATUS_INVALID_HANDLE;

    case WSATRY_AGAIN:
        return STATUS_RETRY;

    default:
        return STATUS_UNSUCCESSFUL;
    }
}


Quote
Ivan P wrote:
Is it possible to manually return ERROR_TIME_OUT? Will it be converted to STATUS_TIMEOUT?

Returning of the STATUS_TIMEOUT error code in some cases caused BSOD in the system code. That is why it isn't in the list.
#21865
Posted: 10/08/2012 03:30:48
by Ivan P (Priority Standard support level)
Joined: 04/11/2011
Posts: 66

Found interesting MS KB article that describes the opposite mapping:
"Mapping NT Status Error Codes to Win32 Error Codes"
http://support.microsoft.com/kb/113996
Though it's quite old (2005), I don't think it changed significantly (maybe extended), and still can be used to understand what to expect from windows applications that work with CBFS-mounted disk.
Foe example, throwing ECBFSError with code ERROR_BAD_UNIT inside CBFS callback, will cause driver to report STATUS_NO_SUCH_DEVICE, which according to the article will be finally passed to windows app as ERROR_FILE_NOT_FOUND.

Sincerely,
IP
#21868
Posted: 10/08/2012 08:43:14
by Volodymyr Zinin (EldoS Corp.)

Thank you. We know about this conversion list and add from time to time some items from there to our list.
#21890
Posted: 10/09/2012 11:51:59
by Ivan P (Priority Standard support level)
Joined: 04/11/2011
Posts: 66

One more question then. According to your code ECBFSError with ERROR_INVALID_FUNCTION code will be translated into STATUS_NOT_SUPPORTED status, and then will be translated by Windows to ERROR_NOT_SUPPORTED win32 error code.

Wouldn't it be more correct to translate ERROR_INVALID_FUNCTION to STATUS_ILLEGAL_FUNCTION or other NT status code that will be brought to WinAPI as ERROR_INVALID_FUNCTION too?

The same applies to ERROR_SHARING_VIOLATION which is translated to STATUS_RETRY instead of STATUS_SHARING_VIOLATION

Thanks,
IP
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 7691 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!