ReactOS  0.4.15-dev-1068-g467feb9
BtrfsSend Class Reference

#include <send.h>

Collaboration diagram for BtrfsSend:

Public Member Functions

 BtrfsSend ()
 
 ~BtrfsSend ()
 
void Open (HWND hwnd, WCHAR *path)
 
INT_PTR SendDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 
DWORD Thread ()
 

Private Member Functions

void StartSend (HWND hwnd)
 
void Browse (HWND hwnd)
 
void BrowseParent (HWND hwnd)
 
void AddClone (HWND hwnd)
 
void RemoveClone (HWND hwnd)
 

Private Attributes

bool started
 
bool incremental
 
WCHAR file [MAX_PATH]
 
WCHAR closetext [255]
 
HANDLE thread
 
HANDLE dirh
 
HANDLE stream
 
HWND hwnd
 
wstring subvol
 
charbuf
 
vector< wstring > clones
 

Detailed Description

Definition at line 27 of file send.h.

Constructor & Destructor Documentation

◆ BtrfsSend()

BtrfsSend::BtrfsSend ( )
inline

Definition at line 29 of file send.h.

29  {
30  started = false;
31  file[0] = 0;
34  subvol = L"";
35  buf = nullptr;
36  incremental = false;
37  }
bool started
Definition: send.h:55
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
bool incremental
Definition: send.h:56
static const WCHAR L[]
Definition: oid.c:1250
Definition: parse.h:22
wstring subvol
Definition: send.h:60
HANDLE dirh
Definition: send.h:58
Definition: fci.c:126

◆ ~BtrfsSend()

BtrfsSend::~BtrfsSend ( )
inline

Definition at line 39 of file send.h.

39  {
40  if (buf)
41  free(buf);
42  }
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define free
Definition: debug_ros.c:5

Member Function Documentation

◆ AddClone()

void BtrfsSend::AddClone ( HWND  hwnd)
private

Definition at line 359 of file send.cpp.

359  {
360  BROWSEINFOW bi;
361  PIDLIST_ABSOLUTE root, pidl;
362  HRESULT hr;
363  WCHAR path[MAX_PATH], volpathw[MAX_PATH];
366  btrfs_get_file_ids bgfi;
367 
368  if (!GetVolumePathNameW(subvol.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1))
370 
371  hr = SHParseDisplayName(volpathw, 0, &root, 0, 0);
372  if (FAILED(hr))
374 
375  memset(&bi, 0, sizeof(BROWSEINFOW));
376 
377  bi.hwndOwner = hwnd;
378  bi.pidlRoot = root;
380 
381  pidl = SHBrowseForFolderW(&bi);
382 
383  if (!pidl)
384  return;
385 
386  if (!SHGetPathFromIDListW(pidl, path))
388 
389  {
391  if (h == INVALID_HANDLE_VALUE)
393 
394  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_FILE_IDS, nullptr, 0, &bgfi, sizeof(btrfs_get_file_ids));
395  if (!NT_SUCCESS(Status))
397  }
398 
399  if (bgfi.inode != 0x100 || bgfi.top)
401 
403 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
HRESULT hr
Definition: shlfolder.c:183
#define LB_ADDSTRING
Definition: winuser.h:2013
struct _root root
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
HWND hwndOwner
Definition: shlobj.h:1127
#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)
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
#define BIF_NONEWFOLDERBUTTON
Definition: shlobj.h:1154
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
#define IDS_SHPARSEDISPLAYNAME_FAILED
Definition: resource.h:188
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define IDC_CLONE_LIST
Definition: resource.h:332
#define IDS_NOT_SUBVOL
Definition: resource.h:186
LONG_PTR LPARAM
Definition: windef.h:208
#define OPEN_EXISTING
Definition: compat.h:523
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LONG HRESULT
Definition: typedefs.h:79
#define MAX_PATH
Definition: compat.h:34
#define BIF_USENEWUI
Definition: shlobj.h:1151
Status
Definition: gdiplustypes.h:24
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
HWND hwnd
Definition: send.h:59
#define FSCTL_BTRFS_GET_FILE_IDS
Definition: btrfsioctl.h:7
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1128
wstring subvol
Definition: send.h:60
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1335
UINT ulFlags
Definition: shlobj.h:1131
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1144
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1381
#define IDS_SEND_CANT_OPEN_DIR
Definition: resource.h:179
#define CreateFileW
Definition: compat.h:489
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define IDS_SHGETPATHFROMIDLIST_FAILED
Definition: resource.h:189
#define IDS_GET_FILE_IDS_FAILED
Definition: resource.h:187
#define memset(x, y, z)
Definition: compat.h:39
#define IDS_RECV_GETVOLUMEPATHNAME_FAILED
Definition: resource.h:169

