4

I wrote a program to get the details of hard disk drive using HDIO_ ioctl calls.

For writing program, I'm referring Documentation/ioctl/hdio.txt in kernel source(2.6.32).

Here is my main part of code:

fd = open("/dev/sda", O_RDONLY);  // validated fd.
retval = ioctl(fd, HDIO_GET_IDENTITY, &driveid);
if(retval < 0) {
            perror("ioctl(HDIO_GET_IDENTITY)");
            exit(3);
}

When I run(as root) the above code, I got below error:

ioctl(HDIO_GET_IDENTITY): Invalid argument

What is the wrong in the program? Why I'm getting error?

Additional Info: OS: CentOS-6.5, kernel version: 2.6.32, IA:x86_64 (running on VMware).

Result of hdparm -i /dev/sda is

SG_IO: bad/missing sense data, sb[]:  70 00 05 00 00 00 00 0a 00 00 00 00 20 00 00 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
HDIO_GET_IDENTITY failed: Invalid argument

1 Answer 1

0

Is there a device /dev/sda in your system? What type is the driveid variable? Show us whole code, or try changing driveid to:

struct hd_driveid driveid;

Then you can print it's content, i.e.:

printf("Firmware Revision=%.8s\n",driveid.fw_rev);
printf("Cylinders=%d\n",driveid.cyls);

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

5
  • driverid variable??
    – gangadhars
    Apr 18, 2014 at 9:29
  • retval = ioctl(fd, HDIO_GET_IDENTITY, &driveid); Is it struct or char or whatever?
    – tommy
    Apr 18, 2014 at 9:43
  • first I tried for char it thrown same error and then I tried struct hd_drive. I got same error.
    – gangadhars
    Apr 18, 2014 at 10:37
  • I added some extra part to my question. pls see the question again.
    – gangadhars
    Apr 18, 2014 at 10:40
  • It's due the lack o drivers I suppose. If you select different device ie /dev/sr0 it works perfectly. Guess your using vmware player with centos livecd ?
    – tommy
    Apr 18, 2014 at 11:55

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .