VirtualBox

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

Last change on this file since 48671 was 48671, checked in by vboxsync, 11 years ago

C++ kludge

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.6 KB
Line 
1/* $Id: VBoxVolInfo.cpp 48671 2013-09-25 07:56:57Z vboxsync $ */
2/** @file
3 * Apps - VBoxVolInfo, Volume information tool.
4 */
5
6/*
7 * Copyright (C) 2012 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 */
17
18
19
20/*******************************************************************************
21* Header Files *
22*******************************************************************************/
23#include <dirent.h>
24#define private privatekw
25#include <libdevmapper.h>
26#include <stdio.h>
27#include <sys/types.h>
28#include <sys/stat.h>
29#include <unistd.h>
30
31/*******************************************************************************
32* Function Prototypes *
33*******************************************************************************/
34void print_dev_name(dev_t devid);
35
36/*
37 * Extracts logical volume dependencies via devmapper API and print them out.
38 */
39int main(int argc, char **argv)
40{
41 struct dm_task *dmtask;
42 struct dm_info dminfo;
43
44 if (argc != 2)
45 {
46 fprintf(stderr, "USAGE: %s <volume_name>\n", argv[0]);
47 return 1;
48 }
49
50 dmtask = dm_task_create(DM_DEVICE_DEPS);
51 if (!dmtask)
52 return 2;
53
54 if (dm_task_set_name(dmtask, argv[1]))
55 if (dm_task_run(dmtask))
56 if (dm_task_get_info(dmtask, &dminfo))
57 {
58 struct dm_deps *dmdeps = dm_task_get_deps(dmtask);
59 if (dmdeps)
60 {
61 unsigned i;
62 for (i = 0; i < dmdeps->count; ++i)
63 print_dev_name(dmdeps->device[i]);
64 }
65 }
66
67 dm_task_destroy(dmtask);
68 return 0;
69}
70
71/*
72 * Looks up device name by id using /dev directory. Prints it to stdout.
73 */
74void print_dev_name(dev_t devid)
75{
76 char path[PATH_MAX];
77 struct dirent *de;
78 DIR *dir = opendir("/dev");
79
80 while ((de = readdir(dir)) != NULL)
81 {
82 struct stat st;
83 snprintf(path, sizeof(path), "/dev/%s", de->d_name);
84 if (!stat(path, &st))
85 if (S_ISBLK(st.st_mode))
86 if (devid == st.st_rdev)
87 {
88 puts(de->d_name);
89 break;
90 }
91 }
92 closedir(dir);
93}
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