VirtualBox

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

Last change on this file since 106061 was 106061, checked in by vboxsync, 4 days ago

Copyright year updates by scm.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.4 KB
Line 
1/* $Id: VBoxVolInfo.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
2/** @file
3 * Apps - VBoxVolInfo, Volume information tool.
4 */
5
6/*
7 * Copyright (C) 2012-2024 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.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 <iprt/errcore.h>
40
41#include "libdevmapper.h"
42
43
44/*********************************************************************************************************************************
45* Internal Functions *
46*********************************************************************************************************************************/
47
48/*
49 * Looks up device name by id using /dev directory. Prints it to stdout.
50 */
51static void print_dev_name(dev_t devid)
52{
53 char path[PATH_MAX];
54 struct dirent *de;
55 DIR *dir = opendir("/dev");
56
57 while ((de = readdir(dir)) != NULL)
58 {
59 struct stat st;
60 snprintf(path, sizeof(path), "/dev/%s", de->d_name);
61 if (!stat(path, &st))
62 if (S_ISBLK(st.st_mode))
63 if (devid == st.st_rdev)
64 {
65 puts(de->d_name);
66 break;
67 }
68 }
69 closedir(dir);
70}
71
72
73/*
74 * Extracts logical volume dependencies via devmapper API and print them out.
75 */
76int main(int argc, char **argv)
77{
78 struct dm_task *dmtask;
79 struct dm_info dminfo;
80
81 if (argc != 2)
82 {
83 fprintf(stderr, "USAGE: %s <volume_name>\n", argv[0]);
84 return 1;
85 }
86
87 int vrc = RTDevmapperLoadLib();
88 if (RT_FAILURE(vrc))
89 {
90 fprintf(stderr, "%s: libdevmapper library not found. Service not available.\n", argv[0]);
91 return 1;
92 }
93
94 dmtask = dm_task_create(DM_DEVICE_DEPS);
95 if (!dmtask)
96 return 2;
97
98 if (dm_task_set_name(dmtask, argv[1]))
99 if (dm_task_run(dmtask))
100 if (dm_task_get_info(dmtask, &dminfo))
101 {
102 struct dm_deps *dmdeps = dm_task_get_deps(dmtask);
103 if (dmdeps)
104 {
105 unsigned i;
106 for (i = 0; i < dmdeps->count; ++i)
107 print_dev_name(dmdeps->device[i]);
108 }
109 }
110
111 dm_task_destroy(dmtask);
112 return 0;
113}
Note: See TracBrowser for help on using the repository browser.

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