2010-09-16 68 views
1

我想编写一个应用程序来创建闪存驱动器的'映像'。这包括驱动器的总体地形,而不仅仅是文件。所以如果驱动器是4GB,你会得到一个4GB的文件。这是否可能,如果有的话,是否有人可以指示我如何实现这一目标?闪存驱动器映像

+0

什么是操作系统?我只问,因为我想知道我是在处理Windows API和CMD工具还是Linux API和shell工具。 – linuxuser27 2010-09-16 17:42:22

+0

对不起。是的,我在Windows上。在Visual Studio.net中工作2008 – BigPete 2010-09-16 17:43:02

+0

复制之后,您打算如何处理图像? – Robaticus 2010-09-16 20:04:40

回答

1

这是可能的。我为一个内部应用程序做了这个,所以我不能只是粘贴它的源代码,但我可以给你一些提示。你将不得不P /调用一些东西。

[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 
} 
0

您是否尝试过将驱动器作为文件打开并复制?

+1

那不会给他形象。从他所描述的内容来看,他想要一个完整的“扇区副本”的闪存驱动器。 – Robaticus 2010-09-16 20:03:50

+0

@Robaticus会有什么遗漏? – 2010-09-16 21:09:41

+0

引导程序信息,非本地文件系统。 – Robaticus 2010-09-17 12:33:00