Search code examples
clinuxlinux-kernelsysfs

How can i read sysfs attributes


How can i read sysfs attributes from user app. It is similar content from cat command. Such as I have a tag is brightness. How can i get the value of brightness tag? Because i need to read the USB infor from my app and i see they were exported to sysfs like below topology:

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

Solution

  • Open the file using e.g. fopen("//sys/bus/usb/devices/1-1/version", "rt") and read its contents like with any other file. Not sure about brightness, you don't mention which file its in and there's no file with that name.