1

recently I have been trying all sorts of things with harddrives. Now I am stuck...

what I want to get is the serial,model,revision and WWN of harddrives.

for scsi all of the above is obtainable by a scsi inquiry. for SATA drives I use HDIO_GET_IDENTITY ioctl to obtain model,serial and revision but it doesnt include WWN. However I have not found how I can get thw WWN id for those drives. Anyone have some knowledge in this area?

  • An alternative approach: try using the results of `ls -l /dev/disk/by-id`. I'm leaving for lunch now and maybe when I'm back I can seek for the exact parameter needed for `ioctl`. – starrify Feb 24 '14 at 04:18
  • yes you could. but I allready have the udev library integrated. plus not all oses support the /dev/disk/by-id. –  Feb 24 '14 at 17:39

2 Answers2

4

In the end after the looking at linux/hdreg.h and some documentations from disk manufacterers I have found that the information IS included in HDIO_GET_IDENTITY IOCTL. But it is rather obscured.

http://lxr.free-electrons.com/source/include/linux/hdreg.h?v=2.6.32

at line 595 there are a few unspecified words. 4 of these words contain the WWN. you can get them like so:

sprintf(wwnstr,"0x%04x%04x%04x%04x",hd.words104_125[4],hd.words104_125[5],hd.words104_125[6],hd.words104_125[7]);

Anyway as has been noted a SCSI inquiry could be used to get the WWN data on SATA disks aswell. Here is some sample of a little program I wrote which sends an inquiry and obtains data.

this is a scsi disk and the WWN HEX is the WWN at offset 8 in vpd page 0x83 in the for of hex numbers, the WNN naa. is the string at offset 56 in the same page!

model:      ST3600057SS     
serial:     3SL1DBA00
revision:   EN03
wnn HEX:    0x5000C500286ACC13
wnn naa.:   0x5000C500286ACC10

However done on a SATA disk the same program will result in this:

model:      SAMSUNG HD103UJ 
serial:     S13PJ1DQ403064  
revision:   1AA0
wnn HEX:    0x533133504A314451
wnn naa.:   0x    

As you can seen the WWN is not specified as a string.

Is there are reason why the 2 WWN are not the same?

2

You need to do a specific Page83 INQUIRY to the device in order to obtain its wwn as well as the serial number, model and revision.

I cover this (in part) at

https://www.jmcpdotcom.com/~jmcp/WhatIsAGuid.pdf

You need to set EVPD=1, page code = 0x83, and then look for a designator type of 0x2 (EUI-64) or 0x3 (NAA). EUI-64 based designators are covered in SPC-4rev 36 table 7.8.6.5 and NAA based are covered in SPC-4rev 36 table 7.8.6.6.

For a SATA-attached device, you should also review section 10.3.4 in the SCSI/ATA Translation Layer spec SAT-3.

Both SPC4 and SAT3 are available from http://www.t10.org.

James McPherson
  • 2,476
  • 1
  • 12
  • 16
  • a scsi inquiry doesnt seem to work on most SATA drives to get to WWN. I have described it below wih some examples. –  Feb 24 '14 at 12:11
  • It's my opinion that a page83 INQUIRY(12) *should* provide you with the wwn. If it doesn't, then I'd be checking your SATL implementation very closely for compliance with the standard. The information I pointed to above works on Solaris. – James McPherson Feb 24 '14 at 12:53
  • you are correct, however it seems the wwn string later in the page isnt the same as the hex bytes in the beginning. I have updated my answer! Thank you for helping me –  Feb 24 '14 at 16:53