6.6. Sysfs Plugin

The sysfs plugin provides access to the devices on the i2c bus that are exposed by sysfs. This plugin uses libsysfs to access the sysfs data.

The sysfs plugin follows the standard plugin naming conventions. It is called sysfs in the OpenHPI tree and should be referenced using libsysfs in OpenHPI configuration files.

The sysfs plugin code can be tested using examples/list_resources.c and examples/set_resources.c.

6.6.1. Prerequisites

As with other plugins, the sysfs plugin needs to be enabled during the OpenHPI build process via the configure flag --enable-sysfs when running ./configure.

The sysfs plugin in OpenHPI release 0.4 and later relies on libsysfs 0.3.0 (found in sysutils 0.3.0) on the Linux Diagnostic Tools project page.

The sysfs plugin in release 0.3 relies on libsysfs 0.2.0 (found in sysutils 0.2.0) on the Linux Diagnostic Tools project page. Source code for the sysfs plugin that works with libsysfs 0.2.0 can be retrieved from OpenHPI cvs using the tag libsysfs0_2_0. libsysfs0.2.0 has two bugs that need to be fixed before using the OpenHPI sysfs plugin. Applying the two patches below (separate, sorry!) will fix these. Both issues are fixed in libsysfs 0.3.0.

Patch 1:

--- sysfsutils-0_2_0/lib/sysfs_device.c.orig    2003-10-17 11:25:37.000000000 -0
700
+++ sysfsutils-0_2_0/lib/sysfs_device.c 2003-10-20 12:41:59.000000000 -0700
@@ -80,6 +80,7 @@
                errno = EINVAL;
                return NULL;
        }
+       strcpy(attrname, name);
        dlist_for_each_data(dev->directory->attributes, cur,
        

Patch 2:

--- sysfs_dir.c.orig    2003-08-29 04:43:27.000000000 -0700
+++ sysfs_dir.c 2003-11-20 11:28:36.000000000 -0800
@@ -274,6 +274,7 @@
             errno = EINVAL;
             return -1;
        }
+       attr->value = malloc(sizeof(value));
        strncpy(attr->value,value,sizeof(value));
        if ((sysfs_write_attribute(attr) != 0 )) {
             dprintf("Error write to attribute %s\n", attrpath)
        

Follow the libsysfs instructions for installing libsysfs.

6.6.2. Configuration

Below is an example configuration stanza:

plugin libsysfs

handler libsysfs {
          name="0"
          addr="0"
          entity_root = "{ROOT,0}{SYSTEM_CHASSIS,0}"
}