EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Disk is not formatted error when using CallbackFS

Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.
#6748
Posted: 06/25/2008 15:48:28
by Volodymyr Zinin (EldoS Corp.)

I think I've understood where the problem is.
When a callback function (OnEnumerateDirectory in your case) returns an error, the error before sending to the CallbackFS driver is converted (by CallbackFS) from win32 error format to a status code. For example ERROR_ACCESS_DENIED is converted to STATUS_ACCESS_DENIED. It's necessary because kernel mode code only works with the STATUS_... error codes.
But the internal function that performs this conversion doesn't convert all the win32 errors (at least now). A lot of win32 errors are currently converted to STATUS_UNSUCCESSFUL (with code 0xC0000001) and in your case (when you throw a CBFSError with your own formatted string from OnEnumerateDirectory) just this error is sent to the driver, and the driver returns this error to the system, and the system decides to show the "Disk not formatted" message box.

I see the following workaround of the problem - to throw a CBFSError with an win32 error code that is "correctly" converted to a status code (see the list below). Tell me if you want to throw another error and I will add the conversion for it too.

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;

    default:
        return STATUS_UNSUCCESSFUL;
}
#6789
Posted: 06/30/2008 10:54:55
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

What .h file has the definitions for the STATUS_ codes?
#6791
Posted: 06/30/2008 12:28:43
by Volodymyr Zinin (EldoS Corp.)

It's located in DDK and called status.h
But please write me a list of ERROR_ codes which you want to add and I'll add the corresponding STATUS_ codes myself.
#6792
Posted: 06/30/2008 12:32:22
by Volodymyr Zinin (EldoS Corp.)

Quote
Vladimir Zinin wrote:
called status.h

Oh, sorry. It's called ntstatus.h
#6793
Posted: 06/30/2008 17:37:20
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

Well, the errors I get back from my system are UNIX style errors, so I wrote a conversion program to convert them to Winerror.h style errors. That conversion program is listed below. All the error codes I use are in it.

int CSrbVDiskApp::ConvertErrnoToWinerr()
{
switch (errno)
{
case EACCES:
case EPERM:
return ERROR_ACCESS_DENIED;
case ENOENT:
return ERROR_FILE_NOT_FOUND;
case ESRCH:
return ERROR_PROC_NOT_FOUND;
case EINTR:
return WSAEINTR;
case EIO:
return TYPE_E_IOERROR;
case ENODEV:
case EXDEV:
case ENXIO:
case ENOTTY:
return ERROR_BAD_UNIT;
case E2BIG:
case EINVAL:
return ERROR_BAD_ARGUMENTS;
case ENOEXEC:
return ERROR_BAD_EXE_FORMAT;
case EBADF:
return ERROR_FILE_NOT_FOUND;
case ECHILD:
return ERROR_WAIT_NO_CHILDREN;
case EAGAIN:
return WSATRY_AGAIN;
case ENOMEM:
return ERROR_NOT_ENOUGH_MEMORY;
case EFAULT:
return ERROR_INVALID_ADDRESS;
case EBUSY:
return ERROR_BUSY;
case EISDIR:
case EEXIST:
return ERROR_FILE_EXISTS;
case ENOTDIR:
return ERROR_DIRECTORY;
case ENFILE:
return ERROR_EA_TABLE_FULL;
case EMFILE:
return ERROR_TOO_MANY_OPEN_FILES;
case EFBIG:
return ERROR_FILE_INVALID;
case ENOSPC:
return ERROR_DISK_FULL;
case ENOTCONN:
return ERROR_CONNECTION_UNAVAIL;
case EMLINK:
return ERROR_TOO_MANY_LINKS;
case EPIPE:
return ERROR_BROKEN_PIPE;
case EDOM:
return ERROR_ARITHMETIC_OVERFLOW;
case EDEADLK:
return ERROR_POSSIBLE_DEADLOCK;
case ENAMETOOLONG:
return ERROR_BUFFER_OVERFLOW;
case ENOLCK:
return ERROR_TOO_MANY_SEMAPHORES;
case ENOSYS:
return ERROR_CALL_NOT_IMPLEMENTED;
case ENOTEMPTY:
return ERROR_DIR_NOT_EMPTY;
}
return ERROR_SUCCESS;
}
#6825
Posted: 07/02/2008 15:49:36
by Volodymyr Zinin (EldoS Corp.)

These error codes will be available in the next build. We'll add them.
#10683
Posted: 07/28/2009 11:56:04
by Ivan Moiseev (Standard support level)
Joined: 07/28/2009
Posts: 1

The bug(?) is found.

OnEnumerateDirectory event documentation says:
CreationTime - the event handler must place the time of the object creation to this parameter. The value can be empty (zero in VCL, DateTime.MinValue in .NET) if the parameter is not supported.
LastAccessTime - the event handler must place the time of last access to the object to this parameter. The value can be empty (zero in VCL, DateTime.MinValue in .NET) or equal if the parameter is not supported.
LastWriteTime - the event handler must place the time of last modification of the object to this parameter. The value can be empty (zero in VCL, DateTime.MinValue in .NET) if the parameter is not supported.


The following code will cause "Disk is not formatted" message:
Code
CreationTime = DateTime.MinValue;
LastAccessTime = DateTime.MinValue;            
LastWriteTime = finfo.LastWriteTime;


I've changed 2 lines of code in .NET 2.0 sample (According to the documentation, it's not it?) and got this error message.
#10684
Posted: 07/28/2009 12:02:58
by Eugene Mayevski (EldoS Corp.)

Thank you for report. I've moved it to HelpDesk for investigation.


Sincerely yours
Eugene Mayevski
#15305
Posted: 12/14/2010 15:09:29
by Matthew Buchman (Priority Standard support level)
Joined: 12/14/2010
Posts: 1

We have just started encountering this error on Windows 2008 SP2. I've read through the thread above but wasn't clear on what the resolution was. Is there a resolution to the problem in code?
#15306
Posted: 12/14/2010 20:39:31
by Eugene Mayevski (EldoS Corp.)

This topic became too long and it's not clear if it has anything to do with your current problem.

Let's create a new forum post and start solving the problem as if it were a new one.


Sincerely yours
Eugene Mayevski
Also by EldoS: CallbackFilter
A component to monitor and control disk activity, track file and directory operations (create, read, write, rename etc.), alter file data, encrypt files, create virtual files.

Reply

Statistics

Topic viewed 23239 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!