VirtualBox

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

Last change on this file since 48669 was 48669, checked in by vboxsync, 12 years ago

move VBoxVolInfo to the correct place and export it

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

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