当前位置:网站首页>libudev manual
libudev manual
2022-07-30 13:22:00 【Ruo_Xiao】
First, initialization
First call udev_new to create a udev library context.The udev library context adopts the reference counting mechanism. The default reference count of the created context is 1. Use udev_ref and udev_unref to increase or decrease the reference count. If the reference count is 0, the internal resources are released.
Second, enumerate devices
Use udev_enumerate_new to create an enumerator that scans the system for connected devices.Use udev_enumerate_ref and udev_enumerate_unref to increase or decrease the citation count.
Use the udev_enumerate_add_match / nomatch_xxx series of functions to add enumeration filters and filter keyWords are represented by characters, such as "block" devices.
Use the udev_enumerate_scan_xxx series of functions to scan the /sys directory for all devices that match the filter.The data structure after scanning is a linked list, use udev_enumerate_get_list_entry to get the first node of the linked list, use udev_list_entry_foreach Traverse the entire linked list.
3. Monitoring device plugging and unplugging udev's equipment plugging and unplugging is implemented based on netlink.
Use udev_monitor_new_from_netlink to create a new monitor, the second parameter of the function is the name of the event source, optional "kernel" or "udev".Event notifications based on "kernel" are earlier than "udev", but the related device nodes may not be created, so the design of general applications should be monitored based on "udev".
Use udev_monitor_filter_add_match_subsystem_devtype to add a udev event filter based on device type, eg: "block" devices.
Use udev_monitor_enable_receiving to start the monitoring process.For monitoring, you can use udev_monitor_get_fd to get a file descriptor, and based on the returned fd, you can perform the poll operation to simplify program design.
After the plug event arrives, you can use udev_monitor_receive_device to get the device mapping that generated the event.Calling udev_device_get_action can get a string: "add" or "remove", and "change", "online", "offline", etc., but the last threeIt is unknown under what circumstances it will occur.
Fourth, get device information
Use udev_list_entry_get_name to get the sys path of a device node, based on this path use udev_device_new_from_syspath can create a map of udev devices, which can be used to get device properties.To get device properties use udev_device_get_properties_list_entry to return a linked list that stores all property information of the device, use udev_list_entry_foreach Traverse the list and use udev_list_entry_get_name and udev_list_entry_get_value to get the name and value of the attribute.
Reprinted: libudev instruction manual_coroutinesBlog - CSDN Blog_libudev
(SAW: Game Over!)
边栏推荐
- 一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
- 云主机上的MongoDB被威胁,开启AUTH认证
- RTSP/Onvif协议视频平台EasyNVR服务一键升级功能的使用教程
- Markdown 1 - 图文音视频等
- R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(xlab、ylab、改变可视化图像的坐标轴标签内容)
- SyntaxError: EOL while scanning string literal
- 湖仓一体电商项目(一):项目背景和架构介绍
- CMake library search function does not search LD_LIBRARY_PATH
- strlen跟sizeof区别
- 当下,产业园区发展面临的十大问题
猜你喜欢
随机推荐
【软考软件评测师】自动化测试章节下篇
Mysql batch insert transaction unique key repeated processing
datax开启hana支持以及dolphinscheduler开启datax任务
基于空洞补全的动态SLAM方法
漫谈金丝雀部署(Canary Deployment)
dolphinscheduler单机化改造
判断链表是否有环
cpu / CS 和 IP
How to display an Excel table in the body of an email?
自从外包干了四年,基本废了...
curl 执行脚本时传递环境变量与参数
What are the hard-core upgrades and applications that cannot be missed in Greenplum 6.0?
域名抢注“卷”到了表情包?ENS逆势上涨的新推力
【Kaggle:UW-Madison GI Tract Image Segmentation】肠胃分割比赛:赛后复盘+数据再理解
jsArray数组复制方法性能测试2207300823
R语言ggstatsplot包grouped_ggwithinstats函数可视化分组小提琴图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)
05 | 后台登录:基于账号密码的登录方式(下)
基于DoS攻击能量分级的ICPS综合安全控制与通信协同设计
群晖系统安装相关文件分享
R语言ggplot2可视化:使用ggpubr包的ggboxplot函数可视化分组箱图、使用ggpar函数改变图形化参数(ylim、修改可视化图像y轴坐标轴数值范围)