ReactOS  0.4.14-dev-583-g2a1ba2c
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 584 of file volpropsheet.cpp.

584  {
585  LVCOLUMNW lvc;
586  wstring s;
587 
588  if (!load_string(module, string, s))
589  throw last_error(GetLastError());
590 
591  lvc.mask = LVCF_TEXT|LVCF_WIDTH;
592  lvc.pszText = (WCHAR*)s.c_str();
593  lvc.cx = cx;
595 }
#define LVCF_WIDTH
Definition: commctrl.h:2583
#define LVCF_TEXT
Definition: commctrl.h:2584
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#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 606 of file volpropsheet.cpp.

606  {
607  btrfs_usage* bue;
608  uint64_t alloc;
609 
610  alloc = 0;
611 
612  bue = usage;
613  while (true) {
614  uint64_t k;
615 
616  for (k = 0; k < bue->num_devices; k++) {
617  if (bue->devices[k].dev_id == dev_id)
618  alloc += bue->devices[k].alloc;
619  }
620 
621  if (bue->next_entry > 0)
622  bue = (btrfs_usage*)((uint8_t*)bue + bue->next_entry);
623  else
624  break;
625  }
626 
627  return alloc;
628 }
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 597 of file volpropsheet.cpp.

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

Referenced by BtrfsVolPropSheet::RefreshDevList().

◆ PropSheetDlgProc()

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

Definition at line 1327 of file volpropsheet.cpp.

1327  {
1328  try {
1329  switch (uMsg) {
1330  case WM_INITDIALOG:
1331  {
1333  BtrfsVolPropSheet* bps = (BtrfsVolPropSheet*)psp->lParam;
1334  btrfs_device* bd;
1335 
1337 
1338  SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)bps);
1339 
1340  bps->readonly = true;
1341  bd = bps->devices;
1342 
1343  while (true) {
1344  if (!bd->readonly) {
1345  bps->readonly = false;
1346  break;
1347  }
1348 
1349  if (bd->next_entry > 0)
1350  bd = (btrfs_device*)((uint8_t*)bd + bd->next_entry);
1351  else
1352  break;
1353  }
1354 
1355  if (bps->uuid_set) {
1356  WCHAR s[255];
1357  wstring t;
1358 
1359  GetDlgItemTextW(hwndDlg, IDC_UUID, s, sizeof(s) / sizeof(WCHAR));
1360 
1361  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],
1362  bps->uuid.uuid[6], bps->uuid.uuid[7], bps->uuid.uuid[8], bps->uuid.uuid[9], bps->uuid.uuid[10], bps->uuid.uuid[11],
1363  bps->uuid.uuid[12], bps->uuid.uuid[13], bps->uuid.uuid[14], bps->uuid.uuid[15]);
1364 
1365  SetDlgItemTextW(hwndDlg, IDC_UUID, t.c_str());
1366  } else
1367  SetDlgItemTextW(hwndDlg, IDC_UUID, L"");
1368 
1369  SendMessageW(GetDlgItem(hwndDlg, IDC_VOL_SCRUB), BCM_SETSHIELD, 0, true);
1371 
1372  return false;
1373  }
1374 
1375  case WM_NOTIFY:
1376  {
1377  switch (((LPNMHDR)lParam)->code) {
1378  case PSN_KILLACTIVE:
1379  SetWindowLongPtrW(hwndDlg, DWLP_MSGRESULT, false);
1380  break;
1381  }
1382  break;
1383  }
1384 
1385  case WM_COMMAND:
1386  {
1388 
1389  if (bps) {
1390  switch (HIWORD(wParam)) {
1391  case BN_CLICKED: {
1392  switch (LOWORD(wParam)) {
1393  case IDC_VOL_SHOW_USAGE:
1394  bps->ShowUsage(hwndDlg);
1395  break;
1396 
1397  case IDC_VOL_BALANCE:
1398  bps->balance->ShowBalance(hwndDlg);
1399  break;
1400 
1401  case IDC_VOL_DEVICES:
1402  bps->ShowDevices(hwndDlg);
1403  break;
1404 
1405  case IDC_VOL_SCRUB:
1406  bps->ShowScrub(hwndDlg);
1407  break;
1408 
1410  bps->ShowChangeDriveLetter(hwndDlg);
1411  break;
1412  }
1413  }
1414  }
1415  }
1416 
1417  break;
1418  }
1419  }
1420  } catch (const exception& e) {
1421  error_message(hwndDlg, e.what());
1422  }
1423 
1424  return false;
1425 }
void ShowChangeDriveLetter(HWND hwndDlg)
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2265
#define IDC_VOL_CHANGE_DRIVE_LETTER
Definition: resource.h:333
#define IDC_VOL_BALANCE
Definition: resource.h:236
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:235
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
void ShowBalance(HWND hwndDlg)
Definition: balance.cpp:971
#define IDC_UUID
Definition: resource.h:304
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
BYTE uint8_t
Definition: msvideo1.c:66
#define IDC_VOL_DEVICES
Definition: resource.h:243
uint8_t uuid[16]
Definition: btrfs.h:124
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:246
#define HIWORD(l)
Definition: typedefs.h:246
#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: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 1628 of file volpropsheet.cpp.

