当前位置:网站首页>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!)
边栏推荐
- curl 执行脚本时传递环境变量与参数
- datax开启hana支持以及dolphinscheduler开启datax任务
- 物理服务器与虚拟机:主要区别和相似之处
- OpenHarmony环境搭建报错: ImportError: cannot import name ‘VERSION‘ from ‘hb.__main__‘
- R语言向前或者向后移动时间序列数据(自定义滞后或者超前的期数):使用dplyr包中的lag函数将时间序列数据向后移动一天(设置参数n为负值)
- R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
- 关于香港高防IP需要关注的几个问题
- 常见的云计算安全问题以及如何解决
- PyQt5快速开发与实战 8.6 设置样式
- 打破原则引入SQL,MongoDB到底想要干啥???
猜你喜欢
随机推荐
jsArray数组复制方法性能测试2207300040
Mac Brew 安装PHP
奇异值分解(SVD)原理与在降维中的应用(附带例题讲解)(纯理论)
ENVI图像处理(6):NDVI和植被指数
Hand tearing read-write lock performance test
Markdown 3 - 流程图表
R语言ggstatsplot包grouped_ggwithinstats函数可视化分组小提琴图、并添加假设检验结果(包含样本数、统计量、效应大小及其置信区间、显著性、组间两两比较、贝叶斯假设)
漫谈金丝雀部署(Canary Deployment)
CMake library search function does not search LD_LIBRARY_PATH
Decoding Redis' most overlooked high CPU and memory usage issues
如何把Excel表格显示到邮件正文里?
int a=8,a=a++,a? int b=8,b=b+1,b?
【自校正控制】自校正PID
关于香港高防IP需要关注的几个问题
物理服务器与虚拟机:主要区别和相似之处
树形dp小总结(换根,基环树,杂七杂八的dp)
R语言筛选时间序列数据的子集(subset time series data)、使用window函数筛选连续日期时间范围内的数据(start参数和end参数分别指定起始和结束时间)
434. 字符串中的单词数
R语言使用方差分析ANOVA比较回归模型的差异、anova函数比较两个模型并报告它们是否存在显著差异(两个模型的数据相同,一个模型使用的预测特征包含另外一个模型的特征)
[PostgreSQL] - explain SQL analysis introduction









