Using HDIO_GET_IDENTITY & Converting SCSI ioctl to SG_IO

Submitted by TragicWarrior
on June 19, 2006 - 2:35pm

I'm writing an application which tries to detect the difference between ATA and ATAPI devices. At present I am using the ioctl HDIO_GET_IDENTITY which sends the command "IDENTIFY PACKET DEVICE" to the device and then checks for the value "COMMAND ABORTED".

All works well except that I get the printk msg in my ring buffer, "program foo is using a deprecated SCSI ioctl, please convert it to SG_IO"

Anyone know how I would get the same information using SG_IO? I assume that one of the fields in struct sg_io_hdr might help, but I'm not quite sure what I'm looking for. If someone has already done this, a code snippet showing SG_IO usage would be great.

The code I am currently using looks like this:

ioctl(fd,HDIO_GET_IDENTITY,&hwdev_storage->ata2);
if(!(ata2.config & 0x4000) && ((ata2.config & 0x1f00) >> 8)==5)
{
/* device is ata */
}
else
{
/* device is atapi */
}

Thanks in advance!