| 发表于:2007-06-01 23:28:362楼 得分:0 |
#define __no_version__ #include <linux/module.h> #include <linux/config.h> #include <linux/version.h> #include <asm/uaccess.h> #include <linux/types.h> #include <linux/fs.h> #include <linux/mm.h> #include <linux/errno.h> #include <asm/segment.h> unsigned int test_major = 0; static ssize_t read_test(struct file *file,char *buf,size_t count,loff_t *f_pos) { int left; if (verify_area(verify_write,buf,count) == -efault ) return -efault; for(left = count ; left > 0 ; left--) { __put_user(1,buf); buf++; } return count; } static ssize_t write_test(struct file *file, const char *buf, size_t count, loff_t *f_pos) { return count; } static int open_test(struct inode *inode,struct file *file ) { mod_inc_use_count; return 0; } static int release_test(struct inode *inode,struct file *file ) { mod_dec_use_count; return 0; } struct file_operations test_fops = { read:read_test, write:write_test, open: open_test, release:release_test }; int init_module(void) { int result; result = register_chrdev(0, "test ", &test_fops); if (result < 0) { printk(kern_info "test: can 't get major number\n "); return result; } if (test_major == 0) test_major = result; /* dynamic */ return 0; } void cleanup_module(void) { unregister_chrdev(test_major, "test "); } module_license( "gpl "); module_author( "beckham "); 上面是源程序,用写的makefile可以在2.4内核下通过编译,用2.6内核通不过,说有很多东西没有定义之类的. 大家帮我看一下有什么问题,谢谢! | | |
|