balance.cpp (71ac5e6c) balance.cpp (7b718d36)
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.

--- 28 unchanged lines hidden (view full) ---

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
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.

--- 28 unchanged lines hidden (view full) ---

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
45static UINT64 convtypes2[] = { BLOCK_FLAG_SINGLE, BLOCK_FLAG_DUPLICATE, BLOCK_FLAG_RAID0, BLOCK_FLAG_RAID1, BLOCK_FLAG_RAID5, BLOCK_FLAG_RAID6, BLOCK_FLAG_RAID10 };
45static uint64_t convtypes2[] = { BLOCK_FLAG_SINGLE, BLOCK_FLAG_DUPLICATE, BLOCK_FLAG_RAID0, BLOCK_FLAG_RAID1, BLOCK_FLAG_RAID5, BLOCK_FLAG_RAID6, BLOCK_FLAG_RAID10 };
46
46
47static WCHAR hex_digit(UINT8 u) {
47static WCHAR hex_digit(uint8_t u) {
48 if (u >= 0xa && u <= 0xf)
48 if (u >= 0xa && u <= 0xf)
49 return u - 0xa + 'a';
49 return (uint8_t)(u - 0xa + 'a');
50 else
50 else
51 return u + '0';
51 return (uint8_t)(u + '0');
52}
53
54static void serialize(void* data, ULONG len, WCHAR* s) {
52}
53
54static void serialize(void* data, ULONG len, WCHAR* s) {
55 UINT8* d;
55 uint8_t* d;
56
56
57 d = (UINT8*)data;
57 d = (uint8_t*)data;
58
58
59 while (TRUE) {
60 *s = hex_digit(*d >> 4); s++;
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
73void BtrfsBalance::StartBalance(HWND hwndDlg) {
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
73void BtrfsBalance::StartBalance(HWND hwndDlg) {
74 WCHAR t[MAX_PATH + 600], u[600];
74 wstring t;
75 WCHAR modfn[MAX_PATH], u[600];
75 SHELLEXECUTEINFOW sei;
76 btrfs_start_balance bsb;
77
76 SHELLEXECUTEINFOW sei;
77 btrfs_start_balance bsb;
78
78 t[0] = '"';
79 GetModuleFileNameW(module, t + 1, (sizeof(t) / sizeof(WCHAR)) - 1);
80 wcscat(t, L"\",StartBalance ");
81 wcscat(t, fn);
82 wcscat(t, L" ");
79 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
83
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
84 RtlCopyMemory(&bsb.opts[0], &data_opts, sizeof(btrfs_balance_opts));
85 RtlCopyMemory(&bsb.opts[1], &metadata_opts, sizeof(btrfs_balance_opts));
86 RtlCopyMemory(&bsb.opts[2], &system_opts, sizeof(btrfs_balance_opts));
87
88 if (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED)
89 bsb.opts[0].flags |= BTRFS_BALANCE_OPTS_ENABLED;
90 else
91 bsb.opts[0].flags &= ~BTRFS_BALANCE_OPTS_ENABLED;

--- 4 unchanged lines hidden (view full) ---

96 bsb.opts[1].flags &= ~BTRFS_BALANCE_OPTS_ENABLED;
97
98 if (IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED)
99 bsb.opts[2].flags |= BTRFS_BALANCE_OPTS_ENABLED;
100 else
101 bsb.opts[2].flags &= ~BTRFS_BALANCE_OPTS_ENABLED;
102
103 serialize(&bsb, sizeof(btrfs_start_balance), u);
87 RtlCopyMemory(&bsb.opts[0], &data_opts, sizeof(btrfs_balance_opts));
88 RtlCopyMemory(&bsb.opts[1], &metadata_opts, sizeof(btrfs_balance_opts));
89 RtlCopyMemory(&bsb.opts[2], &system_opts, sizeof(btrfs_balance_opts));
90
91 if (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED)
92 bsb.opts[0].flags |= BTRFS_BALANCE_OPTS_ENABLED;
93 else
94 bsb.opts[0].flags &= ~BTRFS_BALANCE_OPTS_ENABLED;

--- 4 unchanged lines hidden (view full) ---

99 bsb.opts[1].flags &= ~BTRFS_BALANCE_OPTS_ENABLED;
100
101 if (IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED)
102 bsb.opts[2].flags |= BTRFS_BALANCE_OPTS_ENABLED;
103 else
104 bsb.opts[2].flags &= ~BTRFS_BALANCE_OPTS_ENABLED;
105
106 serialize(&bsb, sizeof(btrfs_start_balance), u);
104 wcscat(t, u);
105
107
108 t += u;
109
106 RtlZeroMemory(&sei, sizeof(sei));
107
108 sei.cbSize = sizeof(sei);
109 sei.hwnd = hwndDlg;
110 sei.lpVerb = L"runas";
111 sei.lpFile = L"rundll32.exe";
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";
112 sei.lpParameters = t;
116 sei.lpParameters = t.c_str();
113 sei.nShow = SW_SHOW;
114 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
115
117 sei.nShow = SW_SHOW;
118 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
119
116 if (!ShellExecuteExW(&sei)) {
117 ShowError(hwndDlg, GetLastError());
118 return;
119 }
120 if (!ShellExecuteExW(&sei))
121 throw last_error(GetLastError());
120
122
121 cancelling = FALSE;
122 removing = FALSE;
123 shrinking = FALSE;
123 cancelling = false;
124 removing = false;
125 shrinking = false;
124 balance_status = BTRFS_BALANCE_RUNNING;
125
126 balance_status = BTRFS_BALANCE_RUNNING;
127
126 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), TRUE);
127 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), TRUE);
128 EnableWindow(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), TRUE);
129 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), FALSE);
130 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), FALSE);
131 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), FALSE);
132 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), data_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? TRUE : FALSE);
133 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), metadata_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? TRUE : FALSE);
134 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), system_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? TRUE : FALSE);
128 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), true);
129 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), true);
130 EnableWindow(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), true);
131 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), false);
132 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), false);
133 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), false);
134 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), data_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? true : false);
135 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), metadata_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? true : false);
136 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), system_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? true : false);
135
137
136 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), FALSE);
138 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), false);
137
138 WaitForSingleObject(sei.hProcess, INFINITE);
139 CloseHandle(sei.hProcess);
140}
141
142void BtrfsBalance::PauseBalance(HWND hwndDlg) {
139
140 WaitForSingleObject(sei.hProcess, INFINITE);
141 CloseHandle(sei.hProcess);
142}
143
144void BtrfsBalance::PauseBalance(HWND hwndDlg) {
143 WCHAR t[MAX_PATH + 100];
145 WCHAR modfn[MAX_PATH];
146 wstring t;
144 SHELLEXECUTEINFOW sei;
145
147 SHELLEXECUTEINFOW sei;
148
146 t[0] = '"';
147 GetModuleFileNameW(module, t + 1, (sizeof(t) / sizeof(WCHAR)) - 1);
148 wcscat(t, L"\",PauseBalance ");
149 wcscat(t, fn);
149 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
150
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
151 RtlZeroMemory(&sei, sizeof(sei));
152
153 sei.cbSize = sizeof(sei);
154 sei.hwnd = hwndDlg;
155 sei.lpVerb = L"runas";
156 sei.lpFile = L"rundll32.exe";
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";
157 sei.lpParameters = t;
163 sei.lpParameters = t.c_str();
158 sei.nShow = SW_SHOW;
159 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
160
164 sei.nShow = SW_SHOW;
165 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
166
161 if (!ShellExecuteExW(&sei)) {
162 ShowError(hwndDlg, GetLastError());
163 return;
164 }
167 if (!ShellExecuteExW(&sei))
168 throw last_error(GetLastError());
165
166 WaitForSingleObject(sei.hProcess, INFINITE);
167 CloseHandle(sei.hProcess);
168}
169
170void BtrfsBalance::StopBalance(HWND hwndDlg) {
169
170 WaitForSingleObject(sei.hProcess, INFINITE);
171 CloseHandle(sei.hProcess);
172}
173
174void BtrfsBalance::StopBalance(HWND hwndDlg) {
171 WCHAR t[MAX_PATH + 100];
175 WCHAR modfn[MAX_PATH];
176 wstring t;
172 SHELLEXECUTEINFOW sei;
173
177 SHELLEXECUTEINFOW sei;
178
174 t[0] = '"';
175 GetModuleFileNameW(module, t + 1, (sizeof(t) / sizeof(WCHAR)) - 1);
176 wcscat(t, L"\",StopBalance ");
177 wcscat(t, fn);
179 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
178
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
179 RtlZeroMemory(&sei, sizeof(sei));
180
181 sei.cbSize = sizeof(sei);
182 sei.hwnd = hwndDlg;
183 sei.lpVerb = L"runas";
184 sei.lpFile = L"rundll32.exe";
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";
185 sei.lpParameters = t;
193 sei.lpParameters = t.c_str();
186 sei.nShow = SW_SHOW;
187 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
188
194 sei.nShow = SW_SHOW;
195 sei.fMask = SEE_MASK_NOCLOSEPROCESS;
196
189 if (!ShellExecuteExW(&sei)) {
190 ShowError(hwndDlg, GetLastError());
191 return;
192 }
197 if (!ShellExecuteExW(&sei))
198 throw last_error(GetLastError());
193
199
194 cancelling = TRUE;
200 cancelling = true;
195
196 WaitForSingleObject(sei.hProcess, INFINITE);
197 CloseHandle(sei.hProcess);
198}
199
201
202 WaitForSingleObject(sei.hProcess, INFINITE);
203 CloseHandle(sei.hProcess);
204}
205
200void BtrfsBalance::RefreshBalanceDlg(HWND hwndDlg, BOOL first) {
201 HANDLE h;
202 BOOL balancing = FALSE;
203 WCHAR s[255], t[255];
206void BtrfsBalance::RefreshBalanceDlg(HWND hwndDlg, bool first) {
207 bool balancing = false;
208 wstring s, t;
204
209
205 h = CreateFileW(fn, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
206 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
207 if (h != INVALID_HANDLE_VALUE) {
208 NTSTATUS Status;
209 IO_STATUS_BLOCK iosb;
210 {
211 win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
212 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
210
213
211 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_BALANCE, NULL, 0, &bqb, sizeof(btrfs_query_balance));
214 if (h != INVALID_HANDLE_VALUE) {
215 NTSTATUS Status;
216 IO_STATUS_BLOCK iosb;
212
217
213 if (!NT_SUCCESS(Status)) {
214 ShowNtStatusError(hwndDlg, Status);
215 CloseHandle(h);
216 return;
217 }
218 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_QUERY_BALANCE, nullptr, 0, &bqb, sizeof(btrfs_query_balance));
218
219
219 CloseHandle(h);
220 } else {
221 ShowError(hwndDlg, GetLastError());
222 return;
220 if (!NT_SUCCESS(Status))
221 throw ntstatus_error(Status);
222 } else
223 throw last_error(GetLastError());
223 }
224
225 if (cancelling)
226 bqb.status = BTRFS_BALANCE_STOPPED;
227
228 balancing = bqb.status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED);
229
230 if (!balancing) {
231 if (first || balance_status != BTRFS_BALANCE_STOPPED) {
232 int resid;
233
224 }
225
226 if (cancelling)
227 bqb.status = BTRFS_BALANCE_STOPPED;
228
229 balancing = bqb.status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED);
230
231 if (!balancing) {
232 if (first || balance_status != BTRFS_BALANCE_STOPPED) {
233 int resid;
234
234 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), FALSE);
235 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), FALSE);
235 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), false);
236 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), false);
236 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
237 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
237 EnableWindow(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), FALSE);
238 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), TRUE);
239 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), TRUE);
240 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), TRUE);
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);
241
242 if (balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED)) {
243 CheckDlgButton(hwndDlg, IDC_DATA, BST_UNCHECKED);
244 CheckDlgButton(hwndDlg, IDC_METADATA, BST_UNCHECKED);
245 CheckDlgButton(hwndDlg, IDC_SYSTEM, BST_UNCHECKED);
246
247 SendMessage(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETPOS, 0, 0);
248 }
249
242
243 if (balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED)) {
244 CheckDlgButton(hwndDlg, IDC_DATA, BST_UNCHECKED);
245 CheckDlgButton(hwndDlg, IDC_METADATA, BST_UNCHECKED);
246 CheckDlgButton(hwndDlg, IDC_SYSTEM, BST_UNCHECKED);
247
248 SendMessage(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETPOS, 0, 0);
249 }
250
250 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ? TRUE : FALSE);
251 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED ? TRUE : FALSE);
252 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED ? TRUE : FALSE);
251 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ? true : false);
252 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED ? true : false);
253 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED ? true : false);
253
254 if (bqb.status & BTRFS_BALANCE_ERROR) {
255 if (removing)
256 resid = IDS_BALANCE_FAILED_REMOVAL;
257 else if (shrinking)
258 resid = IDS_BALANCE_FAILED_SHRINK;
259 else
260 resid = IDS_BALANCE_FAILED;
261
254
255 if (bqb.status & BTRFS_BALANCE_ERROR) {
256 if (removing)
257 resid = IDS_BALANCE_FAILED_REMOVAL;
258 else if (shrinking)
259 resid = IDS_BALANCE_FAILED_SHRINK;
260 else
261 resid = IDS_BALANCE_FAILED;
262
262 if (!LoadStringW(module, resid, s, sizeof(s) / sizeof(WCHAR))) {
263 ShowError(hwndDlg, GetLastError());
264 return;
265 }
263 if (!load_string(module, resid, s))
264 throw last_error(GetLastError());
266
265
267 if (StringCchPrintfW(t, sizeof(t) / sizeof(WCHAR), s, bqb.error, format_ntstatus(bqb.error).c_str()) == STRSAFE_E_INSUFFICIENT_BUFFER)
268 return;
266 wstring_sprintf(t, s, bqb.error, format_ntstatus(bqb.error).c_str());
269
267
270 SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, t);
268 SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, t.c_str());
271 } else {
272 if (cancelling)
273 resid = removing ? IDS_BALANCE_CANCELLED_REMOVAL : (shrinking ? IDS_BALANCE_CANCELLED_SHRINK : IDS_BALANCE_CANCELLED);
274 else if (balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED))
275 resid = removing ? IDS_BALANCE_COMPLETE_REMOVAL : (shrinking ? IDS_BALANCE_COMPLETE_SHRINK : IDS_BALANCE_COMPLETE);
276 else
277 resid = IDS_NO_BALANCE;
278
269 } else {
270 if (cancelling)
271 resid = removing ? IDS_BALANCE_CANCELLED_REMOVAL : (shrinking ? IDS_BALANCE_CANCELLED_SHRINK : IDS_BALANCE_CANCELLED);
272 else if (balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED))
273 resid = removing ? IDS_BALANCE_COMPLETE_REMOVAL : (shrinking ? IDS_BALANCE_COMPLETE_SHRINK : IDS_BALANCE_COMPLETE);
274 else
275 resid = IDS_NO_BALANCE;
276
279 if (!LoadStringW(module, resid, s, sizeof(s) / sizeof(WCHAR))) {
280 ShowError(hwndDlg, GetLastError());
281 return;
282 }
277 if (!load_string(module, resid, s))
278 throw last_error(GetLastError());
283
279
284 SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, s);
280 SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, s.c_str());
285 }
286
287 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
281 }
282
283 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
288 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? TRUE: FALSE);
284 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
289
290 balance_status = bqb.status;
285
286 balance_status = bqb.status;
291 cancelling = FALSE;
287 cancelling = false;
292 }
293
294 return;
295 }
296
297 if (first || !(balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED))) {
288 }
289
290 return;
291 }
292
293 if (first || !(balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED))) {
298 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), TRUE);
299 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), TRUE);
300 EnableWindow(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), TRUE);
301 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), FALSE);
302 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), FALSE);
303 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), FALSE);
294 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), true);
295 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), true);
296 EnableWindow(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), true);
297 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA), false);
298 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA), false);
299 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM), false);
304
305 CheckDlgButton(hwndDlg, IDC_DATA, bqb.data_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? BST_CHECKED : BST_UNCHECKED);
306 CheckDlgButton(hwndDlg, IDC_METADATA, bqb.metadata_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? BST_CHECKED : BST_UNCHECKED);
307 CheckDlgButton(hwndDlg, IDC_SYSTEM, bqb.system_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? BST_CHECKED : BST_UNCHECKED);
308
300
301 CheckDlgButton(hwndDlg, IDC_DATA, bqb.data_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? BST_CHECKED : BST_UNCHECKED);
302 CheckDlgButton(hwndDlg, IDC_METADATA, bqb.metadata_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? BST_CHECKED : BST_UNCHECKED);
303 CheckDlgButton(hwndDlg, IDC_SYSTEM, bqb.system_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? BST_CHECKED : BST_UNCHECKED);
304
309 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), bqb.data_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? TRUE : FALSE);
310 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), bqb.metadata_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? TRUE : FALSE);
311 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), bqb.system_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? TRUE : FALSE);
305 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), bqb.data_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? true : false);
306 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), bqb.metadata_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? true : false);
307 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), bqb.system_opts.flags & BTRFS_BALANCE_OPTS_ENABLED ? true : false);
312
308
313 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), FALSE);
309 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), false);
314 }
315
316 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETRANGE32, 0, (LPARAM)bqb.total_chunks);
317 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETPOS, (WPARAM)(bqb.total_chunks - bqb.chunks_left), 0);
318
319 if (bqb.status & BTRFS_BALANCE_PAUSED && balance_status != bqb.status)
320 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_PAUSED, 0);
321 else if (!(bqb.status & BTRFS_BALANCE_PAUSED) && balance_status & BTRFS_BALANCE_PAUSED)
322 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
323
324 balance_status = bqb.status;
325
326 if (bqb.status & BTRFS_BALANCE_REMOVAL) {
310 }
311
312 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETRANGE32, 0, (LPARAM)bqb.total_chunks);
313 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETPOS, (WPARAM)(bqb.total_chunks - bqb.chunks_left), 0);
314
315 if (bqb.status & BTRFS_BALANCE_PAUSED && balance_status != bqb.status)
316 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_PAUSED, 0);
317 else if (!(bqb.status & BTRFS_BALANCE_PAUSED) && balance_status & BTRFS_BALANCE_PAUSED)
318 SendMessageW(GetDlgItem(hwndDlg, IDC_BALANCE_PROGRESS), PBM_SETSTATE, PBST_NORMAL, 0);
319
320 balance_status = bqb.status;
321
322 if (bqb.status & BTRFS_BALANCE_REMOVAL) {
327 if (!LoadStringW(module, balance_status & BTRFS_BALANCE_PAUSED ? IDS_BALANCE_PAUSED_REMOVAL : IDS_BALANCE_RUNNING_REMOVAL, s, sizeof(s) / sizeof(WCHAR))) {
328 ShowError(hwndDlg, GetLastError());
329 return;
330 }
323 if (!load_string(module, balance_status & BTRFS_BALANCE_PAUSED ? IDS_BALANCE_PAUSED_REMOVAL : IDS_BALANCE_RUNNING_REMOVAL, s))
324 throw last_error(GetLastError());
331
325
332 if (StringCchPrintfW(t, sizeof(t) / sizeof(WCHAR), s, bqb.data_opts.devid, bqb.total_chunks - bqb.chunks_left,
333 bqb.total_chunks, (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks) == STRSAFE_E_INSUFFICIENT_BUFFER)
334 return;
326 wstring_sprintf(t, s, bqb.data_opts.devid, bqb.total_chunks - bqb.chunks_left, bqb.total_chunks,
327 (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks);
335
328
336 removing = TRUE;
337 shrinking = FALSE;
329 removing = true;
330 shrinking = false;
338 } else if (bqb.status & BTRFS_BALANCE_SHRINKING) {
331 } else if (bqb.status & BTRFS_BALANCE_SHRINKING) {
339 if (!LoadStringW(module, balance_status & BTRFS_BALANCE_PAUSED ? IDS_BALANCE_PAUSED_SHRINK : IDS_BALANCE_RUNNING_SHRINK, s, sizeof(s) / sizeof(WCHAR))) {
340 ShowError(hwndDlg, GetLastError());
341 return;
342 }
332 if (!load_string(module, balance_status & BTRFS_BALANCE_PAUSED ? IDS_BALANCE_PAUSED_SHRINK : IDS_BALANCE_RUNNING_SHRINK, s))
333 throw last_error(GetLastError());
343
334
344 if (StringCchPrintfW(t, sizeof(t) / sizeof(WCHAR), s, bqb.data_opts.devid, bqb.total_chunks - bqb.chunks_left,
345 bqb.total_chunks, (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks) == STRSAFE_E_INSUFFICIENT_BUFFER)
346 return;
335 wstring_sprintf(t, s, bqb.data_opts.devid, bqb.total_chunks - bqb.chunks_left, bqb.total_chunks,
336 (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks);
347
337
348 removing = FALSE;
349 shrinking = TRUE;
338 removing = false;
339 shrinking = true;
350 } else {
340 } else {
351 if (!LoadStringW(module, balance_status & BTRFS_BALANCE_PAUSED ? IDS_BALANCE_PAUSED : IDS_BALANCE_RUNNING, s, sizeof(s) / sizeof(WCHAR))) {
352 ShowError(hwndDlg, GetLastError());
353 return;
354 }
341 if (!load_string(module, balance_status & BTRFS_BALANCE_PAUSED ? IDS_BALANCE_PAUSED : IDS_BALANCE_RUNNING, s))
342 throw last_error(GetLastError());
355
343
356 if (StringCchPrintfW(t, sizeof(t) / sizeof(WCHAR), s, bqb.total_chunks - bqb.chunks_left,
357 bqb.total_chunks, (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks) == STRSAFE_E_INSUFFICIENT_BUFFER)
358 return;
344 wstring_sprintf(t, s, bqb.total_chunks - bqb.chunks_left, bqb.total_chunks,
345 (float)(bqb.total_chunks - bqb.chunks_left) * 100.0f / (float)bqb.total_chunks);
359
346
360 removing = FALSE;
361 shrinking = FALSE;
347 removing = false;
348 shrinking = false;
362 }
363
349 }
350
364 SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, t);
351 SetDlgItemTextW(hwndDlg, IDC_BALANCE_STATUS, t.c_str());
365}
366
367void BtrfsBalance::SaveBalanceOpts(HWND hwndDlg) {
368 btrfs_balance_opts* opts;
369
370 switch (opts_type) {
371 case 1:
372 opts = &data_opts;

--- 33 unchanged lines hidden (view full) ---

406 sel = SendMessageW(GetDlgItem(hwndDlg, IDC_DEVID_COMBO), CB_GETCURSEL, 0, 0);
407
408 if (sel == CB_ERR)
409 opts->flags &= ~BTRFS_BALANCE_OPTS_DEVID;
410 else {
411 btrfs_device* bd = devices;
412 int i = 0;
413
352}
353
354void BtrfsBalance::SaveBalanceOpts(HWND hwndDlg) {
355 btrfs_balance_opts* opts;
356
357 switch (opts_type) {
358 case 1:
359 opts = &data_opts;

--- 33 unchanged lines hidden (view full) ---

393 sel = SendMessageW(GetDlgItem(hwndDlg, IDC_DEVID_COMBO), CB_GETCURSEL, 0, 0);
394
395 if (sel == CB_ERR)
396 opts->flags &= ~BTRFS_BALANCE_OPTS_DEVID;
397 else {
398 btrfs_device* bd = devices;
399 int i = 0;
400
414 while (TRUE) {
401 while (true) {
415 if (i == sel) {
416 opts->devid = bd->dev_id;
417 break;
418 }
419
420 i++;
421
422 if (bd->next_entry > 0)
402 if (i == sel) {
403 opts->devid = bd->dev_id;
404 break;
405 }
406
407 i++;
408
409 if (bd->next_entry > 0)
423 bd = (btrfs_device*)((UINT8*)bd + bd->next_entry);
410 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
424 else
425 break;
426 }
427
428 if (opts->devid == 0)
429 opts->flags &= ~BTRFS_BALANCE_OPTS_DEVID;
430 }
431 }

--- 4 unchanged lines hidden (view full) ---

436 opts->flags |= BTRFS_BALANCE_OPTS_DRANGE;
437
438 GetWindowTextW(GetDlgItem(hwndDlg, IDC_DRANGE_START), s, sizeof(s) / sizeof(WCHAR));
439 opts->drange_start = _wtoi64(s);
440
441 GetWindowTextW(GetDlgItem(hwndDlg, IDC_DRANGE_END), s, sizeof(s) / sizeof(WCHAR));
442 opts->drange_end = _wtoi64(s);
443
411 else
412 break;
413 }
414
415 if (opts->devid == 0)
416 opts->flags &= ~BTRFS_BALANCE_OPTS_DEVID;
417 }
418 }

--- 4 unchanged lines hidden (view full) ---

423 opts->flags |= BTRFS_BALANCE_OPTS_DRANGE;
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
444 if (opts->drange_end < opts->drange_start) {
445 ShowStringError(hwndDlg, IDS_DRANGE_END_BEFORE_START);
446 return;
447 }
431 if (opts->drange_end < opts->drange_start)
432 throw string_error(IDS_DRANGE_END_BEFORE_START);
448 }
449
450 if (IsDlgButtonChecked(hwndDlg, IDC_VRANGE) == BST_CHECKED) {
451 WCHAR s[255];
452
453 opts->flags |= BTRFS_BALANCE_OPTS_VRANGE;
454
455 GetWindowTextW(GetDlgItem(hwndDlg, IDC_VRANGE_START), s, sizeof(s) / sizeof(WCHAR));
456 opts->vrange_start = _wtoi64(s);
457
458 GetWindowTextW(GetDlgItem(hwndDlg, IDC_VRANGE_END), s, sizeof(s) / sizeof(WCHAR));
459 opts->vrange_end = _wtoi64(s);
460
433 }
434
435 if (IsDlgButtonChecked(hwndDlg, IDC_VRANGE) == BST_CHECKED) {
436 WCHAR s[255];
437
438 opts->flags |= BTRFS_BALANCE_OPTS_VRANGE;
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
461 if (opts->vrange_end < opts->vrange_start) {
462 ShowStringError(hwndDlg, IDS_VRANGE_END_BEFORE_START);
463 return;
464 }
446 if (opts->vrange_end < opts->vrange_start)
447 throw string_error(IDS_VRANGE_END_BEFORE_START);
465 }
466
467 if (IsDlgButtonChecked(hwndDlg, IDC_LIMIT) == BST_CHECKED) {
468 WCHAR s[255];
469
470 opts->flags |= BTRFS_BALANCE_OPTS_LIMIT;
471
472 GetWindowTextW(GetDlgItem(hwndDlg, IDC_LIMIT_START), s, sizeof(s) / sizeof(WCHAR));
473 opts->limit_start = _wtoi64(s);
474
475 GetWindowTextW(GetDlgItem(hwndDlg, IDC_LIMIT_END), s, sizeof(s) / sizeof(WCHAR));
476 opts->limit_end = _wtoi64(s);
477
448 }
449
450 if (IsDlgButtonChecked(hwndDlg, IDC_LIMIT) == BST_CHECKED) {
451 WCHAR s[255];
452
453 opts->flags |= BTRFS_BALANCE_OPTS_LIMIT;
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
478 if (opts->limit_end < opts->limit_start) {
479 ShowStringError(hwndDlg, IDS_LIMIT_END_BEFORE_START);
480 return;
481 }
461 if (opts->limit_end < opts->limit_start)
462 throw string_error(IDS_LIMIT_END_BEFORE_START);
482 }
483
484 if (IsDlgButtonChecked(hwndDlg, IDC_STRIPES) == BST_CHECKED) {
485 WCHAR s[255];
486
487 opts->flags |= BTRFS_BALANCE_OPTS_STRIPES;
488
489 GetWindowTextW(GetDlgItem(hwndDlg, IDC_STRIPES_START), s, sizeof(s) / sizeof(WCHAR));
463 }
464
465 if (IsDlgButtonChecked(hwndDlg, IDC_STRIPES) == BST_CHECKED) {
466 WCHAR s[255];
467
468 opts->flags |= BTRFS_BALANCE_OPTS_STRIPES;
469
470 GetWindowTextW(GetDlgItem(hwndDlg, IDC_STRIPES_START), s, sizeof(s) / sizeof(WCHAR));
490 opts->stripes_start = _wtoi(s);
471 opts->stripes_start = (uint8_t)_wtoi(s);
491
492 GetWindowTextW(GetDlgItem(hwndDlg, IDC_STRIPES_END), s, sizeof(s) / sizeof(WCHAR));
472
473 GetWindowTextW(GetDlgItem(hwndDlg, IDC_STRIPES_END), s, sizeof(s) / sizeof(WCHAR));
493 opts->stripes_end = _wtoi(s);
474 opts->stripes_end = (uint8_t)_wtoi(s);
494
475
495 if (opts->stripes_end < opts->stripes_start) {
496 ShowStringError(hwndDlg, IDS_STRIPES_END_BEFORE_START);
497 return;
498 }
476 if (opts->stripes_end < opts->stripes_start)
477 throw string_error(IDS_STRIPES_END_BEFORE_START);
499 }
500
501 if (IsDlgButtonChecked(hwndDlg, IDC_USAGE) == BST_CHECKED) {
502 WCHAR s[255];
503
504 opts->flags |= BTRFS_BALANCE_OPTS_USAGE;
505
506 GetWindowTextW(GetDlgItem(hwndDlg, IDC_USAGE_START), s, sizeof(s) / sizeof(WCHAR));
478 }
479
480 if (IsDlgButtonChecked(hwndDlg, IDC_USAGE) == BST_CHECKED) {
481 WCHAR s[255];
482
483 opts->flags |= BTRFS_BALANCE_OPTS_USAGE;
484
485 GetWindowTextW(GetDlgItem(hwndDlg, IDC_USAGE_START), s, sizeof(s) / sizeof(WCHAR));
507 opts->usage_start = _wtoi(s);
486 opts->usage_start = (uint8_t)_wtoi(s);
508
509 GetWindowTextW(GetDlgItem(hwndDlg, IDC_USAGE_END), s, sizeof(s) / sizeof(WCHAR));
487
488 GetWindowTextW(GetDlgItem(hwndDlg, IDC_USAGE_END), s, sizeof(s) / sizeof(WCHAR));
510 opts->usage_end = _wtoi(s);
489 opts->usage_end = (uint8_t)_wtoi(s);
511
490
512 if (opts->usage_end < opts->usage_start) {
513 ShowStringError(hwndDlg, IDS_USAGE_END_BEFORE_START);
514 return;
515 }
491 if (opts->usage_end < opts->usage_start)
492 throw string_error(IDS_USAGE_END_BEFORE_START);
516 }
517
518 if (IsDlgButtonChecked(hwndDlg, IDC_CONVERT) == BST_CHECKED) {
519 int sel;
520
521 opts->flags |= BTRFS_BALANCE_OPTS_CONVERT;
522
523 sel = SendMessageW(GetDlgItem(hwndDlg, IDC_CONVERT_COMBO), CB_GETCURSEL, 0, 0);

--- 6 unchanged lines hidden (view full) ---

530 if (IsDlgButtonChecked(hwndDlg, IDC_SOFT) == BST_CHECKED) opts->flags |= BTRFS_BALANCE_OPTS_SOFT;
531 }
532 }
533
534 EndDialog(hwndDlg, 0);
535}
536
537INT_PTR CALLBACK BtrfsBalance::BalanceOptsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
493 }
494
495 if (IsDlgButtonChecked(hwndDlg, IDC_CONVERT) == BST_CHECKED) {
496 int sel;
497
498 opts->flags |= BTRFS_BALANCE_OPTS_CONVERT;
499
500 sel = SendMessageW(GetDlgItem(hwndDlg, IDC_CONVERT_COMBO), CB_GETCURSEL, 0, 0);

--- 6 unchanged lines hidden (view full) ---

507 if (IsDlgButtonChecked(hwndDlg, IDC_SOFT) == BST_CHECKED) opts->flags |= BTRFS_BALANCE_OPTS_SOFT;
508 }
509 }
510
511 EndDialog(hwndDlg, 0);
512}
513
514INT_PTR CALLBACK BtrfsBalance::BalanceOptsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
538 switch (uMsg) {
539 case WM_INITDIALOG:
540 {
541 HWND devcb, convcb;
542 btrfs_device* bd;
543 btrfs_balance_opts* opts;
544 static int convtypes[] = { IDS_SINGLE2, IDS_DUP, IDS_RAID0, IDS_RAID1, IDS_RAID5, IDS_RAID6, IDS_RAID10, 0 };
545 int i, num_devices = 0, num_writeable_devices = 0;
546 WCHAR s[255], u[255];
547 BOOL balance_started = balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED);
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);
548
526
549 switch (opts_type) {
550 case 1:
551 opts = balance_started ? &bqb.data_opts : &data_opts;
552 break;
527 switch (opts_type) {
528 case 1:
529 opts = balance_started ? &bqb.data_opts : &data_opts;
530 break;
553
531
554 case 2:
555 opts = balance_started ? &bqb.metadata_opts : &metadata_opts;
556 break;
532 case 2:
533 opts = balance_started ? &bqb.metadata_opts : &metadata_opts;
534 break;
557
535
558 case 3:
559 opts = balance_started ? &bqb.system_opts : &system_opts;
560 break;
536 case 3:
537 opts = balance_started ? &bqb.system_opts : &system_opts;
538 break;
561
539
562 default:
563 return TRUE;
564 }
540 default:
541 return true;
542 }
565
543
566 EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
544 EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
567
545
568 devcb = GetDlgItem(hwndDlg, IDC_DEVID_COMBO);
546 devcb = GetDlgItem(hwndDlg, IDC_DEVID_COMBO);
569
547
570 if (!LoadStringW(module, IDS_DEVID_LIST, u, sizeof(u) / sizeof(WCHAR))) {
571 ShowError(hwndDlg, GetLastError());
572 return TRUE;
573 }
548 if (!load_string(module, IDS_DEVID_LIST, u))
549 throw last_error(GetLastError());
574
550
575 bd = devices;
576 while (TRUE) {
577 WCHAR t[255], v[255];
551 bd = devices;
552 while (true) {
553 wstring t, v;
578
554
579 if (bd->device_number == 0xffffffff) {
580 memcpy(s, bd->name, bd->namelen);
581 s[bd->namelen / sizeof(WCHAR)] = 0;
582 } else if (bd->partition_number == 0) {
583 if (!LoadStringW(module, IDS_DISK_NUM, v, sizeof(v) / sizeof(WCHAR))) {
584 ShowError(hwndDlg, GetLastError());
585 return TRUE;
586 }
555 if (bd->device_number == 0xffffffff)
556 s = wstring(bd->name, bd->namelen);
557 else if (bd->partition_number == 0) {
558 if (!load_string(module, IDS_DISK_NUM, v))
559 throw last_error(GetLastError());
587
560
588 if (StringCchPrintfW(s, sizeof(s) / sizeof(WCHAR), v, bd->device_number) == STRSAFE_E_INSUFFICIENT_BUFFER)
589 break;
590 } else {
591 if (!LoadStringW(module, IDS_DISK_PART_NUM, v, sizeof(v) / sizeof(WCHAR))) {
592 ShowError(hwndDlg, GetLastError());
593 return TRUE;
561 wstring_sprintf(s, v, bd->device_number);
562 } else {
563 if (!load_string(module, IDS_DISK_PART_NUM, v))
564 throw last_error(GetLastError());
565
566 wstring_sprintf(s, v, bd->device_number, bd->partition_number);
594 }
595
567 }
568
596 if (StringCchPrintfW(s, sizeof(s) / sizeof(WCHAR), v, bd->device_number, bd->partition_number) == STRSAFE_E_INSUFFICIENT_BUFFER)
597 break;
598 }
569 wstring_sprintf(t, u, bd->dev_id, s.c_str());
599
570
600 if (StringCchPrintfW(t, sizeof(t) / sizeof(WCHAR), u, bd->dev_id, s) == STRSAFE_E_INSUFFICIENT_BUFFER)
601 break;
571 SendMessage(devcb, CB_ADDSTRING, 0, (LPARAM)t.c_str());
602
572
603 SendMessage(devcb, CB_ADDSTRING, NULL, (LPARAM)t);
573 if (opts->devid == bd->dev_id)
574 SendMessage(devcb, CB_SETCURSEL, num_devices, 0);
604
575
605 if (opts->devid == bd->dev_id)
606 SendMessage(devcb, CB_SETCURSEL, num_devices, 0);
576 num_devices++;
607
577
608 num_devices++;
578 if (!bd->readonly)
579 num_writeable_devices++;
609
580
610 if (!bd->readonly)
611 num_writeable_devices++;
581 if (bd->next_entry > 0)
582 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
583 else
584 break;
585 }
612
586
613 if (bd->next_entry > 0)
614 bd = (btrfs_device*)((UINT8*)bd + bd->next_entry);
615 else
616 break;
617 }
587 convcb = GetDlgItem(hwndDlg, IDC_CONVERT_COMBO);
618
588
619 convcb = GetDlgItem(hwndDlg, IDC_CONVERT_COMBO);
589 if (num_writeable_devices == 0)
590 num_writeable_devices = num_devices;
620
591
621 if (num_writeable_devices == 0)
622 num_writeable_devices = num_devices;
592 i = 0;
593 while (convtypes[i] != 0) {
594 if (!load_string(module, convtypes[i], s))
595 throw last_error(GetLastError());
623
596
624 i = 0;
625 while (convtypes[i] != 0) {
626 if (!LoadStringW(module, convtypes[i], s, sizeof(s) / sizeof(WCHAR))) {
627 ShowError(hwndDlg, GetLastError());
628 break;
629 }
597 SendMessage(convcb, CB_ADDSTRING, 0, (LPARAM)s.c_str());
630
598
631 SendMessage(convcb, CB_ADDSTRING, NULL, (LPARAM)s);
599 if (opts->convert == convtypes2[i])
600 SendMessage(convcb, CB_SETCURSEL, i, 0);
632
601
633 if (opts->convert == convtypes2[i])
634 SendMessage(convcb, CB_SETCURSEL, i, 0);
602 i++;
635
603
636 i++;
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 }
637
611
638 if (num_writeable_devices < 2 && i == 2)
639 break;
640 else if (num_writeable_devices < 3 && i == 4)
641 break;
642 else if (num_writeable_devices < 4 && i == 5)
643 break;
644 }
612 // profiles
645
613
646 // profiles
614 CheckDlgButton(hwndDlg, IDC_PROFILES, opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? BST_CHECKED : BST_UNCHECKED);
615 CheckDlgButton(hwndDlg, IDC_PROFILES_SINGLE, opts->profiles & BLOCK_FLAG_SINGLE ? BST_CHECKED : BST_UNCHECKED);
616 CheckDlgButton(hwndDlg, IDC_PROFILES_DUP, opts->profiles & BLOCK_FLAG_DUPLICATE ? BST_CHECKED : BST_UNCHECKED);
617 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID0, opts->profiles & BLOCK_FLAG_RAID0 ? BST_CHECKED : BST_UNCHECKED);
618 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID1, opts->profiles & BLOCK_FLAG_RAID1 ? BST_CHECKED : BST_UNCHECKED);
619 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID10, opts->profiles & BLOCK_FLAG_RAID10 ? BST_CHECKED : BST_UNCHECKED);
620 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID5, opts->profiles & BLOCK_FLAG_RAID5 ? BST_CHECKED : BST_UNCHECKED);
621 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID6, opts->profiles & BLOCK_FLAG_RAID6 ? BST_CHECKED : BST_UNCHECKED);
647
622
648 CheckDlgButton(hwndDlg, IDC_PROFILES, opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? BST_CHECKED : BST_UNCHECKED);
649 CheckDlgButton(hwndDlg, IDC_PROFILES_SINGLE, opts->profiles & BLOCK_FLAG_SINGLE ? BST_CHECKED : BST_UNCHECKED);
650 CheckDlgButton(hwndDlg, IDC_PROFILES_DUP, opts->profiles & BLOCK_FLAG_DUPLICATE ? BST_CHECKED : BST_UNCHECKED);
651 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID0, opts->profiles & BLOCK_FLAG_RAID0 ? BST_CHECKED : BST_UNCHECKED);
652 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID1, opts->profiles & BLOCK_FLAG_RAID1 ? BST_CHECKED : BST_UNCHECKED);
653 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID10, opts->profiles & BLOCK_FLAG_RAID10 ? BST_CHECKED : BST_UNCHECKED);
654 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID5, opts->profiles & BLOCK_FLAG_RAID5 ? BST_CHECKED : BST_UNCHECKED);
655 CheckDlgButton(hwndDlg, IDC_PROFILES_RAID6, opts->profiles & BLOCK_FLAG_RAID6 ? BST_CHECKED : BST_UNCHECKED);
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);
656
631
657 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_SINGLE), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
658 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_DUP), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
659 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID0), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
660 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID1), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
661 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID10), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
662 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID5), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
663 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID6), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_PROFILES ? TRUE : FALSE);
664 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES), balance_started ? FALSE : TRUE);
632 // usage
665
633
666 // usage
634 CheckDlgButton(hwndDlg, IDC_USAGE, opts->flags & BTRFS_BALANCE_OPTS_USAGE ? BST_CHECKED : BST_UNCHECKED);
667
635
668 CheckDlgButton(hwndDlg, IDC_USAGE, opts->flags & BTRFS_BALANCE_OPTS_USAGE ? BST_CHECKED : BST_UNCHECKED);
636 s = to_wstring(opts->usage_start);
637 SetDlgItemTextW(hwndDlg, IDC_USAGE_START, s.c_str());
638 SendMessageW(GetDlgItem(hwndDlg, IDC_USAGE_START_SPINNER), UDM_SETRANGE32, 0, 100);
669
639
670 _itow(opts->usage_start, s, 10);
671 SetDlgItemTextW(hwndDlg, IDC_USAGE_START, s);
672 SendMessageW(GetDlgItem(hwndDlg, IDC_USAGE_START_SPINNER), UDM_SETRANGE32, 0, 100);
640 s = to_wstring(opts->usage_end);
641 SetDlgItemTextW(hwndDlg, IDC_USAGE_END, s.c_str());
642 SendMessageW(GetDlgItem(hwndDlg, IDC_USAGE_END_SPINNER), UDM_SETRANGE32, 0, 100);
673
643
674 _itow(opts->usage_end, s, 10);
675 SetDlgItemTextW(hwndDlg, IDC_USAGE_END, s);
676 SendMessageW(GetDlgItem(hwndDlg, IDC_USAGE_END_SPINNER), UDM_SETRANGE32, 0, 100);
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);
677
649
678 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? TRUE : FALSE);
679 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? TRUE : FALSE);
680 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? TRUE : FALSE);
681 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_USAGE ? TRUE : FALSE);
682 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE), balance_started ? FALSE : TRUE);
650 // devid
683
651
684 // devid
652 if (num_devices < 2 || balance_started)
653 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVID), false);
685
654
686 if (num_devices < 2 || balance_started)
687 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVID), FALSE);
655 CheckDlgButton(hwndDlg, IDC_DEVID, opts->flags & BTRFS_BALANCE_OPTS_DEVID ? BST_CHECKED : BST_UNCHECKED);
656 EnableWindow(devcb, (opts->flags & BTRFS_BALANCE_OPTS_DEVID && num_devices >= 2 && !balance_started) ? true : false);
688
657
689 CheckDlgButton(hwndDlg, IDC_DEVID, opts->flags & BTRFS_BALANCE_OPTS_DEVID ? BST_CHECKED : BST_UNCHECKED);
690 EnableWindow(devcb, (opts->flags & BTRFS_BALANCE_OPTS_DEVID && num_devices >= 2 && !balance_started) ? TRUE : FALSE);
658 // drange
691
659
692 // drange
660 CheckDlgButton(hwndDlg, IDC_DRANGE, opts->flags & BTRFS_BALANCE_OPTS_DRANGE ? BST_CHECKED : BST_UNCHECKED);
693
661
694 CheckDlgButton(hwndDlg, IDC_DRANGE, opts->flags & BTRFS_BALANCE_OPTS_DRANGE ? BST_CHECKED : BST_UNCHECKED);
662 s = to_wstring(opts->drange_start);
663 SetDlgItemTextW(hwndDlg, IDC_DRANGE_START, s.c_str());
695
664
696 _itow(opts->drange_start, s, 10);
697 SetDlgItemTextW(hwndDlg, IDC_DRANGE_START, s);
665 s = to_wstring(opts->drange_end);
666 SetDlgItemTextW(hwndDlg, IDC_DRANGE_END, s.c_str());
698
667
699 _itow(opts->drange_end, s, 10);
700 SetDlgItemTextW(hwndDlg, IDC_DRANGE_END, s);
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);
701
671
702 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_DRANGE ? TRUE : FALSE);
703 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_DRANGE ? TRUE : FALSE);
704 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE), balance_started ? FALSE : TRUE);
672 // vrange
705
673
706 // vrange
674 CheckDlgButton(hwndDlg, IDC_VRANGE, opts->flags & BTRFS_BALANCE_OPTS_VRANGE ? BST_CHECKED : BST_UNCHECKED);
707
675
708 CheckDlgButton(hwndDlg, IDC_VRANGE, opts->flags & BTRFS_BALANCE_OPTS_VRANGE ? BST_CHECKED : BST_UNCHECKED);
676 s = to_wstring(opts->vrange_start);
677 SetDlgItemTextW(hwndDlg, IDC_VRANGE_START, s.c_str());
709
678
710 _itow(opts->vrange_start, s, 10);
711 SetDlgItemTextW(hwndDlg, IDC_VRANGE_START, s);
679 s = to_wstring(opts->vrange_end);
680 SetDlgItemTextW(hwndDlg, IDC_VRANGE_END, s.c_str());
712
681
713 _itow(opts->vrange_end, s, 10);
714 SetDlgItemTextW(hwndDlg, IDC_VRANGE_END, s);
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);
715
685
716 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_VRANGE ? TRUE : FALSE);
717 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_VRANGE ? TRUE : FALSE);
718 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE), balance_started ? FALSE : TRUE);
686 // limit
719
687
720 // limit
688 CheckDlgButton(hwndDlg, IDC_LIMIT, opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? BST_CHECKED : BST_UNCHECKED);
721
689
722 CheckDlgButton(hwndDlg, IDC_LIMIT, opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? BST_CHECKED : BST_UNCHECKED);
690 s = to_wstring(opts->limit_start);
691 SetDlgItemTextW(hwndDlg, IDC_LIMIT_START, s.c_str());
692 SendMessageW(GetDlgItem(hwndDlg, IDC_LIMIT_START_SPINNER), UDM_SETRANGE32, 0, 0x7fffffff);
723
693
724 _itow(opts->limit_start, s, 10);
725 SetDlgItemTextW(hwndDlg, IDC_LIMIT_START, s);
726 SendMessageW(GetDlgItem(hwndDlg, IDC_LIMIT_START_SPINNER), UDM_SETRANGE32, 0, 0x7fffffff);
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);
727
697
728 _itow(opts->limit_end, s, 10);
729 SetDlgItemTextW(hwndDlg, IDC_LIMIT_END, s);
730 SendMessageW(GetDlgItem(hwndDlg, IDC_LIMIT_END_SPINNER), UDM_SETRANGE32, 0, 0x7fffffff);
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);
731
703
732 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? TRUE : FALSE);
733 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? TRUE : FALSE);
734 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? TRUE : FALSE);
735 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_LIMIT ? TRUE : FALSE);
736 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT), balance_started ? FALSE : TRUE);
704 // stripes
737
705
738 // stripes
706 CheckDlgButton(hwndDlg, IDC_STRIPES, opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? BST_CHECKED : BST_UNCHECKED);
739
707
740 CheckDlgButton(hwndDlg, IDC_STRIPES, opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? BST_CHECKED : BST_UNCHECKED);
708 s = to_wstring(opts->stripes_start);
709 SetDlgItemTextW(hwndDlg, IDC_STRIPES_START, s.c_str());
710 SendMessageW(GetDlgItem(hwndDlg, IDC_STRIPES_START_SPINNER), UDM_SETRANGE32, 0, 0xffff);
741
711
742 _itow(opts->stripes_start, s, 10);
743 SetDlgItemTextW(hwndDlg, IDC_STRIPES_START, s);
744 SendMessageW(GetDlgItem(hwndDlg, IDC_STRIPES_START_SPINNER), UDM_SETRANGE32, 0, 0xffff);
712 s = to_wstring(opts->stripes_end);
713 SetDlgItemTextW(hwndDlg, IDC_STRIPES_END, s.c_str());
714 SendMessageW(GetDlgItem(hwndDlg, IDC_STRIPES_END_SPINNER), UDM_SETRANGE32, 0, 0xffff);
745
715
746 _itow(opts->stripes_end, s, 10);
747 SetDlgItemTextW(hwndDlg, IDC_STRIPES_END, s);
748 SendMessageW(GetDlgItem(hwndDlg, IDC_STRIPES_END_SPINNER), UDM_SETRANGE32, 0, 0xffff);
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);
749
721
750 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? TRUE : FALSE);
751 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? TRUE : FALSE);
752 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? TRUE : FALSE);
753 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END_SPINNER), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_STRIPES ? TRUE : FALSE);
754 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES), balance_started ? FALSE : TRUE);
722 // convert
755
723
756 // convert
724 CheckDlgButton(hwndDlg, IDC_CONVERT, opts->flags & BTRFS_BALANCE_OPTS_CONVERT ? BST_CHECKED : BST_UNCHECKED);
725 CheckDlgButton(hwndDlg, IDC_SOFT, opts->flags & BTRFS_BALANCE_OPTS_SOFT ? BST_CHECKED : BST_UNCHECKED);
757
726
758 CheckDlgButton(hwndDlg, IDC_CONVERT, opts->flags & BTRFS_BALANCE_OPTS_CONVERT ? BST_CHECKED : BST_UNCHECKED);
759 CheckDlgButton(hwndDlg, IDC_SOFT, opts->flags & BTRFS_BALANCE_OPTS_SOFT ? BST_CHECKED : BST_UNCHECKED);
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);
760
730
761 EnableWindow(GetDlgItem(hwndDlg, IDC_SOFT), !balance_started && opts->flags & BTRFS_BALANCE_OPTS_CONVERT ? TRUE : FALSE);
762 EnableWindow(convcb, !balance_started && opts->flags & BTRFS_BALANCE_OPTS_CONVERT ? TRUE : FALSE);
763 EnableWindow(GetDlgItem(hwndDlg, IDC_CONVERT), balance_started ? FALSE : TRUE);
731 break;
732 }
764
733
765 break;
766 }
734 case WM_COMMAND:
735 switch (HIWORD(wParam)) {
736 case BN_CLICKED:
737 switch (LOWORD(wParam)) {
738 case IDOK:
739 if (balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED))
740 EndDialog(hwndDlg, 0);
741 else
742 SaveBalanceOpts(hwndDlg);
743 return true;
767
744
768 case WM_COMMAND:
769 switch (HIWORD(wParam)) {
770 case BN_CLICKED:
771 switch (LOWORD(wParam)) {
772 case IDOK:
773 if (balance_status & (BTRFS_BALANCE_RUNNING | BTRFS_BALANCE_PAUSED))
745 case IDCANCEL:
774 EndDialog(hwndDlg, 0);
746 EndDialog(hwndDlg, 0);
775 else
776 SaveBalanceOpts(hwndDlg);
777 return TRUE;
747 return true;
778
748
779 case IDCANCEL:
780 EndDialog(hwndDlg, 0);
781 return TRUE;
749 case IDC_PROFILES: {
750 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_PROFILES) == BST_CHECKED ? true : false;
782
751
783 case IDC_PROFILES: {
784 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_PROFILES) == BST_CHECKED ? TRUE : FALSE;
752 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_SINGLE), enabled);
753 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_DUP), enabled);
754 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID0), enabled);
755 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID1), enabled);
756 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID10), enabled);
757 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID5), enabled);
758 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID6), enabled);
759 break;
760 }
785
761
786 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_SINGLE), enabled);
787 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_DUP), enabled);
788 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID0), enabled);
789 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID1), enabled);
790 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID10), enabled);
791 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID5), enabled);
792 EnableWindow(GetDlgItem(hwndDlg, IDC_PROFILES_RAID6), enabled);
793 break;
794 }
762 case IDC_USAGE: {
763 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_USAGE) == BST_CHECKED ? true : false;
795
764
796 case IDC_USAGE: {
797 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_USAGE) == BST_CHECKED ? TRUE : FALSE;
765 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START), enabled);
766 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START_SPINNER), enabled);
767 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END), enabled);
768 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END_SPINNER), enabled);
769 break;
770 }
798
771
799 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START), enabled);
800 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_START_SPINNER), enabled);
801 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END), enabled);
802 EnableWindow(GetDlgItem(hwndDlg, IDC_USAGE_END_SPINNER), enabled);
803 break;
804 }
772 case IDC_DEVID: {
773 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_DEVID) == BST_CHECKED ? true : false;
805
774
806 case IDC_DEVID: {
807 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_DEVID) == BST_CHECKED ? TRUE : FALSE;
775 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVID_COMBO), enabled);
776 break;
777 }
808
778
809 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVID_COMBO), enabled);
810 break;
811 }
779 case IDC_DRANGE: {
780 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_DRANGE) == BST_CHECKED ? true : false;
812
781
813 case IDC_DRANGE: {
814 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_DRANGE) == BST_CHECKED ? TRUE : FALSE;
782 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_START), enabled);
783 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_END), enabled);
784 break;
785 }
815
786
816 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_START), enabled);
817 EnableWindow(GetDlgItem(hwndDlg, IDC_DRANGE_END), enabled);
818 break;
819 }
787 case IDC_VRANGE: {
788 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_VRANGE) == BST_CHECKED ? true : false;
820
789
821 case IDC_VRANGE: {
822 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_VRANGE) == BST_CHECKED ? TRUE : FALSE;
790 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_START), enabled);
791 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_END), enabled);
792 break;
793 }
823
794
824 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_START), enabled);
825 EnableWindow(GetDlgItem(hwndDlg, IDC_VRANGE_END), enabled);
826 break;
827 }
795 case IDC_LIMIT: {
796 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_LIMIT) == BST_CHECKED ? true : false;
828
797
829 case IDC_LIMIT: {
830 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_LIMIT) == BST_CHECKED ? TRUE : FALSE;
798 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START), enabled);
799 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START_SPINNER), enabled);
800 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END), enabled);
801 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END_SPINNER), enabled);
802 break;
803 }
831
804
832 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START), enabled);
833 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_START_SPINNER), enabled);
834 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END), enabled);
835 EnableWindow(GetDlgItem(hwndDlg, IDC_LIMIT_END_SPINNER), enabled);
836 break;
837 }
805 case IDC_STRIPES: {
806 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_STRIPES) == BST_CHECKED ? true : false;
838
807
839 case IDC_STRIPES: {
840 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_STRIPES) == BST_CHECKED ? TRUE : FALSE;
808 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START), enabled);
809 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START_SPINNER), enabled);
810 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END), enabled);
811 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END_SPINNER), enabled);
812 break;
813 }
841
814
842 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START), enabled);
843 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_START_SPINNER), enabled);
844 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END), enabled);
845 EnableWindow(GetDlgItem(hwndDlg, IDC_STRIPES_END_SPINNER), enabled);
846 break;
847 }
815 case IDC_CONVERT: {
816 bool enabled = IsDlgButtonChecked(hwndDlg, IDC_CONVERT) == BST_CHECKED ? true : false;
848
817
849 case IDC_CONVERT: {
850 BOOL enabled = IsDlgButtonChecked(hwndDlg, IDC_CONVERT) == BST_CHECKED ? TRUE : FALSE;
851
852 EnableWindow(GetDlgItem(hwndDlg, IDC_CONVERT_COMBO), enabled);
853 EnableWindow(GetDlgItem(hwndDlg, IDC_SOFT), enabled);
854 break;
818 EnableWindow(GetDlgItem(hwndDlg, IDC_CONVERT_COMBO), enabled);
819 EnableWindow(GetDlgItem(hwndDlg, IDC_SOFT), enabled);
820 break;
821 }
855 }
822 }
856 }
857 break;
858 }
859 break;
823 break;
824 }
825 break;
826 }
827 } catch (const exception& e) {
828 error_message(hwndDlg, e.what());
860 }
861
829 }
830
862 return FALSE;
831 return false;
863}
864
865static INT_PTR CALLBACK stub_BalanceOptsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
866 BtrfsBalance* bb;
867
868 if (uMsg == WM_INITDIALOG) {
869 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
870 bb = (BtrfsBalance*)lParam;
871 } else {
872 bb = (BtrfsBalance*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
873 }
874
875 if (bb)
876 return bb->BalanceOptsDlgProc(hwndDlg, uMsg, wParam, lParam);
877 else
832}
833
834static INT_PTR CALLBACK stub_BalanceOptsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
835 BtrfsBalance* bb;
836
837 if (uMsg == WM_INITDIALOG) {
838 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
839 bb = (BtrfsBalance*)lParam;
840 } else {
841 bb = (BtrfsBalance*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
842 }
843
844 if (bb)
845 return bb->BalanceOptsDlgProc(hwndDlg, uMsg, wParam, lParam);
846 else
878 return FALSE;
847 return false;
879}
880
848}
849
881void BtrfsBalance::ShowBalanceOptions(HWND hwndDlg, UINT8 type) {
850void BtrfsBalance::ShowBalanceOptions(HWND hwndDlg, uint8_t type) {
882 opts_type = type;
883 DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_BALANCE_OPTIONS), hwndDlg, stub_BalanceOptsDlgProc, (LPARAM)this);
884}
885
886INT_PTR CALLBACK BtrfsBalance::BalanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
851 opts_type = type;
852 DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_BALANCE_OPTIONS), hwndDlg, stub_BalanceOptsDlgProc, (LPARAM)this);
853}
854
855INT_PTR CALLBACK BtrfsBalance::BalanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
887 switch (uMsg) {
888 case WM_INITDIALOG:
889 {
890 EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
856 try {
857 switch (uMsg) {
858 case WM_INITDIALOG:
859 {
860 EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
891
861
892 RtlZeroMemory(&data_opts, sizeof(btrfs_balance_opts));
893 RtlZeroMemory(&metadata_opts, sizeof(btrfs_balance_opts));
894 RtlZeroMemory(&system_opts, sizeof(btrfs_balance_opts));
862 RtlZeroMemory(&data_opts, sizeof(btrfs_balance_opts));
863 RtlZeroMemory(&metadata_opts, sizeof(btrfs_balance_opts));
864 RtlZeroMemory(&system_opts, sizeof(btrfs_balance_opts));
895
865
896 removing = called_from_RemoveDevice;
897 shrinking = called_from_ShrinkDevice;
898 balance_status = (removing || shrinking) ? BTRFS_BALANCE_RUNNING : BTRFS_BALANCE_STOPPED;
899 cancelling = FALSE;
900 RefreshBalanceDlg(hwndDlg, TRUE);
866 removing = called_from_RemoveDevice;
867 shrinking = called_from_ShrinkDevice;
868 balance_status = (removing || shrinking) ? BTRFS_BALANCE_RUNNING : BTRFS_BALANCE_STOPPED;
869 cancelling = false;
870 RefreshBalanceDlg(hwndDlg, true);
901
871
902 if (readonly) {
903 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), FALSE);
904 EnableWindow(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), FALSE);
905 EnableWindow(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), FALSE);
906 }
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 }
907
877
908 SendMessageW(GetDlgItem(hwndDlg, IDC_START_BALANCE), BCM_SETSHIELD, 0, TRUE);
909 SendMessageW(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), BCM_SETSHIELD, 0, TRUE);
910 SendMessageW(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), BCM_SETSHIELD, 0, TRUE);
878 SendMessageW(GetDlgItem(hwndDlg, IDC_START_BALANCE), BCM_SETSHIELD, 0, true);
879 SendMessageW(GetDlgItem(hwndDlg, IDC_PAUSE_BALANCE), BCM_SETSHIELD, 0, true);
880 SendMessageW(GetDlgItem(hwndDlg, IDC_CANCEL_BALANCE), BCM_SETSHIELD, 0, true);
911
881
912 SetTimer(hwndDlg, 1, 1000, NULL);
882 SetTimer(hwndDlg, 1, 1000, nullptr);
913
883
914 break;
915 }
884 break;
885 }
916
886
917 case WM_COMMAND:
918 switch (HIWORD(wParam)) {
919 case BN_CLICKED:
920 switch (LOWORD(wParam)) {
921 case IDOK:
922 case IDCANCEL:
923 KillTimer(hwndDlg, 1);
924 EndDialog(hwndDlg, 0);
925 return TRUE;
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;
926
896
927 case IDC_DATA:
928 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ? TRUE : FALSE);
897 case IDC_DATA:
898 EnableWindow(GetDlgItem(hwndDlg, IDC_DATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ? true : false);
929
899
930 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
931 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? TRUE: FALSE);
932 return TRUE;
900 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
901 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
902 return true;
933
903
934 case IDC_METADATA:
935 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED ? TRUE : FALSE);
904 case IDC_METADATA:
905 EnableWindow(GetDlgItem(hwndDlg, IDC_METADATA_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED ? true : false);
936
906
937 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
938 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? TRUE: FALSE);
939 return TRUE;
907 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
908 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
909 return true;
940
910
941 case IDC_SYSTEM:
942 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED ? TRUE : FALSE);
911 case IDC_SYSTEM:
912 EnableWindow(GetDlgItem(hwndDlg, IDC_SYSTEM_OPTIONS), IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED ? true : false);
943
913
944 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
945 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? TRUE: FALSE);
946 return TRUE;
914 EnableWindow(GetDlgItem(hwndDlg, IDC_START_BALANCE), !readonly && (IsDlgButtonChecked(hwndDlg, IDC_DATA) == BST_CHECKED ||
915 IsDlgButtonChecked(hwndDlg, IDC_METADATA) == BST_CHECKED || IsDlgButtonChecked(hwndDlg, IDC_SYSTEM) == BST_CHECKED) ? true: false);
916 return true;
947
917
948 case IDC_DATA_OPTIONS:
949 ShowBalanceOptions(hwndDlg, 1);
950 return TRUE;
918 case IDC_DATA_OPTIONS:
919 ShowBalanceOptions(hwndDlg, 1);
920 return true;
951
921
952 case IDC_METADATA_OPTIONS:
953 ShowBalanceOptions(hwndDlg, 2);
954 return TRUE;
922 case IDC_METADATA_OPTIONS:
923 ShowBalanceOptions(hwndDlg, 2);
924 return true;
955
925
956 case IDC_SYSTEM_OPTIONS:
957 ShowBalanceOptions(hwndDlg, 3);
958 return TRUE;
926 case IDC_SYSTEM_OPTIONS:
927 ShowBalanceOptions(hwndDlg, 3);
928 return true;
959
929
960 case IDC_START_BALANCE:
961 StartBalance(hwndDlg);
962 return TRUE;
930 case IDC_START_BALANCE:
931 StartBalance(hwndDlg);
932 return true;
963
933
964 case IDC_PAUSE_BALANCE:
965 PauseBalance(hwndDlg);
966 RefreshBalanceDlg(hwndDlg, FALSE);
967 return TRUE;
934 case IDC_PAUSE_BALANCE:
935 PauseBalance(hwndDlg);
936 RefreshBalanceDlg(hwndDlg, false);
937 return true;
968
938
969 case IDC_CANCEL_BALANCE:
970 StopBalance(hwndDlg);
971 RefreshBalanceDlg(hwndDlg, FALSE);
972 return TRUE;
973 }
974 break;
975 }
976 break;
977
978 case WM_TIMER:
979 RefreshBalanceDlg(hwndDlg, FALSE);
939 case IDC_CANCEL_BALANCE:
940 StopBalance(hwndDlg);
941 RefreshBalanceDlg(hwndDlg, false);
942 return true;
943 }
944 break;
945 }
980 break;
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());
981 }
982
954 }
955
983 return FALSE;
956 return false;
984}
985
986static INT_PTR CALLBACK stub_BalanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
987 BtrfsBalance* bb;
988
989 if (uMsg == WM_INITDIALOG) {
990 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
991 bb = (BtrfsBalance*)lParam;
992 } else {
993 bb = (BtrfsBalance*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
994 }
995
996 if (bb)
997 return bb->BalanceDlgProc(hwndDlg, uMsg, wParam, lParam);
998 else
957}
958
959static INT_PTR CALLBACK stub_BalanceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
960 BtrfsBalance* bb;
961
962 if (uMsg == WM_INITDIALOG) {
963 SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
964 bb = (BtrfsBalance*)lParam;
965 } else {
966 bb = (BtrfsBalance*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
967 }
968
969 if (bb)
970 return bb->BalanceDlgProc(hwndDlg, uMsg, wParam, lParam);
971 else
999 return FALSE;
972 return false;
1000}
1001
1002void BtrfsBalance::ShowBalance(HWND hwndDlg) {
973}
974
975void BtrfsBalance::ShowBalance(HWND hwndDlg) {
1003 HANDLE h;
1004 btrfs_device* bd;
1005
1006 if (devices) {
1007 free(devices);
976 btrfs_device* bd;
977
978 if (devices) {
979 free(devices);
1008 devices = NULL;
980 devices = nullptr;
1009 }
1010
981 }
982
1011 h = CreateFileW(fn, FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1012 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
983 {
984 win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
985 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
1013
986
1014 if (h != INVALID_HANDLE_VALUE) {
1015 NTSTATUS Status;
1016 IO_STATUS_BLOCK iosb;
1017 ULONG devsize, i;
987 if (h != INVALID_HANDLE_VALUE) {
988 NTSTATUS Status;
989 IO_STATUS_BLOCK iosb;
990 ULONG devsize, i;
1018
991
1019 i = 0;
1020 devsize = 1024;
992 i = 0;
993 devsize = 1024;
1021
994
1022 devices = (btrfs_device*)malloc(devsize);
995 devices = (btrfs_device*)malloc(devsize);
1023
996
1024 while (TRUE) {
1025 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_GET_DEVICES, NULL, 0, devices, devsize);
1026 if (Status == STATUS_BUFFER_OVERFLOW) {
1027 if (i < 8) {
1028 devsize += 1024;
997 while (true) {
998 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
999 if (Status == STATUS_BUFFER_OVERFLOW) {
1000 if (i < 8) {
1001 devsize += 1024;
1029
1002
1030 free(devices);
1031 devices = (btrfs_device*)malloc(devsize);
1003 free(devices);
1004 devices = (btrfs_device*)malloc(devsize);
1032
1005
1033 i++;
1006 i++;
1007 } else
1008 return;
1034 } else
1009 } else
1035 return;
1036 } else
1037 break;
1038 }
1010 break;
1011 }
1039
1012
1040 if (!NT_SUCCESS(Status)) {
1041 CloseHandle(h);
1042 ShowNtStatusError(hwndDlg, Status);
1043 return;
1044 }
1045
1046 CloseHandle(h);
1047 } else {
1048 ShowError(hwndDlg, GetLastError());
1049 return;
1013 if (!NT_SUCCESS(Status))
1014 throw ntstatus_error(Status);
1015 } else
1016 throw last_error(GetLastError());
1050 }
1051
1017 }
1018
1052 readonly = TRUE;
1019 readonly = true;
1053 bd = devices;
1054
1020 bd = devices;
1021
1055 while (TRUE) {
1022 while (true) {
1056 if (!bd->readonly) {
1023 if (!bd->readonly) {
1057 readonly = FALSE;
1024 readonly = false;
1058 break;
1059 }
1060
1061 if (bd->next_entry > 0)
1025 break;
1026 }
1027
1028 if (bd->next_entry > 0)
1062 bd = (btrfs_device*)((UINT8*)bd + bd->next_entry);
1029 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
1063 else
1064 break;
1065 }
1066
1067 DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_BALANCE), hwndDlg, stub_BalanceDlgProc, (LPARAM)this);
1068}
1069
1030 else
1031 break;
1032 }
1033
1034 DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_BALANCE), hwndDlg, stub_BalanceDlgProc, (LPARAM)this);
1035}
1036
1070static UINT8 from_hex_digit(WCHAR c) {
1037static uint8_t from_hex_digit(WCHAR c) {
1071 if (c >= 'a' && c <= 'f')
1038 if (c >= 'a' && c <= 'f')
1072 return c - 'a' + 0xa;
1039 return (uint8_t)(c - 'a' + 0xa);
1073 else if (c >= 'A' && c <= 'F')
1040 else if (c >= 'A' && c <= 'F')
1074 return c - 'A' + 0xa;
1041 return (uint8_t)(c - 'A' + 0xa);
1075 else
1042 else
1076 return c - '0';
1043 return (uint8_t)(c - '0');
1077}
1078
1079static void unserialize(void* data, ULONG len, WCHAR* s) {
1044}
1045
1046static void unserialize(void* data, ULONG len, WCHAR* s) {
1080 UINT8* d;
1047 uint8_t* d;
1081
1048
1082 d = (UINT8*)data;
1049 d = (uint8_t*)data;
1083
1084 while (s[0] != 0 && s[1] != 0 && len > 0) {
1050
1051 while (s[0] != 0 && s[1] != 0 && len > 0) {
1085 *d = from_hex_digit(s[0]) << 4 | from_hex_digit(s[1]);
1052 *d = (uint8_t)(from_hex_digit(s[0]) << 4) | from_hex_digit(s[1]);
1086
1087 s += 2;
1088 d++;
1089 len--;
1090 }
1091}
1092
1093#ifdef __REACTOS__
1094extern "C" {
1095#endif
1096
1097void CALLBACK StartBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1053
1054 s += 2;
1055 d++;
1056 len--;
1057 }
1058}
1059
1060#ifdef __REACTOS__
1061extern "C" {
1062#endif
1063
1064void CALLBACK StartBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1098 WCHAR *s, *vol, *block;
1099 HANDLE h, token;
1100 btrfs_start_balance bsb;
1101 TOKEN_PRIVILEGES tp;
1102 LUID luid;
1065 try {
1066 WCHAR *s, *vol, *block;
1067 win_handle h, token;
1068 btrfs_start_balance bsb;
1069 TOKEN_PRIVILEGES tp;
1070 LUID luid;
1103
1071
1104 s = wcsstr(lpszCmdLine, L" ");
1105 if (!s)
1106 return;
1072 s = wcsstr(lpszCmdLine, L" ");
1073 if (!s)
1074 return;
1107
1075
1108 s[0] = 0;
1076 s[0] = 0;
1109
1077
1110 vol = lpszCmdLine;
1111 block = &s[1];
1078 vol = lpszCmdLine;
1079 block = &s[1];
1112
1080
1113 RtlZeroMemory(&bsb, sizeof(btrfs_start_balance));
1114 unserialize(&bsb, sizeof(btrfs_start_balance), block);
1081 RtlZeroMemory(&bsb, sizeof(btrfs_start_balance));
1082 unserialize(&bsb, sizeof(btrfs_start_balance), block);
1115
1083
1116 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
1117 ShowError(hwnd, GetLastError());
1118 return;
1119 }
1084 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
1085 throw last_error(GetLastError());
1120
1086
1121 if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
1122 ShowError(hwnd, GetLastError());
1123 goto end;
1124 }
1087 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1088 throw last_error(GetLastError());
1125
1089
1126 tp.PrivilegeCount = 1;
1127 tp.Privileges[0].Luid = luid;
1128 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1090 tp.PrivilegeCount = 1;
1091 tp.Privileges[0].Luid = luid;
1092 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1129
1093
1130 if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
1131 ShowError(hwnd, GetLastError());
1132 goto end;
1133 }
1094 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1095 throw last_error(GetLastError());
1134
1096
1135 h = CreateFileW(vol, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1136 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
1097 h = CreateFileW(vol, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
1098 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
1137
1099
1138 if (h != INVALID_HANDLE_VALUE) {
1139 NTSTATUS Status;
1140 IO_STATUS_BLOCK iosb;
1100 if (h != INVALID_HANDLE_VALUE) {
1101 NTSTATUS Status;
1102 IO_STATUS_BLOCK iosb;
1141
1103
1142 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_START_BALANCE, &bsb, sizeof(btrfs_start_balance), NULL, 0);
1104 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_START_BALANCE, &bsb, sizeof(btrfs_start_balance), nullptr, 0);
1143
1105
1144 if (Status == STATUS_DEVICE_NOT_READY) {
1145 btrfs_query_scrub bqs;
1146 NTSTATUS Status2;
1106 if (Status == STATUS_DEVICE_NOT_READY) {
1107 btrfs_query_scrub bqs;
1108 NTSTATUS Status2;
1147
1109
1148 Status2 = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_SCRUB, NULL, 0, &bqs, sizeof(btrfs_query_scrub));
1110 Status2 = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_QUERY_SCRUB, nullptr, 0, &bqs, sizeof(btrfs_query_scrub));
1149
1111
1150 if ((NT_SUCCESS(Status2) || Status2 == STATUS_BUFFER_OVERFLOW) && bqs.status != BTRFS_SCRUB_STOPPED) {
1151 ShowStringError(hwnd, IDS_BALANCE_SCRUB_RUNNING);
1152 CloseHandle(h);
1153 goto end;
1112 if ((NT_SUCCESS(Status2) || Status2 == STATUS_BUFFER_OVERFLOW) && bqs.status != BTRFS_SCRUB_STOPPED)
1113 throw string_error(IDS_BALANCE_SCRUB_RUNNING);
1154 }
1114 }
1155 }
1156
1115
1157 if (!NT_SUCCESS(Status)) {
1158 ShowNtStatusError(hwnd, Status);
1159 CloseHandle(h);
1160 goto end;
1161 }
1162
1163 CloseHandle(h);
1164 } else {
1165 ShowError(hwnd, GetLastError());
1166 goto end;
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());
1167 }
1122 }
1168
1169end:
1170 CloseHandle(token);
1171}
1172
1173void CALLBACK PauseBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1123}
1124
1125void CALLBACK PauseBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1174 HANDLE h, token;
1175 TOKEN_PRIVILEGES tp;
1176 LUID luid;
1126 try {
1127 win_handle h, token;
1128 TOKEN_PRIVILEGES tp;
1129 LUID luid;
1177
1130
1178 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
1179 ShowError(hwnd, GetLastError());
1180 return;
1181 }
1131 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
1132 throw last_error(GetLastError());
1182
1133
1183 if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
1184 ShowError(hwnd, GetLastError());
1185 goto end;
1186 }
1134 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1135 throw last_error(GetLastError());
1187
1136
1188 tp.PrivilegeCount = 1;
1189 tp.Privileges[0].Luid = luid;
1190 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1137 tp.PrivilegeCount = 1;
1138 tp.Privileges[0].Luid = luid;
1139 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1191
1140
1192 if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
1193 ShowError(hwnd, GetLastError());
1194 goto end;
1195 }
1141 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1142 throw last_error(GetLastError());
1196
1143
1197 h = CreateFileW(lpszCmdLine, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1198 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
1144 h = CreateFileW(lpszCmdLine, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
1145 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
1199
1146
1200 if (h != INVALID_HANDLE_VALUE) {
1201 NTSTATUS Status;
1202 IO_STATUS_BLOCK iosb;
1203 btrfs_query_balance bqb2;
1147 if (h != INVALID_HANDLE_VALUE) {
1148 NTSTATUS Status;
1149 IO_STATUS_BLOCK iosb;
1150 btrfs_query_balance bqb2;
1204
1151
1205 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_BALANCE, NULL, 0, &bqb2, sizeof(btrfs_query_balance));
1206 if (!NT_SUCCESS(Status)) {
1207 ShowNtStatusError(hwnd, Status);
1208 CloseHandle(h);
1209 goto end;
1210 }
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);
1211
1155
1212 if (bqb2.status & BTRFS_BALANCE_PAUSED)
1213 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_RESUME_BALANCE, NULL, 0, NULL, 0);
1214 else if (bqb2.status & BTRFS_BALANCE_RUNNING)
1215 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_PAUSE_BALANCE, NULL, 0, NULL, 0);
1216 else {
1217 CloseHandle(h);
1218 goto end;
1219 }
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;
1220
1162
1221 if (!NT_SUCCESS(Status)) {
1222 ShowNtStatusError(hwnd, Status);
1223 CloseHandle(h);
1224 goto end;
1225 }
1226
1227 CloseHandle(h);
1228 } else {
1229 ShowError(hwnd, GetLastError());
1230 goto end;
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());
1231 }
1169 }
1232
1233end:
1234 CloseHandle(token);
1235}
1236
1237void CALLBACK StopBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1170}
1171
1172void CALLBACK StopBalanceW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
1238 HANDLE h, token;
1239 TOKEN_PRIVILEGES tp;
1240 LUID luid;
1173 try {
1174 win_handle h, token;
1175 TOKEN_PRIVILEGES tp;
1176 LUID luid;
1241
1177
1242 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
1243 ShowError(hwnd, GetLastError());
1244 return;
1245 }
1178 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
1179 throw last_error(GetLastError());
1246
1180
1247 if (!LookupPrivilegeValueW(NULL, L"SeManageVolumePrivilege", &luid)) {
1248 ShowError(hwnd, GetLastError());
1249 goto end;
1250 }
1181 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1182 throw last_error(GetLastError());
1251
1183
1252 tp.PrivilegeCount = 1;
1253 tp.Privileges[0].Luid = luid;
1254 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1184 tp.PrivilegeCount = 1;
1185 tp.Privileges[0].Luid = luid;
1186 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1255
1187
1256 if (!AdjustTokenPrivileges(token, FALSE, &tp, sizeof(TOKEN_PRIVILEGES), NULL, NULL)) {
1257 ShowError(hwnd, GetLastError());
1258 goto end;
1259 }
1188 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1189 throw last_error(GetLastError());
1260
1190
1261 h = CreateFileW(lpszCmdLine, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL,
1262 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, NULL);
1191 h = CreateFileW(lpszCmdLine, FILE_TRAVERSE, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
1192 OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
1263
1193
1264 if (h != INVALID_HANDLE_VALUE) {
1265 NTSTATUS Status;
1266 IO_STATUS_BLOCK iosb;
1267 btrfs_query_balance bqb2;
1194 if (h != INVALID_HANDLE_VALUE) {
1195 NTSTATUS Status;
1196 IO_STATUS_BLOCK iosb;
1197 btrfs_query_balance bqb2;
1268
1198
1269 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_QUERY_BALANCE, NULL, 0, &bqb2, sizeof(btrfs_query_balance));
1270 if (!NT_SUCCESS(Status)) {
1271 ShowNtStatusError(hwnd, Status);
1272 CloseHandle(h);
1273 goto end;
1274 }
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);
1275
1202
1276 if (bqb2.status & BTRFS_BALANCE_PAUSED || bqb2.status & BTRFS_BALANCE_RUNNING)
1277 Status = NtFsControlFile(h, NULL, NULL, NULL, &iosb, FSCTL_BTRFS_STOP_BALANCE, NULL, 0, NULL, 0);
1278 else {
1279 CloseHandle(h);
1280 goto end;
1281 }
1203 if (bqb2.status & BTRFS_BALANCE_PAUSED || bqb2.status & BTRFS_BALANCE_RUNNING)
1204 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_STOP_BALANCE, nullptr, 0, nullptr, 0);
1205 else
1206 return;
1282
1207
1283 if (!NT_SUCCESS(Status)) {
1284 ShowNtStatusError(hwnd, Status);
1285 CloseHandle(h);
1286 goto end;
1287 }
1288
1289 CloseHandle(h);
1290 } else {
1291 ShowError(hwnd, GetLastError());
1292 goto end;
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());
1293 }
1214 }
1294
1295end:
1296 CloseHandle(token);
1297}
1298
1299#ifdef __REACTOS__
1300} /* extern "C" */
1301#endif
1215}
1216
1217#ifdef __REACTOS__
1218} /* extern "C" */
1219#endif