2017-10-30 17 views
0

私はそれをするのLinuxカーネルでは4.11OPAL-SEDライブラリioctlの使用法?

を追加しましたsedのオパールのライブラリを使用しようとしています、私はこのような基本的なプログラムを書かれている:私が使用したいとき

#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); 

答えて

0

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, ...); 
+0

私たちはユーザー空間プログラムで直接sed_ioctlを使用できますか? – user3453931

+0

はい、私たちはユーザー空間で使用できます。定義はsed-opal.hに含まれています。試して返信してください。 – Devidas

+0

私はuapi/linux/sed-opal.hからsed-opalを追加しました。あなたが言及しているsed_ioctlは/linux/sed-opal.hにあり、他のカーネルモジュールから使用できるように公開されています。 例をお勧めしますか? – user3453931

関連する問題