ReactOS 0.4.16-dev-329-g9223134
devices.cpp File Reference
#include "shellext.h"
#include "devices.h"
#include "resource.h"
#include "balance.h"
#include <stddef.h>
#include <uxtheme.h>
#include <setupapi.h>
#include <strsafe.h>
#include <mountmgr.h>
#include <algorithm>
#include "../btrfs.h"
Include dependency graph for devices.cpp:

Go to the source code of this file.

Macros

#define ISOLATION_AWARE_ENABLED   1
 
#define STRSAFE_NO_DEPRECATE
 

Functions

 DEFINE_GUID (GUID_DEVINTERFACE_HIDDEN_VOLUME, 0x7f108a28L, 0x9833, 0x4b3b, 0xb7, 0x80, 0x2c, 0x6b, 0x5f, 0xa5, 0xc0, 0x62)
 
static wstring get_mountdev_name (const nt_handle &h)
 
static void find_devices (HWND hwnd, const GUID *guid, const mountmgr &mm, vector< device > &device_list)
 
static bool sort_devices (device i, device j)
 
static INT_PTR CALLBACK stub_DeviceAddDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static INT_PTR CALLBACK stub_DeviceResizeDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void CALLBACK AddDeviceW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 
void CALLBACK RemoveDeviceW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 
void CALLBACK ResizeDeviceW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 

Macro Definition Documentation

◆ ISOLATION_AWARE_ENABLED

#define ISOLATION_AWARE_ENABLED   1

Definition at line 18 of file devices.cpp.

◆ STRSAFE_NO_DEPRECATE

#define STRSAFE_NO_DEPRECATE

Definition at line 19 of file devices.cpp.

Function Documentation

◆ AddDeviceW()

