insmod 错误 -1 Invalid module format
21lyw 2009-06-29 11:43:21 查看系统信息为: disagrees about version of symbol struct_module
当前运行内核版本是 Linux version 2.6.18-1.2798.fc6 (brewbuilder@hs20-bc2-3.build.redhat.com) (gcc version 4.1.1 20061011 (Red Hat 4.1.1-30)) #1 SMP Mon Oct 16 14:54:20 EDT 2006
源码下载的是:2.6.18.1
程序为
#include <linux/module.h>
#include <linux/init.h>
#include <linux/fs.h> /* everything... */
#define DEVICE_NAME "demo"
#define demo_MAJOR 249
#define demo_MINOR 0
#define MAX_BUF_LEN 20
//MODULE_LICENSE("GPL");
#ifdef UTS_RELEASE
#undef UTS_RELEASE
#endif
#define UTS_RELEASE "2.6.18-1"
static char drv_buf[20];
static int demo_open(struct inode *inode, struct file *file)
{
//MOD_INC_USE_COUNT;
//sprintf(drv_buf,"device open sucess!\n");
//printk("device open sucess!\n");
return 0;
}
static int demo_release(struct inode *inode, struct file *filp)
{
//MOD_DEC_USE_COUNT;
//printk("device release\n");
return 0;
}
static ssize_t demo_read(struct file *filp, char *buffer, size_t count, loff_t *ppos)
{
if(count > MAX_BUF_LEN)
count=MAX_BUF_LEN;
//copy_to_user(buffer, drv_buf,count);
printk("user read data from driver\n");
return count;
}
static ssize_t demo_write(struct file *filp,const char *buffer, size_t count)
{
//copy_from_user(drv_buf , buffer, count);
printk("user write data to driver\n");
//your code here
return count;
}
static struct file_operations demo_fops =
{
write: demo_write,
read: demo_read,
open: demo_open,
release: demo_release,
};
static int demo_init(void)
{
int result;
/*SET_MODULE_OWNER(&demo_fops);*/
result = register_chrdev(demo_MAJOR, "demo", &demo_fops);
if (result < 0) return result;
printk(DEVICE_NAME " initialized\n");
return 0;
}
static void demo_exit(void)
{
unregister_chrdev(demo_MAJOR, "demo");
printk(DEVICE_NAME " unloaded\n");
}
module_init(demo_init);
module_exit(demo_exit);