EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Running simple app using EldoS RawDisk

Also by EldoS: Solid File System
A virtual file system that offers a feature-rich storage for application documents and data with built-in compression and encryption.
#27499
Posted: 11/29/2013 04:08:44
by Jakub Bulczak (Basic support level)
Joined: 11/29/2013
Posts: 4

Hi :)

I am trying to write simple C++ application using EldoS RawDisk. It have to write data contained in buffer into specified sector on my hard drive (2057th sector to be specific). When I'm using a CreateFile method i get linking error (code 2019, VS2010), while when using Open or OpenEx method application is being build successfuly, but when launched it simply crashes.

Code posted below:

Code
#include <stdio.h>
#include <rawdisk.h>

void main(){

   printf("CheckPoint 0");

   LPBOOL reboot = false;
   CRawDisk::InstallDriver(L"C:\\rawdisk\\location\\path\\elrawdsk.sys", "EldoS_RawDisk", reboot);

   printf("CheckPoint 1");

   HANDLE h = CRawDisk::Open(L"\\??\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, license_key);
   //HANDLE h = CRawDisk::OpenEx(...)
   //HANDLE h = CRawDisk::CreateFileA(L"\\\\.\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, OPEN_EXISTING, 0, license_key);

   printf("CheckPoint 2");
   
   unsigned char* data = new unsigned char[512];
   for(int i=0; i < 512; i++)
      data[i] = '0' + (i % 10);

   printf("CheckPoint 3");

   CRawDisk::WriteSectors(h, 2057, 1, data);

   printf("CheckPoint 4");

   return;
}


A have tried varius ways to get rid of this issues:

- Instaling driver at the beginning on the aplication (as shown above) or not
- Using Windows.h CreateFile methods to obtain a DiskHandle
- Using ////.//PHYSICALDRIVE0 and //??//PHYSICALDRIVE0 device name
- Using CreateFile, OpenEx and Open methods from CRawDisk class (where CreateFile method don't work, as described above).

One more interesting thing I discovered is when I am using CRawDisk::CreateFileA() method it refer to rawdisk.h CRawDisk CreateFile method, but when I'm using CRawDisk::CreateFile() method (as it is specified in a rawdisk.h header) it refer to WinBase.h #define CreateFile method (despide it is not included).

I will be grateful for help or some working sample code of using CRawDisk::WriteSector() method.

I am working on Windows 7 Ultimate x64, developing on Visual Studio 2010 Ultimate, C++ project build in x86 debug mode, using MT CPP library for 32-bit projects (EldoS\RawDisk\CPP\VC2010\32bit\static_runtime(MT)).

I am using a trial version of RawDisk library.

Thanks from advance,
Bulczi.


#27500
Posted: 11/29/2013 05:57:01
by Volodymyr Zinin (EldoS Corp.)

Hi Bulczi,

In order to read/write disk sectors use CRawDisk::Open or CRawDisk::OpenEx methods. The CRawDisk::CreateFile method is only to access files.

I.e. the call
HANDLE h = CRawDisk::Open(L"\\??\\PHYSICALDRIVE0", GENERIC_READ | GENERIC_WRITE, license_key);
should work correctly.

Please specify what a call in your code sample that actually causes the crash.
Thanks.
#27511
Posted: 11/29/2013 10:49:16
by Jakub Bulczak (Basic support level)
Joined: 11/29/2013
Posts: 4

Error is thrown by InstallDriver method (Access Violation Error), either (if I put InstallDriver line in comments) Open method (ERDError - both for "\\\\.\\PHYSICALDRIVE0" and "\\??\\PHYSICALDRIVE0").

My HDD is described by WMI as "\\\\.\\PHYSICALDRIVE0".


#27515
Posted: 11/29/2013 13:23:17
by Volodymyr Zinin (EldoS Corp.)

LPBOOL reboot = false; <====== here is the error
CRawDisk::InstallDriver(L"C:\\rawdisk\\location\\path\\elrawdsk.sys", "EldoS_RawDisk", reboot);
#27521
Posted: 12/01/2013 15:10:11
by Jakub Bulczak (Basic support level)
Joined: 11/29/2013
Posts: 4

Now it's working great :)

I've changed:
Code
LPBOOL reboot = false;
CRawDisk::InstallDriver(L"C:\\rawdisk\\location\\path\\elrawdsk.sys", "EldoS_RawDisk", reboot);

into
Code
bool reboot = false;
CRawDisk::InstallDriver(L"C:\\rawdisk\\location\\path\\elrawdsk.sys", "EldoS_RawDisk", (LPBOOL)(&reboot));


Thanks very much for your help :)
Bulczi.
#27529
Posted: 12/02/2013 05:48:29
by Jakub Bulczak (Basic support level)
Joined: 11/29/2013
Posts: 4

Hi again - I have one more question:

Does CRawDisk::InstallDriver supports relative file paths? Because when I'm trying to use
Code
CRawDisk::InstallDriver(L"elrawdsk.sys", "EldoS_RawDisk", reboot);

instead of
Code
CRawDisk::InstallDriver(L"C:\\rawdisk\\location\\path\\elrawdsk.sys", "EldoS_RawDisk", reboot);

I recive an ERDError. Driver and my_app.exe file are in the same directory.

Thanks from advance :),
Bulczi.
#27530
Posted: 12/02/2013 05:50:38
by Eugene Mayevski (EldoS Corp.)

MSDN strongly discourages against using "current directory" concept in your applications. So you should use absolute paths wherever possible.


Sincerely yours
Eugene Mayevski
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.

Reply

Statistics

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