想整理下设备驱动这块的知识。
结果用模块编译的时候出现了如下的错误:
源文件:
//mydisk.c
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "mydisk.h"
struct file_operations mydisk_fops={
open: generic_file_open,
write: generic_file_write,
release: generic_file_release,
ioctl: generic_file_ioctl,
llseek: generic_file_llseek,
read: generic_file_read,
};
int init_modules(void)
{
printk(KERN_INFO "MOUNT IDE DISK...\N");
if(register_blkdev(DEV_MAJOR,DEV_NAME,&mydisk_fops)<0)
{
printk(KERN_INFO "Couldn't register a device.\n");
return -1;
}
return 0;
}
int cleanup_modlue(void)
{
if(unregister_blkdev(DEV_MAJOR,DEV_NAME))
printk("Failed to unregister device.\n");
else
printk("Device uninstalled.\n");
}
MODULE_LICENSE("GPL");
//mydisk.h
#ifndef _MYDISK_H_
#define DEV_MAJOR 3
#define DEV_NAME "IDEDISK"
#endif
编译:
gcc -c mydisk.c -D_KERNEL_ -DMODULE -O2 -g -Wall -o mydisk.o
错误提示:
In file included from /usr/include/linux/sched.h:14
from /usr/include/linux/mm.h:4
from /usr/include/linux/locks.h:5
from /usr/include/linux/devfs_fs_kernel.h:6,
from mydisk.c:4
/usr/include/linux/timex.h:173: field 'time' has incomplete type
/usr/include/linux/timex.h:188: confused by earlier errors, bailing out
///////////////////////////////////////
1.这个问题怎么解决?
2.以前没写过Linux的驱动,甚至程序也不怎么写过,想问一下,模块编译时候的头文件包含到底要怎么办,都弄不太清楚。
希望前辈指点。谢谢。。。~~~