ReactOS  0.4.13-dev-544-gede3fdd
scrub.cpp File Reference
#include "shellext.h"
#include "scrub.h"
#include "resource.h"
#include "../btrfsioctl.h"
#include <shlobj.h>
#include <uxtheme.h>
#include <stdio.h>
#include <strsafe.h>
#include <winternl.h>
#include <shlwapi.h>
Include dependency graph for scrub.cpp:

Go to the source code of this file.

Macros

#define NO_SHLWAPI_STRFCNS
 

Functions

static INT_PTR CALLBACK stub_ScrubDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void CALLBACK ShowScrubW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 
void CALLBACK StartScrubW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 
void CALLBACK StopScrubW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 

Macro Definition Documentation

◆ NO_SHLWAPI_STRFCNS

#define NO_SHLWAPI_STRFCNS

Definition at line 41 of file scrub.cpp.

Function Documentation

◆ ShowScrubW()

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

Definition at line 490 of file scrub.cpp.

490  {
491  try {
494  LUID luid;
495 
497  throw last_error(GetLastError());
498 
499  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
500  throw last_error(GetLastError());
501 
502  tp.PrivilegeCount = 1;
503  tp.Privileges[0].Luid = luid;
504  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
505 
506  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
507  throw last_error(GetLastError());
508 
509  set_dpi_aware();
510 
511  BtrfsScrub scrub(lpszCmdLine);
512 
514  } catch (const exception& e) {
515  error_message(hwnd, e.what());
516  }
517 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define IDD_SCRUB
Definition: resource.h:82
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
_In_ UINT64 _In_ UINT64 _In_ UINT64 _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2694
#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
LONG_PTR LPARAM
Definition: windef.h:208
#define TOKEN_QUERY
Definition: setypes.h:874
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
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
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:296
static INT_PTR CALLBACK stub_ScrubDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrub.cpp:470
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:876
void set_dpi_aware()
Definition: main.cpp:50

◆ StartScrubW()

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

Definition at line 519 of file scrub.cpp.

519  {
521 
522  command_line_to_args(lpszCmdLine, args);
523 
524  if (args.size() >= 1) {
525  LUID luid;
527 
528  {
530 
532  return;
533 
534  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
535  return;
536 
537  tp.PrivilegeCount = 1;
538  tp.Privileges[0].Luid = luid;
539  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
540 
541  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
542  return;
543  }
544 
547  if (h != INVALID_HANDLE_VALUE) {
549 
550  NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_START_SCRUB, nullptr, 0, nullptr, 0);
551  }
552  }
553 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
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
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
Definition: match.c:390
#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 SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
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
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#define FSCTL_BTRFS_START_SCRUB
Definition: btrfsioctl.h:24
#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
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
#define args
Definition: format.c:66
void command_line_to_args(LPWSTR cmdline, vector< wstring > args)
Definition: main.cpp:610

◆ StopScrubW()

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

Definition at line 555 of file scrub.cpp.

555  {
557 
558  command_line_to_args(lpszCmdLine, args);
559 
560  if (args.size() >= 1) {
561  LUID luid;
563 
564  {
566 
568  return;
569 
570  if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
571  return;
572 
573  tp.PrivilegeCount = 1;
574  tp.Privileges[0].Luid = luid;
575  tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
576 
577  if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
578  return;
579  }
580 
583  if (h != INVALID_HANDLE_VALUE) {
585 
586  NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_STOP_SCRUB, nullptr, 0, nullptr, 0);
587  }
588  }
589 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
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
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
Definition: match.c:390
#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 SE_PRIVILEGE_ENABLED
Definition: setypes.h:63
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
HANDLE WINAPI GetCurrentProcess(VOID)
Definition: proc.c:1168
#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
#define FSCTL_BTRFS_STOP_SCRUB
Definition: btrfsioctl.h:28
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
#define args
Definition: format.c:66
void command_line_to_args(LPWSTR cmdline, vector< wstring > args)
Definition: main.cpp:610

◆ stub_ScrubDlgProc()

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

Definition at line 470 of file scrub.cpp.

470  {
471  BtrfsScrub* bs;
472 
473  if (uMsg == WM_INITDIALOG) {
475  bs = (BtrfsScrub*)lParam;
476  } else {
478  }
479 
480  if (bs)
481  return bs->ScrubDlgProc(hwndDlg, uMsg, wParam, lParam);
482  else
483  return false;
484 }
#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
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
#define WM_INITDIALOG
Definition: winuser.h:1715
LPARAM lParam
Definition: combotst.c:139

Referenced by ShowScrubW().