• Welcome to Valhalla Legends Archive.
 

SCSI Drive

Started by Grok, April 14, 2005, 08:21 AM

Previous topic - Next topic

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, drives, 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.

l)ragon

#1
This what you wanted?
System.IO.Directory.GetLogicalDrives()

Edit:    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
*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*ˆ¨¯¯¨ˆ*^~·.,l)ragon,.-·~^*ˆ¨¯¯¨ˆ*^~·.,¸¸,.·´¯`·.,¸¸,.-·~^*

dxoigmn

Just being picky here with Dragon's code but why not something like:


Private Sub ListDrives()
    For Each drive as String in System.IO.Directory.GetLogicalDrives()
        Console.WriteLine(drive)
    Next
End Sub


?

MyndFyre

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.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

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.

MyndFyre

Quote from: Adron on April 15, 2005, 02:35 PM
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.

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).


  IL_000c:  call       string System.IO.Path::GetFileName(string)


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:


  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)


Checking this in the Command Window during debugging will give you the exception:


Environment.GetResourceString("Arg_DevicesNotSupported")
"FileStream will not open Win32 devices such as disk partitions and tape drives.  Don't use \"\\\\.\\\" in your path."

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.