是否有方法通过ioctl函数调用检索NVME驱动器的型号?通过使用/include/linux/hdreg.h中定义的hd_driveid结构,这对于IDE驱动器来说是可能的。
hdreg.h
struct hd_driveid{
...
unsigned short ecc_bytes;
unsigned char fw_rev[8];
unsigned char model[40]; /*see here*/
unsigned char max_multsect;
...
}在/include/linux/ NVMe _ioctl.h中,我看不到检索nvme驱动器模型的类似方法。
我怕
发布于 2022-09-14 02:22:10
查看1.4规格的5.15.2.2节。这应该能行。我没有要测试的NVMe驱动器。
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <linux/nvme_ioctl.h>
int main(int argc, char** argv) {
int fd = open(argv[1], O_RDWR);
if (fd == 0) {
perror("open: ");
exit(1);
}
char buf[4096] = {0};
struct nvme_admin_cmd mib = {0};
mib.opcode = 0x06; // identify
mib.nsid = 0;
mib.addr = (__u64) buf;
mib.data_len = sizeof(buf);
mib.cdw10 = 1; // controller
int ret = ioctl(fd, NVME_IOCTL_ADMIN_CMD, &mib);
if (ret) {
perror("ioctl: ");
exit(1);
}
printf("SN: %.20s\n", &buf[4]);
printf("SN: %.40s\n", &buf[24]);
printf("FW: %.8s\n", &buf[64]);
return 0;
}https://stackoverflow.com/questions/73695037
复制相似问题