Back to index

lshw  02.16
Classes | Functions | Variables
sysfs.cc File Reference
#include "version.h"
#include "sysfs.h"
#include "osutils.h"
#include <limits.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <dirent.h>
#include <libgen.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>

Go to the source code of this file.

Classes

struct  sysfs::entry_i
struct  sysfs_t

Functions

 __ID ("@(#) $Id: sysfs.cc 2433 2012-01-10 22:01:30Z lyonel $")
static string sysfs_getbustype (const string &path)
static string sysfstopci (const string &path)
static string sysfstoide (const string &path)
static string sysfstobusinfo (const string &path)
static string sysfs_getbusinfo_byclass (const string &devclass, const string &devname)
static string sysfs_getbusinfo_bybus (const string &devbus, const string &devname)
string sysfs_getbusinfo (const entry &e)
static string finddevice (const string &name, const string &root="")
string sysfs_finddevice (const string &name)
string sysfs_getdriver (const string &devclass, const string &devname)
bool scan_sysfs (hwNode &n)

Variables

static sysfs_t fs

Class Documentation

struct sysfs::entry_i

Definition at line 25 of file sysfs.cc.

Collaboration diagram for sysfs::entry_i:
Class Members
string devbus
string devclass
string devname

Function Documentation

__ID ( "@(#) $Id: sysfs.cc 2433 2012-01-10 22:01:30Z lyonel $"  )
static string finddevice ( const string &  name,
const string &  root = "" 
) [static]

Definition at line 189 of file sysfs.cc.

{
  struct dirent **namelist;
  int n;
  string result = "";

  if(exists(name))
    return root + "/" + name;

  n = scandir(".", &namelist, selectdir, alphasort);

  for (int i = 0; i < n; i++)
  {
    pushd(namelist[i]->d_name);
    string findinchild = finddevice(name, root + "/" + string(namelist[i]->d_name));
    popd();

    free(namelist[i]);
    if(findinchild != "")
    {
      result = findinchild;
    }
  }
  free(namelist);

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool scan_sysfs ( hwNode n)

Definition at line 308 of file sysfs.cc.

{
  return false;
}

Here is the caller graph for this function:

string sysfs_finddevice ( const string &  name)

Definition at line 218 of file sysfs.cc.

{
  string devices = fs.path + string("/devices/");
  string result = "";

  if(!pushd(devices))
    return "";
  result = finddevice(name);
  popd();

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

string sysfs_getbusinfo ( const entry e)

Definition at line 179 of file sysfs.cc.

{
  if(e.This->devclass != "")
    return sysfs_getbusinfo_byclass(e.This->devclass, e.This->devname);
  if(e.This->devbus != "")
    return sysfs_getbusinfo_bybus(e.This->devbus, e.This->devname);
  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string sysfs_getbusinfo_bybus ( const string &  devbus,
const string &  devname 
) [static]

Definition at line 166 of file sysfs.cc.

{
  string device =
    fs.path + string("/bus/") + devbus + string("/devices/") + devname;
  char buffer[PATH_MAX + 1];

  if (!realpath(device.c_str(), buffer))
    return "";

  return sysfstobusinfo(hw::strip(buffer));
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string sysfs_getbusinfo_byclass ( const string &  devclass,
const string &  devname 
) [static]

Definition at line 147 of file sysfs.cc.

{
  string device =
    fs.path + string("/class/") + devclass + string("/") + devname + "/device";
  string result = "";
  int i = 0;

  while((result == "") && (i<2))                  // device may point to /businfo or /businfo/devname
  {
    if(!exists(device)) return "";
    result = sysfstobusinfo(realpath(device));
    device += "/../" + devname + "/..";
    i++;
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string sysfs_getbustype ( const string &  path) [static]

Definition at line 84 of file sysfs.cc.

{
  struct dirent **namelist;
  int i, n;
  string devname;

/*
  to determine to which kind of bus a device is connected:
  - for each subdirectory of /sys/bus,
  - look in ./devices/ for a link with the same basename as 'path'
  - check if this link and 'path' point to the same inode
  - if they do, the bus type is the name of the current directory
 */
  pushd(fs.path + "/bus");
  n = scandir(".", &namelist, selectdir, alphasort);
  popd();

  for (i = 0; i < n; i++)
  {
    devname =
      string(fs.path + "/bus/") + string(namelist[i]->d_name) +
      "/devices/" + basename((char *) path.c_str());

    if (samefile(devname, path))
      return string(namelist[i]->d_name);
  }

  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

string sysfs_getdriver ( const string &  devclass,
const string &  devname 
)

Definition at line 232 of file sysfs.cc.

{
  string driverpath =
    fs.path + string("/class/") + devclass + string("/") + devname + "/";
  string driver = driverpath + "/driver";
  char buffer[PATH_MAX + 1];
  int namelen = 0;

  if ((namelen = readlink(driver.c_str(), buffer, sizeof(buffer))) < 0)
    return "";

  return string(basename(buffer));
}

Here is the call graph for this function:

static string sysfstobusinfo ( const string &  path) [static]

Definition at line 133 of file sysfs.cc.

{
  string bustype = sysfs_getbustype(path);

  if (bustype == "pci")
    return sysfstopci(path);

  if (bustype == "ide")
    return sysfstoide(path);

  return "";
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string sysfstoide ( const string &  path) [static]

Definition at line 124 of file sysfs.cc.

{
  if (path.substr(0, 3) == "ide")
    return "ide@" + path.substr(path.length() - 3);
  else
    return "ide@" + path;
}

Here is the caller graph for this function:

static string sysfstopci ( const string &  path) [static]

Definition at line 115 of file sysfs.cc.

{
  if (path.length() > strlen("XXXX:XX:XX.X"))
    return "pci@" + path.substr(path.length() - strlen("XXXX:XX:XX.X"));
  else
    return "";
}

Here is the caller graph for this function:


Variable Documentation

sysfs_t fs [static]

Definition at line 82 of file sysfs.cc.