Chinaunix首页 | 论坛 | 博客
  • 博客访问: 89785
  • 博文数量: 31
  • 博客积分: 15
  • 博客等级: 民兵
  • 技术积分: 142
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-08 13:05
文章分类

全部博文(31)

文章存档

2014年(17)

2013年(11)

2012年(3)

我的朋友

分类: LINUX

2014-01-13 12:34:30

错误1:

点击(此处)折叠或打开

  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
  2. make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
  3. scripts/Makefile.build:49: *** CFLAGS was changed in "/home/yangql/ldd3/code/scullc/Makefile". Fix it to use ccflags-y. Stop.
  4. make[1]: *** [_module_/home/yangql/ldd3/code/scullc] Error 2
  5. make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
  6. make: *** [modules] Error 2
修改Makefile,将CFLAGS修改为EXTRA_CFLAGS

错误2:

点击(此处)折叠或打开

  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
  2. make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
  3.   CC [M] /home/yangql/ldd3/code/scullc/main.o
  4. /home/yangql/ldd3/code/scullc/main.c:18:26: fatal error: linux/config.h: No such file or directory
  5. compilation terminated.
  6. make[2]: *** [/home/yangql/ldd3/code/scullc/main.o] Error 1
  7. make[1]: *** [_module_/home/yangql/ldd3/code/scullc] Error 2
  8. make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
  9. make: *** [modules] Error 2
去掉头文件config.h
错误3:

点击(此处)折叠或打开

  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
  2. make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic-pae'
  3.   CC [M] /home/yangql/ldd3/code/scullc/main.o
  4. /home/yangql/ldd3/code/scullc/main.c:52:1: error: unknown type name ???kmem_cache_t???
  5. /home/yangql/ldd3/code/scullc/main.c: In function ???scullc_write???:
  6. /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:

点击(此处)折叠或打开

  1. CC [M] /home/yangql/ldd3/code/scullc/main.o
  2. /home/yangql/ldd3/code/scullc/main.c: In function ???scullc_defer_op???:
  3. /home/yangql/ldd3/code/scullc/main.c:440:54: error: macro "INIT_WORK" passed 3 arguments, but takes just 2
  4. /home/yangql/ldd3/code/scullc/main.c:440:2: error: ???INIT_WORK??? undeclared (first use in this function)
  5. /home/yangql/ldd3/code/scullc/main.c:440:2: note: each undeclared identifier is reported only once for each function it appears in
  6. /home/yangql/ldd3/code/scullc/main.c:441:2: warning: passing argument 1 of ???schedule_delayed_work??? from incompatible pointer type [enabled by default]
修改

点击(此处)折叠或打开

  1. struct async_work {
  2.     struct kiocb *iocb;
  3.     int result;
  4.     struct work_struct work;
  5. };
为:
点击(此处)折叠或打开
  1. struct async_work {
  2.     struct kiocb *iocb;
  3.     int result;
  4.     struct delayed_work delayed_work;
  5. }
修改:
点击(此处)折叠或打开
  1. INIT_WORK(&stuff->work, scull_do_deferred_op, stuff);
  2. schedule_delayed_work(&stuff->work, HZ/100);
为:
点击(此处)折叠或打开
  1. INIT_DELAYED_WORK(&stuff->delayed_work, scullc_do_deferred_op);
  2. schedule_delayed_work(&stuff->delayed_work, HZ/100);
错误5:
点击(此处)折叠或打开
  1. /home/yangql/ldd3/code/scullc/main.c: In function ???scullc_init???:
  2. /home/yangql/ldd3/code/scullc/main.c:561:4: error: too many arguments to function ???kmem_cache_create???
函数kmem_cache_create的原型已经改变:

点击(此处)折叠或打开

  1. struct kmem_cache *kmem_cache_create(const char *, size_t, size_t, unsigned long, void (*)(void *));
故调用它的时候应该将参数做出相应的改变。需要将最后一个NULL去掉。

错误6:
点击(此处)折叠或打开
  1. /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)



处理警告信息

点击(此处)折叠或打开

  1. /home/yangql/ldd3/code/scullc/main.c: In function ???scullc_defer_op???:
  2. /home/yangql/ldd3/code/scullc/main.c:440:2: warning: assignment from incompatible pointer type [enabled by default]
  3. /home/yangql/ldd3/code/scullc/main.c: At top level:
  4. /home/yangql/ldd3/code/scullc/main.c:470:2: warning: initialization from incompatible pointer type [enabled by default]
  5. /home/yangql/ldd3/code/scullc/main.c:470:2: warning: (near initialization for ???scullc_fops.unlocked_ioctl???) [enabled by default]
  6. /home/yangql/ldd3/code/scullc/main.c:473:2: warning: initialization from incompatible pointer type [enabled by default]
  7. /home/yangql/ldd3/code/scullc/main.c:473:2: warning: (near initialization for ???scullc_fops.aio_read???) [enabled by default]
  8. /home/yangql/ldd3/code/scullc/main.c:474:2: warning: initialization from incompatible pointer type [enabled by default]
  9. /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结构体中,如下:
点击(此处)折叠或打开
  1. struct delayed_work {
  2.         struct work_struct work;
  3.         struct timer_list timer;
  4. }
因此函数scullc_do_deferred_op修改如下:

点击(此处)折叠或打开

  1. static void scullc_do_deferred_op(struct work_struct *p)
  2. {
  3.         struct async_work *stuff = container_of(p, struct async_work, delayed_work.work);
  4.         aio_complete(stuff->iocb, stuff->result, 0);
  5.         kfree(stuff);
  6. }

由于aio_read和aio_write函数有改变,最新的声明为:
点击(此处)折叠或打开

  1. ssize_t (*aio_read) (struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos);
  2. ssize_t (*aio_write) (struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos);

根据上面的声明修改下面的函数为

点击(此处)折叠或打开

  1. static ssize_t scullc_aio_read(struct kiocb *iocb, const struct iovec *iov, unsigned long niovloff_t pos)
  2. {
  3.     return scullc_defer_op(0, iocb, iov, niov, pos);
  4. }
  5.  
  6. static ssize_t scullc_aio_write(struct kiocb *iocb, const struct iovec *iov,unsigned long niov, loff_t pos)
  7. {
  8.     return scullc_defer_op(1, iocb, iov, niov, pos);
  9. }

  10. static int scullc_defer_op(int write, struct kiocb *iocb, const struct iovec *iov, unsigned long niov, loff_t pos)
  11. {
  12.     struct async_work *stuff;
  13.     int result;

  14.      /* Copy now while we can access the buffer */
  15.      if (write)
  16.          result = scullc_write(iocb->ki_filp, (char *)(iov->iov_base), iov->iov_len, &pos);
  17.     else
  18.          result = scullc_read(iocb->ki_filp, (char *)(iov->iov_base), iov->iov_len, &pos);

  19.     /* If this is a synchronous IOCB, we return our status now. */
  20.     if (is_sync_kiocb(iocb))
  21.         return result;

  22.      /* Otherwise defer the completion for a few milliseconds. */
  23.     stuff = kmalloc (sizeof (*stuff), GFP_KERNEL);
  24.     if (stuff == NULL)
  25.         return result; /* No memory, just complete now */
  26.     stuff->iocb = iocb;
  27.     stuff->result = result;
  28.     INIT_DELAYED_WORK(&(stuff->delayed_work), scullc_do_deferred_op);
  29.     schedule_delayed_work(&(stuff->delayed_work), HZ/100);
  30.     return -EIOCBQUEUED;
  31. }




阅读(2157) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~