ReactOS  0.4.15-dev-1197-g8081ba9
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 "mountmgr.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)
 
void CALLBACK ShowChangeDriveLetterW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 

Variables

static const NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034
 

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 586 of file volpropsheet.cpp.

586  {
587  LVCOLUMNW lvc;
588  wstring s;
589 
590  if (!load_string(module, string, s))
591  throw last_error(GetLastError());
592 
593  lvc.mask = LVCF_TEXT|LVCF_WIDTH;
594  lvc.pszText = (WCHAR*)s.c_str();
595  lvc.cx = cx;
597 }
#define LVCF_WIDTH
Definition: commctrl.h:2583
#define LVCF_TEXT
Definition: commctrl.h:2584
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define LVM_INSERTCOLUMNW
Definition: commctrl.h:2628
LONG_PTR LPARAM
Definition: windef.h:208
__wchar_t WCHAR
Definition: xmlstorage.h:180
LPWSTR pszText
Definition: commctrl.h:2563
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:581

Referenced by BtrfsVolPropSheet::DeviceDlgProc().

◆ find_dev_alloc()

static uint64_t find_dev_alloc ( uint64_t  dev_id,
btrfs_usage usage 
)
static

Definition at line 608 of file volpropsheet.cpp.

608  {
609  btrfs_usage* bue;
610  uint64_t alloc;
611 
612  alloc = 0;
613 
614  bue = usage;
615  while (true) {
616  uint64_t k;
617 
618  for (k = 0; k < bue->num_devices; k++) {
619  if (bue->devices[k].dev_id == dev_id)
620  alloc += bue->devices[k].alloc;
621  }
622 
623  if (bue->next_entry > 0)
624  bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
625  else
626  break;
627  }
628 
629  return alloc;
630 }
uint64_t num_devices
Definition: btrfsioctl.h:125
uint32_t next_entry
Definition: btrfsioctl.h:121
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
btrfs_usage_device devices[1]
Definition: btrfsioctl.h:126
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 599 of file volpropsheet.cpp.

599  {
600  if (lParam1 < lParam2)
601  return -1;
602  else if (lParam1 > lParam2)
603  return 1;
604  else
605  return 0;
606 }

Referenced by BtrfsVolPropSheet::RefreshDevList().

◆ PropSheetDlgProc()

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

Definition at line 1329 of file volpropsheet.cpp.

1329  {
1330  try {
1331  switch (uMsg) {
1332  case WM_INITDIALOG:
1333  {
1335  BtrfsVolPropSheet* bps = (BtrfsVolPropSheet*)psp->lParam;
1336  btrfs_device* bd;
1337 
1339 
1340  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)bps);
1341 
1342  bps->readonly = true;
1343  bd = bps->devices;
1344 
1345  while (true) {
1346  if (!bd->readonly) {
1347  bps->readonly = false;
1348  break;
1349  }
1350 
1351  if (bd->next_entry > 0)
1352  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
1353  else
1354  break;
1355  }
1356 
1357  if (bps->uuid_set) {
1358  WCHAR s[255];
1359  wstring t;
1360 
1361  GetDlgItemTextW(hwndDlg, IDC_UUID, s, sizeof(s) / sizeof(WCHAR));
1362 
1363  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],
1364  bps->uuid.uuid[6], bps->uuid.uuid[7], bps->uuid.uuid[8], bps->uuid.uuid[9], bps->uuid.uuid[10], bps->uuid.uuid[11],
1365  bps->uuid.uuid[12], bps->uuid.uuid[13], bps->uuid.uuid[14], bps->uuid.uuid[15]);
1366 
1367  SetDlgItemTextW(hwndDlg, IDC_UUID, t.c_str());
1368  } else
1369  SetDlgItemTextW(hwndDlg, IDC_UUID, L"");
1370 
1371  SendMessageW(GetDlgItem(hwndDlg, IDC_VOL_SCRUB), BCM_SETSHIELD, 0, true);
1373 
1374  return false;
1375  }
1376 
1377  case WM_NOTIFY:
1378  {
1379  switch (((LPNMHDR)lParam)->code) {
1380  case PSN_KILLACTIVE:
1381  SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, false);
1382  break;
1383  }
1384  break;
1385  }
1386 
1387  case WM_COMMAND:
1388  {
1390 
1391  if (bps) {
1392  switch (HIWORD(wParam)) {
1393  case BN_CLICKED: {
1394  switch (LOWORD(wParam)) {
1395  case IDC_VOL_SHOW_USAGE:
1396  bps->ShowUsage(hwndDlg);
1397  break;
1398 
1399  case IDC_VOL_BALANCE:
1400  bps->balance->ShowBalance(hwndDlg);
1401  break;
1402 
1403  case IDC_VOL_DEVICES:
1404  bps->ShowDevices(hwndDlg);
1405  break;
1406 
1407  case IDC_VOL_SCRUB:
1408  bps->ShowScrub(hwndDlg);
1409  break;
1410 
1412  bps->ShowChangeDriveLetter(hwndDlg);
1413  break;
1414  }
1415  }
1416  }
1417  }
1418 
1419  break;
1420  }
1421  }
1422  } catch (const exception& e) {
1423  error_message(hwndDlg, e.what());
1424  }
1425 
1426  return false;
1427 }
void ShowChangeDriveLetter(HWND hwndDlg)
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2271
#define IDC_VOL_CHANGE_DRIVE_LETTER
Definition: resource.h:337
#define IDC_VOL_BALANCE
Definition: resource.h:238
btrfs_device * devices
Definition: volpropsheet.h:100
GLdouble GLdouble t
Definition: gl.h:2047
BtrfsBalance * balance
Definition: volpropsheet.h:102
#define BCM_SETSHIELD
Definition: commctrl.h:4649
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:785
#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:237
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
void ShowBalance(HWND hwndDlg)
Definition: balance.cpp:979
#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:1907
void ShowDevices(HWND hwndDlg)
static const WCHAR L[]
Definition: oid.c:1250
GLdouble s
Definition: gl.h:2039
#define WM_COMMAND
Definition: winuser.h:1722
Definition: inflate.c:139
BYTE uint8_t
Definition: msvideo1.c:66
#define IDC_VOL_DEVICES
Definition: resource.h:245
uint8_t uuid[16]
Definition: btrfs.h:133
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:247
#define SetWindowLongPtrW
Definition: winuser.h:5321
#define GetWindowLongPtr
Definition: treelist.c:73
#define WM_INITDIALOG
Definition: winuser.h:1721
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define PROPSHEETPAGE
Definition: prsht.h:389
#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 1630 of file volpropsheet.cpp.

1630  {
1631  try {
1632  win_handle token;
1633  NTSTATUS Status;
1635  LUID luid;
1636  uint64_t devid;
1637  wstring cmdline, vol, dev;
1638  size_t pipe;
1640 
1641  set_dpi_aware();
1642 
1643  cmdline = lpszCmdLine;
1644 
1646  throw last_error(GetLastError());
1647 
1648  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1649  throw last_error(GetLastError());
1650 
1651  tp.PrivilegeCount = 1;
1652  tp.Privileges[0].Luid = luid;
1653  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1654 
1655  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1656  throw last_error(GetLastError());
1657 
1658  pipe = cmdline.find(L"|");
1659 
1660  if (pipe == string::npos)
1661  return;
1662 
1663  vol = cmdline.substr(0, pipe);
1664  dev = cmdline.substr(pipe + 1);
1665 
1666  devid = _wtoi(dev.c_str());
1667  if (devid == 0)
1668  return;
1669 
1672 
1673  if (h == INVALID_HANDLE_VALUE)
1674  throw last_error(GetLastError());
1675 
1676  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESET_STATS, &devid, sizeof(uint64_t), nullptr, 0);
1677  if (!NT_SUCCESS(Status))
1678  throw ntstatus_error(Status);
1679  } catch (const exception& e) {
1680  error_message(hwnd, e.what());
1681  }
1682 }
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:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
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)
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:136
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:29
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:785
#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:523
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2930
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
Status
Definition: gdiplustypes.h:24
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define GetCurrentProcess()
Definition: compat.h:507
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:376
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:489
#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

◆ ShowChangeDriveLetterW()

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

Definition at line 1684 of file volpropsheet.cpp.

1684  {
1685  BtrfsChangeDriveLetter bcdl(hwnd, lpszCmdLine);
1686 
1687  bcdl.show();
1688 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22

◆ stub_DeviceDlgProc()

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

Definition at line 1249 of file volpropsheet.cpp.

1249  {
1250  BtrfsVolPropSheet* bvps;
1251 
1252  if (uMsg == WM_INITDIALOG) {
1254  bvps = (BtrfsVolPropSheet*)lParam;
1255  } else {
1257  }
1258 
1259  if (bvps)
1260  return bvps->DeviceDlgProc(hwndDlg, uMsg, wParam, lParam);
1261  else
1262  return false;
1263 }
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:1721
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 942 of file volpropsheet.cpp.

942  {
943  BtrfsVolPropSheet* bvps;
944 
945  if (uMsg == WM_INITDIALOG) {
947  bvps = (BtrfsVolPropSheet*)lParam;
948  } else {
950  }
951 
952  if (bvps)
953  return bvps->StatsDlgProc(hwndDlg, uMsg, wParam, lParam);
954  else
955  return false;
956 }
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:1721
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 566 of file volpropsheet.cpp.

566  {
567  BtrfsVolPropSheet* bvps;
568 
569  if (uMsg == WM_INITDIALOG) {
571  bvps = (BtrfsVolPropSheet*)lParam;
572  } else {
574  }
575 
576  if (bvps)
577  return bvps->UsageDlgProc(hwndDlg, uMsg, wParam, lParam);
578  else
579  return false;
580 }
#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:1721
LPARAM lParam
Definition: combotst.c:139

Referenced by BtrfsVolPropSheet::ShowUsage().

Variable Documentation

◆ STATUS_OBJECT_NAME_NOT_FOUND

const NTSTATUS STATUS_OBJECT_NAME_NOT_FOUND = 0xC0000034
static

Definition at line 48 of file volpropsheet.cpp.

Referenced by BtrfsChangeDriveLetter::DlgProc().