EldoS | Feel safer!

Software components for data protection, secure storage and transfer

WriteFile error Message?

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.
#10784
Posted: 08/11/2009 10:47:16
by Bastian Moldenhauer (Standard support level)
Joined: 06/04/2009
Posts: 40

Hey,

I want the explorer to pop up a message that tells the user that the write opperation failed something like :"Error writing file to disk."

I tried the following:
Code
      private void CbFsWriteFile(object sender, CbFsFileInfo FileInfo, IntPtr FileHandleContext, long Position, byte[] Buffer, int BytesToWrite, ref int BytesWritten)
      {
            BytesWritten = 0;
            //ERROR_WRITE_FAULT == 29, see WinError.h
            throw new ECBFSError((uint)Errors.ERROR_WRITE_FAULT);
}

The strange thing here is, the explorer tells me that the source file could not been read!?
I even tried to return -1 for BytesWritten with the same results..

How to tell the OS that the write operation failed?

Regards
#10785
Posted: 08/11/2009 11:05:32
by Eugene Mayevski (EldoS Corp.)

Unfortunately we don't have an exact answer, because the error code you are setting is passed to the kernel mode (which uses it's own error constants, and we perform translation of the errors), next the OS converts those error codes to user-mode errors in Explorer, and then Explorer decides how to display the error codes to the user. You would need to test different error codes. If you find some suitable solution, please let everybody know by posting your findings here.


Sincerely yours
Eugene Mayevski
#10786
Posted: 08/11/2009 11:31:07
by Bastian Moldenhauer (Standard support level)
Joined: 06/04/2009
Posts: 40

mmhh, I tried:

Code
private void CbFsWriteFile(object sender, CbFsFileInfo FileInfo, IntPtr FileHandleContext, long Position, byte[] Buffer, int BytesToWrite, ref int BytesWritten)
      {
            BytesWritten = 0;
}
//and
private void CbFsWriteFile(object sender, CbFsFileInfo FileInfo, IntPtr FileHandleContext, long Position, byte[] Buffer, int BytesToWrite, ref int BytesWritten)
      {
            BytesWritten = -1;
}


in my understanding at least those should pop up the correct message..
maybe something with the constants regarding read and write is mixed up?

i will try to find a value that returns the correct error message
#10787
Posted: 08/11/2009 11:39:45
by Volodymyr Zinin (EldoS Corp.)

For the ReadFile/WriteFile callbacks there is also another problem. If a file is accessed via memory mapped section then the real read/write is performed by the system memory manager. And if an error occurs then the last one will try to read/write several times and then show an error notification box in the desktop tray. At least this is so for the Write operation. Such behavior was implemented by Windows because it isn't possible to know whether an error occurs during writing to MMF section - an application just writes to the memory allocated for a MMF section but the real file I/O is performed later by the memory manager during the data flush.
#10788
Posted: 08/11/2009 12:23:18
by Bastian Moldenhauer (Standard support level)
Joined: 06/04/2009
Posts: 40

don't laugh at me..i just tried the following:
Code
        static uint error = 0;
      private void CbFsWriteFile(object sender, CbFsFileInfo FileInfo, IntPtr FileHandleContext, long Position, byte[] Buffer, int BytesToWrite, ref int BytesWritten)
      {
            BytesWritten = 0;
            uint t = error;
            error++;
            throw new ECBFSError(t);

and klicked "repeat" about 3000 times(thank god my mouse is still alive..)
and came up with this messages

20 - Element not found
32 - File already opened
38 - EOF(End of File)
80 - duplicate Name
183 - duplicate name
109 - pipe closed
111 - path too long
112 - disc full, not enough space
123 - path too long
143 - folder not empty
268 - foldername invalid
1201 - network error while acessing file(which i will take)

There have been some "out of ressources" and other messages i did not write down.
Most of the errorcode lead to "source file could not been read". maybe something is mixed up here. error in write should default to a write error message i think...
Also by EldoS: SecureBlackbox
200+ components and classes for digital security, signing, encryption and secure networking.

Reply

Statistics

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