如何在不运行 mknod 的情况下让 Linux 字符设备自动显示在 /dev 中?
让角色出现在 /dev 中的最佳方法是什么?我有一个调用 register_chrdev 的驱动程序,当我加载模块时,我在 /proc/devices 中看到该条目。但是,我仍然需要在命令行上调用 mknod 才能使其显示在 /dev 中。
有没有一种好方法可以在模块加载时以编程方式执行此操作?
What is the best way to get a character to show up in /dev? I have a driver that calls register_chrdev, and I see the entry in /proc/devices when I load the module. However, I still have to call mknod on the command-line in order to get it show up in /dev.
Is there a good way to do this programmatic-ally at module load time?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要自动创建设备节点(例如通过 udev 或 devtmpfs),需要生成随附的 kevent。单独的 register_chrdev 并不能做到这一点。相反,它需要遵循设备/驱动程序模型(另请参阅文档/驱动程序模型/),并使用 kobject。
与 drivers/char/misc.c 进行比较,这是一个更简单的示例:它使用 device_create()。其先决条件是拥有一个结构类,misc.c 也展示了这一点。
To have a device node automatically created, for example by means of udev or devtmpfs, an accompanying kevent needs to be generated. register_chrdev alone does not do this. Instead, it is required to follow the device/driver model (see also Documentation/driver-model/), and make use of kobjects.
Compare with drivers/char/misc.c for one of the simpler examples: it uses device_create(). The prerequisite for that is having a struct class, also showcased by misc.c.