完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
源程序:
#define _NO_VERSION #include #include #include #include char kernel_version[] =UTS_RELEASE; #define KERNEL #include #include #include #include #include #define SUCCESS 0 #define DEVICE_NAME "char_dev" static int Device_Open=0; unsigned int test_major=0; static int open_test(struct inode *inode,struct file *file){ #ifdef DEBUG printk("device_open(%p)n",file); #endif if(Device_Open) return -EBUSY; Device_Open++; MOD_INC_USE_COUNT; return SUCCESS; } static int release_test(struct inode *inode,struct file *file){ #ifdef DEBUG printk("device_release(%p,%p)n",inode,file); #endif Device_Open--; MOD_DEC_USE_COUNT; return 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 struct file_operations tdd_fops = { read:read_test, openpen_test, release:release_test, }; int init_module(void) { int result; result = register_chrdev(0, "char_dev", &tdd_fops); if (result < 0) { printk("char_dev: can't get major numbern"); return result; } if (test_major == 0) test_major = result; /* dynamic */ printk("Hello,I'm in kernel moden"); return 0; } void cleanup_module(void) { printk("<0>""Hello,I'm going to outn"); unregister_chrdev(test_major,"test"); } 编译命令:gcc -D_KERNEL_ -DMODULE -DLINUX -I/usr/src/linux-2.4.20-8/include -c -o CharDriver.o CharDriver.c 结果: CharDriver.c: At top level: CharDriver.c:17: warning: `struct inode' declared inside parameter list CharDriver.c:36: warning: `struct file' declared inside parameter list CharDriver.c:36: warning: `struct inode' declared inside parameter list CharDriver.c:48: warning: `struct file' declared inside parameter list CharDriver.c:58: variable `tdd_fops' has initializer but incomplete type CharDriver.c:59: unknown field `read' specified in initializer CharDriver.c:59: warning: excess elements in struct initializer CharDriver.c:59: warning: (near initialization for `tdd_fops') CharDriver.c:60: unknown field `open' specified in initializer CharDriver.c:60: warning: excess elements in struct initializer CharDriver.c:60: warning: (near initialization for `tdd_fops') CharDriver.c:61: unknown field `release' specified in initializer CharDriver.c:61: warning: excess elements in struct initializer CharDriver.c:61: warning: (near initialization for `tdd_fops') CharDriver.c:58: storage size of `tdd_fops' isn't known 我的linux为Red Hat linux 9,我认为这里出现上述的问题主要是因为链接到了/usr/include/linux/fs.h,没有链接到usr/src/linux2.4.20.8/incude/linux/fs.h.s 我的系统是: Linux Red Hat9.0 Kernel 2.4.20-8 gcc 版本: 3.2.2 20030222 |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1056 浏览 0 评论
AI模型部署边缘设备的奇妙之旅:如何在边缘端部署OpenCV
3545 浏览 0 评论
tms320280021 adc采样波形,为什么adc采样频率上来波形就不好了?
1482 浏览 0 评论
2181 浏览 0 评论
1663 浏览 0 评论
75421 浏览 21 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-29 12:55 , Processed in 0.586874 second(s), Total 69, Slave 53 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号