Instead of
if (ioctl(driveptr,HDIO_GET_IDENTITY, &hd)!=0) {
you probably want
if (ioctl(fileno(driveptr),HDIO_GET_IDENTITY, &hd)!= -1) {
^^^^^^^ ^ ^^
Because ioctl
's first argument need to be an integer file descriptor not a FILE *
fileno()
will give you an integer fd from a FILE *
.
Note also that ioctl
returns -1 on an error and sets errno.
Reading the man pages of the functions you are using is probably quicker than posting to StackOverflow.