2010-09-16 90 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