EldoS | Feel safer!

Software components for data protection, secure storage and transfer

opening a file in read-only mode

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#6049
Posted: 04/30/2008 02:31:56
by Vijay Mani (Standard support level)
Joined: 03/09/2008
Posts: 29

Hi all,
I'm having some issues opening a file in read-only mode. We're using CBFS as our virtual FS backed by a cached store. The call we're using in the openfile callback when readonly is:
hFile = CreateFile(strFileName, // file to open
GENERIC_READ, // open for reading
FILE_SHARE_READ | FILE_SHARE_WRITE, // share for reading
NULL, // default security
OPEN_EXISTING, // existing file only
FILE_ATTRIBUTE_READONLY, // normal file
NULL); // no attr. template
So, when opening a file with notepad, the file is opened and when the change is written the WriteFile call fails and we throw an ECBFSError with the last error from writefile, but for some reason the failure is silent.
Is that by design? I'd imagine that it'd be useful to use a dialog box to indicate error, like it's done with other operations fail and an ECBFSError is thrown. Ofcourse it could be the native fs that actually throws the error. So I thought I might ask.

Also, when opening the file with word, given the way it saves (saving to a temp file and then renaming the temp file to the original file) is it possible to indicate to word that the file being opened is readonly? Otherwise, given that word writes the changes to a temp file, it's not possible to block the write.

Thanks.
#6050
Posted: 04/30/2008 02:46:13
by Eugene Mayevski (EldoS Corp.)

You should decline the requests, if they include write permissions. However, with current version of CBFS this is not possible as it doesn't report open mode and share mode flags. This will be fixed in version 2.0, which will be available in a week or two.


Sincerely yours
Eugene Mayevski
#6051
Posted: 04/30/2008 03:11:21
by Volodymyr Zinin (EldoS Corp.)

Hello,

Notepad works with files using the system memory mapping. So when Notepad writes to a file it really writes to the MMF section opened for the file in the system memory and a little later the system memory manager flushes data to the file using the "modified pages writer" thread. But the latter if the error occurs can't notify the originator of the request (i.e. Notepad) about the error.

I see the following workarounds:
1. Specifies FILE_ATTRIBUTE_READ_ONLY for txt-files when the file attributes are requested. In such case Notepad will open files in read-only mode.
2. Specifies that the virtual storage is read-only (CallbackFileSystem.StorageCharacteristics = scReadOnlyDevice).
3. In CallbackFS version 2.0 we are going to add additional parameters to the OnCreate/OnOpen callbacks. One of them will be DWORD DesiredAccess. So you will be able to return an error from these callbacks if the requested access is not possible.

Reply

Statistics

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