Linux驱动开发之2.6.38版本下LDD3驱动的编译 来源:linux社区 作者:pang123hui

这两天一直看LDD3,看的很爽,似懂非懂的样子,今天开始编译例程代码scull的时候,悲剧很大,折腾了很久,主要是我Ubuntu 11.04的内核版本是2.6.38,而例程编译的内核版本是2.6.10,这中间内核本身已经发生了翻天覆地的变化。说白了,能make过去,那才出鬼了,好吧,一个错误一个错误来,不急。        直接make,第一个问题来了。。。。

根据提示把Makefile里的CFLAGS 改成EXTRA_CFLAGS 即可,继续……

提示:

        如果您使用的是vi,可以和我一样一道命令解决:0,$s/CFLAGS/EXTRA_CFLAGS/g

       别忘了保存,继续make……

       第二个问题来了。。。。

好吧,我不理解了,讲驱动最常见的ioctl 你不认识,why?

       原来在2.6.36版本更新中,file_operations发生了很大的变化,去掉了ioctl,而加入了两个新函数

  1. long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);     
  2. long (*compat_ioctl) (struct file *, unsigned int, unsigned long);    

注:2.6.38的file_operation结构体
  1. struct file_operations {     
  2.     struct module *owner;     
  3.     loff_t (*llseek) (struct file *, loff_t, int);     
  4.     ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);     
  5.     ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);     
  6.     ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);     
  7.     ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);     
  8.     int (*readdir) (struct file *, void *, filldir_t);     
  9.     unsigned int (*poll) (struct file *, struct poll_table_struct *);     
  10.     long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);     
  11.     long (*compat_ioctl) (struct file *, unsigned int, unsigned long);     
  12.     int (*mmap) (struct file *, struct vm_area_struct *);     
  13.     int (*open) (struct inode *, struct file *);     
  14.     int (*flush) (struct file *, fl_owner_t id);     
  15.     int (*release) (struct inode *, struct file *);     
  16.     int (*fsync) (struct file *, int datasync);     
  17.     int (*aio_fsync) (struct kiocb *, int datasync);     
  18.     int (*fasync) (int, struct file *, int);     
  19.     int (*lock) (struct file *, int, struct file_lock *);     
  20.     ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);     
  21.     unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);     
  22.     int (*check_flags)(int);     
  23.     int (*flock) (struct file *, int, struct file_lock *);     
  24.     ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);     
  25.     ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);     
  26.     int (*setlease)(struct file *, long, struct file_lock **);     
  27.     long (*fallocate)(struct file *file, int mode, loff_t offset,     
  28.               loff_t len);     
  29. };    

问题找到了,那么怎么解决呢?在main.c 文件中:

按照我下面的代码这样改就OK了。  
  1.  * The unlocked_ioctl() implementation     
  2.  */     
  3. int scull_unlocked_ioctl(struct file *filp,     
  4.                  unsigned int cmd, unsigned long arg)    
还有在file_operation 赋值处修改如下:
  1. struct file_operations scull_fops = {     
  2.     .owner =    THIS_MODULE,     
  3.     .llseek =   scull_llseek,     
  4.     .read =     scull_read,     
  5.     .write =    scull_write,     
  6.     .unlocked_ioctl =    scull_unlocked_ioctl,     
  7.     .open =     scull_open,     
  8.     .release =  scull_release,     
  9. };    

pipe.cscull.h 以及access.h 中也类似修改。

再次make,至少这个问题已经解决了,但是新的问题又来了……

第三个问题来了。。。。

init_MUTEX(&scull_devices[i].sem); 修改为sema_init(&scull_devices[i].sem, 1);

access.c 文件中做相似修改。

第四个问题来了。    

pipe.c 中添加一个头文件:#include <linux/sched.h>

第五个问题来了。 
  

access.c 中添加一个头文件:#include <linux/sched.h>         

第六个问题来了。 

truct task_struct定义在include/linux/sched.h中,原来task_struct结构体定义有所改动,将uid和euid等挪到cred中,见include/linux/sched.h和include/linux/cred.h。

因此只需要将报error的代码做如下修改
current->uid 修改为 current->cred->uid
current->euid 修改为 current->cred->euid
    

------------------------------

OK,make成功!





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值