#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/ata.h>
int main(int argc, char *argv[])
{
int fd;
int rv = -1;
const char *dvc = "/dev/ad0";
if((fd = open(dvc, O_RDONLY)) != -1)
{
struct ata_params atap;
if(ioctl(fd, IOCATAGPARM, &atap) != -1)
{
printf("Drive serial number: %s\n", atap.serial);
rv = 0;
}
else
{
fprintf(stderr, "ioctl(IOCATAGPARM) failed (%s)\n",
strerror(errno));
}
close(fd);
}
else
{
fprintf(stderr, "failed to open %s (%s)\n",
dvc, strerror(errno));
}
return rv;
}