wfeiisch
驱动牛犊
驱动牛犊
  • 注册日期2002-10-17
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1975回复:4

请问linux中ioctl定义

楼主#
更多 发布于:2003-03-07 12:26
#define SCULL_IOCXQUANTUM _IOWR(SCULL_IOC_MAGIC, 9, 4000)
(这是我在一个例子中看到的)

请问linux中ioctl定义中的第三个参数:4000 是不是指用户在调用ioctl进行数据传输时,argp 所指的内存大小??

如果不是的话,请问是什么其他的意思?
zheng2002
驱动中牛
驱动中牛
  • 注册日期2002-04-17
  • 最后登录2004-12-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-03-08 10:30
可以这么理解
你可以看书《Linux Device Drivers》
qq:14459938 email:zheng2002@21cn.com RH9 kernel 2.4.20
tianxiangyuan
驱动牛犊
驱动牛犊
  • 注册日期2003-02-13
  • 最后登录2008-10-06
  • 粉丝0
  • 关注0
  • 积分1分
  • 威望1点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-03-10 23:58
和Windows中的定义是一样的
wfeiisch
驱动牛犊
驱动牛犊
  • 注册日期2002-10-17
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-03-11 11:05
#define IOCTL_GET_MSG _IOR(MAJOR_NUM, 1, char *)
/* This IOCTL is used for output, to get the message
* of the device driver. However, we still need the
* buffer to place the message in to be input,
* as it is allocated by the process.
*/
/* Get the n\'th byte of the message */
#define IOCTL_GET_NTH_BYTE _IOWR(MAJOR_NUM, 2, int)
/* The IOCTL is used for both input and output. It
* receives from the user a number, n, and returns
* Message[n]. */
#define IOCTL_SET_MSG _IOR(MAJOR_NUM, 0, char *)
/* _IOR means that we\'re creating an ioctl command
* number for passing information from a user process
* to the kernel module.*/

switch (ioctl_num) {
case IOCTL_SET_MSG:
/* Receive a pointer to a message (in user space)
* and set that to be the device\'s message. */
/* Get the parameter given to ioctl by the process */
temp = (char *) ioctl_param;
/* Find the length of the message */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
get_user(ch, temp);
for (i=0; ch && i<BUF_LEN; i++, temp++)
get_user(ch, temp);
#else
for (i=0; get_user(temp) && i<BUF_LEN; i++, temp++)
;
#endif
/* Don\'t reinvent the wheel - call device_write */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
device_write(file, (char *) ioctl_param, i, 0);
#else
device_write(inode, file, (char *) ioctl_param, i);
#endif
break;
case IOCTL_GET_MSG:
/* Give the current message to the calling
* process - the parameter we got is a pointer,
* fill it. */
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
i = device_read(file, (char *) ioctl_param, 99, 0);
#else
i = device_read(inode, file, (char *) ioctl_param,
99);
#endif
/* Warning - we assume here the buffer length is
* 100. If it\'s less than that we might overflow
* the buffer, causing the process to core dump.
*
* The reason we only allow up to 99 characters is
* that the NULL which terminates the string also
* needs room. */
/* Put a zero at the end of the buffer, so it
* will be properly terminated */
put_user(\'\\0\', (char *) ioctl_param+i);
break;
case IOCTL_GET_NTH_BYTE:
/* This ioctl is both input (ioctl_param) and
* output (the return value of this function) */
return Message[ioctl_param];
break;
.......


这一段源代码又怎么解释呢??

ioctl申明中第三个参数好像是给出了argp的类型!!

至于指针char*的大小用了一下一段程序去验证。
if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
get_user(ch, temp);
for (i=0; ch && i<BUF_LEN; i++, temp++)
get_user(ch, temp);
#else
for (i=0; get_user(temp) && i<BUF_LEN; i++, temp++)
;
#endif

是否说明了其argp指的内存区域的大小没有规定,你可以取大也可取小,具体的大小由你自己的驱动程序中自己检验大小,或自己设法告诉驱动程序空间大小!??


zhtao
驱动牛犊
驱动牛犊
  • 注册日期2003-02-07
  • 最后登录2003-10-20
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地下室#
发布于:2003-08-04 22:00
其实很多东西你man一下就有很详细的解释了
游客

返回顶部