I need to get specifications of hard disk on both Win and *nix machines. I used <hdreg.h>
on Linux like this:
static struct hd_driveid hd;
int device;
if ((device = open("/dev/sda", O_RDONLY | O_NONBLOCK)) < 0)
{
cerr << "ERROR: Cannot open device /dev/sda \n";
exit(1);
}
if (!ioctl(device, HDIO_GET_IDENTITY, &hd))
{
cout << hd.model << endl;
cout << hd.serial_no << endl;
cout << hd.heads << endl;
}
I need hd_driveid
to tell me some more information about disk. I want to know:
My questions are:
Nearly everything in your list has nothing to do with "specifications of hard disk":
hd_driveid.sector_bytes
(usually 512, but some modern drives use 4096). I'm not aware of a maximum "block size", which is a property of the filesystem. I'm also not sure why this is useful.The total size in sectors is in hd_driveid.lba_capacity_2
. Additionally, the size in bytes can probably be obtained with something like
#define _FILE_OFFSET_BITS 64
#include <sys/types.h>
#include <unistd.h>
...
off_t size_in_bytes = lseek(device, 0, SEEK_END);
if (size_in_bytes == (off_t)-1) { ... error, error code in ERRNO ... }
Note that in both cases, it'll probably be a few megabytes bigger than sizes calculated by C×H×S.
It might help if you told us why you wanted this information...