EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Callback File System Intercepting File Requests

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.
#10031
Posted: 05/16/2009 02:11:21
by Giovanni Aninon (Basic support level)
Joined: 05/16/2009
Posts: 11

Hello.

I am testing Callback FS for possible use in my project. I hope someone can help me with my investigation.

I would like to implement the VFS in such a way that if an external application requested for a file that is not found on my virtual disk, the VFS will call another external application of mine to get a data stream from a different location (for example, in byte array format).

Then, I would like this stream to be returned to the caller without creating an actual file on my virtual disk. I am currently looking at GetFileInfo, OpenFile, and ReadFile handlers. Can anyone give me suggestions on how to go around with this or perhaps any documentation available for this?

Thank you very much for your time.
#10033
Posted: 05/16/2009 03:35:23
by Volodymyr Zinin (EldoS Corp.)

Hi,

Using CallbackFS you can represent any data as files. As an example for your purpose you can use the Mapper sample. It creates a virtual disk that duplicates file structure from some directory on a local or remote disk. But for you it's necessary to add in the OnOpen callback an additional handler for a case when some file isn't exist but must be shown. After the OnOpen callback finishes without an error for this virtual file then other callbacks will be called for it (OnRead, OnWrite, etc) and you can work with any data there. Also if you want to have the file visible in the directory it's necessary to return data for it during the OnEnumerateDirectory callback.
#10034
Posted: 05/16/2009 04:09:01
by Giovanni Aninon (Basic support level)
Joined: 05/16/2009
Posts: 11

Hi,

Thank you for the reply.
However, I debugged the samples (Mapper, VDisk) and it seems that it goes first into the CbFsGetFileInfo function when my external application tries to read the virtual disk. The CbFsOpenFile, CbFsReadFile, etc will not be excuted when this function returns false.

It seems that if a file is not available, I get stuck in CbFsGetFileInfo.
I've been trying to create a dummy file info and force return a "true" but still it did not work.

Thank you.
#10036
Posted: 05/16/2009 10:34:59
by Volodymyr Zinin (EldoS Corp.)

Yes, it is necessary to return file information in CbFsGetFileInfo. And it should work. Usually after the successful CbFsGetFileInfo the OnOpen callback is called.

Quote
Giovanni Aninon wrote:
I've been trying to create a dummy file info and force return a "true" but still it did not work.

It should work. If you still have a problem with it then tell me and on the next Monday I modify the Mapper sample and give it to you.
#10037
Posted: 05/16/2009 12:32:06
by Giovanni Aninon (Basic support level)
Joined: 05/16/2009
Posts: 11

Thank you very much for the reply.
I am able to successfully pass thru CbFsGetFileInfo now but I am still having problems achieving my goal on intercepting file requests. Perhaps you can shed some more light on this.

Here is more detail on what I would like to do:
I have application#1 which searches/reads a directory/file managed by CallbackFS. I would like to implement CallbackFS in such a way that if application#1 will request for a file that does not exists, CFS will call a function from my application#2 (the missing files are in application#2). My application#2 returns a byte array representation of the file (for example, a byte array representing "Hello World"). Now, my CallbackFS code has the byte array. How do I return this to the caller (application#1)? I would like to use streaming only and the file does not really exists in the virtual disk.

I am quite new to CallbackFS and I've been doing trial and error on the Mapper sample (particulary CbFsOpenFile and CbFsReadFile) for possible use. Perhaps you have past experiences similar to this. I am quite confused as to which portion in CbFsOpenFile and CbFsReadFile should I be changing.

Thank you.
#10039
Posted: 05/17/2009 12:03:19
by Eugene Mayevski (EldoS Corp.)

You are stuck with your understanding of what CBFS does.

CBFS is just a "gateway" so "file does not exist" situation is not possible. It's *you* who determines whether the "file" exists, and how to get it's data.
now to answer your question:

Quote
Giovanni Aninon wrote:
Now, my CallbackFS code has the byte array. How do I return this to the caller (application#1)? I would like to use streaming only and the file does not really exists in the virtual disk.


First of all, you need to tell the OS that you *have* this file. This is done by passing approriate information about the file via OnGetFileInfo callback.

Next, you handle OnOpen and OnRead, and in response to OnRead you read your data from the stream that you have and pass it to the requestor.


Sincerely yours
Eugene Mayevski
#10045
Posted: 05/18/2009 05:37:17
by Giovanni Aninon (Basic support level)
Joined: 05/16/2009
Posts: 11

Thanks so far for all your help.

After trying out so many ways, I was finally able to pass the the data back to the OS.

I have a related follow-up question though. When the OS requested for a fileA, the following callbacks are executed:

1. OnGetFileInfo
2. OnOpen
3. OnRead
4. OnClose

In successive calls to same fileA, the call to GetFileInfo is no longer performed but only the following are performed:

1. OnOpen
2. OnRead
3. OnClose

I implemented my CBFS code in such a way that fileA will be modified after everytime it is returned to the OS. If the original size is 100 and the updates changed the file size to 500, the OS will only receive the 100 portion during the successive calls since OnGetFileInfo was not executed (meaning, EndOfFile was not changed).

1. Is there any way for me to update "EndOfFile" from within OnOpen or OnRead?
2. If #1 is not possible, Is there any way for me to tell the OS that the file has changed so that in next successive calls, the OS will trigger OnGetFileInfo? I tried using mCbFs.NotifyDirectoryChange but it didn't trigger another call to OnGetFileInfo in the next OS call.

Thank you.
#10046
Posted: 05/18/2009 05:54:52
by Eugene Mayevski (EldoS Corp.)

If you change the underlying data not via the virtual disk, then you need to tell the OS that the directory contents of the virtual disk have been changed and the OS needs to refresh directory information. This is done by NotifyDirectoryChanges() method. Please check the help file and search the forum for information about this method.


Sincerely yours
Eugene Mayevski
#10047
Posted: 05/18/2009 06:03:13
by Volodymyr Zinin (EldoS Corp.)

On the second call OnGetFileInfo is not called because of the meta-data cache in the CallbackFS driver. This cache helps to decrease quantity of OnGetFileInfo requests. You can either switch this cache off (see the DisableMetaDataCache method) or use NotifyDirectoryChange. The second method is more preferable. Perhaps you call it with incorrect parameters. Please specify your code snippet that performs this call.
Also you can find some discussions of this function in this forum. For example: http://www.eldos.com/forum/read.php?FID=13&TID=1634
#10049
Posted: 05/18/2009 08:25:16
by Giovanni Aninon (Basic support level)
Joined: 05/16/2009
Posts: 11

Thank you very much for all your help.
I was able to implement CBFS as what I would like it to do.
My file contents are dynamic so I used the DisableMetaDataCache method so that OnGetFileInfo will be triggered for each file request.

Using the Mapper sample:
1. I created a temporary file during OnGetFileInfo and wrote it with dynamic values.
2. During OnOpen, I used the name of the temporary file.
3. During onClose, I deleted the temporary file.

Again, thank you guys for all the help.
Although there are so many file operations going on (create, write, delete temp file), when I placed timestamps during debugging, it seems these are handled fast by CBFS.

Thank you for all the replies.
Also by EldoS: BizCrypto
Components for BizTalk® and SQL Server® Integration Services that let you securely store and transfer information in your business automation solutions.

Reply

Statistics

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