基于linux内核4.12 编译 scullc程序遇到的一些问题

字符设备驱动程序 scullc
基于linux 内核 4.12
由于Linux内核4.12 相比与 2.6 数据结构,接口都发生巨大变化,因此这个驱动程序需要做许多修改。

1. main.c 18行, 注释
#include <linux/config.h>
因为4.12下不包含config.h文件

2. main.c 30行 将#include <asm/uaccess.h>
改为: #include <linux/uaccess.h>

3. 52 行 将:kmem_cache_t *scullc_cache;
改为:struct kmem_cache *scullc_cache;

4. 275行 将 int scullc_ioctl (struct inode *inode, struct file *filp,
unsigned int cmd, unsigned long arg)
改为:
long scullc_ioctl (struct file *filp,
unsigned int cmd, unsigned long arg)

5. 404 行 将 struct work_struct work;
改为:struct delayed_work dwork;

6. 由于异步io 部分牵连比较多,虽然修改了很多地方,但是碰到迭代器我就放弃了,暂时就不深究异步io了,直接注释异步io部分。
比如 strcut file_opration 结构体中 ioctrl ,aio_read, aio_write都发生了变化,, , aio_complete 接口也已经变为static函数了,不能直接调用,暂时由于对struct iov_iter等数据结构还不熟悉,因此还不能完成异步IO接口的实现,只能暂时注释该功能。
再 410 行 static void scullc_do_deferred_op(void *p) 上面 加上 #if 0
在 444 行 加上 #endif
在 449 行 将 return scullc_defer_op(0, iocb, buf, count, pos);
改为://return scullc_defer_op(0, iocb, buf, count, pos);
return 0;
在 455行 将 return scullc_defer_op(1, iocb, (char __user *) buf, count, pos);
改为://return scullc_defer_op(1, iocb, (char __user *) buf, count, pos);
return 0;
在 446 行 将 接口:
static ssize_t scullc_aio_read(struct kiocb *iocb, char __user *buf, size_t count,
loff_t pos)
{
return scullc_defer_op(0, iocb, buf, count, pos);
}

static ssize_t scullc_aio_write(struct kiocb *iocb, const char __user *buf,
size_t count, loff_t pos)
{
return scullc_defer_op(1, iocb, (char __user *) buf, count, pos);
}

改为:
static ssize_t scullc_aio_read(struct kiocb *iocb, struct iov_iter *iter)
{
//return scullc_defer_op(0, iocb, buf, count, pos);
return 0;
}

static ssize_t scullc_aio_write(struct kiocb *iocb, struct iov_iter *iter)
{
//return scullc_defer_op(1, iocb, (char __user *) buf, count, pos);
return 0;
}


7. 在470 行 将 .ioctl = scullc_ioctl,
改为:.unlocked_ioctl = scullc_ioctl,

在473 , 474 行 将 .aio_read = scullc_aio_read,
.aio_write = scullc_aio_write,
改为:.read_iter = scullc_aio_read,
.write_iter = scullc_aio_write,

8. 在560 行, 将
scullc_cache = kmem_cache_create("scullc", scullc_quantum,
0, SLAB_HWCACHE_ALIGN, NULL, NULL); /* no ctor/dtor */
改为:
scullc_cache = kmem_cache_create("scullc", scullc_quantum,
0, SLAB_HWCACHE_ALIGN, NULL); /* no ctor/dtor */

8. 最后修改一下脚本 scullc_load
将18行的, -f 参数去掉。
这里如果不去掉,我在安装模块时提示:
ERROR: could not insert module ./scullc.ko: Invalid module format
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值