天天看点

基于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); 改为: scullc_cache = kmem_cache_create("scullc", scullc_quantum, 0, SLAB_HWCACHE_ALIGN, NULL);

8. 最后修改一下脚本 scullc_load 将18行的, -f 参数去掉。 这里如果不去掉,我在安装模块时提示: ERROR: could not insert module ./scullc.ko: Invalid module format