【发布时间】:2013-12-15 23:03:40
【问题描述】:
我想从硬盘驱动器获取基本信息并将其打印出来。最重要的是物理扇区大小正确。
在过去的几个小时里,我一直在与ioctl 斗争,以得到我想要的东西,但我想不通。
我以前从未使用过ioctl,而且我似乎无法找到一个简单的解释来说明你到底要做什么。
反正我的代码是这样的
int main () {
FILE *driveptr;
int sectorsize;
struct hd_driveid hd;
driveptr=fopen("/dev/sda","r");
if (ioctl(driveptr,HDIO_GET_IDENTITY, &hd)!=0) {
printf("Hard disk model: %s\n",hd.model);
printf("Serial number: %s\n",hd.serial_no);
printf("Sector size: %i\n",hd.sector_bytes);
sectorsize=hd.sector_bytes;
} else {
printf("Error fetching device data.\n");
}
}
在编译器中它会抛出这些警告,它会编译但打印时字符串是空的。
gcc -o test source.c
source.c: In function ‘main’:
source.c:67:9: warning: passing argument 1 of ‘ioctl’ makes integer from pointer without a cast [enabled by default]
/usr/include/x86_64-linux-gnu/sys/ioctl.h:42:12: note: expected ‘int’ but argument is of type ‘struct FILE *’
我希望有人可以向我解释出了什么问题!
【问题讨论】:
-
现在硬盘不是经常谎报扇区大小吗?