开发者

flash drive imaging

I would like to write an application that will create an 'image' of a flash drive. This incl开发者_开发知识库udes the total topography of the drive, not just the files. So if the drive is 4GB you get a 4GB file. Is this possible, and if so, could someone point me in the direction of information on how this may be accomplished?


It is possible. I did it for an internal app, so I can't just paste the source for it, but I can give you some hints. You will have to P/Invoke some things.

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "CreateFileW", SetLastError = true)]
public static extern IntPtr CreateFile(string name, int access, int share, byte[] attributes, int create, int flags, IntPtr template);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int CloseHandle(IntPtr handle);

[DllImport("kernel32.dll", SetLastError = true)]
public static extern int DeviceIoControl(IntPtr handle, DiskIoctl ioctl, byte[] inBuffer, int inBufferSize, byte[] outBuffer, int outBufferSize, ref int bytesReturned, IntPtr overlapped);

[DllImport("kernel32.dll", CharSet = CharSet.Unicode, EntryPoint = "GetLogicalDriveStringsW", SetLastError = true)]
public static extern int GetLogicalDriveStrings(int bufferLength, byte[] buffer);

public enum DiskIoctl
{
    ScsiPassThrough = 315396,

    Lock = 589848,

    Unlock = 589852,

    Dismount = 589856,

    UpdateProperties = 459072,

    GetDiskLayout = 475148,

    SetDiskLayout = 507920
}

public enum ScsiOp
{
    ReadCapacity = 0x25,

    Read = 0x28,

    Write = 0x2A
}


Have you tried simply opening the drive as a file and copying it?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