Changeset 98717 in vbox for trunk/src/VBox/Main/src-helper-apps
- Timestamp:
- Feb 24, 2023 11:04:07 AM (2 years ago)
- Location:
- trunk/src/VBox/Main/src-helper-apps/VBoxVolInfo
- Files:
-
- 5 added
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-helper-apps/VBoxVolInfo/VBoxVolInfo.cpp
r98716 r98717 32 32 *********************************************************************************************************************************/ 33 33 #include <dirent.h> 34 extern "C"35 {36 #define private privatekw37 #include <libdevmapper.h>38 }39 34 #include <stdio.h> 40 35 #include <sys/types.h> … … 42 37 #include <unistd.h> 43 38 39 #include <VBox/err.h> 40 41 #include "libdevmapper.h" 44 42 45 43 /********************************************************************************************************************************* 46 * Function Prototypes*44 * Internal Functions * 47 45 *********************************************************************************************************************************/ 48 void print_dev_name(dev_t devid); 46 47 /* 48 * Looks up device name by id using /dev directory. Prints it to stdout. 49 */ 50 static 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 49 71 50 72 /* … … 59 81 { 60 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]); 61 90 return 1; 62 91 } … … 82 111 return 0; 83 112 } 84 85 /*86 * Looks up device name by id using /dev directory. Prints it to stdout.87 */88 void print_dev_name(dev_t devid)89 {90 char path[PATH_MAX];91 struct dirent *de;92 DIR *dir = opendir("/dev");93 94 while ((de = readdir(dir)) != NULL)95 {96 struct stat st;97 snprintf(path, sizeof(path), "/dev/%s", de->d_name);98 if (!stat(path, &st))99 if (S_ISBLK(st.st_mode))100 if (devid == st.st_rdev)101 {102 puts(de->d_name);103 break;104 }105 }106 closedir(dir);107 }
Note:
See TracChangeset
for help on using the changeset viewer.