完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
|
我本想注册一个字符设备,但是通过device_create自动创建出来的节点设备类型是块设备,导致运行测试程序是找不到设备文件
内核:linux-2.6.32.2 # ls -l /dev/xyz brw-rw---- 1 0 0 253, 0 Jun 15 03:16 /dev/xyz # 驱动代码是韦东山教程里的例程: #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct class *firstdrv_class; static struct device *firstdrv_class_dev; static int first_drv_open(struct inode *inode, struct file *file) { printk("first_drv_openn"); return 0; } static ssize_t first_drv_write(struct file *file, const char __user *buf, size_t count, loff_t * ppos) { int val; printk("first_drv_writen"); copy_from_user(&val, buf, count); // copy_to_user(); if (val == 1) { } else { } return 0; } static struct file_operations first_drv_fops = { .owner = THIS_MODULE, .open = first_drv_open, .write = first_drv_write, }; int major; static int first_drv_init(void) { major = register_chrdev(0, "first_drv", &first_drv_fops); //register_chrdev(111, "first_drv", &first_drv_fops); firstdrv_class = class_create(THIS_MODULE, "firstdrv"); firstdrv_class_dev = device_create(firstdrv_class, NULL, MKDEV(major, 0), NULL, "xyz"); /* /dev/xyz */ return 0; } static void first_drv_exit(void) { unregister_chrdev(major, "first_drv"); device_unregister(firstdrv_class_dev); class_destroy(firstdrv_class); } module_init(first_drv_init); module_exit(first_drv_exit); MODULE_LICENSE("GPL"); |
|
相关推荐
3个回答
|
|
|
编译有没有问题呢?
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
只有小组成员才能发言,加入小组>>
TuyaOpen开源 + DshanPi-A1(RK3576)开发板的Tuya IoT平台接入与AI大模型整合方案(笔记)
1327 浏览 0 评论
「含关键代码」基于AM3352/AM3354/AM3359的Linux开发案例分享
5241 浏览 0 评论
87854 浏览 0 评论
【高手问答】如何做到精通linux技术?资深工程师带你突破难点
5306 浏览 2 评论
3997 浏览 2 评论
2328浏览 1评论
SiRider S1芯擎工业开发板测评+1.防止黑客入侵通信监控系统(PSA)
1657浏览 0评论
TuyaOpen开源 + DshanPi-A1(RK3576)开发板的Tuya IoT平台接入与AI大模型整合方案(笔记)
1327浏览 0评论
/9
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2025-12-2 12:47 , Processed in 0.741477 second(s), Total 76, Slave 60 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191

淘帖
2080