首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >基于ioctl的NVMe驱动模型数据

基于ioctl的NVMe驱动模型数据
EN

Stack Overflow用户
提问于 2022-09-12 20:40:49
回答 1查看 54关注 0票数 1

是否有方法通过ioctl函数调用检索NVME驱动器的型号?通过使用/include/linux/hdreg.h中定义的hd_driveid结构,这对于IDE驱动器来说是可能的。

hdreg.h

代码语言:javascript
复制
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驱动器模型的类似方法。

我怕

EN

回答 1

Stack Overflow用户

发布于 2022-09-14 02:22:10

查看1.4规格的5.15.2.2节。这应该能行。我没有要测试的NVMe驱动器。

代码语言:javascript
复制
#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;
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73695037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档