|
发表于 2009-10-15 12:34:13
|
显示全部楼层
1.fedora11应该是 /dev/sda
2.应该用root执行
#include <stdio.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <linux/hdreg.h>
#include <cstring>
int main(void)
{
int fd;
struct hd_driveid hdinfo;
fd = open("/dev/sda" , O_RDONLY);
printf("%d %p\n", fd, &hdinfo);
if(ioctl(fd, HDIO_GET_IDENTITY , &hdinfo) == -1){
perror("Found error when get hdinfo:");
}
else{
printf("module:%s,serialno:%s\n" , hdinfo.model,hdinfo.serial_no);
}
printf("\n");
return 0;
}
上述代码调试通过,只是显示有点不太好看~ |
|