Last active
December 26, 2015 12:49
-
-
Save Makistos/7153883 to your computer and use it in GitHub Desktop.
This code will print out all sysfs devices under a certain device class (which is supplied as a parameter). #linux #sysfs #c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <sysfs/libsysfs.h> | |
#include <stdio.h> | |
/** | |
* @brief Lists all the devices in the given class. | |
* | |
* @param className Name of the class (in /sys/class). | |
*/ | |
void sysFsListDevices(char *className) | |
{ | |
struct sysfs_class *class; | |
struct dlist *devices; | |
struct sysfs_class_device *class_device; | |
struct sysfs_device *device; | |
class = sysfs_open_class(className); | |
devices = sysfs_get_class_devices(class); | |
dlist_for_each(devices) { | |
class_device = | |
(struct sysfs_class_device *)devices->marker->data; | |
printf("Class - Name: %s, classname: %s, path: %s\n", | |
class_device->name, class_device->classname, | |
class_device->path); | |
device = sysfs_get_classdev_device(class_device); | |
printf | |
("Device - Name: %s, bus_id: %s, bus: %s, driver_name: %s, path: %s\n\n", | |
device->name, device->bus_id, device->bus, | |
device->driver_name, device->path); | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment