阅读:1219回复:2
急救
兄弟我是linux新手,现在正在作设备驱动程序原码如下:
#define MODULE #define __NO_VERSION__ #include <linux/module.h> #include <linux/version.h> char kernel_version [] = UTS_RELEASE; #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 int read_test(struct inode *node, struct file *file, char *buf, int count) { int left; if (verify_area(VERIFY_WRITE,buf,count) == -EFAULT ) return -EFAULT; for(left = count ; left > 0 ; left--) { __put_user(1,buf,1); buf++; } return count; } static int write_test(struct inode *inode, struct file *file, const char *buf, int count) { return count; } static int open_test(struct inode *inode, struct file *file ) { MOD_INC_USE_COUNT; return 0; } static void release_test(struct inode *inode, struct file *file ) { MOD_DEC_USE_COUNT; } struct file_operations test_fops = { NULL, read_test, write_test, NULL, /* test_readdir */ NULL, NULL, /* test_ioctl */ NULL, /* test_mmap */ open_test, release_test, NULL, /* test_fsync */ NULL, /* test_fasync */ /* nothing more, fill with NULLs */ NULL, NULL, NULL, }; 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 \"); return result; } if (test_major == 0) test_major = result; /* dynamic */ return 0; } void cleanup_module(void) { unregister_chrdev(test_major, \"test\"); } 编译命令如下: gcc test.c -DMODULE -D__KERNEL__ -o test.o 结果出现很多源文件错误,如在/usr/incude/linux/fs.h中找不到file_operation数据结构...... 那位大虾给兄弟指点一下迷津 |
|
沙发#
发布于:2004-04-14 05:35
你的驱动种序编译出来也装不上去._NO_VERSION不能随便乱用的.
|
|
板凳#
发布于:2004-04-15 21:06
写一个makefile吧
CC=gcc MODCFLAGS:=-Wall -DMODULE -D__KERNEL__ -DLINUX -I /usr/src/linux-2.4.20-8(为你所用的版本号)/include test.o:test.c /usr/include/linux/version.h $(CC) $(MODCFLAGS) -c test.c 然后在目录下make就可以了! |
|