這兩天一直看LDD3,看的很爽,似懂非懂的樣子,今天開始編譯常式代碼scull的時候,悲劇很大,折騰了很久,主要是我Ubuntu11.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結構體
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
中也類似修改。
再次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成功!!!!!!!!!!!!!
------------------------------------------------------------------------------------------------------------------
作者:龐輝
出處:http://www.cnblogs.com/pang123hui/
本文基於署名 2.5 中國大陸許可協議發布,歡迎轉載,演繹或用於商業目的,但是必須保留本文的署名龐輝(包含連結).