As you have mentioned in comments to user3588161's answer
, you are having SATA and SAS disk attached to the same SAS controller, so I'd suggest to use the smartctl
command!
The smartctl command act as a control and monitor Utility for SMART disks under Linux and Unix like operating systems. Type the following command to get information about /dev/sda (SATA disk):
# smartctl -d ata -a -i /dev/sda
For SAS disk use one of the following syntax:
# smartctl -d scsi --all /dev/sgX
# smartctl -d scsi --all /dev/sg1
# smartctl -d scsi --all /dev/sg1 -H
I guess all of the information is somehow related to this location :-
/sys/class/scsi_device/?:?:?:?/device/model
I suggest you try doing this too to check what output does it render.
cat /sys/class/scsi_device/0\:0\:0\:0/device/{model,vendor}
(The backslashes next to zeros are for escaping special char :
.)
Also, I'd like to suggest you to visit these two links in order for more information or detail like sample output,etc :-
Find Out Hard Disk Specs
To Check Disk behind Adaptec RAID Controllers
/proc
. You explicitly state you don't want to use/sys
, but that -- and possibly some bus- and/or controller-specific ioctls -- is the answer. You've painted yourself in a corner; good luck. – Roofdeck/sys/
pseudo-filesystem. (In fact, you only need that, and in some cases some driver/bus/device-specific ioctls to get all the information; a handful of command-line tools can do that for you.) By rejecting/sys/
, you are tying your own hands behind your back. – Roofdeck/sys/
because I want to work towards an OS independant solution. I don`t just want to know whether it is a SAS, SATA, SCSI, FC or whatever disk I want to know HOW it knows what disk it is and replicate it via talking to the device instead of asking the kernel. – Astrometrysdparm
background, to get a better overview? – Roofdeck/sys/block/DEVICE
pseudosymlink and/sys/block/DEVICE/device/vendor
and/block/DEVICE/device/model
pseudofiles in Linux, andsdparm
,hdparm
, andsmartctl
cross-platform utilities on all architectures) to find this information with minimum fuss and high reliability. Why does that not work for you? – Roofdecksdparm
,hdparm
andsmartctl
on my own. This is of little significance and can be fully done using standardized knowledge on SCSI and ATA commands. The problem for me is the kernel has a way of exposing the command set a drive talks in. I want to know how it does that. I do not need a code snippet which works on a particular platform. I want to know HOW the kernel acquires this information from the disk/bus. an analogy is that of getting the serial information of a disk via/sys
or via a SCSI inquiry. Is getting it via inquiry useless? of course not. – Astrometry/sys/
, but you rejected that. Because of that, I said you've made the task impossible for yourself. Now you say you want to know how the kernels do this. (That answer is easy, in the sources.) That will not help your application: kernel has access and privileges userspace does not. You've limited yourself to a sterile approach. – Roofdeck