ReactOS 0.4.15-dev-8348-gc1b9bb5
send.cpp File Reference
#include "shellext.h"
#include "send.h"
#include "resource.h"
#include <stddef.h>
#include <shlobj.h>
#include <iostream>
Include dependency graph for send.cpp:

Go to the source code of this file.

Macros

#define SEND_BUFFER_LEN   1048576
 

Functions

static DWORD WINAPI send_thread (LPVOID lpParameter)
 
static INT_PTR CALLBACK stub_SendDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
void CALLBACK SendSubvolGUIW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 
static void send_subvol (const wstring &subvol, const wstring &file, const wstring &parent, const vector< wstring > &clones)
 
void CALLBACK SendSubvolW (HWND hwnd, HINSTANCE hinst, LPWSTR lpszCmdLine, int nCmdShow)
 

Macro Definition Documentation

◆ SEND_BUFFER_LEN

#define SEND_BUFFER_LEN   1048576

Definition at line 28 of file send.cpp.

Function Documentation

◆ send_subvol()

static void send_subvol ( const wstring &  subvol,
const wstring &  file,
const wstring &  parent,
const vector< wstring > &  clones 
)
static

Definition at line 564 of file send.cpp.

564 {
565 char* buf;
566 win_handle dirh, stream;
567 ULONG i;
573
574 buf = (char*)malloc(SEND_BUFFER_LEN);
575
576 try {
578 if (dirh == INVALID_HANDLE_VALUE)
579 throw last_error(GetLastError());
580
583 throw last_error(GetLastError());
584
585 try {
586 size_t bss_size = offsetof(btrfs_send_subvol, clones[0]) + (clones.size() * sizeof(HANDLE));
587 bss = (btrfs_send_subvol*)malloc(bss_size);
588 memset(bss, 0, bss_size);
589
590 if (parent != L"") {
591 HANDLE parenth;
592
594 if (parenth == INVALID_HANDLE_VALUE)
595 throw last_error(GetLastError());
596
597 bss->parent = parenth;
598 } else
599 bss->parent = nullptr;
600
601 bss->num_clones = (ULONG)clones.size();
602
603 for (i = 0; i < bss->num_clones; i++) {
604 HANDLE h;
605
607 if (h == INVALID_HANDLE_VALUE) {
608 auto le = GetLastError();
609 ULONG j;
610
611 for (j = 0; j < i; j++) {
612 CloseHandle(bss->clones[j]);
613 }
614
615 if (bss->parent) CloseHandle(bss->parent);
616
617 throw last_error(le);
618 }
619
620 bss->clones[i] = h;
621 }
622
623 Status = NtFsControlFile(dirh, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SEND_SUBVOL, bss, (ULONG)bss_size, nullptr, 0);
624
625 for (i = 0; i < bss->num_clones; i++) {
626 CloseHandle(bss->clones[i]);
627 }
628
629 if (bss->parent) CloseHandle(bss->parent);
630
631 if (!NT_SUCCESS(Status))
632 throw ntstatus_error(Status);
633
634 memcpy(header.magic, BTRFS_SEND_MAGIC, sizeof(header.magic));
635 header.version = 1;
636
637 if (!WriteFile(stream, &header, sizeof(header), nullptr, nullptr))
638 throw last_error(GetLastError());
639
640 do {
641 Status = NtFsControlFile(dirh, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_READ_SEND_BUFFER, nullptr, 0, buf, SEND_BUFFER_LEN);
642
643 if (NT_SUCCESS(Status))
644 WriteFile(stream, buf, (DWORD)iosb.Information, nullptr, nullptr);
645 } while (NT_SUCCESS(Status));
646
648 throw ntstatus_error(Status);
649
650 end.length = 0;
652 end.csum = 0x9dc96c50;
653
654 if (!WriteFile(stream, &end, sizeof(end), nullptr, nullptr))
655 throw last_error(GetLastError());
656
658 } catch (...) {
659 FILE_DISPOSITION_INFO fdi;
660
661 fdi.DeleteFile = true;
662
663 Status = NtSetInformationFile(stream, &iosb, &fdi, sizeof(FILE_DISPOSITION_INFO), FileDispositionInformation);
664 if (!NT_SUCCESS(Status))
665 throw ntstatus_error(Status);
666
667 throw;
668 }
669 } catch (...) {
670 free(buf);
671 throw;
672 }
673
674 free(buf);
675}
LONG NTSTATUS
Definition: precomp.h:26
#define FSCTL_BTRFS_SEND_SUBVOL
Definition: btrfsioctl.h:36
#define FSCTL_BTRFS_READ_SEND_BUFFER
Definition: btrfsioctl.h:37
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define CreateFileW
Definition: compat.h:741
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
#define FILE_SHARE_READ
Definition: compat.h:136
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
r parent
Definition: btrfs.c:3010
#define BTRFS_SEND_CMD_END
Definition: btrfs.h:565
#define BTRFS_SEND_MAGIC
Definition: btrfs.h:593
unsigned long DWORD
Definition: ntddk_ex.h:95
@ FileDispositionInformation
Definition: from_kernel.h:74
Status
Definition: gdiplustypes.h:25
GLuint GLuint end
Definition: gl.h:1545
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
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 GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
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 GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define OPEN_ALWAYS
Definition: disk.h:70
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3096
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define DELETE
Definition: nt_native.h:57
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)
#define L(x)
Definition: ntvdm.h:50
#define offsetof(TYPE, MEMBER)
#define memset(x, y, z)
Definition: compat.h:39
#define SEND_BUFFER_LEN
Definition: send.cpp:28
#define STATUS_END_OF_FILE
Definition: shellext.h:67
HANDLE clones[1]
Definition: btrfsioctl.h:270
Definition: fci.c:127
Definition: parse.h:23
size_type size() const
Definition: _vector.h:192
PVOID HANDLE
Definition: typedefs.h:73
uint32_t ULONG
Definition: typedefs.h:59
DWORD WINAPI GetLastError(void)
Definition: except.c:1042

Referenced by fsctl_request(), and SendSubvolW().

◆ send_thread()

static DWORD WINAPI send_thread ( LPVOID  lpParameter)
static

Definition at line 227 of file send.cpp.

227 {
228 BtrfsSend* bs = (BtrfsSend*)lpParameter;
229
230 return bs->Thread();
231}
Definition: send.h:27
static struct msdos_boot_sector bs
Definition: mkdosfs.c:539

Referenced by send_subvol(), and BtrfsSend::StartSend().

◆ SendSubvolGUIW()

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

Definition at line 535 of file send.cpp.

535 {
536 try {
539 LUID luid;
540
542
544 throw last_error(GetLastError());
545
546 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
547 throw last_error(GetLastError());
548
549 tp.PrivilegeCount = 1;
550 tp.Privileges[0].Luid = luid;
551 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
552
553 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
554 throw last_error(GetLastError());
555
557
558 bs.Open(hwnd, lpszCmdLine);
559 } catch (const exception& e) {
560 error_message(hwnd, e.what());
561 }
562}
void set_dpi_aware()
Definition: main.cpp:50
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:783
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
_In_ LONG _In_ HWND hwnd
Definition: winddi.h:4023
#define TOKEN_ADJUST_PRIVILEGES
Definition: setypes.h:930
#define TOKEN_QUERY
Definition: setypes.h:928
#define SE_PRIVILEGE_ENABLED
Definition: setypes.h:63

◆ SendSubvolW()

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

Definition at line 677 of file send.cpp.

677 {
679 wstring subvol = L"", parent = L"", file = L"";
680 vector<wstring> clones;
681
682 command_line_to_args(lpszCmdLine, args);
683
684 if (args.size() >= 2) {
686 LUID luid;
687
688 {
690
692 return;
693
694 if (!LookupPrivilegeValueW(nullptr, L"SeManageVolumePrivilege", &luid))
695 return;
696
697 tp.PrivilegeCount = 1;
698 tp.Privileges[0].Luid = luid;
699 tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
700
701 if (!AdjustTokenPrivileges(token, false, &tp, sizeof(TOKEN_PRIVILEGES), nullptr, nullptr))
702 return;
703 }
704
705 for (unsigned int i = 0; i < args.size(); i++) {
706 if (args[i][0] == '-') {
707 if (args[i][2] == 0 && i < args.size() - 1) {
708 if (args[i][1] == 'p') {
709 parent = args[i+1];
710 i++;
711 } else if (args[i][1] == 'c') {
712 clones.push_back(args[i+1]);
713 i++;
714 }
715 }
716 } else {
717 if (subvol == L"")
718 subvol = args[i];
719 else if (file == L"")
720 file = args[i];
721 }
722 }
723
724 if (subvol != L"" && file != L"") {
725 try {
726 send_subvol(subvol, file, parent, clones);
727 } catch (const exception& e) {
728 cerr << "Error: " << e.what() << endl;
729 }
730 }
731 }
732}
basic_ostream< _CharT, _Traits > &_STLP_CALL endl(basic_ostream< _CharT, _Traits > &__os)
Definition: _ostream.h:357
void command_line_to_args(LPWSTR cmdline, vector< wstring > &args)
Definition: main.cpp:645
#define cerr
Definition: iostream.cpp:39
static void send_subvol(const wstring &subvol, const wstring &file, const wstring &parent, const vector< wstring > &clones)
Definition: send.cpp:564
Definition: match.c:390
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379

◆ stub_SendDlgProc()

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

Definition at line 513 of file send.cpp.

513 {
514 BtrfsSend* bs;
515
516 if (uMsg == WM_INITDIALOG) {
518 bs = (BtrfsSend*)lParam;
519 } else
521
522 if (bs)
523 return bs->SendDlgProc(hwndDlg, uMsg, wParam, lParam);
524 else
525 return false;
526}
WPARAM wParam
Definition: combotst.c:138
LPARAM lParam
Definition: combotst.c:139
__int3264 LONG_PTR
Definition: mstsclib_h.h:276
#define GWLP_USERDATA
Definition: treelist.c:63
#define GetWindowLongPtrW
Definition: winuser.h:4829
#define WM_INITDIALOG
Definition: winuser.h:1739
#define SetWindowLongPtrW
Definition: winuser.h:5355

Referenced by BtrfsSend::Open().