EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Creating mounted disk in memory

Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.
#6360
Posted: 05/22/2008 20:25:35
by Warner Ardelt (Basic support level)
Joined: 05/22/2008
Posts: 10

Hi,

I would like to create a virtual RAM drive instead of the sample demo, which uses a file. I'm not sure how to do go about doing this, so if I could get a few pointers or an example, I would really appreciate it.

I would like to assign a Drive letter (i.e. M:) like the sample:

TCHAR * SymLink = L"M:";

mCBDisk.AddMountingPoint(SymLink);


But instead of loading a file as my virtual drive storage, how would I do this in memory?

I assume I would 1st need allocate or declare an unsigned char buffer (i.e. OutBuf) with the same size as OutBufLen, before I use the following function?

bool GetMountingPoint(int Index, wchar_t *OutBuf, unsigned long OutBufLen, unsigned long *BytesReturned);

If so, would the "index" value be 0 since it's the only one I need? also how to assign it to my drive letter M: ?

Also once I have created a mounting point (M:) and assigned it the buffer in memory as my storage, I should be able to format it so I can use it.

Thank You
Warren
#6361
Posted: 05/23/2008 00:56:29
by Eugene Mayevski (EldoS Corp.)

Quote
Warner Ardelt wrote:
But instead of loading a file as my virtual drive storage, how would I do this in memory?


In OnReadFile and OnWriteFile callback handlers you need to use an in-memory data storage instead of reading/writing the data from/to the file.
In .NET or VCL you can use MemoryStream class for such storage.

No other changes are needed.

Your idea about statically allocated buffers is unapplicable.


Sincerely yours
Eugene Mayevski
#6387
Posted: 05/26/2008 21:12:09
by Warner Ardelt (Basic support level)
Joined: 05/22/2008
Posts: 10

Hi,

Thank you for the quick response, however I'm currently running VC6. I tried several attempts without success. So I finally installed Visual Studio 2008 but minimally due to disk availablity (installing only VC 2008), but I am not quite familiar with it (well ok, that's my problem-oh well). However I still cannot compile the demo as is, let alone experiment with MemoryStream class. Using either of the supplied VS2008 project files, I get the following linker errors:

unresolved external symbol "public: wchar_t const * __thiscall ECBDiskError::Message(void)"
unresolved external symbol "public: static void __cdecl CBDisk::InstallDriver(wchar_t const *,char const * const,signed char *)"
unresolved external symbol "public: void __thiscall CBDisk::SetRegistrationKey(wchar_t const *)"
unresolved external symbol "public: void __thiscall CBDisk::AddMountingPoint(wchar_t const *)"
unresolved external symbol "public: void __thiscall CBDisk::DeleteMountingPoint(wchar_t const *)"

<<<<<<<<<<<< EDIT >>>>>>>>>>>>

Never mind, I found the problem :(, ignore this reply.

I was using the wrong header and lib files (used the ones found under VC6 dir instead of VC2005\32bit)

ok, now on to try to get a temp RAM storage...

Warren
#6389
Posted: 05/27/2008 00:48:55
by Eugene Mayevski (EldoS Corp.)

MemoryStream class is only available in .NET Framework. You can't use it from Win32 C++ application.


Sincerely yours
Eugene Mayevski
#6403
Posted: 05/27/2008 15:30:49
by Warner Ardelt (Basic support level)
Joined: 05/22/2008
Posts: 10

Quote
MemoryStream class is only available in .NET Framework


Yes, I realize this, well I should have mentioned my minimal install included some .NET components (Common Language Runtime), but I'm not familiar with C#, so I'm using VC++9. I found a simple example here which I have working: [URL=http://msdn.microsoft.com/en-us/library/system.io.memorystream.aspx]Microsoft MSDN: system.io.memorystream[/URL]

However I was required to configure the project's properties accodingly by enabling Common Language Runtime Support (/clr), and also by selecting "Multi-threaded DLL" (/MD) for the C++ Code generation to compile successfully.

But I'm still wondering how I can assign the MemoryStream to the Mounting Pt. The demo uses a Handle (i.e. CallbackSupportStruct), and it looks quite complicated -- seems most of the demo code needs to be changed to accomodate?

I realise that I will need to alter the OnReadFile and OnWriteFile callback handlers, but I should be able to "mount" the allocated MemoryStream to the Mounting Pt to be able to format it (i.e. step 1).

Thank you for all your help & patience :)



Warren
#6404
Posted: 05/27/2008 23:41:43
by Eugene Mayevski (EldoS Corp.)

Quote
Warner Ardelt wrote:
But I'm still wondering how I can assign the MemoryStream to the Mounting Pt.


And the answer is still the same - no way.

Please see the sample. It's YOUR job to read and write the data to the storage. CallbackDisk only gives you the data and you write it.


Sincerely yours
Eugene Mayevski
#6405
Posted: 05/27/2008 23:50:27
by Eugene Mayevski (EldoS Corp.)

Here's how you work with in-memory storage:

1) Allocate some block of memory (you can do it via MemoryStream or just use byte *buf = malloc(512 * NumberOfSectorsInTheDisk); . Implement OnGetFileSize to return size of the disk. Note, that the size must be a multiple of 512.
2) Implement OnWrite callback. In this callback you need to copy the passed data to your block of memory. In case of MemoryStream class you call MemoryStream.Seek and MemoryStream.Write. If you have byte *buf, then use "memmove(buf[offset], source, size);"
3) Implement OnRead callback that will read the data from your block of memory to the buffer provided by CallbackDisk.
4) Mount the storage to some letter using AddMountingPoint.
5) In OS (CallbackDisk doesn't currently have functions for this) format the disk. The OS will write some data to that disk and this data will come to OnWrite. The OS will read the data from the disk, and the data will be read back via OnRead.



Sincerely yours
Eugene Mayevski
#6473
Posted: 06/02/2008 16:45:03
by Warner Ardelt (Basic support level)
Joined: 05/22/2008
Posts: 10

Hello Eugene Mayevski,

Thank you for all your help.

I have been busy lately and only had an opportunity to look at this again today. However looking at my problem once again, it seems to me that I'm not quite up to the challenge, conceding defeat - unable to do what I wanted, even with your guidance. Perhaps someone else interested can pick where I left off - following it through to the end. I hang my head in shame, disappointed with myself.

If I could do this it would be great, to be able to create a virtual drive in RAM hidden on the fly created to your specifications is something programmers could only dreamed about, with CallBackDisk the possiblilities are endless. For one you could use it as an ultimate application "packer" (compress using other means), where you have pre-formated a "storage file" containing all your app's support files including executables -whatever. Then include this file as a resource, later copying it's contents to a newly created hidden CallbackDisk RAM drive sized to contain it (saving formating time). Other things you could do is redirect output to RAM or unarchive private data (text in my case) into RAM, where it it's contents can easily, quickly and privately read. There's probably many more uses I haven't even thought of yet.

Warren

#6499
Posted: 06/05/2008 09:40:55
by Eugene Mayevski (EldoS Corp.)

We will add such sample in July.


Sincerely yours
Eugene Mayevski
#6529
Posted: 06/09/2008 13:02:48
by Warner Ardelt (Basic support level)
Joined: 05/22/2008
Posts: 10

Eugene Mayevski wrote:

Quote
We will add such sample in July.


Thank You, very much for your wonderful support! Can't wait to try the new demo sample in July!

(maybe the following question is better suited in another thread)

I was wondering when you create a new virtual disk in RAM, if a Quick Format would be sufficient enough, saving time -- but then again you probaly wouldn't have that much RAM available on your PC that a regular format would take that long to format anyway. How about formatting a Callback virtual drive created within a file, would a Quick Format also be good enough if you wanted to save time? What do you suggest?

Thanks again,

Warren
Also by EldoS: CallbackRegistry
A component to monitor and control Windows registry access and create virtual registry keys.

Reply

Statistics

Topic viewed 22169 times

none




|

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!