I want to retrieve SCSI hard drive serial on Linux (Ubuntu) from a C++ program without root priveleges. I tried ioctl(fd, HDIO_GET_IDENTITY, &id) but it seems to work only for ATA devices. Does anyone have a solution for SCSI HDDs? The solution I am looking for should not require the user to have root priveleges. Any source code will be much appreciated
Asked
Active
Viewed 2,679 times
0
-
You're going to need permission from root, for the same reasons explained [here](http://stackoverflow.com/questions/4985270/how-to-get-motherboard-id-on-linux-from-a-c-program) – Ben Voigt Feb 13 '11 at 17:18
-
You are still doing it wrong... sorry. – Juliano Feb 13 '11 at 17:25
1 Answers
0
How about sending a SCSI Inquiry command, as described here: http://tldp.org/HOWTO/archived/SCSI-Programming-HOWTO/SCSI-Programming-HOWTO-9.html
A complete program: http://tldp.org/HOWTO/archived/SCSI-Programming-HOWTO/SCSI-Programming-HOWTO-24.html
Edit: The bottom of this page shows the specific structures required for the SCSI serial number inquiry request and response: http://sunbolic.com/sunbolic/code/cpp/aspi_unit_sn.htm

John Zwinck
- 239,568
- 38
- 324
- 436
-
I tried this code on my Ubuntu, but 1) it requires root priveleges and 2) it does not get serial, only "type and make of the device" – Alexey Feb 13 '11 at 17:17
-
Aha, you have amended your question to say it has to be done without root privileges. I think you should reconsider your entire approach to the higher-level issues at hand here, as discussed in your other question about motherboard serial numbers: http://stackoverflow.com/questions/4985270/how-to-get-motherboard-id-on-linux-from-a-c-program – John Zwinck Feb 13 '11 at 18:14
-
Even if we put aside root issue for now (although if someone still has non-root solution that would be ideal) which bits in this SCSI Inquiry command represent serial? Is it "Product Identification" bits 16-31? – Alexey Feb 13 '11 at 22:40
-
As per the Wikipedia page, you must set the Page Code in the Inquiry command to 0x80. – John Zwinck Feb 14 '11 at 01:56