Referenced by SendDlgProc().

◆ Browse()

void BtrfsSend::Browse ( HWND  hwnd)
private

Definition at line 295 of file send.cpp.

295  {
297 
298  file[0] = 0;
299 
300  memset(&ofn, 0, sizeof(OPENFILENAMEW));
301  ofn.lStructSize = sizeof(OPENFILENAMEW);
302  ofn.hwndOwner = hwnd;
303  ofn.hInstance = module;
304  ofn.lpstrFile = file;
305  ofn.nMaxFile = sizeof(file) / sizeof(WCHAR);
306 
307  if (!GetSaveFileNameW(&ofn))
308  return;
309 
311 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
HMODULE module
Definition: main.cpp:47
HWND hwndOwner
Definition: commdlg.h:330
OPENFILENAME ofn
Definition: main.cpp:37
WCHAR file[MAX_PATH]
Definition: send.h:57
#define IDC_STREAM_DEST
Definition: resource.h:327
BOOL WINAPI GetSaveFileNameW(LPOPENFILENAMEW ofn)
Definition: filedlg.c:4736
DWORD nMaxFile
Definition: commdlg.h:337
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
HINSTANCE hInstance
Definition: commdlg.h:331
__wchar_t WCHAR
Definition: xmlstorage.h:180
DWORD lStructSize
Definition: commdlg.h:329
struct tagOFNW OPENFILENAMEW
HWND hwnd
Definition: send.h:59
LPSTR lpstrFile
Definition: commdlg.h:336
#define memset(x, y, z)
Definition: compat.h:39
Definition: fci.c:126

Referenced by SendDlgProc().

◆ BrowseParent()

void BtrfsSend::BrowseParent ( HWND  hwnd)
private

Definition at line 313 of file send.cpp.

313  {
314  BROWSEINFOW bi;
315  PIDLIST_ABSOLUTE root, pidl;
316  HRESULT hr;
317  WCHAR parent[MAX_PATH], volpathw[MAX_PATH];
320  btrfs_get_file_ids bgfi;
321 
322  if (!GetVolumePathNameW(subvol.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1))
324 
325  hr = SHParseDisplayName(volpathw, 0, &root, 0, 0);
326  if (FAILED(hr))
328 
329  memset(&bi, 0, sizeof(BROWSEINFOW));
330 
331  bi.hwndOwner = hwnd;
332  bi.pidlRoot = root;
334 
335  pidl = SHBrowseForFolderW(&bi);
336 
337  if (!pidl)
338  return;
339 
340  if (!SHGetPathFromIDListW(pidl, parent))
342 
343  {
345  if (h == INVALID_HANDLE_VALUE)
347 
348  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_GET_FILE_IDS, nullptr, 0, &bgfi, sizeof(btrfs_get_file_ids));
349  if (!NT_SUCCESS(Status))
351  }
352 
353  if (bgfi.inode != 0x100 || bgfi.top)
355 
357 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
HRESULT hr
Definition: shlfolder.c:183
struct _root root
LONG NTSTATUS
Definition: precomp.h:26
BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
Definition: pidl.c:1294
HWND hwndOwner
Definition: shlobj.h:1127
#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)
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
#define BIF_NONEWFOLDERBUTTON
Definition: shlobj.h:1154
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
#define IDS_SHPARSEDISPLAYNAME_FAILED
Definition: resource.h:188
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define FILE_TRAVERSE
Definition: nt_native.h:643
#define IDS_NOT_SUBVOL
Definition: resource.h:186
#define OPEN_EXISTING
Definition: compat.h:523
r parent
Definition: btrfs.c:2944
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
LONG HRESULT
Definition: typedefs.h:79
#define MAX_PATH
Definition: compat.h:34
#define BIF_USENEWUI
Definition: shlobj.h:1151
Status
Definition: gdiplustypes.h:24
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
HWND hwnd
Definition: send.h:59
#define FSCTL_BTRFS_GET_FILE_IDS
Definition: btrfsioctl.h:7
PCIDLIST_ABSOLUTE pidlRoot
Definition: shlobj.h:1128
wstring subvol
Definition: send.h:60
LPITEMIDLIST WINAPI SHBrowseForFolderW(LPBROWSEINFOW lpbi)
Definition: brsfolder.c:1335
UINT ulFlags
Definition: shlobj.h:1131
#define BIF_RETURNONLYFSDIRS
Definition: shlobj.h:1144
HRESULT WINAPI SHParseDisplayName(LPCWSTR pszName, IBindCtx *pbc, LPITEMIDLIST *ppidl, SFGAOF sfgaoIn, SFGAOF *psfgaoOut)
Definition: pidl.c:1381
#define IDS_SEND_CANT_OPEN_DIR
Definition: resource.h:179
#define IDC_PARENT_SUBVOL
Definition: resource.h:331
#define CreateFileW
Definition: compat.h:489
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define IDS_SHGETPATHFROMIDLIST_FAILED
Definition: resource.h:189
#define IDS_GET_FILE_IDS_FAILED
Definition: resource.h:187
#define memset(x, y, z)
Definition: compat.h:39
#define IDS_RECV_GETVOLUMEPATHNAME_FAILED
Definition: resource.h:169

Referenced by SendDlgProc().

◆ Open()

void BtrfsSend::Open ( HWND  hwnd,
WCHAR path 
)

Definition at line 527 of file send.cpp.

527  {
528  subvol = path;
529 
531  throw last_error(GetLastError());
532 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
INT_PTR WINAPI DialogBoxParamW(_In_opt_ HINSTANCE, _In_ LPCWSTR, _In_opt_ HWND, _In_opt_ DLGPROC, _In_ LPARAM)
GLsizei const GLchar ** path
Definition: glext.h:7234
static INT_PTR CALLBACK stub_SendDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: send.cpp:512
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
LONG_PTR LPARAM
Definition: windef.h:208
#define IDD_SEND_SUBVOL
Definition: resource.h:88
wstring subvol
Definition: send.h:60
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582

◆ RemoveClone()

void BtrfsSend::RemoveClone ( HWND  hwnd)
private

Definition at line 405 of file send.cpp.

405  {
406  LRESULT sel;
408 
409  sel = SendMessageW(cl, LB_GETCURSEL, 0, 0);
410 
411  if (sel == LB_ERR)
412  return;
413 
414  SendMessageW(cl, LB_DELETESTRING, sel, 0);
415 
416  if (SendMessageW(cl, LB_GETCURSEL, 0, 0) == LB_ERR)
418 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDC_CLONE_REMOVE
Definition: resource.h:291
#define LB_ERR
Definition: winuser.h:2407
#define IDC_CLONE_LIST
Definition: resource.h:332
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define LB_GETCURSEL
Definition: winuser.h:2021
LONG_PTR LRESULT
Definition: windef.h:209
#define LB_DELETESTRING
Definition: winuser.h:2014

Referenced by SendDlgProc().

◆ SendDlgProc()

INT_PTR BtrfsSend::SendDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 420 of file send.cpp.

420  {
421  try {
422  switch (uMsg) {
423  case WM_INITDIALOG:
424  this->hwnd = hwndDlg;
425 
426  GetDlgItemTextW(hwndDlg, IDCANCEL, closetext, sizeof(closetext) / sizeof(WCHAR));
427  break;
428 
429  case WM_COMMAND:
430  switch (HIWORD(wParam)) {
431  case BN_CLICKED:
432  switch (LOWORD(wParam)) {
433  case IDOK:
434  StartSend(hwndDlg);
435  return true;
436 
437  case IDCANCEL:
438  if (started) {
440 
441  if (stream != INVALID_HANDLE_VALUE) {
443  FILE_DISPOSITION_INFO fdi;
445 
446  fdi.DeleteFile = true;
447 
448  Status = NtSetInformationFile(stream, &iosb, &fdi, sizeof(FILE_DISPOSITION_INFO), FileDispositionInformation);
449 
451 
452  if (!NT_SUCCESS(Status))
453  throw ntstatus_error(Status);
454  }
455 
456  if (dirh != INVALID_HANDLE_VALUE)
457  CloseHandle(dirh);
458 
459  started = false;
460 
462 
463  EnableWindow(GetDlgItem(hwnd, IDOK), true);
466  } else
467  EndDialog(hwndDlg, 1);
468  return true;
469 
470  case IDC_BROWSE:
471  Browse(hwndDlg);
472  return true;
473 
474  case IDC_INCREMENTAL:
476 
479  return true;
480 
481  case IDC_PARENT_BROWSE:
482  BrowseParent(hwndDlg);
483  return true;
484 
485  case IDC_CLONE_ADD:
486  AddClone(hwndDlg);
487  return true;
488 
489  case IDC_CLONE_REMOVE:
490  RemoveClone(hwndDlg);
491  return true;
492  }
493  break;
494 
495  case LBN_SELCHANGE:
496  switch (LOWORD(wParam)) {
497  case IDC_CLONE_LIST:
499  return true;
500  }
501  break;
502  }
503  break;
504  }
505  } catch (const exception& e) {
506  error_message(hwnd, e.what());
507  }
508 
509  return false;
510 }
bool started
Definition: send.h:55
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2271
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:487
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define IDC_CLONE_REMOVE
Definition: resource.h:291
BOOL WINAPI TerminateThread(IN HANDLE hThread, IN DWORD dwExitCode)
Definition: thread.c:586
#define IDC_BROWSE
Definition: resource.h:21
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
#define IDC_STREAM_DEST
Definition: resource.h:327
#define LBN_SELCHANGE
Definition: winuser.h:2057
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
#define IDC_CLONE_ADD
Definition: resource.h:287
#define IDC_PARENT_BROWSE
Definition: resource.h:282
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define IDC_INCREMENTAL
Definition: resource.h:321
void RemoveClone(HWND hwnd)
Definition: send.cpp:405
void error_message(HWND hwnd, const char *msg)
Definition: main.cpp:785
bool incremental
Definition: send.h:56
#define e
Definition: ke_i.h:82
#define IDC_CLONE_LIST
Definition: resource.h:332
void BrowseParent(HWND hwnd)
Definition: send.cpp:313
void StartSend(HWND hwnd)
Definition: send.cpp:233
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
void AddClone(HWND hwnd)
Definition: send.cpp:359
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BN_CLICKED
Definition: winuser.h:1907
Status
Definition: gdiplustypes.h:24
Definition: parse.h:22
#define WM_COMMAND
Definition: winuser.h:1722
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
void Browse(HWND hwnd)
Definition: send.cpp:295
#define IDC_PARENT_SUBVOL
Definition: resource.h:331
HANDLE dirh
Definition: send.h:58
WCHAR closetext[255]
Definition: send.h:57
#define HIWORD(l)
Definition: typedefs.h:247
#define IDCANCEL
Definition: winuser.h:825
#define WM_INITDIALOG
Definition: winuser.h:1721
#define LOWORD(l)
Definition: pedump.c:82
HANDLE thread
Definition: send.h:58

◆ StartSend()

void BtrfsSend::StartSend ( HWND  hwnd)
private

Definition at line 233 of file send.cpp.

233  {
234  wstring s;
235  HWND cl;
236 
237  if (started)
238  return;
239 
240  GetDlgItemTextW(hwnd, IDC_STREAM_DEST, file, sizeof(file) / sizeof(WCHAR));
241 
242  if (file[0] == 0)
243  return;
244 
245  if (incremental) {
247 
249 
250  if (parent[0] == 0)
251  return;
252  }
253 
254  started = true;
255 
256  wstring writing;
257 
259 
260  SetDlgItemTextW(hwnd, IDC_SEND_STATUS, writing.c_str());
261 
263  SetDlgItemTextW(hwnd, IDCANCEL, s.c_str());
264 
265  EnableWindow(GetDlgItem(hwnd, IDOK), false);
268 
269  clones.clear();
270 
272  auto num_clones = SendMessageW(cl, LB_GETCOUNT, 0, 0);
273 
274  if (num_clones != LB_ERR) {
275  for (unsigned int i = 0; i < (unsigned int)num_clones; i++) {
276  WCHAR* t;
277 
278  auto len = SendMessageW(cl, LB_GETTEXTLEN, i, 0);
279  t = (WCHAR*)malloc((len + 1) * sizeof(WCHAR));
280 
281  SendMessageW(cl, LB_GETTEXT, i, (LPARAM)t);
282 
283  clones.push_back(t);
284 
285  free(t);
286  }
287  }
288 
289  thread = CreateThread(nullptr, 0, send_thread, this, 0, nullptr);
290 
291  if (!thread)
292  throw last_error(GetLastError());
293 }
bool started
Definition: send.h:55
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2271
#define IDOK
Definition: winuser.h:824
#define IDC_SEND_STATUS
Definition: resource.h:329
#define IDC_BROWSE
Definition: resource.h:21
#define free
Definition: debug_ros.c:5
GLdouble GLdouble t
Definition: gl.h:2047
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define IDC_STREAM_DEST
Definition: resource.h:327
#define IDS_SEND_WRITING
Definition: resource.h:192
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
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
bool incremental
Definition: send.h:56
#define LB_ERR
Definition: winuser.h:2407
#define IDC_CLONE_LIST
Definition: resource.h:332
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:136
LONG_PTR LPARAM
Definition: windef.h:208
#define LB_GETTEXTLEN
Definition: winuser.h:2032
#define LB_GETCOUNT
Definition: winuser.h:2020
r parent
Definition: btrfs.c:2944
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
void push_back(const _Tp &__x=_STLP_DEFAULT_CONSTRUCTED(_Tp))
Definition: _vector.h:379
vector< wstring > clones
Definition: send.h:62
#define MAX_PATH
Definition: compat.h:34
static DWORD WINAPI send_thread(LPVOID lpParameter)
Definition: send.cpp:227
#define LB_GETTEXT
Definition: winuser.h:2031
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define IDS_SEND_CANCEL
Definition: resource.h:191
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
#define IDC_PARENT_SUBVOL
Definition: resource.h:331
#define malloc
Definition: debug_ros.c:4
#define IDCANCEL
Definition: winuser.h:825
void clear()
Definition: _vector.h:653
HANDLE thread
Definition: send.h:58
unsigned int(__cdecl typeof(jpeg_read_scanlines))(struct jpeg_decompress_struct *
Definition: typeof.h:31
Definition: fci.c:126

Referenced by SendDlgProc().

◆ Thread()

DWORD BtrfsSend::Thread ( )

Definition at line 30 of file send.cpp.

30  {
31  try {
34  btrfs_send_subvol* bss;
37  ULONG i;
38 
39  buf = (char*)malloc(SEND_BUFFER_LEN);
40 
41  try {
45 
46  try {
47  size_t bss_size = offsetof(btrfs_send_subvol, clones[0]) + (clones.size() * sizeof(HANDLE));
48  bss = (btrfs_send_subvol*)malloc(bss_size);
49  memset(bss, 0, bss_size);
50 
51  if (incremental) {
53  HANDLE parenth;
54 
55  parent[0] = 0;
56 
58 
60  if (parenth == INVALID_HANDLE_VALUE)
62 
63  bss->parent = parenth;
64  } else
65  bss->parent = nullptr;
66 
67  bss->num_clones = (ULONG)clones.size();
68 
69  for (i = 0; i < bss->num_clones; i++) {
70  HANDLE h;
71 
73  if (h == INVALID_HANDLE_VALUE) {
74  auto le = GetLastError();
75  ULONG j;
76 
77  for (j = 0; j < i; j++) {
78  CloseHandle(bss->clones[j]);
79  }
80 
81  if (bss->parent) CloseHandle(bss->parent);
82 
83  throw string_error(IDS_SEND_CANT_OPEN_DIR, clones[i].c_str(), le, format_message(le).c_str());
84  }
85 
86  bss->clones[i] = h;
87  }
88 
89  Status = NtFsControlFile(dirh, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SEND_SUBVOL, bss, (ULONG)bss_size, nullptr, 0);
90 
91  for (i = 0; i < bss->num_clones; i++) {
92  CloseHandle(bss->clones[i]);
93  }
94 
95  if (!NT_SUCCESS(Status)) {
99  auto le = GetLastError();
100  if (bss->parent) CloseHandle(bss->parent);
102  }
103 
104  if (!(fileinfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
105  if (bss->parent) CloseHandle(bss->parent);
107  }
108 
109  if (bss->parent) {
111  auto le = GetLastError();
112  CloseHandle(bss->parent);
114  }
115 
116  if (!(fileinfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
117  CloseHandle(bss->parent);
119  }
120  }
121  }
122 
123  if (bss->parent) CloseHandle(bss->parent);
125  }
126 
127  if (bss->parent) CloseHandle(bss->parent);
128 
132 
133  try {
134  memcpy(header.magic, BTRFS_SEND_MAGIC, sizeof(header.magic));
135  header.version = 1;
136 
137  if (!WriteFile(stream, &header, sizeof(header), nullptr, nullptr))
139 
140  do {
141  Status = NtFsControlFile(dirh, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_READ_SEND_BUFFER, nullptr, 0, buf, SEND_BUFFER_LEN);
142 
143  if (NT_SUCCESS(Status)) {
144  if (!WriteFile(stream, buf, (DWORD)iosb.Information, nullptr, nullptr))
146  }
147  } while (NT_SUCCESS(Status));
148 
149  if (Status != STATUS_END_OF_FILE)
151 
152  end.length = 0;
153  end.cmd = BTRFS_SEND_CMD_END;
154  end.csum = 0x9dc96c50;
155 
156  if (!WriteFile(stream, &end, sizeof(end), nullptr, nullptr))
158 
160  } catch (...) {
161  FILE_DISPOSITION_INFO fdi;
162 
163  fdi.DeleteFile = true;
164 
165  Status = NtSetInformationFile(stream, &iosb, &fdi, sizeof(FILE_DISPOSITION_INFO), FileDispositionInformation);
166 
169 
170  if (!NT_SUCCESS(Status))
171  throw ntstatus_error(Status);
172 
173  throw;
174  }
175 
178  } catch (...) {
179  CloseHandle(dirh);
181 
182  throw;
183  }
184 
185  CloseHandle(dirh);
187  } catch (...) {
188  free(buf);
189  buf = nullptr;
190 
191  started = false;
192 
194  EnableWindow(GetDlgItem(hwnd, IDOK), true);
197 
198  throw;
199  }
200  } catch (const exception& e) {
201  auto msg = utf8_to_utf16(e.what());
202 
204  return 0;
205  }
206 
207 
208  free(buf);
209  buf = nullptr;
210 
211  started = false;
212 
214  EnableWindow(GetDlgItem(hwnd, IDOK), true);
217 
218  wstring success;
219 
221 
223 
224  return 0;
225 }
bool started
Definition: send.h:55
#define IDS_SEND_CANT_OPEN_FILE
Definition: resource.h:178
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
UINT WINAPI GetDlgItemTextW(HWND hDlg, int nIDDlgItem, LPWSTR lpString, int nMaxCount)
Definition: dialog.c:2271
#define IDOK
Definition: winuser.h:824
#define CloseHandle
Definition: compat.h:487
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
#define IDC_SEND_STATUS
Definition: resource.h:329
#define IDS_SEND_PARENT_NOT_READONLY
Definition: resource.h:190
#define IDS_SEND_GET_FILE_INFO_FAILED
Definition: resource.h:184
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define IDS_SEND_NOT_READONLY
Definition: resource.h:185
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
#define IDS_SEND_SUCCESS
Definition: resource.h:182
#define IDC_BROWSE
Definition: resource.h:21
#define free
Definition: debug_ros.c:5
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1004
LONG NTSTATUS
Definition: precomp.h:26
#define SEND_BUFFER_LEN
Definition: send.cpp:28
#define INVALID_HANDLE_VALUE
Definition: compat.h:479
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define IDC_STREAM_DEST
Definition: resource.h:327
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)
GLuint GLuint end
Definition: gl.h:1545
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:136
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define STATUS_END_OF_FILE
Definition: shellext.h:67
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
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
bool incremental
Definition: send.h:56
#define e
Definition: ke_i.h:82
#define IDS_SEND_FSCTL_BTRFS_READ_SEND_BUFFER_FAILED
Definition: resource.h:181
#define FSCTL_BTRFS_SEND_SUBVOL
Definition: btrfsioctl.h:36
#define offsetof(TYPE, MEMBER)
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define OPEN_EXISTING
Definition: compat.h:523
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
r parent
Definition: btrfs.c:2944
BOOL WINAPI GetFileInformationByHandle(HANDLE hFile, LPBY_HANDLE_FILE_INFORMATION lpFileInformation)
Definition: fileinfo.c:458
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
vector< wstring > clones
Definition: send.h:62
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define MAX_PATH
Definition: compat.h:34
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
HANDLE clones[1]
Definition: btrfsioctl.h:269
unsigned long DWORD
Definition: ntddk_ex.h:95
PVOID HANDLE
Definition: typedefs.h:73
#define IDS_SEND_FSCTL_BTRFS_SEND_SUBVOL_FAILED
Definition: resource.h:180
#define FSCTL_BTRFS_READ_SEND_BUFFER
Definition: btrfsioctl.h:37
#define success(from, fromstr, to, tostr)
#define OPEN_ALWAYS
Definition: disk.h:70
#define FILE_READ_ATTRIBUTES
Definition: nt_native.h:647
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
Status
Definition: gdiplustypes.h:24
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
Definition: parse.h:22
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define BTRFS_SEND_CMD_END
Definition: btrfs.h:553
wstring subvol
Definition: send.h:60
BOOL WINAPI EnableWindow(_In_ HWND, _In_ BOOL)
#define BTRFS_SEND_MAGIC
Definition: btrfs.h:581
#define IDS_SEND_CANT_OPEN_DIR
Definition: resource.h:179
static int load_string(HINSTANCE hModule, UINT resId, LPWSTR pwszBuffer, INT cMaxChars)
Definition: muireg.c:10
#define IDC_PARENT_SUBVOL
Definition: resource.h:331
#define CreateFileW
Definition: compat.h:489
HANDLE dirh
Definition: send.h:58
#define msg(x)
Definition: auth_time.c:54
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
WCHAR closetext[255]
Definition: send.h:57
#define IDS_SEND_WRITEFILE_FAILED
Definition: resource.h:183
size_type size() const
Definition: _vector.h:192
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define IDCANCEL
Definition: winuser.h:825
#define memset(x, y, z)
Definition: compat.h:39
struct CFHEADER header
Definition: fdi.c:101
#define DELETE
Definition: nt_native.h:57
Definition: fci.c:126

Member Data Documentation

◆ buf

char* BtrfsSend::buf
private

Definition at line 61 of file send.h.

◆ clones

vector<wstring> BtrfsSend::clones
private

Definition at line 62 of file send.h.

Referenced by StartSend(), and Thread().

◆ closetext

WCHAR BtrfsSend::closetext[255]
private

Definition at line 57 of file send.h.

Referenced by SendDlgProc(), and Thread().

◆ dirh

HANDLE BtrfsSend::dirh
private

Definition at line 58 of file send.h.

Referenced by BtrfsSend(), SendDlgProc(), and Thread().

◆ file

WCHAR BtrfsSend::file[MAX_PATH]
private

Definition at line 57 of file send.h.

Referenced by Browse().

◆ hwnd

HWND BtrfsSend::hwnd
private

Definition at line 59 of file send.h.

Referenced by AddClone(), Browse(), and BrowseParent().

◆ incremental

bool BtrfsSend::incremental
private

Definition at line 56 of file send.h.

Referenced by BtrfsSend(), SendDlgProc(), StartSend(), and Thread().

◆ started

bool BtrfsSend::started
private

Definition at line 55 of file send.h.

Referenced by BtrfsSend(), SendDlgProc(), StartSend(), and Thread().

◆ stream

HANDLE BtrfsSend::stream
private

Definition at line 58 of file send.h.

◆ subvol

wstring BtrfsSend::subvol
private

Definition at line 60 of file send.h.

Referenced by AddClone(), BrowseParent(), BtrfsSend(), Open(), and Thread().

◆ thread

HANDLE BtrfsSend::thread
private

Definition at line 58 of file send.h.

Referenced by SendDlgProc(), and StartSend().


The documentation for this class was generated from the following files: