EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Adding file Programmatically

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
Posted: 09/29/2008 13:37:57
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75


When I try to create a file/subfolder programmatically inside CbFsEnumerateDirectory event. Always I got Access to the path ... is denied.

(using Windows XP + VDisk sample code.)



Posted: 09/30/2008 09:48:44
by Volodymyr Zinin (EldoS Corp.)


Where do you create the file? Is it created in a CallbackFS virtual disk for which the CbFsEnumerateDirectory event is being called or in some other destination?
Posted: 09/30/2008 09:58:50
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75

Hi Vladimir

Yes, I create the file inside CallbackFS virtual disk when the CbFsEnumerateDirectory event is being called.

If I create a subfolder in the same place, Windows Explorer is hanging. using this code:
for (int i = 0; i < list.Count; i++)
    DirectoryInfo newDir = new DirectoryInfo("Z:" + list[i].FolderName + list[i].FileName + "\\");
    mCbFs.NotifyDirectoryChange("Z:" + list[i].FolderName + list[i].FileName + "\\", CbFsNotifyFileAction.fanAdded);

Now, if I called the above code from a button, subfolders are created successfully.

Posted: 09/30/2008 10:39:46
by Vladimir Cherniga (EldoS Corp.)

In any case you shouldn't refers to cbfs virtual drive from user callbacks. This can leads to deadlock situation. You should implement virtual storage in other places - physical disk storage, file, memory and similar.
Posted: 09/30/2008 13:36:16
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75

I am creating a database application, where all files and subfolders are stored in a database, when the user select a folder, I have to retrieve all subfolders and files belong to the selected folder and build them programmatically.

I think CbFsEnumerateDirectory event is the best place I can start to build files/subfolders structure.

I used a different thread to build the subfolders/files structure, a gain deadlock situation.

Can you suggest how to implement virtual storage in other place?
How to call it and build the structure?

Posted: 09/30/2008 14:06:21
by Eugene Mayevski (EldoS Corp.)

Khayralla AL-Athari wrote:
Can you suggest how to implement virtual storage in other place?
How to call it and build the structure?

It's up to you where and how you build the storage and it's structure. CBFS is a tool to *expose* the existing structure. Of course, the structure can be dynamic, i.e. change on the fly (and in this case you use NotifyDirectoryChange method). But the virtual disk created by CBFS should not be accessed from your code. I.e. if you mount a virtual file system to drive Z:, you should not (unless you know really well what you are doing and why) perform any activity involving the paths starting from "Z:\". Doing so in callback handlers will lead to deadlock (100% guaranteed), and for simplicity we don't recommend accessing the disk in other places of your code either.

All disk structure building or modification operations must be performed *out* of CBFS-mounted disk. If you have a DB, then you should modify either DB records, or some hierarchical cache that you use to build a structure from the flat DB table. Then you *expose* the structure to the OS by calling NotifyDirectoryChange and processing OnEnumerateDirectory callback.

Sincerely yours
Eugene Mayevski
Posted: 09/30/2008 15:35:26
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

Well, maybe I don't understand what this thread is all about, but I am doing something very similar to what Mr. Al-Athari seems to be talking about and everything I am doing works pretty well.

For example, I create a storage in CbFs and mount a drive letter in it called the S: drive. That S: drive represaents my database system. When the user clicks on the S: drive in Windows Explorer, I field the call to CbFsEnumerateDirectory and in that callback I call my database system's API functions that basically do the same thing as EnumerateDirectory, i.e we have a function called "opendir" that opens a "directory" in our database and another function called "readdir" that reads the file names from the directory, so the first time I get the EnumerateDirectory callback I do an opendir and then the next time I do a readdir and I pass back FileFound = TRUE and the name of the file to CBFS. This lists the files and subdirectories in Windows Explorer exactly as I'd expect it to. I can then drag and drop, right-click/Open and do anything else that a normal user can do on a real drive.

I've had some problems with it, as you can see from some of my previous posts, but in general it works pretty well and Eugene and Vladimir have been pretty good about helping me.

If Mr. Al-Athari wants to elaborate more on the problems he is having I'd be willing to try to help him, but at this point I really don't quite understand what he is saying.
Posted: 09/30/2008 16:01:29
by Khayralla AL-Athari (Standard support level)
Joined: 09/23/2008
Posts: 75

Hi Schipper

thanks for your replay.

I have an application in which I saved some folders and files. Next time when the user enumerate a folder, all child (sub folders and files) that belong to it must be expose to the user inside Windows explorer.

Now, as you said, you will pass back FileFound = TRUE and the name of the file to CBFS, what if there are more than one file and subfolder?

how can you pass back the names?

I think we are doing same database application.


Posted: 09/30/2008 16:12:13
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

The Enumerate Directory callback gets called by the OS over and over again for each file in the directory. It is very similar to the way the Windows API function FileFind works. The initial call to FileFind with a mask of *.* opens the directory and then subsequent calls list all the files.

Well, the Enumerate Directory callback works pretty much the same way. The first call to it is when the user first clicks on the directory to open it, subsequent calls are made every time you send back FileFound = TRUE, until you send back FileFound = FALSE, at which point the OS should call the CloseEnumeration callback.

I believe that is the way it works, but Eugene or Vladimir can probably explain it better.
Posted: 10/02/2008 03:00:22
by Volodymyr Zinin (EldoS Corp.)

Yes. It's correct.
The problem is (as I understand) that Mr. AL-Athari in his EnumerateDirectory callback tries to access the same virtual disk for which this EnumerateDirectory callback is being called. Such behavior is prohibited because often can cause of a deadlock.
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.



Topic viewed 8965 times

Number of guests: 2, 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!