2017-09-08 11:59:42 +00:00
|
|
|
/* Copyright (c) Mark Harmstone 2016-17
|
|
|
|
*
|
|
|
|
* This file is part of WinBtrfs.
|
|
|
|
*
|
|
|
|
* WinBtrfs is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public Licence as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the Licence, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* WinBtrfs is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public Licence for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public Licence
|
|
|
|
* along with WinBtrfs. If not, see <http://www.gnu.org/licenses/>. */
|
|
|
|
|
|
|
|
#define ISOLATION_AWARE_ENABLED 1
|
|
|
|
#define STRSAFE_NO_DEPRECATE
|
|
|
|
|
|
|
|
#include "shellext.h"
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
#include <windows.h>
|
|
|
|
#include <strsafe.h>
|
|
|
|
#include <winternl.h>
|
|
|
|
#else
|
|
|
|
#define WIN32_NO_STATUS
|
|
|
|
#include <windef.h>
|
|
|
|
#include <winbase.h>
|
|
|
|
#include <strsafe.h>
|
|
|
|
#include <ndk/iofuncs.h>
|
|
|
|
#include <ndk/iotypes.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define NO_SHLWAPI_STRFCNS
|
|
|
|
#include <shlwapi.h>
|
|
|
|
#include <uxtheme.h>
|
|
|
|
|
|
|
|
#include "volpropsheet.h"
|
|
|
|
#include "resource.h"
|
2019-11-12 20:45:49 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
#include "mountmgr.h"
|
|
|
|
#else
|
|
|
|
#include "mountmgr_local.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
static const NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034;
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
HRESULT __stdcall BtrfsVolPropSheet::QueryInterface(REFIID riid, void **ppObj) {
|
|
|
|
if (riid == IID_IUnknown || riid == IID_IShellPropSheetExt) {
|
|
|
|
*ppObj = static_cast<IShellPropSheetExt*>(this);
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
} else if (riid == IID_IShellExtInit) {
|
|
|
|
*ppObj = static_cast<IShellExtInit*>(this);
|
|
|
|
AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
*ppObj = nullptr;
|
2017-09-08 11:59:42 +00:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall BtrfsVolPropSheet::Initialize(PCIDLIST_ABSOLUTE pidlFolder, IDataObject* pdtobj, HKEY hkeyProgID) {
|
|
|
|
ULONG num_files;
|
2018-12-16 11:04:40 +00:00
|
|
|
FORMATETC format = { CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
|
2017-09-08 11:59:42 +00:00
|
|
|
HDROP hdrop;
|
2018-12-16 11:04:40 +00:00
|
|
|
WCHAR fnbuf[MAX_PATH];
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (pidlFolder)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
if (!pdtobj)
|
|
|
|
return E_FAIL;
|
|
|
|
|
|
|
|
stgm.tymed = TYMED_HGLOBAL;
|
|
|
|
|
|
|
|
if (FAILED(pdtobj->GetData(&format, &stgm)))
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
stgm_set = true;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
hdrop = (HDROP)GlobalLock(stgm.hGlobal);
|
|
|
|
|
|
|
|
if (!hdrop) {
|
|
|
|
ReleaseStgMedium(&stgm);
|
2018-12-16 11:04:40 +00:00
|
|
|
stgm_set = false;
|
2017-09-08 11:59:42 +00:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
num_files = DragQueryFileW((HDROP)stgm.hGlobal, 0xFFFFFFFF, nullptr, 0);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (num_files > 1) {
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (DragQueryFileW((HDROP)stgm.hGlobal, 0, fnbuf, sizeof(fnbuf) / sizeof(MAX_PATH))) {
|
|
|
|
fn = fnbuf;
|
|
|
|
|
|
|
|
win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
ULONG devsize, i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
devsize = 1024;
|
|
|
|
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
|
2017-09-08 11:59:42 +00:00
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
devsize += 1024;
|
|
|
|
|
|
|
|
free(devices);
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_UUID, nullptr, 0, &uuid, sizeof(BTRFS_UUID));
|
2017-09-08 11:59:42 +00:00
|
|
|
uuid_set = NT_SUCCESS(Status);
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
ignore = false;
|
2017-09-08 11:59:42 +00:00
|
|
|
balance = new BtrfsBalance(fn);
|
|
|
|
} else {
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
GlobalUnlock(hdrop);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
typedef struct {
|
2018-12-16 11:04:40 +00:00
|
|
|
uint64_t dev_id;
|
|
|
|
wstring name;
|
|
|
|
uint64_t alloc;
|
|
|
|
uint64_t size;
|
2017-09-08 11:59:42 +00:00
|
|
|
} dev;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
void BtrfsVolPropSheet::FormatUsage(HWND hwndDlg, wstring& s, btrfs_usage* usage) {
|
|
|
|
uint8_t i, j;
|
|
|
|
uint64_t num_devs, dev_size, dev_alloc, data_size, data_alloc, metadata_size, metadata_alloc;
|
2017-09-08 11:59:42 +00:00
|
|
|
btrfs_device* bd;
|
2018-12-16 11:04:40 +00:00
|
|
|
vector<dev> devs;
|
2017-09-08 11:59:42 +00:00
|
|
|
btrfs_usage* bue;
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring t, u, v;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
static const uint64_t types[] = { BLOCK_FLAG_DATA, BLOCK_FLAG_DATA | BLOCK_FLAG_METADATA, BLOCK_FLAG_METADATA, BLOCK_FLAG_SYSTEM };
|
2017-09-08 11:59:42 +00:00
|
|
|
static const ULONG typestrings[] = { IDS_USAGE_DATA, IDS_USAGE_MIXED, IDS_USAGE_METADATA, IDS_USAGE_SYSTEM };
|
2018-12-16 11:04:40 +00:00
|
|
|
static const uint64_t duptypes[] = { 0, BLOCK_FLAG_DUPLICATE, BLOCK_FLAG_RAID0, BLOCK_FLAG_RAID1, BLOCK_FLAG_RAID10, BLOCK_FLAG_RAID5, BLOCK_FLAG_RAID6 };
|
2017-09-08 11:59:42 +00:00
|
|
|
static const ULONG dupstrings[] = { IDS_SINGLE, IDS_DUP, IDS_RAID0, IDS_RAID1, IDS_RAID10, IDS_RAID5, IDS_RAID6 };
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s = L"";
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
num_devs = 0;
|
|
|
|
bd = devices;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
2017-09-08 11:59:42 +00:00
|
|
|
num_devs++;
|
|
|
|
|
|
|
|
if (bd->next_entry > 0)
|
2018-12-16 11:04:40 +00:00
|
|
|
bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
|
2017-09-08 11:59:42 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bd = devices;
|
|
|
|
|
|
|
|
dev_size = 0;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
dev d;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bd->missing) {
|
|
|
|
if (!load_string(module, IDS_MISSING, d.name))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
} else if (bd->device_number == 0xffffffff)
|
|
|
|
d.name = wstring(bd->name, bd->namelen / sizeof(WCHAR));
|
|
|
|
else if (bd->partition_number == 0) {
|
|
|
|
if (!load_string(module, IDS_DISK_NUM, u))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
|
|
|
|
wstring_sprintf(d.name, u, bd->device_number);
|
2017-09-08 11:59:42 +00:00
|
|
|
} else {
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_DISK_PART_NUM, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(d.name, u, bd->device_number, bd->partition_number);
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
d.dev_id = bd->dev_id;
|
|
|
|
d.alloc = 0;
|
|
|
|
d.size = bd->size;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
devs.push_back(d);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
dev_size += bd->size;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (bd->next_entry > 0)
|
2018-12-16 11:04:40 +00:00
|
|
|
bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
|
2017-09-08 11:59:42 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
dev_alloc = 0;
|
|
|
|
data_size = data_alloc = 0;
|
|
|
|
metadata_size = metadata_alloc = 0;
|
|
|
|
|
|
|
|
bue = usage;
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
for (uint64_t k = 0; k < bue->num_devices; k++) {
|
2017-09-08 11:59:42 +00:00
|
|
|
dev_alloc += bue->devices[k].alloc;
|
|
|
|
|
|
|
|
if (bue->type & BLOCK_FLAG_DATA) {
|
|
|
|
data_alloc += bue->devices[k].alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bue->type & BLOCK_FLAG_METADATA) {
|
|
|
|
metadata_alloc += bue->devices[k].alloc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bue->type & BLOCK_FLAG_DATA)
|
2017-09-08 11:59:42 +00:00
|
|
|
data_size += bue->size;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bue->type & BLOCK_FLAG_METADATA)
|
2017-09-08 11:59:42 +00:00
|
|
|
metadata_size += bue->size;
|
|
|
|
|
|
|
|
if (bue->next_entry > 0)
|
2018-12-16 11:04:40 +00:00
|
|
|
bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
|
2017-09-08 11:59:42 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// device size
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_USAGE_DEV_SIZE, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(dev_size, v, false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, u, v.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s += t + L"\r\n";
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
// device allocated
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_USAGE_DEV_ALLOC, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(dev_alloc, v, false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, u, v.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
s += t + L"\r\n"s;
|
|
|
|
#else
|
|
|
|
s += t + L"\r\n";
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
// device unallocated
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_USAGE_DEV_UNALLOC, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(dev_size - dev_alloc, v, false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, u, v.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
s += t + L"\r\n"s;
|
|
|
|
#else
|
|
|
|
s += t + L"\r\n";
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
// data ratio
|
|
|
|
|
|
|
|
if (data_alloc > 0) {
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_USAGE_DATA_RATIO, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, u, (float)data_alloc / (float)data_size);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
s += t + L"\r\n"s;
|
|
|
|
#else
|
|
|
|
s += t + L"\r\n";
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// metadata ratio
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_USAGE_METADATA_RATIO, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, u, (float)metadata_alloc / (float)metadata_size);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s += t + L"\r\n\r\n";
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
for (i = 0; i < sizeof(types) / sizeof(types[0]); i++) {
|
|
|
|
for (j = 0; j < sizeof(duptypes) / sizeof(duptypes[0]); j++) {
|
|
|
|
bue = usage;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
2017-09-08 11:59:42 +00:00
|
|
|
if ((bue->type & types[i]) == types[i] &&
|
|
|
|
((duptypes[j] == 0 && (bue->type & (BLOCK_FLAG_DUPLICATE | BLOCK_FLAG_RAID0 | BLOCK_FLAG_RAID1 | BLOCK_FLAG_RAID10 | BLOCK_FLAG_RAID5 | BLOCK_FLAG_RAID6)) == 0)
|
|
|
|
|| bue->type & duptypes[j])) {
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring sizestring, usedstring, typestring, dupstring;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (bue->type & BLOCK_FLAG_DATA && bue->type & BLOCK_FLAG_METADATA && (types[i] == BLOCK_FLAG_DATA || types[i] == BLOCK_FLAG_METADATA))
|
|
|
|
break;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, typestrings[i], typestring))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, dupstrings[j], dupstring))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(bue->size, sizestring, false);
|
|
|
|
format_size(bue->used, usedstring, false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, typestring, dupstring.c_str(), sizestring.c_str(), usedstring.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s += t + L"\r\n";
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
for (uint64_t k = 0; k < bue->num_devices; k++) {
|
|
|
|
bool found = false;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(bue->devices[k].alloc, sizestring, false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
for (size_t l = 0; l < min((uint64_t)SIZE_MAX, num_devs); l++) {
|
2017-09-08 11:59:42 +00:00
|
|
|
if (devs[l].dev_id == bue->devices[k].dev_id) {
|
2018-12-16 11:04:40 +00:00
|
|
|
s += devs[l].name + L"\t" + sizestring + L"\r\n";
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
devs[l].alloc += bue->devices[k].alloc;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
found = true;
|
2017-09-08 11:59:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_UNKNOWN_DEVICE, typestring))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, typestring, bue->devices[k].dev_id);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
s += t + L"\t"s + sizestring + L"\r\n"s;
|
|
|
|
#else
|
|
|
|
s += t + L"\t" + sizestring + L"\r\n";
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s += L"\r\n";
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bue->next_entry > 0)
|
2018-12-16 11:04:40 +00:00
|
|
|
bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
|
2017-09-08 11:59:42 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_USAGE_UNALLOC, t))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
s += t + L"\r\n"s;
|
|
|
|
#else
|
|
|
|
s += t + L"\r\n";
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
for (size_t k = 0; k < min((uint64_t)SIZE_MAX, num_devs); k++) {
|
|
|
|
wstring sizestring;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(devs[k].size - devs[k].alloc, sizestring, false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s += devs[k].name + L"\t" + sizestring + L"\r\n";
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtrfsVolPropSheet::RefreshUsage(HWND hwndDlg) {
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring s;
|
2017-09-08 11:59:42 +00:00
|
|
|
btrfs_usage* usage;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
ULONG devsize, usagesize, i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
devsize = 1024;
|
|
|
|
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
|
2017-09-08 11:59:42 +00:00
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
devsize += 1024;
|
|
|
|
|
|
|
|
free(devices);
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2017-09-08 11:59:42 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
usagesize = 1024;
|
|
|
|
|
|
|
|
usage = (btrfs_usage*)malloc(usagesize);
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_USAGE, nullptr, 0, usage, usagesize);
|
2017-09-08 11:59:42 +00:00
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
usagesize += 1024;
|
|
|
|
|
|
|
|
free(usage);
|
|
|
|
usage = (btrfs_usage*)malloc(usagesize);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
} else
|
|
|
|
return;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
free(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
ignore = false;
|
2017-09-08 11:59:42 +00:00
|
|
|
} else
|
|
|
|
return;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
FormatUsage(hwndDlg, s, usage);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_USAGE_BOX, s.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
free(usage);
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK BtrfsVolPropSheet::UsageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2018-12-16 11:04:40 +00:00
|
|
|
try {
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
wstring s;
|
|
|
|
int i;
|
|
|
|
ULONG usagesize;
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
btrfs_usage* usage;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
i = 0;
|
|
|
|
usagesize = 1024;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
usage = (btrfs_usage*)malloc(usagesize);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_USAGE, nullptr, 0, usage, usagesize);
|
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
usagesize += 1024;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
free(usage);
|
|
|
|
usage = (btrfs_usage*)malloc(usagesize);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
i++;
|
|
|
|
} else
|
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
} else
|
|
|
|
break;
|
2018-12-16 11:04:40 +00:00
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
free(usage);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
FormatUsage(hwndDlg, s, usage);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_USAGE_BOX, s.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
free(usage);
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
switch (HIWORD(wParam)) {
|
|
|
|
case BN_CLICKED:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case IDC_USAGE_REFRESH:
|
|
|
|
RefreshUsage(hwndDlg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-12-16 11:04:40 +00:00
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(hwndDlg, e.what());
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK stub_UsageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
BtrfsVolPropSheet* bvps;
|
|
|
|
|
|
|
|
if (uMsg == WM_INITDIALOG) {
|
|
|
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
|
|
|
|
bvps = (BtrfsVolPropSheet*)lParam;
|
|
|
|
} else {
|
|
|
|
bvps = (BtrfsVolPropSheet*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bvps)
|
|
|
|
return bvps->UsageDlgProc(hwndDlg, uMsg, wParam, lParam);
|
|
|
|
else
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BtrfsVolPropSheet::ShowUsage(HWND hwndDlg) {
|
|
|
|
DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_VOL_USAGE), hwndDlg, stub_UsageDlgProc, (LPARAM)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void add_lv_column(HWND list, int string, int cx) {
|
|
|
|
LVCOLUMNW lvc;
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring s;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, string, s))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
lvc.mask = LVCF_TEXT|LVCF_WIDTH;
|
2018-12-16 11:04:40 +00:00
|
|
|
lvc.pszText = (WCHAR*)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
lvc.cx = cx;
|
|
|
|
SendMessageW(list, LVM_INSERTCOLUMNW, 0, (LPARAM)&lvc);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int CALLBACK lv_sort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort) {
|
|
|
|
if (lParam1 < lParam2)
|
|
|
|
return -1;
|
|
|
|
else if (lParam1 > lParam2)
|
|
|
|
return 1;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
static uint64_t find_dev_alloc(uint64_t dev_id, btrfs_usage* usage) {
|
2017-09-08 11:59:42 +00:00
|
|
|
btrfs_usage* bue;
|
2018-12-16 11:04:40 +00:00
|
|
|
uint64_t alloc;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
alloc = 0;
|
|
|
|
|
|
|
|
bue = usage;
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
uint64_t k;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
for (k = 0; k < bue->num_devices; k++) {
|
|
|
|
if (bue->devices[k].dev_id == dev_id)
|
|
|
|
alloc += bue->devices[k].alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bue->next_entry > 0)
|
2018-12-16 11:04:40 +00:00
|
|
|
bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
|
2017-09-08 11:59:42 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return alloc;
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtrfsVolPropSheet::RefreshDevList(HWND devlist) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
ULONG usagesize, devsize;
|
|
|
|
btrfs_usage* usage;
|
|
|
|
btrfs_device* bd;
|
|
|
|
int i;
|
2018-12-16 11:04:40 +00:00
|
|
|
uint64_t num_rw_devices;
|
|
|
|
{
|
|
|
|
win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
i = 0;
|
|
|
|
devsize = 1024;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (devices)
|
|
|
|
free(devices);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
|
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
devsize += 1024;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
free(devices);
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
i++;
|
|
|
|
} else
|
|
|
|
return;
|
2017-09-08 11:59:42 +00:00
|
|
|
} else
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
return;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
bd = devices;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
i = 0;
|
|
|
|
usagesize = 1024;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
usage = (btrfs_usage*)malloc(usagesize);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_USAGE, nullptr, 0, usage, usagesize);
|
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
usagesize += 1024;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
free(usage);
|
|
|
|
usage = (btrfs_usage*)malloc(usagesize);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
i++;
|
|
|
|
} else {
|
|
|
|
free(usage);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!NT_SUCCESS(Status)) {
|
|
|
|
free(usage);
|
|
|
|
return;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SendMessageW(devlist, LVM_DELETEALLITEMS, 0, 0);
|
|
|
|
|
|
|
|
num_rw_devices = 0;
|
|
|
|
|
|
|
|
i = 0;
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
2017-09-08 11:59:42 +00:00
|
|
|
LVITEMW lvi;
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring s, u;
|
|
|
|
uint64_t alloc;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
// ID
|
|
|
|
|
|
|
|
RtlZeroMemory(&lvi, sizeof(LVITEMW));
|
|
|
|
lvi.mask = LVIF_TEXT | LVIF_PARAM;
|
2019-11-12 20:45:49 +00:00
|
|
|
lvi.iItem = (int)SendMessageW(devlist, LVM_GETITEMCOUNT, 0, 0);
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.lParam = (LPARAM)bd->dev_id;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
s = to_wstring(bd->dev_id);
|
|
|
|
lvi.pszText = (LPWSTR)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
SendMessageW(devlist, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
// description
|
|
|
|
|
|
|
|
lvi.mask = LVIF_TEXT;
|
|
|
|
lvi.iSubItem = 1;
|
|
|
|
|
|
|
|
if (bd->missing) {
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_MISSING, s))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
} else if (bd->device_number == 0xffffffff)
|
|
|
|
s = wstring(bd->name, bd->namelen / sizeof(WCHAR));
|
|
|
|
else if (bd->partition_number == 0) {
|
|
|
|
if (!load_string(module, IDS_DISK_NUM, u))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
|
|
|
|
wstring_sprintf(s, u, bd->device_number);
|
2017-09-08 11:59:42 +00:00
|
|
|
} else {
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_DISK_PART_NUM, u))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(s, u, bd->device_number, bd->partition_number);
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.pszText = (LPWSTR)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
// readonly
|
|
|
|
|
|
|
|
lvi.iSubItem = 2;
|
2018-12-16 11:04:40 +00:00
|
|
|
load_string(module, bd->readonly ? IDS_DEVLIST_READONLY_YES : IDS_DEVLIST_READONLY_NO, s);
|
|
|
|
lvi.pszText = (LPWSTR)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
if (!bd->readonly)
|
|
|
|
num_rw_devices++;
|
|
|
|
|
|
|
|
// size
|
|
|
|
|
|
|
|
lvi.iSubItem = 3;
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(bd->size, s, false);
|
|
|
|
lvi.pszText = (LPWSTR)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
// alloc
|
|
|
|
|
|
|
|
alloc = find_dev_alloc(bd->dev_id, usage);
|
|
|
|
|
|
|
|
lvi.iSubItem = 4;
|
2018-12-16 11:04:40 +00:00
|
|
|
format_size(alloc, s, false);
|
|
|
|
lvi.pszText = (LPWSTR)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
// alloc %
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(s, L"%1.1f%%", (float)alloc * 100.0f / (float)bd->size);
|
2017-09-08 11:59:42 +00:00
|
|
|
lvi.iSubItem = 5;
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.pszText = (LPWSTR)s.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
|
|
|
|
if (bd->next_entry > 0)
|
2018-12-16 11:04:40 +00:00
|
|
|
bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
|
2017-09-08 11:59:42 +00:00
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
free(usage);
|
|
|
|
|
|
|
|
SendMessageW(devlist, LVM_SORTITEMS, 0, (LPARAM)lv_sort);
|
|
|
|
|
|
|
|
EnableWindow(GetDlgItem(GetParent(devlist), IDC_DEVICE_ADD), num_rw_devices > 0);
|
|
|
|
EnableWindow(GetDlgItem(GetParent(devlist), IDC_DEVICE_REMOVE), num_rw_devices > 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtrfsVolPropSheet::ResetStats(HWND hwndDlg) {
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring t, sel;
|
|
|
|
WCHAR modfn[MAX_PATH];
|
2017-09-08 11:59:42 +00:00
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
sel = to_wstring(stats_dev);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
t = L"\""s + modfn + L"\",ResetStats " + fn + L"|" + sel;
|
|
|
|
#else
|
|
|
|
t = wstring(L"\"") + modfn + wstring(L"\",ResetStats ") + fn + wstring(L"|") + sel;
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
RtlZeroMemory(&sei, sizeof(sei));
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.hwnd = hwndDlg;
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
sei.lpFile = L"rundll32.exe";
|
2018-12-16 11:04:40 +00:00
|
|
|
sei.lpParameters = t.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
sei.nShow = SW_SHOW;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!ShellExecuteExW(&sei))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
CloseHandle(sei.hProcess);
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
win_handle h = CreateFileW(fn.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
if (h != INVALID_HANDLE_VALUE) {
|
|
|
|
NTSTATUS Status;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
|
|
|
ULONG devsize, i;
|
|
|
|
|
|
|
|
i = 0;
|
|
|
|
devsize = 1024;
|
|
|
|
|
|
|
|
free(devices);
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
|
2017-09-08 11:59:42 +00:00
|
|
|
if (Status == STATUS_BUFFER_OVERFLOW) {
|
|
|
|
if (i < 8) {
|
|
|
|
devsize += 1024;
|
|
|
|
|
|
|
|
free(devices);
|
|
|
|
devices = (btrfs_device*)malloc(devsize);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
} else
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK BtrfsVolPropSheet::StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2018-12-16 11:04:40 +00:00
|
|
|
try {
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
WCHAR s[255];
|
|
|
|
wstring t;
|
|
|
|
btrfs_device *bd, *dev = nullptr;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
static int stat_ids[] = { IDC_WRITE_ERRS, IDC_READ_ERRS, IDC_FLUSH_ERRS, IDC_CORRUPTION_ERRS, IDC_GENERATION_ERRS };
|
|
|
|
|
|
|
|
bd = devices;
|
|
|
|
|
|
|
|
while (true) {
|
|
|
|
if (bd->dev_id == stats_dev) {
|
|
|
|
dev = bd;
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bd->next_entry > 0)
|
|
|
|
bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
|
|
|
|
else
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!dev) {
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
throw string_error(IDS_CANNOT_FIND_DEVICE);
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
GetDlgItemTextW(hwndDlg, IDC_DEVICE_ID, s, sizeof(s) / sizeof(WCHAR));
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, s, dev->dev_id);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_DEVICE_ID, t.c_str());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
GetDlgItemTextW(hwndDlg, stat_ids[i], s, sizeof(s) / sizeof(WCHAR));
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, s, dev->stats[i]);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SetDlgItemTextW(hwndDlg, stat_ids[i], t.c_str());
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDC_RESET_STATS), BCM_SETSHIELD, 0, true);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_RESET_STATS), !readonly);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
switch (HIWORD(wParam)) {
|
|
|
|
case BN_CLICKED:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case IDC_RESET_STATS:
|
|
|
|
ResetStats(hwndDlg);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
break;
|
|
|
|
}
|
2018-12-16 11:04:40 +00:00
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(hwndDlg, e.what());
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK stub_StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
BtrfsVolPropSheet* bvps;
|
|
|
|
|
|
|
|
if (uMsg == WM_INITDIALOG) {
|
|
|
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
|
|
|
|
bvps = (BtrfsVolPropSheet*)lParam;
|
|
|
|
} else {
|
|
|
|
bvps = (BtrfsVolPropSheet*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bvps)
|
|
|
|
return bvps->StatsDlgProc(hwndDlg, uMsg, wParam, lParam);
|
|
|
|
else
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
void BtrfsVolPropSheet::ShowStats(HWND hwndDlg, uint64_t devid) {
|
2017-09-08 11:59:42 +00:00
|
|
|
stats_dev = devid;
|
|
|
|
|
|
|
|
DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_DEVICE_STATS), hwndDlg, stub_StatsDlgProc, (LPARAM)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR CALLBACK BtrfsVolPropSheet::DeviceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2018-12-16 11:04:40 +00:00
|
|
|
try {
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
HWND devlist;
|
|
|
|
RECT rect;
|
|
|
|
ULONG w;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
GetClientRect(devlist, &rect);
|
|
|
|
w = rect.right - rect.left;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
add_lv_column(devlist, IDS_DEVLIST_ALLOC_PC, w * 5 / 44);
|
|
|
|
add_lv_column(devlist, IDS_DEVLIST_ALLOC, w * 6 / 44);
|
|
|
|
add_lv_column(devlist, IDS_DEVLIST_SIZE, w * 6 / 44);
|
|
|
|
add_lv_column(devlist, IDS_DEVLIST_READONLY, w * 7 / 44);
|
|
|
|
add_lv_column(devlist, IDS_DEVLIST_DESC, w * 16 / 44);
|
|
|
|
add_lv_column(devlist, IDS_DEVLIST_ID, w * 4 / 44);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDC_DEVICE_ADD), BCM_SETSHIELD, 0, true);
|
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDC_DEVICE_REMOVE), BCM_SETSHIELD, 0, true);
|
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDC_DEVICE_RESIZE), BCM_SETSHIELD, 0, true);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
RefreshDevList(devlist);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (HIWORD(wParam)) {
|
|
|
|
case BN_CLICKED:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDOK:
|
|
|
|
case IDCANCEL:
|
|
|
|
KillTimer(hwndDlg, 1);
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_DEVICE_ADD:
|
|
|
|
{
|
|
|
|
wstring t;
|
|
|
|
WCHAR modfn[MAX_PATH];
|
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
|
|
|
|
GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
t = L"\""s + modfn + L"\",AddDevice "s + fn;
|
|
|
|
#else
|
|
|
|
t = wstring(L"\"") + modfn + wstring(L"\",AddDevice ") + fn;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RtlZeroMemory(&sei, sizeof(sei));
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.hwnd = hwndDlg;
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
sei.lpFile = L"rundll32.exe";
|
|
|
|
sei.lpParameters = t.c_str();
|
|
|
|
sei.nShow = SW_SHOW;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
|
|
|
|
if (!ShellExecuteExW(&sei))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
|
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
CloseHandle(sei.hProcess);
|
|
|
|
|
|
|
|
RefreshDevList(GetDlgItem(hwndDlg, IDC_DEVLIST));
|
|
|
|
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_DEVICE_REFRESH:
|
|
|
|
RefreshDevList(GetDlgItem(hwndDlg, IDC_DEVLIST));
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_DEVICE_SHOW_STATS:
|
|
|
|
{
|
|
|
|
WCHAR sel[MAX_PATH];
|
|
|
|
HWND devlist;
|
|
|
|
LVITEMW lvi;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2019-11-12 20:45:49 +00:00
|
|
|
auto index = SendMessageW(devlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (index == -1)
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
RtlZeroMemory(&lvi, sizeof(LVITEMW));
|
|
|
|
lvi.mask = LVIF_TEXT;
|
2019-11-12 20:45:49 +00:00
|
|
|
lvi.iItem = (int)index;
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.iSubItem = 0;
|
|
|
|
lvi.pszText = sel;
|
|
|
|
lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
|
|
|
|
SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
ShowStats(hwndDlg, _wtoi(sel));
|
|
|
|
return true;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_DEVICE_REMOVE:
|
|
|
|
{
|
|
|
|
wstring t, mess, mess2, title;
|
|
|
|
WCHAR modfn[MAX_PATH], sel[MAX_PATH], sel2[MAX_PATH];
|
|
|
|
HWND devlist;
|
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
LVITEMW lvi;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2019-11-12 20:45:49 +00:00
|
|
|
auto index = SendMessageW(devlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (index == -1)
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
RtlZeroMemory(&lvi, sizeof(LVITEMW));
|
|
|
|
lvi.mask = LVIF_TEXT;
|
2019-11-12 20:45:49 +00:00
|
|
|
lvi.iItem = (int)index;
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.iSubItem = 0;
|
|
|
|
lvi.pszText = sel;
|
|
|
|
lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
|
|
|
|
SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.iSubItem = 1;
|
|
|
|
lvi.pszText = sel2;
|
|
|
|
lvi.cchTextMax = sizeof(sel2) / sizeof(WCHAR);
|
|
|
|
SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_REMOVE_DEVICE_CONFIRMATION, mess))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(mess2, mess, sel, sel2);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!load_string(module, IDS_CONFIRMATION_TITLE, title))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (MessageBoxW(hwndDlg, mess2.c_str(), title.c_str(), MB_YESNO) != IDYES)
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
#ifndef __REACTOS__
|
|
|
|
t = L"\""s + modfn + L"\",RemoveDevice "s + fn + L"|"s + sel;
|
|
|
|
#else
|
|
|
|
t = wstring(L"\"") + modfn + wstring(L"\",RemoveDevice ") + fn + wstring(L"|") + sel;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RtlZeroMemory(&sei, sizeof(sei));
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.hwnd = hwndDlg;
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
sei.lpFile = L"rundll32.exe";
|
|
|
|
sei.lpParameters = t.c_str();
|
|
|
|
sei.nShow = SW_SHOW;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!ShellExecuteExW(&sei))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
|
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
CloseHandle(sei.hProcess);
|
|
|
|
|
|
|
|
RefreshDevList(GetDlgItem(hwndDlg, IDC_DEVLIST));
|
|
|
|
|
|
|
|
return true;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_DEVICE_RESIZE:
|
|
|
|
{
|
|
|
|
HWND devlist;
|
|
|
|
LVITEMW lvi;
|
|
|
|
wstring t;
|
|
|
|
WCHAR modfn[MAX_PATH], sel[100];
|
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
|
|
|
|
devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
|
|
|
|
|
2019-11-12 20:45:49 +00:00
|
|
|
auto index = SendMessageW(devlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
|
2018-12-16 11:04:40 +00:00
|
|
|
|
|
|
|
if (index == -1)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
RtlZeroMemory(&lvi, sizeof(LVITEMW));
|
|
|
|
lvi.mask = LVIF_TEXT;
|
2019-11-12 20:45:49 +00:00
|
|
|
lvi.iItem = (int)index;
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.iSubItem = 0;
|
|
|
|
lvi.pszText = sel;
|
|
|
|
lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
|
|
|
|
SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
|
|
|
|
|
|
|
|
GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
t = L"\""s + modfn + L"\",ResizeDevice "s + fn + L"|"s + sel;
|
|
|
|
#else
|
|
|
|
t = wstring(L"\"") + modfn + wstring(L"\",ResizeDevice ") + fn + wstring(L"|") + sel;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RtlZeroMemory(&sei, sizeof(sei));
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.hwnd = hwndDlg;
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
sei.lpFile = L"rundll32.exe";
|
|
|
|
sei.lpParameters = t.c_str();
|
|
|
|
sei.nShow = SW_SHOW;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
|
|
|
|
if (!ShellExecuteExW(&sei))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
CloseHandle(sei.hProcess);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
RefreshDevList(GetDlgItem(hwndDlg, IDC_DEVLIST));
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case WM_NOTIFY:
|
|
|
|
switch (((LPNMHDR)lParam)->code) {
|
|
|
|
case LVN_ITEMCHANGED:
|
|
|
|
{
|
|
|
|
NMLISTVIEW* nmv = (NMLISTVIEW*)lParam;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_SHOW_STATS), nmv->uNewState & LVIS_SELECTED);
|
|
|
|
|
|
|
|
if (nmv->uNewState & LVIS_SELECTED && !readonly) {
|
2017-09-08 11:59:42 +00:00
|
|
|
HWND devlist;
|
2018-12-16 11:04:40 +00:00
|
|
|
btrfs_device* bd;
|
|
|
|
bool device_readonly = false;
|
2017-09-08 11:59:42 +00:00
|
|
|
LVITEMW lvi;
|
2018-12-16 11:04:40 +00:00
|
|
|
WCHAR sel[MAX_PATH];
|
|
|
|
uint64_t devid;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
|
|
|
|
|
|
|
|
RtlZeroMemory(&lvi, sizeof(LVITEMW));
|
|
|
|
lvi.mask = LVIF_TEXT;
|
2018-12-16 11:04:40 +00:00
|
|
|
lvi.iItem = nmv->iItem;
|
2017-09-08 11:59:42 +00:00
|
|
|
lvi.iSubItem = 0;
|
|
|
|
lvi.pszText = sel;
|
|
|
|
lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
|
|
|
|
SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
|
2018-12-16 11:04:40 +00:00
|
|
|
devid = _wtoi(sel);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
bd = devices;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
if (bd->dev_id == devid) {
|
|
|
|
device_readonly = bd->readonly;
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bd->next_entry > 0)
|
|
|
|
bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
|
|
|
|
else
|
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_RESIZE), !device_readonly);
|
|
|
|
} else
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_RESIZE), false);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(hwndDlg, e.what());
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static INT_PTR CALLBACK stub_DeviceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
BtrfsVolPropSheet* bvps;
|
|
|
|
|
|
|
|
if (uMsg == WM_INITDIALOG) {
|
|
|
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
|
|
|
|
bvps = (BtrfsVolPropSheet*)lParam;
|
|
|
|
} else {
|
|
|
|
bvps = (BtrfsVolPropSheet*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bvps)
|
|
|
|
return bvps->DeviceDlgProc(hwndDlg, uMsg, wParam, lParam);
|
|
|
|
else
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void BtrfsVolPropSheet::ShowDevices(HWND hwndDlg) {
|
|
|
|
DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_DEVICES), hwndDlg, stub_DeviceDlgProc, (LPARAM)this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void BtrfsVolPropSheet::ShowScrub(HWND hwndDlg) {
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring t;
|
|
|
|
WCHAR modfn[MAX_PATH];
|
2017-09-08 11:59:42 +00:00
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
t = L"\""s + modfn + L"\",ShowScrub "s + fn;
|
|
|
|
#else
|
|
|
|
t = wstring(L"\"") + modfn + wstring(L"\",ShowScrub ") + fn;
|
|
|
|
#endif
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
RtlZeroMemory(&sei, sizeof(sei));
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.hwnd = hwndDlg;
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
sei.lpFile = L"rundll32.exe";
|
2018-12-16 11:04:40 +00:00
|
|
|
sei.lpParameters = t.c_str();
|
2017-09-08 11:59:42 +00:00
|
|
|
sei.nShow = SW_SHOW;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!ShellExecuteExW(&sei))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
CloseHandle(sei.hProcess);
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:45:49 +00:00
|
|
|
void BtrfsVolPropSheet::ShowChangeDriveLetter(HWND hwndDlg) {
|
|
|
|
wstring t;
|
|
|
|
WCHAR modfn[MAX_PATH];
|
|
|
|
SHELLEXECUTEINFOW sei;
|
|
|
|
|
|
|
|
GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
|
|
|
|
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
t = L"\""s + modfn + L"\",ShowChangeDriveLetter "s + fn;
|
|
|
|
#else
|
|
|
|
t = wstring(L"\"") + modfn + wstring(L"\",ShowChangeDriveLetter ") + fn;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
RtlZeroMemory(&sei, sizeof(sei));
|
|
|
|
|
|
|
|
sei.cbSize = sizeof(sei);
|
|
|
|
sei.hwnd = hwndDlg;
|
|
|
|
sei.lpVerb = L"runas";
|
|
|
|
sei.lpFile = L"rundll32.exe";
|
|
|
|
sei.lpParameters = t.c_str();
|
|
|
|
sei.nShow = SW_SHOW;
|
|
|
|
sei.fMask = SEE_MASK_NOCLOSEPROCESS;
|
|
|
|
|
|
|
|
if (!ShellExecuteExW(&sei))
|
|
|
|
throw last_error(GetLastError());
|
|
|
|
|
|
|
|
WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
|
CloseHandle(sei.hProcess);
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:59:42 +00:00
|
|
|
static INT_PTR CALLBACK PropSheetDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
2018-12-16 11:04:40 +00:00
|
|
|
try {
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
PROPSHEETPAGE* psp = (PROPSHEETPAGE*)lParam;
|
|
|
|
BtrfsVolPropSheet* bps = (BtrfsVolPropSheet*)psp->lParam;
|
|
|
|
btrfs_device* bd;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
EnableThemeDialogTexture(hwndDlg, ETDT_ENABLETAB);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)bps);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
bps->readonly = true;
|
|
|
|
bd = bps->devices;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
while (true) {
|
|
|
|
if (!bd->readonly) {
|
|
|
|
bps->readonly = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bd->next_entry > 0)
|
|
|
|
bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
|
|
|
|
else
|
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bps->uuid_set) {
|
|
|
|
WCHAR s[255];
|
|
|
|
wstring t;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
GetDlgItemTextW(hwndDlg, IDC_UUID, s, sizeof(s) / sizeof(WCHAR));
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
wstring_sprintf(t, s, bps->uuid.uuid[0], bps->uuid.uuid[1], bps->uuid.uuid[2], bps->uuid.uuid[3], bps->uuid.uuid[4], bps->uuid.uuid[5],
|
|
|
|
bps->uuid.uuid[6], bps->uuid.uuid[7], bps->uuid.uuid[8], bps->uuid.uuid[9], bps->uuid.uuid[10], bps->uuid.uuid[11],
|
|
|
|
bps->uuid.uuid[12], bps->uuid.uuid[13], bps->uuid.uuid[14], bps->uuid.uuid[15]);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_UUID, t.c_str());
|
|
|
|
} else
|
2017-09-08 11:59:42 +00:00
|
|
|
SetDlgItemTextW(hwndDlg, IDC_UUID, L"");
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDC_VOL_SCRUB), BCM_SETSHIELD, 0, true);
|
2019-11-12 20:45:49 +00:00
|
|
|
SendMessageW(GetDlgItem(hwndDlg, IDC_VOL_CHANGE_DRIVE_LETTER), BCM_SETSHIELD, 0, true);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case WM_NOTIFY:
|
|
|
|
{
|
|
|
|
switch (((LPNMHDR)lParam)->code) {
|
|
|
|
case PSN_KILLACTIVE:
|
|
|
|
SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, false);
|
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case WM_COMMAND:
|
|
|
|
{
|
|
|
|
BtrfsVolPropSheet* bps = (BtrfsVolPropSheet*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (bps) {
|
|
|
|
switch (HIWORD(wParam)) {
|
|
|
|
case BN_CLICKED: {
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDC_VOL_SHOW_USAGE:
|
|
|
|
bps->ShowUsage(hwndDlg);
|
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_VOL_BALANCE:
|
|
|
|
bps->balance->ShowBalance(hwndDlg);
|
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_VOL_DEVICES:
|
|
|
|
bps->ShowDevices(hwndDlg);
|
|
|
|
break;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
case IDC_VOL_SCRUB:
|
|
|
|
bps->ShowScrub(hwndDlg);
|
|
|
|
break;
|
2019-11-12 20:45:49 +00:00
|
|
|
|
|
|
|
case IDC_VOL_CHANGE_DRIVE_LETTER:
|
|
|
|
bps->ShowChangeDriveLetter(hwndDlg);
|
|
|
|
break;
|
2018-12-16 11:04:40 +00:00
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
2018-12-16 11:04:40 +00:00
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(hwndDlg, e.what());
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
return false;
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall BtrfsVolPropSheet::AddPages(LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam) {
|
2018-12-16 11:04:40 +00:00
|
|
|
try {
|
|
|
|
PROPSHEETPAGE psp;
|
|
|
|
HPROPSHEETPAGE hPage;
|
|
|
|
INITCOMMONCONTROLSEX icex;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (ignore)
|
2017-09-08 11:59:42 +00:00
|
|
|
return S_OK;
|
2018-12-16 11:04:40 +00:00
|
|
|
|
|
|
|
icex.dwSize = sizeof(icex);
|
|
|
|
icex.dwICC = ICC_LINK_CLASS;
|
|
|
|
|
|
|
|
if (!InitCommonControlsEx(&icex))
|
|
|
|
throw string_error(IDS_INITCOMMONCONTROLSEX_FAILED);
|
|
|
|
|
|
|
|
psp.dwSize = sizeof(psp);
|
|
|
|
psp.dwFlags = PSP_USEREFPARENT | PSP_USETITLE;
|
|
|
|
psp.hInstance = module;
|
|
|
|
psp.pszTemplate = MAKEINTRESOURCE(IDD_VOL_PROP_SHEET);
|
|
|
|
psp.hIcon = 0;
|
|
|
|
psp.pszTitle = MAKEINTRESOURCE(IDS_VOL_PROP_SHEET_TITLE);
|
|
|
|
psp.pfnDlgProc = (DLGPROC)PropSheetDlgProc;
|
|
|
|
psp.pcRefParent = (UINT*)&objs_loaded;
|
|
|
|
psp.pfnCallback = nullptr;
|
|
|
|
psp.lParam = (LPARAM)this;
|
|
|
|
|
|
|
|
hPage = CreatePropertySheetPage(&psp);
|
|
|
|
|
|
|
|
if (hPage) {
|
|
|
|
if (pfnAddPage(hPage, lParam)) {
|
|
|
|
this->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
} else
|
|
|
|
DestroyPropertySheetPage(hPage);
|
2017-09-08 11:59:42 +00:00
|
|
|
} else
|
2018-12-16 11:04:40 +00:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(nullptr, e.what());
|
|
|
|
}
|
2017-09-08 11:59:42 +00:00
|
|
|
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT __stdcall BtrfsVolPropSheet::ReplacePage(UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:45:49 +00:00
|
|
|
void BtrfsChangeDriveLetter::do_change(HWND hwndDlg) {
|
|
|
|
unsigned int sel = (unsigned int)SendDlgItemMessageW(hwndDlg, IDC_DRIVE_LETTER_COMBO, CB_GETCURSEL, 0, 0);
|
|
|
|
|
|
|
|
if (sel >= 0 && sel < letters.size()) {
|
|
|
|
wstring dd;
|
|
|
|
|
|
|
|
if (fn.length() == 3 && fn[1] == L':' && fn[2] == L'\\') {
|
|
|
|
dd = L"\\DosDevices\\?:";
|
|
|
|
|
|
|
|
dd[12] = fn[0];
|
|
|
|
} else
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
throw runtime_error("Volume path was not root of drive.");
|
|
|
|
#else
|
|
|
|
error_message(nullptr, "Volume path was not root of drive.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mountmgr mm;
|
|
|
|
wstring dev_name;
|
|
|
|
|
|
|
|
{
|
|
|
|
auto v = mm.query_points(dd);
|
|
|
|
|
|
|
|
if (v.empty())
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
throw runtime_error("Error finding device name.");
|
|
|
|
#else
|
|
|
|
error_message(nullptr, "Error finding device name.");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
dev_name = v[0].device_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
wstring new_dd = L"\\DosDevices\\?:";
|
|
|
|
new_dd[12] = letters[sel];
|
|
|
|
|
|
|
|
mm.delete_points(dd);
|
|
|
|
|
|
|
|
try {
|
|
|
|
mm.create_point(new_dd, dev_name);
|
|
|
|
} catch (...) {
|
|
|
|
// if fails, try to recreate old symlink, so we're not left with no drive letter at all
|
|
|
|
mm.create_point(dd, dev_name);
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EndDialog(hwndDlg, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
INT_PTR BtrfsChangeDriveLetter::DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
try {
|
|
|
|
switch (uMsg) {
|
|
|
|
case WM_INITDIALOG:
|
|
|
|
{
|
|
|
|
HWND cb = GetDlgItem(hwndDlg, IDC_DRIVE_LETTER_COMBO);
|
|
|
|
|
|
|
|
SendMessageW(cb, CB_RESETCONTENT, 0, 0);
|
|
|
|
|
|
|
|
mountmgr mm;
|
|
|
|
wstring drv;
|
|
|
|
|
|
|
|
drv = L"\\DosDevices\\?:";
|
|
|
|
|
|
|
|
for (wchar_t l = 'A'; l <= 'Z'; l++) {
|
|
|
|
bool found = true;
|
|
|
|
|
|
|
|
drv[12] = l;
|
|
|
|
|
|
|
|
try {
|
|
|
|
auto v = mm.query_points(drv);
|
|
|
|
|
|
|
|
if (v.empty())
|
|
|
|
found = false;
|
|
|
|
} catch (const ntstatus_error& ntstatus) {
|
|
|
|
if (ntstatus.Status == STATUS_OBJECT_NAME_NOT_FOUND)
|
|
|
|
found = false;
|
|
|
|
else
|
|
|
|
throw;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!found) {
|
|
|
|
wstring str = L"?:";
|
|
|
|
|
|
|
|
str[0] = l;
|
|
|
|
letters.push_back(l);
|
|
|
|
|
|
|
|
SendMessageW(cb, CB_ADDSTRING, 0, reinterpret_cast<LPARAM>(str.c_str()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case WM_COMMAND:
|
|
|
|
switch (HIWORD(wParam)) {
|
|
|
|
case BN_CLICKED:
|
|
|
|
switch (LOWORD(wParam)) {
|
|
|
|
case IDOK:
|
|
|
|
do_change(hwndDlg);
|
|
|
|
return true;
|
|
|
|
|
|
|
|
case IDCANCEL:
|
|
|
|
EndDialog(hwndDlg, 0);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(hwndDlg, e.what());
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef __REACTOS__
|
|
|
|
INT_PTR CALLBACK VolPropSheetDlgproc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
BtrfsChangeDriveLetter* bcdl;
|
|
|
|
|
|
|
|
if (uMsg == WM_INITDIALOG) {
|
|
|
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
|
|
|
|
bcdl = (BtrfsChangeDriveLetter*)lParam;
|
|
|
|
} else
|
|
|
|
bcdl = (BtrfsChangeDriveLetter*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
|
|
|
|
|
|
|
return bcdl->DlgProc(hwndDlg, uMsg, wParam, lParam);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void BtrfsChangeDriveLetter::show() {
|
|
|
|
#ifndef __REACTOS__
|
|
|
|
DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_DRIVE_LETTER), hwnd, [](HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) {
|
|
|
|
BtrfsChangeDriveLetter* bcdl;
|
|
|
|
|
|
|
|
if (uMsg == WM_INITDIALOG) {
|
|
|
|
SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)lParam);
|
|
|
|
bcdl = (BtrfsChangeDriveLetter*)lParam;
|
|
|
|
} else
|
|
|
|
bcdl = (BtrfsChangeDriveLetter*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA);
|
|
|
|
|
|
|
|
return bcdl->DlgProc(hwndDlg, uMsg, wParam, lParam);
|
|
|
|
}, (LPARAM)this);
|
|
|
|
#else
|
|
|
|
DialogBoxParamW(module, MAKEINTRESOURCEW(IDD_DRIVE_LETTER), hwnd, VolPropSheetDlgproc, (LPARAM)this);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:59:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void CALLBACK ResetStatsW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
|
2018-12-16 11:04:40 +00:00
|
|
|
try {
|
|
|
|
win_handle token;
|
|
|
|
NTSTATUS Status;
|
|
|
|
TOKEN_PRIVILEGES tp;
|
|
|
|
LUID luid;
|
|
|
|
uint64_t devid;
|
|
|
|
wstring cmdline, vol, dev;
|
|
|
|
size_t pipe;
|
|
|
|
IO_STATUS_BLOCK iosb;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
set_dpi_aware();
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
cmdline = lpszCmdLine;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
tp.PrivilegeCount = 1;
|
|
|
|
tp.Privileges[0].Luid = luid;
|
|
|
|
tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
pipe = cmdline.find(L"|");
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (pipe == string::npos)
|
|
|
|
return;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
vol = cmdline.substr(0, pipe);
|
|
|
|
dev = cmdline.substr(pipe + 1);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
devid = _wtoi(dev.c_str());
|
|
|
|
if (devid == 0)
|
|
|
|
return;
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
win_handle h = CreateFileW(vol.c_str(), FILE_TRAVERSE | FILE_READ_ATTRIBUTES, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, nullptr,
|
|
|
|
OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OPEN_REPARSE_POINT, nullptr);
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
if (h == INVALID_HANDLE_VALUE)
|
|
|
|
throw last_error(GetLastError());
|
2017-09-08 11:59:42 +00:00
|
|
|
|
2018-12-16 11:04:40 +00:00
|
|
|
Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESET_STATS, &devid, sizeof(uint64_t), nullptr, 0);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
throw ntstatus_error(Status);
|
|
|
|
} catch (const exception& e) {
|
|
|
|
error_message(hwnd, e.what());
|
2017-09-08 11:59:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-12 20:45:49 +00:00
|
|
|
void CALLBACK ShowChangeDriveLetterW(HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow) {
|
|
|
|
BtrfsChangeDriveLetter bcdl(hwnd, lpszCmdLine);
|
|
|
|
|
|
|
|
bcdl.show();
|
|
|
|
}
|
|
|
|
|
2017-09-08 11:59:42 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|