如何在不运行 mknod 的情况下让 Linux 字符设备自动显示在 /dev 中?

发布于 2024-10-03 05:57:05 字数 163 浏览 0 评论 0原文

让角色出现在 /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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

少女净妖师 2024-10-10 05:57:05

要自动创建设备节点(例如通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文