EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Encapsulating a virtual drive in a class

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
Posted: 10/18/2012 12:59:26
by Sid Schipper (Standard support level)
Joined: 03/14/2008
Posts: 285

Suppose in the Mapper Sample I add two drives, Z: and Q:.

How do the callbacks differentiate between the drives?

Unless I am mistaken the CbFs file system pointer is a global variable so the callbacks are the same for both drives, so how does GetVolumeSize, for example, know which drive it is providing the sizes for? Isn't it conceivable that the drives would be of different sizes?

Do you see where I am going with this?

It is conceivable that a user's system would mount different drive letters to represent different things, so things like volume size and other such items would be different for different drives, but your callbacks don't accommodate this. Using a different CbFsFileSystem pointer for each also doesn't work as the callbacks are all global static functions, so they are the same for every CallBack File System. What I would like would be the ability to encapsulate a drive in a class and have the callbacks as members of the class and establish them somehow using their runtime address, so that at runtime we get a different callback called for each drive letter. This is not easy in C++ as there is no way to get the runtime address of a member function. So, I don't really have a good idea as to how you or I could implement this, but I'd still like to know your thoughts on this, maybe I am just way off base and I am missing something simple.
Posted: 10/18/2012 13:28:33
by Kenny Kim (Standard support level)
Joined: 08/19/2009
Posts: 38

How do the callbacks differentiate between the drives?...

May be the following will help you a bit.
Currently I am using .Net version of CBFS.
And my application can handle mounting multiple virtual disks without a problem.
What I did is, I have separated all operations related to CBFS to a separate class, like this:
public class Mapper
        private CallbackFileSystem mCbFs;
        private string mRootPath = string.Empty;

        private const uint FILE_FLAG_BACKUP_SEMANTICS = 0x02000000;
        private const uint FILE_ATTRIBUTE_NORMAL = 0x00000080;
        puclic Mapper (string baseFolder, string driveLetter, ...)
                mCbFs.StorageCharacteristics = 0;

And, whenever my application mounts a new drive, it will create a new thread by creating an instance of Mapper class with corresponding parameters. By doing this way, GetVolumeSize() and other methods will be different for each thread.

I hope this info will help you.

Thank you.
Posted: 10/18/2012 14:02:49
by Volodymyr Zinin (EldoS Corp.)

In every callback there is a parameter which is a pointer to CallbackFileSystem object. By the use of it you can differentiate different disks.

Sid Schipper wrote:
Suppose in the Mapper Sample I add two drives, Z: and Q:.

These are not drives, but mounting points (which are "drive letters" in this case).



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