ReactOS 0.4.15-dev-5667-ged97270
BtrfsVolPropSheet Class Reference

#include <volpropsheet.h>

Inheritance diagram for BtrfsVolPropSheet:
Collaboration diagram for BtrfsVolPropSheet:

Public Member Functions

 BtrfsVolPropSheet ()
 
virtual ~BtrfsVolPropSheet ()
 
HRESULT __stdcall QueryInterface (REFIID riid, void **ppObj)
 
ULONG __stdcall AddRef ()
 
ULONG __stdcall Release ()
 
virtual HRESULT __stdcall Initialize (PCIDLIST_ABSOLUTE pidlFolder, IDataObject *pdtobj, HKEY hkeyProgID)
 
virtual HRESULT __stdcall AddPages (LPFNADDPROPSHEETPAGE pfnAddPage, LPARAM lParam)
 
virtual HRESULT __stdcall ReplacePage (UINT uPageID, LPFNADDPROPSHEETPAGE pfnReplacePage, LPARAM lParam)
 
void FormatUsage (HWND hwndDlg, wstring &s, btrfs_usage *usage)
 
void RefreshUsage (HWND hwndDlg)
 
void ShowUsage (HWND hwndDlg)
 
INT_PTR CALLBACK UsageDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void RefreshDevList (HWND devlist)
 
INT_PTR CALLBACK DeviceDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void ShowDevices (HWND hwndDlg)
 
void ShowScrub (HWND hwndDlg)
 
void ShowChangeDriveLetter (HWND hwndDlg)
 
INT_PTR CALLBACK StatsDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void ShowStats (HWND hwndDlg, uint64_t devid)
 
void ResetStats (HWND hwndDlg)
 
HRESULT Initialize ([in] PCIDLIST_ABSOLUTE pidlFolder, [in] IDataObject *pdtobj, [in] HKEY hkeyProgID)
 
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Public Attributes

btrfs_devicedevices
 
bool readonly
 
BtrfsBalancebalance
 
BTRFS_UUID uuid
 
bool uuid_set
 

Private Attributes

LONG refcount
 
bool ignore
 
STGMEDIUM stgm
 
bool stgm_set
 
wstring fn
 
uint64_t stats_dev
 

Additional Inherited Members

- Public Types inherited from IShellExtInit
typedef IShellExtInitLPSHELLEXTINIT
 
- Public Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Private Types inherited from IShellPropSheetExt
enum  tagSHELLPROPSHEETEXTPAGEID { EXPPS_FILETYPES = 0x1 }
 
typedef UINT EXPPS
 
- Private Types inherited from IUnknown
typedef IUnknownLPUNKNOWN
 
- Private Member Functions inherited from IShellPropSheetExt
HRESULT AddPages ([in] LPFNSVADDPROPSHEETPAGE pfnAddPage, [in] LPARAM lParam)
 
HRESULT ReplacePage ([in] EXPPS uPageID, [in] LPFNSVADDPROPSHEETPAGE pfnReplaceWith, [in] LPARAM lParam)
 
HRESULT QueryInterface ([in] REFIID riid, [out, iid_is(riid)] void **ppvObject)
 
ULONG AddRef ()
 
ULONG Release ()
 

Detailed Description

Definition at line 33 of file volpropsheet.h.

Constructor & Destructor Documentation

◆ BtrfsVolPropSheet()

BtrfsVolPropSheet::BtrfsVolPropSheet ( )
inline

Definition at line 35 of file volpropsheet.h.

35 {
36 refcount = 0;
37 ignore = true;
38 stgm_set = false;
39 devices = nullptr;
40
42
43 balance = nullptr;
44 }
#define InterlockedIncrement
Definition: armddk.h:53
BtrfsBalance * balance
Definition: volpropsheet.h:102
btrfs_device * devices
Definition: volpropsheet.h:100
LONG objs_loaded
Definition: main.cpp:48

◆ ~BtrfsVolPropSheet()

virtual BtrfsVolPropSheet::~BtrfsVolPropSheet ( )
inlinevirtual

Definition at line 46 of file volpropsheet.h.

46 {
47 if (stgm_set) {
48 GlobalUnlock(stgm.hGlobal);
50 }
51
52 if (devices)
54
56
57 if (balance)
58 delete balance;
59 }
#define InterlockedDecrement
Definition: armddk.h:52
#define free
Definition: debug_ros.c:5
void WINAPI ReleaseStgMedium(STGMEDIUM *pmedium)
Definition: ole2.c:2033
BOOL NTAPI GlobalUnlock(HGLOBAL hMem)
Definition: heapmem.c:1190

Member Function Documentation

◆ AddPages()

HRESULT __stdcall BtrfsVolPropSheet::AddPages ( LPFNADDPROPSHEETPAGE  pfnAddPage,
LPARAM  lParam 
)
virtual

Definition at line 1429 of file volpropsheet.cpp.

1429 {
1430 try {
1431 PROPSHEETPAGEW psp;
1432 HPROPSHEETPAGE hPage;
1434
1435 if (ignore)
1436 return S_OK;
1437
1438 icex.dwSize = sizeof(icex);
1439 icex.dwICC = ICC_LINK_CLASS;
1440
1441 if (!InitCommonControlsEx(&icex))
1443
1444 psp.dwSize = sizeof(psp);
1446 psp.hInstance = module;
1448 psp.hIcon = 0;
1451 psp.pcRefParent = (UINT*)&objs_loaded;
1452 psp.pfnCallback = nullptr;
1453 psp.lParam = (LPARAM)this;
1454
1455 hPage = CreatePropertySheetPageW(&psp);
1456
1457 if (hPage) {
1458 if (pfnAddPage(hPage, lParam)) {
1459 this->AddRef();
1460 return S_OK;
1461 } else
1463 } else
1464 return E_OUTOFMEMORY;
1465 } catch (const exception& e) {
1466 error_message(nullptr, e.what());
1467 }
1468
1469 return E_FAIL;
1470}
ULONG __stdcall AddRef()
Definition: volpropsheet.h:65
LPARAM lParam
Definition: combotst.c:139
BOOL WINAPI InitCommonControlsEx(const INITCOMMONCONTROLSEX *lpInitCtrls)
Definition: commctrl.c:893
#define E_OUTOFMEMORY
Definition: ddrawi.h:100
#define E_FAIL
Definition: ddrawi.h:102
#define DLGPROC
Definition: maze.c:62
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
#define IDS_VOL_PROP_SHEET_TITLE
Definition: resource.h:41
#define IDS_INITCOMMONCONTROLSEX_FAILED
Definition: resource.h:205
#define IDD_VOL_PROP_SHEET
Definition: resource.h:11
HPROPSHEETPAGE WINAPI CreatePropertySheetPageW(LPCPROPSHEETPAGEW lpPropSheetPage)
Definition: propsheet.c:3075
BOOL WINAPI DestroyPropertySheetPage(HPROPSHEETPAGE hPropPage)
Definition: propsheet.c:3144
#define S_OK
Definition: intsafe.h:52
#define e
Definition: ke_i.h:82
struct _PSP * HPROPSHEETPAGE
Definition: mstask.idl:90
unsigned int UINT
Definition: ndis.h:50
static INT_PTR CALLBACK PropSheetDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: propsheet.cpp:1102
#define PSP_USEREFPARENT
Definition: prsht.h:29
#define PSP_USETITLE
Definition: prsht.h:26
#define ICC_LINK_CLASS
Definition: commctrl.h:74
DLGPROC pfnDlgProc
Definition: prsht.h:226
DWORD dwSize
Definition: prsht.h:214
DWORD dwFlags
Definition: prsht.h:215
LPARAM lParam
Definition: prsht.h:227
HICON hIcon
Definition: prsht.h:222
LPCWSTR pszTemplate
Definition: prsht.h:218
struct _PROPSHEETPAGEW *UINT * pcRefParent
Definition: prsht.h:229
LPCWSTR pszTitle
Definition: prsht.h:225
HINSTANCE hInstance
Definition: prsht.h:216
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

