ReactOS  0.4.11-dev-721-g95bc44e
scrub.cpp
Go to the documentation of this file.
1 /* Copyright (c) Mark Harmstone 2017
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 "scrub.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 #include <string>
41 
42 #define NO_SHLWAPI_STRFCNS
43 #include <shlwapi.h>
44 #include <uxtheme.h>
45 
47  btrfs_query_scrub* bqs2 = NULL;
48  BOOL alloc_bqs2 = FALSE;
50  std::wstring s;
51  WCHAR t[255], u[255], dt[255], tm[255];
53  SYSTEMTIME systime;
54  UINT64 recoverable_errors = 0, unrecoverable_errors = 0;
55 
56  if (bqs->num_errors > 0) {
57  HANDLE h;
59  ULONG len;
60 
63  if (h == INVALID_HANDLE_VALUE) {
64  ShowError(hwndDlg, GetLastError());
65  return;
66  }
67 
68  len = 0;
69 
70  do {
71  len += 1024;
72 
73  if (bqs2)
74  free(bqs2);
75 
76  bqs2 = (btrfs_query_scrub*)malloc(len);
77 
78  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_SCRUB, NULL, 0, bqs2, len);
79 
80  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW) {
81  ShowNtStatusError(hwndDlg, Status);
82  CloseHandle(h);
83  free(bqs2);
84  return;
85  }
86  } while (Status == STATUS_BUFFER_OVERFLOW);
87 
88  alloc_bqs2 = TRUE;
89 
90  CloseHandle(h);
91  } else
92  bqs2 = bqs;
93 
94  s[0] = 0;
95 
96  // "scrub started"
97  if (bqs2->start_time.QuadPart > 0) {
98  filetime.dwLowDateTime = bqs2->start_time.LowPart;
99  filetime.dwHighDateTime = bqs2->start_time.HighPart;
100 
101  if (!FileTimeToSystemTime(&filetime, &systime)) {
102  ShowError(hwndDlg, GetLastError());
103  goto end;
104  }
105 
106  if (!SystemTimeToTzSpecificLocalTime(NULL, &systime, &systime)) {
107  ShowError(hwndDlg, GetLastError());
108  goto end;
109  }
110 
111  if (!LoadStringW(module, IDS_SCRUB_MSG_STARTED, t, sizeof(t) / sizeof(WCHAR))) {
112  ShowError(hwndDlg, GetLastError());
113  goto end;
114  }
115 
116  if (!GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systime, NULL, dt, sizeof(dt) / sizeof(WCHAR))) {
117  ShowError(hwndDlg, GetLastError());
118  goto end;
119  }
120 
121  if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, NULL, tm, sizeof(tm) / sizeof(WCHAR))) {
122  ShowError(hwndDlg, GetLastError());
123  goto end;
124  }
125 
126  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, dt, tm) == STRSAFE_E_INSUFFICIENT_BUFFER)
127  goto end;
128 
129  s += u;
130  s += L"\r\n";
131  }
132 
133  // errors
134  if (bqs2->num_errors > 0) {
135  btrfs_scrub_error* bse = &bqs2->errors;
136 
137  do {
138  if (bse->recovered)
139  recoverable_errors++;
140  else
141  unrecoverable_errors++;
142 
143  if (bse->parity) {
144  if (!LoadStringW(module, IDS_SCRUB_MSG_RECOVERABLE_PARITY, t, sizeof(t) / sizeof(WCHAR))) {
145  ShowError(hwndDlg, GetLastError());
146  goto end;
147  }
148 
149  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device) == STRSAFE_E_INSUFFICIENT_BUFFER)
150  goto end;
151  } else if (bse->is_metadata) {
152  int message;
153 
154  if (bse->recovered)
156  else if (bse->metadata.firstitem.obj_id == 0 && bse->metadata.firstitem.obj_type == 0 && bse->metadata.firstitem.offset == 0)
158  else
160 
161  if (!LoadStringW(module, message, t, sizeof(t) / sizeof(WCHAR))) {
162  ShowError(hwndDlg, GetLastError());
163  goto end;
164  }
165 
166  if (bse->recovered) {
167  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device) == STRSAFE_E_INSUFFICIENT_BUFFER)
168  goto end;
169  } else if (bse->metadata.firstitem.obj_id == 0 && bse->metadata.firstitem.obj_type == 0 && bse->metadata.firstitem.offset == 0) {
170  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device,
171  bse->metadata.root, bse->metadata.level) == STRSAFE_E_INSUFFICIENT_BUFFER)
172  goto end;
173  } else {
174  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device,
175  bse->metadata.root, bse->metadata.level, bse->metadata.firstitem.obj_id, bse->metadata.firstitem.obj_type,
176  bse->metadata.firstitem.offset) == STRSAFE_E_INSUFFICIENT_BUFFER)
177  goto end;
178  }
179  } else {
180  int message;
181 
182  if (bse->recovered)
184  else if (bse->data.subvol != 0)
186  else
188 
189  if (!LoadStringW(module, message, t, sizeof(t) / sizeof(WCHAR))) {
190  ShowError(hwndDlg, GetLastError());
191  goto end;
192  }
193 
194  if (bse->recovered) {
195  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device) == STRSAFE_E_INSUFFICIENT_BUFFER)
196  goto end;
197  } else if (bse->data.subvol != 0) {
198  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device, bse->data.subvol,
199  bse->data.filename_length / sizeof(WCHAR), bse->data.filename, bse->data.offset) == STRSAFE_E_INSUFFICIENT_BUFFER)
200  goto end;
201  } else {
202  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, bse->address, bse->device, bse->data.filename_length / sizeof(WCHAR),
203  bse->data.filename, bse->data.offset) == STRSAFE_E_INSUFFICIENT_BUFFER)
204  goto end;
205  }
206  }
207 
208  s += u;
209  s += L"\r\n";
210 
211  if (bse->next_entry == 0)
212  break;
213  else
214  bse = (btrfs_scrub_error*)((UINT8*)bse + bse->next_entry);
215  } while (TRUE);
216  }
217 
218  if (bqs2->finish_time.QuadPart > 0) {
219  WCHAR d1[255], d2[255];
220  float speed;
221 
222  // "scrub finished"
223 
224  filetime.dwLowDateTime = bqs2->finish_time.LowPart;
225  filetime.dwHighDateTime = bqs2->finish_time.HighPart;
226 
227  if (!FileTimeToSystemTime(&filetime, &systime)) {
228  ShowError(hwndDlg, GetLastError());
229  goto end;
230  }
231 
232  if (!SystemTimeToTzSpecificLocalTime(NULL, &systime, &systime)) {
233  ShowError(hwndDlg, GetLastError());
234  goto end;
235  }
236 
237  if (!LoadStringW(module, IDS_SCRUB_MSG_FINISHED, t, sizeof(t) / sizeof(WCHAR))) {
238  ShowError(hwndDlg, GetLastError());
239  goto end;
240  }
241 
242  if (!GetDateFormatW(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &systime, NULL, dt, sizeof(dt) / sizeof(WCHAR))) {
243  ShowError(hwndDlg, GetLastError());
244  goto end;
245  }
246 
247  if (!GetTimeFormatW(LOCALE_USER_DEFAULT, 0, &systime, NULL, tm, sizeof(tm) / sizeof(WCHAR))) {
248  ShowError(hwndDlg, GetLastError());
249  goto end;
250  }
251 
252  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, dt, tm) == STRSAFE_E_INSUFFICIENT_BUFFER)
253  goto end;
254 
255  s += u;
256  s += L"\r\n";
257 
258  // summary
259 
260  if (!LoadStringW(module, IDS_SCRUB_MSG_SUMMARY, t, sizeof(t) / sizeof(WCHAR))) {
261  ShowError(hwndDlg, GetLastError());
262  goto end;
263  }
264 
265  format_size(bqs2->data_scrubbed, d1, sizeof(d1) / sizeof(WCHAR), FALSE);
266 
267  speed = (float)bqs2->data_scrubbed / ((float)bqs2->duration / 10000000.0f);
268 
269  format_size((UINT64)speed, d2, sizeof(d2) / sizeof(WCHAR), FALSE);
270 
271  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, d1, bqs2->duration / 10000000, d2) == STRSAFE_E_INSUFFICIENT_BUFFER)
272  goto end;
273 
274  s += u;
275  s += L"\r\n";
276 
277  // recoverable errors
278 
279  if (!LoadStringW(module, IDS_SCRUB_MSG_SUMMARY_ERRORS_RECOVERABLE, t, sizeof(t) / sizeof(WCHAR))) {
280  ShowError(hwndDlg, GetLastError());
281  goto end;
282  }
283 
284  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, recoverable_errors) == STRSAFE_E_INSUFFICIENT_BUFFER)
285  goto end;
286 
287  s += u;
288  s += L"\r\n";
289 
290  // unrecoverable errors
291 
292  if (!LoadStringW(module, IDS_SCRUB_MSG_SUMMARY_ERRORS_UNRECOVERABLE, t, sizeof(t) / sizeof(WCHAR))) {
293  ShowError(hwndDlg, GetLastError());
294  goto end;
295  }
296 
297  if (StringCchPrintfW(u, sizeof(u) / sizeof(WCHAR), t, unrecoverable_errors) == STRSAFE_E_INSUFFICIENT_BUFFER)
298  goto end;
299 
300  s += u;
301  s += L"\r\n";
302  }
303 
304  SetWindowTextW(GetDlgItem(hwndDlg, IDC_SCRUB_INFO), s.c_str());
305 
306 end:
307  if (alloc_bqs2)
308  free(bqs2);
309 }
310 
311 void BtrfsScrub::RefreshScrubDlg(HWND hwndDlg, BOOL first_time) {
312  HANDLE h;
313  btrfs_query_scrub bqs;
314 
317  if (h != INVALID_HANDLE_VALUE) {
320 
321  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_SCRUB, NULL, 0, &bqs, sizeof(btrfs_query_scrub));
322 
323  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW) {
324  ShowNtStatusError(hwndDlg, Status);
325  CloseHandle(h);
326  return;
327  }
328 
329  CloseHandle(h);
330  } else {
331  ShowError(hwndDlg, GetLastError());
332  return;
333  }
334 
335  if (first_time || status != bqs.status || chunks_left != bqs.chunks_left) {
336  WCHAR s[255];
337 
338  if (bqs.status == BTRFS_SCRUB_STOPPED) {
342 
343  if (bqs.error != STATUS_SUCCESS) {
344  WCHAR t[255];
345 
346  if (!LoadStringW(module, IDS_SCRUB_FAILED, t, sizeof(t) / sizeof(WCHAR))) {
347  ShowError(hwndDlg, GetLastError());
348  return;
349  }
350 
351  if (StringCchPrintfW(s, sizeof(s) / sizeof(WCHAR), t, bqs.error) == STRSAFE_E_INSUFFICIENT_BUFFER)
352  return;
353  } else {
354  if (!LoadStringW(module, bqs.total_chunks == 0 ? IDS_NO_SCRUB : IDS_SCRUB_FINISHED, s, sizeof(s) / sizeof(WCHAR))) {
355  ShowError(hwndDlg, GetLastError());
356  return;
357  }
358  }
359  } else {
360  WCHAR t[255];
361  float pc;
362 
366 
367  if (!LoadStringW(module, bqs.status == BTRFS_SCRUB_PAUSED ? IDS_SCRUB_PAUSED : IDS_SCRUB_RUNNING, t, sizeof(t) / sizeof(WCHAR))) {
368  ShowError(hwndDlg, GetLastError());
369  return;
370  }
371 
372  pc = ((float)(bqs.total_chunks - bqs.chunks_left) / (float)bqs.total_chunks) * 100.0f;
373 
374  if (StringCchPrintfW(s, sizeof(s) / sizeof(WCHAR), t, bqs.total_chunks - bqs.chunks_left, bqs.total_chunks, pc) == STRSAFE_E_INSUFFICIENT_BUFFER)
375  return;
376  }
377 
378  SetDlgItemTextW(hwndDlg, IDC_SCRUB_STATUS, s);
379 
380  if (first_time || status != bqs.status) {
382 
383  if (bqs.status != BTRFS_SCRUB_STOPPED) {
386 
387  if (bqs.status == BTRFS_SCRUB_PAUSED)
388  SendMessageW(GetDlgItem(hwndDlg, IDC_SCRUB_PROGRESS), PBM_SETSTATE, PBST_PAUSED, 0);
389  else
390  SendMessageW(GetDlgItem(hwndDlg, IDC_SCRUB_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
391  } else {
394  }
395 
396  chunks_left = bqs.chunks_left;
397  }
398  }
399 
400  if (bqs.status != BTRFS_SCRUB_STOPPED && chunks_left != bqs.chunks_left) {
402  chunks_left = bqs.chunks_left;
403  }
404 
405  if (first_time || status != bqs.status || num_errors != bqs.num_errors) {
406  UpdateTextBox(hwndDlg, &bqs);
407 
408  num_errors = bqs.num_errors;
409  }
410 
411  status = bqs.status;
412 }
413 
415  HANDLE h;
416 
419  if (h != INVALID_HANDLE_VALUE) {
422 
423  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_START_SCRUB, NULL, 0, NULL, 0);
424 
425  if (Status == STATUS_DEVICE_NOT_READY) {
427  NTSTATUS Status2;
428 
429  Status2 = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_BALANCE, NULL, 0, &bqb, sizeof(btrfs_query_balance));
430 
431  if (NT_SUCCESS(Status2) && bqb.status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED)) {
433  CloseHandle(h);
434  return;
435  }
436  }
437 
438  if (!NT_SUCCESS(Status)) {
439  ShowNtStatusError(hwndDlg, Status);
440  CloseHandle(h);
441  return;
442  }
443 
444  RefreshScrubDlg(hwndDlg, TRUE);
445 
446  CloseHandle(h);
447  } else {
448  ShowError(hwndDlg, GetLastError());
449  return;
450  }
451 }
452 
454  HANDLE h;
455  btrfs_query_scrub bqs;
456 
459  if (h != INVALID_HANDLE_VALUE) {
462 
463  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_SCRUB, NULL, 0, &bqs, sizeof(btrfs_query_scrub));
464 
465  if (!NT_SUCCESS(Status) && Status != STATUS_BUFFER_OVERFLOW) {
466  ShowNtStatusError(hwndDlg, Status);
467  CloseHandle(h);
468  return;
469  }
470 
471  if (bqs.status == BTRFS_SCRUB_PAUSED)
472  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_RESUME_SCRUB, NULL, 0, NULL, 0);
473  else
474  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_PAUSE_SCRUB, NULL, 0, NULL, 0);
475 
476  if (!NT_SUCCESS(Status)) {
477  ShowNtStatusError(hwndDlg, Status);
478  CloseHandle(h);
479  return;
480  }
481 
482  CloseHandle(h);
483  } else {
484  ShowError(hwndDlg, GetLastError());
485  return;
486  }
487 }
488 
490  HANDLE h;
491 
494  if (h != INVALID_HANDLE_VALUE) {
497 
498  Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_STOP_SCRUB, NULL, 0, NULL, 0);
499 
500  if (!NT_SUCCESS(Status)) {
501  ShowNtStatusError(hwndDlg, Status);
502  CloseHandle(h);
503  return;
504  }
505 
506  CloseHandle(h);
507  } else {
508  ShowError(hwndDlg, GetLastError());
509  return;
510  }
511 }
512 
514  switch (uMsg) {
515  case WM_INITDIALOG:
516  RefreshScrubDlg(hwndDlg, TRUE);
517  SetTimer(hwndDlg, 1, 1000, NULL);
518  break;
519 
520  case WM_COMMAND:
521  switch (HIWORD(wParam)) {
522  case BN_CLICKED:
523  switch (LOWORD(wParam)) {
524  case IDOK:
525  case IDCANCEL:
526  EndDialog(hwndDlg, 0);
527  return TRUE;
528 
529  case IDC_START_SCRUB:
530  StartScrub(hwndDlg);
531  return TRUE;
532 
533  case IDC_PAUSE_SCRUB:
534  PauseScrub(hwndDlg);
535  return TRUE;
536 
537  case IDC_CANCEL_SCRUB:
538  StopScrub(hwndDlg);
539  return TRUE;
540  }
541  break;
542  }
543  break;
544 
545  case WM_TIMER:
546  RefreshScrubDlg(hwndDlg, FALSE);
547  break;
548  }
549 
550  return FALSE;
551 }
552 
554  BtrfsScrub* bs;
555 
556  if (uMsg == WM_INITDIALOG) {
557  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
558  bs = (BtrfsScrub*)lParam;
559  } else {
560  bs = (BtrfsScrub*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
561  }
562 
563  if (bs)
564  return bs->ScrubDlgProc(hwndDlg, uMsg, wParam, lParam);
565  else
566  return FALSE;
567 }
568 
569 #ifdef __REACTOS__
570 extern "C" {
571 #endif
572 
573 void CALLBACK ShowScrubW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
574  HANDLE token;
576  LUID luid;
577  BtrfsScrub* scrub;
578 
580  ShowError(hwnd, GetLastError());
581  return;
582  }
583 
584  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
585  ShowError(hwnd, GetLastError());
586  goto end;
587  }
588 
589  tp.PrivilegeCount = 1;
590  tp.Privileges[0].Luid = luid;
592 
593  if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
594  ShowError(hwnd, GetLastError());
595  goto end;
596  }
597 
598  set_dpi_aware();
599 
600  scrub = new BtrfsScrub(lpszCmdLine);
601 
603 
604  delete scrub;
605 
606 end:
607  CloseHandle(token);
608 }
609 
610 void CALLBACK StartScrubW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
611  LPWSTR* args;
612  int num_args;
613 
614  args = CommandLineToArgvW(lpszCmdLine, &num_args);
615 
616  if (!args)
617  return;
618 
619  if (num_args >= 1) {
620  HANDLE h, token;
621  LUID luid;
623 
625  goto end;
626 
627  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
628  CloseHandle(token);
629  goto end;
630  }
631 
632  tp.PrivilegeCount = 1;
633  tp.Privileges[0].Luid = luid;
635 
636  if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
637  CloseHandle(token);
638  goto end;
639  }
640 
641  CloseHandle(token);
642 
645  if (h != INVALID_HANDLE_VALUE) {
647 
649 
650  CloseHandle(h);
651  }
652  }
653 
654 end:
655  LocalFree(args);
656 }
657 
658 void CALLBACK StopScrubW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
659  LPWSTR* args;
660  int num_args;
661 
662  args = CommandLineToArgvW(lpszCmdLine, &num_args);
663 
664  if (!args)
665  return;
666 
667  if (num_args >= 1) {
668  HANDLE h, token;
669  LUID luid;
671 
673  goto end;
674 
675  if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid))
676  goto end;
677 
678  tp.PrivilegeCount = 1;
679  tp.Privileges[0].Luid = luid;
681 
682  if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL))
683  goto end;
684 
685  CloseHandle(token);
686 
689  if (h != INVALID_HANDLE_VALUE) {
691 
693 
694  CloseHandle(h);
695  }
696  }
697 
698 end:
699  LocalFree(args);
700 }
701 
702 #ifdef __REACTOS__
703 } /* extern "C" */
704 #endif
#define FSCTL_BTRFS_QUERY_BALANCE
Definition: btrfsioctl.h:16
btrfs_scrub_error errors
Definition: btrfsioctl.h:226
UINT32 num_errors
Definition: scrub.h:47
void CALLBACK StartScrubW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: scrub.cpp:610
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
struct btrfs_scrub_error::@624::@626 data
#define PBM_SETRANGE32
Definition: commctrl.h:2158
#define TRUE
Definition: types.h:120
void StartScrub(HWND hwndDlg)
Definition: scrub.cpp:414
#define BTRFS_SCRUB_STOPPED
Definition: btrfsioctl.h:188
#define IDOK
Definition: winuser.h:824
void format_size(UINT64 size, WCHAR *s, ULONG len, BOOL show_bytes)
Definition: main.cpp:126
#define CloseHandle
Definition: compat.h:398
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define IDC_SCRUB_PROGRESS
Definition: resource.h:301
LARGE_INTEGER start_time
Definition: btrfsioctl.h:218
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define IDS_SCRUB_MSG_STARTED
Definition: resource.h:107
#define IDS_SCRUB_MSG_RECOVERABLE_DATA
Definition: resource.h:108
void StopScrub(HWND hwndDlg)
Definition: scrub.cpp:489
#define BTRFS_SCRUB_PAUSED
Definition: btrfsioctl.h:190
#define IDS_SCRUB_MSG_UNRECOVERABLE_DATA_SUBVOL
Definition: resource.h:111
INT_PTR CALLBACK ScrubDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrub.cpp:513
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define IDD_SCRUB
Definition: resource.h:82
#define LOCALE_USER_DEFAULT
#define DATE_SHORTDATE
Definition: winnls.h:193
WCHAR fn[MAX_PATH]
Definition: scrub.h:44
#define free
Definition: debug_ros.c:5
#define IDS_SCRUB_MSG_UNRECOVERABLE_METADATA_FIRSTITEM
Definition: resource.h:113
GLenum GLuint GLenum GLsizei const GLchar * message
Definition: glext.h:5579
#define CALLBACK
Definition: compat.h:27
UINT uMsg
Definition: precomp.h:45
void ShowNtStatusError(HWND hwnd, NTSTATUS Status)
Definition: main.cpp:89
#define IDS_SCRUB_MSG_UNRECOVERABLE_DATA
Definition: resource.h:110
GLdouble GLdouble t
Definition: gl.h:2047
HANDLE HWND
Definition: compat.h:13
$ULONG PrivilegeCount
Definition: setypes.h:969
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define PBM_SETPOS
Definition: commctrl.h:2154
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)
GLenum GLclampf GLint GLenum GLuint GLenum GLenum GLsizei GLenum const GLvoid GLfloat GLfloat GLfloat GLfloat GLclampd GLint 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 GLboolean GLboolean GLboolean GLint GLenum GLsizei const GLvoid GLenum GLint GLenum GLint GLint GLsizei GLint GLenum GLint GLint GLint GLint GLsizei GLenum GLsizei const GLuint GLboolean GLenum GLenum GLint GLsizei GLenum GLsizei GLenum const GLvoid GLboolean const GLboolean GLenum const GLdouble * u
Definition: glfuncs.h:88
#define IDC_CANCEL_SCRUB
Definition: resource.h:300
BOOL WINAPI SetWindowTextW(_In_ HWND, _In_opt_ LPCWSTR)
GLuint GLuint end
Definition: gl.h:1545
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2630
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
void ShowError(HWND hwnd, ULONG err)
Definition: main.cpp:49
int32_t INT_PTR
Definition: typedefs.h:62
#define IDS_SCRUB_MSG_UNRECOVERABLE_METADATA
Definition: resource.h:112
#define WCHAR
Definition: msvc.h:43
void CALLBACK StopScrubW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: scrub.cpp:658
#define BTRFS_BALANCE_RUNNING
Definition: btrfsioctl.h:154
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define STRSAFE_E_INSUFFICIENT_BUFFER
Definition: strsafe.h:103
#define SetWindowLongPtr
Definition: treelist.c:70
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
UINT_PTR WPARAM
Definition: windef.h:207
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
BOOL WINAPI SystemTimeToTzSpecificLocalTime(CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation, CONST SYSTEMTIME *lpUniversalTime, LPSYSTEMTIME lpLocalTime)
Definition: timezone.c:377
void ShowStringError(HWND hwndDlg, int num,...)
Definition: main.cpp:63
#define FILE_TRAVERSE
Definition: nt_native.h:643
DWORD dwHighDateTime
Definition: mapidefs.h:66
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
#define FALSE
Definition: types.h:117
#define IDS_SCRUB_FAILED
Definition: resource.h:120
#define IDS_SCRUB_MSG_SUMMARY_ERRORS_UNRECOVERABLE
Definition: resource.h:119
LONG_PTR LPARAM
Definition: windef.h:208
#define GWLP_USERDATA
Definition: treelist.c:63
LPWSTR *WINAPI CommandLineToArgvW(LPCWSTR lpCmdline, int *numargs)
Definition: shell32_main.c:76
smooth NULL
Definition: ftsmooth.c:416
#define IDS_SCRUB_MSG_SUMMARY_ERRORS_RECOVERABLE
Definition: resource.h:118
#define IDS_SCRUB_RUNNING
Definition: resource.h:104
#define IDC_SCRUB_INFO
Definition: resource.h:295
#define FSCTL_BTRFS_PAUSE_SCRUB
Definition: btrfsioctl.h:26
#define IDS_SCRUB_PAUSED
Definition: resource.h:106
#define OPEN_EXISTING
Definition: compat.h:426
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
void PauseScrub(HWND hwndDlg)
Definition: scrub.cpp:453
int token
Definition: lex.c:71
BOOL WINAPI FileTimeToSystemTime(IN CONST FILETIME *lpFileTime, OUT LPSYSTEMTIME lpSystemTime)
Definition: time.c:178
unsigned int BOOL
Definition: ntddk_ex.h:94
#define IDS_NO_SCRUB
Definition: resource.h:103
LONG NTSTATUS
Definition: precomp.h:26
#define FSCTL_BTRFS_RESUME_SCRUB
Definition: btrfsioctl.h:27
#define TOKEN_QUERY
Definition: setypes.h:874
UINT64 chunks_left
Definition: scrub.h:46
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:24
UINT WPARAM wParam
Definition: precomp.h:45
#define WM_TIMER
Definition: winuser.h:1718
#define FSCTL_BTRFS_QUERY_SCRUB
Definition: btrfsioctl.h:25
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
UINT64 data_scrubbed
Definition: btrfsioctl.h:222
#define BN_CLICKED
Definition: winuser.h:1886
#define IDC_START_SCRUB
Definition: resource.h:297
HANDLE HINSTANCE
Definition: typedefs.h:75
void UpdateTextBox(HWND hwndDlg, btrfs_query_scrub *bqs)
Definition: scrub.cpp:46
#define FSCTL_BTRFS_START_SCRUB
Definition: btrfsioctl.h:24
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1087
ULONG LowPart
Definition: typedefs.h:104
GLdouble s
Definition: gl.h:2039
GLenum GLsizei len
Definition: glext.h:6722
Definition: time.h:76
#define WM_COMMAND
Definition: winuser.h:1716
#define IDC_SCRUB_STATUS
Definition: resource.h:302
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:372
INT WINAPI GetDateFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpDateStr, INT cchOut)
Definition: lcformat.c:916
Status
Definition: gdiplustypes.h:24
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
DWORD *typedef HANDLE
Definition: winlogon.h:61
#define IDS_SCRUB_MSG_RECOVERABLE_PARITY
Definition: resource.h:122
#define FSCTL_BTRFS_STOP_SCRUB
Definition: btrfsioctl.h:28
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:49
HLOCAL NTAPI LocalFree(HLOCAL hMem)
Definition: heapmem.c:1577
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
LARGE_INTEGER finish_time
Definition: btrfsioctl.h:219
STRSAFEAPI StringCchPrintfW(STRSAFE_LPWSTR pszDest, size_t cchDest, STRSAFE_LPCWSTR pszFormat,...)
Definition: strsafe.h:530
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
UINT WPARAM LPARAM lParam
Definition: precomp.h:45
unsigned int UINT
Definition: ndis.h:50
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:292
#define IDS_SCRUB_MSG_FINISHED
Definition: resource.h:114
LUID_AND_ATTRIBUTES Privileges[ANYSIZE_ARRAY]
Definition: setypes.h:970
#define CreateFileW
Definition: compat.h:400
#define IDC_PAUSE_SCRUB
Definition: resource.h:299
#define IDS_SCRUB_BALANCE_RUNNING
Definition: resource.h:117
void RefreshScrubDlg(HWND hwndDlg, BOOL first_time)
Definition: scrub.cpp:311
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FILE_FLAG_OPEN_REPARSE_POINT
Definition: disk.h:39
struct btrfs_scrub_error::@624::@627 metadata
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
static HINSTANCE hinst
Definition: edit.c:551
#define malloc
Definition: debug_ros.c:4
static INT_PTR CALLBACK stub_ScrubDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrub.cpp:553
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define GetWindowLongPtr
Definition: treelist.c:73
#define IDS_SCRUB_FINISHED
Definition: resource.h:105
unsigned long long UINT64
#define IDCANCEL
Definition: winuser.h:825
#define IDS_SCRUB_MSG_RECOVERABLE_METADATA
Definition: resource.h:109
#define BTRFS_BALANCE_PAUSED
Definition: btrfsioctl.h:155
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
return STATUS_SUCCESS
Definition: btrfs.c:2710
INT WINAPI GetTimeFormatW(LCID lcid, DWORD dwFlags, const SYSTEMTIME *lpTime, LPCWSTR lpFormat, LPWSTR lpTimeStr, INT cchOut)
Definition: lcformat.c:1016
unsigned char UINT8
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
#define args
Definition: format.c:66
void set_dpi_aware()
Definition: main.cpp:111
void CALLBACK ShowScrubW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
Definition: scrub.cpp:573
#define WM_INITDIALOG
Definition: winuser.h:1715
#define LOWORD(l)
Definition: pedump.c:82
#define IDS_SCRUB_MSG_SUMMARY
Definition: resource.h:115
DWORD dwLowDateTime
Definition: mapidefs.h:65
LONGLONG QuadPart
Definition: typedefs.h:112
#define STATUS_DEVICE_NOT_READY
Definition: shellext.h:53
Definition: ps.c:97