错误1:
-
make -C /lib/modules/3.2.0-23-generic-pae/build M=/home/yangql/ldd3/code/scullc LDDINC=/home/yangql/ldd3/code/scullc modules
-
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
-
scripts/Makefile.build:49: *** CFLAGS was changed in "/home/yangql/ldd3/code/scullc/Makefile". Fix it to use ccflags-y. Stop.
-
make[1]: *** [_module_/home/yangql/ldd3/code/scullc] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
-
make: *** [modules] Error 2
修改Makefile,将CFLAGS修改为EXTRA_CFLAGS
错误2:
-
make -C /lib/modules/3.2.0-23-generic-pae/build M=/home/yangql/ldd3/code/scullc LDDINC=/home/yangql/ldd3/code/scullc modules
-
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
-
CC [M] /home/yangql/ldd3/code/scullc/main.o
-
/home/yangql/ldd3/code/scullc/main.c:18:26: fatal error: linux/config.h: No such file or directory
-
compilation terminated.
-
make[2]: *** [/home/yangql/ldd3/code/scullc/main.o] Error 1
-
make[1]: *** [_module_/home/yangql/ldd3/code/scullc] Error 2
-
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
-
make: *** [modules] Error 2
去掉头文件config.h
错误3:
-
make -C /lib/modules/3.2.0-23-generic-pae/build M=/home/yangql/ldd3/code/scullc LDDINC=/home/yangql/ldd3/code/scullc modules
-
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
-
CC [M] /home/yangql/ldd3/code/scullc/main.o
-
/home/yangql/ldd3/code/scullc/main.c:52:1: error: unknown type name ???kmem_cache_t???
-
/home/yangql/ldd3/code/scullc/main.c: In function ???scullc_write???:
-
/home/yangql/ldd3/code/scullc/main.c:247:3: warning: passing argument 1 of ???kmem_cache_alloc??? from incompatible pointer type [enabled by default]
这是因为kmem_cache_t结构被换成了kmem_cache。而kmem_cache定义在和。但是你并不需要包含这两个文件中的一个。因为会根据CONFIG_SLUB等来判断具体包含,还是。故例程中需要将
kmem_cache_t *scullc_cache;
改为:
struct kmem_cache *scullc_cache;
错误4:
-
CC [M] /home/yangql/ldd3/code/scullc/main.o
-
/home/yangql/ldd3/code/scullc/main.c: In function ???scullc_defer_op???:
-
/home/yangql/ldd3/code/scullc/main.c:440:54: error: macro "INIT_WORK" passed 3 arguments, but takes just 2
-
/home/yangql/ldd3/code/scullc/main.c:440:2: error: ???INIT_WORK??? undeclared (first use in this function)
-
/home/yangql/ldd3/code/scullc/main.c:440:2: note: each undeclared identifier is reported only once for each function it appears in
-
/home/yangql/ldd3/code/scullc/main.c:441:2: warning: passing argument 1 of ???schedule_delayed_work??? from incompatible pointer type [enabled by default]
修改
-
struct async_work {
-
struct kiocb *iocb;
-
int result;
-
struct work_struct work;
-
};
为:
点击(此处)折叠或打开
-
struct async_work {
-
struct kiocb *iocb;
-
int result;
-
struct delayed_work delayed_work;
-
}
修改:
点击(此处)折叠或打开
-
INIT_WORK(&stuff->work, scull_do_deferred_op, stuff);
-
schedule_delayed_work(&stuff->work, HZ/100);
为:
点击(此处)折叠或打开
-
INIT_DELAYED_WORK(&stuff->delayed_work, scullc_do_deferred_op);
-
schedule_delayed_work(&stuff->delayed_work, HZ/100);
错误5:
点击(此处)折叠或打开
-
/home/yangql/ldd3/code/scullc/main.c: In function ???scullc_init???:
-
/home/yangql/ldd3/code/scullc/main.c:561:4: error: too many arguments to function ???kmem_cache_create???
函数kmem_cache_create的原型已经改变:
-
struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, unsigned long, void (*)(void *));
故调用它的时候应该将参数做出相应的改变。需要将最后一个NULL去掉。
错误6:
点击(此处)折叠或打开
-
/home/yangql/ldd3/code/scullc/main.c:470:2: error: unknown field ???ioctl??? specified in initializer
修改
.ioctl = scullc_ioctl, 为.unlocked_ioctl = scullc_ioctl, 同时将scullc_ioctl的返回值修改为
long scullc_ioctl (struct file *filp, unsigned int cmd, unsigned long arg)
处理警告信息
-
/home/yangql/ldd3/code/scullc/main.c: In function ???scullc_defer_op???:
-
/home/yangql/ldd3/code/scullc/main.c:440:2: warning: assignment from incompatible pointer type [enabled by default]
-
/home/yangql/ldd3/code/scullc/main.c: At top level:
-
/home/yangql/ldd3/code/scullc/main.c:470:2: warning: initialization from incompatible pointer type [enabled by default]
-
/home/yangql/ldd3/code/scullc/main.c:470:2: warning: (near initialization for ???scullc_fops.unlocked_ioctl???) [enabled by default]
-
/home/yangql/ldd3/code/scullc/main.c:473:2: warning: initialization from incompatible pointer type [enabled by default]
-
/home/yangql/ldd3/code/scullc/main.c:473:2: warning: (near initialization for ???scullc_fops.aio_read???) [enabled by default]
-
/home/yangql/ldd3/code/scullc/main.c:474:2: warning: initialization from incompatible pointer type [enabled by default]
-
/home/yangql/ldd3/code/scullc/main.c:474:2: warning: (near initialization for ???scullc_fops.aio_write???) [enabled by default]
在2.6.22版本以后的内核中,INIT_WORK已经做了大幅度的修改 ,INIT_WORK现在使用2个参数,去掉了最后一个data参数,传入func的声明也有所变化。如下所示:
INIT_WORK(struct work_struct *work, void (*function)(struct work_struct *));
INIT_DELAYED_WORK(struct delayed_work *work, void (*function)(struct work_struct *));
这时function以INIT_WROK中的第一参数work作为参数。因此在使用时需要将的struct work_struct *work加入到data所在的数据结构。这里需要注意在引用INIT_DELAYED_WORK时struct work_struct这个结构自身的改动,
work_struct结构体包含于delayed_work结构体中,如下:
点击(此处)折叠或打开
-
struct delayed_work {
-
struct work_struct work;
-
struct timer_list timer;
-
}
因此函数scullc_do_deferred_op修改如下:
-
static void scullc_do_deferred_op(struct work_struct *p)
-
{
-
struct async_work *stuff = container_of(p, struct async_work, delayed_work.work);
-
aio_complete(stuff->iocb, stuff->result, 0);
-
kfree(stuff);
-
}
由于aio_read和aio_write函数有改变,最新的声明为:
点击(此处)折叠或打开
-
ssize_t (*aio_read) (struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos);
-
ssize_t (*aio_write) (struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos);
根据上面的声明修改下面的函数为
-
static ssize_t scullc_aio_read(struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos)
-
{
-
return scullc_defer_op(0, iocb, iov, niov, pos);
-
}
-
-
static ssize_t scullc_aio_write(struct kiocb *iocb, const struct iovec *iov,unsigned long niov, loff_t pos)
-
{
-
return scullc_defer_op(1, iocb, iov, niov, pos);
-
}
-
-
static int scullc_defer_op(int write, struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos)
-
{
-
struct async_work *stuff;
-
int result;
-
-
/* Copy now while we can access the buffer */
-
if (write)
-
result = scullc_write(iocb->ki_filp, (char *)(iov->iov_base), iov->iov_len, &pos);
-
else
-
result = scullc_read(iocb->ki_filp, (char *)(iov->iov_base), iov->iov_len, &pos);
-
-
/* If this is a synchronous IOCB, we return our status now. */
-
if (is_sync_kiocb(iocb))
-
return result;
-
-
/* Otherwise defer the completion for a few milliseconds. */
-
stuff = kmalloc (sizeof (*stuff), GFP_KERNEL);
-
if (stuff == NULL)
-
return result; /* No memory, just complete now */
-
stuff->iocb = iocb;
-
stuff->result = result;
-
INIT_DELAYED_WORK(&(stuff->delayed_work), scullc_do_deferred_op);
-
schedule_delayed_work(&(stuff->delayed_work), HZ/100);
-
return -EIOCBQUEUED;
-
}
阅读(2157) | 评论(0) | 转发(0) |