VirtualBox

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

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

OSE build fix.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 2.7 KB
Line 
1/* $Id: VBoxVolInfo.cpp 48672 2013-09-25 08:07:39Z 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>
24extern "C"
25{
26#define private privatekw
27#include <libdevmapper.h>
28}
29#include <stdio.h>
30#include <sys/types.h>
31#include <sys/stat.h>
32#include <unistd.h>
33
34/*******************************************************************************
35* Function Prototypes *
36*******************************************************************************/
37void print_dev_name(dev_t devid);
38
39/*
40 * Extracts logical volume dependencies via devmapper API and print them out.
41 */
42int main(int argc, char **argv)
43{
44 struct dm_task *dmtask;
45 struct dm_info dminfo;
46
47 if (argc != 2)
48 {
49 fprintf(stderr, "USAGE: %s <volume_name>\n", argv[0]);
50 return 1;
51 }
52
53 dmtask = dm_task_create(DM_DEVICE_DEPS);
54 if (!dmtask)
55 return 2;
56
57 if (dm_task_set_name(dmtask, argv[1]))
58 if (dm_task_run(dmtask))
59 if (dm_task_get_info(dmtask, &dminfo))
60 {
61 struct dm_deps *dmdeps = dm_task_get_deps(dmtask);
62 if (dmdeps)
63 {
64 unsigned i;
65 for (i = 0; i < dmdeps->count; ++i)
66 print_dev_name(dmdeps->device[i]);
67 }
68 }
69
70 dm_task_destroy(dmtask);
71 return 0;
72}
73
74/*
75 * Looks up device name by id using /dev directory. Prints it to stdout.
76 */
77void print_dev_name(dev_t devid)
78{
79 char path[PATH_MAX];
80 struct dirent *de;
81 DIR *dir = opendir("/dev");
82
83 while ((de = readdir(dir)) != NULL)
84 {
85 struct stat st;
86 snprintf(path, sizeof(path), "/dev/%s", de->d_name);
87 if (!stat(path, &st))
88 if (S_ISBLK(st.st_mode))
89 if (devid == st.st_rdev)
90 {
91 puts(de->d_name);
92 break;
93 }
94 }
95 closedir(dir);
96}
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