ReactOS  0.4.13-dev-259-g5ca9c9c
balance.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 #include "shellext.h"
19 #include "balance.h"
20 #include "resource.h"
21 #ifndef __REACTOS__
22 #include "../btrfsioctl.h"
23 #else
24 #include "btrfsioctl.h"
25 #endif
26 #include <shlobj.h>
27 #include <uxtheme.h>
28 #include <stdio.h>
29 #ifndef __REACTOS__
30 #include <strsafe.h>
31 #include <winternl.h>
32 #else
33 #define WIN32_NO_STATUS
34 #include <windef.h>
35 #include <winbase.h>
36 #include <strsafe.h>
37 #include <ndk/iofuncs.h>
38 #include <ndk/iotypes.h>
39 #endif
40 
41 #define NO_SHLWAPI_STRFCNS
42 #include <shlwapi.h>
43 #include <uxtheme.h>
44 
46 
48  if (u >= 0xa && u <= 0xf)
49  return (uint8_t)(u - 0xa + 'a');
50  else
51  return (uint8_t)(u + '0');
52 }
53 
54 static void serialize(void* data, ULONG len, WCHAR* s) {
55  uint8_t* d;
56 
57  d = (uint8_t*)data;
58 
59  while (true) {
60  *s = hex_digit((uint8_t)(*d >> 4)); s++;
61  *s = hex_digit(*d & 0xf); s++;
62 
63  d++;
64  len--;
65 
66  if (len == 0) {
67  *s = 0;
68  return;
69  }
70  }
71 }
72 
74  wstring t;
75  WCHAR modfn[MAX_PATH], u[600];
78 
79  GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
80 
81 #ifndef __REACTOS__
82  t = L"\""s + modfn + L"\",StartBalance "s + fn + L" "s;
83 #else
84  t = wstring(L"\"") + modfn + wstring(L"\",StartBalance ") + fn + wstring(L" ");
85 #endif
86 
87  RtlCopyMemory(&bsb.opts[0], &data_opts, sizeof(btrfs_balance_opts));
90 
91  if (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED)
93  else
95 
98  else
100 
101  if (IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED)
103  else
105 
106  serialize(&bsb, sizeof(btrfs_start_balance), u);
107 
108  t += u;
109 
110  RtlZeroMemory(&sei, sizeof(sei));
111 
112  sei.cbSize = sizeof(sei);
113  sei.hwnd = hwndDlg;
114  sei.lpVerb = L"runas";
115  sei.lpFile = L"rundll32.exe";
116  sei.lpParameters = t.c_str();
117  sei.nShow = SW_SHOW;
119 
120  if (!ShellExecuteExW(&sei))
121  throw last_error(GetLastError());
122 
123  cancelling = false;
124  removing = false;
125  shrinking = false;
127 
128  EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), true);
129  EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), true);
131  EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), false);
132  EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), false);
133  EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), false);
137 
138  EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), false);
139 
141  CloseHandle(sei.hProcess);
142 }
143 
145  WCHAR modfn[MAX_PATH];
146  wstring t;
147  SHELLEXECUTEINFOW sei;
148 
149  GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
150 
151 #ifndef __REACTOS__
152  t = L"\""s + modfn + L"\",PauseBalance " + fn;
153 #else
154  t = wstring(L"\"") + modfn + wstring(L"\",PauseBalance ") + fn;
155 #endif
156 
157  RtlZeroMemory(&sei, sizeof(sei));
158 
159  sei.cbSize = sizeof(sei);
160  sei.hwnd = hwndDlg;
161  sei.lpVerb = L"runas";
162  sei.lpFile = L"rundll32.exe";
163  sei.lpParameters = t.c_str();
164  sei.nShow = SW_SHOW;
166 
167  if (!ShellExecuteExW(&sei))
168  throw last_error(GetLastError());
169 
171  CloseHandle(sei.hProcess);
172 }
173 
175  WCHAR modfn[MAX_PATH];
176  wstring t;
177  SHELLEXECUTEINFOW sei;
178 
179  GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
180 
181 #ifndef __REACTOS__
182  t = L"\""s + modfn + L"\",StopBalance " + fn;
183 #else
184  t = wstring(L"\"") + modfn + wstring(L"\",StopBalance ") + fn;
185 #endif
186 
187  RtlZeroMemory(&sei, sizeof(sei));
188 
189  sei.cbSize = sizeof(sei);
190  sei.hwnd = hwndDlg;
191  sei.lpVerb = L"runas";
192  sei.lpFile = L"rundll32.exe";
193  sei.lpParameters = t.c_str();
194  sei.nShow = SW_SHOW;
196 
197  if (!ShellExecuteExW(&sei))
198  throw last_error(GetLastError());
199 
200  cancelling = true;
201 
203  CloseHandle(sei.hProcess);
204 }
205 
207  bool balancing = false;
208  wstring s, t;
209 
210  {
213 
214  if (h != INVALID_HANDLE_VALUE) {
217 
218  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_QUERY_BALANCE, nullptr, 0, &bqb, sizeof(btrfs_query_balance));
219 
220  if (!NT_SUCCESS(Status))
221  throw ntstatus_error(Status);
222  } else
223  throw last_error(GetLastError());
224  }
225 
226  if (cancelling)
228 
230 
231  if (!balancing) {
233  int resid;
234 
235  EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), false);
236  EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), false);
237  SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
238  EnableWindow(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), false);
239  EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), true);
240  EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), true);
241  EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), true);
242 
247 
249  }
250 
251  EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ? true : false);
253  EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED ? true : false);
254 
256  if (removing)
258  else if (shrinking)
260  else
261  resid = IDS_BALANCE_FAILED;
262 
263  if (!load_string(module, resid, s))
264  throw last_error(GetLastError());
265 
267 
268  SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, t.c_str());
269  } else {
270  if (cancelling)
274  else
275  resid = IDS_NO_BALANCE;
276 
277  if (!load_string(module, resid, s))
278  throw last_error(GetLastError());
279 
280  SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, s.c_str());
281  }
282 
284  IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
285 
287  cancelling = false;
288  }
289 
290  return;
291  }
292 
294  EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), true);
295  EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), true);
297  EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), false);
298  EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), false);
299  EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), false);
300 
304 
308 
309  EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), false);
310  }
311 
314 
316  SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_PAUSED, 0);
318  SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
319 
321 
324  throw last_error(GetLastError());
325 
327  (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks);
328 
329  removing = true;
330  shrinking = false;
331  } else if (bqb.status & BTRFS_BALANCE_SHRINKING) {
333  throw last_error(GetLastError());
334 
336  (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks);
337 
338  removing = false;
339  shrinking = true;
340  } else {
342  throw last_error(GetLastError());
343 
345  (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks);
346 
347  removing = false;
348  shrinking = false;
349  }
350 
351  SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, t.c_str());
352 }
353 
355  btrfs_balance_opts* opts;
356 
357  switch (opts_type) {
358  case 1:
359  opts = &data_opts;
360  break;
361 
362  case 2:
363  opts = &metadata_opts;
364  break;
365 
366  case 3:
367  opts = &system_opts;
368  break;
369 
370  default:
371  return;
372  }
373 
374  RtlZeroMemory(opts, sizeof(btrfs_balance_opts));
375 
376  if (IsDlgButtonChecked(hwndDlg, IDC_PROFILES) == BST_CHECKED) {
378 
386  }
387 
388  if (IsDlgButtonChecked(hwndDlg, IDC_DEVID) == BST_CHECKED) {
389  int sel;
390 
392 
393  sel = SendMessageW(GetDlgItem(hwndDlg, IDC_DEVID_COMBO), CB_GETCURSEL, 0, 0);
394 
395  if (sel == CB_ERR)
397  else {
398  btrfs_device* bd = devices;
399  int i = 0;
400 
401  while (true) {
402  if (i == sel) {
403  opts->devid = bd->dev_id;
404  break;
405  }
406 
407  i++;
408 
409  if (bd->next_entry > 0)
410  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
411  else
412  break;
413  }
414 
415  if (opts->devid == 0)
417  }
418  }
419 
420  if (IsDlgButtonChecked(hwndDlg, IDC_DRANGE) == BST_CHECKED) {
421  WCHAR s[255];
422 
424 
425  GetWindowTextW(GetDlgItem(hwndDlg, IDC_DRANGE_START), s, sizeof(s) / sizeof(WCHAR));
426  opts->drange_start = _wtoi64(s);
427 
428  GetWindowTextW(GetDlgItem(hwndDlg, IDC_DRANGE_END), s, sizeof(s) / sizeof(WCHAR));
429  opts->drange_end = _wtoi64(s);
430 
431  if (opts->drange_end < opts->drange_start)
433  }
434 
435  if (IsDlgButtonChecked(hwndDlg, IDC_VRANGE) == BST_CHECKED) {
436  WCHAR s[255];
437 
439 
440  GetWindowTextW(GetDlgItem(hwndDlg, IDC_VRANGE_START), s, sizeof(s) / sizeof(WCHAR));
441  opts->vrange_start = _wtoi64(s);
442 
443  GetWindowTextW(GetDlgItem(hwndDlg, IDC_VRANGE_END), s, sizeof(s) / sizeof(WCHAR));
444  opts->vrange_end = _wtoi64(s);
445 
446  if (opts->vrange_end < opts->vrange_start)
448  }
449 
450  if (IsDlgButtonChecked(hwndDlg, IDC_LIMIT) == BST_CHECKED) {
451  WCHAR s[255];
452 
454 
455  GetWindowTextW(GetDlgItem(hwndDlg, IDC_LIMIT_START), s, sizeof(s) / sizeof(WCHAR));
456  opts->limit_start = _wtoi64(s);
457 
458  GetWindowTextW(GetDlgItem(hwndDlg, IDC_LIMIT_END), s, sizeof(s) / sizeof(WCHAR));
459  opts->limit_end = _wtoi64(s);
460 
461  if (opts->limit_end < opts->limit_start)
463  }
464 
465  if (IsDlgButtonChecked(hwndDlg, IDC_STRIPES) == BST_CHECKED) {
466  WCHAR s[255];
467 
469 
470  GetWindowTextW(GetDlgItem(hwndDlg, IDC_STRIPES_START), s, sizeof(s) / sizeof(WCHAR));
471  opts->stripes_start = (uint8_t)_wtoi(s);
472 
473  GetWindowTextW(GetDlgItem(hwndDlg, IDC_STRIPES_END), s, sizeof(s) / sizeof(WCHAR));
474  opts->stripes_end = (uint8_t)_wtoi(s);
475 
476  if (opts->stripes_end < opts->stripes_start)
478  }
479 
480  if (IsDlgButtonChecked(hwndDlg, IDC_USAGE) == BST_CHECKED) {
481  WCHAR s[255];
482 
484 
485  GetWindowTextW(GetDlgItem(hwndDlg, IDC_USAGE_START), s, sizeof(s) / sizeof(WCHAR));
486  opts->usage_start = (uint8_t)_wtoi(s);
487 
488  GetWindowTextW(GetDlgItem(hwndDlg, IDC_USAGE_END), s, sizeof(s) / sizeof(WCHAR));
489  opts->usage_end = (uint8_t)_wtoi(s);
490 
491  if (opts->usage_end < opts->usage_start)
493  }
494 
495  if (IsDlgButtonChecked(hwndDlg, IDC_CONVERT) == BST_CHECKED) {
496  int sel;
497 
499 
500  sel = SendMessageW(GetDlgItem(hwndDlg, IDC_CONVERT_COMBO), CB_GETCURSEL, 0, 0);
501 
502  if (sel == CB_ERR || (unsigned int)sel >= sizeof(convtypes2) / sizeof(convtypes2[0]))
504  else {
505  opts->convert = convtypes2[sel];
506 
508  }
509  }
510 
511  EndDialog(hwndDlg, 0);
512 }
513 
515  try {
516  switch (uMsg) {
517  case WM_INITDIALOG:
518  {
519  HWND devcb, convcb;
520  btrfs_device* bd;
521  btrfs_balance_opts* opts;
522  static int convtypes[] = { IDS_SINGLE2, IDS_DUP, IDS_RAID0, IDS_RAID1, IDS_RAID5, IDS_RAID6, IDS_RAID10, 0 };
523  int i, num_devices = 0, num_writeable_devices = 0;
524  wstring s, u;
525  bool balance_started = balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED);
526 
527  switch (opts_type) {
528  case 1:
529  opts = balance_started ? &bqb.data_opts : &data_opts;
530  break;
531 
532  case 2:
533  opts = balance_started ? &bqb.metadata_opts : &metadata_opts;
534  break;
535 
536  case 3:
537  opts = balance_started ? &bqb.system_opts : &system_opts;
538  break;
539 
540  default:
541  return true;
542  }
543 
545 
546  devcb = GetDlgItem(hwndDlg, IDC_DEVID_COMBO);
547 
549  throw last_error(GetLastError());
550 
551  bd = devices;
552  while (true) {
553  wstring t, v;
554 
555  if (bd->device_number == 0xffffffff)
556  s = wstring(bd->name, bd->namelen);
557  else if (bd->partition_number == 0) {
559  throw last_error(GetLastError());
560 
562  } else {
564  throw last_error(GetLastError());
565 
567  }
568 
569  wstring_sprintf(t, u, bd->dev_id, s.c_str());
570 
571  SendMessage(devcb, CB_ADDSTRING, 0, (LPARAM)t.c_str());
572 
573  if (opts->devid == bd->dev_id)
574  SendMessage(devcb, CB_SETCURSEL, num_devices, 0);
575 
576  num_devices++;
577 
578  if (!bd->readonly)
579  num_writeable_devices++;
580 
581  if (bd->next_entry > 0)
582  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
583  else
584  break;
585  }
586 
587  convcb = GetDlgItem(hwndDlg, IDC_CONVERT_COMBO);
588 
589  if (num_writeable_devices == 0)
590  num_writeable_devices = num_devices;
591 
592  i = 0;
593  while (convtypes[i] != 0) {
594  if (!load_string(module, convtypes[i], s))
595  throw last_error(GetLastError());
596 
597  SendMessage(convcb, CB_ADDSTRING, 0, (LPARAM)s.c_str());
598 
599  if (opts->convert == convtypes2[i])
600  SendMessage(convcb, CB_SETCURSEL, i, 0);
601 
602  i++;
603 
604  if (num_writeable_devices < 2 && i == 2)
605  break;
606  else if (num_writeable_devices < 3 && i == 4)
607  break;
608  else if (num_writeable_devices < 4 && i == 5)
609  break;
610  }
611 
612  // profiles
613 
622 
623  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_SINGLE), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
624  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_DUP), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
625  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID0), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
626  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID1), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
627  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID10), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
628  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID5), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
629  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID6), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? true : false);
630  EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES), balance_started ? false : true);
631 
632  // usage
633 
635 
636  s = to_wstring(opts->usage_start);
637  SetDlgItemTextW(hwndDlg, IDC_USAGE_START, s.c_str());
639 
640  s = to_wstring(opts->usage_end);
641  SetDlgItemTextW(hwndDlg, IDC_USAGE_END, s.c_str());
643 
644  EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? true : false);
645  EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? true : false);
646  EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? true : false);
647  EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? true : false);
648  EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE), balance_started ? false : true);
649 
650  // devid
651 
652  if (num_devices < 2 || balance_started)
653  EnableWindow(GetDlgItem(hwndDlg, IDC_DEVID), false);
654 
656  EnableWindow(devcb, (opts->flags & BTRFS_BALANCE_OPTS_DEVID && num_devices >= 2 && !balance_started) ? true : false);
657 
658  // drange
659 
661 
662  s = to_wstring(opts->drange_start);
663  SetDlgItemTextW(hwndDlg, IDC_DRANGE_START, s.c_str());
664 
665  s = to_wstring(opts->drange_end);
666  SetDlgItemTextW(hwndDlg, IDC_DRANGE_END, s.c_str());
667 
668  EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_DRANGE ? true : false);
669  EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_DRANGE ? true : false);
670  EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE), balance_started ? false : true);
671 
672  // vrange
673 
675 
676  s = to_wstring(opts->vrange_start);
677  SetDlgItemTextW(hwndDlg, IDC_VRANGE_START, s.c_str());
678 
679  s = to_wstring(opts->vrange_end);
680  SetDlgItemTextW(hwndDlg, IDC_VRANGE_END, s.c_str());
681 
682  EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_VRANGE ? true : false);
683  EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_VRANGE ? true : false);
684  EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE), balance_started ? false : true);
685 
686  // limit
687 
689 
690  s = to_wstring(opts->limit_start);
691  SetDlgItemTextW(hwndDlg, IDC_LIMIT_START, s.c_str());
693 
694  s = to_wstring(opts->limit_end);
695  SetDlgItemTextW(hwndDlg, IDC_LIMIT_END, s.c_str());
696  SendMessageW(GetDlgItem(hwndDlg, IDC_LIMIT_END_SPINNER), UDM_SETRANGE32, 0, 0x7fffffff);
697 
698  EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? true : false);
699  EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? true : false);
700  EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? true : false);
701  EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? true : false);
702  EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT), balance_started ? false : true);
703 
704  // stripes
705 
707 
708  s = to_wstring(opts->stripes_start);
709  SetDlgItemTextW(hwndDlg, IDC_STRIPES_START, s.c_str());
711 
712  s = to_wstring(opts->stripes_end);
713  SetDlgItemTextW(hwndDlg, IDC_STRIPES_END, s.c_str());
715 
716  EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? true : false);
717  EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? true : false);
718  EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? true : false);
719  EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? true : false);
720  EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES), balance_started ? false : true);
721 
722  // convert
723 
726 
727  EnableWindow(GetDlgItem(hwndDlg, IDC_SOFT), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_CONVERT ? true : false);
728  EnableWindow(convcb, !balance_started && opts->flags & BTRFS_BALANCE_OPTS_CONVERT ? true : false);
729  EnableWindow(GetDlgItem(hwndDlg, IDC_CONVERT), balance_started ? false : true);
730 
731  break;
732  }
733 
734  case WM_COMMAND:
735  switch (HIWORD(wParam)) {
736  case BN_CLICKED:
737  switch (LOWORD(wParam)) {
738  case IDOK:
740  EndDialog(hwndDlg, 0);
741  else
742  SaveBalanceOpts(hwndDlg);
743  return true;
744 
745  case IDCANCEL:
746  EndDialog(hwndDlg, 0);
747  return true;
748 
749  case IDC_PROFILES: {
750  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_PROFILES) == BST_CHECKED ? true : false;
751 
759  break;
760  }
761 
762  case IDC_USAGE: {
763  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_USAGE) == BST_CHECKED ? true : false;
764 
769  break;
770  }
771 
772  case IDC_DEVID: {
773  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_DEVID) == BST_CHECKED ? true : false;
774 
776  break;
777  }
778 
779  case IDC_DRANGE: {
780  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_DRANGE) == BST_CHECKED ? true : false;
781 
784  break;
785  }
786 
787  case IDC_VRANGE: {
788  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_VRANGE) == BST_CHECKED ? true : false;
789 
792  break;
793  }
794 
795  case IDC_LIMIT: {
796  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_LIMIT) == BST_CHECKED ? true : false;
797 
802  break;
803  }
804 
805  case IDC_STRIPES: {
806  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_STRIPES) == BST_CHECKED ? true : false;
807 
812  break;
813  }
814 
815  case IDC_CONVERT: {
816  bool enabled = IsDlgButtonChecked(hwndDlg, IDC_CONVERT) == BST_CHECKED ? true : false;
817 
820  break;
821  }
822  }
823  break;
824  }
825  break;
826  }
827  } catch (const exception& e) {
828  error_message(hwndDlg, e.what());
829  }
830 
831  return false;
832 }
833 
835  BtrfsBalance* bb;
836 
837  if (uMsg == WM_INITDIALOG) {
839  bb = (BtrfsBalance*)lParam;
840  } else {
842  }
843 
844  if (bb)
845  return bb->BalanceOptsDlgProc(hwndDlg, uMsg, wParam, lParam);
846  else
847  return false;
848 }
849 
851  opts_type = type;
853 }
854 
856  try {
857  switch (uMsg) {
858  case WM_INITDIALOG:
859  {
861 
865 
869  cancelling = false;
870  RefreshBalanceDlg(hwndDlg, true);
871 
872  if (readonly) {
873  EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), false);
874  EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), false);
875  EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), false);
876  }
877 
881 
882  SetTimer(hwndDlg, 1, 1000, nullptr);
883 
884  break;
885  }
886 
887  case WM_COMMAND:
888  switch (HIWORD(wParam)) {
889  case BN_CLICKED:
890  switch (LOWORD(wParam)) {
891  case IDOK:
892  case IDCANCEL:
893  KillTimer(hwndDlg, 1);
894  EndDialog(hwndDlg, 0);
895  return true;
896 
897  case IDC_DATA:
898  EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ? true : false);
899 
901  IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
902  return true;
903 
904  case IDC_METADATA:
906 
908  IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
909  return true;
910 
911  case IDC_SYSTEM:
912  EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED ? true : false);
913 
915  IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
916  return true;
917 
918  case IDC_DATA_OPTIONS:
919  ShowBalanceOptions(hwndDlg, 1);
920  return true;
921 
923  ShowBalanceOptions(hwndDlg, 2);
924  return true;
925 
926  case IDC_SYSTEM_OPTIONS:
927  ShowBalanceOptions(hwndDlg, 3);
928  return true;
929 
930  case IDC_START_BALANCE:
931  StartBalance(hwndDlg);
932  return true;
933 
934  case IDC_PAUSE_BALANCE:
935  PauseBalance(hwndDlg);
936  RefreshBalanceDlg(hwndDlg, false);
937  return true;
938 
939  case IDC_CANCEL_BALANCE:
940  StopBalance(hwndDlg);
941  RefreshBalanceDlg(hwndDlg, false);
942  return true;
943  }
944  break;
945  }
946  break;
947 
948  case WM_TIMER:
949  RefreshBalanceDlg(hwndDlg, false);
950  break;
951  }
952  } catch (const exception& e) {
953  error_message(hwndDlg, e.what());
954  }
955 
956  return false;
957 }
958 
960  BtrfsBalance* bb;
961 
962  if (uMsg == WM_INITDIALOG) {
964  bb = (BtrfsBalance*)lParam;
965  } else {
967  }
968 
969  if (bb)
970  return bb->BalanceDlgProc(hwndDlg, uMsg, wParam, lParam);
971  else
972  return false;
973 }
974 
976  btrfs_device* bd;
977 
978  if (devices) {
979  free(devices);
980  devices = nullptr;
981  }
982 
983  {
986 
987  if (h != INVALID_HANDLE_VALUE) {
990  ULONG devsize, i;
991 
992  i = 0;
993  devsize = 1024;
994 
995  devices = (btrfs_device*)malloc(devsize);
996 
997  while (true) {
998  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
1000  if (i < 8) {
1001  devsize += 1024;
1002 
1003  free(devices);
1004  devices = (btrfs_device*)malloc(devsize);
1005 
1006  i++;
1007  } else
1008  return;
1009  } else
1010  break;
1011  }
1012 
1013  if (!NT_SUCCESS(Status))
1014  throw ntstatus_error(Status);
1015  } else
1016  throw last_error(GetLastError());
1017  }
1018 
1019  readonly = true;
1020  bd = devices;
1021 
1022  while (true) {
1023  if (!bd->readonly) {
1024  readonly = false;
1025  break;
1026  }
1027 
1028  if (bd->next_entry > 0)
1029  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
1030  else
1031  break;
1032  }
1033 
1035 }
1036 
1038  if (c >= 'a' && c <= 'f')
1039  return (uint8_t)(c - 'a' + 0xa);
1040  else if (c >= 'A' && c <= 'F')
1041  return (uint8_t)(c - 'A' + 0xa);
1042  else
1043  return (uint8_t)(c - '0');
1044 }
1045 
1046 static void unserialize(void* data, ULONG len, WCHAR* s) {
1047  uint8_t* d;
1048 
1049  d = (uint8_t*)data;
1050 
1051  while (s[0] != 0 && s[1] != 0 && len > 0) {
1052  *d = (uint8_t)(from_hex_digit(s[0]) << 4) | from_hex_digit(s[1]);
1053 
1054  s += 2;
1055  d++;
1056  len--;
1057  }
1058 }
1059 
1060 #ifdef __REACTOS__
1061 extern "C" {
1062 #endif
1063 
1064 void CALLBACK StartBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1065  try {
1066  WCHAR *s, *vol, *block;
1067  win_handle h, token;
1068  btrfs_start_balance bsb;
1070  LUID luid;
1071 
1072  s = wcsstr(lpszCmdLine, L" ");
1073  if (!s)
1074  return;
1075 
1076  s[0] = 0;
1077 
1078  vol = lpszCmdLine;
1079  block = &s[1];
1080 
1081  RtlZeroMemory(&bsb, sizeof(btrfs_start_balance));
1082  unserialize(&bsb, sizeof(btrfs_start_balance), block);
1083 
1085  throw last_error(GetLastError());
1086 
1087  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1088  throw last_error(GetLastError());
1089 
1090  tp.PrivilegeCount = 1;
1091  tp.Privileges[0].Luid = luid;
1092  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1093 
1094  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1095  throw last_error(GetLastError());
1096 
1099 
1100  if (h != INVALID_HANDLE_VALUE) {
1101  NTSTATUS Status;
1103 
1104  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_START_BALANCE, &bsb, sizeof(btrfs_start_balance), nullptr, 0);
1105 
1107  btrfs_query_scrub bqs;
1108  NTSTATUS Status2;
1109 
1110  Status2 = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_QUERY_SCRUB, nullptr, 0, &bqs, sizeof(btrfs_query_scrub));
1111 
1112  if ((NT_SUCCESS(Status2) || Status2 == STATUS_BUFFER_OVERFLOW) && bqs.status != BTRFS_SCRUB_STOPPED)
1114  }
1115 
1116  if (!NT_SUCCESS(Status))
1117  throw ntstatus_error(Status);
1118  } else
1119  throw last_error(GetLastError());
1120  } catch (const exception& e) {
1121  error_message(hwnd, e.what());
1122  }
1123 }
1124 
1125 void CALLBACK PauseBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1126  try {
1127  win_handle h, token;
1129  LUID luid;
1130 
1132  throw last_error(GetLastError());
1133 
1134  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1135  throw last_error(GetLastError());
1136 
1137  tp.PrivilegeCount = 1;
1138  tp.Privileges[0].Luid = luid;
1139  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1140 
1141  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1142  throw last_error(GetLastError());
1143 
1146 
1147  if (h != INVALID_HANDLE_VALUE) {
1148  NTSTATUS Status;
1150  btrfs_query_balance bqb2;
1151 
1152  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_QUERY_BALANCE, nullptr, 0, &bqb2, sizeof(btrfs_query_balance));
1153  if (!NT_SUCCESS(Status))
1154  throw ntstatus_error(Status);
1155 
1156  if (bqb2.status & BTRFS_BALANCE_PAUSED)
1157  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESUME_BALANCE, nullptr, 0, nullptr, 0);
1158  else if (bqb2.status & BTRFS_BALANCE_RUNNING)
1159  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_PAUSE_BALANCE, nullptr, 0, nullptr, 0);
1160  else
1161  return;
1162 
1163  if (!NT_SUCCESS(Status))
1164  throw ntstatus_error(Status);
1165  } else
1166  throw last_error(GetLastError());
1167  } catch (const exception& e) {
1168  error_message(hwnd, e.what());
1169  }
1170 }
1171 
1172 void CALLBACK StopBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1173  try {
1174  win_handle h, token;
1176  LUID luid;
1177 
1179  throw last_error(GetLastError());
1180 
1181  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1182  throw last_error(GetLastError());
1183 
1184  tp.PrivilegeCount = 1;
1185  tp.Privileges[0].Luid = luid;
1186  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1187 
1188  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1189  throw last_error(GetLastError());
1190 
1193 
1194  if (h != INVALID_HANDLE_VALUE) {
1195  NTSTATUS Status;
1197  btrfs_query_balance bqb2;
1198 
1199  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_QUERY_BALANCE, nullptr, 0, &bqb2, sizeof(btrfs_query_balance));
1200  if (!NT_SUCCESS(Status))
1201  throw ntstatus_error(Status);
1202 
1204  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_STOP_BALANCE, nullptr, 0, nullptr, 0);
1205  else
1206  return;
1207 
1208  if (!NT_SUCCESS(Status))
1209  throw ntstatus_error(Status);
1210  } else
1211  throw last_error(GetLastError());
1212  } catch (const exception& e) {
1213  error_message(hwnd, e.what());
1214  }
1215 }
1216 
1217 #ifdef __REACTOS__
1218 } /* extern "C" */
1219 #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
static unsigned int block
Definition: xmlmemory.c:118
void StartBalance(HWND hwndDlg)
Definition: balance.cpp:73
static WCHAR hex_digit(uint8_t u)
Definition: balance.cpp:47
#define FSCTL_BTRFS_QUERY_BALANCE
Definition: btrfsioctl.h:16
#define FSCTL_BTRFS_RESUME_BALANCE
Definition: btrfsioctl.h:18
WCHAR name[1]
Definition: btrfsioctl.h:126
#define IDS_NO_BALANCE
Definition: resource.h:61
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:607
#define IDC_LIMIT_START
Definition: resource.h:278
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDS_RAID10
Definition: resource.h:47
BOOL WINAPI CheckDlgButton(_In_ HWND, _In_ int, _In_ UINT)
#define IDC_USAGE_END_SPINNER
Definition: resource.h:256
#define IDC_STRIPES
Definition: resource.h:297
#define PBM_SETRANGE32
Definition: commctrl.h:2160
USHORT namelen
Definition: btrfsioctl.h:125
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
#define BTRFS_SCRUB_STOPPED
Definition: btrfsioctl.h:208
#define IDOK
Definition: winuser.h:824
#define IDD_BALANCE
Definition: resource.h:19
#define CloseHandle
Definition: compat.h:398
btrfs_balance_opts metadata_opts
Definition: btrfsioctl.h:186
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)
#define IDS_USAGE_END_BEFORE_START
Definition: resource.h:69
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
#define IDC_DATA
Definition: resource.h:266
static INT_PTR CALLBACK stub_BalanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: balance.cpp:959
#define IDS_BALANCE_RUNNING
Definition: resource.h:64
#define IDC_LIMIT_END_SPINNER
Definition: resource.h:292
#define BTRFS_BALANCE_OPTS_PROFILES
Definition: btrfsioctl.h:144
#define BTRFS_BALANCE_STOPPED
Definition: btrfsioctl.h:173
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
#define IDC_USAGE_START_SPINNER
Definition: resource.h:254
#define IDC_STRIPES_START
Definition: resource.h:301
_CONST_RETURN wchar_t *__cdecl wcsstr(_In_z_ const wchar_t *_Str, _In_z_ const wchar_t *_SubStr)
#define IDC_DEVID_COMBO
Definition: resource.h:259
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
#define IDC_PROFILES_RAID5
Definition: resource.h:251
#define free
Definition: debug_ros.c:5
#define IDC_METADATA_OPTIONS
Definition: resource.h:280
const GLint * first
Definition: glext.h:5794
LONG NTSTATUS
Definition: precomp.h:26
static uint8_t from_hex_digit(WCHAR c)
Definition: balance.cpp:1037
#define IDS_BALANCE_FAILED_REMOVAL
Definition: resource.h:100
#define CALLBACK
Definition: compat.h:27
btrfs_balance_opts data_opts
Definition: balance.h:50
GLdouble GLdouble t
Definition: gl.h:2047
UINT64 dev_id
Definition: btrfsioctl.h:117
#define IDS_STRIPES_END_BEFORE_START
Definition: resource.h:68
#define IDS_VRANGE_END_BEFORE_START
Definition: resource.h:66
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define BTRFS_BALANCE_OPTS_VRANGE
Definition: btrfsioctl.h:147
#define PBM_SETPOS
Definition: commctrl.h:2156
static INT_PTR CALLBACK stub_BalanceOptsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: balance.cpp:834
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
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2663
#define BCM_SETSHIELD
Definition: commctrl.h:4625
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
int32_t INT_PTR
Definition: typedefs.h:62
#define IDC_PROFILES
Definition: resource.h:242
btrfs_balance_opts data_opts
Definition: btrfsioctl.h:185
#define BTRFS_BALANCE_RUNNING
Definition: btrfsioctl.h:174
#define IDS_BALANCE_PAUSED_SHRINK
Definition: resource.h:195
GLenum GLenum GLsizei const GLuint GLboolean enabled
Definition: glext.h:7750
#define SetWindowLongPtr
Definition: treelist.c:70
#define CB_GETCURSEL
Definition: winuser.h:1904
#define IDS_BALANCE_CANCELLED_SHRINK
Definition: resource.h:196
#define IDC_DATA_OPTIONS
Definition: resource.h:273
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
bool removing
Definition: balance.h:54
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define IDC_STRIPES_END
Definition: resource.h:305
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define BLOCK_FLAG_SINGLE
Definition: btrfsioctl.h:154
#define IDS_LIMIT_END_BEFORE_START
Definition: resource.h:67
#define IDC_BALANCE_STATUS
Definition: resource.h:289
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define BTRFS_BALANCE_OPTS_USAGE
Definition: btrfsioctl.h:150
#define IDC_DEVID
Definition: resource.h:258
#define FILE_TRAVERSE
Definition: nt_native.h:643
#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
ULONG device_number
Definition: btrfsioctl.h:122
static void unserialize(void *data, ULONG len, WCHAR *s)
Definition: balance.cpp:1046
uint32_t balance_status
Definition: balance.h:49
#define BTRFS_BALANCE_OPTS_CONVERT
Definition: btrfsioctl.h:151
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:738
#define IDS_RAID5
Definition: resource.h:48
static uint64_t convtypes2[]
Definition: balance.cpp:45
#define e
Definition: ke_i.h:82
btrfs_balance_opts metadata_opts
Definition: balance.h:50
#define IDC_VRANGE
Definition: resource.h:269
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 FSCTL_BTRFS_PAUSE_BALANCE
Definition: btrfsioctl.h:17
#define IDS_RAID0
Definition: resource.h:45
bool called_from_RemoveDevice
Definition: balance.h:59
#define IDC_METADATA
Definition: resource.h:268
#define GWLP_USERDATA
Definition: treelist.c:63
#define IDC_LIMIT_END
Definition: resource.h:295
#define IDC_PROFILES_RAID1
Definition: resource.h:249
#define CB_ADDSTRING
Definition: winuser.h:1897
#define IDS_DISK_PART_NUM
Definition: resource.h:102
#define IDS_DISK_NUM
Definition: resource.h:101
#define ETDT_ENABLETAB
Definition: dxdiag.c:30
#define BLOCK_FLAG_RAID10
Definition: shellext.h:76
LONG_PTR LPARAM
Definition: windef.h:208
#define IDC_CONVERT
Definition: resource.h:307
#define IDC_PROFILES_SINGLE
Definition: resource.h:243
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2225
bool called_from_ShrinkDevice
Definition: balance.h:59
ULONG partition_number
Definition: btrfsioctl.h:123
#define UDM_SETRANGE32
Definition: commctrl.h:2123
#define SW_SHOW
Definition: winuser.h:769
#define IDS_BALANCE_FAILED_SHRINK
Definition: resource.h:198
#define FSCTL_BTRFS_STOP_BALANCE
Definition: btrfsioctl.h:19
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define IDC_PROFILES_RAID6
Definition: resource.h:252
#define OPEN_EXISTING
Definition: compat.h:426
#define IDC_LIMIT
Definition: resource.h:267
#define CB_ERR
Definition: winuser.h:2389
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
void CALLBACK StartBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: balance.cpp:1064
wstring fn
Definition: balance.h:56
#define IDC_LIMIT_START_SPINNER
Definition: resource.h:271
#define BTRFS_BALANCE_OPTS_SOFT
Definition: btrfsioctl.h:152
#define IDC_DRANGE_START
Definition: resource.h:260
#define IDC_SOFT
Definition: resource.h:311
#define IDC_VRANGE_END
Definition: resource.h:283
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
#define BLOCK_FLAG_RAID0
Definition: shellext.h:73
void SaveBalanceOpts(HWND hwndDlg)
Definition: balance.cpp:354
btrfs_query_balance bqb
Definition: balance.h:52
void ShowBalance(HWND hwndDlg)
Definition: balance.cpp:975
#define d
Definition: ke_i.h:81
#define IDS_BALANCE_RUNNING_REMOVAL
Definition: resource.h:85
#define TOKEN_QUERY
Definition: setypes.h:874
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HRESULT WINAPI EnableThemeDialogTexture(_In_ HWND hwnd, _In_ DWORD dwFlags)
Definition: uxthemesupp.c:55
#define IDS_DUP
Definition: resource.h:44
#define WM_TIMER
Definition: winuser.h:1718
#define FSCTL_BTRFS_QUERY_SCRUB
Definition: btrfsioctl.h:25
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#define MAX_PATH
Definition: compat.h:26
#define BTRFS_BALANCE_OPTS_LIMIT
Definition: btrfsioctl.h:148
const GLubyte * c
Definition: glext.h:8905
_Check_return_ __MINGW_EXTENSION _CRTIMP __int64 __cdecl _wtoi64(_In_z_ const wchar_t *_Str)
#define BN_CLICKED
Definition: winuser.h:1886
#define IDS_BALANCE_CANCELLED_REMOVAL
Definition: resource.h:89
#define IDS_RAID6
Definition: resource.h:49
#define BTRFS_BALANCE_SHRINKING
Definition: btrfsioctl.h:178
#define BLOCK_FLAG_RAID6
Definition: shellext.h:78
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
void ShowBalanceOptions(HWND hwndDlg, uint8_t type)
Definition: balance.cpp:850
#define IDS_BALANCE_FAILED
Definition: resource.h:99
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define IDC_USAGE
Definition: resource.h:253
#define IDC_START_BALANCE
Definition: resource.h:293
#define IDD_BALANCE_OPTIONS
Definition: resource.h:17
#define BTRFS_BALANCE_OPTS_ENABLED
Definition: btrfsioctl.h:143
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
#define IDC_VRANGE_START
Definition: resource.h:288
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_BALANCE_ERROR
Definition: btrfsioctl.h:177
#define BTRFS_BALANCE_REMOVAL
Definition: btrfsioctl.h:176
#define BTRFS_BALANCE_OPTS_DRANGE
Definition: btrfsioctl.h:146
#define IDC_SYSTEM
Definition: resource.h:270
#define IDS_DEVID_LIST
Definition: resource.h:63
#define IDC_CANCEL_BALANCE
Definition: resource.h:299
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
btrfs_balance_opts opts[3]
Definition: btrfsioctl.h:191
INT_PTR CALLBACK BalanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: balance.cpp:855
#define CB_SETCURSEL
Definition: winuser.h:1922
#define WM_COMMAND
Definition: winuser.h:1716
#define BST_UNCHECKED
Definition: winuser.h:199
#define IDS_BALANCE_PAUSED_REMOVAL
Definition: resource.h:87
BYTE uint8_t
Definition: msvideo1.c:66
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
#define IDC_PROFILES_RAID10
Definition: resource.h:250
bool shrinking
Definition: balance.h:55
btrfs_device * devices
Definition: balance.h:57
Status
Definition: gdiplustypes.h:24
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define IDC_PROFILES_RAID0
Definition: resource.h:246
bool cancelling
Definition: balance.h:53
uint8_t opts_type
Definition: balance.h:51
void RefreshBalanceDlg(HWND hwndDlg, bool first)
Definition: balance.cpp:206
UINT64 uint64_t
Definition: types.h:77
const GLdouble * v
Definition: gl.h:2040
#define uint8_t
Definition: nsiface.idl:59
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:61
btrfs_balance_opts system_opts
Definition: btrfsioctl.h:187
int WINAPI GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
Definition: window.c:1378
#define IDS_SINGLE2
Definition: resource.h:62
#define IDC_STRIPES_START_SPINNER
Definition: resource.h:300
#define IDC_DRANGE_END
Definition: resource.h:265
void StopBalance(HWND hwndDlg)
Definition: balance.cpp:174
LPCWSTR lpParameters
Definition: shellapi.h:331
#define IDS_BALANCE_SCRUB_RUNNING
Definition: resource.h:116
UINT32 next_entry
Definition: btrfsioctl.h:116
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDS_BALANCE_RUNNING_SHRINK
Definition: resource.h:194
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
unsigned int UINT
Definition: ndis.h:50
bool readonly
Definition: balance.h:58
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
#define FSCTL_BTRFS_GET_DEVICES
Definition: btrfsioctl.h:13
#define BST_CHECKED
Definition: winuser.h:197
#define CreateFileW
Definition: compat.h:400
void PauseBalance(HWND hwndDlg)
Definition: balance.cpp:144
btrfs_balance_opts system_opts
Definition: balance.h:50
#define IDC_USAGE_START
Definition: resource.h:255
#define SendMessage
Definition: winuser.h:5709
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define IDC_STRIPES_END_SPINNER
Definition: resource.h:303
#define FILE_FLAG_OPEN_REPARSE_POINT
Definition: disk.h:39
#define IDC_USAGE_END
Definition: resource.h:257
#define BTRFS_BALANCE_OPTS_DEVID
Definition: btrfsioctl.h:145
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
#define IDS_BALANCE_COMPLETE_SHRINK
Definition: resource.h:197
static HINSTANCE hinst
Definition: edit.c:551
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
#define malloc
Definition: debug_ros.c:4
#define IDS_DRANGE_END_BEFORE_START
Definition: resource.h:65
#define IDS_BALANCE_COMPLETE_REMOVAL
Definition: resource.h:91
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:75
#define GetWindowLongPtr
Definition: treelist.c:73
#define IDS_RAID1
Definition: resource.h:46
#define BLOCK_FLAG_RAID5
Definition: shellext.h:77
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define IDCANCEL
Definition: winuser.h:825
INT_PTR CALLBACK BalanceOptsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: balance.cpp:514
void CALLBACK StopBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: balance.cpp:1172
#define BTRFS_BALANCE_PAUSED
Definition: btrfsioctl.h:175
static void serialize(void *data, ULONG len, WCHAR *s)
Definition: balance.cpp:54
#define INFINITE
Definition: serial.h:102
#define IDS_BALANCE_COMPLETE
Definition: resource.h:71
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
#define IDS_BALANCE_PAUSED
Definition: resource.h:72
#define WM_INITDIALOG
Definition: winuser.h:1715
#define true
Definition: stdbool.h:37
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define IDC_CONVERT_COMBO
Definition: resource.h:309
#define IDC_PAUSE_BALANCE
Definition: resource.h:296
#define BTRFS_BALANCE_OPTS_STRIPES
Definition: btrfsioctl.h:149
#define IDC_BALANCE_PROGRESS
Definition: resource.h:263
#define IDC_DRANGE
Definition: resource.h:261
void CALLBACK PauseBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: balance.cpp:1125
#define IDS_BALANCE_CANCELLED
Definition: resource.h:73
#define IDC_PROFILES_DUP
Definition: resource.h:244
#define IDC_SYSTEM_OPTIONS
Definition: resource.h:285
#define FSCTL_BTRFS_START_BALANCE
Definition: btrfsioctl.h:15
#define BLOCK_FLAG_RAID1
Definition: shellext.h:74
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:65