I used /proc/diskstats to get the number of sectors read and wrote. I want to convert this number to bytes so I look for the sector size. I used How to find floppy\ CD sector size in Linux? to get the sector size of disks sda, sda1 and sda2 but it fails with the following errors: failed ioctl on file /dev/sda with error Invalid argument failed ioctl on file /dev/sda1 with error Inappropriate ioctl for device and the same for sda2. Will appreciate your help. Thanks
struct hd_driveid id;
string fileName = "/dev/";
fileName += diskName;
int fd;
fd = open(fileName.c_str(), O_RDONLY|O_NONBLOCK);
if (fd < 0) {
LogError("Cannot open file " << fileName);
}
else
{
if (ioctl(fd, HDIO_GET_IDENTITY, &id) < 0) {
LogError("failed ioctl on with error " << strerror(errno));
} else {
currBytesPerSector = id.sector_bytes;
}
close(fd);
}