c - 我如何读取 sysfs 属性

标签 c linux linux-kernel sysfs

我如何从用户应用程序读取 sysfs 属性。它与 cat 命令的内容类似。比如我有一个标签是亮度。如何获取亮度标签的值?因为我需要从我的应用程序读取 USB 信息,并且我看到它们被导出到 sysfs,如下拓扑所示:

ls /sys/bus/usb/devices/1-1
1-1:1.0              busnum               port
authorized           configuration        power
avoid_reset_quirk    descriptors          product
bConfigurationValue  dev                  quirks
bDeviceClass         devnum               removable
bDeviceProtocol      devpath              remove
bDeviceSubClass      driver               serial
bMaxPacketSize0      ep_00                speed
bMaxPower            idProduct            subsystem
bNumConfigurations   idVendor             uevent
bNumInterfaces       ltm_capable          urbnum
bcdDevice            manufacturer         version
bmAttributes         maxchild

最佳答案

使用例如打开文件fopen("//sys/bus/usb/devices/1-1/version", "rt") 并像读取任何其他文件一样读取其内容。不确定亮度,您没有提及它在哪个文件中,并且没有具有该名称的文件。

关于c - 我如何读取 sysfs 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33391792/

相关文章:

java - 为什么有前缀/后缀++而没有前缀/后缀+=?

c - 为 makefiles/kconfig 中的变量赋值

linux - "Ambiguous redirect"执行脚本时出错

c - C中的String Inverter Program中的警告

c - PCI_VDEVICE 和 PCI_DEVICE 有什么区别?

docker - 如何在Docker容器上应用内核调整

c - redis存储数据的锁机制

c - 通过它的 API(或扩展)识别一个分辨率在 X11 屏幕上是虚拟的

c - 虽然循环等待全局变量不触发

linux - 如何使用 Perl 终止 OpenVPN 连接?