我编写了一个程序,使用HDIO_ ioctl 调用来获取硬盘驱动器的详细信息
。
对于编写程序,我指的是Documentation/ioctl/hdio.txt
在内核源代码(2.6.32)中。
这是我的代码的主要部分:
unsigned char driveid[512];
fd = open("/dev/sda", O_RDONLY); // validated fd.
retval = ioctl(fd, HDIO_GET_IDENTITY, &driveid);
if(retval < 0) {
perror("ioctl(HDIO_GET_IDENTITY)");
exit(3);
}
当我(以 root 身份)运行上述代码时,出现以下错误:
ioctl(HDIO_GET_IDENTITY): Invalid argument
程序有什么问题吗? 为什么我会收到错误?
其他信息:操作系统:CentOS-6.5
,内核版本:2.6.32
,IA:x86_64
(在 VMware 上运行)。
最佳答案
HDIO_GET_IDENTITY ioctl()
不将原始字符缓冲区作为其第三个参数。
它使用linux/hdreg.h
中定义的结构。
struct hd_driveid driveid;
fd = open("/dev/sda", O_RDONLY); // validated fd.
retval = ioctl(fd, HDIO_GET_IDENTITY, &driveid);
if(retval < 0) {
perror("ioctl(HDIO_GET_IDENTITY)");
exit(3);
}
这样应该可以工作。请注意,它仅适用于 IDE/SATA 驱动器,不支持 SCSI。
有
如果您想知道如何在命令 ioctl()
成功返回后获取信息,我建议您查看
http://lxr.free-electrons.com/source/include/linux/hdreg.h?v=2.6.36
关于c - IOCTL:HDIO_GET_IDENTITY 的参数无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23148621/