Example #1
0
/**
 * This function validates whether given object is valid for filesystem
 * informations statistics and stores path suitable for it in given
 * filesystem information structure for later use. Filesystem must be mounted.
 *
 * Valid objects are file or directory that are part of requested
 * filesystem, block special device or mountpoint.
 *
 * In the case of file, directory or mountpoint the result is original
 * object, in the case of block special device mountpoint is returned.
 *
 * @param inf     Information structure where resulting data will be stored
 * @param object  Identifies appropriate device object
 * @return        NULL in the case of failure otherwise filesystem path
 */
char *device_path(Info_T inf, char *object) {

  struct stat buf;

  ASSERT(inf);
  ASSERT(object);

  if(stat(object, &buf) != 0) {
    LogError("%s: Cannot stat '%s' -- %s\n", prog, object, STRERROR);
    return NULL;
  }

  if(S_ISREG(buf.st_mode) || S_ISDIR(buf.st_mode)) {

    inf->mntpath[sizeof(inf->mntpath) - 1] = 0;
    return strncpy(inf->mntpath, object, sizeof(inf->mntpath) - 1);

  } else if(S_ISBLK(buf.st_mode)) {

    return device_mountpoint_sysdep(inf, object);

  }

  LogError("%s: Not file, directory or block special device: '%s'",
    prog, object);

  return NULL;

}
/**
 * This function validates whether given object is valid for filesystem
 * informations statistics and stores path suitable for it in given
 * filesystem information structure for later use. Filesystem must be mounted.
 *
 * Valid objects are file or directory that are part of requested
 * filesystem, device or mountpoint.
 *
 * In the case of file, directory or mountpoint the result is original
 * object, in the case of device the mountpoint is returned.
 *
 * @param inf     Information structure where resulting data will be stored
 * @param object  Identifies appropriate device object
 * @return        NULL in the case of failure otherwise filesystem path
 */
char *device_path(Info_T inf, char *object) {
  struct stat buf;

  ASSERT(inf);
  ASSERT(object);

  if(stat(object, &buf) != 0) {
    LogError("Cannot stat '%s' -- %s\n", object, STRERROR);
    return NULL;
  }

  if(S_ISREG(buf.st_mode) || S_ISDIR(buf.st_mode)) {
    inf->priv.filesystem.mntpath = Str_dup(object);
    return inf->priv.filesystem.mntpath;
  } else if(S_ISBLK(buf.st_mode) || S_ISCHR(buf.st_mode)) {
    return device_mountpoint_sysdep(inf, object);
  }

  LogError("Not file, directory or device: '%s'", object);

  return NULL;
}