Author | Message | Time |
---|---|---|
Grok | The end goal is to read sectors off a SCSI disk. But first things first. Which namespace can I use to enumerate the system drives? I poked around in System.IO, but nothing is jumping out at me. There is no System.IO.Drives namespace, even though one link promises to "Discusses how to use the .NET System.IO model to work with files, [color=yellow]drives[/color], and folders." but following the link mentions nothing more about drives. Once I can get a handle to the drive, I will get whatever properties I can about the formatting of the disk in the drive, and open a BinaryReader to read sectors. | April 14, 2005, 1:21 PM |
dRAgoN | This what you wanted? System.IO.Directory.GetLogicalDrives() Edit:[code] Private Sub ListDrives() Dim DriveList() As String Dim ENDrives As System.Collections.IEnumerator DriveList = System.IO.Directory.GetLogicalDrives() ENDrives = DriveList.GetEnumerator While ENDrives.MoveNext Console.WriteLine(CStr(ENDrives.Current)) End While End Sub[/code] | April 14, 2005, 5:39 PM |
kamakazie | Just being picky here with Dragon's code but why not something like: [code] Private Sub ListDrives() For Each drive as String in System.IO.Directory.GetLogicalDrives() Console.WriteLine(drive) Next End Sub [/code] ? | April 14, 2005, 6:43 PM |
Myndfyr | I do not believe you will be able to read physical sectors off of a drive without using the Win32 API (or a file system driver). Simply put, I don't believe it is possible to get a handle to a physical disk through the .NET Framework short of using platform invoke and the Win32 API. | April 14, 2005, 11:39 PM |
Adron | I'll suggest trying before giving up. Unless the .NET framework for some reason filters the file names as strings before passing them to CreateFile, you should be able to open a disk drive just fine. | April 15, 2005, 7:35 PM |
Myndfyr | [quote author=Adron link=topic=11274.msg108677#msg108677 date=1113593700] I'll suggest trying before giving up. Unless the .NET framework for some reason filters the file names as strings before passing them to CreateFile, you should be able to open a disk drive just fine. [/quote] I believe it does, in fact. I just opened the disassembly for mscorlib.dll (1.1) and looked at the overload of the constructor for FileStream with which I am most familiar (new FileStream(string path, FileMode mode, FileAccess access). [code] IL_000c: call string System.IO.Path::GetFileName(string) [/code] The operation of Path::GetFileName(string) doesn't reveal anything (it doesn't throw a FileNotFound exception, for example), but then I opened up the overload called by the above constructor: [code] IL_00d2: ldstr "\\\\.\\" IL_00d7: callvirt instance bool System.String::StartsWith(string) IL_00dc: brfalse.s IL_00ee IL_00de: ldstr "Arg_DevicesNotSupported" IL_00e3: call string System.Environment::GetResourceString(string) [/code] Checking this in the Command Window during debugging will give you the exception: [code] Environment.GetResourceString("Arg_DevicesNotSupported") "FileStream will not open Win32 devices such as disk partitions and tape drives. Don't use \"\\\\.\\\" in your path." [/code] | April 15, 2005, 9:09 PM |