分享

新旧版本驱动模块的一些不同

 huihaoking 2014-01-27

1.ioctl 与 unlocked_ioctl   / int 与long

旧版本:

static const struct file_operations globalmem_fops=
{
.owner=THIS_MODULE,
.llseek=globalmem_llseek,
.open=globalmem_open,
.read=globalmem_read,
.write=globalmem_write,
.ioctl=globalmem_ioctl,
.release=globalmem_release,
};

int globalmem_ioctl(struct inode* inode,struct file* filp, unsigned int cmd,unsigned long arg)

{

switch (cmd)

  {

   case:XXX:   ...

    ……

  }

}

新版本:

static const struct file_operations globalmem_fops=
{
.owner=THIS_MODULE,
.llseek=globalmem_llseek,
.open=globalmem_open,
.read=globalmem_read,
.write=globalmem_write,
.unlocked_ioctl=globalmem_ioctl,
.release=globalmem_release,
};

long globalmem_ioctl(struct file* filp, unsigned int cmd,unsigned long arg)//没有inode参数!

{

switch (cmd)

  {

   case:XXX:   ...

    ……

  }

}


2.class_create/device_create 与 devfs_mk_cdev

旧版本:devfs_mk_cdev(MKDEV(LED_MAJOR, 0), S_IFCHR | S_IRUSR | S_IWUSR | S_IRGRP,DEVICE_NAME);  

新版本:

/*******     功能:内核驱动注册完后,用以下代码创建设备文件  ******/

mydriver_class = class_create(THIS_MODULE, DEVICE_NAME); //注册一个类,使mdev可以在"/dev/"目录下 面建立设备节点

//创建一个设备节点,节点名为DEVICE_NAME

device_create(mydriver_class, NULL, devno, NULL, DEVICE_NAME);  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多