void CALLBACK AddDeviceW ( HWND  hwnd,
HINSTANCE  hinst,
LPWSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 849 of file devices.cpp.

849 {
850 try {
853 LUID luid;
854
856
858 throw last_error(GetLastError());
859
860 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
861 throw last_error(GetLastError());
862
863 tp.PrivilegeCount = 1;
864 tp.Privileges[0].Luid = luid;
865 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
866
867 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
868 throw last_error(GetLastError());
869
870 BtrfsDeviceAdd bda(hinst, hwnd, lpszCmdLine);
871 bda.ShowDialog();
872 } catch (const exception& e) {
873 error_message(hwnd, e.what());
874 }
875}
void set_dpi_aware()
Definition: main.cpp:50
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define e
Definition: ke_i.h:82
static HINSTANCE hinst
Definition: edit.c:551
#define L(x)
Definition: ntvdm.h:50
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_QUERY
Definition: setypes.h:928
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

◆ DEFINE_GUID()

DEFINE_GUID ( GUID_DEVINTERFACE_HIDDEN_VOLUME  ,
0x7f108a28L  ,
0x9833  ,
0x4b3b  ,
0xb7  ,
0x80  ,
0x2c  ,
0x6b  ,
0x5f  ,
0xa5  ,
0xc0  ,
0x62   
)

◆ find_devices()

static void find_devices ( HWND  hwnd,
const GUID guid,
const mountmgr mm,
vector< device > &  device_list 
)
static

Definition at line 73 of file devices.cpp.

73 {
74 HDEVINFO h;
75
76 static const wstring dosdevices = L"\\DosDevices\\";
77
79
80 if (h != INVALID_HANDLE_VALUE) {
81 DWORD index = 0;
83
84 did.cbSize = sizeof(did);
85
86 if (!SetupDiEnumDeviceInterfaces(h, nullptr, guid, index, &did))
87 return;
88
89 do {
92 DWORD size;
93
94 dd.cbSize = sizeof(dd);
95
96 SetupDiGetDeviceInterfaceDetailW(h, &did, nullptr, 0, &size, nullptr);
97
99 memset(detail, 0, size);
100
102
103 if (SetupDiGetDeviceInterfaceDetailW(h, &did, detail, size, &size, &dd)) {
106 device dev;
112 ULONG i;
113 uint8_t sb[4096];
114
115 path.Buffer = detail->DevicePath;
116 path.Length = path.MaximumLength = (uint16_t)(wcslen(detail->DevicePath) * sizeof(WCHAR));
117
118 if (path.Length > 4 * sizeof(WCHAR) && path.Buffer[0] == '\\' && path.Buffer[1] == '\\' && path.Buffer[2] == '?' && path.Buffer[3] == '\\')
119 path.Buffer[1] = '?';
120
121 InitializeObjectAttributes(&attr, &path, 0, nullptr, nullptr);
122
124
125 if (!NT_SUCCESS(Status)) {
126 free(detail);
127 index++;
128 continue;
129 }
130
131 dev.pnp_name = detail->DevicePath;
132
133 Status = NtDeviceIoControlFile(file, nullptr, nullptr, nullptr, &iosb, IOCTL_DISK_GET_LENGTH_INFO, nullptr, 0, &gli, sizeof(GET_LENGTH_INFORMATION));
134 if (!NT_SUCCESS(Status)) {
135 free(detail);
136 index++;
137 continue;
138 }
139
140 dev.size = gli.Length.QuadPart;
141
142 Status = NtDeviceIoControlFile(file, nullptr, nullptr, nullptr, &iosb, IOCTL_STORAGE_GET_DEVICE_NUMBER, nullptr, 0, &sdn, sizeof(STORAGE_DEVICE_NUMBER));
143 if (!NT_SUCCESS(Status)) {
144 dev.disk_num = 0xffffffff;
145 dev.part_num = 0xffffffff;
146 } else {
147 dev.disk_num = sdn.DeviceNumber;
148 dev.part_num = sdn.PartitionNumber;
149 }
150
151 dev.friendly_name = L"";
152 dev.drive = L"";
153 dev.fstype = L"";
154 dev.has_parts = false;
155 dev.ignore = false;
156 dev.multi_device = false;
157
158 dev.is_disk = RtlCompareMemory(guid, &GUID_DEVINTERFACE_DISK, sizeof(GUID)) == sizeof(GUID);
159
160 if (dev.is_disk) {
162 STORAGE_DEVICE_DESCRIPTOR sdd, *sdd2;
163 ULONG dlisize;
164 DRIVE_LAYOUT_INFORMATION_EX* dli;
165
168 spq.AdditionalParameters[0] = 0;
169
170 Status = NtDeviceIoControlFile(file, nullptr, nullptr, nullptr, &iosb, IOCTL_STORAGE_QUERY_PROPERTY,
171 &spq, sizeof(STORAGE_PROPERTY_QUERY), &sdd, sizeof(STORAGE_DEVICE_DESCRIPTOR));
172
174 sdd2 = (STORAGE_DEVICE_DESCRIPTOR*)malloc(sdd.Size);
175
176 Status = NtDeviceIoControlFile(file, nullptr, nullptr, nullptr, &iosb, IOCTL_STORAGE_QUERY_PROPERTY,
177 &spq, sizeof(STORAGE_PROPERTY_QUERY), sdd2, sdd.Size);
178 if (NT_SUCCESS(Status)) {
179 string desc2;
180
181 desc2 = "";
182
183 if (sdd2->VendorIdOffset != 0) {
184 desc2 += (char*)((uint8_t*)sdd2 + sdd2->VendorIdOffset);
185
186 while (desc2.length() > 0 && desc2[desc2.length() - 1] == ' ')
187 desc2 = desc2.substr(0, desc2.length() - 1);
188 }
189
190 if (sdd2->ProductIdOffset != 0) {
191 if (sdd2->VendorIdOffset != 0 && desc2.length() != 0 && desc2[desc2.length() - 1] != ' ')
192 desc2 += " ";
193
194 desc2 += (char*)((uint8_t*)sdd2 + sdd2->ProductIdOffset);
195
196 while (desc2.length() > 0 && desc2[desc2.length() - 1] == ' ')
197 desc2 = desc2.substr(0, desc2.length() - 1);
198 }
199
200 if (sdd2->VendorIdOffset != 0 || sdd2->ProductIdOffset != 0) {
201 ULONG ss;
202
203 ss = MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, desc2.c_str(), -1, nullptr, 0);
204
205 if (ss > 0) {
206 WCHAR* desc3 = (WCHAR*)malloc(ss * sizeof(WCHAR));
207
208 if (MultiByteToWideChar(CP_OEMCP, MB_PRECOMPOSED, desc2.c_str(), -1, desc3, ss))
209 dev.friendly_name = desc3;
210
211 free(desc3);
212 }
213 }
214 }
215
216 free(sdd2);
217 }
218
219 dlisize = 0;
220 dli = nullptr;
221
222 do {
223 dlisize += 1024;
224
225 if (dli)
226 free(dli);
227
228 dli = (DRIVE_LAYOUT_INFORMATION_EX*)malloc(dlisize);
229
231 nullptr, 0, dli, dlisize);
232 } while (Status == STATUS_BUFFER_TOO_SMALL);
233
234 if (NT_SUCCESS(Status) && dli->PartitionCount > 0)
235 dev.has_parts = true;
236
237 free(dli);
238 } else {
239 try {
240 auto v = mm.query_points(L"", L"", wstring_view(path.Buffer, path.Length / sizeof(WCHAR)));
241
242#ifndef __REACTOS__
243 for (const auto& p : v) {
244 if (p.symlink.length() == 14 && p.symlink.substr(0, dosdevices.length()) == dosdevices && p.symlink[13] == ':') {
245#else
246 for(auto p = v.begin(); p != v.end(); ++p) {
247 if ((*p).symlink.length() == 14 && (*p).symlink.substr(0, dosdevices.length()) == dosdevices && (*p).symlink[13] == ':') {
248#endif
249 WCHAR dr[3];
250
251#ifndef __REACTOS__
252 dr[0] = p.symlink[12];
253#else
254 dr[0] = (*p).symlink[12];
255#endif
256 dr[1] = ':';
257 dr[2] = 0;
258
259 dev.drive = dr;
260 break;
261 }
262 }
263 } catch (...) { // don't fail entirely if mountmgr refuses to co-operate
264 }
265 }
266
267 if (!dev.is_disk || !dev.has_parts) {
268 i = 0;
269 while (fs_ident[i].name) {
270 if (i == 0 || fs_ident[i].kboff != fs_ident[i-1].kboff) {
271 LARGE_INTEGER off;
272
273 off.QuadPart = fs_ident[i].kboff * 1024;
274 Status = NtReadFile(file, nullptr, nullptr, nullptr, &iosb, sb, sizeof(sb), &off, nullptr);
275 }
276
277 if (NT_SUCCESS(Status)) {
278 if (RtlCompareMemory(sb + fs_ident[i].sboff, fs_ident[i].magic, fs_ident[i].magiclen) == fs_ident[i].magiclen) {
279 dev.fstype = fs_ident[i].name;
280
281 if (dev.fstype == L"Btrfs") {
282 superblock* bsb = (superblock*)sb;
283
284 RtlCopyMemory(&dev.fs_uuid, &bsb->uuid, sizeof(BTRFS_UUID));
285 RtlCopyMemory(&dev.dev_uuid, &bsb->dev_item.device_uuid, sizeof(BTRFS_UUID));
286 }
287
288 break;
289 }
290 }
291
292 i++;
293 }
294
295 if (dev.fstype == L"Btrfs" && RtlCompareMemory(guid, &GUID_DEVINTERFACE_DISK, sizeof(GUID)) != sizeof(GUID)) {
296 wstring name;
297 wstring pref = L"\\Device\\Btrfs{";
298
300
301 if (name.length() > pref.length() && RtlCompareMemory(name.c_str(), pref.c_str(), pref.length() * sizeof(WCHAR)) == pref.length() * sizeof(WCHAR))
302 dev.ignore = true;
303 }
304 }
305
306 device_list.push_back(dev);
307 }
308
309 free(detail);
310
311 index++;
312 } while (SetupDiEnumDeviceInterfaces(h, nullptr, guid, index, &did));
313
315 } else
316 throw last_error(GetLastError());
317}
LONG NTSTATUS
Definition: precomp.h:26
_Self substr(size_type __pos=0, size_type __n=npos) const
Definition: _string.h:1022
const _CharT * c_str() const
Definition: _string.h:949
size_type length() const
Definition: _string.h:401
std::vector< mountmgr_point > query_points(const std::wstring_view &symlink=L"", const std::wstring_view &unique_id=L"", const std::wstring_view &device_name=L"") const
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
static wstring get_mountdev_name(const nt_handle &h)
Definition: devices.cpp:44
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
static const fs_identifier fs_ident[]
Definition: devices.h:64
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define MultiByteToWideChar
Definition: compat.h:110
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2780
HDEVINFO WINAPI SetupDiGetClassDevsW(CONST GUID *class, LPCWSTR enumstr, HWND parent, DWORD flags)
Definition: devinst.c:2292
BOOL WINAPI SetupDiGetDeviceInterfaceDetailW(HDEVINFO DeviceInfoSet, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData, PSP_DEVICE_INTERFACE_DETAIL_DATA_W DeviceInterfaceDetailData, DWORD DeviceInterfaceDetailDataSize, PDWORD RequiredSize, PSP_DEVINFO_DATA DeviceInfoData)
Definition: devinst.c:3011
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2893
superblock * sb
Definition: btrfs.c:4261
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
unsigned long DWORD
Definition: ntddk_ex.h:95
#define IOCTL_DISK_GET_DRIVE_LAYOUT_EX
Definition: ntddk_ex.h:207
#define FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
Status
Definition: gdiplustypes.h:25
const GLdouble * v
Definition: gl.h:2040
GLsizeiptr size
Definition: glext.h:5919
GLuint index
Definition: glext.h:6031
GLfloat GLfloat p
Definition: glext.h:8902
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define ss
Definition: i386-dis.c:441
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
const GUID * guid
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
BYTE uint8_t
Definition: msvideo1.c:66
#define uint16_t
Definition: nsiface.idl:60
NTSYSAPI NTSTATUS NTAPI NtOpenFile(OUT PHANDLE phFile, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG ShareMode, IN ULONG OpenMode)
Definition: file.c:3952
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
NTSYSAPI NTSTATUS NTAPI NtDeviceIoControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_GENERIC_READ
Definition: nt_native.h:653
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:178
#define IOCTL_STORAGE_GET_DEVICE_NUMBER
Definition: ntddstor.h:143
@ StorageDeviceProperty
Definition: ntddstor.h:512
STORAGE_DEVICE_DESCRIPTOR
Definition: ntddstor.h:576
@ PropertyStandardQuery
Definition: ntddstor.h:505
#define memset(x, y, z)
Definition: compat.h:39
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
#define DIGCF_PRESENT
Definition: setupapi.h:171
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
NTSTATUS NTAPI NtReadFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, PVOID Buffer, ULONG Length, PLARGE_INTEGER ByteOffset, PULONG Key)
BTRFS_UUID device_uuid
Definition: btrfs.h:190
LARGE_INTEGER Length
Definition: imports.h:232
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:855
STORAGE_QUERY_TYPE QueryType
Definition: ntddstor.h:553
UCHAR AdditionalParameters[1]
Definition: ntddstor.h:554
STORAGE_PROPERTY_ID PropertyId
Definition: ntddstor.h:552
Definition: cookie.c:202
uint64_t size
Definition: devices.h:37
Definition: fci.c:127
uint32_t kboff
Definition: devices.h:58
const WCHAR * name
Definition: devices.h:54
Definition: name.c:39
BTRFS_UUID uuid
Definition: btrfs.h:225
DEV_ITEM dev_item
Definition: btrfs.h:251
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
LONGLONG QuadPart
Definition: typedefs.h:114
#define CP_OEMCP
Definition: winnls.h:233
#define MB_PRECOMPOSED
Definition: winnls.h:283
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by BtrfsDeviceAdd::populate_device_tree().

