0

I'm developing in windows with C/C++ and I want to know is it possible to get an apropriate \\.\SCSI device name by \\.\PhysicalDrive ?..

For example, it's wonderful to know how to get that \\.\PhysicalDrive0 is the same that \\.\SCSI0.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Ilya Matveychikov
  • 3,936
  • 2
  • 27
  • 42

1 Answers1

1

Look at the code which I posted in my answer to the question. The author of the question had changed the text of the question so many time and the last version of text clear nor really what the original problem was.

In the example, which C source code you can download here, I show how to get many kind of information about the local drive using different Windows API. The important thing which you need is that some name conversion like DeviceType and DeviceNumber (received by IOCTL_STORAGE_GET_DEVICE_NUMBER) like the following

DeviceType: 7, DeviceNumber: 5, PartitionNumber: 1

are unique in the operation system and can be used to identify the same devices. The reference to the statement you can find in the documentation of IOCTL_STORAGE_GET_DEVICE_NUMBER control code:

The values in the STORAGE_DEVICE_NUMBER structure are guaranteed to remain unchanged until the device is removed or the system is restarted. It is not guaranteed to be persistent across device restarts or system restarts.

In the way you can compare \\.\SCSI0 devices and \\.\PhysicalDrive0 and find out the correspondence.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Oleg, many thanks for your reply. I'll try it as soon as I can. – Ilya Matveychikov Apr 07 '11 at 17:45
  • It seems to be not a simple task to get `STORAGE_DEVICE_NUMBER` data for `\\.\SCSI` device because `IOCTL_STORAGE_GET_DEVICE_NUMBER` fails and GetLastError says ERROR_INVALID_FUNCTION. – Ilya Matveychikov Apr 08 '11 at 08:41
  • @Ilya Matvejchikov: Probably you mean `\\.\SCSI0` or `\\.\SCSI1` and not just `\\.\SCSI`?. I recomend you befor all to use [WinObj](http://technet.microsoft.com/en-us/sysinternals/bb896657) to examine which devices exist on the computer. Look in `GLOBAL??` at the begining. – Oleg Apr 08 '11 at 08:50
  • @Oleg: Yes, you are right, I meant `\\.\SCSI0`. WinObj says that I have 2 SCSI devices -- Scsi0: -> \Device\Ide\IdePort0 and Scsi1: -> \Device\Ide\IdePort1 – Ilya Matveychikov Apr 08 '11 at 08:54
  • @Ilya Matvejchikov: If `\\.\SCSI0:` device return `ERROR_INVALID_FUNCTION` to the `IOCTL_STORAGE_GET_DEVICE_NUMBER` then it not support the request. I not really understand why you need use SCSI emulation of the IDE drive to access it? What is your original goal? What information you want get about the devices? Do you want to work with hard disks or a general SCSI device? – Oleg Apr 08 '11 at 09:52
  • @Oleg: I've used `IOCTL_SCSI_MINIPORT` with a code `IOCTL_SCSI_MINIPORT_IDENTIFY` to get drive's serial number. So, the general problem is that I can't map the PhysicalDrive into corresponding Scsi device. – Ilya Matveychikov Apr 08 '11 at 11:34
  • @Ilya Matvejchikov: Do you want to work with hard disks or a general SCSI device? – Oleg Apr 08 '11 at 11:56