1 Star 2 Fork 2

e665107/Linux-Device-Drivers-Development

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Character device driver

After running make command, there will be one module:

  • dummy-char.ko

After loading the module, there will be a /dev/dummy_char char device. There is also a class created for this device, /sys/class/dummy_char_class/. One can actually print info on the device using udevadm info command:

# insmod dummy-char.ko
# udevadm info /dev/dummy_char
P: /devices/virtual/dummy_char_class/dummy_char
N: dummy_char
E: DEVNAME=/dev/dummy_char
E: DEVPATH=/devices/virtual/dummy_char_class/dummy_char
E: MAJOR=241
E: MINOR=0
E: SUBSYSTEM=dummy_char_class


$ ls -l /sys/class/dummy_char_class/
total 0
lrwxrwxrwx 1 root root 0 oct.  12 16:05 dummy_char -> ../../devices/virtual/dummy_char_class/dummy_char
$ cat /sys/class/dummy_char_class/dummy_char/dev 
241:0

For testing purpose, one can use cat and read commands:

# cat /dev/dummy_char 
# echo "blabla" > /dev/dummy_char 
# rmmod dummy-char.ko 

$ dmesg
[...]
[31444.392114] dummy_char major number = 241
[31444.392217] dummy char module loaded
[31452.575938] Someone tried to open me
[31452.575945] Nothing to read guy
[31452.575950] Someone closed me
[31483.210527] Someone tried to open me
[31483.210570] Can't accept any data guy
[31483.210578] Someone closed me
[31498.998185] dummy char module Unloaded
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/e665107/Linux-Device-Drivers-Development.git
git@gitee.com:e665107/Linux-Device-Drivers-Development.git
e665107
Linux-Device-Drivers-Development
Linux-Device-Drivers-Development
master

搜索帮助