我想从硬盘驱动器中获取基本信息并将其打印出来。最重要的是物理扇区大小正确。
在过去的几个小时里,我一直在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 *’
我希望有人可以向我解释出了什么问题!