◆ AddRef()

ULONG __stdcall BtrfsVolPropSheet::AddRef ( void  )
inline

Implements IUnknown.

Definition at line 65 of file volpropsheet.h.

65 {
67 }

Referenced by AddPages(), and QueryInterface().

◆ DeviceDlgProc()

INT_PTR CALLBACK BtrfsVolPropSheet::DeviceDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 964 of file volpropsheet.cpp.

964 {
965 try {
966 switch (uMsg) {
967 case WM_INITDIALOG:
968 {
969 HWND devlist;
970 RECT rect;
971 ULONG w;
972
974
975 devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
976
977 GetClientRect(devlist, &rect);
978 w = rect.right - rect.left;
979
980 add_lv_column(devlist, IDS_DEVLIST_ALLOC_PC, w * 5 / 44);
981 add_lv_column(devlist, IDS_DEVLIST_ALLOC, w * 6 / 44);
982 add_lv_column(devlist, IDS_DEVLIST_SIZE, w * 6 / 44);
983 add_lv_column(devlist, IDS_DEVLIST_READONLY, w * 7 / 44);
984 add_lv_column(devlist, IDS_DEVLIST_DESC, w * 16 / 44);
985 add_lv_column(devlist, IDS_DEVLIST_ID, w * 4 / 44);
986
990
991 RefreshDevList(devlist);
992
993 break;
994 }
995
996 case WM_COMMAND:
997 switch (HIWORD(wParam)) {
998 case BN_CLICKED:
999 switch (LOWORD(wParam)) {
1000 case IDOK:
1001 case IDCANCEL:
1002 KillTimer(hwndDlg, 1);
1003 EndDialog(hwndDlg, 0);
1004 return true;
1005
1006 case IDC_DEVICE_ADD:
1007 {
1008 wstring t;
1009 WCHAR modfn[MAX_PATH];
1011
1012 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
1013
1014#ifndef __REACTOS__
1015 t = L"\""s + modfn + L"\",AddDevice "s + fn;
1016#else
1017 t = wstring(L"\"") + modfn + wstring(L"\",AddDevice ") + fn;
1018#endif
1019
1020 RtlZeroMemory(&sei, sizeof(sei));
1021
1022 sei.cbSize = sizeof(sei);
1023 sei.hwnd = hwndDlg;
1024 sei.lpVerb = L"runas";
1025 sei.lpFile = L"rundll32.exe";
1026 sei.lpParameters = t.c_str();
1027 sei.nShow = SW_SHOW;
1029
1030 if (!ShellExecuteExW(&sei))
1031 throw last_error(GetLastError());
1032
1034 CloseHandle(sei.hProcess);
1035
1037
1038 return true;
1039 }
1040
1041 case IDC_DEVICE_REFRESH:
1043 return true;
1044
1046 {
1047 WCHAR sel[MAX_PATH];
1048 HWND devlist;
1049 LVITEMW lvi;
1050
1051 devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
1052
1053 auto index = SendMessageW(devlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
1054
1055 if (index == -1)
1056 return true;
1057
1058 RtlZeroMemory(&lvi, sizeof(LVITEMW));
1059 lvi.mask = LVIF_TEXT;
1060 lvi.iItem = (int)index;
1061 lvi.iSubItem = 0;
1062 lvi.pszText = sel;
1063 lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
1064 SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
1065
1066 ShowStats(hwndDlg, _wtoi(sel));
1067 return true;
1068 }
1069
1070 case IDC_DEVICE_REMOVE:
1071 {
1072 wstring t, mess, mess2, title;
1073 WCHAR modfn[MAX_PATH], sel[MAX_PATH], sel2[MAX_PATH];
1074 HWND devlist;
1076 LVITEMW lvi;
1077
1078 devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
1079
1080 auto index = SendMessageW(devlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
1081
1082 if (index == -1)
1083 return true;
1084
1085 RtlZeroMemory(&lvi, sizeof(LVITEMW));
1086 lvi.mask = LVIF_TEXT;
1087 lvi.iItem = (int)index;
1088 lvi.iSubItem = 0;
1089 lvi.pszText = sel;
1090 lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
1091 SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
1092
1093 lvi.iSubItem = 1;
1094 lvi.pszText = sel2;
1095 lvi.cchTextMax = sizeof(sel2) / sizeof(WCHAR);
1096 SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
1097
1099 throw last_error(GetLastError());
1100
1101 wstring_sprintf(mess2, mess, sel, sel2);
1102
1104 throw last_error(GetLastError());
1105
1106 if (MessageBoxW(hwndDlg, mess2.c_str(), title.c_str(), MB_YESNO) != IDYES)
1107 return true;
1108
1109 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
1110
1111#ifndef __REACTOS__
1112 t = L"\""s + modfn + L"\",RemoveDevice "s + fn + L"|"s + sel;
1113#else
1114 t = wstring(L"\"") + modfn + wstring(L"\",RemoveDevice ") + fn + wstring(L"|") + sel;
1115#endif
1116
1117 RtlZeroMemory(&sei, sizeof(sei));
1118
1119 sei.cbSize = sizeof(sei);
1120 sei.hwnd = hwndDlg;
1121 sei.lpVerb = L"runas";
1122 sei.lpFile = L"rundll32.exe";
1123 sei.lpParameters = t.c_str();
1124 sei.nShow = SW_SHOW;
1126
1127 if (!ShellExecuteExW(&sei))
1128 throw last_error(GetLastError());
1129
1131 CloseHandle(sei.hProcess);
1132
1134
1135 return true;
1136 }
1137
1138 case IDC_DEVICE_RESIZE:
1139 {
1140 HWND devlist;
1141 LVITEMW lvi;
1142 wstring t;
1143 WCHAR modfn[MAX_PATH], sel[100];
1145
1146 devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
1147
1148 auto index = SendMessageW(devlist, LVM_GETNEXTITEM, -1, LVNI_SELECTED);
1149
1150 if (index == -1)
1151 return true;
1152
1153 RtlZeroMemory(&lvi, sizeof(LVITEMW));
1154 lvi.mask = LVIF_TEXT;
1155 lvi.iItem = (int)index;
1156 lvi.iSubItem = 0;
1157 lvi.pszText = sel;
1158 lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
1159 SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
1160
1161 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
1162
1163#ifndef __REACTOS__
1164 t = L"\""s + modfn + L"\",ResizeDevice "s + fn + L"|"s + sel;
1165#else
1166 t = wstring(L"\"") + modfn + wstring(L"\",ResizeDevice ") + fn + wstring(L"|") + sel;
1167#endif
1168
1169 RtlZeroMemory(&sei, sizeof(sei));
1170
1171 sei.cbSize = sizeof(sei);
1172 sei.hwnd = hwndDlg;
1173 sei.lpVerb = L"runas";
1174 sei.lpFile = L"rundll32.exe";
1175 sei.lpParameters = t.c_str();
1176 sei.nShow = SW_SHOW;
1178
1179 if (!ShellExecuteExW(&sei))
1180 throw last_error(GetLastError());
1181
1183 CloseHandle(sei.hProcess);
1184
1186 }
1187 }
1188 break;
1189 }
1190 break;
1191
1192 case WM_NOTIFY:
1193 switch (((LPNMHDR)lParam)->code) {
1194 case LVN_ITEMCHANGED:
1195 {
1196 NMLISTVIEW* nmv = (NMLISTVIEW*)lParam;
1197
1199
1200 if (nmv->uNewState & LVIS_SELECTED && !readonly) {
1201 HWND devlist;
1202 btrfs_device* bd;
1203 bool device_readonly = false;
1204 LVITEMW lvi;
1205 WCHAR sel[MAX_PATH];
1206 uint64_t devid;
1207
1208 devlist = GetDlgItem(hwndDlg, IDC_DEVLIST);
1209
1210 RtlZeroMemory(&lvi, sizeof(LVITEMW));
1211 lvi.mask = LVIF_TEXT;
1212 lvi.iItem = nmv->iItem;
1213 lvi.iSubItem = 0;
1214 lvi.pszText = sel;
1215 lvi.cchTextMax = sizeof(sel) / sizeof(WCHAR);
1216 SendMessageW(devlist, LVM_GETITEMW, 0, (LPARAM)&lvi);
1217 devid = _wtoi(sel);
1218
1219 bd = devices;
1220
1221 while (true) {
1222 if (bd->dev_id == devid) {
1223 device_readonly = bd->readonly;
1224 break;
1225 }
1226
1227 if (bd->next_entry > 0)
1228 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
1229 else
1230 break;
1231 }
1232
1233 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_RESIZE), !device_readonly);
1234 } else
1235 EnableWindow(GetDlgItem(hwndDlg, IDC_DEVICE_RESIZE), false);
1236
1237 break;
1238 }
1239 }
1240 break;
1241 }
1242 } catch (const exception& e) {
1243 error_message(hwndDlg, e.what());
1244 }
1245
1246 return false;
1247}
void RefreshDevList(HWND devlist)
void ShowStats(HWND hwndDlg, uint64_t devid)
WPARAM wParam
Definition: combotst.c:138
UINT64 uint64_t
Definition: types.h:77
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
#define IDC_DEVICE_REFRESH
Definition: resource.h:281
#define IDS_REMOVE_DEVICE_CONFIRMATION
Definition: resource.h:96
#define IDC_DEVICE_SHOW_STATS
Definition: resource.h:290
#define IDS_DEVLIST_ALLOC_PC
Definition: resource.h:83
#define IDC_DEVICE_ADD
Definition: resource.h:274
#define IDC_DEVICE_RESIZE
Definition: resource.h:294
#define IDC_DEVLIST
Definition: resource.h:302
#define IDS_DEVLIST_DESC
Definition: resource.h:75
#define IDS_DEVLIST_ALLOC
Definition: resource.h:81
#define IDS_DEVLIST_READONLY
Definition: resource.h:76
#define IDS_CONFIRMATION_TITLE
Definition: resource.h:97
#define IDS_DEVLIST_ID
Definition: resource.h:74
#define IDS_DEVLIST_SIZE
Definition: resource.h:77
#define IDC_DEVICE_REMOVE
Definition: resource.h:286
#define CloseHandle
Definition: compat.h:739
#define MAX_PATH
Definition: compat.h:34
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
#define INFINITE
Definition: serial.h:102
#define ETDT_ENABLETAB
Definition: dxdiag.c:30
GLdouble s
Definition: gl.h:2039
GLdouble GLdouble t
Definition: gl.h:2047
GLuint index
Definition: glext.h:6031
GLubyte GLubyte GLubyte GLubyte w
Definition: glext.h:6102
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
BYTE uint8_t
Definition: msvideo1.c:66
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
#define L(x)
Definition: ntvdm.h:50
#define LOWORD(l)
Definition: pedump.c:82
static char title[]
Definition: ps.c:92
#define LVNI_SELECTED
Definition: commctrl.h:2424
#define BCM_SETSHIELD
Definition: commctrl.h:4653
#define LVM_GETNEXTITEM
Definition: commctrl.h:2433
#define LVIS_SELECTED
Definition: commctrl.h:2319
#define LVIF_TEXT
Definition: commctrl.h:2309
#define LVN_ITEMCHANGED
Definition: commctrl.h:3131
#define LVM_GETITEMW
Definition: commctrl.h:2390
#define WM_NOTIFY
Definition: richedit.h:61
#define SEE_MASK_NOCLOSEPROCESS
Definition: shellapi.h:31
BOOL WINAPI DECLSPEC_HOTPATCH ShellExecuteExW(LPSHELLEXECUTEINFOW sei)
Definition: shlexec.cpp:2335
& rect
Definition: startmenu.cpp:1413
LPCWSTR lpParameters
Definition: shellapi.h:330
uint64_t dev_id
Definition: btrfsioctl.h:104
uint32_t next_entry
Definition: btrfsioctl.h:103
Definition: inflate.c:139
LPWSTR pszText
Definition: commctrl.h:2365
int iSubItem
Definition: commctrl.h:2362
int cchTextMax
Definition: commctrl.h:2366
UINT mask
Definition: commctrl.h:2360
UINT uNewState
Definition: commctrl.h:3036
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:262
uint32_t ULONG
Definition: typedefs.h:59
#define HIWORD(l)
Definition: typedefs.h:247
HRESULT WINAPI EnableThemeDialogTexture(_In_ HWND hwnd, _In_ DWORD dwFlags)
Definition: uxthemesupp.c:55
static void add_lv_column(HWND list, int string, int cx)
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define IDCANCEL
Definition: winuser.h:825
#define WM_COMMAND
Definition: winuser.h:1730
#define WM_INITDIALOG
Definition: winuser.h:1729
#define MB_YESNO
Definition: winuser.h:811
int WINAPI MessageBoxW(_In_opt_ HWND hWnd, _In_opt_ LPCWSTR lpText, _In_opt_ LPCWSTR lpCaption, _In_ UINT uType)
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define IDOK
Definition: winuser.h:824
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define BN_CLICKED
Definition: winuser.h:1915
#define SW_SHOW
Definition: winuser.h:769
#define IDYES
Definition: winuser.h:829
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by stub_DeviceDlgProc().

◆ FormatUsage()

void BtrfsVolPropSheet::FormatUsage ( HWND  hwndDlg,
wstring &  s,
btrfs_usage usage 
)

Definition at line 165 of file volpropsheet.cpp.

165 {
166 uint8_t i, j;
167 uint64_t num_devs, dev_size, dev_alloc, data_size, data_alloc, metadata_size, metadata_alloc;
168 btrfs_device* bd;
169 vector<dev> devs;
170 btrfs_usage* bue;
171 wstring t, u, v;
172
174 static const ULONG typestrings[] = { IDS_USAGE_DATA, IDS_USAGE_MIXED, IDS_USAGE_METADATA, IDS_USAGE_SYSTEM };
178
181
182 s = L"";
183
184 num_devs = 0;
185 bd = devices;
186
187 while (true) {
188 num_devs++;
189
190 if (bd->next_entry > 0)
191 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
192 else
193 break;
194 }
195
196 bd = devices;
197
198 dev_size = 0;
199
200 while (true) {
201 dev d;
202
203 if (bd->missing) {
205 throw last_error(GetLastError());
206 } else if (bd->device_number == 0xffffffff)
207 d.name = wstring(bd->name, bd->namelen / sizeof(WCHAR));
208 else if (bd->partition_number == 0) {
210 throw last_error(GetLastError());
211
213 } else {
215 throw last_error(GetLastError());
216
218 }
219
220 d.dev_id = bd->dev_id;
221 d.alloc = 0;
222 d.size = bd->size;
223
224 devs.push_back(d);
225
226 dev_size += bd->size;
227
228 if (bd->next_entry > 0)
229 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
230 else
231 break;
232 }
233
234 dev_alloc = 0;
235 data_size = data_alloc = 0;
236 metadata_size = metadata_alloc = 0;
237
238 bue = usage;
239 while (true) {
240 for (uint64_t k = 0; k < bue->num_devices; k++) {
241 dev_alloc += bue->devices[k].alloc;
242
243 if (bue->type & BLOCK_FLAG_DATA) {
244 data_alloc += bue->devices[k].alloc;
245 }
246
247 if (bue->type & BLOCK_FLAG_METADATA) {
248 metadata_alloc += bue->devices[k].alloc;
249 }
250 }
251
252 if (bue->type & BLOCK_FLAG_DATA)
253 data_size += bue->size;
254
255 if (bue->type & BLOCK_FLAG_METADATA)
256 metadata_size += bue->size;
257
258 if (bue->next_entry > 0)
259 bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
260 else
261 break;
262 }
263
264 // device size
265
267 throw last_error(GetLastError());
268
269 format_size(dev_size, v, false);
270
271 wstring_sprintf(t, u, v.c_str());
272
273 s += t + L"\r\n";
274
275 // device allocated
276
278 throw last_error(GetLastError());
279
280 format_size(dev_alloc, v, false);
281
282 wstring_sprintf(t, u, v.c_str());
283
284#ifndef __REACTOS__
285 s += t + L"\r\n"s;
286#else
287 s += t + L"\r\n";
288#endif
289
290 // device unallocated
291
293 throw last_error(GetLastError());
294
295 format_size(dev_size - dev_alloc, v, false);
296
297 wstring_sprintf(t, u, v.c_str());
298
299#ifndef __REACTOS__
300 s += t + L"\r\n"s;
301#else
302 s += t + L"\r\n";
303#endif
304
305 // data ratio
306
307 if (data_alloc > 0) {
309 throw last_error(GetLastError());
310
311 wstring_sprintf(t, u, (float)data_alloc / (float)data_size);
312
313#ifndef __REACTOS__
314 s += t + L"\r\n"s;
315#else
316 s += t + L"\r\n";
317#endif
318 }
319
320 // metadata ratio
321
323 throw last_error(GetLastError());
324
325 wstring_sprintf(t, u, (float)metadata_alloc / (float)metadata_size);
326
327 s += t + L"\r\n\r\n";
328
329 for (i = 0; i < sizeof(types) / sizeof(types[0]); i++) {
330 for (j = 0; j < sizeof(duptypes) / sizeof(duptypes[0]); j++) {
331 bue = usage;
332
333 while (true) {
334 if ((bue->type & types[i]) == types[i] && ((duptypes[j] == 0 && (bue->type & raid_types) == 0) || bue->type & duptypes[j])) {
335 wstring sizestring, usedstring, typestring, dupstring;
336
338 break;
339
340 if (!load_string(module, typestrings[i], typestring))
341 throw last_error(GetLastError());
342
343 if (!load_string(module, dupstrings[j], dupstring))
344 throw last_error(GetLastError());
345
346 format_size(bue->size, sizestring, false);
347 format_size(bue->used, usedstring, false);
348
349 wstring_sprintf(t, typestring, dupstring.c_str(), sizestring.c_str(), usedstring.c_str());
350
351 s += t + L"\r\n";
352
353 for (uint64_t k = 0; k < bue->num_devices; k++) {
354 bool found = false;
355
356 format_size(bue->devices[k].alloc, sizestring, false);
357
358 for (size_t l = 0; l < min((uint64_t)SIZE_MAX, num_devs); l++) {
359 if (devs[l].dev_id == bue->devices[k].dev_id) {
360 s += devs[l].name + L"\t" + sizestring + L"\r\n";
361
362 devs[l].alloc += bue->devices[k].alloc;
363
364 found = true;
365 break;
366 }
367 }
368
369 if (!found) {
370 if (!load_string(module, IDS_UNKNOWN_DEVICE, typestring))
371 throw last_error(GetLastError());
372
373 wstring_sprintf(t, typestring, bue->devices[k].dev_id);
374
375#ifndef __REACTOS__
376 s += t + L"\t"s + sizestring + L"\r\n"s;
377#else
378 s += t + L"\t" + sizestring + L"\r\n";
379#endif
380 }
381 }
382
383 s += L"\r\n";
384
385 break;
386 }
387
388 if (bue->next_entry > 0)
389 bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
390 else
391 break;
392 }
393 }
394 }
395
397 throw last_error(GetLastError());
398
399#ifndef __REACTOS__
400 s += t + L"\r\n"s;
401#else
402 s += t + L"\r\n";
403#endif
404
405 for (size_t k = 0; k < min((uint64_t)SIZE_MAX, num_devs); k++) {
406 wstring sizestring;
407
408 format_size(devs[k].size - devs[k].alloc, sizestring, false);
409
410 s += devs[k].name + L"\t" + sizestring + L"\r\n";
411 }
412}
r l[0]
Definition: byte_order.h:167
void format_size(uint64_t size, wstring &s, bool show_bytes)
Definition: main.cpp:65
#define IDS_USAGE_UNALLOC
Definition: resource.h:54
#define IDS_SINGLE
Definition: resource.h:43
#define IDS_USAGE_MIXED
Definition: resource.h:51
#define IDS_DISK_NUM
Definition: resource.h:102
#define IDS_USAGE_DEV_SIZE
Definition: resource.h:56
#define IDS_UNKNOWN_DEVICE
Definition: resource.h:55
#define IDS_USAGE_DATA_RATIO
Definition: resource.h:59
#define IDS_RAID10
Definition: resource.h:47
#define IDS_USAGE_METADATA
Definition: resource.h:52
#define IDS_MISSING
Definition: resource.h:193
#define IDS_RAID1
Definition: resource.h:46
#define IDS_RAID0
Definition: resource.h:45
#define IDS_USAGE_DEV_ALLOC
Definition: resource.h:57
#define IDS_DUP
Definition: resource.h:44
#define IDS_USAGE_DATA
Definition: resource.h:50
#define IDS_USAGE_SYSTEM
Definition: resource.h:53
#define IDS_RAID6
Definition: resource.h:49
#define IDS_USAGE_DEV_UNALLOC
Definition: resource.h:58
#define IDS_RAID5
Definition: resource.h:48
#define IDS_USAGE_METADATA_RATIO
Definition: resource.h:60
#define IDS_RAID1C3
Definition: resource.h:137
#define IDS_RAID1C4
Definition: resource.h:149
#define IDS_DISK_PART_NUM
Definition: resource.h:103
#define BLOCK_FLAG_RAID1C4
Definition: btrfs.h:88
#define BLOCK_FLAG_RAID1C3
Definition: btrfs.h:87
const GLdouble * v
Definition: gl.h:2040
GLsizeiptr size
Definition: glext.h:5919
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble * u
Definition: glfuncs.h:240
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define SIZE_MAX
Definition: limits.h:75
#define d
Definition: ke_i.h:81
#define min(a, b)
Definition: monoChain.cc:55
int k
Definition: mpi.c:3369
#define alloc
Definition: rosglue.h:13
#define BLOCK_FLAG_RAID5
Definition: shellext.h:82
#define BLOCK_FLAG_DATA
Definition: shellext.h:75
#define BLOCK_FLAG_DUPLICATE
Definition: shellext.h:80
#define BLOCK_FLAG_SYSTEM
Definition: shellext.h:76
#define BLOCK_FLAG_RAID10
Definition: shellext.h:81
#define BLOCK_FLAG_RAID0
Definition: shellext.h:78
#define BLOCK_FLAG_RAID6
Definition: shellext.h:83
#define BLOCK_FLAG_METADATA
Definition: shellext.h:77
#define BLOCK_FLAG_RAID1
Definition: shellext.h:79
USHORT namelen
Definition: btrfsioctl.h:112
ULONG partition_number
Definition: btrfsioctl.h:110
uint64_t size
Definition: btrfsioctl.h:105
ULONG device_number
Definition: btrfsioctl.h:109
WCHAR name[1]
Definition: btrfsioctl.h:113
uint32_t next_entry
Definition: btrfsioctl.h:122
uint64_t size
Definition: btrfsioctl.h:124
btrfs_usage_device devices[1]
Definition: btrfsioctl.h:127
uint64_t type
Definition: btrfsioctl.h:123
uint64_t num_devices
Definition: btrfsioctl.h:126
uint64_t used
Definition: btrfsioctl.h:125
char * name
Definition: compiler.c:66
Definition: cmds.c:130
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379

Referenced by RefreshUsage(), and UsageDlgProc().

◆ Initialize()

HRESULT __stdcall BtrfsVolPropSheet::Initialize ( PCIDLIST_ABSOLUTE  pidlFolder,
IDataObject pdtobj,
HKEY  hkeyProgID 
)
virtual

Implements IShellExtInit.

Definition at line 66 of file volpropsheet.cpp.

66 {
67 ULONG num_files;
68 FORMATETC format = { CF_HDROP, nullptr, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
69 HDROP hdrop;
70 WCHAR fnbuf[MAX_PATH];
71
72 if (pidlFolder)
73 return E_FAIL;
74
75 if (!pdtobj)
76 return E_FAIL;
77
78 stgm.tymed = TYMED_HGLOBAL;
79
80 if (FAILED(pdtobj->GetData(&format, &stgm)))
81 return E_INVALIDARG;
82
83 stgm_set = true;
84
85 hdrop = (HDROP)GlobalLock(stgm.hGlobal);
86
87 if (!hdrop) {
89 stgm_set = false;
90 return E_INVALIDARG;
91 }
92
93 num_files = DragQueryFileW((HDROP)stgm.hGlobal, 0xFFFFFFFF, nullptr, 0);
94
95 if (num_files > 1) {
96 GlobalUnlock(hdrop);
97 return E_FAIL;
98 }
99
100 if (DragQueryFileW((HDROP)stgm.hGlobal, 0, fnbuf, sizeof(fnbuf) / sizeof(WCHAR))) {
101 fn = fnbuf;
102
105
106 if (h != INVALID_HANDLE_VALUE) {
109 ULONG devsize, i;
110
111 i = 0;
112 devsize = 1024;
113
114 devices = (btrfs_device*)malloc(devsize);
115
116 while (true) {
117 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
119 if (i < 8) {
120 devsize += 1024;
121
122 free(devices);
123 devices = (btrfs_device*)malloc(devsize);
124
125 i++;
126 } else {
127 GlobalUnlock(hdrop);
128 return E_FAIL;
129 }
130 } else
131 break;
132 }
133
134 if (!NT_SUCCESS(Status)) {
135 GlobalUnlock(hdrop);
136 return E_FAIL;
137 }
138
139 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_UUID, nullptr, 0, &uuid, sizeof(BTRFS_UUID));
141
142 ignore = false;
143 balance = new BtrfsBalance(fn);
144 } else {
145 GlobalUnlock(hdrop);
146 return E_FAIL;
147 }
148 } else {
149 GlobalUnlock(hdrop);
150 return E_FAIL;
151 }
152
153 GlobalUnlock(hdrop);
154
155 return S_OK;
156}
LONG NTSTATUS
Definition: precomp.h:26
#define CF_HDROP
Definition: constants.h:410
#define FSCTL_BTRFS_GET_UUID
Definition: btrfsioctl.h:22
#define FSCTL_BTRFS_GET_DEVICES
Definition: btrfsioctl.h:12
#define E_INVALIDARG
Definition: ddrawi.h:101
#define malloc
Definition: debug_ros.c:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_SHARE_READ
Definition: compat.h:136
UINT WINAPI DragQueryFileW(HDROP hDrop, UINT lFile, LPWSTR lpszwFile, UINT lLength)
Definition: shellole.c:622
Status
Definition: gdiplustypes.h:25
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
LPVOID NTAPI GlobalLock(HGLOBAL hMem)
Definition: heapmem.c:755
HRESULT GetData([in, unique] FORMATETC *pformatetcIn, [out] STGMEDIUM *pmedium)
Definition: msctf.idl:511
#define FAILED(hr)
Definition: intsafe.h:51
#define FILE_FLAG_OPEN_REPARSE_POINT
Definition: disk.h:39
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_TRAVERSE
Definition: nt_native.h:643
NTSYSAPI NTSTATUS NTAPI NtFsControlFile(IN HANDLE hFile, IN HANDLE hEvent OPTIONAL, IN PIO_APC_ROUTINE IoApcRoutine OPTIONAL, IN PVOID IoApcContext OPTIONAL, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN ULONG DeviceIoControlCode, IN PVOID InBuffer OPTIONAL, IN ULONG InBufferLength, OUT PVOID OutBuffer OPTIONAL, IN ULONG OutBufferLength)
#define STATUS_BUFFER_OVERFLOW
Definition: shellext.h:66

◆ QueryInterface()

HRESULT __stdcall BtrfsVolPropSheet::QueryInterface ( REFIID  riid,
void **  ppObj 
)

Implements IUnknown.

Definition at line 51 of file volpropsheet.cpp.

51 {
52 if (riid == IID_IUnknown || riid == IID_IShellPropSheetExt) {
53 *ppObj = static_cast<IShellPropSheetExt*>(this);
54 AddRef();
55 return S_OK;
56 } else if (riid == IID_IShellExtInit) {
57 *ppObj = static_cast<IShellExtInit*>(this);
58 AddRef();
59 return S_OK;
60 }
61
62 *ppObj = nullptr;
63 return E_NOINTERFACE;
64}
const GUID IID_IUnknown
REFIID riid
Definition: atlbase.h:39
#define E_NOINTERFACE
Definition: winerror.h:2364

Referenced by Factory::CreateInstance().

◆ RefreshDevList()

void BtrfsVolPropSheet::RefreshDevList ( HWND  devlist)

Definition at line 632 of file volpropsheet.cpp.

632 {
635 ULONG usagesize, devsize;
637 btrfs_device* bd;
638 int i;
639 uint64_t num_rw_devices;
640 {
643
644 if (h == INVALID_HANDLE_VALUE)
645 throw last_error(GetLastError());
646
647 i = 0;
648 devsize = 1024;
649
650 if (devices)
651 free(devices);
652
653 devices = (btrfs_device*)malloc(devsize);
654
655 while (true) {
656 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
658 if (i < 8) {
659 devsize += 1024;
660
661 free(devices);
662 devices = (btrfs_device*)malloc(devsize);
663
664 i++;
665 } else
666 return;
667 } else
668 break;
669 }
670
671 if (!NT_SUCCESS(Status))
672 return;
673
674 bd = devices;
675
676 i = 0;
677 usagesize = 1024;
678
679 usage = (btrfs_usage*)malloc(usagesize);
680
681 while (true) {
682 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_USAGE, nullptr, 0, usage, usagesize);
684 if (i < 8) {
685 usagesize += 1024;
686
687 free(usage);
688 usage = (btrfs_usage*)malloc(usagesize);
689
690 i++;
691 } else {
692 free(usage);
693 return;
694 }
695 } else
696 break;
697 }
698
699 if (!NT_SUCCESS(Status)) {
700 free(usage);
701 return;
702 }
703 }
704
705 SendMessageW(devlist, LVM_DELETEALLITEMS, 0, 0);
706
707 num_rw_devices = 0;
708
709 i = 0;
710 while (true) {
711 LVITEMW lvi;
712 wstring s, u;
714
715 // ID
716
717 RtlZeroMemory(&lvi, sizeof(LVITEMW));
718 lvi.mask = LVIF_TEXT | LVIF_PARAM;
719 lvi.iItem = (int)SendMessageW(devlist, LVM_GETITEMCOUNT, 0, 0);
720 lvi.lParam = (LPARAM)bd->dev_id;
721
722 s = to_wstring(bd->dev_id);
723 lvi.pszText = (LPWSTR)s.c_str();
724
725 SendMessageW(devlist, LVM_INSERTITEMW, 0, (LPARAM)&lvi);
726
727 // description
728
729 lvi.mask = LVIF_TEXT;
730 lvi.iSubItem = 1;
731
732 if (bd->missing) {
734 throw last_error(GetLastError());
735 } else if (bd->device_number == 0xffffffff)
736 s = wstring(bd->name, bd->namelen / sizeof(WCHAR));
737 else if (bd->partition_number == 0) {
739 throw last_error(GetLastError());
740
742 } else {
744 throw last_error(GetLastError());
745
747 }
748
749 lvi.pszText = (LPWSTR)s.c_str();
750
751 SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
752
753 // readonly
754
755 lvi.iSubItem = 2;
757 lvi.pszText = (LPWSTR)s.c_str();
758 SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
759
760 if (!bd->readonly)
761 num_rw_devices++;
762
763 // size
764
765 lvi.iSubItem = 3;
766 format_size(bd->size, s, false);
767 lvi.pszText = (LPWSTR)s.c_str();
768 SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
769
770 // alloc
771
773
774 lvi.iSubItem = 4;
775 format_size(alloc, s, false);
776 lvi.pszText = (LPWSTR)s.c_str();
777 SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
778
779 // alloc %
780
781 wstring_sprintf(s, L"%1.1f%%", (float)alloc * 100.0f / (float)bd->size);
782 lvi.iSubItem = 5;
783 lvi.pszText = (LPWSTR)s.c_str();
784 SendMessageW(devlist, LVM_SETITEMW, 0, (LPARAM)&lvi);
785
786 i++;
787
788 if (bd->next_entry > 0)
789 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
790 else
791 break;
792 }
793
794 free(usage);
795
797
798 EnableWindow(GetDlgItem(GetParent(devlist), IDC_DEVICE_ADD), num_rw_devices > 0);
799 EnableWindow(GetDlgItem(GetParent(devlist), IDC_DEVICE_REMOVE), num_rw_devices > 1);
800}
#define FSCTL_BTRFS_GET_USAGE
Definition: btrfsioctl.h:13
#define IDS_DEVLIST_READONLY_NO
Definition: resource.h:79
#define IDS_DEVLIST_READONLY_YES
Definition: resource.h:78
#define LVM_DELETEALLITEMS
Definition: commctrl.h:2413
#define LVM_GETITEMCOUNT
Definition: commctrl.h:2306
#define LVM_SETITEMW
Definition: commctrl.h:2397
#define LVIF_PARAM
Definition: commctrl.h:2311
#define LVM_INSERTITEMW
Definition: commctrl.h:2404
#define LVM_SORTITEMS
Definition: commctrl.h:2702
LPARAM lParam
Definition: commctrl.h:2368
static int CALLBACK lv_sort(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
static uint64_t find_dev_alloc(uint64_t dev_id, btrfs_usage *usage)
HWND WINAPI GetParent(_In_ HWND)
WCHAR * LPWSTR
Definition: xmlstorage.h:184

Referenced by DeviceDlgProc().

◆ RefreshUsage()

void BtrfsVolPropSheet::RefreshUsage ( HWND  hwndDlg)

Definition at line 414 of file volpropsheet.cpp.

414 {
415 wstring s;
417
420
421 if (h != INVALID_HANDLE_VALUE) {
424 ULONG devsize, usagesize, i;
425
426 i = 0;
427 devsize = 1024;
428
429 devices = (btrfs_device*)malloc(devsize);
430
431 while (true) {
432 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
434 if (i < 8) {
435 devsize += 1024;
436
437 free(devices);
438 devices = (btrfs_device*)malloc(devsize);
439
440 i++;
441 } else
442 return;
443 } else
444 break;
445 }
446
447 if (!NT_SUCCESS(Status))
448 return;
449
450 i = 0;
451 usagesize = 1024;
452
453 usage = (btrfs_usage*)malloc(usagesize);
454
455 while (true) {
456 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_USAGE, nullptr, 0, usage, usagesize);
458 if (i < 8) {
459 usagesize += 1024;
460
461 free(usage);
462 usage = (btrfs_usage*)malloc(usagesize);
463
464 i++;
465 } else
466 return;
467 } else
468 break;
469 }
470
471 if (!NT_SUCCESS(Status)) {
472 free(usage);
473 return;
474 }
475
476 ignore = false;
477 } else
478 return;
479
480 FormatUsage(hwndDlg, s, usage);
481
482 SetDlgItemTextW(hwndDlg, IDC_USAGE_BOX, s.c_str());
483
484 free(usage);
485}
void FormatUsage(HWND hwndDlg, wstring &s, btrfs_usage *usage)
#define IDC_USAGE_BOX
Definition: resource.h:230
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)

Referenced by UsageDlgProc().

◆ Release()

ULONG __stdcall BtrfsVolPropSheet::Release ( void  )
inline

Implements IUnknown.

Definition at line 69 of file volpropsheet.h.

69 {
71
72 if (rc == 0)
73 delete this;
74
75 return rc;
76 }
long LONG
Definition: pedump.c:60

◆ ReplacePage()

HRESULT __stdcall BtrfsVolPropSheet::ReplacePage ( UINT  uPageID,
LPFNADDPROPSHEETPAGE  pfnReplacePage,
LPARAM  lParam 
)
virtual

Definition at line 1472 of file volpropsheet.cpp.

1472 {
1473 return S_OK;
1474}

◆ ResetStats()

void BtrfsVolPropSheet::ResetStats ( HWND  hwndDlg)

Definition at line 802 of file volpropsheet.cpp.

802 {
803 wstring t, sel;
804 WCHAR modfn[MAX_PATH];
806
807 sel = to_wstring(stats_dev);
808
809 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
810
811#ifndef __REACTOS__
812 t = L"\""s + modfn + L"\",ResetStats " + fn + L"|" + sel;
813#else
814 t = wstring(L"\"") + modfn + wstring(L"\",ResetStats ") + fn + wstring(L"|") + sel;
815#endif
816
817 RtlZeroMemory(&sei, sizeof(sei));
818
819 sei.cbSize = sizeof(sei);
820 sei.hwnd = hwndDlg;
821 sei.lpVerb = L"runas";
822 sei.lpFile = L"rundll32.exe";
823 sei.lpParameters = t.c_str();
824 sei.nShow = SW_SHOW;
826
827 if (!ShellExecuteExW(&sei))
828 throw last_error(GetLastError());
829
832
835
836 if (h != INVALID_HANDLE_VALUE) {
839 ULONG devsize, i;
840
841 i = 0;
842 devsize = 1024;
843
844 free(devices);
845 devices = (btrfs_device*)malloc(devsize);
846
847 while (true) {
848 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_DEVICES, nullptr, 0, devices, devsize);
850 if (i < 8) {
851 devsize += 1024;
852
853 free(devices);
854 devices = (btrfs_device*)malloc(devsize);
855
856 i++;
857 } else
858 break;
859 } else
860 break;
861 }
862 }
863
864 EndDialog(hwndDlg, 0);
865}

Referenced by StatsDlgProc().

◆ ShowChangeDriveLetter()

void BtrfsVolPropSheet::ShowChangeDriveLetter ( HWND  hwndDlg)

Definition at line 1299 of file volpropsheet.cpp.

1299 {
1300 wstring t;
1301 WCHAR modfn[MAX_PATH];
1303
1304 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
1305
1306#ifndef __REACTOS__
1307 t = L"\""s + modfn + L"\",ShowChangeDriveLetter "s + fn;
1308#else
1309 t = wstring(L"\"") + modfn + wstring(L"\",ShowChangeDriveLetter ") + fn;
1310#endif
1311
1312 RtlZeroMemory(&sei, sizeof(sei));
1313
1314 sei.cbSize = sizeof(sei);
1315 sei.hwnd = hwndDlg;
1316 sei.lpVerb = L"runas";
1317 sei.lpFile = L"rundll32.exe";
1318 sei.lpParameters = t.c_str();
1319 sei.nShow = SW_SHOW;
1321
1322 if (!ShellExecuteExW(&sei))
1323 throw last_error(GetLastError());
1324
1326 CloseHandle(sei.hProcess);
1327}

Referenced by PropSheetDlgProc().

◆ ShowDevices()

void BtrfsVolPropSheet::ShowDevices ( HWND  hwndDlg)

Definition at line 1265 of file volpropsheet.cpp.

1265 {
1267}
#define IDD_DEVICES
Definition: resource.h:21
static INT_PTR CALLBACK stub_DeviceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)

Referenced by PropSheetDlgProc().

◆ ShowScrub()

void BtrfsVolPropSheet::ShowScrub ( HWND  hwndDlg)

Definition at line 1269 of file volpropsheet.cpp.

1269 {
1270 wstring t;
1271 WCHAR modfn[MAX_PATH];
1273
1274 GetModuleFileNameW(module, modfn, sizeof(modfn) / sizeof(WCHAR));
1275
1276#ifndef __REACTOS__
1277 t = L"\""s + modfn + L"\",ShowScrub "s + fn;
1278#else
1279 t = wstring(L"\"") + modfn + wstring(L"\",ShowScrub ") + fn;
1280#endif
1281
1282 RtlZeroMemory(&sei, sizeof(sei));
1283
1284 sei.cbSize = sizeof(sei);
1285 sei.hwnd = hwndDlg;
1286 sei.lpVerb = L"runas";
1287 sei.lpFile = L"rundll32.exe";
1288 sei.lpParameters = t.c_str();
1289 sei.nShow = SW_SHOW;
1291
1292 if (!ShellExecuteExW(&sei))
1293 throw last_error(GetLastError());
1294
1296 CloseHandle(sei.hProcess);
1297}

Referenced by PropSheetDlgProc().

◆ ShowStats()

void BtrfsVolPropSheet::ShowStats ( HWND  hwndDlg,
uint64_t  devid 
)

Definition at line 958 of file volpropsheet.cpp.

958 {
959 stats_dev = devid;
960
962}
#define IDD_DEVICE_STATS
Definition: resource.h:84
static INT_PTR CALLBACK stub_StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)

Referenced by DeviceDlgProc().

◆ ShowUsage()

void BtrfsVolPropSheet::ShowUsage ( HWND  hwndDlg)

Definition at line 582 of file volpropsheet.cpp.

582 {
584}
#define IDD_VOL_USAGE
Definition: resource.h:13
static INT_PTR CALLBACK stub_UsageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)

Referenced by PropSheetDlgProc().

◆ StatsDlgProc()

INT_PTR CALLBACK BtrfsVolPropSheet::StatsDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 867 of file volpropsheet.cpp.

867 {
868 try {
869 switch (uMsg) {
870 case WM_INITDIALOG:
871 {
872 WCHAR s[255];
873 wstring t;
874 btrfs_device *bd, *dev = nullptr;
875 int i;
876
878
879 bd = devices;
880
881 while (true) {
882 if (bd->dev_id == stats_dev) {
883 dev = bd;
884 break;
885 }
886
887 if (bd->next_entry > 0)
888 bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
889 else
890 break;
891 }
892
893 if (!dev) {
894 EndDialog(hwndDlg, 0);
896 }
897
898 GetDlgItemTextW(hwndDlg, IDC_DEVICE_ID, s, sizeof(s) / sizeof(WCHAR));
899
901
902 SetDlgItemTextW(hwndDlg, IDC_DEVICE_ID, t.c_str());
903
904 for (i = 0; i < 5; i++) {
905 GetDlgItemTextW(hwndDlg, stat_ids[i], s, sizeof(s) / sizeof(WCHAR));
906
907 wstring_sprintf(t, s, dev->stats[i]);
908
909 SetDlgItemTextW(hwndDlg, stat_ids[i], t.c_str());
910 }
911
914
915 break;
916 }
917
918 case WM_COMMAND:
919 switch (HIWORD(wParam)) {
920 case BN_CLICKED:
921 switch (LOWORD(wParam)) {
922 case IDOK:
923 case IDCANCEL:
924 EndDialog(hwndDlg, 0);
925 return true;
926
927 case IDC_RESET_STATS:
928 ResetStats(hwndDlg);
929 return true;
930 }
931 break;
932 }
933 break;
934 }
935 } catch (const exception& e) {
936 error_message(hwndDlg, e.what());
937 }
938
939 return false;
940}
void ResetStats(HWND hwndDlg)
#define IDS_CANNOT_FIND_DEVICE
Definition: resource.h:29
#define IDC_RESET_STATS
Definition: resource.h:275
#define IDC_FLUSH_ERRS
Definition: resource.h:326
#define IDC_DEVICE_ID
Definition: resource.h:322
#define IDC_READ_ERRS
Definition: resource.h:324
#define IDC_GENERATION_ERRS
Definition: resource.h:330
#define IDC_WRITE_ERRS
Definition: resource.h:323
#define IDC_CORRUPTION_ERRS
Definition: resource.h:328
uint64_t dev_id
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2263

Referenced by stub_StatsDlgProc().

◆ UsageDlgProc()

INT_PTR CALLBACK BtrfsVolPropSheet::UsageDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 487 of file volpropsheet.cpp.

487 {
488 try {
489 switch (uMsg) {
490 case WM_INITDIALOG:
491 {
492 wstring s;
493 int i;
494 ULONG usagesize;
497
499
502
503 if (h != INVALID_HANDLE_VALUE) {
505
506 i = 0;
507 usagesize = 1024;
508
509 usage = (btrfs_usage*)malloc(usagesize);
510
511 while (true) {
512 Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_USAGE, nullptr, 0, usage, usagesize);
514 if (i < 8) {
515 usagesize += 1024;
516
517 free(usage);
518 usage = (btrfs_usage*)malloc(usagesize);
519
520 i++;
521 } else
522 break;
523 } else
524 break;
525 }
526
527 if (!NT_SUCCESS(Status)) {
528 free(usage);
529 break;
530 }
531
532 FormatUsage(hwndDlg, s, usage);
533
534 SetDlgItemTextW(hwndDlg, IDC_USAGE_BOX, s.c_str());
535
536 free(usage);
537 }
538
539 break;
540 }
541
542 case WM_COMMAND:
543 switch (HIWORD(wParam)) {
544 case BN_CLICKED:
545 switch (LOWORD(wParam)) {
546 case IDOK:
547 case IDCANCEL:
548 EndDialog(hwndDlg, 0);
549 return true;
550
552 RefreshUsage(hwndDlg);
553 return true;
554 }
555 break;
556 }
557 break;
558 }
559 } catch (const exception& e) {
560 error_message(hwndDlg, e.what());
561 }
562
563 return false;
564}
void RefreshUsage(HWND hwndDlg)
#define IDC_USAGE_REFRESH
Definition: resource.h:233

Referenced by stub_UsageDlgProc().

Member Data Documentation

◆ balance

BtrfsBalance* BtrfsVolPropSheet::balance

◆ devices

◆ fn

wstring BtrfsVolPropSheet::fn
private

◆ ignore

bool BtrfsVolPropSheet::ignore
private

Definition at line 108 of file volpropsheet.h.

Referenced by AddPages(), BtrfsVolPropSheet(), Initialize(), and RefreshUsage().

◆ readonly

bool BtrfsVolPropSheet::readonly

Definition at line 101 of file volpropsheet.h.

Referenced by DeviceDlgProc(), PropSheetDlgProc(), and StatsDlgProc().

◆ refcount

LONG BtrfsVolPropSheet::refcount
private

Definition at line 107 of file volpropsheet.h.

Referenced by AddRef(), BtrfsVolPropSheet(), and Release().

◆ stats_dev

uint64_t BtrfsVolPropSheet::stats_dev
private

Definition at line 112 of file volpropsheet.h.

Referenced by ResetStats(), ShowStats(), and StatsDlgProc().

◆ stgm

STGMEDIUM BtrfsVolPropSheet::stgm
private

Definition at line 109 of file volpropsheet.h.

Referenced by Initialize(), and ~BtrfsVolPropSheet().

◆ stgm_set

bool BtrfsVolPropSheet::stgm_set
private

Definition at line 110 of file volpropsheet.h.

Referenced by BtrfsVolPropSheet(), Initialize(), and ~BtrfsVolPropSheet().

◆ uuid

BTRFS_UUID BtrfsVolPropSheet::uuid

Definition at line 103 of file volpropsheet.h.

Referenced by PropSheetDlgProc().

◆ uuid_set

bool BtrfsVolPropSheet::uuid_set

Definition at line 104 of file volpropsheet.h.

Referenced by Initialize(), and PropSheetDlgProc().


The documentation for this class was generated from the following files: