【发布时间】:2013-11-30 14:46:39
【问题描述】:
我使用 /proc/diskstats 来获取读取和写入的扇区数。 我想将此数字转换为字节,以便查找扇区大小。 我使用How to find floppy\ CD sector size in Linux? 获取磁盘 sda、sda1 和 sda2 的扇区大小,但失败并出现以下错误: 文件 /dev/sda 上的 ioctl 失败,错误参数无效 文件 /dev/sda1 上的 ioctl 失败,错误为设备的 ioctl 不合适 和 sda2 一样。 将感谢您的帮助。 谢谢
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);
}
【问题讨论】:
-
我已经编辑了你链接到的问题中的代码,它是无效的并且传递了一个野指针。
-
我之前已经为我进行了更改,但仍然无法正常工作。
-
和this question有关系吗?