Return to Snippet

Revision: 65113
at October 25, 2013 19:08 by Makistos

Initial Code
#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,

                device = sysfs_get_classdev_device(class_device);

                    ("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);



Initial URL

Initial Description
This code will print out all sysfs devices under a certain device class (which is supplied as a parameter).

Initial Title
Reading sysfs devices in Linux

Initial Tags

Initial Language