/* Collection of code snippets by Arne Vajhøj */
/* (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) */
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>
#include <fcntl.h>
#include <errno.h>

int main()
{
    struct hd_driveid id;
    int fd;
    fd = open("/dev/hda", O_RDONLY|O_NONBLOCK);  
    if (fd < 0)
    {
        perror("/dev/hda");
    }
    if(!ioctl(fd, HDIO_GET_IDENTITY, &id))
    {
       printf("Serial Number=%s\n",id.serial_no);
    }
    return 0;
}
