MCPcopy Create free account
hub / github.com/Icinga/icinga2 / check_drives

Function check_drives

plugins/check_disk.cpp:42–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

40static bool l_Debug;
41
42static int check_drives(std::vector<drive>& vDrives, std::vector<std::wstring>& vExclude_Drives)
43{
44 DWORD dwResult, dwSize = 0, dwVolumePathNamesLen = MAX_PATH + 1;
45 WCHAR szLogicalDrives[1024], szVolumeName[MAX_PATH], *szVolumePathNames = NULL;
46 HANDLE hVolume = NULL;
47 std::wstring wsLogicalDrives;
48 size_t volumeNameEnd = 0;
49
50 std::set<std::wstring> sDrives;
51
52 if (l_Debug)
53 std::wcout << "Getting logic drive string (includes network drives)\n";
54
55 dwResult = GetLogicalDriveStrings(MAX_PATH, szLogicalDrives);
56 if (dwResult > MAX_PATH)
57 goto die;
58 if (l_Debug)
59 std::wcout << "Splitting string into single drive names\n";
60
61 LPTSTR szSingleDrive = szLogicalDrives;
62 while (*szSingleDrive) {
63 std::wstring drname = szSingleDrive;
64 sDrives.insert(drname);
65 szSingleDrive += wcslen(szSingleDrive) + 1;
66 if (l_Debug)
67 std::wcout << "Got: " << drname << '\n';
68 }
69
70 if (l_Debug)
71 std::wcout << "Getting volume mountpoints (includes NTFS folders)\n"
72 << "Getting first volume\n";
73
74 hVolume = FindFirstVolume(szVolumeName, MAX_PATH);
75 if (hVolume == INVALID_HANDLE_VALUE)
76 goto die;
77
78 if (l_Debug)
79 std::wcout << "Traversing through list of drives\n";
80
81 while (GetLastError() != ERROR_NO_MORE_FILES) {
82 if (l_Debug)
83 std::wcout << "Path name for " << szVolumeName << "= \"";
84 volumeNameEnd = wcslen(szVolumeName) - 1;
85 szVolumePathNames = new WCHAR[dwVolumePathNamesLen];
86
87 while (!GetVolumePathNamesForVolumeName(szVolumeName, szVolumePathNames, dwVolumePathNamesLen,
88 &dwVolumePathNamesLen)) {
89 if (GetLastError() != ERROR_MORE_DATA)
90 break;
91 delete[] szVolumePathNames;
92 szVolumePathNames = new WCHAR[dwVolumePathNamesLen];
93
94 }
95 if (l_Debug)
96 std::wcout << szVolumePathNames << "\"\n";
97
98 sDrives.insert(std::wstring(szVolumePathNames));
99 FindNextVolume(hVolume, szVolumeName, MAX_PATH);

Callers 1

wmainFunction · 0.85

Calls 8

driveClass · 0.85
printErrorInfoFunction · 0.85
push_backMethod · 0.80
findMethod · 0.80
insertMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected