Other Gathering some Disks informations

Hi,

I'm working on a tool (in perl) that show some informations about availables disks.

For this tool, i use under the hood theses commands :
Code:
   - sas2ircu / sas3ircu
   - geom
   - gmultipath
   - glabel
   - zpool
   - diskinfo

with theses commands, i have a lot of informations, but i'm not able to determine:
Code:
 - Disk type                  (SSD, HDD)
 - Disk Connection type (SAS, SATA, NVME, USB)

For the disk type, i tried to use "smartctl" using "Rotational Rate" attribute.
But smartctl didn't work for USB device and i'm not sure that smartctl report theses attributes the same way for all disks (since it may depends to the disk firmware ?)

For the connection type, i had some options (but theses ones did'nt cover all fields)
Code:
  - camcontrol identify  : if no error, it's a SATA drive
  - camcontrol inquiry   : if no error, it's a SAS drive or a SATA drive on a SAS controller.
  - nvmecontrol list       : for detect nvme drives

I'm not able to determine a SATA drive if it is connected on a SAS controller (i want the disk connection type, not the current controller used in this case)

For USB key, i haven't any idea for detect this type.

Thanks for any advice,
Sébastien.
 
For this tool, i use under the hood theses commands :
...

In the end, all these command will issue either low-level SCSI, ATA, or NVMe commands to the devices. Most likely, you'll be better off downloading a copy of the SCSI standard and the ATA standard and the NVMe standard, and issue these commands yourself, and decode the results. That will be less ambiguous.

with theses commands, i have a lot of informations, but i'm not able to determine:
- Disk type (SSD, HDD)

If the device is a SCSI device or reachable via a SCSI controller (meaning, it is able to execute SCSI CDBs, or the SCSI controller emulates the SCSI CDBs for you), then issue an Inquiry command to the disk, and ask for page 0xB1, also known as the "block device characteristics" page. There, the disk will tell you its rotation rate, including telling you whether it is non-rotating. If you don't feel like writing C code yourself, you can download the sg_utils package, which has a sg_inq command, which can send inquiry CDBs.

For ATA disks, there is an equivalent command I've used before, but I can't remember it by heart; it's been too long.

I don't know how to do this for NVMe disks. Read the NVMe standard. Most likely, it's pointless anyhow: I've never heard of a spinning disk connected via NVMe, so the assumption that any NVMe disk is solid-state is probably safe. There is a SCSI emulation standard for NVMe, but I've only dealt with one implementation of it, and it was ridiculously bad, so bad that I wouldn't trust anything it says.

- Disk Connection type (SAS, SATA, NVME, USB)

This is really hard, because SAS controllers have the nasty habit of emulating SCSI commands on ATA disks. So as you described below, you can send a SCSI command (CDB) like "inquiry" to a non-SCSI disk, and it will respond. That means that SATA disks will pretend to be SAS disks.

I know this is possible. You need to use special ioctl() calls on the SAS HBA, and communicate with the devices underneath using the SMP protocol; that will tell you specifics of the low-level connection (for example whether it is running over 3gig or 6gig SAS), including whether the low-level connection is SAS or SATA. I've never done this myself, but I've seen colleagues do it. I know these ioctl() calls exist in linux, and there is even a smp_utils package (it is like the sg_utils package, except for SMP commands) on Linux; don't know whether any of this stuff exists on FreeBSD.

For USB key, i haven't any idea for detect this type.
No idea about USB storage at all. But is it worth the effort? Most USB storage are little memory sticks, which are not very interesting.
 
Back
Top