【发布时间】:2018-05-28 21:47:24
【问题描述】:
我目前正在阅读一本名为"Linux device drivers" from O'Reilly的书。
事情是,这本书 imo 并不是真正的如何 编写驱动程序的指南,而是解释了所有的 API 及其原理。 所以我试着用我目前读到的东西写一个小驱动程序——它没有做任何有趣的事情。 事情是:
我不知道我可以在哪个文件上执行
cat或echo以调用我的回调函数它看起来和我在网上找到的所有其他代码 sn-ps 完全不同
不同的代码片段:
-
我的代码 (https://paste.ubuntu.com/p/8tVyTJTPBQ/) 创建:
$ls /sys/module/main/oresize holders initsize initstate notes refcnt sections srcversion taint ueventno new entry in /dev -
使用 device_create 编码 sn-p:https://paste.ubuntu.com/p/cJxjdyXjhX/ source 创建:
$ ls /sys/module/main/coresize holders initsize initstate notes refcnt sections srcversion taint uevent$ ls -l /dev/ebbcharcrw------- 1 root root 238, 0 Mai 28 07:52 /dev/ebbchar -
使用 kobjects 的代码:https://paste.ubuntu.com/p/nt3XvZs7vF/ source 创建:
$ls -l /sys/kernel/drwxr-xr-x 2 root root 0 Dec 17 16:29 etx_sysfs
我可以看到我的代码在 /sys/kernel 下成功创建了一堆文件。现在我的代码和其他两个 sn-ps 之间的 endgoal 有什么区别?我应该使用 device_create/kobjects 还是不使用这些?我正在阅读的这本书没有提到其他两段代码使用的函数。所以不确定我应该遵循哪种方式......
谢谢_xe
【问题讨论】:
-
是的,您应该为您的内核版本使用最新的可用 API。 LDDv3 对 udev 机制一无所知。
-
@0andriy 你怎么知道这不是最新的 API?您如何及时了解最新的 API?
标签: c linux linux-kernel linux-device-driver