chard-driveioctlsata

obtaining WWN of SATA disks


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?


Solution

  • 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?