Skip to content

Instantly share code, notes, and snippets.

@Makistos
Last active December 26, 2015 12:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Makistos/7153883 to your computer and use it in GitHub Desktop.
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
#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