◆ get_mountdev_name()

static wstring get_mountdev_name ( const nt_handle h)
static

Definition at line 44 of file devices.cpp.

44 {
47 MOUNTDEV_NAME mdn, *mdn2;
48 wstring name;
49
51 nullptr, 0, &mdn, sizeof(MOUNTDEV_NAME));
53 return L"";
54
55 size_t mdnsize = offsetof(MOUNTDEV_NAME, Name[0]) + mdn.NameLength;
56
57 mdn2 = (MOUNTDEV_NAME*)malloc(mdnsize);
58
60 nullptr, 0, mdn2, (ULONG)mdnsize);
61 if (!NT_SUCCESS(Status)) {
62 free(mdn2);
63 return L"";
64 }
65
66 name = wstring(mdn2->Name, mdn2->NameLength / sizeof(WCHAR));
67
68 free(mdn2);
69
70 return name;
71}
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:91
#define offsetof(TYPE, MEMBER)
USHORT NameLength
Definition: imports.h:141
WCHAR Name[1]
Definition: imports.h:142

Referenced by find_devices().

◆ RemoveDeviceW()

void CALLBACK RemoveDeviceW ( HWND  hwnd,
HINSTANCE  hinst,
LPWSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 877 of file devices.cpp.

877 {
878 try {
879 WCHAR *s, *vol, *dev;
880 uint64_t devid;
883 LUID luid;
886
888
890 throw last_error(GetLastError());
891
892 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
893 throw last_error(GetLastError());
894
895 tp.PrivilegeCount = 1;
896 tp.Privileges[0].Luid = luid;
897 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
898
899 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
900 throw last_error(GetLastError());
901
902 s = wcsstr(lpszCmdLine, L"|");
903 if (!s)
904 return;
905
906 s[0] = 0;
907
908 vol = lpszCmdLine;
909 dev = &s[1];
910
911 devid = _wtoi(dev);
912 if (devid == 0)
913 return;
914
917
918 if (h == INVALID_HANDLE_VALUE)
919 throw last_error(GetLastError());
920
921 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_REMOVE_DEVICE, &devid, sizeof(uint64_t), nullptr, 0);
922 if (!NT_SUCCESS(Status)) {
925 else
926 throw ntstatus_error(Status);
927
928 return;
929 }
930
931 BtrfsBalance bb(vol, true);
932 bb.ShowBalance(hwnd);
933 } catch (const exception& e) {
934 error_message(hwnd, e.what());
935 }
936}
#define FSCTL_BTRFS_REMOVE_DEVICE
Definition: btrfsioctl.h:20
UINT64 uint64_t
Definition: types.h:77
#define IDS_CANNOT_REMOVE_RAID
Definition: resource.h:94
#define OPEN_EXISTING
Definition: compat.h:775
#define CreateFileW
Definition: compat.h:741
GLdouble s
Definition: gl.h:2039
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define FILE_FLAG_OPEN_REPARSE_POINT
Definition: disk.h:39
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_TRAVERSE
Definition: nt_native.h:643
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define STATUS_CANNOT_DELETE
Definition: shellext.h:71

◆ ResizeDeviceW()

void CALLBACK ResizeDeviceW ( HWND  hwnd,
HINSTANCE  hinst,
LPWSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 938 of file devices.cpp.

938 {
939 try {
940 WCHAR *s, *vol, *dev;
941 uint64_t devid;
944 LUID luid;
945
947
949 throw last_error(GetLastError());
950
951 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
952 throw last_error(GetLastError());
953
954 tp.PrivilegeCount = 1;
955 tp.Privileges[0].Luid = luid;
956 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
957
958 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
959 throw last_error(GetLastError());
960
961 s = wcsstr(lpszCmdLine, L"|");
962 if (!s)
963 return;
964
965 s[0] = 0;
966
967 vol = lpszCmdLine;
968 dev = &s[1];
969
970 devid = _wtoi(dev);
971 if (devid == 0)
972 return;
973
975 bdr.ShowDialog(hwnd, vol, devid);
976 } catch (const exception& e) {
977 error_message(hwnd, e.what());
978 }
979}
void ShowDialog(HWND hwnd, const wstring &fn, uint64_t dev_id)
Definition: devices.cpp:838

◆ sort_devices()

static bool sort_devices ( device  i,
device  j 
)
static

Definition at line 320 of file devices.cpp.

320 {
321 if (i.disk_num < j.disk_num)
322 return true;
323
324 if (i.disk_num == j.disk_num && i.part_num < j.part_num)
325 return true;
326
327 return false;
328}
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250

Referenced by BtrfsDeviceAdd::populate_device_tree().

◆ stub_DeviceAddDlgProc()

static INT_PTR CALLBACK stub_DeviceAddDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 628 of file devices.cpp.

628 {
629 BtrfsDeviceAdd* bda;
630
631 if (uMsg == WM_INITDIALOG) {
633 bda = (BtrfsDeviceAdd*)lParam;
634 } else {
636 }
637
638 if (bda)
639 return bda->DeviceAddDlgProc(hwndDlg, uMsg, wParam, lParam);
640 else
641 return false;
642}
INT_PTR CALLBACK DeviceAddDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: devices.cpp:568
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GWLP_USERDATA
Definition: treelist.c:63
#define GetWindowLongPtrW
Definition: winuser.h:4832
#define WM_INITDIALOG
Definition: winuser.h:1742
#define SetWindowLongPtrW
Definition: winuser.h:5358

Referenced by BtrfsDeviceAdd::ShowDialog().

◆ stub_DeviceResizeDlgProc()

static INT_PTR CALLBACK stub_DeviceResizeDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 823 of file devices.cpp.

823 {
825
826 if (uMsg == WM_INITDIALOG) {
829 } else
831
832 if (bdr)
833 return bdr->DeviceResizeDlgProc(hwndDlg, uMsg, wParam, lParam);
834 else
835 return false;
836}
INT_PTR CALLBACK DeviceResizeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: devices.cpp:697

Referenced by BtrfsDeviceResize::ShowDialog().