EldoS | Feel safer!

Software components for data protection, secure storage and transfer

cancel reading

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#8598
Posted: 01/12/2009 13:58:38
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75


There are some cases when I have to cancel reading operation (disc is not present) in the function :
Code
private void CbFsReadFile(...)
{
            GCHandle gch = GCHandle.FromIntPtr(FileHandleContext);
            VirtualFile vfile = (VirtualFile)gch.Target;
            if (vfile.FStream == null)
            {
                vfile.FStream = GetFileStream(ref vfile);
                if (vfile.FStream == null)
                    throw new ECBFSError("File not found.");
            }
            vfile.Read(Buffer, Position, BytesToRead, ref BytesRead);
}  

I find that cbfs keep calling CbFsReadFile again and again. Even when I throw a ECBFSError. In this case windows explorer is freezing for a while.
How can I stop it from the first time.

I am using CBFSNet version 2.1.43.26137

Thanks

#8599
Posted: 01/12/2009 14:05:55
by Eugene Mayevski (EldoS Corp.)

You must throw "new ECBFSError(2)" which will tell the OS that the file is not found (WinAPI error code 2 == ERROR_FILE_NOT_FOUND). Of course, you can use some other error code.


Sincerely yours
Eugene Mayevski
#8600
Posted: 01/12/2009 14:46:04
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75

still keep reading and this repeating is depend on the file size.
I mean it will take longer time with big file size.

Quote

Of course, you can use some other error code.

I searched eldos web site for other error code but I didn't find them.
Also I googled but there is different error codes.

Can I give the list/link of all error code ?

thanks
#8601
Posted: 01/12/2009 15:18:52
by Eugene Mayevski (EldoS Corp.)

Quote
Khayralla AL-Athari wrote:
still keep reading and this repeating is depend on the file size.


This is a known problem -- if you didn't report "file not found" error when opening the file, then you should return some other error code that has some other meaning. For the list of WinAPI error codes you need to search MSDN and check winerror.h file in Platform SDK. As these are not CBFS codes, we don't have them.

Not all error codes are passed as is to the OS. This is caused by double conversion of error codes to native and then back to WinAPI.

Vladimir Zinin will give more information tomorrow.


Sincerely yours
Eugene Mayevski
#8602
Posted: 01/12/2009 15:19:58
by Eugene Mayevski (EldoS Corp.)

"Native" here denotes native subsystem of Windows NT kernel.


Sincerely yours
Eugene Mayevski
#8604
Posted: 01/13/2009 00:51:35
by Volodymyr Zinin (EldoS Corp.)

Hi,

It's the system cache manager repeats the OnRead/OnWrite request several times and the CallbackFS core only passes it to the user callbacks. Perhaps returning some specific error will help to interrupt the repeating. Use for this the constructor ECBFSError(uint Win32ErrorCode).
But the right way is to call UnmountMedia. After this call the CallbackFS driver will report to the system that the "media" is removed. UnmountMedia should be called not from the callbacks functions.
#8605
Posted: 01/13/2009 08:44:12
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75

Hi Vladimir

Quote

But the right way is to call UnmountMedia. After this call the CallbackFS driver will report to the system that the "media" is removed. UnmountMedia should be called not from the callbacks functions.


I have a Robotics containing 200 DVD, some of these DVD's are present, others are not.
Do you think it is effective to use UnmountMedia for the absent DVD's and then use mountMedia(5000) for those present, or your seggestion just for one DVD in the Read/write Optical Drive.

thanks
#8606
Posted: 01/13/2009 09:01:15
by Eugene Mayevski (EldoS Corp.)

How comes that the DVD disappears during reading? If you have opened the file and have not reported the error, is it possible that the DVD goes away while the file is open? If yes, then you should find the right error code which will tell the OS to stop reading the file. I am pretty sure that such error code exists.


Sincerely yours
Eugene Mayevski
#8607
Posted: 01/13/2009 09:08:43
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75

Actually I am reading Files information from a database, which contains the DVD position in the robotics, so user can see files in the Windows Explorer.

When he click on a specific file, robtics will move the DVD into the robotics Drive if that DVD exist. Otherwise I have to throw an error.

Any way, I will look for the right error code.

thanks again.
#8610
Posted: 01/13/2009 10:53:29
by Eugene Mayevski (EldoS Corp.)

You initially asked about the error during *reading of file*. The scenario that you describe now doesn't correlate with the initial question. You should not open the file if the media is not available, and that's the most straightforward solution. First load the media, then open the file. So all handling of disk absence should be done in OnFileOpen.

Opening the file successfully and then not letting the OS to read can cause various problems as you can see yourself.


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 7084 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!