1628  {
1629  try {
1630  win_handle token;
1631  NTSTATUS Status;
1633  LUID luid;
1634  uint64_t devid;
1635  wstring cmdline, vol, dev;
1636  size_t pipe;
1638 
1639  set_dpi_aware();
1640 
1641  cmdline = lpszCmdLine;
1642 
1644  throw last_error(GetLastError());
1645 
1646  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
1647  throw last_error(GetLastError());
1648 
1649  tp.PrivilegeCount = 1;
1650  tp.Privileges[0].Luid = luid;
1651  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
1652 
1653  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
1654  throw last_error(GetLastError());
1655 
1656  pipe = cmdline.find(L"|");
1657 
1658  if (pipe == string::npos)
1659  return;
1660 
1661  vol = cmdline.substr(0, pipe);
1662  dev = cmdline.substr(pipe + 1);
1663 
1664  devid = _wtoi(dev.c_str());
1665  if (devid == 0)
1666  return;
1667 
1670 
1671  if (h == INVALID_HANDLE_VALUE)
1672  throw last_error(GetLastError());
1673 
1674  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESET_STATS, &devid, sizeof(uint64_t), nullptr, 0);
1675  if (!NT_SUCCESS(Status))
1676  throw ntstatus_error(Status);
1677  } catch (const exception& e) {
1678  error_message(hwnd, e.what());
1679  }
1680 }
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:399
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)
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: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:434
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2855
#define TOKEN_QUERY
Definition: setypes.h:874
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1138
#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:408
#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 1682 of file volpropsheet.cpp.

1682  {
1683  BtrfsChangeDriveLetter bcdl(hwnd, lpszCmdLine);
1684 
1685  bcdl.show();
1686 }
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 1247 of file volpropsheet.cpp.

1247  {
1248  BtrfsVolPropSheet* bvps;
1249 
1250  if (uMsg == WM_INITDIALOG) {
1252  bvps = (BtrfsVolPropSheet*)lParam;
1253  } else {
1255  }
1256 
1257  if (bvps)
1258  return bvps->DeviceDlgProc(hwndDlg, uMsg, wParam, lParam);
1259  else
1260  return false;
1261 }
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 940 of file volpropsheet.cpp.

940  {
941  BtrfsVolPropSheet* bvps;
942 
943  if (uMsg == WM_INITDIALOG) {
945  bvps = (BtrfsVolPropSheet*)lParam;
946  } else {
948  }
949 
950  if (bvps)
951  return bvps->StatsDlgProc(hwndDlg, uMsg, wParam, lParam);
952  else
953  return false;
954 }
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 564 of file volpropsheet.cpp.

564  {
565  BtrfsVolPropSheet* bvps;
566 
567  if (uMsg == WM_INITDIALOG) {
569  bvps = (BtrfsVolPropSheet*)lParam;
570  } else {
572  }
573 
574  if (bvps)
575  return bvps->UsageDlgProc(hwndDlg, uMsg, wParam, lParam);
576  else
577  return false;
578 }
#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().