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?

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.

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 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.

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.

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.

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.

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

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.

We use cookies to help provide you with the best possible online experience. By using this site, you agree that we may store and access cookies on your device. You can find out more about and set your own preferences here.