_IOR(MY_MACIG,0,int)宏的含义是什么? [英] what is the meaning of this macro _IOR(MY_MACIG, 0, int)?

查看:331
本文介绍了_IOR(MY_MACIG,0,int)宏的含义是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在检查ioctl示例程序,以检查它如何与内核空间通信.程序WRITE_IOCTL中的命令用作命令

i was going through ioctl sample programs to check how it communicates with kernel space. in program WRITE_IOCTL is used as command

#define WRITE_IOCTL _IOW(MY_MACIG, 1, int)
ioctl(fd, WRITE_IOCTL, "hello world")

我不明白什么是_IOW(MY_MACIG, 1, int). 这是我下载程序的链接.请帮我. http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-4.html

I am not able to understand what is _IOW(MY_MACIG, 1, int). here is the link from where i downloaded the program. please help me. http://people.ee.ethz.ch/~arkeller/linux/multi/kernel_user_space_howto-4.html

推荐答案

您可能知道,ioctl应该是唯一的,如《 Linux设备驱动程序》一书中所述:

As you may know, an ioctl should be unique, as explained in the Linux Device Drivers book:

ioctl命令编号在整个系统中应按顺序唯一 防止由于向错误的命令发出正确的命令而导致的错误 设备.这种不匹配不太可能发生,并且程序可能 发现自己试图更改非串行端口输入的波特率 流,例如FIFO或音频设备.如果每个ioctl编号是 唯一的,应用程序会收到EINVAL错误,而不是成功执行 做一些意想不到的事情.

The ioctl command numbers should be unique across the system in order to prevent errors caused by issuing the right command to the wrong device.Such a mismatch is not unlikely to happen, and a program might find itself trying to change the baudrate of a non-serial-port input stream, such as a FIFO or an audio device. If each ioctl number is unique, the application gets an EINVAL error rather than succeeding in doing something unintended.

此外,ioctl可能需要向内核空间写入数据和/或从内核空间读取数据.

Furthermore, an ioctl can require to write data to and/or read data from kernel space.

创建一个自己的驱动程序来执行ioctl时,他将需要在ioctl命令中对其进行描述.

When one creates it's own driver that performs ioctls, he will need to describe all this in the ioctl command.

_IO,_IOW,_IOR,_IORW是帮助程序宏,用于创建唯一的ioctl标识符并添加所需的R/W所需的功能(方向).

_IO, _IOW, _IOR, _IORW are helper macros to create a unique ioctl identifier and add the required R/W needed features (direction).

这些可以采用以下参数:幻数,命令ID和将要传递的数据类型(如果有)

These can take the following params: magic number, the command id, and the data type that will be passed (if any)

魔术数字是一个唯一的数字,它使驾驶员能够检测到错误,例如LDD书中引用的数字.

The magic number is a unique number that will allow the driver to detect errors such as the one mentioned in the LDD book's quote.

命令ID,是您的驱动程序了解需要调用什么命令的一种方式.

The command id, is a way for your dirver to understand what command is needed to be called.

最后一个参数(类型)将使内核了解要复制的大小.

Last parameter (the type) will allow the kernel to understand the size to be copied.

希望这会有所帮助.

PS:您可以在Linux Device Drivers一书中获得更多详细信息(第6章) https://lwn.net/images/pdf/LDD3/ch06.pdf

PS: you can have more details in Linux Device Drivers book (chapter 6) https://lwn.net/images/pdf/LDD3/ch06.pdf

这篇关于_IOR(MY_MACIG,0,int)宏的含义是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