VirtualBox

source: vbox/trunk/src/VBox/Main/src-helper-apps/VBoxVolInfo/VBoxVolInfo.cpp@ 98717

最後變更 在這個檔案從98717是 98717,由 vboxsync 提交於 2 年 前

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

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 3.4 KB
 
1/* $Id: VBoxVolInfo.cpp 98717 2023-02-24 11:04:07Z vboxsync $ */
2/** @file
3 * Apps - VBoxVolInfo, Volume information tool.
4 */
5
6/*
7 * Copyright (C) 2012-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.alldomusa.eu.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28
29
30/*********************************************************************************************************************************
31* Header Files *
32*********************************************************************************************************************************/
33#include <dirent.h>
34#include <stdio.h>
35#include <sys/types.h>
36#include <sys/stat.h>
37#include <unistd.h>
38
39#include <VBox/err.h>
40
41#include "libdevmapper.h"
42
43/*********************************************************************************************************************************
44* Internal Functions *
45*********************************************************************************************************************************/
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
71
72/*
73 * Extracts logical volume dependencies via devmapper API and print them out.
74 */
75int main(int argc, char **argv)
76{
77 struct dm_task *dmtask;
78 struct dm_info dminfo;
79
80 if (argc != 2)
81 {
82 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]);
90 return 1;
91 }
92
93 dmtask = dm_task_create(DM_DEVICE_DEPS);
94 if (!dmtask)
95 return 2;
96
97 if (dm_task_set_name(dmtask, argv[1]))
98 if (dm_task_run(dmtask))
99 if (dm_task_get_info(dmtask, &dminfo))
100 {
101 struct dm_deps *dmdeps = dm_task_get_deps(dmtask);
102 if (dmdeps)
103 {
104 unsigned i;
105 for (i = 0; i < dmdeps->count; ++i)
106 print_dev_name(dmdeps->device[i]);
107 }
108 }
109
110 dm_task_destroy(dmtask);
111 return 0;
112}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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