c - OPAL-SED 库 ioctl 用法?

标签 c git github linux-device-driver nvme

我正在尝试使用 linux-kernel 4.11 中添加的 sed-opal 库

为此,我编写了一个像这样的基本程序:

#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <linux/nvme_ioctl.h>
#include <uapi/linux/sed-opal.h>
#include <fcntl.h>
#include <linux/types.h>

int main()
{
    int f_desc;

    printf("Trying to open device /dev/nvme0...\n");

    f_desc = open("/dev/nvme0", O_RDWR);
    if(f_desc == 0)
    {
            printf("Could not open the file..\n");
    }
    else
    {
            printf("Open call returns : %d\n", f_desc);
    }


    struct nvme_admin_cmd cmd = {
    .opcode = 0x81,                 //0x81 Security Send. 0x82 Security Receive
    .nsid   = 0xffffffff,
    .cdw10  = 0x02000000,
    };

    int ret_ioctl_value;

    ret_ioctl_value = ioctl(f_desc, IOC_OPAL_REVERT_TPR, &cmd);

    printf("ioctl returned value : %d \n", ret_ioctl_value);
    perror("Flush");
    close(f_desc);

}

当我想使用上面代码中提到的 sed-opal 库 ioctl 命令时,问题就出现了。

Error is like:-
Trying to open device /dev/nvme0...
Open call returns : 3
ioctl returned value : -1
Flush: Inappropriate ioctl for device

这是发送安全 SEND/RECV 命令的正确方法吗?

如果是,错误的可能原因是什么?

感谢任何帮助。 :)

谢谢。

Note:
- With the above code the basic NVMe protocol specific ADMIN commands works and i am able to receive response of a SMART health log page from the device.
- I have built /usr/src/linux/block/ directory by Enabling the  "Logic for interfacing with OPAL enabled SEDs" from the menuconfig.
- Using 4.13.9 kernel level right now.

================================================== =======

Edit:
So it is supposed to be done as follows:
open(/dev/nvme0n1");
set up opal_structures here from /uapi/linux/sed-opal.h
ioctl(fd, IOC_OPAL_*, &struct_from_above);

最佳答案

尝试使用sed_ioctl而不是ioctl。它在 'sed-opal.h' 中定义

语法相似。

int sed_ioctl(struct opal_dev *dev, unsigned int cmd, void __user *ioctl_ptr);

ioctl 所在的位置。

int ioctl(int fd, unsigned long request, ...);

关于c - OPAL-SED 库 ioctl 用法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47015424/

相关文章:

git - 如何在我的 mac osx 终端上显示我的 git 分支和提交状态?

Gitlab 部署 key 已配置但仍不授予访问权限

api - GitHub API (v3) : Order tags by creation date

java - Intellij-在 Github 上分享项目

c - 使用 GCC 链接器强制执行 32 位枚举

c - 这个对象如何引用自身

git - 为 Gerrit 和 Hudson 创建 SSH key

c - 获取字符串的索引

c - 如何使用 C 将 int 分配给 unsigned long?

git - 如何将新的 pull 请求附加到 github 上的现有问题?