tags:

views:

181

answers:

3

I need to clone CF cards (with a certain amount of custom functionality that precludes using off-the-shelf cloning tools). I need a proper image for this to work - I can't just copy all the files. I would like to write a program for this in c#, but I have no idea where to start.

Could anyone point me to a basic sample or something to get me going in the right direction?

+1  A: 

Cant you use a program like : http://xedit.smike.ru/

Otherwise you have to fall back to Win32 API calls, like CreateFile (for drive G, for example, use "\.\g:", as file name parameter)

Also look into the ReadFile/WriteFile, SetFilePointer and DeviceIoControl functions.

Wim Haanstra
+1  A: 

You use the same API to read and write to To read raw data from a Volume in Windows that you use for ordinary file io. The difference is in the open call.

CreateFile("\.\M:", GENERIC_READ | GENERIC_WRITE, ...)

Will open drive M: for raw read and write. I've never tried it, but you might be able to get away with passing "\.\M:" as the filename to one of the stream open functions in C#, it might work. But you would be wiser to write at least the file io part of the project in unmanaged code.

See the CreateFile documentation for more information. look for the section

Physical Disks and Volumes

Direct access to the disk or to a volume is restricted. For more information, see "Changes to the file system and to the storage stack to restrict direct disk access and direct volume access in Windows Vista and in Windows Server 2008" in the Help and Support Knowledge Base at

John Knoeller
A: 

You would need to use Pinvoke to call block mode io. What is the reason you cant just copy files?

TFD
The file system has to be preserved for use in a proprietary device.
Jon B