Back to index

lshw  02.16
Defines | Functions
mounts.cc File Reference
#include "version.h"
#include "mounts.h"
#include "osutils.h"
#include <vector>
#include <iostream>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

Go to the source code of this file.

Defines

#define MOUNTS   "/proc/mounts"

Functions

 __ID ("@(#) $Id: mounts.cc 2433 2012-01-10 22:01:30Z lyonel $")
static bool has_device (const string &dev, hwNode &n)
static string unescape (string s)
static void update_mount_status (hwNode &n, const vector< string > &mount)
static bool process_mount (const string &s, hwNode &n)
bool scan_mounts (hwNode &n)

Define Documentation

#define MOUNTS   "/proc/mounts"

Definition at line 21 of file mounts.cc.


Function Documentation

__ID ( "@(#) $Id: mounts.cc 2433 2012-01-10 22:01:30Z lyonel $"  )
static bool has_device ( const string &  dev,
hwNode n 
) [static]

Definition at line 23 of file mounts.cc.

{
  string devid = get_devid(dev);
  vector <string> lnames;
  size_t i;

  if(devid == "")
    return false;

  if(get_devid(dev) == n.getDev())
    return true;

  lnames = n.getLogicalNames();
  for(i=0; i<lnames.size(); i++)
  {
    if(get_devid(lnames[i]) == devid)
      return true;
  }
  return false;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static bool process_mount ( const string &  s,
hwNode n 
) [static]

Definition at line 82 of file mounts.cc.

{
  vector <string> mount;
  struct stat buf;

  // entries' format is
  // devicenode mountpoint fstype mountoptions dumpfrequency pass
  if(splitlines(s, mount, ' ') != 6)
  {
    mount.clear();
    if(splitlines(s, mount, '\t') != 6)
      return false;
  }

  mount[0] = unescape(mount[0]);
  mount[1] = unescape(mount[1]);

  if(mount[0][0] != '/')    // devicenode isn't a full path
    return false;

  if(stat(mount[0].c_str(), &buf) != 0)
    return false;

  if(!S_ISBLK(buf.st_mode)) // we're only interested in block devices
    return false;

  update_mount_status(n, mount);

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool scan_mounts ( hwNode n)

Definition at line 113 of file mounts.cc.

{
  vector <string> mounts;
  size_t i;

  if(!loadfile(MOUNTS, mounts))
    return false;

  for(i=0; i<mounts.size(); i++)
    process_mount(mounts[i], n);

  return true;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static string unescape ( string  s) [static]

Definition at line 47 of file mounts.cc.

{
  size_t backslash = 0;
  string result = s;
  
  while((backslash=result.find('\\', backslash)) != string::npos)
  {
    string code = result.substr(backslash+1,3);
    if(matches(code, "^[0-9][0-9][0-9]$"))
    {
      result[backslash] = (char)strtol(code.c_str(), NULL, 8); // value is octal
      result.erase(backslash+1,3);
    }
    backslash++;
  }

  return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void update_mount_status ( hwNode n,
const vector< string > &  mount 
) [static]

Definition at line 66 of file mounts.cc.

{
  unsigned i;

  if(has_device(mount[0], n))
  {
    n.setConfig("state", "mounted");
    n.setLogicalName(mount[1]);           // mountpoint
    n.setConfig("mount.fstype", mount[2]);
    n.setConfig("mount.options", mount[3]);
  }

  for(i=0; i<n.countChildren(); i++)
    update_mount_status(*n.getChild(i), mount);
}

Here is the call graph for this function:

Here is the caller graph for this function: