ReactOS  0.4.15-dev-439-g292f67a
BtrfsRecv Class Reference

#include <recv.h>

Collaboration diagram for BtrfsRecv:

Public Member Functions

 BtrfsRecv ()
 
virtual ~BtrfsRecv ()
 
void Open (HWND hwnd, const wstring &file, const wstring &path, bool quiet)
 
DWORD recv_thread ()
 
INT_PTR CALLBACK RecvProgressDlgProc (HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
 

Private Member Functions

void cmd_subvol (HWND hwnd, btrfs_send_command *cmd, uint8_t *data, const win_handle &parent)
 
void cmd_snapshot (HWND hwnd, btrfs_send_command *cmd, uint8_t *data, const win_handle &parent)
 
void cmd_mkfile (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_rename (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_link (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_unlink (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_rmdir (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_setxattr (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_removexattr (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_write (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_clone (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_truncate (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_chmod (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_chown (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void cmd_utimes (HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
 
void add_cache_entry (BTRFS_UUID *uuid, uint64_t transid, const wstring &path)
 
bool find_tlv (uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
 
void do_recv (const win_handle &f, uint64_t *pos, uint64_t size, const win_handle &parent)
 

Private Attributes

HANDLE dir
 
HANDLE master
 
HANDLE thread
 
HANDLE lastwritefile
 
HWND hwnd
 
wstring streamfile
 
wstring dirpath
 
wstring subvolpath
 
wstring lastwritepath
 
DWORD lastwriteatt
 
ULONG num_received
 
uint64_t stransid
 
BTRFS_UUID subvol_uuid
 
bool running
 
bool cancelling
 
vector< subvol_cachecache
 

Detailed Description

Definition at line 35 of file recv.h.

Constructor & Destructor Documentation

◆ BtrfsRecv()

BtrfsRecv::BtrfsRecv ( )
inline

Definition at line 37 of file recv.h.

37  {
38  thread = nullptr;
41  running = false;
42  cancelling = false;
43  stransid = 0;
44  num_received = 0;
45  hwnd = nullptr;
46  cache.clear();
47  }
Definition: cache.c:48
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
ULONG num_received
Definition: recv.h:81
bool running
Definition: recv.h:84
HANDLE dir
Definition: recv.h:77
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
bool cancelling
Definition: recv.h:84
HANDLE thread
Definition: recv.h:77
HANDLE master
Definition: recv.h:77
uint64_t stransid
Definition: recv.h:82

◆ ~BtrfsRecv()

virtual BtrfsRecv::~BtrfsRecv ( )
inlinevirtual

Definition at line 49 of file recv.h.

49  {
50  cache.clear();
51  }
Definition: cache.c:48

Member Function Documentation

◆ add_cache_entry()

void BtrfsRecv::add_cache_entry ( BTRFS_UUID uuid,
uint64_t  transid,
const wstring &  path 
)
private

Definition at line 257 of file recv.cpp.

257  {
258  subvol_cache sc;
259 
260  sc.uuid = *uuid;
261  sc.transid = transid;
262  sc.path = path;
263 
264  cache.push_back(sc);
265 }
Definition: cache.c:48
BTRFS_UUID uuid
Definition: recv.h:30
GLsizei const GLchar ** path
Definition: glext.h:7234
uint64_t transid
Definition: recv.h:31
wstring path
Definition: recv.h:32

Referenced by cmd_clone(), cmd_snapshot(), and cmd_subvol().

◆ cmd_chmod()

void BtrfsRecv::cmd_chmod ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 1090 of file recv.cpp.

1090  {
1091  win_handle h;
1092  uint32_t* mode;
1093  ULONG modelen;
1094  wstring pathu;
1095  btrfs_set_inode_info bsii;
1096  NTSTATUS Status;
1098 
1099  {
1100  char* path;
1101  ULONG pathlen;
1102 
1103  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
1105 
1106  pathu = utf8_to_utf16(string(path, pathlen));
1107  }
1108 
1109  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen))
1111 
1112  if (modelen < sizeof(uint32_t))
1113  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(uint32_t));
1114 
1115  h = CreateFileW((subvolpath + pathu).c_str(), WRITE_DAC, 0, nullptr, OPEN_EXISTING,
1117  if (h == INVALID_HANDLE_VALUE)
1119 
1120  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
1121 
1122  bsii.mode_changed = true;
1123  bsii.st_mode = *mode;
1124 
1125  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
1126  if (!NT_SUCCESS(Status))
1128 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
LONG NTSTATUS
Definition: precomp.h:26
#define IDS_RECV_SETINODEINFO_FAILED
Definition: resource.h:150
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
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)
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
#define OPEN_EXISTING
Definition: compat.h:435
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define WRITE_DAC
Definition: nt_native.h:59
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define FSCTL_BTRFS_SET_INODE_INFO
Definition: btrfsioctl.h:11
GLenum mode
Definition: glext.h:6217
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
Status
Definition: gdiplustypes.h:24
#define BTRFS_SEND_TLV_MODE
Definition: btrfs.h:560
UINT32 uint32_t
Definition: types.h:75
#define CreateFileW
Definition: compat.h:409
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
unsigned int ULONG
Definition: retypes.h:1
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define memset(x, y, z)
Definition: compat.h:39
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_chown()

void BtrfsRecv::cmd_chown ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 1130 of file recv.cpp.

1130  {
1131  win_handle h;
1132  uint32_t *uid, *gid;
1133  ULONG uidlen, gidlen;
1134  wstring pathu;
1135  btrfs_set_inode_info bsii;
1136 
1137  {
1138  char* path;
1139  ULONG pathlen;
1140 
1141  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
1143 
1144  pathu = utf8_to_utf16(string(path, pathlen));
1145  }
1146 
1147  h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_ATTRIBUTES | WRITE_OWNER | WRITE_DAC, 0, nullptr, OPEN_EXISTING,
1149  if (h == INVALID_HANDLE_VALUE)
1151 
1152  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
1153 
1154  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_UID, (void**)&uid, &uidlen)) {
1155  if (uidlen < sizeof(uint32_t))
1156  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"uid", uidlen, sizeof(uint32_t));
1157 
1158  bsii.uid_changed = true;
1159  bsii.st_uid = *uid;
1160  }
1161 
1162  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_GID, (void**)&gid, &gidlen)) {
1163  if (gidlen < sizeof(uint32_t))
1164  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"gid", gidlen, sizeof(uint32_t));
1165 
1166  bsii.gid_changed = true;
1167  bsii.st_gid = *gid;
1168  }
1169 
1170  if (bsii.uid_changed || bsii.gid_changed) {
1171  NTSTATUS Status;
1173 
1174  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
1175  if (!NT_SUCCESS(Status))
1177  }
1178 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define BTRFS_SEND_TLV_UID
Definition: btrfs.h:561
#define BTRFS_SEND_TLV_GID
Definition: btrfs.h:562
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
LONG NTSTATUS
Definition: precomp.h:26
#define IDS_RECV_SETINODEINFO_FAILED
Definition: resource.h:150
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
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)
#define WRITE_OWNER
Definition: nt_native.h:60
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
#define OPEN_EXISTING
Definition: compat.h:435
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define WRITE_DAC
Definition: nt_native.h:59
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define FSCTL_BTRFS_SET_INODE_INFO
Definition: btrfsioctl.h:11
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
Status
Definition: gdiplustypes.h:24
UINT32 uint32_t
Definition: types.h:75
#define CreateFileW
Definition: compat.h:409
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
unsigned int ULONG
Definition: retypes.h:1
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define memset(x, y, z)
Definition: compat.h:39
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_clone()

void BtrfsRecv::cmd_clone ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 901 of file recv.cpp.

901  {
902  uint64_t *offset, *cloneoffset, *clonetransid, *clonelen;
903  BTRFS_UUID* cloneuuid;
904  ULONG i, offsetlen, cloneoffsetlen, cloneuuidlen, clonetransidlen, clonelenlen;
905  wstring pathu, clonepathu, clonepar;
906  btrfs_find_subvol bfs;
909  WCHAR cloneparw[MAX_PATH];
911  LARGE_INTEGER filesize;
912  bool found = false;
913 
914  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_OFFSET, (void**)&offset, &offsetlen))
916 
917  if (offsetlen < sizeof(uint64_t))
918  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"offset", offsetlen, sizeof(uint64_t));
919 
920  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_LENGTH, (void**)&clonelen, &clonelenlen))
921  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_len");
922 
923  if (clonelenlen < sizeof(uint64_t))
924  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_len", clonelenlen, sizeof(uint64_t));
925 
926  {
927  char* path;
928  ULONG pathlen;
929 
930  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
932 
933  pathu = utf8_to_utf16(string(path, pathlen));
934  }
935 
936  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_UUID, (void**)&cloneuuid, &cloneuuidlen))
937  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_uuid");
938 
939  if (cloneuuidlen < sizeof(BTRFS_UUID))
940  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_uuid", cloneuuidlen, sizeof(BTRFS_UUID));
941 
942  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_CTRANSID, (void**)&clonetransid, &clonetransidlen))
943  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_ctransid");
944 
945  if (clonetransidlen < sizeof(uint64_t))
946  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_ctransid", clonetransidlen, sizeof(uint64_t));
947 
948  {
949  char* clonepath;
950  ULONG clonepathlen;
951 
952  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_PATH, (void**)&clonepath, &clonepathlen))
953  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_path");
954 
955  clonepathu = utf8_to_utf16(string(clonepath, clonepathlen));
956  }
957 
958  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_OFFSET, (void**)&cloneoffset, &cloneoffsetlen))
959  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_offset");
960 
961  if (cloneoffsetlen < sizeof(uint64_t))
962  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_offset", cloneoffsetlen, sizeof(uint64_t));
963 
964  for (i = 0; i < cache.size(); i++) {
965  if (!memcmp(cloneuuid, &cache[i].uuid, sizeof(BTRFS_UUID)) && *clonetransid == cache[i].transid) {
966  clonepar = cache[i].path;
967  found = true;
968  break;
969  }
970  }
971 
972  if (!found) {
973  WCHAR volpathw[MAX_PATH];
974 
975  bfs.uuid = *cloneuuid;
976  bfs.ctransid = *clonetransid;
977 
978  Status = NtFsControlFile(dir, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_FIND_SUBVOL, &bfs, sizeof(btrfs_find_subvol),
979  cloneparw, sizeof(cloneparw));
980  if (Status == STATUS_NOT_FOUND)
982  else if (!NT_SUCCESS(Status))
984 
985  if (!GetVolumePathNameW(dirpath.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1))
987 
988  clonepar = volpathw;
989  if (clonepar.substr(clonepar.length() - 1) == L"\\")
990  clonepar = clonepar.substr(0, clonepar.length() - 1);
991 
992  clonepar += cloneparw;
993  clonepar += L"\\";
994 
995  add_cache_entry(cloneuuid, *clonetransid, clonepar);
996  }
997 
998  {
1001  if (src == INVALID_HANDLE_VALUE)
1002  throw string_error(IDS_RECV_CANT_OPEN_FILE, funcname, (clonepar + clonepathu).c_str(), GetLastError(), format_message(GetLastError()).c_str());
1003 
1006  if (dest == INVALID_HANDLE_VALUE)
1008 
1009  if (!GetFileSizeEx(dest, &filesize))
1011 
1012  if ((uint64_t)filesize.QuadPart < *offset + *clonelen) {
1013  LARGE_INTEGER sizeli;
1014 
1015  sizeli.QuadPart = *offset + *clonelen;
1016 
1019 
1020  if (!SetEndOfFile(dest))
1022  }
1023 
1024  ded.FileHandle = src;
1025  ded.SourceFileOffset.QuadPart = *cloneoffset;
1027  ded.ByteCount.QuadPart = *clonelen;
1028 
1029  Status = NtFsControlFile(dest, nullptr, nullptr, nullptr, &iosb, FSCTL_DUPLICATE_EXTENTS_TO_FILE, &ded, sizeof(DUPLICATE_EXTENTS_DATA),
1030  nullptr, 0);
1031  if (!NT_SUCCESS(Status))
1033  }
1034 }
#define BTRFS_SEND_TLV_OFFSET
Definition: btrfs.h:573
Definition: cache.c:48
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
#define IDS_RECV_GETFILESIZEEX_FAILED
Definition: resource.h:173
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
HANDLE dir
Definition: recv.h:77
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define IDS_RECV_CANT_FIND_CLONE_SUBVOL
Definition: resource.h:172
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 FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
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
#define BTRFS_SEND_TLV_CLONE_PATH
Definition: btrfs.h:577
#define FILE_READ_DATA
Definition: nt_native.h:628
BTRFS_UUID uuid
Definition: btrfsioctl.h:262
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define OPEN_EXISTING
Definition: compat.h:435
LARGE_INTEGER SourceFileOffset
Definition: shellext.h:200
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define IDS_RECV_FIND_SUBVOL_FAILED
Definition: resource.h:167
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define BTRFS_SEND_TLV_CLONE_LENGTH
Definition: btrfs.h:579
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define MAX_PATH
Definition: compat.h:26
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
wstring dirpath
Definition: recv.h:79
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
#define FSCTL_BTRFS_FIND_SUBVOL
Definition: btrfsioctl.h:35
#define GetFileSizeEx
Definition: compat.h:423
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_RECV_SETFILEPOINTER_FAILED
Definition: resource.h:144
ULONG LowPart
Definition: typedefs.h:105
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
GLenum src
Definition: glext.h:6340
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
Status
Definition: gdiplustypes.h:24
#define BTRFS_SEND_TLV_CLONE_UUID
Definition: btrfs.h:575
#define FILE_BEGIN
Definition: winbase.h:112
UINT64 uint64_t
Definition: types.h:77
#define IDS_RECV_DUPLICATE_EXTENTS_FAILED
Definition: resource.h:174
LARGE_INTEGER TargetFileOffset
Definition: shellext.h:201
#define CreateFileW
Definition: compat.h:409
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
Definition: msctf.idl:510
unsigned int ULONG
Definition: retypes.h:1
#define BTRFS_SEND_TLV_CLONE_CTRANSID
Definition: btrfs.h:576
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
static char * dest
Definition: rtl.c:135
#define IDS_RECV_SETENDOFFILE_FAILED
Definition: resource.h:147
void add_cache_entry(BTRFS_UUID *uuid, uint64_t transid, const wstring &path)
Definition: recv.cpp:257
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
LARGE_INTEGER ByteCount
Definition: shellext.h:202
uint64_t ctransid
Definition: btrfsioctl.h:263
wstring subvolpath
Definition: recv.h:79
#define BTRFS_SEND_TLV_CLONE_OFFSET
Definition: btrfs.h:578
LONGLONG QuadPart
Definition: typedefs.h:113
#define FSCTL_DUPLICATE_EXTENTS_TO_FILE
Definition: shellext.h:205
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155
#define IDS_RECV_GETVOLUMEPATHNAME_FAILED
Definition: resource.h:169

Referenced by do_recv().

◆ cmd_link()

void BtrfsRecv::cmd_link ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 567 of file recv.cpp.

567  {
568  wstring pathu, path_linku;
569 
570  {
571  char* path;
572  ULONG path_len;
573 
574  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &path_len))
576 
577  pathu = utf8_to_utf16(string(path, path_len));
578  }
579 
580  {
581  char* path_link;
582  ULONG path_link_len;
583 
584  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_LINK, (void**)&path_link, &path_link_len))
585  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"path_link");
586 
587  path_linku = utf8_to_utf16(string(path_link, path_link_len));
588  }
589 
590  if (!CreateHardLinkW((subvolpath + pathu).c_str(), (subvolpath + path_linku).c_str(), nullptr))
591  throw string_error(IDS_RECV_CREATEHARDLINK_FAILED, pathu.c_str(), path_linku.c_str(), GetLastError(), format_message(GetLastError()).c_str());
592 }
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define BTRFS_SEND_TLV_PATH_LINK
Definition: btrfs.h:572
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
static DWORD path_len
Definition: batch.c:31
unsigned int ULONG
Definition: retypes.h:1
wstring subvolpath
Definition: recv.h:79
#define IDS_RECV_CREATEHARDLINK_FAILED
Definition: resource.h:146
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_mkfile()

void BtrfsRecv::cmd_mkfile ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 390 of file recv.cpp.

390  {
391  uint64_t *inode, *rdev = nullptr, *mode = nullptr;
392  ULONG inodelen;
395  btrfs_mknod* bmn;
396  wstring nameu, pathlinku;
397 
398  {
399  char* name;
400  ULONG namelen;
401 
402  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&name, &namelen))
404 
405  nameu = utf8_to_utf16(string(name, namelen));
406  }
407 
408  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_INODE, (void**)&inode, &inodelen))
410 
411  if (inodelen < sizeof(uint64_t))
412  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"inode", inodelen, sizeof(uint64_t));
413 
414  if (cmd->cmd == BTRFS_SEND_CMD_MKNOD || cmd->cmd == BTRFS_SEND_CMD_MKFIFO || cmd->cmd == BTRFS_SEND_CMD_MKSOCK) {
415  ULONG rdevlen, modelen;
416 
417  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_RDEV, (void**)&rdev, &rdevlen))
419 
420  if (rdevlen < sizeof(uint64_t))
421  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"rdev", rdev, sizeof(uint64_t));
422 
423  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen))
425 
426  if (modelen < sizeof(uint64_t))
427  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(uint64_t));
428  } else if (cmd->cmd == BTRFS_SEND_CMD_SYMLINK) {
429  char* pathlink;
430  ULONG pathlinklen;
431 
432  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_LINK, (void**)&pathlink, &pathlinklen))
433  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"path_link");
434 
435  pathlinku = utf8_to_utf16(string(pathlink, pathlinklen));
436  }
437 
438  size_t bmnsize = sizeof(btrfs_mknod) - sizeof(WCHAR) + (nameu.length() * sizeof(WCHAR));
439  bmn = (btrfs_mknod*)malloc(bmnsize);
440 
441  bmn->inode = *inode;
442 
443  if (cmd->cmd == BTRFS_SEND_CMD_MKDIR)
444  bmn->type = BTRFS_TYPE_DIRECTORY;
445  else if (cmd->cmd == BTRFS_SEND_CMD_MKNOD)
447  else if (cmd->cmd == BTRFS_SEND_CMD_MKFIFO)
448  bmn->type = BTRFS_TYPE_FIFO;
449  else if (cmd->cmd == BTRFS_SEND_CMD_MKSOCK)
450  bmn->type = BTRFS_TYPE_SOCKET;
451  else
452  bmn->type = BTRFS_TYPE_FILE;
453 
454  bmn->st_rdev = rdev ? *rdev : 0;
455  bmn->namelen = (uint16_t)(nameu.length() * sizeof(WCHAR));
456  memcpy(bmn->name, nameu.c_str(), bmn->namelen);
457 
458  Status = NtFsControlFile(dir, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_MKNOD, bmn, (ULONG)bmnsize, nullptr, 0);
459  if (!NT_SUCCESS(Status)) {
460  free(bmn);
462  }
463 
464  free(bmn);
465 
466  if (cmd->cmd == BTRFS_SEND_CMD_SYMLINK) {
467  REPARSE_DATA_BUFFER* rdb;
469 
470  size_t rdblen = offsetof(REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer.PathBuffer[0]) + (2 * pathlinku.length() * sizeof(WCHAR));
471 
472  if (rdblen >= 0x10000)
474 
475  rdb = (REPARSE_DATA_BUFFER*)malloc(rdblen);
476 
478  rdb->ReparseDataLength = (uint16_t)(rdblen - offsetof(REPARSE_DATA_BUFFER, SymbolicLinkReparseBuffer));
479  rdb->Reserved = 0;
480  rdb->SymbolicLinkReparseBuffer.SubstituteNameOffset = 0;
481  rdb->SymbolicLinkReparseBuffer.SubstituteNameLength = (uint16_t)(pathlinku.length() * sizeof(WCHAR));
482  rdb->SymbolicLinkReparseBuffer.PrintNameOffset = (uint16_t)(pathlinku.length() * sizeof(WCHAR));
483  rdb->SymbolicLinkReparseBuffer.PrintNameLength = (uint16_t)(pathlinku.length() * sizeof(WCHAR));
485 
486  memcpy(rdb->SymbolicLinkReparseBuffer.PathBuffer, pathlinku.c_str(), rdb->SymbolicLinkReparseBuffer.SubstituteNameLength);
487  memcpy(rdb->SymbolicLinkReparseBuffer.PathBuffer + (rdb->SymbolicLinkReparseBuffer.SubstituteNameLength / sizeof(WCHAR)),
488  pathlinku.c_str(), rdb->SymbolicLinkReparseBuffer.PrintNameLength);
489 
492  if (h == INVALID_HANDLE_VALUE) {
493  free(rdb);
495  }
496 
497  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_SET_REPARSE_POINT, rdb, (ULONG)rdblen, nullptr, 0);
498  if (!NT_SUCCESS(Status)) {
499  free(rdb);
501  }
502 
503  free(rdb);
504 
505  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
506 
507  bsii.mode_changed = true;
508  bsii.st_mode = 0777;
509 
510  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
511  if (!NT_SUCCESS(Status))
513  } else if (cmd->cmd == BTRFS_SEND_CMD_MKNOD || cmd->cmd == BTRFS_SEND_CMD_MKFIFO || cmd->cmd == BTRFS_SEND_CMD_MKSOCK) {
514  uint64_t* mode;
515  ULONG modelen;
516 
517  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_MODE, (void**)&mode, &modelen)) {
519 
520  if (modelen < sizeof(uint64_t))
521  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"mode", modelen, sizeof(uint64_t));
522 
525  if (h == INVALID_HANDLE_VALUE)
527 
528  memset(&bsii, 0, sizeof(btrfs_set_inode_info));
529 
530  bsii.mode_changed = true;
531  bsii.st_mode = (uint32_t)*mode;
532 
533  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_INODE_INFO, &bsii, sizeof(btrfs_set_inode_info), nullptr, 0);
534  if (!NT_SUCCESS(Status))
536  }
537  }
538 }
#define IDS_RECV_MKNOD_FAILED
Definition: resource.h:141
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
uint16_t namelen
Definition: btrfsioctl.h:239
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
#define BTRFS_TYPE_SOCKET
Definition: shellext.h:90
Definition: ftp_var.h:139
HANDLE dir
Definition: recv.h:77
#define BTRFS_TYPE_BLOCKDEV
Definition: shellext.h:88
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
#define BTRFS_TYPE_FIFO
Definition: shellext.h:89
#define IDS_RECV_SETINODEINFO_FAILED
Definition: resource.h:150
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
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)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define uint16_t
Definition: nsiface.idl:60
#define BTRFS_TYPE_CHARDEV
Definition: shellext.h:87
GLint namelen
Definition: glext.h:7232
#define BTRFS_SEND_TLV_INODE
Definition: btrfs.h:558
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
Definition: fs.h:78
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
#define BTRFS_SEND_CMD_MKFIFO
Definition: btrfs.h:538
WCHAR PathBuffer[1]
Definition: shellext.h:176
#define GENERIC_WRITE
Definition: nt_native.h:90
#define BTRFS_TYPE_DIRECTORY
Definition: shellext.h:86
#define offsetof(TYPE, MEMBER)
#define BTRFS_SEND_CMD_MKSOCK
Definition: btrfs.h:539
#define OPEN_EXISTING
Definition: compat.h:435
#define BTRFS_SEND_TLV_PATH_LINK
Definition: btrfs.h:572
#define IDS_RECV_SET_REPARSE_POINT_FAILED
Definition: resource.h:142
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define WRITE_DAC
Definition: nt_native.h:59
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
#define BTRFS_SEND_TLV_RDEV
Definition: btrfs.h:563
USHORT ReparseDataLength
Definition: shellext.h:166
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_SEND_CMD_MKNOD
Definition: btrfs.h:537
#define FSCTL_BTRFS_MKNOD
Definition: btrfsioctl.h:30
struct _REPARSE_DATA_BUFFER::@311::@313 SymbolicLinkReparseBuffer
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define FSCTL_BTRFS_SET_INODE_INFO
Definition: btrfsioctl.h:11
GLenum mode
Definition: glext.h:6217
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
#define SYMLINK_FLAG_RELATIVE
Definition: shellext.h:193
Status
Definition: gdiplustypes.h:24
#define S_IFCHR
Definition: ext2fs.h:359
uint64_t st_rdev
Definition: btrfsioctl.h:238
uint8_t type
Definition: btrfsioctl.h:237
#define BTRFS_SEND_TLV_MODE
Definition: btrfs.h:560
UINT64 uint64_t
Definition: types.h:77
#define CreateFileW
Definition: compat.h:409
#define BTRFS_TYPE_FILE
Definition: shellext.h:85
uint64_t inode
Definition: btrfsioctl.h:236
Definition: name.c:38
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
WCHAR name[1]
Definition: btrfsioctl.h:240
#define BTRFS_SEND_CMD_MKDIR
Definition: btrfs.h:536
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define FSCTL_SET_REPARSE_POINT
Definition: winioctl.h:98
#define uint32_t
Definition: nsiface.idl:61
#define memset(x, y, z)
Definition: compat.h:39
#define IO_REPARSE_TAG_SYMLINK
Definition: iotypes.h:6884
wstring subvolpath
Definition: recv.h:79
#define IDS_RECV_PATH_TOO_LONG
Definition: resource.h:208
#define BTRFS_SEND_CMD_SYMLINK
Definition: btrfs.h:540
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by do_recv().

◆ cmd_removexattr()

void BtrfsRecv::cmd_removexattr ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 744 of file recv.cpp.

744  {
745  wstring pathu;
746  string xattrname;
747 
748  {
749  char* path;
750  ULONG pathlen;
751 
752  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
754 
755  pathu = utf8_to_utf16(string(path, pathlen));
756  }
757 
758  {
759  char* xattrnamebuf;
760  ULONG xattrnamelen;
761 
762  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_NAME, (void**)&xattrnamebuf, &xattrnamelen))
763  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"xattr_name");
764 
765  xattrname = string(xattrnamebuf, xattrnamelen);
766  }
767 
768  if (xattrname.length() > XATTR_USER.length() && xattrname.substr(0, XATTR_USER.length()) == XATTR_USER && xattrname != EA_DOSATTRIB && xattrname != EA_EA) { // deleting stream
769  ULONG att;
770 
771  auto streamname = utf8_to_utf16(xattrname);
772 
773  streamname = streamname.substr(XATTR_USER.length());
774 
775  att = GetFileAttributesW((subvolpath + pathu).c_str());
776  if (att == INVALID_FILE_ATTRIBUTES)
778 
779  if (att & FILE_ATTRIBUTE_READONLY) {
780  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
782  }
783 
784  if (!DeleteFileW((subvolpath + pathu + L":" + streamname).c_str()))
785  throw string_error(IDS_RECV_DELETEFILE_FAILED, (pathu + L":" + streamname).c_str(), GetLastError(), format_message(GetLastError()).c_str());
786 
787  if (att & FILE_ATTRIBUTE_READONLY) {
788  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att))
790  }
791  } else {
795  btrfs_set_xattr* bsxa;
796 
797  if (xattrname == EA_NTACL)
798  perms |= WRITE_DAC | WRITE_OWNER;
799  else if (xattrname == EA_EA)
800  perms |= FILE_WRITE_EA;
801 
804  if (h == INVALID_HANDLE_VALUE)
806 
807  size_t bsxalen = offsetof(btrfs_set_xattr, data[0]) + xattrname.length();
808  bsxa = (btrfs_set_xattr*)malloc(bsxalen);
809  if (!bsxa)
811 
812  bsxa->namelen = (uint16_t)(xattrname.length());
813  bsxa->valuelen = 0;
814  memcpy(bsxa->data, xattrname.c_str(), xattrname.length());
815 
816  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_XATTR, bsxa, (ULONG)bsxalen, nullptr, 0);
817  if (!NT_SUCCESS(Status)) {
818  free(bsxa);
820  }
821 
822  free(bsxa);
823  }
824 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
#define FILE_WRITE_EA
Definition: nt_native.h:640
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define IDS_OUT_OF_MEMORY
Definition: resource.h:63
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)
#define BTRFS_SEND_TLV_XATTR_NAME
Definition: btrfs.h:568
#define WRITE_OWNER
Definition: nt_native.h:60
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define uint16_t
Definition: nsiface.idl:60
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define offsetof(TYPE, MEMBER)
#define OPEN_EXISTING
Definition: compat.h:435
const string EA_NTACL
Definition: recv.cpp:37
#define IDS_RECV_SETXATTR_FAILED
Definition: resource.h:161
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define WRITE_DAC
Definition: nt_native.h:59
const string EA_DOSATTRIB
Definition: recv.cpp:38
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const string XATTR_USER
Definition: recv.cpp:41
#define IDS_RECV_DELETEFILE_FAILED
Definition: resource.h:170
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
char string[160]
Definition: util.h:11
Status
Definition: gdiplustypes.h:24
const string EA_EA
Definition: recv.cpp:40
#define CreateFileW
Definition: compat.h:409
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FSCTL_BTRFS_SET_XATTR
Definition: btrfsioctl.h:33
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_rename()

void BtrfsRecv::cmd_rename ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 540 of file recv.cpp.

540  {
541  wstring pathu, path_tou;
542 
543  {
544  char* path;
545  ULONG path_len;
546 
547  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &path_len))
549 
550  pathu = utf8_to_utf16(string(path, path_len));
551  }
552 
553  {
554  char* path_to;
555  ULONG path_to_len;
556 
557  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH_TO, (void**)&path_to, &path_to_len))
558  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"path_to");
559 
560  path_tou = utf8_to_utf16(string(path_to, path_to_len));
561  }
562 
563  if (!MoveFileW((subvolpath + pathu).c_str(), (subvolpath + path_tou).c_str()))
564  throw string_error(IDS_RECV_MOVEFILE_FAILED, pathu.c_str(), path_tou.c_str(), GetLastError(), format_message(GetLastError()).c_str());
565 }
#define BTRFS_SEND_TLV_PATH_TO
Definition: btrfs.h:571
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
BOOL WINAPI MoveFileW(IN LPCWSTR lpExistingFileName, IN LPCWSTR lpNewFileName)
Definition: move.c:1044
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
static DWORD path_len
Definition: batch.c:31
#define IDS_RECV_MOVEFILE_FAILED
Definition: resource.h:143
unsigned int ULONG
Definition: retypes.h:1
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_rmdir()

void BtrfsRecv::cmd_rmdir ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 621 of file recv.cpp.

621  {
622  wstring pathu;
623  ULONG att;
624 
625  {
626  char* path;
627  ULONG pathlen;
628 
629  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
631 
632  pathu = utf8_to_utf16(string(path, pathlen));
633  }
634 
635  att = GetFileAttributesW((subvolpath + pathu).c_str());
636  if (att == INVALID_FILE_ATTRIBUTES)
638 
639  if (att & FILE_ATTRIBUTE_READONLY) {
640  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
642  }
643 
644  if (!RemoveDirectoryW((subvolpath + pathu).c_str()))
646 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
#define IDS_RECV_REMOVEDIRECTORY_FAILED
Definition: resource.h:171
BOOL WINAPI RemoveDirectoryW(IN LPCWSTR lpPathName)
Definition: dir.c:732
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
unsigned int ULONG
Definition: retypes.h:1
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_setxattr()

void BtrfsRecv::cmd_setxattr ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 648 of file recv.cpp.

648  {
649  string xattrname;
650  uint8_t* xattrdata;
651  ULONG xattrdatalen;
652  wstring pathu;
653 
654  {
655  char* path;
656  ULONG pathlen;
657 
658  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
660 
661  pathu = utf8_to_utf16(string(path, pathlen));
662  }
663 
664  {
665  char* xattrnamebuf;
666  ULONG xattrnamelen;
667 
668  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_NAME, (void**)&xattrnamebuf, &xattrnamelen))
669  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"xattr_name");
670 
671  xattrname = string(xattrnamebuf, xattrnamelen);
672  }
673 
674  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_XATTR_DATA, (void**)&xattrdata, &xattrdatalen))
675  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"xattr_data");
676 
677  if (xattrname.length() > XATTR_USER.length() && xattrname.substr(0, XATTR_USER.length()) == XATTR_USER &&
678  xattrname != EA_DOSATTRIB && xattrname != EA_EA && xattrname != EA_REPARSE) {
679  ULONG att;
680 
681  auto streamname = utf8_to_utf16(xattrname);
682 
683  att = GetFileAttributesW((subvolpath + pathu).c_str());
684  if (att == INVALID_FILE_ATTRIBUTES)
686 
687  if (att & FILE_ATTRIBUTE_READONLY) {
688  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
690  }
691 
692  streamname = streamname.substr(XATTR_USER.length());
693 
694  win_handle h = CreateFileW((subvolpath + pathu + L":" + streamname).c_str(), GENERIC_WRITE, 0,
695  nullptr, CREATE_ALWAYS, FILE_FLAG_POSIX_SEMANTICS, nullptr);
696  if (h == INVALID_HANDLE_VALUE)
697  throw string_error(IDS_RECV_CANT_CREATE_FILE, (pathu + L":" + streamname).c_str(), GetLastError(), format_message(GetLastError()).c_str());
698 
699  if (xattrdatalen > 0) {
700  if (!WriteFile(h, xattrdata, xattrdatalen, nullptr, nullptr))
702  }
703 
704  if (att & FILE_ATTRIBUTE_READONLY) {
705  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att))
707  }
708  } else {
712  btrfs_set_xattr* bsxa;
713 
714  if (xattrname == EA_NTACL)
715  perms |= WRITE_DAC | WRITE_OWNER;
716  else if (xattrname == EA_EA)
717  perms |= FILE_WRITE_EA;
718 
721  if (h == INVALID_HANDLE_VALUE)
723 
724  size_t bsxalen = offsetof(btrfs_set_xattr, data[0]) + xattrname.length() + xattrdatalen;
725  bsxa = (btrfs_set_xattr*)malloc(bsxalen);
726  if (!bsxa)
728 
729  bsxa->namelen = (uint16_t)xattrname.length();
730  bsxa->valuelen = (uint16_t)xattrdatalen;
731  memcpy(bsxa->data, xattrname.c_str(), xattrname.length());
732  memcpy(&bsxa->data[xattrname.length()], xattrdata, xattrdatalen);
733 
734  Status = NtFsControlFile(h, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_SET_XATTR, bsxa, (ULONG)bsxalen, nullptr, 0);
735  if (!NT_SUCCESS(Status)) {
736  free(bsxa);
738  }
739 
740  free(bsxa);
741  }
742 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
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
#define FILE_WRITE_EA
Definition: nt_native.h:640
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
#define free
Definition: debug_ros.c:5
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define IDS_OUT_OF_MEMORY
Definition: resource.h:63
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)
#define BTRFS_SEND_TLV_XATTR_NAME
Definition: btrfs.h:568
#define WRITE_OWNER
Definition: nt_native.h:60
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define uint16_t
Definition: nsiface.idl:60
#define BTRFS_SEND_TLV_XATTR_DATA
Definition: btrfs.h:569
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
#define FILE_SHARE_READ
Definition: compat.h:125
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define GENERIC_WRITE
Definition: nt_native.h:90
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
#define offsetof(TYPE, MEMBER)
#define OPEN_EXISTING
Definition: compat.h:435
const string EA_NTACL
Definition: recv.cpp:37
#define IDS_RECV_SETXATTR_FAILED
Definition: resource.h:161
#define IDS_RECV_WRITEFILE_FAILED
Definition: resource.h:145
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define WRITE_DAC
Definition: nt_native.h:59
const string EA_DOSATTRIB
Definition: recv.cpp:38
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
const string XATTR_USER
Definition: recv.cpp:41
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
BYTE uint8_t
Definition: msvideo1.c:66
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
char string[160]
Definition: util.h:11
Status
Definition: gdiplustypes.h:24
#define IDS_RECV_CANT_CREATE_FILE
Definition: resource.h:148
#define CREATE_ALWAYS
Definition: disk.h:72
const string EA_EA
Definition: recv.cpp:40
const string EA_REPARSE
Definition: recv.cpp:39
#define CreateFileW
Definition: compat.h:409
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define FSCTL_BTRFS_SET_XATTR
Definition: btrfsioctl.h:33
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_snapshot()

void BtrfsRecv::cmd_snapshot ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data,
const win_handle parent 
)
private

Definition at line 267 of file recv.cpp.

267  {
268  string name;
269  BTRFS_UUID *uuid, *parent_uuid;
270  uint64_t *gen, *parent_transid;
271  ULONG uuidlen, genlen, paruuidlen, partransidlen;
275  wstring parpath;
276  btrfs_find_subvol bfs;
277  WCHAR parpathw[MAX_PATH], volpathw[MAX_PATH];
278  size_t bcslen;
279 
280  {
281  char* namebuf;
282  ULONG namelen;
283 
284  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&namebuf, &namelen))
286 
287  name = string(namebuf, namelen);
288  }
289 
290  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_UUID, (void**)&uuid, &uuidlen))
292 
293  if (uuidlen < sizeof(BTRFS_UUID))
294  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"uuid", uuidlen, sizeof(BTRFS_UUID));
295 
296  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_TRANSID, (void**)&gen, &genlen))
297  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"transid");
298 
299  if (genlen < sizeof(uint64_t))
300  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"transid", genlen, sizeof(uint64_t));
301 
302  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_UUID, (void**)&parent_uuid, &paruuidlen))
303  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_uuid");
304 
305  if (paruuidlen < sizeof(BTRFS_UUID))
306  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_uuid", paruuidlen, sizeof(BTRFS_UUID));
307 
308  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_CLONE_CTRANSID, (void**)&parent_transid, &partransidlen))
309  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"clone_ctransid");
310 
311  if (partransidlen < sizeof(uint64_t))
312  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"clone_ctransid", partransidlen, sizeof(uint64_t));
313 
314  this->subvol_uuid = *uuid;
315  this->stransid = *gen;
316 
317  auto nameu = utf8_to_utf16(name);
318 
319  bfs.uuid = *parent_uuid;
320  bfs.ctransid = *parent_transid;
321 
322  Status = NtFsControlFile(parent, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_FIND_SUBVOL, &bfs, sizeof(btrfs_find_subvol),
323  parpathw, sizeof(parpathw));
324  if (Status == STATUS_NOT_FOUND)
326  else if (!NT_SUCCESS(Status))
328 
329  if (!GetVolumePathNameW(dirpath.c_str(), volpathw, (sizeof(volpathw) / sizeof(WCHAR)) - 1))
331 
332  parpath = volpathw;
333  if (parpath.substr(parpath.length() - 1) == L"\\")
334  parpath = parpath.substr(0, parpath.length() - 1);
335 
336  parpath += parpathw;
337 
338  {
340  nullptr, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, nullptr);
341  if (subvol == INVALID_HANDLE_VALUE)
342  throw string_error(IDS_RECV_CANT_OPEN_PATH, parpath.c_str(), GetLastError(), format_message(GetLastError()).c_str());
343 
344  bcslen = offsetof(btrfs_create_snapshot, name[0]) + (nameu.length() * sizeof(WCHAR));
345  bcs = (btrfs_create_snapshot*)malloc(bcslen);
346 
347  bcs->readonly = true;
348  bcs->posix = true;
349  bcs->subvol = subvol;
350  bcs->namelen = (uint16_t)(nameu.length() * sizeof(WCHAR));
351  memcpy(bcs->name, nameu.c_str(), bcs->namelen);
352 
353  Status = NtFsControlFile(parent, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_CREATE_SNAPSHOT, bcs, (ULONG)bcslen, nullptr, 0);
354  if (!NT_SUCCESS(Status))
356  }
357 
359  subvolpath += L"\\";
360  subvolpath += nameu;
361 
362  if (dir != INVALID_HANDLE_VALUE)
363  CloseHandle(dir);
364 
367 
372 
373  Status = NtFsControlFile(master, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESERVE_SUBVOL, bcs, (ULONG)bcslen, nullptr, 0);
374  if (!NT_SUCCESS(Status))
376 
380  if (dir == INVALID_HANDLE_VALUE)
382 
383  subvolpath += L"\\";
384 
385  add_cache_entry(&this->subvol_uuid, this->stransid, subvolpath);
386 
387  num_received++;
388 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
ULONG num_received
Definition: recv.h:81
#define IDS_RECV_CANT_FIND_PARENT_SUBVOL
Definition: resource.h:166
#define CloseHandle
Definition: compat.h:407
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
HANDLE dir
Definition: recv.h:77
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
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)
BOOL WINAPI GetVolumePathNameW(IN LPCWSTR lpszFileName, IN LPWSTR lpszVolumePathName, IN DWORD cchBufferLength)
Definition: volume.c:815
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define uint16_t
Definition: nsiface.idl:60
GLint namelen
Definition: glext.h:7232
#define FILE_SHARE_READ
Definition: compat.h:125
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
#define FILE_TRAVERSE
Definition: nt_native.h:643
BTRFS_UUID subvol_uuid
Definition: recv.h:83
#define FILE_ADD_FILE
Definition: nt_native.h:632
#define BTRFS_SEND_TLV_TRANSID
Definition: btrfs.h:557
#define FSCTL_BTRFS_CREATE_SNAPSHOT
Definition: btrfsioctl.h:9
BTRFS_UUID uuid
Definition: btrfsioctl.h:262
#define offsetof(TYPE, MEMBER)
#define OPEN_EXISTING
Definition: compat.h:435
#define STATUS_NOT_FOUND
Definition: shellext.h:72
#define IDS_RECV_FIND_SUBVOL_FAILED
Definition: resource.h:167
r parent
Definition: btrfs.c:2944
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FSCTL_BTRFS_RESERVE_SUBVOL
Definition: btrfsioctl.h:34
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define MAX_PATH
Definition: compat.h:26
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
wstring dirpath
Definition: recv.h:79
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
#define FSCTL_BTRFS_FIND_SUBVOL
Definition: btrfsioctl.h:35
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define GENERIC_READ
Definition: compat.h:124
HANDLE master
Definition: recv.h:77
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
char string[160]
Definition: util.h:11
Status
Definition: gdiplustypes.h:24
#define BTRFS_SEND_TLV_CLONE_UUID
Definition: btrfs.h:575
UINT64 uint64_t
Definition: types.h:77
uint64_t stransid
Definition: recv.h:82
#define IDS_RECV_CREATE_SNAPSHOT_FAILED
Definition: resource.h:168
#define CreateFileW
Definition: compat.h:409
#define IDS_RECV_CANT_OPEN_PATH
Definition: resource.h:136
Definition: name.c:38
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
Definition: msctf.idl:510
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define BTRFS_SEND_TLV_CLONE_CTRANSID
Definition: btrfs.h:576
#define IDS_RECV_RESERVE_SUBVOL_FAILED
Definition: resource.h:164
#define BTRFS_SEND_TLV_UUID
Definition: btrfs.h:556
void add_cache_entry(BTRFS_UUID *uuid, uint64_t transid, const wstring &path)
Definition: recv.cpp:257
uint64_t ctransid
Definition: btrfsioctl.h:263
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155
#define IDS_RECV_GETVOLUMEPATHNAME_FAILED
Definition: resource.h:169
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by do_recv().

◆ cmd_subvol()

void BtrfsRecv::cmd_subvol ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data,
const win_handle parent 
)
private

Definition at line 177 of file recv.cpp.

177  {
178  string name;
179  BTRFS_UUID* uuid;
180  uint64_t* gen;
181  ULONG uuidlen, genlen;
182  btrfs_create_subvol* bcs;
185 
186  {
187  char* namebuf;
188  ULONG namelen;
189 
190  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&namebuf, &namelen))
192 
193  name = string(namebuf, namelen);
194  }
195 
196  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_UUID, (void**)&uuid, &uuidlen))
198 
199  if (uuidlen < sizeof(BTRFS_UUID))
200  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"uuid", uuidlen, sizeof(BTRFS_UUID));
201 
202  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_TRANSID, (void**)&gen, &genlen))
203  throw string_error(IDS_RECV_MISSING_PARAM, funcname, L"transid");
204 
205  if (genlen < sizeof(uint64_t))
206  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"transid", genlen, sizeof(uint64_t));
207 
208  this->subvol_uuid = *uuid;
209  this->stransid = *gen;
210 
211  auto nameu = utf8_to_utf16(name);
212 
213  size_t bcslen = offsetof(btrfs_create_subvol, name[0]) + (nameu.length() * sizeof(WCHAR));
214  bcs = (btrfs_create_subvol*)malloc(bcslen);
215 
216  bcs->readonly = true;
217  bcs->posix = true;
218  bcs->namelen = (uint16_t)(nameu.length() * sizeof(WCHAR));
219  memcpy(bcs->name, nameu.c_str(), bcs->namelen);
220 
221  Status = NtFsControlFile(parent, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_CREATE_SUBVOL, bcs, (ULONG)bcslen, nullptr, 0);
222  if (!NT_SUCCESS(Status))
224 
226  subvolpath += L"\\";
227  subvolpath += nameu;
228 
229  if (dir != INVALID_HANDLE_VALUE)
230  CloseHandle(dir);
231 
234 
239 
240  Status = NtFsControlFile(master, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RESERVE_SUBVOL, bcs, (ULONG)bcslen, nullptr, 0);
241  if (!NT_SUCCESS(Status))
243 
247  if (dir == INVALID_HANDLE_VALUE)
249 
250  subvolpath += L"\\";
251 
252  add_cache_entry(&this->subvol_uuid, this->stransid, subvolpath);
253 
254  num_received++;
255 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
ULONG num_received
Definition: recv.h:81
#define CloseHandle
Definition: compat.h:407
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
HANDLE dir
Definition: recv.h:77
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
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)
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define uint16_t
Definition: nsiface.idl:60
GLint namelen
Definition: glext.h:7232
#define FILE_SHARE_READ
Definition: compat.h:125
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
BTRFS_UUID subvol_uuid
Definition: recv.h:83
#define FILE_ADD_FILE
Definition: nt_native.h:632
#define BTRFS_SEND_TLV_TRANSID
Definition: btrfs.h:557
#define offsetof(TYPE, MEMBER)
#define OPEN_EXISTING
Definition: compat.h:435
#define FSCTL_BTRFS_CREATE_SUBVOL
Definition: btrfsioctl.h:8
r parent
Definition: btrfs.c:2944
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define FSCTL_BTRFS_RESERVE_SUBVOL
Definition: btrfsioctl.h:34
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define IDS_RECV_CREATE_SUBVOL_FAILED
Definition: resource.h:138
wstring dirpath
Definition: recv.h:79
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
static const WCHAR L[]
Definition: oid.c:1250
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define GENERIC_READ
Definition: compat.h:124
HANDLE master
Definition: recv.h:77
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
char string[160]
Definition: util.h:11
Status
Definition: gdiplustypes.h:24
UINT64 uint64_t
Definition: types.h:77
uint64_t stransid
Definition: recv.h:82
#define CreateFileW
Definition: compat.h:409
#define IDS_RECV_CANT_OPEN_PATH
Definition: resource.h:136
Definition: name.c:38
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
Definition: msctf.idl:510
unsigned int ULONG
Definition: retypes.h:1
#define malloc
Definition: debug_ros.c:4
#define IDS_RECV_RESERVE_SUBVOL_FAILED
Definition: resource.h:164
#define BTRFS_SEND_TLV_UUID
Definition: btrfs.h:556
void add_cache_entry(BTRFS_UUID *uuid, uint64_t transid, const wstring &path)
Definition: recv.cpp:257
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155
GLuint const GLchar * name
Definition: glext.h:6031

Referenced by do_recv().

◆ cmd_truncate()

void BtrfsRecv::cmd_truncate ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 1036 of file recv.cpp.

1036  {
1037  uint64_t* size;
1038  ULONG sizelen;
1039  wstring pathu;
1040  LARGE_INTEGER sizeli;
1041  DWORD att;
1042 
1043  {
1044  char* path;
1045  ULONG pathlen;
1046 
1047  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
1049 
1050  pathu = utf8_to_utf16(string(path, pathlen));
1051  }
1052 
1053  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_SIZE, (void**)&size, &sizelen))
1055 
1056  if (sizelen < sizeof(uint64_t))
1057  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"size", sizelen, sizeof(uint64_t));
1058 
1059  att = GetFileAttributesW((subvolpath + pathu).c_str());
1060  if (att == INVALID_FILE_ATTRIBUTES)
1062 
1063  if (att & FILE_ATTRIBUTE_READONLY) {
1064  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
1066  }
1067 
1068  {
1069  win_handle h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_DATA, 0, nullptr, OPEN_EXISTING,
1071 
1072  if (h == INVALID_HANDLE_VALUE)
1074 
1075  sizeli.QuadPart = *size;
1076 
1079 
1080  if (!SetEndOfFile(h))
1082  }
1083 
1084  if (att & FILE_ATTRIBUTE_READONLY) {
1085  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att))
1087  }
1088 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
BOOL WINAPI SetEndOfFile(HANDLE hFile)
Definition: fileinfo.c:1154
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define OPEN_EXISTING
Definition: compat.h:435
#define BTRFS_SEND_TLV_SIZE
Definition: btrfs.h:559
GLsizeiptr size
Definition: glext.h:5919
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
unsigned long DWORD
Definition: ntddk_ex.h:95
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_RECV_SETFILEPOINTER_FAILED
Definition: resource.h:144
ULONG LowPart
Definition: typedefs.h:105
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
#define FILE_BEGIN
Definition: winbase.h:112
UINT64 uint64_t
Definition: types.h:77
#define CreateFileW
Definition: compat.h:409
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
unsigned int ULONG
Definition: retypes.h:1
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define IDS_RECV_SETENDOFFILE_FAILED
Definition: resource.h:147
wstring subvolpath
Definition: recv.h:79
LONGLONG QuadPart
Definition: typedefs.h:113
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_unlink()

void BtrfsRecv::cmd_unlink ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 594 of file recv.cpp.

594  {
595  wstring pathu;
596  ULONG att;
597 
598  {
599  char* path;
600  ULONG pathlen;
601 
602  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
604 
605  pathu = utf8_to_utf16(string(path, pathlen));
606  }
607 
608  att = GetFileAttributesW((subvolpath + pathu).c_str());
609  if (att == INVALID_FILE_ATTRIBUTES)
611 
612  if (att & FILE_ATTRIBUTE_READONLY) {
613  if (!SetFileAttributesW((subvolpath + pathu).c_str(), att & ~FILE_ATTRIBUTE_READONLY))
615  }
616 
617  if (!DeleteFileW((subvolpath + pathu).c_str()))
619 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
BOOL WINAPI DeleteFileW(IN LPCWSTR lpFileName)
Definition: delete.c:39
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define IDS_RECV_DELETEFILE_FAILED
Definition: resource.h:170
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
unsigned int ULONG
Definition: retypes.h:1
wstring subvolpath
Definition: recv.h:79
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_utimes()

void BtrfsRecv::cmd_utimes ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 1184 of file recv.cpp.

1184  {
1185  wstring pathu;
1186  win_handle h;
1187  FILE_BASIC_INFO fbi;
1188  BTRFS_TIME* time;
1189  ULONG timelen;
1191  NTSTATUS Status;
1192 
1193  {
1194  char* path;
1195  ULONG pathlen;
1196 
1197  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
1199 
1200  pathu = utf8_to_utf16(string(path, pathlen));
1201  }
1202 
1203  h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_ATTRIBUTES, 0, nullptr, OPEN_EXISTING,
1205  if (h == INVALID_HANDLE_VALUE)
1207 
1208  memset(&fbi, 0, sizeof(FILE_BASIC_INFO));
1209 
1210  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_OTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1211  fbi.CreationTime.QuadPart = unix_time_to_win(time);
1212 
1213  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_ATIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1214  fbi.LastAccessTime.QuadPart = unix_time_to_win(time);
1215 
1216  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_MTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1217  fbi.LastWriteTime.QuadPart = unix_time_to_win(time);
1218 
1219  if (find_tlv(data, cmd->length, BTRFS_SEND_TLV_CTIME, (void**)&time, &timelen) && timelen >= sizeof(BTRFS_TIME))
1220  fbi.ChangeTime.QuadPart = unix_time_to_win(time);
1221 
1222  Status = NtSetInformationFile(h, &iosb, &fbi, sizeof(FILE_BASIC_INFO), FileBasicInformation);
1223  if (!NT_SUCCESS(Status))
1224  throw ntstatus_error(Status);
1225 }
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define BTRFS_SEND_TLV_MTIME
Definition: btrfs.h:565
__u16 time
Definition: mkdosfs.c:366
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
#define BTRFS_SEND_TLV_OTIME
Definition: btrfs.h:567
#define OPEN_EXISTING
Definition: compat.h:435
static __inline uint64_t unix_time_to_win(BTRFS_TIME *t)
Definition: recv.cpp:1180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_SEND_TLV_CTIME
Definition: btrfs.h:564
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
Status
Definition: gdiplustypes.h:24
#define CreateFileW
Definition: compat.h:409
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
unsigned int ULONG
Definition: retypes.h:1
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define memset(x, y, z)
Definition: compat.h:39
#define FILE_OPEN_REPARSE_POINT
Definition: from_kernel.h:46
wstring subvolpath
Definition: recv.h:79
#define BTRFS_SEND_TLV_ATIME
Definition: btrfs.h:566
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ cmd_write()

void BtrfsRecv::cmd_write ( HWND  hwnd,
btrfs_send_command cmd,
uint8_t data 
)
private

Definition at line 826 of file recv.cpp.

826  {
827  uint64_t* offset;
828  uint8_t* writedata;
829  ULONG offsetlen, datalen;
830  wstring pathu;
831  HANDLE h;
832  LARGE_INTEGER offli;
835 
836  {
837  char* path;
838  ULONG pathlen;
839 
840  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_PATH, (void**)&path, &pathlen))
842 
843  pathu = utf8_to_utf16(string(path, pathlen));
844  }
845 
846  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_OFFSET, (void**)&offset, &offsetlen))
848 
849  if (offsetlen < sizeof(uint64_t))
850  throw string_error(IDS_RECV_SHORT_PARAM, funcname, L"offset", offsetlen, sizeof(uint64_t));
851 
852  if (!find_tlv(data, cmd->length, BTRFS_SEND_TLV_DATA, (void**)&writedata, &datalen))
854 
855  if (lastwritepath != pathu) {
856  FILE_BASIC_INFO fbi;
857 
861  }
862 
864 
865  lastwriteatt = GetFileAttributesW((subvolpath + pathu).c_str());
868 
872  }
873 
874  h = CreateFileW((subvolpath + pathu).c_str(), FILE_WRITE_DATA | FILE_WRITE_ATTRIBUTES, 0, nullptr, OPEN_EXISTING,
876  if (h == INVALID_HANDLE_VALUE)
878 
879  lastwritepath = pathu;
880  lastwritefile = h;
881 
882  memset(&fbi, 0, sizeof(FILE_BASIC_INFO));
883 
884  fbi.LastWriteTime.QuadPart = -1;
885 
886  Status = NtSetInformationFile(h, &iosb, &fbi, sizeof(FILE_BASIC_INFO), FileBasicInformation);
887  if (!NT_SUCCESS(Status))
888  throw ntstatus_error(Status);
889  } else
890  h = lastwritefile;
891 
892  offli.QuadPart = *offset;
893 
896 
897  if (!WriteFile(h, writedata, datalen, nullptr, nullptr))
899 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
#define BTRFS_SEND_TLV_OFFSET
Definition: btrfs.h:573
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
#define CloseHandle
Definition: compat.h:407
#define INVALID_SET_FILE_POINTER
Definition: winbase.h:115
NTSTATUS NTAPI NtSetInformationFile(HANDLE hFile, PIO_STATUS_BLOCK io, PVOID ptr, ULONG len, FILE_INFORMATION_CLASS FileInformationClass)
#define BTRFS_SEND_TLV_DATA
Definition: btrfs.h:574
Definition: ftp_var.h:139
GLsizei const GLchar ** path
Definition: glext.h:7234
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
LONG NTSTATUS
Definition: precomp.h:26
GLintptr offset
Definition: glext.h:5920
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1030
#define FILE_WRITE_ATTRIBUTES
Definition: nt_native.h:649
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define IDS_RECV_SHORT_PARAM
Definition: resource.h:140
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define IDS_RECV_GETFILEATTRIBUTES_FAILED
Definition: resource.h:154
#define FILE_WRITE_DATA
Definition: nt_native.h:631
#define OPEN_EXISTING
Definition: compat.h:435
#define IDS_RECV_WRITEFILE_FAILED
Definition: resource.h:145
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
HANDLE lastwritefile
Definition: recv.h:77
#define INVALID_FILE_ATTRIBUTES
Definition: vfdcmd.c:23
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_TLV_PATH
Definition: btrfs.h:570
static const WCHAR L[]
Definition: oid.c:1250
#define IDS_RECV_SETFILEPOINTER_FAILED
Definition: resource.h:144
ULONG LowPart
Definition: typedefs.h:105
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
BYTE uint8_t
Definition: msvideo1.c:66
#define IDS_RECV_MISSING_PARAM
Definition: resource.h:139
Status
Definition: gdiplustypes.h:24
#define FILE_BEGIN
Definition: winbase.h:112
UINT64 uint64_t
Definition: types.h:77
DWORD lastwriteatt
Definition: recv.h:80
wstring lastwritepath
Definition: recv.h:79
#define CreateFileW
Definition: compat.h:409
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
unsigned int ULONG
Definition: retypes.h:1
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define memset(x, y, z)
Definition: compat.h:39
wstring subvolpath
Definition: recv.h:79
LONGLONG QuadPart
Definition: typedefs.h:113
bool find_tlv(uint8_t *data, ULONG datalen, uint16_t type, void **value, ULONG *len)
Definition: recv.cpp:155

Referenced by do_recv().

◆ do_recv()

void BtrfsRecv::do_recv ( const win_handle f,
uint64_t pos,
uint64_t  size,
const win_handle parent 
)
private

Definition at line 1270 of file recv.cpp.

1270  {
1271  try {
1273  bool ended = false;
1274 
1275  if (!ReadFile(f, &header, sizeof(btrfs_send_header), nullptr, nullptr))
1277 
1278  *pos += sizeof(btrfs_send_header);
1279 
1280  if (memcmp(header.magic, BTRFS_SEND_MAGIC, sizeof(header.magic)))
1282 
1283  if (header.version > 1)
1285 
1287 
1289  lastwritepath = L"";
1290  lastwriteatt = 0;
1291 
1292  while (true) {
1294  uint8_t* data = nullptr;
1295  ULONG progress;
1296 
1297  if (cancelling)
1298  break;
1299 
1300  progress = (ULONG)((float)*pos * 65536.0f / (float)size);
1302 
1303  if (!ReadFile(f, &cmd, sizeof(btrfs_send_command), nullptr, nullptr)) {
1304  if (GetLastError() != ERROR_HANDLE_EOF)
1306 
1307  break;
1308  }
1309 
1310  *pos += sizeof(btrfs_send_command);
1311 
1312  if (cmd.length > 0) {
1313  if (*pos + cmd.length > size)
1315 
1316  data = (uint8_t*)malloc(cmd.length);
1317  if (!data)
1319  }
1320 
1321  try {
1322  if (data) {
1323  if (!ReadFile(f, data, cmd.length, nullptr, nullptr))
1325 
1326  *pos += cmd.length;
1327  }
1328 
1329  if (!check_csum(&cmd, data))
1331 
1332  if (cmd.cmd == BTRFS_SEND_CMD_END) {
1333  ended = true;
1334  break;
1335  }
1336 
1341  }
1342 
1344 
1346  lastwritepath = L"";
1347  lastwriteatt = 0;
1348  }
1349 
1350  switch (cmd.cmd) {
1351  case BTRFS_SEND_CMD_SUBVOL:
1352  cmd_subvol(hwnd, &cmd, data, parent);
1353  break;
1354 
1357  break;
1358 
1359  case BTRFS_SEND_CMD_MKFILE:
1360  case BTRFS_SEND_CMD_MKDIR:
1361  case BTRFS_SEND_CMD_MKNOD:
1362  case BTRFS_SEND_CMD_MKFIFO:
1363  case BTRFS_SEND_CMD_MKSOCK:
1365  cmd_mkfile(hwnd, &cmd, data);
1366  break;
1367 
1368  case BTRFS_SEND_CMD_RENAME:
1369  cmd_rename(hwnd, &cmd, data);
1370  break;
1371 
1372  case BTRFS_SEND_CMD_LINK:
1373  cmd_link(hwnd, &cmd, data);
1374  break;
1375 
1376  case BTRFS_SEND_CMD_UNLINK:
1377  cmd_unlink(hwnd, &cmd, data);
1378  break;
1379 
1380  case BTRFS_SEND_CMD_RMDIR:
1381  cmd_rmdir(hwnd, &cmd, data);
1382  break;
1383 
1385  cmd_setxattr(hwnd, &cmd, data);
1386  break;
1387 
1390  break;
1391 
1392  case BTRFS_SEND_CMD_WRITE:
1393  cmd_write(hwnd, &cmd, data);
1394  break;
1395 
1396  case BTRFS_SEND_CMD_CLONE:
1397  cmd_clone(hwnd, &cmd, data);
1398  break;
1399 
1401  cmd_truncate(hwnd, &cmd, data);
1402  break;
1403 
1404  case BTRFS_SEND_CMD_CHMOD:
1405  cmd_chmod(hwnd, &cmd, data);
1406  break;
1407 
1408  case BTRFS_SEND_CMD_CHOWN:
1409  cmd_chown(hwnd, &cmd, data);
1410  break;
1411 
1412  case BTRFS_SEND_CMD_UTIMES:
1413  cmd_utimes(hwnd, &cmd, data);
1414  break;
1415 
1417  // does nothing
1418  break;
1419 
1420  default:
1422  }
1423  } catch (...) {
1424  if (data) free(data);
1425  throw;
1426  }
1427 
1428  if (data) free(data);
1429  }
1430 
1435  }
1436 
1438  }
1439 
1440  if (!ended && !cancelling)
1442 
1443  if (!cancelling) {
1444  NTSTATUS Status;
1447 
1448  brs.generation = stransid;
1449  brs.uuid = subvol_uuid;
1450 
1451  Status = NtFsControlFile(dir, nullptr, nullptr, nullptr, &iosb, FSCTL_BTRFS_RECEIVED_SUBVOL, &brs, sizeof(btrfs_received_subvol),
1452  nullptr, 0);
1453  if (!NT_SUCCESS(Status))
1455  }
1456 
1457  CloseHandle(dir);
1458 
1461  } catch (...) {
1462  if (subvolpath != L"") {
1463  ULONG attrib;
1464 
1465  attrib = GetFileAttributesW(subvolpath.c_str());
1466  attrib &= ~FILE_ATTRIBUTE_READONLY;
1467 
1468  if (SetFileAttributesW(subvolpath.c_str(), attrib))
1470  }
1471 
1472  throw;
1473  }
1474 }
BOOL WINAPI SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes)
Definition: fileinfo.c:944
static PIO_STATUS_BLOCK iosb
Definition: file.c:98
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define BTRFS_SEND_CMD_LINK
Definition: btrfs.h:542
#define PBM_SETRANGE32
Definition: commctrl.h:2184
#define IDS_RECV_FILE_TRUNCATED
Definition: resource.h:163
#define CloseHandle
Definition: compat.h:407
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
void cmd_chown(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1130
wstring format_ntstatus(NTSTATUS Status)
Definition: main.cpp:184
Definition: ftp_var.h:139
static void delete_directory(const wstring &dir)
Definition: recv.cpp:1227
HANDLE dir
Definition: recv.h:77
#define IDS_RECV_RECEIVED_SUBVOL_FAILED
Definition: resource.h:159
#define free
Definition: debug_ros.c:5
#define IDS_RECV_CSUM_ERROR
Definition: resource.h:155
LONG NTSTATUS
Definition: precomp.h:26
void cmd_chmod(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1090
#define IDS_RECV_READFILE_FAILED
Definition: resource.h:133
#define BTRFS_SEND_CMD_SET_XATTR
Definition: btrfs.h:545
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
void cmd_snapshot(HWND hwnd, btrfs_send_command *cmd, uint8_t *data, const win_handle &parent)
Definition: recv.cpp:267
#define PBM_SETPOS
Definition: commctrl.h:2180
void cmd_unlink(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:594
char * cmd
Definition: vfdcmd.c:85
#define IDS_OUT_OF_MEMORY
Definition: resource.h:63
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)
#define BTRFS_SEND_CMD_UPDATE_EXTENT
Definition: btrfs.h:554
#define IDS_RECV_UNKNOWN_COMMAND
Definition: resource.h:135
void cmd_truncate(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1036
#define BTRFS_SEND_CMD_UTIMES
Definition: btrfs.h:552
#define BTRFS_SEND_CMD_MKFIFO
Definition: btrfs.h:538
#define IDC_RECV_PROGRESS
Definition: resource.h:264
BTRFS_UUID subvol_uuid
Definition: recv.h:83
#define IDS_RECV_UNSUPPORTED_VERSION
Definition: resource.h:157
#define BTRFS_SEND_CMD_SUBVOL
Definition: btrfs.h:533
DWORD WINAPI GetFileAttributesW(LPCWSTR lpFileName)
Definition: fileinfo.c:802
#define BTRFS_SEND_CMD_TRUNCATE
Definition: btrfs.h:549
void cmd_rmdir(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:621
LONG_PTR LPARAM
Definition: windef.h:208
#define BTRFS_SEND_CMD_MKSOCK
Definition: btrfs.h:539
#define BTRFS_SEND_CMD_CHOWN
Definition: btrfs.h:551
void cmd_clone(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:901
bool cancelling
Definition: recv.h:84
GLfloat f
Definition: glext.h:7540
GLsizeiptr size
Definition: glext.h:5919
r parent
Definition: btrfs.c:2944
#define BTRFS_SEND_CMD_REMOVE_XATTR
Definition: btrfs.h:546
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define IDS_RECV_NOT_A_SEND_STREAM
Definition: resource.h:156
#define FILE_ATTRIBUTE_READONLY
Definition: nt_native.h:702
HANDLE lastwritefile
Definition: recv.h:77
void cmd_mkfile(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:390
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define BTRFS_SEND_CMD_WRITE
Definition: btrfs.h:547
void cmd_utimes(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1184
void cmd_removexattr(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:744
#define BTRFS_SEND_CMD_CLONE
Definition: btrfs.h:548
static const WCHAR L[]
Definition: oid.c:1250
#define BTRFS_SEND_CMD_MKNOD
Definition: btrfs.h:537
void cmd_link(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:567
void cmd_subvol(HWND hwnd, btrfs_send_command *cmd, uint8_t *data, const win_handle &parent)
Definition: recv.cpp:177
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
HANDLE master
Definition: recv.h:77
#define BTRFS_SEND_CMD_END
Definition: btrfs.h:553
BYTE uint8_t
Definition: msvideo1.c:66
#define BTRFS_SEND_CMD_CHMOD
Definition: btrfs.h:550
#define BTRFS_SEND_CMD_RENAME
Definition: btrfs.h:541
Status
Definition: gdiplustypes.h:24
#define BTRFS_SEND_MAGIC
Definition: btrfs.h:581
void cmd_setxattr(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:648
static float(__cdecl *square_half_float)(float x
DWORD lastwriteatt
Definition: recv.h:80
static bool check_csum(btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:1257
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
wstring lastwritepath
Definition: recv.h:79
uint64_t stransid
Definition: recv.h:82
void cmd_rename(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:540
#define BTRFS_SEND_CMD_MKFILE
Definition: btrfs.h:535
#define BTRFS_SEND_CMD_RMDIR
Definition: btrfs.h:544
cd_progress_ptr progress
Definition: cdjpeg.h:152
#define IDS_RECV_SETFILEATTRIBUTES_FAILED
Definition: resource.h:153
#define FSCTL_BTRFS_RECEIVED_SUBVOL
Definition: btrfsioctl.h:31
#define BTRFS_SEND_CMD_MKDIR
Definition: btrfs.h:536
unsigned int ULONG
Definition: retypes.h:1
#define ERROR_HANDLE_EOF
Definition: winerror.h:140
#define malloc
Definition: debug_ros.c:4
#define BTRFS_SEND_CMD_SNAPSHOT
Definition: btrfs.h:534
#define BTRFS_SEND_CMD_UNLINK
Definition: btrfs.h:543
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
struct CFHEADER header
Definition: fdi.c:101
void cmd_write(HWND hwnd, btrfs_send_command *cmd, uint8_t *data)
Definition: recv.cpp:826
wstring subvolpath
Definition: recv.h:79
#define BTRFS_SEND_CMD_SYMLINK
Definition: btrfs.h:540

Referenced by recv_thread().

◆ find_tlv()

bool BtrfsRecv::find_tlv ( uint8_t data,
ULONG  datalen,
uint16_t  type,
void **  value,
ULONG len 
)
private

Definition at line 155 of file recv.cpp.

155  {
156  size_t off = 0;
157 
158  while (off < datalen) {
159  btrfs_send_tlv* tlv = (btrfs_send_tlv*)(data + off);
160  uint8_t* payload = data + off + sizeof(btrfs_send_tlv);
161 
162  if (off + sizeof(btrfs_send_tlv) + tlv->length > datalen) // file is truncated
163  return false;
164 
165  if (tlv->type == type) {
166  *value = payload;
167  *len = tlv->length;
168  return true;
169  }
170 
171  off += sizeof(btrfs_send_tlv) + tlv->length;
172  }
173 
174  return false;
175 }
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
int const JOCTET unsigned int datalen
Definition: jpeglib.h:1030
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum GLsizei len
Definition: glext.h:6722
BYTE uint8_t
Definition: msvideo1.c:66
uint16_t type
Definition: btrfs.h:595
uint16_t length
Definition: btrfs.h:596
off
Definition: i386-dis.c:3909

Referenced by cmd_chmod(), cmd_chown(), cmd_clone(), cmd_link(), cmd_mkfile(), cmd_removexattr(), cmd_rename(), cmd_rmdir(), cmd_setxattr(), cmd_snapshot(), cmd_subvol(), cmd_truncate(), cmd_unlink(), cmd_utimes(), and cmd_write().

◆ Open()

void BtrfsRecv::Open ( HWND  hwnd,
const wstring &  file,
const wstring &  path,
bool  quiet 
)

Definition at line 1614 of file recv.cpp.

1614  {
1615 #ifndef __REACTOS__
1616  uint32_t cpuInfo[4];
1617 #endif
1618 
1619  streamfile = file;
1620  dirpath = path;
1621  subvolpath = L"";
1622 
1623 #ifndef __REACTOS__
1624 #ifndef _MSC_VER
1625  __get_cpuid(1, &cpuInfo[0], &cpuInfo[1], &cpuInfo[2], &cpuInfo[3]);
1626  have_sse42 = cpuInfo[2] & bit_SSE4_2;
1627 #else
1628  __cpuid((int*)cpuInfo, 1);
1629  have_sse42 = cpuInfo[2] & (1 << 20);
1630 #endif
1631 #endif
1632 
1633  if (quiet)
1634  recv_thread();
1635  else {
1637  throw last_error(GetLastError());
1638  }
1639 }
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
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
DWORD recv_thread()
Definition: recv.cpp:1476
LONG_PTR LPARAM
Definition: windef.h:208
wstring streamfile
Definition: recv.h:79
#define IDD_RECV_PROGRESS
Definition: resource.h:86
bool have_sse42
Definition: recv.cpp:44
const char file[]
Definition: icontest.c:11
wstring dirpath
Definition: recv.h:79
static INT_PTR CALLBACK stub_RecvProgressDlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: recv.cpp:1598
static const WCHAR L[]
Definition: oid.c:1250
PPC_QUAL void __cpuid(int CPUInfo[], const int InfoType)
Definition: intrin_ppc.h:682
UINT32 uint32_t
Definition: types.h:75
#define MAKEINTRESOURCEW(i)
Definition: winuser.h:582
wstring subvolpath
Definition: recv.h:79

Referenced by RecvSubvolW().

◆ recv_thread()

DWORD BtrfsRecv::recv_thread ( )

Definition at line 1476 of file recv.cpp.

1476  {
1478  uint64_t pos = 0;
1479  bool b = true;
1480 
1481  running = true;
1482 
1483  try {
1484  win_handle f = CreateFileW(streamfile.c_str(), GENERIC_READ, 0, nullptr, OPEN_EXISTING, 0, nullptr);
1485  if (f == INVALID_HANDLE_VALUE)
1487 
1488  if (!GetFileSizeEx(f, &size))
1490 
1491  {
1496 
1497  do {
1498  do_recv(f, &pos, size.QuadPart, parent);
1499  } while (pos < (uint64_t)size.QuadPart);
1500  }
1501  } catch (const exception& e) {
1502  auto msg = utf8_to_utf16(e.what());
1503 
1504  SetDlgItemTextW(hwnd, IDC_RECV_MSG, msg.c_str());
1505 
1506  SendMessageW(GetDlgItem(hwnd, IDC_RECV_PROGRESS), PBM_SETSTATE, PBST_ERROR, 0);
1507 
1508  b = false;
1509  }
1510 
1511  if (b && hwnd) {
1512  wstring s;
1513 
1515 
1516  if (num_received == 1) {
1518  SetDlgItemTextW(hwnd, IDC_RECV_MSG, s.c_str());
1519  } else {
1520  wstring t;
1521 
1523 
1525 
1526  SetDlgItemTextW(hwnd, IDC_RECV_MSG, t.c_str());
1527  }
1528 
1530 
1531  SetDlgItemTextW(hwnd, IDCANCEL, s.c_str());
1532  }
1533 
1534  thread = nullptr;
1535  running = false;
1536 
1537  return 0;
1538 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
ULONG num_received
Definition: recv.h:81
#define IDS_RECV_GETFILESIZEEX_FAILED
Definition: resource.h:173
bool running
Definition: recv.h:84
#define FILE_FLAG_POSIX_SEMANTICS
Definition: disk.h:40
#define IDS_RECV_SUCCESS_PLURAL
Definition: resource.h:175
GLdouble GLdouble t
Definition: gl.h:2047
#define INVALID_HANDLE_VALUE
Definition: compat.h:400
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define PBM_SETPOS
Definition: commctrl.h:2180
#define FILE_SHARE_WRITE
Definition: nt_native.h:681
#define FILE_SHARE_READ
Definition: compat.h:125
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define IDC_RECV_PROGRESS
Definition: resource.h:264
#define FILE_ADD_FILE
Definition: nt_native.h:632
void do_recv(const win_handle &f, uint64_t *pos, uint64_t size, const win_handle &parent)
Definition: recv.cpp:1270
#define e
Definition: ke_i.h:82
wstring streamfile
Definition: recv.h:79
#define IDS_RECV_BUTTON_OK
Definition: resource.h:152
#define OPEN_EXISTING
Definition: compat.h:435
#define IDS_RECV_SUCCESS
Definition: resource.h:151
void wstring_sprintf(wstring &s, wstring fmt,...)
Definition: main.cpp:225
GLfloat f
Definition: glext.h:7540
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLsizeiptr size
Definition: glext.h:5919
r parent
Definition: btrfs.c:2944
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HANDLE thread
Definition: recv.h:77
#define funcname
Definition: shellext.h:96
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
wstring dirpath
Definition: recv.h:79
#define GetFileSizeEx
Definition: compat.h:423
#define FILE_SHARE_DELETE
Definition: nt_native.h:682
#define FILE_ADD_SUBDIRECTORY
Definition: nt_native.h:635
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
GLdouble s
Definition: gl.h:2039
#define GENERIC_READ
Definition: compat.h:124
UINT64 uint64_t
Definition: types.h:77
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 CreateFileW
Definition: compat.h:409
#define msg(x)
Definition: auth_time.c:54
#define IDS_RECV_CANT_OPEN_PATH
Definition: resource.h:136
#define FILE_FLAG_BACKUP_SEMANTICS
Definition: disk.h:41
#define IDS_RECV_CANT_OPEN_FILE
Definition: resource.h:132
#define IDCANCEL
Definition: winuser.h:825
#define IDC_RECV_MSG
Definition: resource.h:325

Referenced by global_recv_thread(), and Open().

◆ RecvProgressDlgProc()

INT_PTR CALLBACK BtrfsRecv::RecvProgressDlgProc ( HWND  hwndDlg,
UINT  uMsg,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 1546 of file recv.cpp.

1546  {
1547  switch (uMsg) {
1548  case WM_INITDIALOG:
1549  try {
1550  this->hwnd = hwndDlg;
1551  thread = CreateThread(nullptr, 0, global_recv_thread, this, 0, nullptr);
1552 
1553  if (!thread)
1555  } catch (const exception& e) {
1556  auto msg = utf8_to_utf16(e.what());
1557 
1558  SetDlgItemTextW(hwnd, IDC_RECV_MSG, msg.c_str());
1559 
1560  SendMessageW(GetDlgItem(hwnd, IDC_RECV_PROGRESS), PBM_SETSTATE, PBST_ERROR, 0);
1561  }
1562  break;
1563 
1564  case WM_COMMAND:
1565  switch (HIWORD(wParam)) {
1566  case BN_CLICKED:
1567  switch (LOWORD(wParam)) {
1568  case IDOK:
1569  case IDCANCEL:
1570  if (running) {
1571  wstring s;
1572 
1573  cancelling = true;
1574 
1576  throw last_error(GetLastError());
1577 
1578  SetDlgItemTextW(hwnd, IDC_RECV_MSG, s.c_str());
1580 
1582  throw last_error(GetLastError());
1583 
1584  SetDlgItemTextW(hwnd, IDCANCEL, s.c_str());
1585  } else
1586  EndDialog(hwndDlg, 1);
1587 
1588  return true;
1589  }
1590  break;
1591  }
1592  break;
1593  }
1594 
1595  return false;
1596 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define IDOK
Definition: winuser.h:824
bool running
Definition: recv.h:84
#define IDS_RECV_CANCELLED
Definition: resource.h:165
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define PBM_SETPOS
Definition: commctrl.h:2180
static DWORD WINAPI global_recv_thread(LPVOID lpParameter)
Definition: recv.cpp:1540
BOOL WINAPI EndDialog(_In_ HWND, _In_ INT_PTR)
WPARAM wParam
Definition: combotst.c:138
BOOL WINAPI SetDlgItemTextW(_In_ HWND, _In_ int, _In_ LPCWSTR)
#define IDC_RECV_PROGRESS
Definition: resource.h:264
#define IDS_RECV_CREATETHREAD_FAILED
Definition: resource.h:162
#define e
Definition: ke_i.h:82
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
#define IDS_RECV_BUTTON_OK
Definition: resource.h:152
bool cancelling
Definition: recv.h:84
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
HANDLE thread
Definition: recv.h:77
wstring utf8_to_utf16(const string_view &utf8)
Definition: main.cpp:736
#define BN_CLICKED
Definition: winuser.h:1907
format_message(j_common_ptr cinfo, char *buffer)
Definition: jerror.c:158
GLdouble s
Definition: gl.h:2039
#define WM_COMMAND
Definition: winuser.h:1722
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 msg(x)
Definition: auth_time.c:54
#define HIWORD(l)
Definition: typedefs.h:246
#define IDCANCEL
Definition: winuser.h:825
#define IDC_RECV_MSG
Definition: resource.h:325
#define WM_INITDIALOG
Definition: winuser.h:1721
#define LOWORD(l)
Definition: pedump.c:82

Referenced by stub_RecvProgressDlgProc().

Member Data Documentation

◆ cache

vector<subvol_cache> BtrfsRecv::cache
private

Definition at line 85 of file recv.h.

◆ cancelling

bool BtrfsRecv::cancelling
private

Definition at line 84 of file recv.h.

Referenced by BtrfsRecv(), do_recv(), and RecvProgressDlgProc().

◆ dir

HANDLE BtrfsRecv::dir
private

Definition at line 77 of file recv.h.

Referenced by BtrfsRecv(), cmd_clone(), cmd_mkfile(), cmd_snapshot(), cmd_subvol(), and do_recv().

◆ dirpath

wstring BtrfsRecv::dirpath
private

Definition at line 79 of file recv.h.

Referenced by cmd_clone(), cmd_snapshot(), cmd_subvol(), Open(), and recv_thread().

◆ hwnd

HWND BtrfsRecv::hwnd
private

Definition at line 78 of file recv.h.

◆ lastwriteatt

DWORD BtrfsRecv::lastwriteatt
private

Definition at line 80 of file recv.h.

Referenced by cmd_write(), and do_recv().

◆ lastwritefile

HANDLE BtrfsRecv::lastwritefile
private

Definition at line 77 of file recv.h.

Referenced by cmd_write(), and do_recv().

◆ lastwritepath

wstring BtrfsRecv::lastwritepath
private

Definition at line 79 of file recv.h.

Referenced by cmd_write(), and do_recv().

◆ master

HANDLE BtrfsRecv::master
private

Definition at line 77 of file recv.h.

Referenced by BtrfsRecv(), cmd_snapshot(), cmd_subvol(), and do_recv().

◆ num_received

ULONG BtrfsRecv::num_received
private

Definition at line 81 of file recv.h.

Referenced by BtrfsRecv(), cmd_snapshot(), cmd_subvol(), and recv_thread().

◆ running

bool BtrfsRecv::running
private

Definition at line 84 of file recv.h.

Referenced by BtrfsRecv(), recv_thread(), and RecvProgressDlgProc().

◆ stransid

uint64_t BtrfsRecv::stransid
private

Definition at line 82 of file recv.h.

Referenced by BtrfsRecv(), cmd_snapshot(), cmd_subvol(), and do_recv().

◆ streamfile

wstring BtrfsRecv::streamfile
private

Definition at line 79 of file recv.h.

Referenced by Open(), and recv_thread().

◆ subvol_uuid

BTRFS_UUID BtrfsRecv::subvol_uuid
private

Definition at line 83 of file recv.h.

Referenced by cmd_snapshot(), cmd_subvol(), and do_recv().

◆ subvolpath

◆ thread

HANDLE BtrfsRecv::thread
private

Definition at line 77 of file recv.h.

Referenced by BtrfsRecv(), recv_thread(), and RecvProgressDlgProc().


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