EldoS | Feel safer!

Software components for data protection, secure storage and transfer

ECBFSError in OnDeleteFile()

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#15587
Posted: 01/21/2011 03:32:17
by Robert Baer (Basic support level)
Joined: 11/08/2010
Posts: 46

Hello,

I just recognized that ECBFSError exceptions inside OnDeleteFile callbacks are not passed to the accessing program. You can reproduce this behavior with Mapper sample. Just add a "throw ECBFSError(ERROR_ACCESS_DENIED);" to the beginning of CbFsDeleteFile method and try to delete a file on the drive. The file will disappear after deletion and shows up again when refreshing.

Regards,
Robert
#15588
Posted: 01/21/2011 05:08:51
by Volodymyr Zinin (EldoS Corp.)

Hello Robert,

It's correct behavior. Windows does file deletion in the following way -
1. A file is opened.
2. The "delete on close" flag is set for the file (for details see the flag FileDispositionInformation in MSDN). During this system request the OnCanFileBeDeleted callback is called.
3. Close the file. And this causes CallbackFS to call the OnDeleteFile callback.

Unfortunately the system doesn't check the status of the close file request. It's expected to always finish successfully. That's why throwing exceptions from OnDeleteFile callbacks doesn't work.
#15594
Posted: 01/24/2011 02:36:03
by Robert Baer (Basic support level)
Joined: 11/08/2010
Posts: 46

Hello Vladimir,

thanks for your explanation. Does it make sense to use OnCanFileBeDeleted callback to perform deletion? Or is it possible that OnCanFileBeDeleted is called without a subsequent call of OnDeleteFile?

Regards,
Robert
#15596
Posted: 01/24/2011 05:33:17
by Volodymyr Zinin (EldoS Corp.)

OnCanFileBeDeleted can't be used for deletion because Windows can use this callback only for a check if a file can be deleted. For example before placing a file to the recycle bin this callback is called (placing a file to the recycle bin doesn't delete the file but only renames it).
#23899
Posted: 03/01/2013 18:39:57
by Ivan P (Priority Standard support level)
Joined: 04/11/2011
Posts: 66

Vladimir, as I understand CBFS works in a similar way as Windows file system driver.

You say that actual file deletion happens after closing it. I don't know how exactly filesystem driver and its related components work, so might miss something.

When a file is to be deleted, Windows filesystem driver must update its metadata on a hard drive.
What happens if some kind disk I/O error occurs during this metadata update?
Will operating system still "think" that the file was successfully deleted and give no error to calling application?

Thanks,
IP
#23914
Posted: 03/04/2013 01:55:28
by Volodymyr Zinin (EldoS Corp.)

At least in NTFS and FAT the real file deletion (i.e. physical removing metadata information for the file) occurs when the last handle to the file is being closed. Actually the CallbackFS behavior is the same.

Quote
Ivan P wrote:
What happens if some kind disk I/O error occurs during this metadata update? Will operating system still "think" that the file was successfully deleted and give no error to calling application?

Do you mean that file system processes the deletion without error, but the disk I/O, which the file system does in order to mark the file's metadata as deleted, returns an error? If so then the file system does nothing (at least FATFS). The metadata in this case will be deleted from the file system cache, but when an open request occurs later then the file system tries to find the file's metadata on the disk and opens it successfully. This is because returning of an error from the "close handle" processing isn't "expectable" by the operating system. I have done an experiment in the past to return an error, but the operating system didn't react on this. Although the system CloseHandle and ZwClose APIs can return an error the IRP_MJ_CLEANUP request, which the system passes to file systems during handle closing, isn't expected to do it.
#23919
Posted: 03/04/2013 07:28:36
by Ivan P (Priority Standard support level)
Joined: 04/11/2011
Posts: 66

Thanks for detailed explanation! That is exactly what I wanted to know.
I was just hoping there's any chance to notify calling application about the error.
Though it's possible to report a notification to a logged-in user through a special component, there's no way to do so in case of scripting scenarios.
Also by EldoS: RawDisk
Access locked and protected files in Windows, read and write disks and partitions and more.

Reply

Statistics

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