Back to index

lshw  02.16
Functions
ide.h File Reference
#include "hw.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool scan_ide (hwNode &n)

Function Documentation

bool scan_ide ( hwNode n)

Definition at line 335 of file ide.cc.

{
  struct dirent **namelist;
  int nentries;

  pushd(PROC_IDE);
  nentries = scandir(".", &namelist, selectdir, alphasort);
  popd();

  if (nentries < 0)
    return false;

  for (int i = 0; i < nentries; i++)
  {
    vector < string > config;
    hwNode ide("ide",
      hw::bus);

    ide.setLogicalName(namelist[i]->d_name);
    ide.setHandle("IDE:" + string(namelist[i]->d_name));

    if (exists(string(PROC_IDE"/") + namelist[i]->d_name + "/channel"))
    {
      vector < string > identify;
      string channel = "";
      char *id = namelist[i]->d_name;

      while ((*id != 0) && (!isdigit(*id)))
        id++;
      if (*id != 0)
      {
        ide.setBusInfo("ide@" + string(id));
        ide.setPhysId(string(id));
      }

      loadfile(string(PROC_IDE"/") + namelist[i]->d_name + "/config", config);
      if (config.size() > 0)
        splitlines(config[0], identify, ' ');
      config.clear();
      loadfile(string(PROC_IDE"/") + namelist[i]->d_name + "/channel", config);
      if (config.size() > 0)
        channel = config[0];
      config.clear();

//if (identify.size() >= 1)
      {
        struct dirent **devicelist;
        int ndevices;

        pushd(string(PROC_IDE) + "/" + namelist[i]->d_name);
        ndevices = scandir(".", &devicelist, selectdir, alphasort);
        popd();

        for (int j = 0; j < ndevices; j++)
        {
          string basepath =
            string(PROC_IDE) + "/" + namelist[i]->d_name + "/" +
            devicelist[j]->d_name;
          hwNode idedevice("device",
            hw::storage);

          idedevice =
            hwNode(get_string(basepath + "/media", "disk"), hw::disk);

          idedevice.setCapacity(512 * get_longlong(basepath + "/capacity"));
          idedevice.setLogicalName(string("/dev/") + devicelist[j]->d_name);
          idedevice.setProduct(get_string(basepath + "/model"));
          idedevice.claim();
          idedevice.setHandle(ide.getHandle() + ":" +
            string(devicelist[j]->d_name));
          if (is_master(devicelist[j]->d_name))
            idedevice.setPhysId(0);
          else
            idedevice.setPhysId(1);
          idedevice.setBusInfo(ide.getBusInfo() + "." +
            idedevice.getPhysId());

          probe_ide(devicelist[j]->d_name, idedevice);

          ide.addChild(idedevice);
          free(devicelist[j]);
        }
        free(devicelist);

        ide.setDescription(hw::strip("IDE Channel " + hw::strip(channel)));

        if ( identify.size() == 11 && identify[0] == "pci")
        {
          string businfo = guessBusInfo(get_pciid(identify[2], identify[4]));
          hwNode *parent = n.findChildByBusInfo(businfo);

          if (parent)
          {
            parent->claim();
            ide.setClock(parent->getClock());
            parent->addChild(ide);
          }
        }
        else                                      // we have to guess the parent device
        {
          hwNode * parent = guessParent(ide, n);
          if(parent)
          {
            parent->claim();
            ide.setClock(parent->getClock());
            parent->addChild(ide);
          }
          else
            for (unsigned int k = 0; k < ide.countChildren(); k++)
          {
            hwNode *candidate =
              n.findChildByLogicalName(ide.getChild(k)->getLogicalName());

            if (candidate)
            {
              parent = candidate;
              candidate->merge(*ide.getChild(k));
              break;
            }
          }
          if(!parent) n.addChild(ide);
        }
      }

    }

    free(namelist[i]);
  }
  free(namelist);

  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function: