11/09/10 3:20
matteo88roma
Risolto!
HDIO_GETGEO e la struct hd_geometry erano definiti (a quanto pare) in un file hdreg.h, sparito poi con l'avvento del kernel 2.6.
Basta ridefinire il tutto e il risultato è garantito!
Output -> (il programma va lanciato con privilegi root!)
#include <fcntl.h> #include <stdio.h> #include <stdlib.h> #include <sys/ioctl.h> #include <sys/stat.h> #include <sys/types.h> #include <unistd.h> #define HDIO_GETGEO 0x0301 struct hd_geometry { unsigned char heads; unsigned char sectors; unsigned short cylinders; unsigned long start; }; int main (int argc, char* argv[]) { struct hd_geometry geom; int drive_fd; //Il famoso hard disk del computer dalla quale sto scrivendo ^^ if ((drive_fd = open("/dev/sda",O_RDONLY))<0) { perror("ERROR: "); } if (ioctl(drive_fd,HDIO_GETGEO,&geom)<0) { perror("ERROR: "); } if (close(drive_fd)<0) { perror("ERROR: "); } printf("Hard Disk Geometry:\n"); printf("Heads: %d\n",geom.heads); printf("Sectors: %d\n",geom.sectors); printf("Cylinders: %d\n",geom.cylinders); printf("Start Offset: %ld\n",geom.start); return EXIT_SUCCESS; }
HDIO_GETGEO e la struct hd_geometry erano definiti (a quanto pare) in un file hdreg.h, sparito poi con l'avvento del kernel 2.6.
Basta ridefinire il tutto e il risultato è garantito!
Output -> (il programma va lanciato con privilegi root!)
matteo@Zi0P4tch0:~/Scrivania$ sudo ./hdgeotest Hard Disk Geometry: Heads: 255 Sectors: 63 Cylinders: 9726 Start Offset: 0
aaa