~ubuntu-branches/ubuntu/gutsy/sysstat/gutsy-backports

« back to all changes in this revision

Viewing changes to ioconf.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Luberda
  • Date: 2007-05-03 11:05:07 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20070503110507-myx4tgq3em3dndbb
Tags: 7.1.4-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
#include <stdlib.h>
26
26
#include <string.h>
27
27
#include <errno.h>
 
28
#include <dirent.h>
 
29
#include <sys/stat.h>
28
30
 
29
31
#include "ioconf.h"
 
32
#include "common.h"
30
33
 
31
34
#ifdef USE_NLS
32
35
#include <locale.h>
435
438
 
436
439
  return (IS_WHOLE(major, minor));
437
440
}
 
441
 
 
442
 
 
443
/*
 
444
 ***************************************************************************
 
445
 * Transform device mapper name: Get the user assigned name of the logical
 
446
 * device instead of the internal device mapper numbering.
 
447
 ***************************************************************************
 
448
 */
 
449
char *transform_devmapname(unsigned int major, unsigned int minor)
 
450
{
 
451
   DIR *dm_dir;
 
452
   struct dirent *dp;
 
453
   char filen[MAX_NAME_LEN];
 
454
   char *dm_name = NULL;
 
455
   struct stat aux;
 
456
   unsigned int dm_major, dm_minor;
 
457
   
 
458
   if ((dm_dir = opendir(DEVMAP_DIR)) == NULL) {
 
459
      fprintf(stderr, _("Cannot open %s: %s\n"), DEVMAP_DIR, strerror(errno));
 
460
      exit(4);
 
461
   }
 
462
   
 
463
   while ((dp = readdir(dm_dir)) != NULL) {
 
464
      /* For each file in DEVMAP_DIR */
 
465
      
 
466
      snprintf(filen, MAX_FILE_LEN, "%s/%s", DEVMAP_DIR, dp->d_name);
 
467
            
 
468
      if (stat(filen, &aux) == 0) {
 
469
         /* Get its minor and major numbers */
 
470
 
 
471
         dm_major = ((aux.st_rdev >> 8) & 0xff);
 
472
         dm_minor = (aux.st_rdev & 0xff);
 
473
         
 
474
         if ((dm_minor == minor) && (dm_major == major)) {
 
475
            dm_name = dp->d_name;
 
476
            break;
 
477
         }
 
478
      }
 
479
   }
 
480
   closedir(dm_dir);
 
481
   
 
482
   return dm_name;
 
483
}