ReactOS 0.4.16-dev-329-g9223134
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 486 of file scrub.cpp.

486 {
487 try {
490 LUID luid;
491
493 throw last_error(GetLastError());
494
495 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
496 throw last_error(GetLastError());
497
498 tp.PrivilegeCount = 1;
499 tp.Privileges[0].Luid = luid;
500 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
501
502 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
503 throw last_error(GetLastError());
504
506
507 BtrfsScrub scrub(lpszCmdLine);
508
510 } catch (const exception& e) {
511 error_message(hwnd, e.what());
512 }
513}
void set_dpi_aware()
Definition: main.cpp:50
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
#define IDD_SCRUB
Definition: resource.h:82
BOOL WINAPI LookupPrivilegeValueW(LPCWSTR lpSystemName, LPCWSTR lpPrivilegeName, PLUID lpLuid)
Definition: misc.c:782
BOOL WINAPI AdjustTokenPrivileges(HANDLE TokenHandle, BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength)
Definition: security.c:374
BOOL WINAPI OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle)
Definition: security.c:294
#define GetCurrentProcess()
Definition: compat.h:759
_In_ uint64_t _In_ uint64_t _In_ uint64_t _In_opt_ traverse_ptr * tp
Definition: btrfs.c:2996
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 e
Definition: ke_i.h:82
#define L(x)
Definition: ntvdm.h:50
static INT_PTR CALLBACK stub_ScrubDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: scrub.cpp:470
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
LONG_PTR LPARAM
Definition: windef.h:208
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_QUERY
Definition: setypes.h:928
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

◆ StartScrubW()

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

Definition at line 515 of file scrub.cpp.

515 {
517
518 command_line_to_args(lpszCmdLine, args);
519
520 if (args.size() >= 1) {
521 LUID luid;
523
524 {
526
528 return;
529
530 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
531 return;
532
533 tp.PrivilegeCount = 1;
534 tp.Privileges[0].Luid = luid;
535 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
536
537 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
538 return;
539 }
540
543 if (h != INVALID_HANDLE_VALUE) {
545
546 NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_START_SCRUB, nullptr, 0, nullptr, 0);
547 }
548 }
549}
#define FSCTL_BTRFS_START_SCRUB
Definition: btrfsioctl.h:23
void command_line_to_args(LPWSTR cmdline, vector< wstring > &args)
Definition: main.cpp:645
#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
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#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_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)
Definition: match.c:390

◆ StopScrubW()

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

Definition at line 551 of file scrub.cpp.

551 {
553
554 command_line_to_args(lpszCmdLine, args);
555
556 if (args.size() >= 1) {
557 LUID luid;
559
560 {
562
564 return;
565
566 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
567 return;
568
569 tp.PrivilegeCount = 1;
570 tp.Privileges[0].Luid = luid;
571 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
572
573 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
574 return;
575 }
576
579 if (h != INVALID_HANDLE_VALUE) {
581
582 NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_STOP_SCRUB, nullptr, 0, nullptr, 0);
583 }
584 }
585}
#define FSCTL_BTRFS_STOP_SCRUB
Definition: btrfsioctl.h:27

◆ 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}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GetWindowLongPtr
Definition: treelist.c:73
#define SetWindowLongPtr
Definition: treelist.c:70
#define GWLP_USERDATA
Definition: treelist.c:63
#define WM_INITDIALOG
Definition: winuser.h:1742

Referenced by ShowScrubW().