ReactOS  0.4.14-dev-608-gd495a4f
devices.cpp
Go to the documentation of this file.
1 /* Copyright (c) Mark Harmstone 2016-17
2  *
3  * This file is part of WinBtrfs.
4  *
5  * WinBtrfs is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public Licence as published by
7  * the Free Software Foundation, either version 3 of the Licence, or
8  * (at your option) any later version.
9  *
10  * WinBtrfs is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public Licence for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public Licence
16  * along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
17 
18 #define ISOLATION_AWARE_ENABLED 1
19 #define STRSAFE_NO_DEPRECATE
20 
21 #include "shellext.h"
22 #include "devices.h"
23 #include "resource.h"
24 #include "balance.h"
25 #include <stddef.h>
26 #include <uxtheme.h>
27 #include <setupapi.h>
28 #include <strsafe.h>
29 #include <mountmgr.h>
30 #ifndef __REACTOS__
31 #include <algorithm>
32 #include "../btrfs.h"
33 #include "mountmgr.h"
34 #else
35 #include <ntddstor.h>
36 #include <ndk/rtlfuncs.h>
37 #include <ndk/obfuncs.h>
38 #include "btrfs.h"
39 #include "mountmgr_local.h"
40 #endif
41 
42 DEFINE_GUID(GUID_DEVINTERFACE_HIDDEN_VOLUME, 0x7f108a28L, 0x9833, 0x4b3b, 0xb7, 0x80, 0x2c, 0x6b, 0x5f, 0xa5, 0xc0, 0x62);
43 
44 static wstring get_mountdev_name(const nt_handle& h ) {
47  MOUNTDEV_NAME mdn, *mdn2;
48  wstring name;
49 
50  Status = NtDeviceIoControlFile(h, nullptr, nullptr, nullptr, &iosb, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
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 
59  Status = NtDeviceIoControlFile(h, nullptr, nullptr, nullptr, &iosb, IOCTL_MOUNTDEV_QUERY_DEVICE_NAME,
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 }
72 
73 static void find_devices(HWND hwnd, const GUID* guid, const mountmgr& mm, vector<device>& device_list) {
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 {
90  SP_DEVINFO_DATA dd;
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 
101  detail->cbSize = sizeof(SP_DEVICE_INTERFACE_DETAIL_DATA_W);
102 
103  if (SetupDiGetDeviceInterfaceDetailW(h, &did, detail, size, &size, &dd)) {
105  nt_handle file;
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;
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, (int)(ss * sizeof(WCHAR))))
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 
230  Status = NtDeviceIoControlFile(file, nullptr, nullptr, nullptr, &iosb, IOCTL_DISK_GET_DRIVE_LAYOUT_EX,
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) {
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 }
318 
319 #ifndef __REACTOS__ // Disabled because building with our <algorithm> seems complex right now...
320 static bool sort_devices(device i, device j) {
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 }
329 #endif
330 
332  HWND hwnd = GetParent(tree);
333  unsigned int i;
334  ULONG last_disk_num = 0xffffffff;
335  HTREEITEM diskitem;
340  btrfs_filesystem* bfs = nullptr;
341 
342  static WCHAR btrfs[] = L"\\Btrfs";
343 
344  device_list.clear();
345 
346  {
347  mountmgr mm;
348 
349  {
350  nt_handle btrfsh;
351 
352  us.Length = us.MaximumLength = (uint16_t)(wcslen(btrfs) * sizeof(WCHAR));
353  us.Buffer = btrfs;
354 
355  InitializeObjectAttributes(&attr, &us, 0, nullptr, nullptr);
356 
359  if (NT_SUCCESS(Status)) {
360  ULONG bfssize = 0;
361 
362  do {
363  bfssize += 1024;
364 
365  if (bfs) free(bfs);
366  bfs = (btrfs_filesystem*)malloc(bfssize);
367 
368  Status = NtDeviceIoControlFile(btrfsh, nullptr, nullptr, nullptr, &iosb, IOCTL_BTRFS_QUERY_FILESYSTEMS, nullptr, 0, bfs, bfssize);
370  free(bfs);
371  bfs = nullptr;
372  break;
373  }
374  } while (Status == STATUS_BUFFER_OVERFLOW);
375 
376  if (bfs && bfs->num_devices == 0) { // no mounted filesystems found
377  free(bfs);
378  bfs = nullptr;
379  }
380  }
381  }
382 
383  find_devices(hwnd, &GUID_DEVINTERFACE_DISK, mm, device_list);
384  find_devices(hwnd, &GUID_DEVINTERFACE_VOLUME, mm, device_list);
385  find_devices(hwnd, &GUID_DEVINTERFACE_HIDDEN_VOLUME, mm, device_list);
386  }
387 
388 #ifndef __REACTOS__ // Disabled because building with our <algorithm> seems complex right now...
390 #endif
391 
392  for (i = 0; i < device_list.size(); i++) {
393  if (!device_list[i].ignore) {
394  TVINSERTSTRUCTW tis;
395  HTREEITEM item;
396  wstring name, size;
397 
398  if (device_list[i].disk_num != 0xffffffff && device_list[i].disk_num == last_disk_num)
399  tis.hParent = diskitem;
400  else
401  tis.hParent = TVI_ROOT;
402 
403  tis.hInsertAfter = TVI_LAST;
405  tis.itemex.state = TVIS_EXPANDED;
407 
408  if (device_list[i].disk_num != 0xffffffff) {
409  wstring t;
410 
411  if (!load_string(module, device_list[i].part_num != 0 ? IDS_PARTITION : IDS_DISK_NUM, t))
412  throw last_error(GetLastError());
413 
414  wstring_sprintf(name, t, device_list[i].part_num != 0 ? device_list[i].part_num : device_list[i].disk_num);
415  } else
416  name = device_list[i].pnp_name;
417 
418  // match child Btrfs devices to their parent
419  if (bfs && device_list[i].drive == L"" && device_list[i].fstype == L"Btrfs") {
420  btrfs_filesystem* bfs2 = bfs;
421 
422  while (true) {
423  if (RtlCompareMemory(&bfs2->uuid, &device_list[i].fs_uuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
424  ULONG j, k;
426 
427  for (j = 0; j < bfs2->num_devices; j++) {
428  if (j == 0)
429  dev = &bfs2->device;
430  else
432 
433  if (RtlCompareMemory(&device_list[i].dev_uuid, &device_list[i].dev_uuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
434  for (k = 0; k < device_list.size(); k++) {
435  if (k != i && device_list[k].fstype == L"Btrfs" && device_list[k].drive != L"" &&
436  RtlCompareMemory(&device_list[k].fs_uuid, &device_list[i].fs_uuid, sizeof(BTRFS_UUID)) == sizeof(BTRFS_UUID)) {
437  device_list[i].drive = device_list[k].drive;
438  break;
439  }
440  }
441 
442  device_list[i].multi_device = bfs2->num_devices > 1;
443 
444  break;
445  }
446  }
447 
448  break;
449  }
450 
451  if (bfs2->next_entry != 0)
452  bfs2 = (btrfs_filesystem*)((uint8_t*)bfs2 + bfs2->next_entry);
453  else
454  break;
455  }
456  }
457 
458  name += L" (";
459 
460  if (device_list[i].friendly_name != L"") {
461  name += device_list[i].friendly_name;
462  name += L", ";
463  }
464 
465  if (device_list[i].drive != L"") {
466  name += device_list[i].drive;
467  name += L", ";
468  }
469 
470  if (device_list[i].fstype != L"") {
471  name += device_list[i].fstype;
472  name += L", ";
473  }
474 
475  format_size(device_list[i].size, size, false);
476  name += size;
477 
478  name += L")";
479 
480  tis.itemex.pszText = (WCHAR*)name.c_str();
481  tis.itemex.cchTextMax = (int)name.length();
482  tis.itemex.lParam = (LPARAM)&device_list[i];
483 
485  if (!item)
487 
488  if (device_list[i].part_num == 0) {
489  diskitem = item;
490  last_disk_num = device_list[i].disk_num;
491  }
492  }
493  }
494 }
495 
497  wstring mess, title;
502 
503  if (!sel) {
504  EndDialog(hwndDlg, 0);
505  return;
506  }
507 
508  if (sel->fstype != L"") {
509  wstring s;
510 
512  throw last_error(GetLastError());
513 
514  wstring_sprintf(mess, s, sel->fstype.c_str());
515  } else {
517  throw last_error(GetLastError());
518  }
519 
521  throw last_error(GetLastError());
522 
523  if (MessageBoxW(hwndDlg, mess.c_str(), title.c_str(), MB_YESNO) != IDYES)
524  return;
525 
528 
529  if (h == INVALID_HANDLE_VALUE)
530  throw last_error(GetLastError());
531 
532  {
533  nt_handle h2;
534 
535  vn.Length = vn.MaximumLength = (uint16_t)(sel->pnp_name.length() * sizeof(WCHAR));
536  vn.Buffer = (WCHAR*)sel->pnp_name.c_str();
537 
539 
541  if (!NT_SUCCESS(Status))
542  throw ntstatus_error(Status);
543 
544  if (!sel->is_disk) {
545  Status = NtFsControlFile(h2, nullptr, nullptr, nullptr, &iosb, FSCTL_LOCK_VOLUME, nullptr, 0, nullptr, 0);
546  if (!NT_SUCCESS(Status))
548  }
549 
550  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_ADD_DEVICE, &h2, sizeof(HANDLE), nullptr, 0);
551  if (!NT_SUCCESS(Status))
552  throw ntstatus_error(Status);
553 
554  if (!sel->is_disk) {
555  Status = NtFsControlFile(h2, nullptr, nullptr, nullptr, &iosb, FSCTL_DISMOUNT_VOLUME, nullptr, 0, nullptr, 0);
556  if (!NT_SUCCESS(Status))
557  throw ntstatus_error(Status);
558 
559  Status = NtFsControlFile(h2, nullptr, nullptr, nullptr, &iosb, FSCTL_UNLOCK_VOLUME, nullptr, 0, nullptr, 0);
560  if (!NT_SUCCESS(Status))
561  throw ntstatus_error(Status);
562  }
563  }
564 
565  EndDialog(hwndDlg, 0);
566 }
567 
569  try {
570  switch (uMsg) {
571  case WM_INITDIALOG:
572  {
575  EnableWindow(GetDlgItem(hwndDlg, IDOK), false);
576  break;
577  }
578 
579  case WM_COMMAND:
580  switch (HIWORD(wParam)) {
581  case BN_CLICKED:
582  switch (LOWORD(wParam)) {
583  case IDOK:
584  AddDevice(hwndDlg);
585  return true;
586 
587  case IDCANCEL:
588  EndDialog(hwndDlg, 0);
589  return true;
590  }
591  break;
592  }
593  break;
594 
595  case WM_NOTIFY:
596  switch (((LPNMHDR)lParam)->code) {
597  case TVN_SELCHANGEDW:
598  {
599  NMTREEVIEWW* nmtv = (NMTREEVIEWW*)lParam;
600  TVITEMW tvi;
601  bool enable = false;
602 
603  RtlZeroMemory(&tvi, sizeof(TVITEMW));
604  tvi.hItem = nmtv->itemNew.hItem;
605  tvi.mask = TVIF_PARAM | TVIF_HANDLE;
606 
607  if (SendMessageW(GetDlgItem(hwndDlg, IDC_DEVICE_TREE), TVM_GETITEMW, 0, (LPARAM)&tvi))
608  sel = tvi.lParam == 0 ? nullptr : (device*)tvi.lParam;
609  else
610  sel = nullptr;
611 
612  if (sel)
613  enable = (!sel->is_disk || !sel->has_parts) && !sel->multi_device;
614 
615  EnableWindow(GetDlgItem(hwndDlg, IDOK), enable);
616  break;
617  }
618  }
619  break;
620  }
621  } catch (const exception& e) {
622  error_message(hwndDlg, e.what());
623  }
624 
625  return false;
626 }
627 
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 }
643 
646 }
647 
649  this->hinst = hinst;
650  this->hwnd = hwnd;
651  this->cmdline = cmdline;
652 
653  sel = nullptr;
654 }
655 
659  btrfs_resize br;
660 
661  {
664 
665  if (h == INVALID_HANDLE_VALUE)
666  throw last_error(GetLastError());
667 
668  br.device = dev_id;
669  br.size = new_size;
670 
671  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESIZE, &br, sizeof(btrfs_resize), nullptr, 0);
672 
674  throw ntstatus_error(Status);
675  }
676 
678  wstring s, t, u;
679 
681  format_size(new_size, u, true);
682  wstring_sprintf(t, s, dev_id, u.c_str());
683  MessageBoxW(hwndDlg, t.c_str(), L"", MB_OK);
684 
685  EndDialog(hwndDlg, 0);
686  } else {
687  HWND par;
688 
689  par = GetParent(hwndDlg);
690  EndDialog(hwndDlg, 0);
691 
692  BtrfsBalance bb(fn, false, true);
693  bb.ShowBalance(par);
694  }
695 }
696 
698  try {
699  switch (uMsg) {
700  case WM_INITDIALOG:
701  {
702  win_handle h;
703  WCHAR s[255];
704  wstring t, u;
705 
707 
708  GetDlgItemTextW(hwndDlg, IDC_RESIZE_DEVICE_ID, s, sizeof(s) / sizeof(WCHAR));
710  SetDlgItemTextW(hwndDlg, IDC_RESIZE_DEVICE_ID, t.c_str());
711 
714 
715  if (h != INVALID_HANDLE_VALUE) {
718  btrfs_device *devices, *bd;
719  ULONG devsize;
720  bool found = false;
721  HWND slider;
722 
723  devsize = 1024;
724  devices = (btrfs_device*)malloc(devsize);
725 
726  while (true) {
727  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
729  devsize += 1024;
730 
731  free(devices);
732  devices = (btrfs_device*)malloc(devsize);
733  } else
734  break;
735  }
736 
737  if (!NT_SUCCESS(Status)) {
738  free(devices);
739  return false;
740  }
741 
742  bd = devices;
743 
744  while (true) {
745  if (bd->dev_id == dev_id) {
746  memcpy(&dev_info, bd, sizeof(btrfs_device));
747  found = true;
748  break;
749  }
750 
751  if (bd->next_entry > 0)
752  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
753  else
754  break;
755  }
756 
757  if (!found) {
758  free(devices);
759  return false;
760  }
761 
762  free(devices);
763 
764  GetDlgItemTextW(hwndDlg, IDC_RESIZE_CURSIZE, s, sizeof(s) / sizeof(WCHAR));
765  format_size(dev_info.size, u, true);
766  wstring_sprintf(t, s, u.c_str());
767  SetDlgItemTextW(hwndDlg, IDC_RESIZE_CURSIZE, t.c_str());
768 
770 
772  wstring_sprintf(t, new_size_text, u.c_str());
773  SetDlgItemTextW(hwndDlg, IDC_RESIZE_NEWSIZE, t.c_str());
774 
775  slider = GetDlgItem(hwndDlg, IDC_RESIZE_SLIDER);
776  SendMessageW(slider, TBM_SETRANGEMIN, false, 0);
778  SendMessageW(slider, TBM_SETPOS, true, (LPARAM)(new_size / 1048576));
779  } else
780  return false;
781 
782  break;
783  }
784 
785  case WM_COMMAND:
786  switch (HIWORD(wParam)) {
787  case BN_CLICKED:
788  switch (LOWORD(wParam)) {
789  case IDOK:
790  do_resize(hwndDlg);
791  return true;
792 
793  case IDCANCEL:
794  EndDialog(hwndDlg, 0);
795  return true;
796  }
797  break;
798  }
799  break;
800 
801  case WM_HSCROLL:
802  {
803  wstring t, u;
804 
806 
807  format_size(new_size, u, true);
808  wstring_sprintf(t, new_size_text, u.c_str());
809  SetDlgItemTextW(hwndDlg, IDC_RESIZE_NEWSIZE, t.c_str());
810 
811  EnableWindow(GetDlgItem(hwndDlg, IDOK), new_size > 0 ? true : false);
812 
813  break;
814  }
815  }
816  } catch (const exception& e) {
817  error_message(hwndDlg, e.what());
818  }
819 
820  return false;
821 }
822 
824  BtrfsDeviceResize* bdr;
825 
826  if (uMsg == WM_INITDIALOG) {
828  bdr = (BtrfsDeviceResize*)lParam;
829  } else
831 
832  if (bdr)
833  return bdr->DeviceResizeDlgProc(hwndDlg, uMsg, wParam, lParam);
834  else
835  return false;
836 }
837 
838 void BtrfsDeviceResize::ShowDialog(HWND hwnd, const wstring& fn, uint64_t dev_id) {
839  this->dev_id = dev_id;
840  this->fn = fn;
841 
843 }
844 
845 #ifdef __cplusplus
846 extern "C" {
847 #endif
848 
849 void CALLBACK AddDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
850  try {
853  LUID luid;
854 
855  set_dpi_aware();
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 }
876 
877 void CALLBACK RemoveDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
878  try {
879  WCHAR *s, *vol, *dev;
880  uint64_t devid;
881  win_handle h, token;
883  LUID luid;
886 
887  set_dpi_aware();
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 }
937 
938 void CALLBACK ResizeDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
939  try {
940  WCHAR *s, *vol, *dev;
941  uint64_t devid;
944  LUID luid;
945 
946  set_dpi_aware();
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 
974  BtrfsDeviceResize bdr;
975  bdr.ShowDialog(hwnd, vol, devid);
976  } catch (const exception& e) {
977  error_message(hwnd, e.what());
978  }
979 }
980 
981 #ifdef __cplusplus
982 }
983 #endif
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 * u
Definition: glfuncs.h:240
void populate_device_tree(HWND tree)
Definition: devices.cpp:331
#define FILE_GENERIC_READ
Definition: nt_native.h:653
WCHAR * cmdline
Definition: devices.h:151
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HINSTANCE hinst
Definition: devices.h:149
#define IDS_PARTITION
Definition: resource.h:92
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2265
#define FSCTL_UNLOCK_VOLUME
Definition: nt_native.h:833
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define IDOK
Definition: winuser.h:824
static INT_PTR CALLBACK stub_DeviceAddDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: devices.cpp:628
LPARAM lParam
Definition: commctrl.h:3351
HTREEITEM hParent
Definition: commctrl.h:3389
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
wstring fstype
Definition: devices.h:41
#define FSCTL_BTRFS_RESIZE
Definition: btrfsioctl.h:38
#define IDS_ADD_DEVICE_CONFIRMATION
Definition: resource.h:98
#define TVM_INSERTITEMW
Definition: commctrl.h:3404
#define IDYES
Definition: winuser.h:829
#define IDD_RESIZE
Definition: resource.h:90
iterator end()
Definition: _vector.h:184
WCHAR DevicePath[ANYSIZE_ARRAY]
Definition: setupapi.h:850
bool multi_device
Definition: devices.h:49
#define STATUS_MORE_PROCESSING_REQUIRED
Definition: shellext.h:68
static GLenum _GLUfuncptr fn
Definition: wgl_font.c:159
BtrfsDeviceAdd(HINSTANCE hinst, HWND hwnd, WCHAR *cmdline)
Definition: devices.cpp:648
superblock * sb
Definition: btrfs.c:4137
static const BYTE us[]
Definition: encode.c:689
GLsizei const GLchar ** path
Definition: glext.h:7234
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define IOCTL_BTRFS_QUERY_FILESYSTEMS
Definition: btrfsioctl.h:21
uint32_t next_entry
Definition: btrfsioctl.h:102
uint64_t size
Definition: btrfsioctl.h:280
_STLP_MOVE_TO_STD_NAMESPACE void sort(_RandomAccessIter __first, _RandomAccessIter __last)
Definition: _algo.c:993
int ignore(int trapCode, ppc_trap_frame_t *trap)
Definition: mmuobject.c:296
void CALLBACK RemoveDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: devices.cpp:877
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:3016
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define free
Definition: debug_ros.c:5
const char * devices
Definition: diskspace.c:793
btrfs_device dev_info
Definition: devices.h:167
LPWSTR pszText
Definition: commctrl.h:3346
struct _TREEITEM * HTREEITEM
Definition: commctrl.h:3260
LONG NTSTATUS
Definition: precomp.h:26
#define MB_PRECOMPOSED
Definition: winnls.h:278
const WCHAR * name
Definition: devices.h:54
#define CALLBACK
Definition: compat.h:27
GLdouble GLdouble t
Definition: gl.h:2047
u32_t magic(void)
uint32_t kboff
Definition: devices.h:58
#define IDC_RESIZE_DEVICE_ID
Definition: resource.h:329
#define INVALID_HANDLE_VALUE
Definition: compat.h:399
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define TBM_SETPOS
Definition: commctrl.h:2032
UINT stateMask
Definition: commctrl.h:3345
#define IDS_TVM_INSERTITEM_FAILED
Definition: resource.h:205
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
UINT_PTR WPARAM
Definition: windef.h:207
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)
TCHAR * cmdline
Definition: stretchblt.cpp:32
#define IDS_CONFIRMATION_TITLE
Definition: resource.h:97
#define IDS_RESIZE_SUCCESSFUL
Definition: resource.h:192
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
HWND slider
Definition: sndrec32.cpp:39
#define uint16_t
Definition: nsiface.idl:60
UINT mask
Definition: commctrl.h:3312
int32_t INT_PTR
Definition: typedefs.h:62
#define IDC_RESIZE_CURSIZE
Definition: resource.h:330
bool is_disk
Definition: devices.h:50
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
device * sel
Definition: devices.h:152
static int dev
Definition: mkdosfs.c:536
#define FILE_SHARE_READ
Definition: compat.h:125
#define STATUS_BUFFER_TOO_SMALL
Definition: shellext.h:69
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define TBM_SETRANGEMIN
Definition: commctrl.h:2034
static void find_devices(HWND hwnd, const GUID *guid, const mountmgr &mm, vector< device > &device_list)
Definition: devices.cpp:73
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
struct _SP_DEVICE_INTERFACE_DETAIL_DATA_W SP_DEVICE_INTERFACE_DETAIL_DATA_W
static wstring get_mountdev_name(const nt_handle &h)
Definition: devices.cpp:44
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define IOCTL_MOUNTDEV_QUERY_DEVICE_NAME
Definition: imports.h:93
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
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 FILE_SYNCHRONOUS_IO_ALERT
Definition: from_kernel.h:30
const GUID * guid
uint32_t num_devices
Definition: btrfsioctl.h:190
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:785
#define TBM_SETRANGEMAX
Definition: commctrl.h:2035
void ShowDialog()
Definition: devices.cpp:644
#define MB_YESNO
Definition: winuser.h:811
HTREEITEM hInsertAfter
Definition: commctrl.h:3390
Definition: devices.h:37
#define e
Definition: ke_i.h:82
#define TBM_GETPOS
Definition: commctrl.h:2027
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
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 GWLP_USERDATA
Definition: treelist.c:63
vector< device > device_list
Definition: devices.h:153
#define offsetof(TYPE, MEMBER)
#define IDS_DISK_NUM
Definition: resource.h:102
uint64_t dev_id
Definition: devices.h:164
#define ETDT_ENABLETAB
Definition: dxdiag.c:30
LONG_PTR LPARAM
Definition: windef.h:208
DEV_ITEM dev_item
Definition: btrfs.h:235
#define TVI_LAST
Definition: commctrl.h:3366
#define IOCTL_STORAGE_GET_DEVICE_NUMBER
Definition: ntddstor.h:132
GLuint index
Definition: glext.h:6031
#define TVN_SELCHANGEDW
Definition: commctrl.h:3644
#define OPEN_EXISTING
Definition: compat.h:434
#define IOCTL_DISK_GET_LENGTH_INFO
Definition: imports.h:192
INT_PTR CALLBACK DeviceAddDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: devices.cpp:568
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
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2855
#define FSCTL_DISMOUNT_VOLUME
Definition: nt_native.h:834
TVITEMEXW itemex
Definition: commctrl.h:3392
BTRFS_UUID device_uuid
Definition: btrfs.h:174
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
TVITEMW itemNew
Definition: commctrl.h:3634
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:3951
#define IDS_CANNOT_REMOVE_RAID
Definition: resource.h:94
#define IOCTL_STORAGE_QUERY_PROPERTY
Definition: ntddstor.h:167
GLsizeiptr size
Definition: glext.h:5919
void CALLBACK AddDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: devices.cpp:849
void ShowBalance(HWND hwndDlg)
Definition: balance.cpp:971
STORAGE_DEVICE_DESCRIPTOR
Definition: ntddstor.h:457
#define TOKEN_QUERY
Definition: setypes.h:874
int WINAPI MessageBoxW(_In_opt_ HWND, _In_opt_ LPCWSTR, _In_opt_ LPCWSTR, _In_ UINT)
if(!(yy_init))
Definition: macro.lex.yy.c:714
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR Name[1]
Definition: imports.h:144
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HRESULT WINAPI EnableThemeDialogTexture(_In_ HWND hwnd, _In_ DWORD dwFlags)
Definition: uxthemesupp.c:55
void AddDevice(HWND hwndDlg)
Definition: devices.cpp:496
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
BOOL WINAPI SetupDiDestroyDeviceInfoList(HDEVINFO devinfo)
Definition: devinst.c:2898
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
const char file[]
Definition: icontest.c:11
#define BN_CLICKED
Definition: winuser.h:1907
unsigned long DWORD
Definition: ntddk_ex.h:95
uint32_t next_entry
Definition: btrfsioctl.h:188
wstring pnp_name
Definition: devices.h:38
Definition: cookie.c:201
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define TVI_ROOT
Definition: commctrl.h:3364
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define STATUS_CANNOT_DELETE
Definition: shellext.h:71
iterator begin()
Definition: _vector.h:182
void do_resize(HWND hwndDlg)
Definition: devices.cpp:656
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
int cchTextMax
Definition: commctrl.h:3347
__u8 attr
Definition: mkdosfs.c:359
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLdouble s
Definition: gl.h:2039
#define SetupDiGetClassDevs
Definition: setupapi.h:2588
#define WM_COMMAND
Definition: winuser.h:1722
static bool sort_devices(device i, device j)
Definition: devices.cpp:320
#define SYNCHRONIZE
Definition: nt_native.h:61
BYTE uint8_t
Definition: msvideo1.c:66
LARGE_INTEGER Length
Definition: winioctl.h:423
INT_PTR CALLBACK DeviceResizeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: devices.cpp:697
void CALLBACK ResizeDeviceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: devices.cpp:938
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
#define TVIF_HANDLE
Definition: commctrl.h:3266
#define TVIS_EXPANDED
Definition: commctrl.h:3280
Status
Definition: gdiplustypes.h:24
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define FILE_GENERIC_WRITE
Definition: nt_native.h:660
HWND WINAPI GetParent(_In_ HWND)
struct _GUID GUID
STORAGE_QUERY_TYPE QueryType
Definition: ntddstor.h:434
GLboolean enable
Definition: glext.h:11120
UINT64 uint64_t
Definition: types.h:77
static ATOM item
Definition: dde.c:856
static const fs_identifier fs_ident[]
Definition: devices.h:64
const GLdouble * v
Definition: gl.h:2040
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66
#define IOCTL_DISK_GET_DRIVE_LAYOUT_EX
Definition: ntddk_ex.h:207
#define IDC_RESIZE_SLIDER
Definition: resource.h:331
#define TVIF_TEXT
Definition: commctrl.h:3262
BTRFS_UUID uuid
Definition: btrfs.h:209
static const WCHAR friendly_name[]
Definition: devenum.c:40
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetupDiEnumDeviceInterfaces(HDEVINFO DeviceInfoSet, PSP_DEVINFO_DATA DeviceInfoData, CONST GUID *InterfaceClassGuid, DWORD MemberIndex, PSP_DEVICE_INTERFACE_DATA DeviceInterfaceData)
Definition: devinst.c:2785
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
DEFINE_GUID(GUID_DEVINTERFACE_HIDDEN_VOLUME, 0x7f108a28L, 0x9833, 0x4b3b, 0xb7, 0x80, 0x2c, 0x6b, 0x5f, 0xa5, 0xc0, 0x62)
#define FSCTL_BTRFS_REMOVE_DEVICE
Definition: btrfsioctl.h:20
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
#define WM_HSCROLL
Definition: winuser.h:1725
#define MB_OK
Definition: winuser.h:784
HTREEITEM hItem
Definition: commctrl.h:3313
USHORT NameLength
Definition: imports.h:143
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
#define FSCTL_BTRFS_ADD_DEVICE
Definition: btrfsioctl.h:19
#define FSCTL_BTRFS_GET_DEVICES
Definition: btrfsioctl.h:12
uint64_t max_size
Definition: btrfsioctl.h:105
STORAGE_PROPERTY_ID PropertyId
Definition: ntddstor.h:433
#define MultiByteToWideChar
Definition: compat.h:100
uint64_t dev_id
Definition: btrfsioctl.h:103
#define CreateFileW
Definition: compat.h:408
uint8_t uuid[16]
Definition: btrfsioctl.h:189
UCHAR AdditionalParameters[1]
Definition: ntddstor.h:435
#define IDS_ADD_DEVICE_CONFIRMATION_FS
Definition: resource.h:99
#define DIGCF_DEVICEINTERFACE
Definition: setupapi.h:174
#define IDD_DEVICE_ADD
Definition: resource.h:80
#define IDC_RESIZE_NEWSIZE
Definition: resource.h:332
#define IDS_LOCK_FAILED
Definition: resource.h:122
bool has_parts
Definition: devices.h:45
Definition: name.c:38
uint64_t new_size
Definition: devices.h:164
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FILE_FLAG_OPEN_REPARSE_POINT
Definition: disk.h:39
#define FSCTL_LOCK_VOLUME
Definition: nt_native.h:832
size_type size() const
Definition: _vector.h:192
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
static HINSTANCE hinst
Definition: edit.c:551
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define TVIF_STATE
Definition: commctrl.h:3265
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define TVM_GETITEMW
Definition: commctrl.h:3482
#define malloc
Definition: debug_ros.c:4
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 vn
Definition: glfuncs.h:238
uint64_t device
Definition: btrfsioctl.h:279
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define TVIF_PARAM
Definition: commctrl.h:3264
#define GetWindowLongPtr
Definition: treelist.c:73
uint64_t size
GLfloat GLfloat p
Definition: glext.h:8902
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
#define ss
Definition: i386-dis.c:432
void clear()
Definition: _vector.h:653
#define memset(x, y, z)
Definition: compat.h:39
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
static INT_PTR CALLBACK stub_DeviceResizeDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: devices.cpp:823
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define UInt32x32To64(a, b)
Definition: intsafe.h:258
void set_dpi_aware()
Definition: main.cpp:50
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
static char title[]
Definition: ps.c:92
int k
Definition: mpi.c:3369
#define LOWORD(l)
Definition: pedump.c:82
#define CP_OEMCP
Definition: winnls.h:228
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
void ShowDialog(HWND hwnd, const wstring &fn, uint64_t dev_id)
Definition: devices.cpp:838
btrfs_filesystem_device device
Definition: btrfsioctl.h:191
#define WM_NOTIFY
Definition: richedit.h:61
WCHAR new_size_text[255]
Definition: devices.h:166
#define RtlCompareMemory(s1, s2, l)
Definition: env_spec_w32.h:465
uint64_t size
Definition: btrfsioctl.h:104
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)
LONGLONG QuadPart
Definition: typedefs.h:112
#define DIGCF_PRESENT
Definition: setupapi.h:171
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
off
Definition: i386-dis.c:3909
Definition: fci.c:126
void format_size(uint64_t size, wstring &s, bool show_bytes)
Definition: main.cpp:65
#define IDC_DEVICE_TREE
Definition: resource.h:302
GLuint const GLchar * name
Definition: glext.h:6031