VirtualBox

Ignore:
Timestamp:
Feb 24, 2023 11:04:07 AM (2 years ago)
Author:
vboxsync
Message:

Main/VBoxVolInfo: Don't link directly against libdevmapper but use the IPRT runtime loader to get rid of the buildtime dependency, bugref:10367

Location:
trunk/src/VBox/Main/src-helper-apps/VBoxVolInfo
Files:
5 added
1 moved

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-helper-apps/VBoxVolInfo/VBoxVolInfo.cpp

    r98716 r98717  
    3232*********************************************************************************************************************************/
    3333#include <dirent.h>
    34 extern "C"
    35 {
    36 #define private privatekw
    37 #include <libdevmapper.h>
    38 }
    3934#include <stdio.h>
    4035#include <sys/types.h>
     
    4237#include <unistd.h>
    4338
     39#include <VBox/err.h>
     40
     41#include "libdevmapper.h"
    4442
    4543/*********************************************************************************************************************************
    46 *   Function Prototypes                                                                                                          *
     44*   Internal Functions                                                                                                           *
    4745*********************************************************************************************************************************/
    48 void print_dev_name(dev_t devid);
     46
     47/*
     48 * Looks up device name by id using /dev directory. Prints it to stdout.
     49 */
     50static void print_dev_name(dev_t devid)
     51{
     52    char path[PATH_MAX];
     53    struct dirent *de;
     54    DIR *dir = opendir("/dev");
     55
     56    while ((de = readdir(dir)) != NULL)
     57    {
     58        struct stat st;
     59        snprintf(path, sizeof(path), "/dev/%s", de->d_name);
     60        if (!stat(path, &st))
     61            if (S_ISBLK(st.st_mode))
     62                if (devid == st.st_rdev)
     63                {
     64                    puts(de->d_name);
     65                    break;
     66                }
     67    }
     68    closedir(dir);
     69}
     70
    4971
    5072/*
     
    5981    {
    6082        fprintf(stderr, "USAGE: %s <volume_name>\n", argv[0]);
     83        return 1;
     84    }
     85
     86    int vrc = RTDevmapperLoadLib();
     87    if (RT_FAILURE(vrc))
     88    {
     89        fprintf(stderr, "%s: libdevmapper library not found.  Service not available.\n", argv[0]);
    6190        return 1;
    6291    }
     
    82111    return 0;
    83112}
    84 
    85 /*
    86  * Looks up device name by id using /dev directory. Prints it to stdout.
    87  */
    88 void print_dev_name(dev_t devid)
    89 {
    90     char path[PATH_MAX];
    91     struct dirent *de;
    92     DIR *dir = opendir("/dev");
    93 
    94     while ((de = readdir(dir)) != NULL)
    95     {
    96         struct stat st;
    97         snprintf(path, sizeof(path), "/dev/%s", de->d_name);
    98         if (!stat(path, &st))
    99             if (S_ISBLK(st.st_mode))
    100                 if (devid == st.st_rdev)
    101                 {
    102                     puts(de->d_name);
    103                     break;
    104                 }
    105     }
    106     closedir(dir);
    107 }
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette