ReactOS  0.4.13-dev-544-gede3fdd
volpropsheet.cpp File Reference
#include "shellext.h"
#include <windows.h>
#include <strsafe.h>
#include <winternl.h>
#include <shlwapi.h>
#include <uxtheme.h>
#include "volpropsheet.h"
#include "resource.h"
Include dependency graph for volpropsheet.cpp:

Go to the source code of this file.

Classes

struct  dev
 

Macros

#define ISOLATION_AWARE_ENABLED   1
 
#define STRSAFE_NO_DEPRECATE
 
#define NO_SHLWAPI_STRFCNS
 

Functions

static INT_PTR CALLBACK stub_UsageDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static void add_lv_column (HWND list, int string, int cx)
 
static int CALLBACK lv_sort (LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
 
static uint64_t find_dev_alloc (uint64_t dev_id, btrfs_usage *usage)
 
static INT_PTR CALLBACK stub_StatsDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static INT_PTR CALLBACK stub_DeviceDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
static INT_PTR CALLBACK PropSheetDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void CALLBACK ResetStatsW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 

Macro Definition Documentation

◆ ISOLATION_AWARE_ENABLED

#define ISOLATION_AWARE_ENABLED   1

Definition at line 18 of file volpropsheet.cpp.

◆ NO_SHLWAPI_STRFCNS

#define NO_SHLWAPI_STRFCNS

Definition at line 35 of file volpropsheet.cpp.

◆ STRSAFE_NO_DEPRECATE

#define STRSAFE_NO_DEPRECATE

Definition at line 19 of file volpropsheet.cpp.

Function Documentation

◆ add_lv_column()

static void add_lv_column ( HWND  list,
int  string,
int  cx 
)
static

Definition at line 575 of file volpropsheet.cpp.

575  {
576  LVCOLUMNW lvc;
577  wstring s;
578 
579  if (!load_string(module, string, s))
580  throw last_error(GetLastError());
581 
582  lvc.mask = LVCF_TEXT|LVCF_WIDTH;
583  lvc.pszText = (WCHAR*)s.c_str();
584  lvc.cx = cx;
586 }
#define LVCF_WIDTH
Definition: commctrl.h:2559
#define LVCF_TEXT
Definition: commctrl.h:2560
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define LVM_INSERTCOLUMNW
Definition: commctrl.h:2604
LONG_PTR LPARAM
Definition: windef.h:208
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPWSTR pszText
Definition: commctrl.h:2539
GLdouble s
Definition: gl.h:2039
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define list
Definition: rosglue.h:35
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
_Out_opt_ int * cx
Definition: commctrl.h:570

Referenced by BtrfsVolPropSheet::DeviceDlgProc().

◆ find_dev_alloc()

static uint64_t find_dev_alloc ( uint64_t  dev_id,
btrfs_usage usage 
)
static

Definition at line 597 of file volpropsheet.cpp.

597  {
598  btrfs_usage* bue;
599  uint64_t alloc;
600 
601  alloc = 0;
602 
603  bue = usage;
604  while (true) {
605  uint64_t k;
606 
607  for (k = 0; k < bue->num_devices; k++) {
608  if (bue->devices[k].dev_id == dev_id)
609  alloc += bue->devices[k].alloc;
610  }
611 
612  if (bue->next_entry > 0)
613  bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
614  else
615  break;
616  }
617 
618  return alloc;
619 }
UINT64 num_devices
Definition: btrfsioctl.h:139
GLsizeiptr const GLvoid GLenum usage
Definition: glext.h:5919
BYTE uint8_t
Definition: msvideo1.c:66
UINT64 uint64_t
Definition: types.h:77
#define alloc
Definition: rosglue.h:13
UINT32 next_entry
Definition: btrfsioctl.h:135
btrfs_usage_device devices[1]
Definition: btrfsioctl.h:140
int k
Definition: mpi.c:3369

Referenced by BtrfsVolPropSheet::RefreshDevList().

◆ lv_sort()

static int CALLBACK lv_sort ( LPARAM  lParam1,
LPARAM  lParam2,
LPARAM  lParamSort 
)
static

Definition at line 588 of file volpropsheet.cpp.

588  {
589  if (lParam1 < lParam2)
590  return -1;
591  else if (lParam1 > lParam2)
592  return 1;
593  else
594  return 0;
595 }

Referenced by BtrfsVolPropSheet::RefreshDevList().

◆ PropSheetDlgProc()

static INT_PTR CALLBACK PropSheetDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1291 of file volpropsheet.cpp.

1291  {
1292  try {
1293  switch (uMsg) {
1294  case WM_INITDIALOG:
1295  {
1297  BtrfsVolPropSheet* bps = (BtrfsVolPropSheet*)psp->lParam;
1298  btrfs_device* bd;
1299 
1301 
1302  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)bps);
1303 
1304  bps->readonly = true;
1305  bd = bps->devices;
1306 
1307  while (true) {
1308  if (!bd->readonly) {
1309  bps->readonly = false;
1310  break;
1311  }
1312 
1313  if (bd->next_entry > 0)
1314  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
1315  else
1316  break;
1317  }
1318 
1319  if (bps->uuid_set) {
1320  WCHAR s[255];
1321  wstring t;
1322 
1323  GetDlgItemTextW(hwndDlg, IDC_UUID, s, sizeof(s) / sizeof(WCHAR));
1324 
1325  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],
1326  bps->uuid.uuid[6], bps->uuid.uuid[7], bps->uuid.uuid[8], bps->uuid.uuid[9], bps->uuid.uuid[10], bps->uuid.uuid[11],
1327  bps->uuid.uuid[12], bps->uuid.uuid[13], bps->uuid.uuid[14], bps->uuid.uuid[15]);
1328 
1329  SetDlgItemTextW(hwndDlg, IDC_UUID, t.c_str());
1330  } else
1331  SetDlgItemTextW(hwndDlg, IDC_UUID, L"");
1332 
1333  SendMessageW(GetDlgItem(hwndDlg, IDC_VOL_SCRUB), BCM_SETSHIELD, 0, true);
1334 
1335  return false;
1336  }
1337 
1338  case WM_NOTIFY:
1339  {
1340  switch (((LPNMHDR)lParam)->code) {
1341  case PSN_KILLACTIVE:
1342  SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, false);
1343  break;
1344  }
1345  break;
1346  }
1347 
1348  case WM_COMMAND:
1349  {
1351 
1352  if (bps) {
1353  switch (HIWORD(wParam)) {
1354  case BN_CLICKED: {
1355  switch (LOWORD(wParam)) {
1356  case IDC_VOL_SHOW_USAGE:
1357  bps->ShowUsage(hwndDlg);
1358  break;
1359 
1360  case IDC_VOL_BALANCE:
1361  bps->balance->ShowBalance(hwndDlg);
1362  break;
1363 
1364  case IDC_VOL_DEVICES:
1365  bps->ShowDevices(hwndDlg);
1366  break;
1367 
1368  case IDC_VOL_SCRUB:
1369  bps->ShowScrub(hwndDlg);
1370  break;
1371  }
1372  }
1373  }
1374  }
1375 
1376  break;
1377  }
1378  }
1379  } catch (const exception& e) {
1380  error_message(hwndDlg, e.what());
1381  }
1382 
1383  return false;
1384 }
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2195
#define IDC_VOL_BALANCE
Definition: resource.h:239
UINT8 uuid[16]
Definition: btrfs.h:122
btrfs_device * devices
Definition: volpropsheet.h:99
GLdouble GLdouble t
Definition: gl.h:2047
BtrfsBalance * balance
Definition: volpropsheet.h:101
#define BCM_SETSHIELD
Definition: commctrl.h:4625
void ShowScrub(HWND hwndDlg)
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define DWLP_MSGRESULT
Definition: winuser.h:864
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:738
#define PSN_KILLACTIVE
Definition: prsht.h:116
#define e
Definition: ke_i.h:82
#define GWLP_USERDATA
Definition: treelist.c:63
#define ETDT_ENABLETAB
Definition: dxdiag.c:30
void ShowUsage(HWND hwndDlg)
#define IDC_VOL_SHOW_USAGE
Definition: resource.h:238
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
void ShowBalance(HWND hwndDlg)
Definition: balance.cpp:975
#define IDC_UUID
Definition: resource.h:306
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
HRESULT WINAPI EnableThemeDialogTexture(_In_ HWND hwnd, _In_ DWORD dwFlags)
Definition: uxthemesupp.c:55
#define BN_CLICKED
Definition: winuser.h:1886
void ShowDevices(HWND hwndDlg)
static const WCHAR L[]
Definition: oid.c:1250
GLdouble s
Definition: gl.h:2039
#define WM_COMMAND
Definition: winuser.h:1716
BYTE uint8_t
Definition: msvideo1.c:66
#define IDC_VOL_DEVICES
Definition: resource.h:245
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define IDC_VOL_SCRUB
Definition: resource.h:248
#define HIWORD(l)
Definition: typedefs.h:246
#define SetWindowLongPtrW
Definition: winuser.h:5215
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define PROPSHEETPAGE
Definition: prsht.h:371
#define WM_NOTIFY
Definition: richedit.h:61

Referenced by BtrfsVolPropSheet::AddPages().

◆ ResetStatsW()

void CALLBACK ResetStatsW ( HWND  hwnd,
HINSTANCE  hinst,
LPWSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 1437 of file volpropsheet.cpp.

1437  {
1438  try {
1439  win_handle token;
1440  NTSTATUS Status;
1442  LUID luid;
1443  uint64_t devid;
1444  wstring cmdline, vol, dev;
1445  size_t pipe;
1447 
1448  set_dpi_aware();
1449 
1450  cmdline = lpszCmdLine;
1451 
1453  throw last_error(GetLastError());
1454 
1455  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1456  throw last_error(GetLastError());
1457 
1458  tp.PrivilegeCount = 1;
1459  tp.Privileges[0].Luid = luid;
1460  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1461 
1462  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1463  throw last_error(GetLastError());
1464 
1465  pipe = cmdline.find(L"|");
1466 
1467  if (pipe == string::npos)
1468  return;
1469 
1470  vol = cmdline.substr(0, pipe);
1471  dev = cmdline.substr(pipe + 1);
1472 
1473  devid = _wtoi(dev.c_str());
1474  if (devid == 0)
1475  return;
1476 
1479 
1480  if (h == INVALID_HANDLE_VALUE)
1481  throw last_error(GetLastError());
1482 
1483  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESET_STATS, &devid, sizeof(uint64_t), nullptr, 0);
1484  if (!NT_SUCCESS(Status))
1485  throw ntstatus_error(Status);
1486  } catch (const exception& e) {
1487  error_message(hwnd, e.what());
1488  }
1489 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
LONG NTSTATUS
Definition: precomp.h:26
static const size_t npos
Definition: _string_npos.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
NTSYSCALLAPI NTSTATUS NTAPI NtFsControlFile(HANDLE FileHandle, HANDLE Event, PIO_APC_ROUTINE ApcRoutine, PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG FsControlCode, PVOID InputBuffer, ULONG InputBufferLength, PVOID OutputBuffer, ULONG OutputBufferLength)
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2694
TCHAR * cmdline
Definition: stretchblt.cpp:32
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
static int dev
Definition: mkdosfs.c:536
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define FSCTL_BTRFS_RESET_STATS
Definition: btrfsioctl.h:30
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:738
#define e
Definition: ke_i.h:82
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
#define OPEN_EXISTING
Definition: compat.h:426
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
Status
Definition: gdiplustypes.h:24
UINT64 uint64_t
Definition: types.h:77
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
#define CreateFileW
Definition: compat.h:400
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FILE_FLAG_OPEN_REPARSE_POINT
Definition: disk.h:39
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
void set_dpi_aware()
Definition: main.cpp:50

◆ stub_DeviceDlgProc()

static INT_PTR CALLBACK stub_DeviceDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 1241 of file volpropsheet.cpp.

1241  {
1242  BtrfsVolPropSheet* bvps;
1243 
1244  if (uMsg == WM_INITDIALOG) {
1246  bvps = (BtrfsVolPropSheet*)lParam;
1247  } else {
1249  }
1250 
1251  if (bvps)
1252  return bvps->DeviceDlgProc(hwndDlg, uMsg, wParam, lParam);
1253  else
1254  return false;
1255 }
INT_PTR CALLBACK DeviceDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define GWLP_USERDATA
Definition: treelist.c:63
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139

Referenced by BtrfsVolPropSheet::ShowDevices().

◆ stub_StatsDlgProc()

static INT_PTR CALLBACK stub_StatsDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 931 of file volpropsheet.cpp.

931  {
932  BtrfsVolPropSheet* bvps;
933 
934  if (uMsg == WM_INITDIALOG) {
936  bvps = (BtrfsVolPropSheet*)lParam;
937  } else {
939  }
940 
941  if (bvps)
942  return bvps->StatsDlgProc(hwndDlg, uMsg, wParam, lParam);
943  else
944  return false;
945 }
INT_PTR CALLBACK StatsDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define GWLP_USERDATA
Definition: treelist.c:63
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139

Referenced by BtrfsVolPropSheet::ShowStats().

◆ stub_UsageDlgProc()

static INT_PTR CALLBACK stub_UsageDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)
static

Definition at line 555 of file volpropsheet.cpp.

555  {
556  BtrfsVolPropSheet* bvps;
557 
558  if (uMsg == WM_INITDIALOG) {
560  bvps = (BtrfsVolPropSheet*)lParam;
561  } else {
563  }
564 
565  if (bvps)
566  return bvps->UsageDlgProc(hwndDlg, uMsg, wParam, lParam);
567  else
568  return false;
569 }
#define SetWindowLongPtr
Definition: treelist.c:70
WPARAM wParam
Definition: combotst.c:138
#define GWLP_USERDATA
Definition: treelist.c:63
INT_PTR CALLBACK UsageDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139

Referenced by BtrfsVolPropSheet::ShowUsage().