2017-08-28 69 views
0

這個問題可能看起來很天真,但我是內核/驅動程序編程的新手。我在一個塊設備上創建了一個設備映射器,該設備工作正常。它是構造函數/析構函數,並調用映射方法。設備映射程序'ioctl'簽名

現在,我正在嘗試爲此映射器編寫一個ioctl。當讀寫控制爲裝置寫入,它具有以下特徵:

int ioctl(int d, /* other args */); 

的文件結構/描述符中的ioctl預期。由於它可以訪問文件,因此應用程序進程可以輕鬆使用它。

但對於設備映射的IOCTL具有以下特徵(在結構TARGET_TYPE):

​​

哪有用戶應用程序可以訪問與IOCTL設備映射器,而無需結構dm_target的知識呢?

回答

0
-Ioctl which stand for Input Output control is a system call used in linux to implement system calls which are not be available in the 
kernel by default. 

-The major use of this is in case of handling some specific operations of a device for which the kernel does not have a system call by default. For eg: Ejecting the media from a "CD" drive. An ioctl command is implemented to give the eject system call to the cd drive. 

-ioctl(fd, cmd , INPARAM or OUTPARAM); 
      | 
     3rd arguement is INPARAM or OUTPARAM i.e we don't have to read a device, then how how to interact with device ? use ioctl. 

-open ioctl.h and check you will get more information 
    #define "ioctl name" __IOX("magic number","command number","argument type") 


static long char_dev_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 
{ 
    /* verify arguemenst using access_ok() */ 
    /* impliment support of ioctl commands */ 
} 
相關問題