#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/hdreg.h>
int main(int argc, char *argv[])
{ static struct hd_driveid hd;
int fd;
if (geteuid() > 0) { printf("ERROR: Tienes que ser root\n"); exit(1);
}
if ((fd = open(argv[1], O_RDONLY|O_NONBLOCK)) < 0) { printf("ERROR: No se puede abrir la unidad %s\n", argv[1]); exit(1);
}
if (!ioctl(fd, HDIO_GET_IDENTITY, &hd)) { printf("Modelo del disco: %.40s\n", hd.model); printf(" Numero de serie: %.20s\n", hd.serial_no); } else if (errno == -ENOMSG) { printf("No se ha podido obtener la información del disco indicado\n"); } else { perror("ERROR: HDIO_GET_IDENTITY"); exit(1);
}
exit(0);
}
gcc miprograma.c -o miprograma
sudo ./miprograma /dev/sda