EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to create a virtual folder

Also by EldoS: MsgConnect
Cross-platform protocol-independent communication framework for building peer-to-peer and client-server applications and middleware components.
#31858
Posted: 01/09/2015 11:52:05
by Stelios Mavridis (Basic support level)
Joined: 01/09/2015
Posts: 34

Hello,

I am trying to implement a virtual folder using CallbackFillter in C#.

I have taken code from the "VirtualFilesCreation" sample and have tried to change it so it creates a folder instead of a file by replacing FILE_ATTRIBUTE_NORMAL with FILE_ATTRIBUTE_DIRECTORY:

Code
        public void CreateVirtualDirTask(Object dir)
        {
            Microsoft.Win32.SafeHandles.SafeFileHandle hFile = filter.CreateVirtualFile((string)dir,
                GENERIC_WRITE | GENERIC_READ,
                FILE_SHARE_READ | FILE_SHARE_WRITE,
                IntPtr.Zero,
                CREATE_NEW, FILE_ATTRIBUTE_DIRECTORY,
                IntPtr.Zero);
            LogWriteInfo("CreateVirtualDirTask("+(string)dir+")");
            CloseHandle(hFile.DangerousGetHandle());
        }


After running it , it creates an empty file instead of a folder.Is my aproach wrong?
Also i am unable to run my program when i set filter.OwnProcessFiltered to true,despite issuing the above code from a different thread.

Finally i have only implemented: OnCreateFileC,OnEnumerateDirectoryC,OnOpenFileC,OnPostCreateFileC,OnPostGetFileSizesC,OnPostOpenFileC.

In the OnCreateFileC and OnOpenFileC i have added the following code to mark virtual folders as such according to the examples/documentation , however they are not called when the virtual folder(file due to my issue) is created.

The other callbacks simply print messages for debuging purposes.
#31859
Posted: 01/09/2015 12:44:55
by Vladimir Cherniga (EldoS Corp.)

Quote
Stelios Mavridis wrote:
I have taken code from the "VirtualFilesCreation" sample and have tried to change it so it creates a folder instead of a file by replacing FILE_ATTRIBUTE_NORMAL with FILE_ATTRIBUTE_DIRECTORY:

CreateVirtualFile is fully identical to CreateFile win32 api. Directories cannot be created using this method. But you can create virtual directory using OnCreateFile/OnOpenFile callbacks. For example, set filter to some empty folder using mask (c:\test\*), then create directory inside folder using any available methods. When OnOpen/OnCreate callback raise, just return appropriate value in BOOL VirtualFile output parameter.
#31860
Posted: 01/09/2015 17:22:52
by Stelios Mavridis (Basic support level)
Joined: 01/09/2015
Posts: 34

Thank you, this was indeed the problem.
#31919
Posted: 01/15/2015 18:23:32
by Stelios Mavridis (Basic support level)
Joined: 01/09/2015
Posts: 34

After your suggestion, i used the Directory.CreateDirectory function.
It seems to create a virtual folder according to the PostOpenCallback FileAttributes.

Now however i want to create sub-folders and files inside the virtual folder.

I have the following issues:

If i try to create a sub-folder with mkdir through cmd i get the error "The parameter is incorrect"
If i try to create a sub-folder with the same code used for the first virtual folder i get the exception "Directory not found" in Directory.CreateDirectory.
I have verified that the path is valid(with code and manually).

Finally if i try to create a file with Explorer i get an infinite loop and get this series of events:

Quote

CbFltCreateFileC
CbFltOpenFileC
CbFltPostOpenFileC
CbFltCloseEnumeration
CbFltOpenFileC
CbFltPostOpenFileC
CbFltCloseEnumeration
CbFltOpenFileC
CbFltPostOpenFileC
CbFltEnumerateDirectoryC
CbFltEnumerateDirectoryC
CbFltCloseEnumeration


I also noticed that the Virtual Directory i did manage to create is marked as read only.

I assume i have to pass additional FileAttributes in the PostOpenCallback function to make the folder read and write -able?

Thank you for your time.
#31924
Posted: 01/16/2015 03:18:46
by Vladimir Cherniga (EldoS Corp.)

Quote
Stelios Mavridis wrote:
f i try to create a sub-folder with mkdir through cmd i get the error "The parameter is incorrect" If i try to create a sub-folder with the same code used for the first virtual folder i get the exception "Directory not found" in Directory.CreateDirectory. I have verified that the path is valid(with code and manually).

Could you confirm, that problem is reproducible with VirtualFileCreate sample ?
#31925
Posted: 01/16/2015 07:52:12
by Stelios Mavridis (Basic support level)
Joined: 01/09/2015
Posts: 34

As you suggested i copied your CreateVirtualFile to CreateVirtualDir and then modified the code as such:

Code
System.Threading.Thread newThread;
                newThread = new System.Threading.Thread(CreateVirtualDir);
                newThread.Start();
                if (newThread.Join(1000))
                {
                    Console.WriteLine("Timeout!");
                }


                newThread = new System.Threading.Thread(CreateVirtualFile);//This was commented
                newThread.Start();//This was commented


VirtualDir simply calls Document.CreateFolder(@"c:\Test\Folder");


The first thread creates a folder at "c:\Test\Folder", the folder is created but it is marked as read-only(see attachment).
For some reason if i use the simple Join() function(no timeout) the program freezes, i assume the thread crashes due to an exception , but Visual studio does not report anything.

The second thread is unmodified and should create a file at "c:\Test\Folder\123.txt", but it does not.

I attach the c:\Test folders properties,the c:\Test\Folder properties are similar (zero files(should be one) and folders).

[img]https://www.eldos.com/upload/forum/upload/65f/65f70c9fff85f028702b7f8b784e22a3[/img]


#31930
Posted: 01/16/2015 10:42:15
by Vladimir Cherniga (EldoS Corp.)

Moved to helpdesk.
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

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