作者:BuauOoO_987 | 来源:互联网 | 2017-09-29 23:42
这两天一直看LDD3,看的很爽,似懂非懂的样子,今天开始编译例程代码scull的时候,悲剧很大,折腾了很久,主要是我Ubuntu11.04的内核版本是2.6.38,而例程编译的内核版本是2.6.10,这中间内核本身已经发生了翻天覆地的变化。说白了,能make过去,那才出鬼了,好吧,一个错误一个错误来,不急。 
这两天一直看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,而加入了两个新函数
- long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
- long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
注:2.6.38的file_operation结构体
view plaincopy to clipboardprint?
- struct file_operations {
- struct module *owner;
- loff_t (*llseek) (struct file *, loff_t, int);
- ssize_t (*read) (struct file *, char __user *, size_t, loff_t *);
- ssize_t (*write) (struct file *, const char __user *, size_t, loff_t *);
- ssize_t (*aio_read) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
- ssize_t (*aio_write) (struct kiocb *, const struct iovec *, unsigned long, loff_t);
- int (*readdir) (struct file *, void *, filldir_t);
- unsigned int (*poll) (struct file *, struct poll_table_struct *);
- long (*unlocked_ioctl) (struct file *, unsigned int, unsigned long);
- long (*compat_ioctl) (struct file *, unsigned int, unsigned long);
- int (*mmap) (struct file *, struct vm_area_struct *);
- int (*open) (struct inode *, struct file *);
- int (*flush) (struct file *, fl_owner_t id);
- int (*release) (struct inode *, struct file *);
- int (*fsync) (struct file *, int datasync);
- int (*aio_fsync) (struct kiocb *, int datasync);
- int (*fasync) (int, struct file *, int);
- int (*lock) (struct file *, int, struct file_lock *);
- ssize_t (*sendpage) (struct file *, struct page *, int, size_t, loff_t *, int);
- unsigned long (*get_unmapped_area)(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
- int (*check_flags)(int);
- int (*flock) (struct file *, int, struct file_lock *);
- ssize_t (*splice_write)(struct pipe_inode_info *, struct file *, loff_t *, size_t, unsigned int);
- ssize_t (*splice_read)(struct file *, loff_t *, struct pipe_inode_info *, size_t, unsigned int);
- int (*setlease)(struct file *, long, struct file_lock **);
- long (*fallocate)(struct file *file, int mode, loff_t offset,
- loff_t len);
- };
问题找到了,那么怎么解决呢?在main.c 文件中:
按照我下面的代码这样改就OK了。
- * The unlocked_ioctl() implementation
- */
- int scull_unlocked_ioctl(struct file *filp,
- unsigned int cmd, unsigned long arg)
还有在file_operation 赋值处修改如下:
- struct file_operations scull_fops = {
- .owner = THIS_MODULE,
- .llseek = scull_llseek,
- .read = scull_read,
- .write = scull_write,
- .unlocked_ioctl = scull_unlocked_ioctl,
- .open = scull_open,
- .release = scull_release,
- };
在pipe.c 和scull.h 以及access.h 中也类似修改。